/* Header ReferentialMessageCore : Class to store referential to decode message Copyright (C) 2019 AleaJactaEst This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef REFERENTIAL_MESSAGE_CORE_H #define REFERENTIAL_MESSAGE_CORE_H #include "core/reference.h" #include "core/dictionary.h" #include "modules/bitstream/bitstream.h" #include "modules/debug/debug.h" String get_command_name(uint32_t id); inline uint32_t getPowerOf2(uint32_t v) { // See code : khanat-opennel-code/code/nel/src/misc/common.cpp uint32_t res = 1; uint32_t ret = 0; uint32_t limit = 8*sizeof(uint32_t); while(res < v && ret < limit) { ret ++; res <<= 1; // res *= 2; } return ret; } class ElementReferential : public Reference { GDCLASS(ElementReferential, Reference) private: uint32_t _id; uint32_t _power2; Vector> _children; public: ElementReferential() {_id=0; _power2=0;} ~ElementReferential() {_children.clear();} void set_id(uint32_t id) {_id=id;} void set_size(uint32_t size) {_children.resize(size); _power2=getPowerOf2(size);DBG_PRINT("[" + itos(size) + " /" + itos(_power2) + "]");} int get_size() { return _children.size();} Ref add_child(uint32_t id, uint32_t pos) { Ref tmp; tmp.instance(); tmp->_id = id; _children.set(pos, tmp); tmp.unref(); return _children[pos]; } void show(int level=0, int pos=0); int read_command(Ref msgin); }; class ReferentialMessageCore : public Reference { GDCLASS(ReferentialMessageCore, Reference) protected: static void _bind_methods(); public: enum Command { TARGET_PARTY, TARGET_INVENTORY, TARGET_FOLLOW, TARGET_NO_FOLLOW, CONNECTION_USER_CHAR, CONNECTION_NO_USER_CHAR, CONNECTION_USER_CHARS, CONNECTION_CREATE_CHAR, CONNECTION_SELECT_CHAR, CONNECTION_DELETE_CHAR, CONNECTION_RENAME_CHAR, CONNECTION_ENTER, CONNECTION_READY, CONNECTION_TIME_DATE_SYNCHRO, CONNECTION_ASK_NAME, CONNECTION_VALID_NAME, CONNECTION_CREATE_CHAR_ERROR, CONNECTION_RECONNECT, CONNECTION_SERVER_RECONNECT_OK, CONNECTION_SHARD_ID, CONNECTION_SERVER_QUIT_OK, CONNECTION_SERVER_QUIT_ABORT, CONNECTION_CLIENT_QUIT_REQUEST, CONNECTION_MAIL_AVAILABLE, CONNECTION_GUILD_MESSAGE_AVAILABLE, CONNECTION_PERMANENT_BAN, CONNECTION_UNBAN, CONNECTION_FAR_TP, CONNECTION_RET_MAINLAND, DB_UPD_PLR, DB_UPD_INV, DB_INIT_PLR, DB_INIT_INV, DB_GROUP_UPDATE_BANK, DB_GROUP_INIT_BANK, DB_GROUP_RESET_BANK, POSITION, HARVEST_DEPOSIT, HARVEST_CORPSE, HARVEST_INTERRUPT, HARVEST_CLOSE_TEMP_INVENTORY, TRAINING, JOB_SET_JOB_STATUS, JOB_SWAP_JOB_STATUS, CASTING_BEGIN, CASTING_INTERRUPT, FABER_OPEN, FABER_CLOSE, FABER_EXECUTE, FABER_SET_NUM_ITEM, FABER_START_CREATE, FABER_START_REPAIR, FABER_START_REFINE, FABER_SET_MP_QUALITY, FABER_SET_MP_REFINE, FABER_SET_TOOL, FABER_RESET_TOOL, FABER_INTERRUPT, COMBAT_ENGAGE, COMBAT_DISENGAGE, COMBAT_DEFAULT_ATTACK, COMBAT_ENGAGE_FAILED, COMBAT_VALIDATE_MELEE, COMBAT_PARRY, COMBAT_DODGE, COMBAT_PROTECTED_SLOT, COMBAT_FLYING_ChaScore1_DELTA, COMBAT_FLYING_TEXT_ISE, COMBAT_FLYING_TEXT, STRING_TELL, STRING_FAR_TELL, STRING_CHAT, STRING_CHAT_TEAM, STRING_ADD_DYN_STR, STRING_FILTER, STRING_CHAT_MODE, STRING_CHAT2, STRING_TELL2, STRING_DYN_STRING, STRING_DYN_STRING_GROUP, STRING_AFK_TXT, STUN_STUN, STUN_WAKE_UP, SENTENCE_EXECUTE, SENTENCE_CANCEL, SENTENCE_CANCEL_CURRENT, SENTENCE_CANCEL_ALL, SENTENCE_CLEAR, SENTENCE_MEMORIZE, SENTENCE_FORGET, SENTENCE_EVALUATE, SENTENCE_ADD_BRICK, SENTENCE_REMOVE_BRICK, SENTENCE_START, SENTENCE_STOP, TEAM_JOIN, TEAM_LEAVE, TEAM_INVITATION, TEAM_JOIN_PROPOSAL, TEAM_JOIN_PROPOSAL_DECLINE, TEAM_KICK, TEAM_SET_SUCCESSOR, TEAM_SHARE_OPEN, TEAM_SHARE_VALID_ITEM, TEAM_SHARE_INVALID_ITEM, TEAM_SHARE_VALID, TEAM_SHARE_INVALID, TEAM_SHARE_CLOSE, TEAM_CONTACT_INIT, TEAM_CONTACT_ADD, TEAM_CONTACT_DEL, TEAM_CONTACT_MOVE, TEAM_CONTACT_CREATE, TEAM_CONTACT_STATUS, TEAM_CONTACT_REMOVE, ITEM_DROP, ITEM_PICK_UP, ITEM_PICK_UP_CLOSE, ITEM_SWAP, ITEM_ACTIVATE_SHEATH, ITEM_HARVEST, ITEM_HARVEST_CLOSE, ITEM_GIVE, ITEM_DESTROY, ITEM_EQUIP, ITEM_UNEQUIP, ITEM_TEMP_TO_BAG, ITEM_ALL_TEMP, ITEM_NO_TEMP, ITEM_ENCHANT, ITEM_OPEN_ROOM_INVENTORY, ITEM_CLOSE_ROOM_INVENTORY, ITEM_USE_ITEM, ITEM_STOP_USE_XP_CAT, TP_RESPAWN, TP_BOT, TP_WANTED, TP_DEST, TP_DEST_WITH_SEASON, TP_ACK, TP_CORRECT, DEATH_RESPAWN_POINT, DEATH_ASK_RESPAWN, DEATH_RESPAWN, ANIMALS_BEAST, ANIMALS_MOUNT_ABORT, EXCHANGE_INVITATION, EXCHANGE_CLOSE_INVITATION, EXCHANGE_PROPOSAL, EXCHANGE_ACCEPT_INVITATION, EXCHANGE_DECLINE_INVITATION, EXCHANGE_VALIDATE, EXCHANGE_INVALIDATE, EXCHANGE_END, EXCHANGE_SEEDS, EXCHANGE_ADD, EXCHANGE_REMOVE, DEBUG_WHERE, DEBUG_WHO, DEBUG_REPLY_WHERE, DEBUG_SERVICES, DEBUG_CMD, DEBUG_PING, DEBUG_COUNTER, COMMAND_EMOTE, COMMAND_CUSTOM_EMOTE, COMMAND_WHERE, COMMAND_ADMIN, COMMAND_ADMIN_OFFLINE, COMMAND_REMOTE_ADMIN, COMMAND_REMOTE_ADMIN_ANSWER, COMMAND_SIT, COMMAND_AFK, COMMAND_RANDOM, COMMAND_GUILDMOTD, MP_EVAL_SET_MP, MP_EVAL_SET_MP_LEVEL, MP_EVAL_SET_MARKET, MP_EVAL_EXECUTE, BOTCHAT_NEXT_PAGE_ITEM, BOTCHAT_NEXT_PAGE_MISSION, BOTCHAT_START_TRADE_ITEM, BOTCHAT_START_TRADE_TELEPORT, BOTCHAT_START_TRADE_FACTION, BOTCHAT_START_TRADE_SKILL, BOTCHAT_START_TRADE_PACT, BOTCHAT_START_TRADE_ACTION, BOTCHAT_BUY, BOTCHAT_SELL, BOTCHAT_DESTROY_ITEM, BOTCHAT_REFRESH_TRADE_LIST, BOTCHAT_SET_FILTERS, BOTCHAT_START_CHOOSE_MISSION, BOTCHAT_START_DYNAMIC_MISSION, BOTCHAT_CONTINUE_MISSION, BOTCHAT_VALIDATE_PLAYER_GIFT, BOTCHAT_PICK_MISSION, BOTCHAT_DM_CHOICE, BOTCHAT_DM_ACCEPT, BOTCHAT_START_NEWS, BOTCHAT_START_CREATE_GUILD, BOTCHAT_END, BOTCHAT_FORCE_END, BOTCHAT_START_CHOOSE_DUTY, BOTCHAT_NEXT_PAGE_DUTY, BOTCHAT_DUTY_APPLY, BOTCHAT_DUTY_CANCEL_APPLY, BOTCHAT_START_TRADE_GUILD_OPTIONS, BOTCHAT_BUY_GUILD_OPTION, BOTCHAT_START_GUILD_RESEARCH, BOTCHAT_DESTROY_BUILDING, BOTCHAT_DYNCHAT_OPEN, BOTCHAT_DYNCHAT_CLOSE, BOTCHAT_DYNCHAT_SEND, JOURNAL_INIT_COMPLETED_MISSIONS, JOURNAL_UPDATE_COMPLETED_MISSIONS, JOURNAL_MISSION_ABANDON, JOURNAL_GROUP_MISSION_ABANDON, JOURNAL_ADD_COMPASS, JOURNAL_ADD_COMPASS_BOT, JOURNAL_REMOVE_COMPASS, JOURNAL_REMOVE_COMPASS_BOT, STRING_MANAGER_SET_LANGUAGE, STRING_MANAGER_PHRASE_SEND, STRING_MANAGER_STRING_RQ, STRING_MANAGER_STRING_RESP, STRING_MANAGER_RELOAD_CACHE, GUILD_CREATE, GUILD_ABORT_CREATION, GUILD_OPEN_GUILD_WINDOW, GUILD_INVITATION, GUILD_ACCEPT_INVITATION, GUILD_REFUSE_INVITATION, GUILD_JOIN_PROPOSAL, GUILD_SET_GRADE, GUILD_SET_LEADER, GUILD_KICK_MEMBER, GUILD_TELEPORT, GUILD_ASCENSOR, GUILD_FIRST_ASCENSOR_PAGE, GUILD_NEXT_ASCENSOR_PAGE, GUILD_LEAVE_ASCENSOR, GUILD_QUIT, GUILD_SET_PLAYER_TITLE, GUILD_UPDATE_PLAYER_TITLE, GUILD_USE_FEMALE_TITLES, GUILD_PUT_MONEY, GUILD_TAKE_MONEY, GUILD_OPEN_INVENTORY, GUILD_CLOSE_INVENTORY, OUTPOST_GIVEUP_OUTPOST, OUTPOST_SELECT, OUTPOST_UNSELECT, OUTPOST_DECLARE_WAR_START, OUTPOST_DECLARE_WAR_ACK, OUTPOST_DECLARE_WAR_VALIDATE, OUTPOST_SET_DEF_PERIOD, OUTPOST_SET_SQUAD, OUTPOST_SET_SQUAD_SPAWN, OUTPOST_INSERT_SQUAD, OUTPOST_REMOVE_SQUAD, OUTPOST_SET_SQUAD_CAPITAL, OUTPOST_CHOOSE_SIDE, OUTPOST_SIDE_CHOSEN, OUTPOST_BANISH_PLAYER, OUTPOST_BANISH_GUILD, OUTPOST_BUY_BUILDING, OUTPOST_DESTROY_BUILDING, PHRASE_DELETE, PHRASE_LEARN, PHRASE_MEMORIZE, PHRASE_FORGET, PHRASE_EXECUTE, PHRASE_EXECUTE_CYCLIC, PHRASE_EXECUTE_FABER, PHRASE_DOWNLOAD, PHRASE_BUY, PHRASE_CONFIRM_BUY, PHRASE_BUY_SHEET, PHRASE_CANCEL_LINK, PHRASE_CANCEL_TOP, PHRASE_CANCEL_ALL, PHRASE_CRISTALIZE, PHRASE_EXEC_CYCLIC_ACK, PHRASE_EXEC_NEXT_ACK, ITEM_INFO_GET, ITEM_INFO_SET, ITEM_INFO_REFRESH_VERSION, MISSION_PREREQ_GET, MISSION_PREREQ_SET, MISSION_ENTER_CRITICAL, MISSION_ASK_ENTER_CRITICAL, MISSION_CLOSE_ENTER_CRITICAL, MISSION_WAKE, MISSION_GROUP_WAKE, DUEL_ASK, DUEL_ACCEPT, DUEL_REFUSE, DUEL_ABANDON, DUEL_INVITATION, DUEL_CANCEL_INVITATION, PVP_CHALLENGE_ASK, PVP_CHALLENGE_ACCEPT, PVP_CHALLENGE_REFUSE, PVP_CHALLENGE_ABANDON, PVP_CHALLENGE_INVITATION, PVP_CHALLENGE_CANCEL_INVITATION, PVP_PVP_TAG, PVP_SET_NEUTRAL_ALLEGIANCE, PVP_SET_NEUTRAL_ALLEGIANCE_GUILD, PVP_FACTION_PUSH_FACTION_WAR, PVP_FACTION_POP_FACTION_WAR, PVP_FACTION_FACTION_WARS, ENCYCLOPEDIA_UPDATE, ENCYCLOPEDIA_INIT, USER_BARS, USER_POPUP, EVENT_SET_ITEM_CUSTOM_TEXT, EVENT_DUMMY, TOTEM_BUILD, TOTEM_DUMMY, MODULE_GATEWAY_FEOPEN, MODULE_GATEWAY_GATEWAY_MSG, MODULE_GATEWAY_FECLOSE, SEASON_SET, SEASON_DUMMY, DM_GIFT_BEGIN, DM_GIFT_VALIDATE, RING_MISSION_MISSION_RING_SELECT, RING_MISSION_DSS_DOWN, NPC_ICON_GET_DESC, NPC_ICON_SET_DESC, NPC_ICON_SVR_EVENT_MIS_AVL, NPC_ICON_SET_TIMER, __LAST_ELEMENT }; class ElementHead { private: uint32_t _size; uint32_t _pos; String _name; public: ElementHead() {} ~ElementHead() {} void set_size(uint32_t size){_size = size;} void set_pos(uint32_t pos){_pos = pos;} void set_name(String name){_name = name;} void create(uint32_t pos, uint32_t size,String name) {set_pos(pos);set_size(size);set_name(name);} uint32_t get_size() {return _size;} uint32_t get_pos() {return _pos;} String get_name() {return _name;} }; private: static ReferentialMessageCore *singleton; BitStream _encoder[Command::__LAST_ELEMENT]; Ref _decoder; int get_command(String name); void read_referential_step(Dictionary step, Vector head, Ref root); public: static ReferentialMessageCore * get_singleton(); ReferentialMessageCore() {_decoder.instance();} ~ReferentialMessageCore() {_decoder.unref();} void read_referential(Dictionary dictionary_message); void show(); static void clear_session(); int read_command(Ref msgin); }; VARIANT_ENUM_CAST(ReferentialMessageCore::Command); #endif