3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-25 12:12:53 +01:00

Fix #17 (netsplit quits)

copy() all the things! Also purge empty channels on quit.
This commit is contained in:
James Lu 2015-06-07 09:33:35 -07:00
parent 6680942424
commit 4b9e7b1937
2 changed files with 7 additions and 2 deletions

View File

@ -26,8 +26,10 @@ class IrcServer():
class IrcChannel(): class IrcChannel():
def __init__(self): def __init__(self):
self.users = [] self.users = []
'''
self.ops = [] self.ops = []
self.halfops = [] self.halfops = []
self.voices = [] self.voices = []
'''
def __repr__(self): def __repr__(self):
return repr(self.__dict__) return repr(self.__dict__)

View File

@ -40,10 +40,13 @@ def removeClient(irc, numeric):
Removes a client from our internal databases, regardless Removes a client from our internal databases, regardless
of whether it's one of our pseudoclients or not.""" 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: if numeric in irc.channels[k].users:
print('Removing client %s from channel %s' % (numeric, k)) print('Removing client %s from channel %s' % (numeric, k))
irc.channels[k].users.remove(numeric) irc.channels[k].users.remove(numeric)
if not irc.channels[k].users:
# Clear empty channels
del irc.channels[k]
sid = numeric[:3] sid = numeric[:3]
print('Removing client %s from irc.users' % numeric) print('Removing client %s from irc.users' % numeric)
del irc.users[numeric] del irc.users[numeric]
@ -168,7 +171,7 @@ def handle_squit(irc, numeric, command, args):
if data.uplink == split_server: if data.uplink == split_server:
print('Server %s also hosts server %s, removing those users too...' % (split_server, sid)) 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]) 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)) print('Removing client %s (%s)' % (user, irc.users[user].nick))
removeClient(irc, user) removeClient(irc, user)
del irc.servers[split_server] del irc.servers[split_server]