def handle_client_connected_message(self, msg): if isinstance(msg.peer, Player): unique_id = utils.first_unused_number_above( self.players.keys(), utils.MIN_UNVERIFIED_ID, utils.MAX_UNVERIFIED_ID) player = msg.peer player.friends.connect_to_social_network(self.social_network) player.unique_id = unique_id player.login_server = self player.complement_address_pair(self.address_pair) player.set_state(UnauthenticatedState) self.players[unique_id] = player elif isinstance(msg.peer, GameServer): server_id = utils.first_unused_number_above( self.all_game_servers().keys(), 1) game_server = msg.peer game_server.server_id = server_id game_server.match_id = server_id + 10000000 game_server.game_setting_mode = None game_server.login_server = self self.game_servers[server_id] = game_server self.logger.info(f'{game_server}: added') elif isinstance(msg.peer, AuthCodeRequester): pass else: assert False, "Invalid connection message received"
def add_account(self, login_name, authcode): login_name = login_name.lower() if login_name in self.accounts: unique_id = self.accounts[login_name].unique_id else: used_ids = {account.unique_id for account in self.accounts.values()} unique_id = first_unused_number_above(used_ids, 1) self.accounts[login_name] = AccountInfo(unique_id, login_name, authcode)
def add(self, receiver, seconds_from_now, callback_func): callback_id = first_unused_number_above(self.callbacks.keys(), 0) self.callbacks[callback_id] = { 'receiver_id': id(receiver), 'callback_func': callback_func } gevent_spawn_later('pending callback for %s' % receiver, seconds_from_now, self._post_callback, callback_id)