mirror of
https://github.com/jlu5/PyLink.git
synced 2024-12-26 04:32:51 +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
9
main.py
9
main.py
@ -77,10 +77,11 @@ class Irc():
|
|||||||
self.schedulePing()
|
self.schedulePing()
|
||||||
self.run()
|
self.run()
|
||||||
except (socket.error, classes.ProtocolError, ConnectionError) as e:
|
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.name, type(e).__name__, str(e))
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
autoconnect = self.serverdata.get('autoconnect')
|
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:
|
if autoconnect is not None and autoconnect >= 0:
|
||||||
log.info('(%s) Going to auto-reconnect in %s seconds.', self.name, autoconnect)
|
log.info('(%s) Going to auto-reconnect in %s seconds.', self.name, autoconnect)
|
||||||
time.sleep(autoconnect)
|
time.sleep(autoconnect)
|
||||||
@ -103,7 +104,6 @@ class Irc():
|
|||||||
while (time.time() - self.lastping) < self.pingtimeout:
|
while (time.time() - self.lastping) < self.pingtimeout:
|
||||||
log.debug('(%s) time_since_last_ping: %s', self.name, (time.time() - self.lastping))
|
log.debug('(%s) time_since_last_ping: %s', self.name, (time.time() - self.lastping))
|
||||||
log.debug('(%s) self.pingtimeout: %s', self.name, self.pingtimeout)
|
log.debug('(%s) self.pingtimeout: %s', self.name, self.pingtimeout)
|
||||||
try:
|
|
||||||
data = self.socket.recv(2048).decode("utf-8")
|
data = self.socket.recv(2048).decode("utf-8")
|
||||||
buf += data
|
buf += data
|
||||||
if not data:
|
if not data:
|
||||||
@ -112,11 +112,6 @@ class Irc():
|
|||||||
line, buf = buf.split('\n', 1)
|
line, buf = buf.split('\n', 1)
|
||||||
log.debug("(%s) <- %s", self.name, line)
|
log.debug("(%s) <- %s", self.name, line)
|
||||||
proto.handle_events(self, 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))
|
|
||||||
break
|
|
||||||
self.disconnect()
|
|
||||||
|
|
||||||
def send(self, data):
|
def send(self, data):
|
||||||
# Safeguard against newlines in input!! Otherwise, each line gets
|
# Safeguard against newlines in input!! Otherwise, each line gets
|
||||||
|
@ -684,6 +684,7 @@ def initializeAll(irc):
|
|||||||
for link in entrydata['links']:
|
for link in entrydata['links']:
|
||||||
network, channel = link
|
network, channel = link
|
||||||
initializeChannel(irc, channel)
|
initializeChannel(irc, channel)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
loadDB()
|
loadDB()
|
||||||
utils.schedulers['relaydb'] = scheduler = sched.scheduler()
|
utils.schedulers['relaydb'] = scheduler = sched.scheduler()
|
||||||
@ -693,3 +694,7 @@ def main():
|
|||||||
thread = threading.Thread(target=scheduler.run)
|
thread = threading.Thread(target=scheduler.run)
|
||||||
thread.daemon = True
|
thread.daemon = True
|
||||||
thread.start()
|
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']
|
realname = realname or irc.botdata['realname']
|
||||||
realhost = realhost or host
|
realhost = realhost or host
|
||||||
raw_modes = utils.joinModes(modes)
|
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}"
|
_send(irc, server, "UID {uid} {ts} {nick} {realhost} {host} {ident} {ip}"
|
||||||
" {ts} {modes} + :{realname}".format(ts=ts, host=host,
|
" {ts} {modes} + :{realname}".format(ts=ts, host=host,
|
||||||
nick=nick, ident=ident, uid=uid,
|
nick=nick, ident=ident, uid=uid,
|
||||||
modes=raw_modes, ip=ip, realname=realname,
|
modes=raw_modes, ip=ip, realname=realname,
|
||||||
realhost=realhost))
|
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
|
return u
|
||||||
|
|
||||||
def joinClient(irc, client, channel):
|
def joinClient(irc, client, channel):
|
||||||
|
Loading…
Reference in New Issue
Block a user