def onConnect(cn): try: same = dbmanager.query(IpToNick).filter( IpToNick.ip == sbserver.playerIpLong(cn)).filter( IpToNick.nick == sbserver.playerName(cn)).all() if len(same) > 0: return except NoResultFound: pass ent = IpToNick(sbserver.playerIpLong(cn), sbserver.playerName(cn)) session.add(ent) session.commit()
def onPlayerActive(cn): nick = sbserver.playerName(cn) p = player(cn) try: nickacct = nickReserver(sbserver.playerName(cn)) except NoResultFound: p.warning_for_login = False return p = player(cn) p.warning_for_login = True p.warn_nickacct = nickacct warnNickReserved(cn, 0, sbserver.playerSessionId(cn))
def userPrivSetCmd(cn, tcn, args): user_id = player(tcn).user.id if args == 'user': try: if isUser(player(tcn).user.id): sbserver.playerMessage(cn, error('%s already has user permissions.' % sbserver.playerName(tcn))) return except (ValueError, AttributeError): pass else: try: user = loggedInAs(tcn) except AttributeError: sbserver.playerMessage(cn, error('%s is not logged in.' % sbserver.playerName(tcn))) else: dbmanager.query(UserPrivilege).filter(UserPrivilege.user_id==user_id).update({ 'privilege': None }) session.add(UserPrivilege(0, user.id)) session.commit() sbserver.playerMessage(cn, info('User privilege has been given to %s (%s)' % (sbserver.playerName(tcn), user.email))) elif args == 'master': try: if isUserMaster(player(tcn).user.id): sbserver.playerMessage(cn, error('%s already has master permissions.' % sbserver.playerName(tcn))) return except (ValueError, AttributeError): pass else: try: user = loggedInAs(tcn) except AttributeError: sbserver.playerMessage(cn, error('%s is not logged in.' % sbserver.playerName(tcn))) else: dbmanager.query(UserPrivilege).filter(UserPrivilege.user_id==user_id).update({ 'privilege': None }) session.add(UserPrivilege(1, user.id)) session.commit() sbserver.playerMessage(cn, info('Master privilege has been given to %s (%s)' % (sbserver.playerName(tcn), user.email))) elif args == 'admin': try: if isUserAdmin(player(tcn).user.id): sbserver.playerMessage(cn, error('%s already has admin permissions.' % sbserver.playerName(tcn))) return except (ValueError, AttributeError): pass else: try: user = loggedInAs(tcn) except AttributeError: sbserver.playerMessage(cn, error('%s is not logged in.' % sbserver.playerName(tcn))) else: dbmanager.query(UserPrivilege).filter(UserPrivilege.user_id==user_id).update({ 'privilege': None }) session.add(UserPrivilege(2, user.id)) session.commit() sbserver.playerMessage(cn, info('Admin privilege has been given to %s (%s)' % (sbserver.playerName(tcn), user.email))) else: sbserver.playerMessage(cn, error('Privilege level must be \'master\' to set master permissions and \'admin\' to set master or admin permissions'))
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))
def formatCaller(owner): if owner[0]=="ingame": import sbserver return sbserver.playerName(owner[1]) if owner[0]=="irc": return owner[1].rstrip("_") return ""
def login(cn, user): if isLoggedIn(cn): raise StateError('You are already logged in') player(cn).user = user player(cn).logged_in = True triggerServerEvent('player_logged_in', (cn,)) sbserver.message(info(green(sbserver.playerName(cn)) + ' is verified'))
def checkConnectBanned(cn): checklist=( sbserver.playerName(cn), ipLongToString(sbserver.playerIpLong(cn)) ) matches=bandatabase.search(checklist) if len(matches)>0: timeperiod="indefinatelly" reason=matches[0][2] if reason== "": reason="none" serverNotice("%s is banned %s, reason: %s" % (sbserver.playerName(cn),matches[0][1],reason)) return True return False
def kick(caller,cn): """This allows the caller to kick another player; however, this will not override players with higher permission. Meaning, a master level permission can not kick someone with admin or trusted permission. To prevent the player from rejoining the server, they will also be banned for the default 60 minutes.""" cn=int(cn) UserSessionManager.checkPermissions(caller,UserSessionManager[("ingame",cn)][1]) #check if the other person is more privileged ban(caller,sbserver.playerName(cn),"kicked by %s" % formatCaller(caller)) triggerServerEvent("player_kicked",[caller,cn]) return sbserver.playerKick(cn)
def serverMessage(cn, args): '''@description Broadcast message to all clients in server @usage message @master''' if args == '': raise UsageError() else: msg = servermsg_template.substitute(colordict, sender=sbserver.playerName(cn), message=args) sbserver.message(msg)
def onConnect(cn): try: same = dbmanager.query(IpToNick).filter(IpToNick.ip==sbserver.playerIpLong(cn)).filter(IpToNick.nick==sbserver.playerName(cn)).all() if len(same) > 0: return except NoResultFound: pass ent = IpToNick(sbserver.playerIpLong(cn), sbserver.playerName(cn)) session.add(ent) session.commit()
def kick(caller,cn): """Kicks another player; however, this command does not work on players with higher permission. Kicking a player also gives them a 60 minute ban.""" cn=int(cn) try: UserSessionManager.checkPermissions(caller,UserSessionManager[("ingame",cn)][1]) #check if the other person is more privileged except PermissionError: triggerServerEvent("player_kick_failed",[caller,cn]) raise ban(caller,sbserver.playerName(cn),"kicked by %s" % formatCaller(caller)) triggerServerEvent("player_kicked",[caller,cn]) return sbserver.playerKick(cn)
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)))
def playerRecordNextMatch(cn, val): if permissions_ok(cn): if val == sbserver.nextMatchRecorded(): return if val: act = 'enabled' else: act = 'disabled' sbserver.setRecordNextMatch(val) sbserver.message(notice(action_temp.substitute(colordict, action=act, user=sbserver.playerName(cn)))) else: insufficientPermissions(cn)
def onGiveMaster(cn, args): '''@description Give master to a client @usage cn @master''' if args == '': raise UsageError() return try: tcn = int(args) except TypeError: raise UsageError() return sbserver.playerMessage(cn, info('You have given master to %s') % sbserver.playerName(tcn)) sbserver.setMaster(tcn)
def onLinkName(cn, args): '''@description Link name to server account, and reserve name. @usage @public''' if args != '': raise UsageError() if not isLoggedIn(cn): raise StateError('You must be logged in to link a name to your account') if sbserver.playerName(cn) in blocked_names: raise StateError('You can not reserve this name') try: dbmanager.query(NickAccount).filter(NickAccount.nick==sbserver.playerName(cn)).one() except NoResultFound: user = loggedInAs(cn) nickacct = NickAccount(sbserver.playerName(cn), user.id) session.add(nickacct) session.commit() sbserver.playerMessage(cn, info('Your name is now linked to your account.')) sbserver.playerMessage(cn, info('You may now login with /setmaster password')) return except MultipleResultsFound: pass raise StateError('Your name is already linked to an account')
def onVoteKick(cn, args): '''@description Vote to kick a player from server @usage <cn>''' if args == '': sbserver.playerMessage(cn, error('Usage #votekick <cn>')) else: try: tcn = int(args) if player(cn).votekick == tcn: sbserver.playerMessage( cn, error('You have already voted to kick that player.')) allow_vote = False else: allow_vote = True except AttributeError: allow_vote = True if allow_vote: sbserver.message( info( vktemp.substitute(colordict, voter=sbserver.playerName(cn), victim=sbserver.playerName(tcn)))) player(cn).votekick = int(args) checkVotes(int(args))
def ban(caller,who=None,reason="",time="60"): """This bans the person specified. If there is not a name given then the caller will be banned. If time is "perm","permanent","permanently","0" or 0 then the ban will be permanent. The default ban time is 60 minutes.""" if who is None: bans(caller) try: who=sbserver.playerName(int(who)) except ValueError: pass if time[-1]=="d": time=int(time[:1])*1440 if time in ["perm","permanent","permanently","0",0]: expires=None else: expires=datetime.utcnow()+timedelta(0,int(time)*60) bandatabase[who]=(expires,reason)
def onVoteKick(cn, args): '''@description Vote to kick a player from server @usage <cn>''' if args == '': sbserver.playerMessage(cn, error('Usage #votekick <cn>')) else: try: tcn = int(args) if player(cn).votekick == tcn: sbserver.playerMessage(cn, error('You have already voted to kick that player.')) allow_vote = False else: allow_vote = True except AttributeError: allow_vote = True if allow_vote: sbserver.message(info(vktemp.substitute(colordict, voter=sbserver.playerName(cn), victim=sbserver.playerName(tcn)))) player(cn).votekick = int(args) checkVotes(int(args))
if self.reconnect_count < 5: self.reconnect_count += 1 self.doConnect() def signedOn(self, bot): if bot not in self.bots: self.bots.append(bot) def signedOut(self, bot): if bot in self.bots: self.bots.remove(bot) addTimer(5000, self.doReconnect, ()) def broadcast(self, message): for bot in self.bots: bot.broadcast(message) event_abilities = { 'player_active': ('player_connect', lambda x: factory.broadcast('%s (\x037 %i \x03) \x032Connected\x03' % (sbserver.playerName(x), x))), 'player_disconnect': ('player_disconnect', lambda x: factory.broadcast('%s (\x037 %i \x03) \x032Disconnected\x03' % (sbserver.playerName(x), x))), 'message': ('player_message', lambda x, y: factory.broadcast('%s (\x037 %i \x03): %s' % (sbserver.playerName(x), x, y))), 'map_change': ('map_changed', lambda x, y: factory.broadcast('\x038Map changed to:\x03 %s (%s)' % (x, sbserver.modeName(y)))), 'gain_admin': ('player_claimed_admin', lambda x: factory.broadcast('%s (\x037 %i \x03) \x036Has claimed admin\x03' % (sbserver.playerName(x), x))), 'gain_master': ('player_claimed_master', lambda x: factory.broadcast('%s (\x037 %i \x03) \x036Has claimed master\x03' % (sbserver.playerName(x), x))), 'auth': ('player_auth_succeed', lambda x, y: factory.broadcast('%s (\x037 %i \x03) has authenticated as\x036 %[email protected]\x03' % (sbserver.playerName(x), x, y))), 'relinquish_admin': ('player_released_admin', lambda x: factory.broadcast('%s (\x037 %i \x03) \x036Has relinquished admin\x03' % (sbserver.playerName(x), x))), 'relinquish_master': ('player_released_master', lambda x: factory.broadcast('%s (\x037 %i \x03) \x036Has relinquished master\x03' % (sbserver.playerName(x), x))), } if enable: factory = IrcBotFactory(nickname, [channel]) factory.doConnect() for key in event_abilities.keys(): if config.getOption('Abilities', key, 'no') == 'yes':
def cndetails(cn): return sbserver.playerName(cn)+" (cn"+str(cn)+"/"+ipLongToString(sbserver.playerIpLong(cn))+")"
def greet(cn): sbserver.message("Hello, " + sbserver.playerName(cn) + ".")
def setMM(cn, mm): sbserver.message((info(green('%s') + ' set master mode to ' + blue('%s')) % (sbserver.playerName(cn), MMNAMES[mm]))) sbserver.setMasterMode(mm)
def signedOut(self, bot): if bot in self.bots: self.bots.remove(bot) addTimer(5000, self.doReconnect, ()) def broadcast(self, message): for bot in self.bots: bot.broadcast(message) event_abilities = { 'player_active': ('player_connect', lambda x: factory.broadcast('%s (\x037 %i \x03) \x032Connected\x03' % (sbserver.playerName(x), x))), 'player_disconnect': ('player_disconnect', lambda x: factory.broadcast('%s (\x037 %i \x03) \x032Disconnected\x03' % (sbserver.playerName(x), x))), 'message': ('player_message', lambda x, y: factory.broadcast('%s (\x037 %i \x03): %s' % (sbserver.playerName(x), x, y))), 'map_change': ('map_changed', lambda x, y: factory.broadcast('\x038Map changed to:\x03 %s (%s)' % (x, sbserver.modeName(y)))), 'gain_admin': ('player_claimed_admin', lambda x: factory. broadcast('%s (\x037 %i \x03) \x036Has claimed admin\x03' % (sbserver.playerName(x), x))),
def onAuthSuccess(cn, name): sbserver.message( info( authtemp.substitute(colordict, name=sbserver.playerName(cn), authname=name)))
def onRelAdmin(cn): sbserver.message( info(ratemp.substitute(colordict, name=sbserver.playerName(cn))))
def onRelMaster(cn): sbserver.message( info(rmtemp.substitute(colordict, name=sbserver.playerName(cn))))
def name(self): '''Name of client''' return sbserver.playerName(self.cn)
def onAuthSuccess(cn, name): sbserver.message(info(authtemp.substitute(colordict, name=sbserver.playerName(cn), authname=name)))
def onRelAdmin(cn): sbserver.message(info(ratemp.substitute(colordict, name=sbserver.playerName(cn))))
def onRelMaster(cn): sbserver.message(info(rmtemp.substitute(colordict, name=sbserver.playerName(cn))))
def announce(cn): sbserver.message(sbtools.orange(sbserver.playerName(cn) + " is connected from " + str(getCountry(sbserver.playerIpLong(cn)))))