Esempio n. 1
0
	def __init__(self, prefix="^1[^3Boteh^1]:", ip='localhost:27960', rcon="", debug=False, playerdb=None):
		from config import UrTConfig

		self.prefix = prefix
		self.ip = ip
		self.rcon = rcon
		self.Q = RCON(self.ip, self.rcon)
		self.pdb = playerdb
		self.status = 1 #1 is on, 0 is off
		self.debug = debug #False will hide messages, True will print them and log them to vars
		
		self.maplist = UrTConfig['maps']
		self.currentMap = None
		self.gameData = {}
		self.loadingMap = False
		self.justChangedMap = False

		self.redScore = 0
		self.blueScore = 0

		self.Modules = {} #Plugins
		self.Listeners = {} #Plugins waiting for Triggers
		self.Triggers = {} #Possible Triggers (Events)
		self.Commands = {} #Commands
		self.Aliases = {} #aliases BIATCH

		self.Clients = {} #AKA players
		self.curClients = lambda: [int(i[0]) for i in self.getStatus()]
Esempio n. 2
0
class Bot():
	def __init__(self, prefix="^1[^3Boteh^1]:", ip='localhost:27960', rcon="", debug=False, playerdb=None):
		from config import UrTConfig

		self.prefix = prefix
		self.ip = ip
		self.rcon = rcon
		self.Q = RCON(self.ip, self.rcon)
		self.pdb = playerdb
		self.status = 1 #1 is on, 0 is off
		self.debug = debug #False will hide messages, True will print them and log them to vars
		
		self.maplist = UrTConfig['maps']
		self.currentMap = None
		self.gameData = {}
		self.loadingMap = False
		self.justChangedMap = False

		self.redScore = 0
		self.blueScore = 0

		self.Modules = {} #Plugins
		self.Listeners = {} #Plugins waiting for Triggers
		self.Triggers = {} #Possible Triggers (Events)
		self.Commands = {} #Commands
		self.Aliases = {} #aliases BIATCH

		self.Clients = {} #AKA players
		self.curClients = lambda: [int(i[0]) for i in self.getStatus()]
		
	def roundNew(self): pass
	def roundEnd(self): pass
	def matchNew(self):
		self.loadingMap = False
		self.justChangedMap = True
	def matchEnd(self):
		print 'Match over... RED: %s BLUE: %s' % (self.redScore, self.blueScore)
		self.eventFire('GAME_MATCH_END', {'redscore':self.redScore, 'bluescore':self.blueScore})
		self.loadingMap = True
	
	def getClient(self, uid): return self.Clients[uid]
	def getGameType(self):
		r = self.Q.rcon('g_gametype')
		r = re.findall(const.rconGameType, r)
		self.gameData['g_gametype'] = r[0][0]
		return r[0][0]

	def setScores(self, line):
		#Scores: R:11 B:9
		line = line.split(':')
		self.redScore = int(line[2].strip(' B'))
		self.blueScore = int(line[3])
	
	def updatePlayers(self):
		#0: Eduardodias2012 BLUE k:9 d:11 ping:196 200.181.147.46:44453
		r = self.Q.rcon('players')
		r = r.split('\n')
		self.setScores(r[3])
		for i in r[4:]:
			if i != '':
				i = i.split(' ')
				cid = int(i[0].strip(':'))
				obj = self.Clients[cid]
				obj.team = i[2].lower()
				obj.score[0] = i[3].strip('k:')
				obj.score[1] = i[4].strip('d:')

	def dumpUser(self, uid):
		vz = []
		varz = {}
		r = self.Q.rcon('dumpuser %s' % uid)
		r = r.split('\n')
		for i in r[3:]:
			if i != '':
				vz.append([j for j in i.split(' ') if j != ''])
		for i in vz:
			varz[i[0]] = i[1]
		return varz
		 
	def getStatus(self):
		varz = []
		r = self.Q.rcon('status')
		r = r.split('\n')[4:]
		for i in r:
			if i != '':
				i = i.split(' ')
				i = [o for o in i if o != '']
				varz.append(i)
		return varz

	def getCurrentMap(self):
		r = self.Q.rcon('mapname')
		r = const.rconCurrentMap.search(r)
		self.currentMap = r.group(1)
		self.gameData['mapname'] = r.group(1)
		return r.group(1)

	def eventFire(self, event, data): 
		obj = init.events.EVENTS[event](data)
		for i in self.Listeners.keys():
			if i == event:
				for listener in self.Listeners[i]:
					thread.start_new_thread(listener, (obj, time.time()))
				break
		return obj

	def Startup(self):
		#print 'CALLED STARTUP'
		from config import UrTConfig
		self.Q.rcon("say "+self.prefix+" ^3"+"Starting up...")
		
		# Get the PK3s/maps the server has loaded
		pk3s = self.Q.rcon("sv_pakNames").split('"')[3].split()
		for ignore in UrTConfig['ignoremaps']:
			if ignore in pk3s: pk3s.remove(ignore)
		self.maplist += pk3s
		print self.maplist

		status = self.getStatus()
		if status == []: return

		for i in status:
			print i, i[0]
			uid = int(i[0])
			self.Clients[uid] = player.Player(uid, self.dumpUser(uid), init.A)
			if self.Clients[uid].cl_guid != None:
		 		self.pdb.playerUpdate(self.Clients[uid])

		self.updatePlayers() #Set team/score for players
		self.getGameType() #Set g_gametype in self.gamedata
		self.getCurrentMap() #set mapname in self.gamedata

		self.Q.rcon("say "+self.prefix+" ^3"+"Startup complete.")
		print 'STARTUP DONE'