Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
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))
Ejemplo n.º 3
0
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'))
Ejemplo n.º 4
0
Archivo: ctl.py Proyecto: pguenth/xsbs
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'))
Ejemplo n.º 5
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))
Ejemplo n.º 6
0
def formatCaller(owner):
	if owner[0]=="ingame":
		import sbserver
		return sbserver.playerName(owner[1])
	if owner[0]=="irc":
		return owner[1].rstrip("_")
	return ""
Ejemplo n.º 7
0
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'))
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
Archivo: ctl.py Proyecto: pguenth/xsbs
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)
Ejemplo n.º 12
0
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()
Ejemplo n.º 13
0
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)
Ejemplo n.º 14
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)))
Ejemplo n.º 15
0
Archivo: demo.py Proyecto: pguenth/xsbs
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)
Ejemplo n.º 16
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)
Ejemplo n.º 17
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')
Ejemplo n.º 18
0
Archivo: ctl.py Proyecto: pguenth/xsbs
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)
Ejemplo n.º 19
0
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))
Ejemplo n.º 20
0
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)
Ejemplo n.º 21
0
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))
Ejemplo n.º 22
0
		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':
Ejemplo n.º 23
0
	def cndetails(cn):
		return sbserver.playerName(cn)+" (cn"+str(cn)+"/"+ipLongToString(sbserver.playerIpLong(cn))+")"
Ejemplo n.º 24
0
def greet(cn):
	sbserver.message("Hello, " + sbserver.playerName(cn) + ".")
Ejemplo n.º 25
0
def setMM(cn, mm):
    sbserver.message((info(green('%s') + ' set master mode to ' + blue('%s')) %
                      (sbserver.playerName(cn), MMNAMES[mm])))
    sbserver.setMasterMode(mm)
Ejemplo n.º 26
0
    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))),
Ejemplo n.º 27
0
def onAuthSuccess(cn, name):
    sbserver.message(
        info(
            authtemp.substitute(colordict,
                                name=sbserver.playerName(cn),
                                authname=name)))
Ejemplo n.º 28
0
def onRelAdmin(cn):
    sbserver.message(
        info(ratemp.substitute(colordict, name=sbserver.playerName(cn))))
Ejemplo n.º 29
0
def onRelMaster(cn):
    sbserver.message(
        info(rmtemp.substitute(colordict, name=sbserver.playerName(cn))))
Ejemplo n.º 30
0
 def name(self):
     '''Name of client'''
     return sbserver.playerName(self.cn)
Ejemplo n.º 31
0
	def name(self):
		'''Name of client'''
		return sbserver.playerName(self.cn)
Ejemplo n.º 32
0
def onAuthSuccess(cn, name):
	sbserver.message(info(authtemp.substitute(colordict, name=sbserver.playerName(cn), authname=name)))
Ejemplo n.º 33
0
def onRelAdmin(cn):
	sbserver.message(info(ratemp.substitute(colordict, name=sbserver.playerName(cn))))
Ejemplo n.º 34
0
def onRelMaster(cn):
	sbserver.message(info(rmtemp.substitute(colordict, name=sbserver.playerName(cn))))
Ejemplo n.º 35
0
def announce(cn):
	sbserver.message(sbtools.orange(sbserver.playerName(cn) + " is connected from " + str(getCountry(sbserver.playerIpLong(cn)))))
Ejemplo n.º 36
0
def setMM(cn, mm):
	sbserver.message((info(green('%s') + ' set master mode to ' + blue('%s')) % (sbserver.playerName(cn), MMNAMES[mm])))
	sbserver.setMasterMode(mm)