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 onMuteCommand(cn, args): '''@description Mute a player @usage cn''' try: args = args.split(' ') tcn = int(args[0]) if len(args) > 1: raise KeyError try: p = player(tcn) except ValueError: raise StateError('Invalid player cn') else: try: muted = p.is_muted except AttributeError: muted = False if muted: raise StateError('Player is already muted.') else: p.is_muted = True name = p.name() muter = player(cn).name() sbserver.message( info( muted_temp.substitute(colordict, muted_name=name, muter=muter))) except KeyError: raise UsageError()
def onDuelCommand(cn, args): if args == '': sbserver.playerMessage( cn, error('Usage: #duel <mapname> (mode) (cn) (cn)')) args = args.split(' ') players = sbserver.players() if len(players) != 2: sbserver.playerMessage( cn, error( 'There must be only two unspectated players to enter duel mode.' )) else: if len(args) == 2: map = args[0] mode = int(args[1]) elif len(args) == 1: map = args[0] mode = sbserver.gameMode() else: sbserver.playerMessage(cn, error('Usage: #duel <mapname> (mode)')) return duelers[0] = players[0] duelers[1] = players[1] prev_mastermode = sbserver.masterMode() sbserver.setMasterMode(2) sbserver.message(green('Duel begins in...')) duelCountdown(5, map, mode)
def check_domination(self): if self.last_victim == self.current_victim: self.domination_count += 1 else: self.domination_count = 0 if self.domination_count in dommessages.keys(): sbserver.message(info(dommessages[self.domination_count].substitute(killername=player(self.playercn).name(), victimname=player(self.last_victim).name())))
def onMuteCommand(cn, args): '''@description Mute a player @usage cn''' try: args = args.split(' ') tcn = int(args[0]) if len(args) > 1: raise KeyError try: p = player(tcn) except ValueError: raise StateError('Invalid player cn') else: try: muted = p.is_muted except AttributeError: muted = False if muted: raise StateError('Player is already muted.') else: p.is_muted = True name = p.name() muter = player(cn).name() sbserver.message(info(muted_temp.substitute(colordict, muted_name=name, muter=muter))) except KeyError: raise UsageError()
def onMapVote(cn, mapname, mapmode): p = player(cn) if sbserver.mapName() == '': setMap(mapname, mapmode) elif isAtLeastMaster(cn) and sbserver.masterMode() > 0: setMap(mapname, mapmode) elif mapmode != sbserver.gameMode() and (lock_mode or not allow_modevote): p.message(error('You cannot vote for a new game mode')) else: try: vote = player(cn).gamevars['mapvote'] allow_vote = vote[0] != mapname and vote[1] != mapmode except KeyError: allow_vote = True if allow_vote: sbserver.message( info( request_temp.substitute( colordict, user=p.name(), modename=sbserver.modeName(mapmode), mapname=mapname))) p.gamevars['mapvote'] = (mapname, mapmode) else: sbserver.playerMessage( cn, error('You have already requested this map.')) countVotes()
def onUnmuteCommand(cn, args): '''@description Unmute a player @usage cn''' try: args = args.split(' ') tcn = int(args[0]) if len(args) > 1: raise KeyError try: p = player(tcn) if p.is_muted: p.is_muted = False muter = player(cn).name() sbserver.message( info( unmuted_temp.substitute(colordict, muted_name=p.name(), muter=muter))) else: raise StateError('Specified player is not crrently muted') except AttributeError: raise StateError('Specified player is not currently muted.') except KeyError: raise UsageError('No cn specified') except ValueError: raise ArgumentValueError('Invalid player cn')
def playerIp(cn, args): '''@description Get string representation of client ip @usage cn @master''' if args == '': raise UsageError() else: sbserver.message(info(player(int(args)).ipString()))
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 onUnMuteSpectatorsCmd(cn, args): '''@description Unmute spectators @usage''' if args == '': if mute_spectators[0] == False: raise StateError('Spectators are not currently muted') else: mute_spectators[0] = False sbserver.message(notice('Spectators are no longer muted')) else: raise ExtraArgumentError()
def onMuteSpectatorsCmd(cn, args): '''@description Mute all spectators @usage''' if args == '': if mute_spectators[0] == True: raise StateError('Spectators are arleady muted') else: mute_spectators[0] = True sbserver.message(notice('Spectators are now muted')) else: raise ExtraArgumentError()
def persistentTeamsCmd(cn, args): '''@description Keep current teams as they are across multiple games. @usage on/off''' if args == 'on': persistentTeams(True) sbserver.message(notice('Persistent teams enabled')) elif args == 'off': persistentTeams(False) sbserver.message(notice('Persistent teams disabled')) else: raise UsageError('on/off')
def persistentTeamsCmd(cn, args): """@description Keep current teams as they are across multiple games. @usage on/off""" if args == "on": persistentTeams(True) sbserver.message(notice("Persistent teams enabled")) elif args == "off": persistentTeams(False) sbserver.message(notice("Persistent teams disabled")) else: raise UsageError("on/off")
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))
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 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))
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(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 setPaused(val, cn=-1): '''Pause or unpause the game''' if isFrozen(): raise StateError('Server is currently frozen') if val == isPaused(): return if val: action = 'paused' else: action = 'unpaused' try: p = player(cn) except ValueError: name = 'Unknown' else: name = p.name() sbserver.message(notice(pause_message.substitute( colordict, action=action, name=name))) sbserver.setPaused(val)
def onUnmuteCommand(cn, args): '''@description Unmute a player @usage cn''' try: args = args.split(' ') tcn = int(args[0]) if len(args) > 1: raise KeyError try: p = player(tcn) if p.is_muted: p.is_muted = False muter = player(cn).name() sbserver.message(info(unmuted_temp.substitute(colordict, muted_name=p.name(), muter=muter))) else: raise StateError('Specified player is not crrently muted') except AttributeError: raise StateError('Specified player is not currently muted.') except KeyError: raise UsageError('No cn specified') except ValueError: raise ArgumentValueError('Invalid player cn')
def onMapVote(cn, mapname, mapmode): p = player(cn) if sbserver.mapName() == '': setMap(mapname, mapmode) elif isAtLeastMaster(cn) and sbserver.masterMode() > 0: setMap(mapname, mapmode) elif mapmode != sbserver.gameMode() and (lock_mode or not allow_modevote): p.message(error('You cannot vote for a new game mode')) else: try: vote = player(cn).gamevars['mapvote'] allow_vote = vote[0] != mapname and vote[1] != mapmode except KeyError: allow_vote = True if allow_vote: sbserver.message(info(request_temp.substitute(colordict, user=p.name(), modename=sbserver.modeName(mapmode), mapname=mapname))) p.gamevars['mapvote'] = (mapname, mapmode) else: sbserver.playerMessage(cn, error('You have already requested this map.')) countVotes()
def onDuelCommand(cn, args): if args == '': sbserver.playerMessage(cn, error('Usage: #duel <mapname> (mode) (cn) (cn)')) args = args.split(' ') players = sbserver.players() if len(players) != 2: sbserver.playerMessage(cn, error('There must be only two unspectated players to enter duel mode.')) else: if len(args) == 2: map = args[0] mode = int(args[1]) elif len(args) == 1: map = args[0] mode = sbserver.gameMode() else: sbserver.playerMessage(cn, error('Usage: #duel <mapname> (mode)')) return duelers[0] = players[0] duelers[1] = players[1] prev_mastermode = sbserver.masterMode() sbserver.setMasterMode(2) sbserver.message(green('Duel begins in...')) duelCountdown(5, map, mode)
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 noticeingame(msg): sbserver.message("\f1%s" % msg)
def check_sprees(self): if self.kills_since_death in spreemessages.keys(): sbserver.message(info(spreemessages[self.kills_since_death].substitute(name=player(self.playercn).name())))
def announce(cn): sbserver.message(sbtools.orange(sbserver.playerName(cn) + " is connected from " + str(getCountry(sbserver.playerIpLong(cn)))))
def sayingame(msg): sbserver.message(msg)
def setMM(cn, mm): sbserver.message((info(green('%s') + ' set master mode to ' + blue('%s')) % (sbserver.playerName(cn), MMNAMES[mm]))) sbserver.setMasterMode(mm)
def greet(cn): sbserver.message("Hello, " + sbserver.playerName(cn) + ".")
def message(string): '''Send message to server.''' sbserver.message(string)
def onAuthSuccess(cn, name): sbserver.message(info(authtemp.substitute(colordict, name=sbserver.playerName(cn), authname=name)))
def check_if_ending_spree(self, killercn): if self.kills_since_death >= 5: if killercn == -2: sbserver.message(info(suicideendmsg.substitute(victimname=player(self.playercn).name()))) else: sbserver.message(info(endmsg.substitute(victimname=player(self.playercn).name(), killername=player(killercn).name())))
def cancelDuel(): endDuel() sbserver.message(info('Duel cancelled.'))
def noticeingame(msg): sbserver.message(msg)
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 usercommunicationingame(caller,msg): if caller[0]=="ingame": return sbserver.message(""+formatCaller(caller)+": "+msg)
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))))