3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-24 03:33:10 +01:00

servprotect: make length and age configurable (#417)

Fixes #395
This commit is contained in:
Ken Spencer 2017-02-21 20:02:26 -05:00 committed by James Lu
parent b3075d3414
commit a8fe353ba4
3 changed files with 29 additions and 6 deletions

View File

@ -86,6 +86,7 @@ def validateConf(conf, logger=None):
if newlogins:
validate(conf.get('permissions'), "New-style accounts enabled but no permissions block was found. You will not be able to administrate your PyLink instance!")
return conf

View File

@ -382,6 +382,10 @@ plugins:
# Servermaps plugin: displays network /map's from the PyLink server's perspective.
#- servermaps
# Servprotect plugin: disconnects from network if a certain limit
# of kills/saves per X seconds is met.
#- servprotect
logging:
# This configuration block defines targets that PyLink should log commands,
# errors, etc., to.
@ -566,6 +570,20 @@ relay:
#
#clientbot_modesync: none
#servprotect:
# This block configures the servprotect plugin.
# You don't need this if you aren't using it.
# length: How many KILL/SAVE's before a disconnect
#length: 5
# time: Determines how much time should pass before
# the servprotect cache is reset.
#max_age: 10
automode:
# The following options in this block are common to all plugins that spawn service bots (games,
# automode, etc.):

View File

@ -1,19 +1,23 @@
# servprotect.py: Protects against KILL and nick collision floods
from expiringdict import ExpiringDict
from pylinkirc import utils
from pylinkirc import utils, conf
from pylinkirc.log import log
# TODO: make length and time configurable
savecache = ExpiringDict(max_len=5, max_age_seconds=10)
killcache = ExpiringDict(max_len=5, max_age_seconds=10)
# check for definitions
servprotect_conf = conf.conf.get('servprotect', {})
length = servprotect_conf.get('length,' 5)
age = servprotect_conf.get('age', 10)
savecache = ExpiringDict(max_len=length, max_age_seconds=age)
killcache = ExpiringDict(max_len=length, max_age_seconds=age)
def handle_kill(irc, numeric, command, args):
"""
Tracks kills against PyLink clients. If too many are received,
automatically disconnects from the network.
"""
if killcache.setdefault(irc.name, 1) >= 5:
if killcache.setdefault(irc.name, 1) >= length:
log.error('(%s) servprotect: Too many kills received, aborting!', irc.name)
irc.disconnect()
@ -27,7 +31,7 @@ def handle_save(irc, numeric, command, args):
Tracks SAVEs (nick collision) against PyLink clients. If too many are received,
automatically disconnects from the network.
"""
if savecache.setdefault(irc.name, 0) >= 5:
if savecache.setdefault(irc.name, 0) >= length:
log.error('(%s) servprotect: Too many nick collisions, aborting!', irc.name)
irc.disconnect()