def onUserPrivCmd(cn, args): '''@description Set privileges for server account @usage <cn> <action> <level> @admin''' sp = args.split(' ') try: if sp[0] == 'set': subcmd = sp[0] tcn = int(sp[2]) args = sp[1] elif sp[0] == 'wipe': subcmd = sp[0] tcn = int(sp[1]) args = 'user' else: subcmd = sp[1] tcn = int(sp[0]) args = sp[2] except ValueError: raise UsageError() if subcmd == 'add': userPrivSetCmd(cn, tcn, args) elif subcmd == 'del': userPrivSetCmd(cn, tcn, 'user') elif subcmd == 'set': userPrivSetCmd(cn, tcn, args) elif subcmd == 'wipe': userPrivSetCmd(cn, tcn, args) else: raise UsageError()
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 namesCmd(cn, args): '''@description Display names used by client @usage cn @public''' if master_required and not isAtLeastMaster(cn): insufficientPermissions(cn) return if args == '': raise UsageError() return try: tcn = int(args) names = dbmanager.query(IpToNick).filter( IpToNick.ip == sbserver.playerIpLong(tcn)).all() if len(names) == 0: sbserver.playerMessage(cn, info('No names found')) return except NoResultFound: sbserver.playerMessage(cn, info('No names found')) return except ValueError: sbserver.playerMessage(cn, error('Invalid cn')) return namestr = 'Other known names: ' for name in names: namestr += name.nick + ' ' sbserver.playerMessage(cn, info(namestr))
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 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 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 onMinsLeft(cn, args): '''@description Set minutes left in current match @usage minutes @master''' if args == '': raise UsageError() else: sbserver.setMinsRemaining(int(args))
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 onResize(cn, args): '''@description Change maximum clients allowed in server @usage maxclients @admin''' if args == '': raise UsageError() else: size = int(args) sbserver.setMaxClients(int(args))
def onRecentBans(cn, args): '''@description Recently added bans @usage''' p = player(cn) if args != '': raise UsageError() else: recent = dbmanager.query(Ban).order_by(Ban.time.desc())[:5] for ban in recent: p.message(info('Nick: %s' % ban.nick))
def onSmiteCommand(cn, args): '''@description Strike a player down @usage <cn> @master''' if args == '': raise UsageError() p = player(cn) t = player(int(args)) sendServerMessage(info(smite_template.substitute(colordict, smiter=p.name(), smited=t.name()))) t.suicide()
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')
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 onLoginCommand(cn, args): '''@description Login to server account @usage email password @public''' args = args.split(' ') if len(args) != 2: raise UsageError() user = userAuth(args[0], args[1]) if user: login(cn, user) else: sbserver.playerMessage(cn, error('Invalid login.'))
def onPmCommand(cn, args): '''@description Send a private message @usage <cn> <message> @public''' args = args.split() if len(args) < 2: raise UsageError() i = 0 for key in args: if i > 1: args[1] += (" " + str(key)) i += 1 player(int(args[0])).message(pm_template.substitute(colordict, sender=player(cn).name(), message=args[1]))
def setPersistantDemoRecord(cn, args): '''@description Enable/disable persistant demo recording @usage enable/disable''' if args == 'enable': player(cn).message(info('Enabling persistant demo recording')) persistent_recording = True sbserver.setRecordNextMatch(persistent_recording) elif args == 'disable': player(cn).message(info('Disabling persistant demo recording')) persistent_recording = False sbserver.setRecordNextMatch(persistent_recording) else: raise UsageError()
def onChangepass(cn, args): '''@description Link name to server account, and reserve name. @usage @public''' args = args.split(' ') if len(args) != 2: raise UsageError() if not isLoggedIn(cn): raise StateError('You must be logged in to change your password') try: dbmanager.query(User).filter(User.id==loggedInAs(cn).id).filter(User.password==args[0]).one() except NoResultFound: raise StateError('Incorrect password.') except MultipleResultsFound: pass else: dbmanager.query(User).filter(User.id==loggedInAs(cn).id).update({ 'password': args[1] }) session.commit() return
def onRegisterCommand(cn, args): '''@description Register account with server @usage email password @public''' args = args.split(' ') if len(args) != 2: raise UsageError() try: dbmanager.query(User).filter(User.email==args[0]).one() except NoResultFound: if not isValidEmail(args[0]): raise ArgumentValueError('Invalid email address') user = User(args[0], args[1]) session.add(user) session.commit() sbserver.playerMessage(cn, info('Account created')) return except MultipleResultsFound: pass raise StateError('An account with that email already exists')
def onBanCmd(cn, text): '''@description Ban user from server @usage <seconds> (reason)''' sp = text.split(' ') p = player(cn) try: tcn = int(sp[0]) ip = p.ipLong() reason = '' length = 0 if len(sp) >= 3: reason = sp[2] else: reason = default_reason if len(sp) >= 2: length = int(sp[1]) else: length = int(default_ban_length) ban(tcn, length, reason, cn) except (ValueError, KeyError): raise UsageError('cn (duration) (reason)')
def onInsertBan(cn, args): '''@description Intert ban for ip address @usage <ip> <seconds> (reason)''' p = player(cn) args = args.split(' ') if len(args) < 2: raise UsageError('ip length (reason)') else: ip = ipStringToLong(args[0]) length = int(args[1]) try: reason = args[2] except IndexError: reason = 'Unspecified reason' expiration = time.time() + length newban = Ban(ip, expiration, reason, 'Unnamed', 0, 'Unnamed', time.time()) session.add(newban) session.commit() p.message( info('Inserted ban for %s for %i seconds for %s.' % (ipLongToString(ip), length, reason)))
def clanWar(cn, args): '''@description Start a clan war with current teams @usage map (mode)''' sender = player(cn) if args == '': raise UsageError() else: args = args.split(' ') if len(args) == 1: map = args mode = currentMode() elif len(args) == 2: map = args[0] try: mode = modeNumber(args[1]) except ValueError: raise ArgumentValueError('Invalid game mode') persistentTeams(True) setMap(map, mode) setMasterMode(2) setPaused(True, cn) setFrozen(True) clanWarTimer(10, cn)
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')