From 4b9e7b193729dee9f84f0f6e5d8c8773dad05f29 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sun, 7 Jun 2015 09:33:35 -0700 Subject: [PATCH] Fix #17 (netsplit quits) copy() all the things! Also purge empty channels on quit. --- classes.py | 2 ++ proto.py | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/classes.py b/classes.py index f147734..d2dd7fa 100644 --- a/classes.py +++ b/classes.py @@ -26,8 +26,10 @@ class IrcServer(): class IrcChannel(): def __init__(self): self.users = [] + ''' self.ops = [] self.halfops = [] self.voices = [] + ''' def __repr__(self): return repr(self.__dict__) diff --git a/proto.py b/proto.py index 9c1e94e..8a1e6ea 100644 --- a/proto.py +++ b/proto.py @@ -40,10 +40,13 @@ def removeClient(irc, numeric): Removes a client from our internal databases, regardless of whether it's one of our pseudoclients or not.""" - for k, v in irc.channels.items(): + for k, v in copy(irc.channels).items(): if numeric in irc.channels[k].users: print('Removing client %s from channel %s' % (numeric, k)) irc.channels[k].users.remove(numeric) + if not irc.channels[k].users: + # Clear empty channels + del irc.channels[k] sid = numeric[:3] print('Removing client %s from irc.users' % numeric) del irc.users[numeric] @@ -168,7 +171,7 @@ def handle_squit(irc, numeric, command, args): if data.uplink == split_server: print('Server %s also hosts server %s, removing those users too...' % (split_server, sid)) handle_squit(irc, sid, 'SQUIT', [sid, "PyLink: Automatically splitting leaf servers of %s" % sid]) - for user in irc.servers[split_server].users: + for user in copy(irc.servers[split_server].users): print('Removing client %s (%s)' % (user, irc.users[user].nick)) removeClient(irc, user) del irc.servers[split_server]