Пример #1
0
def warnNickReserved(cn, count, sessid):
	try:
		p = player(cn)
	except ValueError:
		return
	try:
		nickacct = p.warn_nickacct
		if nickacct.nick != sbserver.playerName(cn) or sessid != sbserver.playerSessionId(cn):
			p.warning_for_login = False
			return
	except (AttributeError, ValueError):
		p.warning_for_login = False
		return
	if isLoggedIn(cn):
		user = loggedInAs(cn)
		if nickacct.user_id != user.id:
			ban(cn, 0, 'Use of reserved name', -1)
		p.warning_for_login = False
		return
	if count > 4:
		ban(cn, 0, 'Use of reserved name', -1)
		p.warning_for_login = False
		return
	remaining = 25-(count*5)
	sbserver.playerMessage(cn, warning('Your name is reserved. You have ' + red('%i') + ' seconds to login or be kicked.') % remaining)
	addTimer(5000, warnNickReserved, (cn, count+1, sessid))
Пример #2
0
 def checkPlayers(self):
     addTimer(5000, self.checkPlayers, ())
     if not self.enabled:
         return
     self.update_averages()
     if self.counter == 0:
         laggers = []
         for player in players.all():
             try:
                 if not player.isSpectator(
                 ) and player.avg_ping > self.max_ping:
                     laggers.append(player.cn)
             except AttributeError:
                 player.avg_ping = 0
         remove_cns = []
         for lagger in laggers:
             if lagger in self.warned_cns:
                 ban(lagger, 0, 'lagging', -1)
                 remove_cns.append(lagger)
             else:
                 sbserver.playerMessage(
                     lagger,
                     warning(
                         'Your ping is too high.  You will be kicked if it is not lowered.'
                     ))
                 self.warned_cns.append(lagger)
         for r_cns in remove_cns:
             self.warned_cns.remove(r_cns)
Пример #3
0
def clanWarTimer(count, cn):
    if count > 0:
        message(notice('Clan war starts in ' + green(str(count))))
        addTimer(1000, clanWarTimer, (count - 1, cn))
    else:
        message(notice('Fight!'))
        setFrozen(False)
        setPaused(False)
Пример #4
0
def clanWarTimer(count, cn):
	if count > 0:
		message(notice('Clan war starts in ' + green(str(count))))
		addTimer(1000, clanWarTimer, (count-1, cn))
	else:
		message(notice('Fight!'))
		setFrozen(False)
		setPaused(False)
Пример #5
0
def duelCountdown(count, map, mode):
	players = sbserver.players()
	if len(sbserver.players()) != 2 or players[0] not in duelers or players[1] not in duelers:
		cancelDuel()
	elif count == 0:
		currently_dueling[0] = True
		sbserver.message(green('Fight!'))
		sbserver.setMap(map, mode)
		sbserver.setPaused(False)
	else:
		sbserver.message(green('%i seconds' % count))
		addTimer(1000, duelCountdown, (count-1, map, mode))
Пример #6
0
def duelCountdown(count, map, mode):
    players = sbserver.players()
    if len(sbserver.players()
           ) != 2 or players[0] not in duelers or players[1] not in duelers:
        cancelDuel()
    elif count == 0:
        currently_dueling[0] = True
        sbserver.message(green('Fight!'))
        sbserver.setMap(map, mode)
        sbserver.setPaused(False)
    else:
        sbserver.message(green('%i seconds' % count))
        addTimer(1000, duelCountdown, (count - 1, map, mode))
Пример #7
0
def warnTagReserved(cn, count, sessid, nick):
	try:
		p = player(cn)
	except ValueError:
		return
	if p.name() != nick or sessid != p.sessionId():
		return
	if len(p.registered_tags) == 0:
		return
	if count > 4:
		ban(cn, 0, 'Use of reserved clan tag', -1)
		p.warning_for_login = False
		return
	remaining = 25-(count*5)
	p.message(warning('Your are using a reserved clan tag. You have ' + red('%i') + ' seconds to login or be kicked.') % remaining)
	addTimer(5000, warnTagReserved, (cn, count+1, sessid, nick))
Пример #8
0
def ban(cn, seconds, reason, banner_cn):
	ip = sbserver.playerIpLong(cn)
	expiration = time.time() + seconds
	nick = sbserver.playerName(cn)
	if banner_cn != -1:
		banner_ip = sbserver.playerIpLong(banner_cn)
		banner_nick = sbserver.playerName(banner_cn)
	else:
		banner_ip = 0
		banner_nick = ''
	newban = Ban(ip, expiration, reason, nick, banner_ip, banner_nick, time.time())
	session.add(newban)
	session.commit()
	addTimer(200, sbserver.playerKick, (cn,))
	logging.info('Player %s (%s) banned for %s by %s (%s)',
		nick,
		ipLongToString(ip),
		reason,
		banner_nick,
		ipLongToString(banner_ip))
	sbserver.message(info(ban_message.substitute(colordict, name=nick, seconds=seconds, reason=reason)))
Пример #9
0
	def checkPlayers(self):
		addTimer(5000, self.checkPlayers, ())
		if not self.enabled:
			return
		self.update_averages()
		if self.counter == 0:
			laggers = []
			for player in players.all():
				try:
					if not player.isSpectator() and player.avg_ping > self.max_ping:
						laggers.append(player.cn)
				except AttributeError:
					player.avg_ping = 0
			remove_cns = []
			for lagger in laggers:
				if lagger in self.warned_cns:
					ban(lagger, 0, 'lagging', -1)
					remove_cns.append(lagger)
				else:
					sbserver.playerMessage(lagger, warning('Your ping is too high.  You will be kicked if it is not lowered.'))
					self.warned_cns.append(lagger)
			for r_cns in remove_cns:
				self.warned_cns.remove(r_cns)
Пример #10
0
 def signedOut(self, bot):
     if bot in self.bots:
         self.bots.remove(bot)
         addTimer(5000, self.doReconnect, ())
Пример #11
0
		A spike-friendlier method is to arrange a list of values and calculate the average on the whole list divided by its length,
		like this: sum(pingvalueslist)/len(pingvalueslist) //Henrik L
		"""
		for player in players.all():
			try:
				player.avg_ping = (player.avg_ping + player.ping()) / 2
			except AttributeError:
				player.avg_ping = player.ping() / 2
		if self.counter:
			self.counter -= 1
		else:
			self.counter = self.action_interval

limiter = PingLimiter(max_ping, action_interval)
limiter.enabled = enable
addTimer(5000, limiter.checkPlayers, ())

@commandHandler('pinglimiter')
@adminRequired
def pingLimiterCmd(cn, args):
	'''@description Enable or disable kicking high ping users
	   @usage enable/disable'''
	if args == 'enable':
		limiter.enabled = True
		sbserver.playerMessage(cn, notice('Ping limiter enabled'))
	elif args == 'disable':
		limiter.enabled = False
		sbserver.playerMessage(cn, notice('Ping limiter disabled'))
	else:
		raise UsageError('enable/disable')
Пример #12
0
def checkforspammerstimer():
    CheckForSpammers()
    addTimer(1000, checkforspammerstimer, ())
Пример #13
0
    for occur in cn_occurs_1sec.keys():
        if cn_occurs_1sec[occur] > max_per_second:
            spammermanager.add_spamming_case(player(occur).ipString())
        else:
            for occur in cn_occurs_interval.keys():
                if cn_occurs_interval[occur] > max_per_interval:
                    spammermanager.add_spamming_case(player(occur).ipString())


def checkforspammerstimer():
    CheckForSpammers()
    addTimer(1000, checkforspammerstimer, ())


addTimer(1000, checkforspammerstimer, ())

spam_last_votekick = {}


# Check for players performing spam attack
@eventHandler('player_kick')
def check_kick_timeout(cn, victim):
    t = time.time()
    try:
        if (t - spam_last_votekick[cn]) <= 2:
            ban(playercn, ban_duration, 'spamming server', -1)
    except KeyError:
        pass
    spam_last_votekick[cn] = t
Пример #14
0
def checkforspammerstimer():
	CheckForSpammers()
	addTimer(1000, checkforspammerstimer, ())
Пример #15
0
	
	cn_occurs_1sec = {}
	cn_occurs_interval = {}
	for timekey in log.keys():
		chatcn = log[timekey][0]
		if (time.time() - timekey) <= 1:
			if not chatcn in cn_occurs_1sec.keys():
				cn_occurs_1sec[chatcn] = 1
			else:
				cn_occurs_1sec[chatcn] += 1
				
		if not chatcn in cn_occurs_interval.keys():
			cn_occurs_interval[chatcn] = 1
		else:
			cn_occurs_interval[chatcn] += 1

	
	for occur in cn_occurs_1sec.keys():
		if cn_occurs_1sec[occur] > max_per_second:
			spammermanager.add_spamming_case(player(occur).ipString())
		else:
			for occur in cn_occurs_interval.keys():
				if cn_occurs_interval[occur] > max_per_interval:
					spammermanager.add_spamming_case(player(occur).ipString())

def checkforspammerstimer():
	CheckForSpammers()
	addTimer(1000, checkforspammerstimer, ())
	
addTimer(1000, checkforspammerstimer, ())
Пример #16
0
	def signedOut(self, bot):
		if bot in self.bots:
			self.bots.remove(bot)
			addTimer(5000, self.doReconnect, ())
Пример #17
0
def onPlayerConnect(cn):
    addPlayerForCn(cn)
    addTimer(1000, triggerConnectDelayed, (cn, ))
Пример #18
0
 def sendMessage(self):
     message(notice(self.msg))
     addTimer(self.delay, self.sendMessage, ())
Пример #19
0
def resumeTimer(count, cn):
	if count > 0:
		sendServerMessage(notice('Resuming in ' + green(str(count)) + white('...')))
		addTimer(1000, resumeTimer, (count-1, cn))
	else:
		setPaused(False, cn)
Пример #20
0
def onPlayerConnect(cn):
	addPlayerForCn(cn)
	addTimer(1000, triggerConnectDelayed, (cn,))
Пример #21
0
 def __init__(self, msg, delay):
     self.msg = string.Template(msg).substitute(colordict)
     self.delay = delay
     addTimer(delay, self.sendMessage, ())
Пример #22
0
		like this: sum(pingvalueslist)/len(pingvalueslist) //Henrik L
		"""
        for player in players.all():
            try:
                player.avg_ping = (player.avg_ping + player.ping()) / 2
            except AttributeError:
                player.avg_ping = player.ping() / 2
        if self.counter:
            self.counter -= 1
        else:
            self.counter = self.action_interval


limiter = PingLimiter(max_ping, action_interval)
limiter.enabled = enable
addTimer(5000, limiter.checkPlayers, ())


@commandHandler('pinglimiter')
@adminRequired
def pingLimiterCmd(cn, args):
    '''@description Enable or disable kicking high ping users
	   @usage enable/disable'''
    if args == 'enable':
        limiter.enabled = True
        sbserver.playerMessage(cn, notice('Ping limiter enabled'))
    elif args == 'disable':
        limiter.enabled = False
        sbserver.playerMessage(cn, notice('Ping limiter disabled'))
    else:
        raise UsageError('enable/disable')
Пример #23
0
 def sendMessage(self):
     message(notice(self.msg))
     addTimer(self.delay, self.sendMessage, ())
Пример #24
0
 def __init__(self, msg, delay):
     self.msg = string.Template(msg).substitute(colordict)
     self.delay = delay
     addTimer(delay, self.sendMessage, ())
Пример #25
0
def resumeTimer(count, cn):
	if count > 0:
		sendServerMessage(notice('Resuming in ' + green(str(count)) + white('...')))
		addTimer(1000, resumeTimer, (count-1, cn))
	else:
		setPaused(False, cn)