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

relay: KILL war protection (#23)

TODO: possibly integrate this into core?
This commit is contained in:
James Lu 2015-09-12 17:41:49 -07:00
parent 1fcacd0d7c
commit b3902c7711

View File

@ -24,6 +24,7 @@ relayusers = defaultdict(dict)
relayservers = defaultdict(dict) relayservers = defaultdict(dict)
spawnlocks = defaultdict(threading.RLock) spawnlocks = defaultdict(threading.RLock)
savecache = ExpiringDict(max_len=5, max_age_seconds=10) savecache = ExpiringDict(max_len=5, max_age_seconds=10)
killcache = ExpiringDict(max_len=5, max_age_seconds=10)
def relayWhoisHandler(irc, target): def relayWhoisHandler(irc, target):
user = irc.users[target] user = irc.users[target]
@ -697,6 +698,7 @@ def handle_kill(irc, numeric, command, args):
# We don't allow killing over the relay, so we must respawn the affected # We don't allow killing over the relay, so we must respawn the affected
# client and rejoin it to its channels. # client and rejoin it to its channels.
del relayusers[realuser][irc.name] del relayusers[realuser][irc.name]
if killcache.setdefault(irc.name, 0) <= 5:
remoteirc = world.networkobjects[realuser[0]] remoteirc = world.networkobjects[realuser[0]]
for remotechan in remoteirc.channels.copy(): for remotechan in remoteirc.channels.copy():
localchan = findRemoteChan(remoteirc, irc, remotechan) localchan = findRemoteChan(remoteirc, irc, remotechan)
@ -717,6 +719,13 @@ def handle_kill(irc, numeric, command, args):
log.info('(%s) Relay claim: Blocked KILL (reason %r) from server %s to relay client %s/%s.', log.info('(%s) Relay claim: Blocked KILL (reason %r) from server %s to relay client %s/%s.',
irc.name, args['text'], irc.servers[numeric].name, irc.name, args['text'], irc.servers[numeric].name,
remoteirc.users[realuser[1]].nick, realuser[0]) remoteirc.users[realuser[1]].nick, realuser[0])
else:
log.error('(%s) Too many kills received for target %s, aborting!',
irc.name, userdata.nick)
irc.aborted.set()
killcache[irc.name] += 1
log.debug('killcache: %s', irc.name, killcache)
# Target user was local. # Target user was local.
else: else:
# IMPORTANT: some IRCds (charybdis) don't send explicit QUIT messages # IMPORTANT: some IRCds (charybdis) don't send explicit QUIT messages