mirror of
https://github.com/jlu5/PyLink.git
synced 2024-12-25 04:02:45 +01:00
Fixes for connection handling?
XXX: using SQUIT on the PyLink server doesn't respect autoconnect delays; why?
This commit is contained in:
parent
836d0e9701
commit
f41e1a2eb5
23
main.py
23
main.py
@ -77,10 +77,11 @@ class Irc():
|
||||
self.schedulePing()
|
||||
self.run()
|
||||
except (socket.error, classes.ProtocolError, ConnectionError) as e:
|
||||
log.warning('(%s) Failed to connect to IRC: %s: %s',
|
||||
log.warning('(%s) Disconnected from IRC: %s: %s',
|
||||
self.name, type(e).__name__, str(e))
|
||||
self.disconnect()
|
||||
autoconnect = self.serverdata.get('autoconnect')
|
||||
log.debug('(%s) Autoconnect delay set to %s seconds.', self.name, autoconnect)
|
||||
if autoconnect is not None and autoconnect >= 0:
|
||||
log.info('(%s) Going to auto-reconnect in %s seconds.', self.name, autoconnect)
|
||||
time.sleep(autoconnect)
|
||||
@ -103,20 +104,14 @@ class Irc():
|
||||
while (time.time() - self.lastping) < self.pingtimeout:
|
||||
log.debug('(%s) time_since_last_ping: %s', self.name, (time.time() - self.lastping))
|
||||
log.debug('(%s) self.pingtimeout: %s', self.name, self.pingtimeout)
|
||||
try:
|
||||
data = self.socket.recv(2048).decode("utf-8")
|
||||
buf += data
|
||||
if not data:
|
||||
break
|
||||
while '\n' in buf:
|
||||
line, buf = buf.split('\n', 1)
|
||||
log.debug("(%s) <- %s", self.name, line)
|
||||
proto.handle_events(self, line)
|
||||
except (socket.error, classes.ProtocolError, ConnectionError) as e:
|
||||
log.warning('(%s) Disconnected from IRC: %s: %s',
|
||||
self.name, type(e).__name__, str(e))
|
||||
data = self.socket.recv(2048).decode("utf-8")
|
||||
buf += data
|
||||
if not data:
|
||||
break
|
||||
self.disconnect()
|
||||
while '\n' in buf:
|
||||
line, buf = buf.split('\n', 1)
|
||||
log.debug("(%s) <- %s", self.name, line)
|
||||
proto.handle_events(self, line)
|
||||
|
||||
def send(self, data):
|
||||
# Safeguard against newlines in input!! Otherwise, each line gets
|
||||
|
@ -684,6 +684,7 @@ def initializeAll(irc):
|
||||
for link in entrydata['links']:
|
||||
network, channel = link
|
||||
initializeChannel(irc, channel)
|
||||
|
||||
def main():
|
||||
loadDB()
|
||||
utils.schedulers['relaydb'] = scheduler = sched.scheduler()
|
||||
@ -693,3 +694,7 @@ def main():
|
||||
thread = threading.Thread(target=scheduler.run)
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
|
||||
def handle_endburst(irc, numeric, command, args):
|
||||
initializeAll(irc)
|
||||
utils.add_hook(handle_endburst, "ENDBURST")
|
||||
|
@ -38,15 +38,14 @@ def spawnClient(irc, nick, ident='null', host='null', realhost=None, modes=set()
|
||||
realname = realname or irc.botdata['realname']
|
||||
realhost = realhost or host
|
||||
raw_modes = utils.joinModes(modes)
|
||||
u = irc.users[uid] = IrcUser(nick, ts, uid, ident=ident, host=host, realname=realname,
|
||||
realhost=realhost, ip=ip, modes=modes)
|
||||
irc.servers[server].users.append(uid)
|
||||
_send(irc, server, "UID {uid} {ts} {nick} {realhost} {host} {ident} {ip}"
|
||||
" {ts} {modes} + :{realname}".format(ts=ts, host=host,
|
||||
nick=nick, ident=ident, uid=uid,
|
||||
modes=raw_modes, ip=ip, realname=realname,
|
||||
realhost=realhost))
|
||||
# XXX Deduplicate the code here
|
||||
u = irc.users[uid] = IrcUser(nick, ts, uid, ident=ident, host=host, realname=realname,
|
||||
realhost=realhost, ip=ip, modes=modes)
|
||||
irc.servers[server].users.append(uid)
|
||||
return u
|
||||
|
||||
def joinClient(irc, client, channel):
|
||||
|
Loading…
Reference in New Issue
Block a user