def _add_required_fields(self, player): for required_field in PLAYER_SPAWN_FIELDS: value = player.get(required_field) if value is None: LOG.error("A required field for player spawning is not set.") LOG.error(str(required_field)) continue self.add_field(required_field, value)
def _try_handle_packet(self, packet): try: self._handle_packet(packet) except Exception as exc: LOG.error("{}: uncaught exception in packet handler:".format( type(self).__name__ )) LOG.error(str(exc)) traceback.print_tb(exc.__traceback__) self.state = self.MAIN_ERROR_STATE
def process(self): if "worldport_ack_pending" in self.conn.shared_data: LOG.debug( "Received expected " + str(OpCode.MSG_MOVE_WORLDPORT_ACK) ) del self.conn.shared_data["worldport_ack_pending"] return None, None else: LOG.error( "Received unexpected " + str(OpCode.MSG_MOVE_WORLDPORT_ACK) ) return self.conn.MAIN_ERROR_STATE, None
def _open_login_server_socket(self): """ Open the login server socket, or set it to None if it couldn't connect properly. """ self.login_server_socket = socket.socket() login_server_address = ( CONFIG["login"]["realm_conn_hostname"] , int(CONFIG["login"]["realm_conn_port"]) ) try: self.login_server_socket.connect(login_server_address) except ConnectionError as exc: LOG.error("Couldn't join login server! " + str(exc)) self.login_server_socket = None
def _try_create_char(char_values, consts): char_data = None with DB.atomic() as transaction: try: char_data = _CharacterCreator._create_char(char_values, consts) except PeeweeException as exc: LOG.error("An error occured while creating character:") LOG.error(str(exc)) transaction.rollback() return None return char_data
def delete_char(guid): """ Try to delete character and all associated data from the database. Return 0 on success, 1 on error. """ with DB.atomic() as transaction: try: _CharacterDestructor._delete_char(guid) except PeeweeException as exc: LOG.error("An error occured while deleting character:") LOG.error(str(exc)) transaction.rollback() return 1 return 0
def _add_default_spells(char_data, consts): spells_id = consts["class"]["spells"] for spell_id in spells_id: try: Spell.create( character = char_data, ident = spell_id.value ) except PeeweeException as exc: LOG.error("Couldn't add spell {} for char {}".format( spell_id.name, char_data.guid )) LOG.error(str(exc))
def add(self, field, value): """ Add a field and its value to the UpdateBlocks. """ try: field_type = FIELD_TYPE_MAP[field] except KeyError: LOG.error("No type associated with " + str(field)) LOG.error("Object not updated.") return field_struct = self.FIELD_BIN_MAP[field_type] field_index = UpdateBlocksBuilder._get_field_index(field) self._set_field_mask_bits(field_index, field_struct) self._set_field_value(field_index, field_struct, value) assert len(self.mask_blocks) < self.HARD_MASK_BLOCKS_LIMIT
def save_player(self, player): char_data = CharacterManager.get_char_data(player.guid) with DB.atomic() as transaction: try: ObjectManager.save_object_coords(player, char_data.position) ObjectManager.save_object_fields(player, char_data) _UnitManager.save_unit_fields(player, char_data) _PlayerManager.save_player_fields(player, char_data) char_data.save() except PeeweeException as exc: LOG.error("An error occured while creating character:") LOG.error(str(exc)) transaction.rollback() return None
def _add_default_skills(char_data, consts): skills_id = consts["class"]["skills"] for skill_id in skills_id: values = skills_id[skill_id] max_values = SKILL_MAX_LEVELS[skill_id] try: Skill.create( character = char_data, ident = skill_id.value, level = values[0], stat_level = values[1], max_level = max_values[0], max_stat_level = max_values[1] ) except PeeweeException as exc: LOG.error("Couldn't add skill {} for char {}".format( skill_id.name, char_data.guid )) LOG.error(str(exc))
def add_field(self, field, value): """ If this update packet can hold update fields, add it. """ if not self.has_fields: LOG.error("Tried to add an update field to a wrong update packet.") return self.blocks_builder.add(field, value)
def log_error(operation, exception): LOG.error("A problem occured during operation '{}'".format(operation)) LOG.error("Is the MySQL server started?") LOG.error("Is the Durator user created? (see database creds)") LOG.error("Does it have full access to the durator database?") LOG.error(str(exception))