Exemple #1
0
	def cancel_jump(self, evt):

		turn = db.getTurn()
		out_dir = os.path.join(util.getTempDir(), config.options['data']['raw-dir'])
		util.assureDirClean(out_dir)

		for acc in config.accounts():
			user_id = int(acc['id'])
			self.pending_actions.user_id = user_id
			
			fleets = []
			fleet_flt = ['owner_id=%s'%(user_id,)]
			
			fleet_name = None #unicode('Fleet')
			# can also filter fleets by names
			#TODO: beware escapes
			if fleet_name:
				fleet_flt.append( 'name="%s"'%(fleet_name,) ) 
			for fleet in db.flyingFleets(turn, fleet_flt):
				#print 'found fleet %s'%(fleet,)
				if fleet['in_transit'] != 0:
					continue
				print 'fleet %s can be stopped'%(fleet,)
			
				self.pending_actions.cancelJump(fleet['id'])
			
			self.perform_actions()
Exemple #2
0
	def perform_next_action(self):
		if self.actions_queue==[]:
			return
		login, acts = self.actions_queue[0]
		del self.actions_queue[0]
		
		out_dir = os.path.join(util.getTempDir(), config.options['data']['raw-dir'])
		util.assureDirClean(out_dir)

		l = loader.AsyncLoader()
		l.sendActions(self, login, acts, out_dir)
		l.start()
Exemple #3
0
	def onUpdateGeo(self, event):
		'download and process info from server'
		import loader
		l = loader.AsyncLoader()
		
		out_dir = os.path.join(util.getTempDir(), config.options['data']['raw-dir'])
		util.assureDirClean(out_dir)
		for acc in config.accounts():
			log.info('requesting user %s info'%(acc['login'],))
			d = os.path.join(util.getTempDir(), 'raw_data') if not out_dir else out_dir
			l.getDcData(self, acc['login'], 'known_planets', d)
		l.start()
Exemple #4
0
	def onUpdate(self, event):
		'download and process info from server'
		import loader
		l = loader.AsyncLoader()
		
		out_dir = os.path.join(util.getTempDir(), config.options['data']['raw-dir'])
		util.assureDirClean(out_dir)
		for acc in config.accounts():
			if self.command_selected_user and int(acc['id']) != self.map.selected_user_id:
				continue
			log.info('requesting user %s info'%(acc['login'],))
			l.getUserInfo(self, acc['login'], out_dir)
		l.start()
Exemple #5
0
	def onUpdate(self, event):
		'download and process info from server'
		l = loader.AsyncLoader()
		
		out_dir = os.path.join(util.getTempDir(), config.options['data']['raw-dir'])
		util.assureDirClean(out_dir)
		
		for acc in config.accounts():
			if self.command_selected_user and int(acc['id']) != self.map.selected_user_id:
				continue
			log.info('requesting user %s info'%(acc['login'],))
			for msg_type in ['all', 'known_planets', 'fleetsmessages']:
				l.getDcData(self, acc['login'], msg_type, out_dir)
		l.start()
Exemple #6
0
def processAllUnpacked():
	xml_dir = os.path.join(util.getTempDir(), config.options['data']['raw-xml-dir'])
	util.assureDirClean(xml_dir)
	log.debug('processing all found data at %s'%(xml_dir,))
	at_least_one = False
	try:
		for file in os.listdir(xml_dir):
			if not file.endswith('.xml'):
				continue
			log.debug('loading %s'%(file,))
			p = os.path.join(xml_dir, file)
			load_xml( p )
			at_least_one = True
		if at_least_one:
			save_load.save()
	except OSError, e:
		log.error('unable to load raw data: %s'%(e,))
Exemple #7
0
def load_sync_data():
	sync_path = config.options['data']['sync_path']
	if not sync_path or sync_path == '':
		print 'sync path not specified, sync not performed'
		return
		
	turns_path = os.path.join(sync_path, 'turns')
	if not os.path.exists(turns_path):
		print 'sync path %s not exist'%(turns_path,)
		return
	available_turns = []
	for f in os.listdir(turns_path):
		available_turns.append(int(f))
	
	if not available_turns:
		print 'no sync data found in %s'%(turns_path,)
		return
	
	load_turn = db.getTurn()
	if not load_turn in available_turns:
		load_turn = max(available_turns)
	
	nick = get_user_nickname()
	
	turn_path = os.path.join(turns_path, str(load_turn))
	for d in os.listdir(turn_path):
		if d == nick:
			continue
		acc_path = os.path.join(turn_path, d)
		print 'load %s turn: %s'%(d, load_turn)
		db.prepareTurn(load_turn)
		
		# do load
		unpack_dir = os.path.join(os.path.join(os.path.join( util.getTempDir(), 'unpack_sync' ), d), str(load_turn))
		util.assureDirClean(unpack_dir)
		for gz_file in os.listdir(acc_path):
			outf = os.path.join(unpack_dir, gz_file)
			if outf.endswith('.gz'):
				outf = outf[:-len('.gz')]
			util.unpack(os.path.join(acc_path, gz_file), outf)
			table_name = os.path.basename(outf)[:-len('.csv')]
			if table_name == db.Db.PROTO or table_name == db.Db.PROTO_ACTION or table_name == db.Db.OPEN_PLANET or table_name == db.Db.USER:
				loadTable(table_name, None, load_turn, None, os.path.dirname(outf))
			else:
				loadTable(table_name, load_turn, None, None, os.path.dirname(outf))
Exemple #8
0
	def do_perform(self):
		out_dir = os.path.join(util.getTempDir(), config.options['data']['raw-dir'])
		util.assureDirClean(out_dir)
		log.debug('preparing directory %s to load action result'%(out_dir,))

		l = loader.AsyncLoader()
		at_leat_one = False
		for user_id, acts in self.stored_actions.iteritems():
			if len(acts) == 0:
				continue
			user = store.get_user(user_id)
			if 'login' in user and user['login']:
				log.debug('Storing actions for user %s'%(user_id,))
				l.sendActions(self, config.get_user_login(user['user_id']), self.prepare_actions_request(user_id), out_dir)
				at_leat_one = True
		
		# clear action list
		self.remove_action_items()
		self.stored_actions = {}
		
		if at_leat_one:
			l.start()
Exemple #9
0
	def onExploreGeoAll(self, _):
		'upload pending events on server'
		
		turn = db.getTurn()
		explore_owned_planets = True
		
		out_dir = os.path.join(util.getTempDir(), config.options['data']['raw-dir'])
		util.assureDirClean(out_dir)
		for acc in config.accounts():
			log.info('requesting user %s info'%(acc['login'],))
			# find if there is any explore-capable fleets over unexplored planets
			# or simply tell explore to every unit =))) game server will do the rest
			
			#1. find all fleets above empty planets
			
			# get fleet position, check if planet geo is unknown
			fleet_planet = {}
			pl = {}
			
			for fleet in db.fleets(turn, ['owner_id=%s'%(acc['id'],)] ):
				print 'got fleet %s'%(fleet,)
				coord = get_coord(fleet)
				cfilter = filter_coord(coord)
				for planet in db.planets(turn, cfilter):
					# skip if occupied
					if planet['owner_id'] and not explore_owned_planets:
						continue
					if planet['o'] and planet['e'] and planet['m'] and planet['t']:
						continue
					#check holes and stars
					if not db.is_planet(coord):
						print '%s not a planet'%(coord,)
						continue
					if not coord in pl:
						pl[coord] = set()
					pl[ coord ].add(fleet['id'])
					print 'planet unexplored %s'%(planet,)
			
			acts = {}
			
			# get all fleet units, check if explore capable
			for coord, planet_fleets in pl.iteritems():
				for fleet_id in planet_fleets:
					for unit in db.units(turn, ['fleet_id=%s'%(fleet_id,)]):
						print '%s %s unit %s'%(coord, fleet_id, unit)
						# ok unit
						bc = unit['class']
						
						#for proto in db.prototypes(['id=%s'%(bc,)]):
						#	print 'proto %s'%(proto,)

						#type 1 probably geo explore
						for act in db.proto_actions(['proto_id=%s'%(bc,), 'type=1']):
							#print 'ACTION: %s %s %s'%(coord, bc, act)
							acts[coord] = unit['id']

			self.pending_actions.user_id = int(acc['id'])
			#self.pendingActions[int(acc['id'])] = actions
			#hw_planet = db.getUserHw(acc['id'])
			#actions.createNewFleet(hw_planet, 'a_new_shiny_fleet')
			
			at_least_one = False
			for coord, unit_id in acts.iteritems():
				print 'explore (%s) %s'%(coord, unit_id)
				self.pending_actions.explore_planet( coord, unit_id )
				at_least_one = True
			
			if at_least_one:
				self.perform_actions()
Exemple #10
0
	def onExploreGeoAll(self, _):
		'upload pending events on server'
		
		explore_owned_planets = True
		
		out_dir = os.path.join(util.getTempDir(), config.options['data']['raw-dir'])
		util.assureDirClean(out_dir)
		for acc in config.accounts():
			if not 'id' in acc:
				continue
			user_id = int(acc['id'])
				
			log.info('requesting user %s info'%(acc['login'],))
			# find if there is any explore-capable fleets over unexplored planets
			# or simply tell explore to every unit =))) game server will do the rest
			
			#1. find all fleets above empty planets
			
			# get fleet position, check if planet geo is unknown
			fleet_planet = {}
			pl = {}
			
			for fleet in store.iter_objects_list('fleet', {'user_id':acc['id']} ):
				#print 'got fleet %s'%(fleet,)
				coord = get_coord(fleet)
				
				if coord in pl:
					pl[coord].add(fleet['fleet_id'])
					continue

				planet = store.get_object('planet', {'x':coord[0], 'y':coord[1]})
				#check holes and stars
				if not planet:
					continue
				
				# check if already explored
				if 'o' in planet and planet['o']:
					continue
				
				if not coord in pl:
					pl[coord] = set()
				pl[ coord ].add(fleet['fleet_id'])
				#print 'Add to exploration list planet %s'%(planet,)
			
			acts = {}
			
			# get all fleet units, check if explore capable
			for coord, planet_fleets in pl.iteritems():
				for fleet_id in planet_fleets:
					for unit in store.get_fleet_units(fleet_id):
						#print '%s %s unit %s'%(coord, fleet_id, unit)
						# ok unit
						bc = unit['proto_id']
						
						#for proto in db.prototypes(['id=%s'%(bc,)]):
						#	print 'proto %s'%(proto,)

						#type 1 probably geo explore
						action_geo_explore = store.get_object('proto_action',{'proto_id':bc, 'proto_action_id':request.RequestMaker.GEO_EXPLORE})
						if action_geo_explore:
							acts[coord] = unit['unit_id']
							break
					# no need to request more then one explore of a single planet
					if coord in acts:
						break

			self.pending_actions.user_id = int(acc['id'])
			#self.pendingActions[int(acc['id'])] = actions
			#hw_planet = db.getUserHw(acc['id'])
			#actions.createNewFleet(hw_planet, 'a_new_shiny_fleet')
			
			at_least_one = False
			for coord, unit_id in acts.iteritems():
				fleet_unit = store.get_object('fleet_unit', {'unit_id':unit_id})
				self.actions.add_action(action.ActionStore(user_id, unit_id, fleet_unit['fleet_id'], coord, action.Action.GEO_EXPLORE))
				#self.pending_actions.explore_planet( coord, unit_id )
				at_least_one = True
			
			if at_least_one:
				self.perform_actions()