def processPacket(self, req): self.runstat.auth_all += 1 if req.code != packet.AccessRequest: self.runstat.auth_drop += 1 raise PacketError('non-AccessRequest packet on authentication socket') reply = req.CreateReply() reply.source = req.source user = store.get_user(req.get_user_name()) if user:self.user_trace.push(user['account_number'],req) # middleware execute for plugin in auth_plugins: self.midware.process(plugin,req=req,resp=reply,user=user) if reply.code == packet.AccessReject: self.auth_delay.add_roster(req.get_mac_addr()) if user:self.user_trace.push(user['account_number'],reply) if self.auth_delay.over_reject(req.get_mac_addr()): return self.auth_delay.add_delay_reject(reply) else: return req.deferred.callback(reply) # send accept reply['Reply-Message'] = 'success!' reply.code=packet.AccessAccept if user:self.user_trace.push(user['account_number'],reply) self.auth_delay.del_roster(req.get_mac_addr()) req.deferred.callback(reply)
def processPacket(self, req): self.runstat.auth_all += 1 if req.code != packet.AccessRequest: self.runstat.auth_drop += 1 raise PacketError( 'non-AccessRequest packet on authentication socket') reply = req.CreateReply() reply.source = req.source user = store.get_user(req.get_user_name()) if user: self.user_trace.push(user['account_number'], req) # middleware execute for plugin in auth_plugins: self.midware.process(plugin, req=req, resp=reply, user=user) if reply.code == packet.AccessReject: self.auth_delay.add_roster(req.get_mac_addr()) if user: self.user_trace.push(user['account_number'], reply) if self.auth_delay.over_reject(req.get_mac_addr()): return self.auth_delay.add_delay_reject(reply) else: return req.deferred.callback(reply) # send accept reply['Reply-Message'] = 'success!' reply.code = packet.AccessAccept if user: self.user_trace.push(user['account_number'], reply) self.auth_delay.del_roster(req.get_mac_addr()) req.deferred.callback(reply)
def add_alien_fleet(self, fleet): ft = fleet['turn'] max_t = store.max_turn() label = '' if ft < max_t: label = '[-%d] '%(max_t - ft,) if max_t - ft > 100: # fleet info is too old return cp = wx.CollapsiblePane(self, label=label+'%s'%fleet['name'], style=wx.CP_DEFAULT_STYLE|wx.CP_NO_TLW_RESIZE) self.sizer.Add(cp) pane = cp.GetPane() u = store.get_user(fleet['user_id']) if u: owner_name = u['name'] else: owner_name = '<unknown>' sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(wx.StaticText(pane, label='owner: %s'%(owner_name,)), 1, wx.EXPAND) for unit in store.iter_objects_list('alien_unit', {'fleet_id':fleet['fleet_id']}): hbox = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(hbox, 1, wx.EXPAND) carp = unit['carapace'] if carp == 0: img = image.getBcImage(unit['class']) else: img = image.getCarapaceImage(carp, unit['color'] ) if img: bitmap = wx.StaticBitmap(pane) bitmap.SetBitmap(img) hbox.Add(bitmap, 1, wx.EXPAND) else: print 'image not found for unit %s, carp %s, color %s'%(unit['unit_id'], int(unit['carapace']), int(unit['color']) ) name = get_unit_name(int(unit['carapace'])) hbox.Add(wx.StaticText(pane, label=name), 1, wx.EXPAND) border = wx.BoxSizer() border.Add(sizer, 1, wx.EXPAND|wx.ALL) pane.SetSizer(border) self.sizer.Layout() self.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnPaneChanged, cp) cp.Expand() cp.Bind(wx.EVT_LEFT_DOWN, self.onFleetSelect) self.fleets[cp] = fleet
def update(self): coord = self.coord self.sizer.DeleteWindows() self.sizer.Add( wx.StaticText(self, wx.ID_ANY, '%s:%s'%coord) ) planet = store.get_object('planet', {'x':coord[0], 'y':coord[1]}) owner = None name = None if not planet: self.sizer.Layout() return if 'o' in planet and planet['o']: self.sizer.Add( wx.StaticText(self, wx.ID_ANY, 'o: %s, e: %s, m: %s, t: %s, s: %s'%(planet['o'], planet['e'], planet['m'], planet['t'], planet['s'])) ) else: pl_sz = store.get_object('planet_size', {'x':coord[0], 'y':coord[1]}) if pl_sz: self.sizer.Add( wx.StaticText(self, wx.ID_ANY, 's: %s'%(pl_sz['s'],)) ) if 'name' in planet and planet['name']: self.sizer.Add( wx.StaticText(self, wx.ID_ANY, planet['name']) ) if 'user_id' not in planet: self.sizer.Layout() return owner_id = planet['user_id'] if not owner_id: self.sizer.Layout() return u = store.get_user(owner_id) if u: owner_name = u['name'] self.sizer.Add( wx.StaticText(self, wx.ID_ANY, owner_name) ) buildings = BuildingsWindows(self) buildings.set_coord(coord) self.sizer.Add(buildings) self.sizer.Layout() self.Bind(event.EVT_BUILD_UNIT, self.on_build_unit) self.Bind(event.EVT_BUILD_CANCEL, self.on_build_cancel)
def processPacket(self, req): self.runstat.acct_all += 1 if req.code != packet.AccountingRequest: self.runstat.acct_drop += 1 raise PacketError('non-AccountingRequest packet on authentication socket') for plugin in acct_before_plugins: self.midware.process(plugin,req=req) user = store.get_user(req.get_user_name()) if user:self.user_trace.push(user['account_number'],req) reply = req.CreateReply() reply.source = req.source if user:self.user_trace.push(user['account_number'],reply) req.deferred.callback(reply) # middleware execute for plugin in acct_plugins: self.midware.process(plugin,req=req,user=user,runstat=self.runstat)
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()
def load_user_data(path): for user in iter_csv_table(path, 'user'): #print 'load user %s'%(user,) turn = int(user['turn']) store_user = store.get_user(user['user_id']) if store_user and 'turn' in store_user: store_user_turn = store_user['turn'] if store_user_turn and int(store_user_turn) >= turn: print 'User %s already exist in db, actual db turn info %s'%(store_user['name'], store_user_turn) continue store.add_user(user) # no need to make it on this level, as there should be only one user store.clear_user_data(user['user_id']) load_csv_table(path, 'open_planet') load_csv_table(path, 'race') load_csv_table(path, 'diplomacy') load_csv_table(path, 'hw') load_csv_table(path, 'flying_fleet') load_csv_table(path, 'alien_flying_fleet') load_csv_table(path, 'user_planet') load_csv_table(path, 'fleet') load_csv_table(path, 'proto') load_csv_table(path, 'proto_action') load_csv_table(path, 'fleet_unit') load_csv_table(path, 'garrison_unit') load_csv_table(path, 'garrison_queue_unit') load_csv_table(path, 'unit') load_csv_table(path, 'proto_action') load_csv_table(path, 'action') store.normalize_user_fleets(user['user_id'])
def fleetMove(self, fleetId, to): act = self.act('move_fleet', pos('move_to', to)+val('fleet_id',fleetId)) # save fleet info fleet = store.get_object('fleet', {'fleet_id':fleetId}) speed, rng = store.get_fleet_speed_range(fleetId) cur_pos = util.get_coord(fleet) dist = util.distance(to, cur_pos) # cannot move this far if dist > rng: print 'Error - attempt to move fleet %s to distance %s which is longer then fleet max range %s'%(fleetId, dist, rng) turns = int(math.ceil(dist / speed)) u = store.get_user(fleet['user_id']) cur_turn = u['turn'] store.add_pending_action(self.act_id, 'fleet', 'erase', {'fleet_id':fleetId}) store.add_pending_action(self.act_id, 'flying_fleet', 'insert', {'x':to[0], 'y':to[1], 'user_id':self.user_id, 'id':fleetId, 'from_x':fleet['x'], 'from_y':fleet['y'], 'arrival_turn':turns + cur_turn}) #db.add_pending_action(self.act_id, db.Db.FLEET, 'erase', ['id=%s'%(fleetId,)]) #db.add_pending_action(self.act_id, db.Db.FLYING_FLEET, 'insert', {'x':to[0], 'y':to[1], 'owner_id':self.user_id, 'id':fleetId, 'from_x':fleet['x'], 'from_y':fleet['y'], 'arrival_turn':turns + db.getTurn()}) return act
def add_fleet(self, fleet): nm = '' if 'arrival_turn' in fleet: nm = '[%d] '%(fleet['arrival_turn'] - store.max_turn(),) nm += fleet['name'] cp = wx.CollapsiblePane(self, label=nm, style=wx.CP_DEFAULT_STYLE|wx.CP_NO_TLW_RESIZE) self.sizer.Add(cp) pane = cp.GetPane() u = store.get_user(fleet['user_id']) if u: owner_name = u['name'] else: owner_name = '<unknown>' sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(wx.StaticText(pane, label='owner: %s'%(owner_name,)), 1, wx.EXPAND) speed, rng = store.get_fleet_speed_range(fleet['fleet_id']) if speed and rng: sizer.Add(wx.StaticText(pane, label='%0.2f / %0.2f'%(speed, rng)), 1, wx.EXPAND) #can we contrl the fleet? is_controlled = 'login' in u and u['login'] in config.users if is_controlled and rng >= 1 and (not 'in_transit' in fleet or fleet['in_transit']==0): jump_button = wx.ToggleButton(pane, label='jump') jump_button.fleet_id = fleet['fleet_id'] sizer.Add(jump_button, 1, wx.EXPAND) self.Bind(wx.EVT_TOGGLEBUTTON, self.on_jump, jump_button) #else: # print 'user %s not controllable'%(u,) for unit in store.get_fleet_units(fleet['fleet_id']): hbox = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(hbox, 1, wx.EXPAND) proto = store.get_object('proto', {'proto_id':unit['proto_id']}) if not proto: print 'Prototype not found for %s'%(unit,) continue obj_carp = int(unit['proto_id']), int(proto['carapace']), int(proto['color']) if is_controlled: planet = store.get_object('planet', {'x':self.coord[0], 'y':self.coord[1]}) inhabited = False if planet and planet['user_id'] and int(planet['user_id']) > 0: inhabited = True # get unit actions ( colony, kill-people ) if not inhabited: for action_type in [action.Action.COLONY_COLONISE, action.Action.ARC_COLONISE, action.Action.OUTPOST_COLONISE]: action_colonize = store.get_object('proto_action', {'proto_id':proto['proto_id'], 'proto_action_id':action_type}) if action_colonize: c_action = store.get_object('action', {'unit_id':unit['unit_id']}) if c_action: # already colonizing cancel_button = wx.Button(pane, label='Cancel colonize %s'%(action.get_colony_population(action_type))) cancel_button.cancel_action = u['user_id'], unit['unit_id'], c_action['cancel_id'] self.Bind(wx.EVT_BUTTON, self.on_cancel_action, cancel_button) sizer.Add( cancel_button , 1, wx.EXPAND ) else: colonize_button = wx.Button(pane, label='Colonize %s'%(action.get_colony_population(action_type))) colonize_button.action = action_type, unit['unit_id'], fleet['fleet_id'], self.coord, u['user_id'] self.Bind(wx.EVT_BUTTON, self.on_store_action, colonize_button) sizer.Add( colonize_button , 1, wx.EXPAND ) if inhabited and planet['user_id'] != u['user_id']: #TODO: check if our mult, or ally, and notify user about it action_kill_people = store.get_object('proto_action', {'proto_id':proto['proto_id'], 'proto_action_id':action.Action.KILL_PEOPLE}) if action_kill_people: c_action = store.get_object('action', {'unit_id':unit['unit_id']}) if c_action: # already colonizing cancel_button = wx.Button(pane, label='Cancel kill people') cancel_button.cancel_action = u['user_id'], unit['unit_id'], c_action['cancel_id'] self.Bind(wx.EVT_BUTTON, self.on_cancel_action, cancel_button) sizer.Add( cancel_button , 1, wx.EXPAND ) else: colonize_button = wx.Button(pane, label='Kill people') colonize_button.action = action.Action.KILL_PEOPLE, unit['unit_id'], fleet['fleet_id'], self.coord, u['user_id'] self.Bind(wx.EVT_BUTTON, self.on_store_action, colonize_button) sizer.Add( colonize_button , 1, wx.EXPAND ) img = image.get_image( int(unit['proto_id']), int(proto['carapace']), int(proto['color']) ) if img: bitmap = wx.StaticBitmap(pane) bitmap.SetBitmap(img) hbox.Add(bitmap, 1, wx.EXPAND) #else: # print 'image not found for unit %s, bc %s, carp %s, color %s'%(unit['unit_id'], int(unit['proto_id']), int(proto['carapace']), int(proto['color']) ) name = proto['name'] if not name: name = get_unit_name(int(proto['carapace'])) hbox.Add(wx.StaticText(pane, label=name), 1, wx.EXPAND) border = wx.BoxSizer() border.Add(sizer, 1, wx.EXPAND|wx.ALL) pane.SetSizer(border) self.sizer.Layout() self.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnPaneChanged, cp) cp.Expand() cp.Bind(wx.EVT_LEFT_DOWN, self.onFleetSelect) self.fleets[cp] = fleet
def drawPlanet(self, dc, planet): planetPos = objPos(planet) rx,ry = self.relPos(planetPos) sz = 1 if 's' in planet and planet['s']: sz = int(planet['s']) col = None owner_id = 0 width = 1 if 'user_id' in planet and planet['user_id']: owner_id = planet.get('user_id', 0) if not owner_id or owner_id == 0: color = 'black' brush_type = None if self.show_good_planets: li = self.draw_good_planet(dc, planet) if li: color = li[0] width = 2 else: brush_type = 1 u = store.get_user(owner_id) if self.selected_user_id == owner_id: color = 'orange' elif not u: color='black' brush_type=None elif 'login' in u and u['login']:# and len(u['login']>0): color = 'red' else: color = 'green' dc.SetPen(wx.Pen(color, width=width)) brush = wx.Brush(color) if not brush_type or (owner_id in self.users and self.users[owner_id]==False): brush.SetStyle(wx.TRANSPARENT) dc.SetBrush(brush) dc.DrawCircle(rx, ry, self.relSize(sz)) return dc.SetPen(wx.Pen(colour='black', width=1)) if not owner_id : owner_id = 0 else: owner_id = int(owner_id) if owner_id == self.selected_user_id: col = config.options['map']['planet_selected_user_color'] dc.SetPen(wx.Pen(colour=col, width=1)) dc.SetBrush(wx.Brush(col)) else: user_open_planet = db.db.get_object(db.Db.OPEN_PLANET, {'=':{'x':planet['x'], 'y':planet['y'], 'user_id':self.selected_user_id}}) if user_open_planet: col = 'blue' #open else: col = getOwnerColor(owner_id) brush = wx.Brush(col) dc.SetPen(wx.Pen(colour=col, width=1)) if owner_id == 0: brush.SetStyle(wx.TRANSPARENT) dc.SetBrush(brush) if self.cell_size == 1: dc.DrawPoint(rx, ry) else: if self.planet_filter_ptr and self.planet_filter_ptr.is_planet_shown(planetPos): dc.SetBrush(wx.Brush('red')) dc.DrawCircle(rx, ry, self.relSize(sz)) #dc.FloodFill(rx, ry, col) dc.SetBrush(wx.Brush('white'))