3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 09:19:23 +01:00

Merge branches 'master' and 'wip/relay-fixes' into devel

This commit is contained in:
James Lu 2016-04-01 18:32:19 -07:00
commit fab404f8d6

View File

@ -153,9 +153,9 @@ def loadDB():
try: try:
with open(dbname, "rb") as f: with open(dbname, "rb") as f:
db = pickle.load(f) db = pickle.load(f)
except (ValueError, IOError): except (ValueError, IOError, OSError):
log.exception("Relay: failed to load links database %s" log.info("Relay: failed to load links database %s"
", creating a new one in memory...", dbname) ", creating a new one in memory...", dbname)
db = {} db = {}
def exportDB(): def exportDB():
@ -172,7 +172,7 @@ def scheduleExport(starting=False):
global exportdb_timer global exportdb_timer
if not starting: if not starting:
# Export the datbase, unless this is being called the first # Export the database, unless this is being called the first
# thing after start (i.e. DB has just been loaded). # thing after start (i.e. DB has just been loaded).
exportDB() exportDB()
@ -225,7 +225,6 @@ def getRemoteSid(irc, remoteirc):
except ValueError: # Network not initialized yet. except ValueError: # Network not initialized yet.
log.exception('(%s) Failed to spawn server for %r:', log.exception('(%s) Failed to spawn server for %r:',
irc.name, remoteirc.name) irc.name, remoteirc.name)
irc.disconnect()
return return
else: else:
irc.servers[sid].remote = remoteirc.name irc.servers[sid].remote = remoteirc.name
@ -1155,36 +1154,38 @@ def handle_disconnect(irc, numeric, command, args):
"""Handles IRC network disconnections (internal hook).""" """Handles IRC network disconnections (internal hook)."""
# Quit all of our users' representations on other nets, and remove # Quit all of our users' representations on other nets, and remove
# them from our relay clients index. # them from our relay clients index.
for k, v in relayusers.copy().items(): with spawnlocks[irc.name]:
if irc.name in v: for k, v in relayusers.copy().items():
del relayusers[k][irc.name] if irc.name in v:
if k[0] == irc.name: del relayusers[k][irc.name]
try: if k[0] == irc.name:
handle_quit(irc, k[1], 'PYLINK_DISCONNECT', {'text': 'Relay network lost connection.'}) try:
del relayusers[k] handle_quit(irc, k[1], 'PYLINK_DISCONNECT', {'text': 'Relay network lost connection.'})
except KeyError: del relayusers[k]
pass except KeyError:
pass
# SQUIT all relay pseudoservers spawned for us, and remove them # SQUIT all relay pseudoservers spawned for us, and remove them
# from our relay subservers index. # from our relay subservers index.
for name, ircobj in world.networkobjects.copy().items(): with spawnlocks_servers[irc.name]:
if name != irc.name and ircobj.connected.is_set(): for name, ircobj in world.networkobjects.copy().items():
if name != irc.name and ircobj.connected.is_set():
try:
rsid = relayservers[name][irc.name]
except KeyError:
continue
else:
ircobj.proto.squit(ircobj.sid, rsid, text='Relay network lost connection.')
try: try:
rsid = relayservers[name][irc.name] del relayservers[name][irc.name]
except KeyError: except KeyError:
continue pass
else:
ircobj.proto.squit(ircobj.sid, rsid, text='Relay network lost connection.')
try: try:
del relayservers[name][irc.name] del relayservers[irc.name]
except KeyError: except KeyError:
pass pass
try:
del relayservers[irc.name]
except KeyError:
pass
utils.add_hook(handle_disconnect, "PYLINK_DISCONNECT") utils.add_hook(handle_disconnect, "PYLINK_DISCONNECT")
def handle_save(irc, numeric, command, args): def handle_save(irc, numeric, command, args):