From 0f9ec2061c4ad6157c3186f1cab9c4d8558980b5 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 29 May 2015 14:30:20 +0300 Subject: Add strong typed int type BeingId. --- src/net/ea/beinghandler.cpp | 30 ++++++++++++++++-------------- src/net/ea/beinghandler.h | 4 ++-- src/net/ea/buysellhandler.cpp | 6 +++--- src/net/ea/buysellhandler.h | 4 +++- src/net/ea/chathandler.cpp | 2 +- src/net/ea/gamehandler.cpp | 6 +++--- src/net/ea/gamehandler.h | 4 +++- src/net/ea/guildhandler.cpp | 4 ++-- src/net/ea/inventoryhandler.h | 4 ++-- src/net/ea/itemhandler.cpp | 4 ++-- src/net/ea/loginhandler.cpp | 2 +- src/net/ea/npchandler.cpp | 14 +++++++------- src/net/ea/partyhandler.cpp | 4 ++-- src/net/ea/token.h | 5 +++-- 14 files changed, 50 insertions(+), 43 deletions(-) (limited to 'src/net/ea') diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index 51771fb30..ab32a3f84 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -43,16 +43,17 @@ namespace Ea { -int BeingHandler::mSpawnId = 0; +BeingId BeingHandler::mSpawnId = BeingId_zero; bool BeingHandler::mSync = false; BeingHandler::BeingHandler(const bool enableSync) { mSync = enableSync; - mSpawnId = 0; + mSpawnId = BeingId_zero; } -Being *BeingHandler::createBeing(const int id, const int16_t job) +Being *BeingHandler::createBeing(const BeingId id, + const int16_t job) { if (!actorManager) return nullptr; @@ -93,7 +94,7 @@ void BeingHandler::processBeingRemove(Net::MessageIn &msg) // A being should be removed or has died - const int id = msg.readInt32("being id"); + const BeingId id = msg.readBeingId("being id"); Being *const dstBeing = actorManager->findBeing(id); if (!dstBeing) { @@ -140,9 +141,9 @@ void BeingHandler::processSkillDamage(Net::MessageIn &msg) const int id = msg.readInt16("skill id"); Being *const srcBeing = actorManager->findBeing( - msg.readInt32("src being id")); + msg.readBeingId("src being id")); Being *const dstBeing = actorManager->findBeing( - msg.readInt32("dst being id")); + msg.readBeingId("dst being id")); msg.readInt32("tick"); msg.readInt32("src speed"); msg.readInt32("dst speed"); @@ -167,9 +168,9 @@ void BeingHandler::processBeingAction(Net::MessageIn &msg) } Being *const srcBeing = actorManager->findBeing( - msg.readInt32("src being id")); + msg.readBeingId("src being id")); Being *const dstBeing = actorManager->findBeing( - msg.readInt32("dst being id")); + msg.readBeingId("dst being id")); msg.readInt32("tick"); const int srcSpeed = msg.readInt32("src speed"); @@ -253,7 +254,8 @@ void BeingHandler::processBeingEmotion(Net::MessageIn &msg) return; } - Being *const dstBeing = actorManager->findBeing(msg.readInt32("being id")); + Being *const dstBeing = actorManager->findBeing( + msg.readBeingId("being id")); if (!dstBeing) { BLOCK_END("BeingHandler::processBeingEmotion") @@ -283,7 +285,7 @@ void BeingHandler::processNameResponse(Net::MessageIn &msg) return; } - const int beingId = msg.readInt32("being id"); + const BeingId beingId = msg.readBeingId("being id"); Being *const dstBeing = actorManager->findBeing(beingId); if (dstBeing) @@ -344,7 +346,7 @@ void BeingHandler::processPlayerStop(Net::MessageIn &msg) return; } - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); if (mSync || id != localPlayer->getId()) { @@ -409,7 +411,7 @@ void BeingHandler::processPvpMapMode(Net::MessageIn &msg) void BeingHandler::processPvpSet(Net::MessageIn &msg) { BLOCK_START("BeingHandler::processPvpSet") - const int id = msg.readInt32("being id"); + const BeingId id = msg.readBeingId("being id"); const int rank = msg.readInt32("rank"); msg.readInt32("num"); if (actorManager) @@ -431,7 +433,7 @@ void BeingHandler::processNameResponse2(Net::MessageIn &msg) } const int len = msg.readInt16("len"); - const int beingId = msg.readInt32("account ic"); + const BeingId beingId = msg.readBeingId("account ic"); const std::string str = msg.readString(len - 8, "name"); Being *const dstBeing = actorManager->findBeing(beingId); if (dstBeing) @@ -481,7 +483,7 @@ void BeingHandler::processBeingMove3(Net::MessageIn &msg) const int len = msg.readInt16("len") - 14; Being *const dstBeing = actorManager->findBeing( - msg.readInt32("being id")); + msg.readBeingId("being id")); if (!dstBeing) { BLOCK_END("BeingHandler::processBeingMove3") diff --git a/src/net/ea/beinghandler.h b/src/net/ea/beinghandler.h index ca575e506..632381fb3 100644 --- a/src/net/ea/beinghandler.h +++ b/src/net/ea/beinghandler.h @@ -36,7 +36,7 @@ class BeingHandler notfinal : public Net::BeingHandler protected: explicit BeingHandler(const bool enableSync); - static Being *createBeing(const int id, + static Being *createBeing(const BeingId id, const int16_t job) A_WARN_UNUSED; static void setSprite(Being *const being, const unsigned int slot, @@ -71,7 +71,7 @@ class BeingHandler notfinal : public Net::BeingHandler static void processBeingMove3(Net::MessageIn &msg); // Should we honor server "Stop Walking" packets - static int mSpawnId; + static BeingId mSpawnId; static bool mSync; }; diff --git a/src/net/ea/buysellhandler.cpp b/src/net/ea/buysellhandler.cpp index e0f686cad..0e939c217 100644 --- a/src/net/ea/buysellhandler.cpp +++ b/src/net/ea/buysellhandler.cpp @@ -42,12 +42,12 @@ namespace Ea { -int BuySellHandler::mNpcId = 0; +BeingId BuySellHandler::mNpcId = BeingId_zero; BuyDialog *BuySellHandler::mBuyDialog = nullptr; BuySellHandler::BuySellHandler() { - mNpcId = 0; + mNpcId = BeingId_zero; mBuyDialog = nullptr; } @@ -55,7 +55,7 @@ void BuySellHandler::processNpcBuySellChoice(Net::MessageIn &msg) { if (!BuySellDialog::isActive()) { - mNpcId = msg.readInt32("npc id"); + mNpcId = msg.readBeingId("npc id"); BuySellDialog *const dialog = new BuySellDialog(mNpcId); dialog->postInit(); } diff --git a/src/net/ea/buysellhandler.h b/src/net/ea/buysellhandler.h index e972b1208..1667332bb 100644 --- a/src/net/ea/buysellhandler.h +++ b/src/net/ea/buysellhandler.h @@ -23,6 +23,8 @@ #ifndef NET_EA_BUYSELLHANDLER_H #define NET_EA_BUYSELLHANDLER_H +#include "enums/simpletypes/beingid.h" + #include "net/buysellhandler.h" class BuyDialog; @@ -44,7 +46,7 @@ class BuySellHandler notfinal : public Net::BuySellHandler static void processNpcBuyResponse(Net::MessageIn &msg); - static int mNpcId; + static BeingId mNpcId; static BuyDialog *mBuyDialog; }; diff --git a/src/net/ea/chathandler.cpp b/src/net/ea/chathandler.cpp index a08b2b9e6..554276d17 100644 --- a/src/net/ea/chathandler.cpp +++ b/src/net/ea/chathandler.cpp @@ -148,7 +148,7 @@ void ChatHandler::processMVPEffect(Net::MessageIn &msg) { BLOCK_START("ChatHandler::processMVPEffect") // Display MVP player - const int id = msg.readInt32("being id"); + const BeingId id = msg.readBeingId("being id"); if (localChatTab && actorManager && config.getBoolValue("showMVP")) { const Being *const being = actorManager->findBeing(id); diff --git a/src/net/ea/gamehandler.cpp b/src/net/ea/gamehandler.cpp index 31c487921..583ef3409 100644 --- a/src/net/ea/gamehandler.cpp +++ b/src/net/ea/gamehandler.cpp @@ -42,13 +42,13 @@ namespace Ea { std::string GameHandler::mMap; -int GameHandler::mCharID = 0; +BeingId GameHandler::mCharID = BeingId_zero; GameHandler::GameHandler() : Net::GameHandler() { mMap.clear(); - mCharID = 0; + mCharID = BeingId_zero; } void GameHandler::who() const @@ -92,7 +92,7 @@ void GameHandler::processMapQuitResponse(Net::MessageIn &msg) void GameHandler::clear() { mMap.clear(); - mCharID = 0; + mCharID = BeingId_zero; } void GameHandler::initEngines() const diff --git a/src/net/ea/gamehandler.h b/src/net/ea/gamehandler.h index 4ecc85692..7ff3a5ca9 100644 --- a/src/net/ea/gamehandler.h +++ b/src/net/ea/gamehandler.h @@ -23,6 +23,8 @@ #ifndef NET_EA_GAMEHANDLER_H #define NET_EA_GAMEHANDLER_H +#include "enums/simpletypes/beingid.h" + #include "net/gamehandler.h" namespace Net @@ -62,7 +64,7 @@ class GameHandler notfinal : public Net::GameHandler protected: static std::string mMap; - static int mCharID; // < Saved for map-server switching + static BeingId mCharID; // < Saved for map-server switching }; } // namespace Ea diff --git a/src/net/ea/guildhandler.cpp b/src/net/ea/guildhandler.cpp index 13317699b..96956b2d9 100644 --- a/src/net/ea/guildhandler.cpp +++ b/src/net/ea/guildhandler.cpp @@ -186,7 +186,7 @@ void GuildHandler::processGuildMemberList(Net::MessageIn &msg) int totalNum = 0; for (int i = 0; i < count; i++) { - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); const int charId = msg.readInt32("char id"); msg.readInt16("hair"); msg.readInt16("hair color"); @@ -290,7 +290,7 @@ void GuildHandler::processGuildPositionChanged(Net::MessageIn &msg) void GuildHandler::processGuildMemberPosChange(Net::MessageIn &msg) { msg.readInt16("len"); - const int accountId = msg.readInt32("account id"); + const BeingId accountId = msg.readBeingId("account id"); const int charId = msg.readInt32("char id"); const int pos = msg.readInt32("position"); if (taGuild) diff --git a/src/net/ea/inventoryhandler.h b/src/net/ea/inventoryhandler.h index 26d74d56a..6050baaff 100644 --- a/src/net/ea/inventoryhandler.h +++ b/src/net/ea/inventoryhandler.h @@ -41,7 +41,7 @@ namespace Ea { typedef std::vector InventoryItems; -typedef std::queue PickupQueue; +typedef std::queue PickupQueue; class InventoryHandler notfinal : public Net::InventoryHandler { @@ -65,7 +65,7 @@ class InventoryHandler notfinal : public Net::InventoryHandler size_t getSize(const int type) const override final A_WARN_UNUSED; - void pushPickup(const int floorId) + void pushPickup(const BeingId floorId) { mSentPickups.push(floorId); } static int getSlot(const int eAthenaSlot) A_WARN_UNUSED; diff --git a/src/net/ea/itemhandler.cpp b/src/net/ea/itemhandler.cpp index a4c1a164b..2c297f69f 100644 --- a/src/net/ea/itemhandler.cpp +++ b/src/net/ea/itemhandler.cpp @@ -41,7 +41,7 @@ ItemHandler::~ItemHandler() void ItemHandler::processItemVisible(Net::MessageIn &msg) { - const int id = msg.readInt32("item object id"); + const BeingId id = msg.readBeingId("item object id"); const int itemId = msg.readInt16("item id"); const uint8_t identify = msg.readUInt8("identify"); const int x = msg.readInt16("x"); @@ -62,7 +62,7 @@ void ItemHandler::processItemRemove(Net::MessageIn &msg) if (actorManager) { if (FloorItem *const item = actorManager - ->findItem(msg.readInt32("floor item id"))) + ->findItem(msg.readBeingId("floor item id"))) { actorManager->destroy(item); } diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp index 8b8077cde..396eb1480 100644 --- a/src/net/ea/loginhandler.cpp +++ b/src/net/ea/loginhandler.cpp @@ -163,7 +163,7 @@ void LoginHandler::processLoginData(Net::MessageIn &msg) const int worldCount = (msg.getLength() - 47) / 32; mToken.session_ID1 = msg.readInt32("session id1"); - mToken.account_ID = msg.readInt32("accound id"); + mToken.account_ID = msg.readBeingId("accound id"); mToken.session_ID2 = msg.readInt32("session id2"); msg.readInt32("old ip"); loginData.lastLogin = msg.readString(24, "last login"); diff --git a/src/net/ea/npchandler.cpp b/src/net/ea/npchandler.cpp index a88025b7f..bfa3c3f81 100644 --- a/src/net/ea/npchandler.cpp +++ b/src/net/ea/npchandler.cpp @@ -104,7 +104,7 @@ void NpcHandler::processNpcIntInput(Net::MessageIn &msg) void NpcHandler::processNpcStrInput(Net::MessageIn &msg) { // Request for a string - int npcId = npcHandler->getNpc(msg); + BeingId npcId = npcHandler->getNpc(msg); if (mRequestLang) { mRequestLang = false; @@ -118,11 +118,11 @@ void NpcHandler::processNpcStrInput(Net::MessageIn &msg) void NpcHandler::processNpcCommand(Net::MessageIn &msg) { - const int npcId = npcHandler->getNpc(msg); + const BeingId npcId = npcHandler->getNpc(msg); mRequestLang = false; const int cmd = msg.readInt16("cmd"); - const int id = msg.readInt32("id"); + const BeingId id = msg.readBeingId("id"); const int x = msg.readInt16("x"); const int y = msg.readInt16("y"); switch (cmd) @@ -139,7 +139,7 @@ void NpcHandler::processNpcCommand(Net::MessageIn &msg) case 2: if (viewport) { - if (!id) + if (id == BeingId_zero) viewport->moveCameraToPosition(x, y); else viewport->moveCameraToActor(id, x, y); @@ -165,7 +165,7 @@ void NpcHandler::processNpcCommand(Net::MessageIn &msg) case 6: // show avatar if (mDialog) { - mDialog->showAvatar(static_cast(id)); + mDialog->showAvatar(id); } break; case 7: // set avatar direction @@ -178,7 +178,7 @@ void NpcHandler::processNpcCommand(Net::MessageIn &msg) break; case 8: // set avatar action if (mDialog) - mDialog->setAvatarAction(id); + mDialog->setAvatarAction(toInt(id, int)); break; case 9: // clear npc dialog if (mDialog) @@ -186,7 +186,7 @@ void NpcHandler::processNpcCommand(Net::MessageIn &msg) break; case 10: // send selected item id { - int invSize = id; + int invSize = toInt(id, int); if (!invSize) invSize = 1; if (mDialog) diff --git a/src/net/ea/partyhandler.cpp b/src/net/ea/partyhandler.cpp index f30a0a83f..1af9ba7ef 100644 --- a/src/net/ea/partyhandler.cpp +++ b/src/net/ea/partyhandler.cpp @@ -140,7 +140,7 @@ void PartyHandler::processPartySettingsContinue(Net::MessageIn &msg, void PartyHandler::processPartyLeave(Net::MessageIn &msg) { - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); const std::string nick = msg.readString(24, "nick"); const int reason = msg.readUInt8("flag"); if (!localPlayer) @@ -224,7 +224,7 @@ void PartyHandler::processPartyLeave(Net::MessageIn &msg) void PartyHandler::processPartyUpdateCoords(Net::MessageIn &msg) { - const int id = msg.readInt32("id"); + const BeingId id = msg.readBeingId("account id"); PartyMember *m = nullptr; if (Ea::taParty) m = Ea::taParty->getMember(id); diff --git a/src/net/ea/token.h b/src/net/ea/token.h index 65368b6e2..a62136aee 100644 --- a/src/net/ea/token.h +++ b/src/net/ea/token.h @@ -20,6 +20,7 @@ * along with this program. If not, see . */ +#include "enums/simpletypes/beingid.h" #include "enums/being/gender.h" #ifndef NET_EA_TOKEN_H @@ -27,14 +28,14 @@ struct Token final { - int account_ID; + BeingId account_ID; int session_ID1; int session_ID2; Gender::Type sex; void clear() { - account_ID = 0; + account_ID = BeingId_zero; session_ID1 = 0; session_ID2 = 0; sex = Gender::UNSPECIFIED; -- cgit v1.2.3-60-g2f50