Beispiel #1
0
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()
Beispiel #2
0
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)
Beispiel #3
0
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))
Beispiel #4
0
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')
Beispiel #5
0
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()
Beispiel #6
0
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()))
Beispiel #7
0
def onMinsLeft(cn, args):
	'''@description Set minutes left in current match
	   @usage minutes
	   @master'''
	if args == '':
		raise UsageError()
	else:
		sbserver.setMinsRemaining(int(args))
Beispiel #8
0
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)
Beispiel #9
0
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))
Beispiel #10
0
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))
Beispiel #11
0
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()
Beispiel #12
0
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')
Beispiel #13
0
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')
Beispiel #14
0
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.'))
Beispiel #15
0
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]))
Beispiel #16
0
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()
Beispiel #17
0
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
Beispiel #18
0
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')
Beispiel #19
0
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)')
Beispiel #20
0
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)))
Beispiel #21
0
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)
Beispiel #22
0
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')