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/tmwa/adminhandler.cpp | 4 +-- src/net/tmwa/adminhandler.h | 2 +- src/net/tmwa/beinghandler.cpp | 62 +++++++++++++++++++------------------- src/net/tmwa/beinghandler.h | 2 +- src/net/tmwa/charserverhandler.cpp | 8 ++--- src/net/tmwa/charserverhandler.h | 2 +- src/net/tmwa/chathandler.cpp | 2 +- src/net/tmwa/gamehandler.cpp | 6 ++-- src/net/tmwa/guildhandler.cpp | 12 ++++---- src/net/tmwa/guildmanager.cpp | 3 +- src/net/tmwa/homunculushandler.cpp | 2 +- src/net/tmwa/homunculushandler.h | 3 +- src/net/tmwa/inventoryhandler.cpp | 4 +-- src/net/tmwa/itemhandler.cpp | 2 +- src/net/tmwa/mercenaryhandler.cpp | 2 +- src/net/tmwa/mercenaryhandler.h | 3 +- src/net/tmwa/messagein.cpp | 5 +++ src/net/tmwa/messagein.h | 2 ++ src/net/tmwa/messageout.cpp | 5 +++ src/net/tmwa/messageout.h | 3 ++ src/net/tmwa/npchandler.cpp | 47 ++++++++++++++++------------- src/net/tmwa/npchandler.h | 24 ++++++++------- src/net/tmwa/partyhandler.cpp | 18 +++++------ src/net/tmwa/playerhandler.cpp | 7 +++-- src/net/tmwa/playerhandler.h | 3 +- src/net/tmwa/skillhandler.cpp | 4 +-- src/net/tmwa/skillhandler.h | 11 ++++--- src/net/tmwa/tradehandler.cpp | 2 +- 28 files changed, 140 insertions(+), 110 deletions(-) (limited to 'src/net/tmwa') diff --git a/src/net/tmwa/adminhandler.cpp b/src/net/tmwa/adminhandler.cpp index 216a33cb7..64638ad46 100644 --- a/src/net/tmwa/adminhandler.cpp +++ b/src/net/tmwa/adminhandler.cpp @@ -86,10 +86,10 @@ void AdminHandler::hide(const bool h A_UNUSED) const outMsg.writeInt32(0, "unused"); } -void AdminHandler::kick(const int playerId) const +void AdminHandler::kick(const BeingId playerId) const { createOutPacket(CMSG_ADMIN_KICK); - outMsg.writeInt32(playerId, "account id"); + outMsg.writeBeingId(playerId, "account id"); } void AdminHandler::kickAll() const diff --git a/src/net/tmwa/adminhandler.h b/src/net/tmwa/adminhandler.h index 35a4ccead..a98d6d850 100644 --- a/src/net/tmwa/adminhandler.h +++ b/src/net/tmwa/adminhandler.h @@ -45,7 +45,7 @@ class AdminHandler final : public MessageHandler, public Ea::AdminHandler void hide(const bool h) const override final; - void kick(const int playerId) const override final; + void kick(const BeingId playerId) const override final; void kickAll() const override final; diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index 20ab2cffa..0191953a4 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -101,10 +101,10 @@ BeingHandler::BeingHandler(const bool enableSync) : beingHandler = this; } -void BeingHandler::requestNameById(const int id) const +void BeingHandler::requestNameById(const BeingId id) const { createOutPacket(CMSG_NAME_REQUEST); - outMsg.writeInt32(id, "being id"); + outMsg.writeBeingId(id, "being id"); } void BeingHandler::handleMessage(Net::MessageIn &msg) @@ -267,7 +267,7 @@ void BeingHandler::processBeingChangeLook(Net::MessageIn &msg) } Being *const dstBeing = actorManager->findBeing( - msg.readInt32("being id")); + msg.readBeingId("being id")); const uint8_t type = msg.readUInt8("type"); const int16_t id = static_cast(msg.readUInt8("id")); @@ -292,7 +292,7 @@ void BeingHandler::processBeingChangeLook2(Net::MessageIn &msg) } Being *const dstBeing = actorManager->findBeing( - msg.readInt32("being id")); + msg.readBeingId("being id")); const uint8_t type = msg.readUInt8("type"); int id2 = 0; @@ -427,7 +427,7 @@ void BeingHandler::processPlayerUpdate1(Net::MessageIn &msg) } // An update about a player, potentially including movement. - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); const int16_t speed = msg.readInt16("speed"); const uint16_t stunMode = msg.readInt16("opt1"); uint32_t statusEffects = msg.readInt16("opt2"); @@ -435,7 +435,7 @@ void BeingHandler::processPlayerUpdate1(Net::MessageIn &msg) << 16; const int16_t job = msg.readInt16("job"); int disguiseId = 0; - if (id < 110000000 && job >= 1000) + if (toInt(id, int) < 110000000 && job >= 1000) disguiseId = job; Being *dstBeing = actorManager->findBeing(id); @@ -579,7 +579,7 @@ void BeingHandler::processPlayerUpdate2(Net::MessageIn &msg) } // An update about a player, potentially including movement. - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); const int16_t speed = msg.readInt16("speed"); const uint16_t stunMode = msg.readInt16("opt1"); uint32_t statusEffects = msg.readInt16("opt2"); @@ -587,7 +587,7 @@ void BeingHandler::processPlayerUpdate2(Net::MessageIn &msg) << 16; const int16_t job = msg.readInt16("job"); int disguiseId = 0; - if (id < 110000000 && job >= 1000) + if (toInt(id, int) < 110000000 && job >= 1000) disguiseId = job; Being *dstBeing = actorManager->findBeing(id); @@ -727,7 +727,7 @@ void BeingHandler::processPlayerMove(Net::MessageIn &msg) } // An update about a player, potentially including movement. - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); const int16_t speed = msg.readInt16("speed"); const uint16_t stunMode = msg.readInt16("opt1"); uint32_t statusEffects = msg.readInt16("opt2"); @@ -735,7 +735,7 @@ void BeingHandler::processPlayerMove(Net::MessageIn &msg) << 16; const int16_t job = msg.readInt16("job"); int disguiseId = 0; - if (id < 110000000 && job >= 1000) + if (toInt(id, int) < 110000000 && job >= 1000) disguiseId = job; Being *dstBeing = actorManager->findBeing(id); @@ -904,15 +904,15 @@ void BeingHandler::processBeingVisible(Net::MessageIn &msg) return; } - int spawnId; + BeingId spawnId; // Information about a being in range - const int id = msg.readInt32("being id"); + const BeingId id = msg.readBeingId("being id"); if (id == mSpawnId) spawnId = mSpawnId; else - spawnId = 0; - mSpawnId = 0; + spawnId = BeingId_zero; + mSpawnId = BeingId_zero; int16_t speed = msg.readInt16("speed"); const uint16_t stunMode = msg.readInt16("opt1"); uint32_t statusEffects = msg.readInt16("opt2"); @@ -936,7 +936,7 @@ void BeingHandler::processBeingVisible(Net::MessageIn &msg) { // Being with id >= 110000000 and job 0 are better // known as ghosts, so don't create those. - if (job == 0 && id >= 110000000) + if (job == 0 && toInt(id, int) >= 110000000) { BLOCK_END("BeingHandler::processBeingVisibleOrMove") return; @@ -969,7 +969,7 @@ void BeingHandler::processBeingVisible(Net::MessageIn &msg) if (dstBeing->getType() == ActorType::Player) dstBeing->setMoveTime(); - if (spawnId) + if (spawnId != BeingId_zero) { dstBeing->setAction(BeingAction::SPAWN, 0); } @@ -1111,15 +1111,15 @@ void BeingHandler::processBeingMove(Net::MessageIn &msg) return; } - int spawnId; + BeingId spawnId; // Information about a being in range - const int id = msg.readInt32("being id"); + const BeingId id = msg.readBeingId("being id"); if (id == mSpawnId) spawnId = mSpawnId; else - spawnId = 0; - mSpawnId = 0; + spawnId = BeingId_zero; + mSpawnId = BeingId_zero; int16_t speed = msg.readInt16("speed"); const uint16_t stunMode = msg.readInt16("opt1"); uint32_t statusEffects = msg.readInt16("opt2"); @@ -1143,7 +1143,7 @@ void BeingHandler::processBeingMove(Net::MessageIn &msg) { // Being with id >= 110000000 and job 0 are better // known as ghosts, so don't create those. - if (job == 0 && id >= 110000000) + if (job == 0 && toInt(id, int) >= 110000000) { BLOCK_END("BeingHandler::processBeingVisibleOrMove") return; @@ -1176,7 +1176,7 @@ void BeingHandler::processBeingMove(Net::MessageIn &msg) if (dstBeing->getType() == ActorType::Player) dstBeing->setMoveTime(); - if (spawnId) + if (spawnId != BeingId_zero) dstBeing->setAction(BeingAction::SPAWN, 0); // Prevent division by 0 when calculating frame @@ -1296,7 +1296,7 @@ void BeingHandler::processBeingSpawn(Net::MessageIn &msg) { BLOCK_START("BeingHandler::processBeingSpawn") // skipping this packet - mSpawnId = msg.readInt32("being id"); + mSpawnId = msg.readBeingId("being id"); msg.readInt16("speed"); msg.readInt16("opt1"); msg.readInt16("opt2"); @@ -1328,7 +1328,7 @@ void BeingHandler::processBeingStatusChange(Net::MessageIn &msg) // Status change const uint16_t status = msg.readInt16("status"); - const int id = msg.readInt32("being id"); + const BeingId id = msg.readBeingId("being id"); const Enable flag = fromBool( msg.readUInt8("flag: 0: stop, 1: start"), Enable); @@ -1352,7 +1352,7 @@ void BeingHandler::processBeingMove2(Net::MessageIn &msg) * later versions of eAthena for both mobs and * players */ - Being *const dstBeing = actorManager->findBeing(msg.readInt32("being id")); + Being *const dstBeing = actorManager->findBeing(msg.readBeingId("being id")); /* * This packet doesn't have enough info to actually @@ -1387,7 +1387,7 @@ void BeingHandler::processBeingChangeDirection(Net::MessageIn &msg) return; } - Being *const dstBeing = actorManager->findBeing(msg.readInt32("being id")); + Being *const dstBeing = actorManager->findBeing(msg.readBeingId("being id")); if (!dstBeing) { @@ -1470,7 +1470,7 @@ void BeingHandler::processPlaterStatusChange(Net::MessageIn &msg) } // Change in players' flags - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); Being *const dstBeing = actorManager->findBeing(id); if (!dstBeing) return; @@ -1499,7 +1499,7 @@ void BeingHandler::processBeingResurrect(Net::MessageIn &msg) // A being changed mortality status - const int id = msg.readInt32("being id"); + const BeingId id = msg.readBeingId("being id"); Being *const dstBeing = actorManager->findBeing(id); if (!dstBeing) { @@ -1525,7 +1525,7 @@ void BeingHandler::processPlayerGuilPartyInfo(Net::MessageIn &msg) return; } - Being *const dstBeing = actorManager->findBeing(msg.readInt32("being id")); + Being *const dstBeing = actorManager->findBeing(msg.readBeingId("being id")); if (dstBeing) { @@ -1562,7 +1562,7 @@ void BeingHandler::processBeingSelfEffect(Net::MessageIn &msg) return; } - const int id = static_cast(msg.readInt32("being id")); + const BeingId id = msg.readBeingId("being id"); Being *const being = actorManager->findBeing(id); if (!being) { @@ -1598,7 +1598,7 @@ void BeingHandler::processIpResponse(Net::MessageIn &msg) return; } - Being *const dstBeing = actorManager->findBeing(msg.readInt32("being id")); + Being *const dstBeing = actorManager->findBeing(msg.readBeingId("being id")); if (dstBeing) dstBeing->setIp(ipToString(msg.readInt32("ip address"))); BLOCK_END("BeingHandler::processIpResponse") diff --git a/src/net/tmwa/beinghandler.h b/src/net/tmwa/beinghandler.h index 64678939b..20badffe0 100644 --- a/src/net/tmwa/beinghandler.h +++ b/src/net/tmwa/beinghandler.h @@ -39,7 +39,7 @@ class BeingHandler final : public MessageHandler, public Ea::BeingHandler void handleMessage(Net::MessageIn &msg) override final; - void requestNameById(const int id) const override final; + void requestNameById(const BeingId id) const override final; void undress(Being *const being) const override final; diff --git a/src/net/tmwa/charserverhandler.cpp b/src/net/tmwa/charserverhandler.cpp index 970d6a9c6..f3a8ab0c6 100644 --- a/src/net/tmwa/charserverhandler.cpp +++ b/src/net/tmwa/charserverhandler.cpp @@ -141,7 +141,7 @@ void CharServerHandler::readPlayerData(Net::MessageIn &msg, static_cast(loginHandler)->getToken(); LocalPlayer *const tempPlayer = new LocalPlayer( - msg.readInt32("account id"), 0); + msg.readBeingId("account id"), 0); tempPlayer->setGender(token.sex); PlayerInfoBackend &data = character->data; @@ -288,7 +288,7 @@ void CharServerHandler::deleteCharacter(Net::Character *const character, mSelectedCharacter = character; createOutPacket(CMSG_CHAR_DELETE); - outMsg.writeInt32(mSelectedCharacter->dummy->getId(), "id?"); + outMsg.writeBeingId(mSelectedCharacter->dummy->getId(), "id?"); outMsg.writeString("a@a.com", 40, "email"); } @@ -310,7 +310,7 @@ void CharServerHandler::connect() mNetwork->disconnect(); mNetwork->connect(charServer); createOutPacket(CMSG_CHAR_SERVER_CONNECT); - outMsg.writeInt32(token.account_ID, "account id"); + outMsg.writeBeingId(token.account_ID, "account id"); outMsg.writeInt32(token.session_ID1, "session id1"); outMsg.writeInt32(token.session_ID2, "session id2"); // [Fate] The next word is unused by the old char server, so we squeeze in @@ -502,7 +502,7 @@ void CharServerHandler::processCharCreate2(Net::MessageIn &msg) BLOCK_END("CharServerHandler::processCharCreate2") } -void CharServerHandler::renameCharacter(const int id A_UNUSED, +void CharServerHandler::renameCharacter(const BeingId id A_UNUSED, const std::string &newName A_UNUSED) { } diff --git a/src/net/tmwa/charserverhandler.h b/src/net/tmwa/charserverhandler.h index 20a162eb1..2d73d5a22 100644 --- a/src/net/tmwa/charserverhandler.h +++ b/src/net/tmwa/charserverhandler.h @@ -57,7 +57,7 @@ class CharServerHandler final : public MessageHandler, void deleteCharacter(Net::Character *const character, const std::string &email) override final; - void renameCharacter(const int id, + void renameCharacter(const BeingId id, const std::string &newName) override final; void switchCharacter() const override final; diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp index ab8036c8c..ed3a1318f 100644 --- a/src/net/tmwa/chathandler.cpp +++ b/src/net/tmwa/chathandler.cpp @@ -615,7 +615,7 @@ void ChatHandler::processBeingChat(Net::MessageIn &msg) BLOCK_START("ChatHandler::processBeingChat") const bool channels = msg.getId() == SMSG_BEING_CHAT2; int chatMsgLength = msg.readInt16("len") - 8; - Being *const being = actorManager->findBeing(msg.readInt32("being id")); + Being *const being = actorManager->findBeing(msg.readBeingId("being id")); if (!being) { BLOCK_END("ChatHandler::processBeingChat") diff --git a/src/net/tmwa/gamehandler.cpp b/src/net/tmwa/gamehandler.cpp index f804b61f2..83bc6e966 100644 --- a/src/net/tmwa/gamehandler.cpp +++ b/src/net/tmwa/gamehandler.cpp @@ -113,14 +113,14 @@ void GameHandler::connect() } else { - mCharID = 0; + mCharID = BeingId_zero; } } // Send login infos createOutPacket(CMSG_MAP_SERVER_CONNECT); - outMsg.writeInt32(token.account_ID, "account id"); - outMsg.writeInt32(mCharID, "char id"); + outMsg.writeBeingId(token.account_ID, "account id"); + outMsg.writeBeingId(mCharID, "char id"); outMsg.writeInt32(token.session_ID1, "session id1"); outMsg.writeInt32(token.session_ID2, "session id2"); outMsg.writeInt8(Being::genderToInt(token.sex), "gender"); diff --git a/src/net/tmwa/guildhandler.cpp b/src/net/tmwa/guildhandler.cpp index f58f873a4..c552cfaef 100644 --- a/src/net/tmwa/guildhandler.cpp +++ b/src/net/tmwa/guildhandler.cpp @@ -222,7 +222,7 @@ void GuildHandler::invite(const std::string &name) const if (being) { createOutPacket(CMSG_GUILD_INVITE); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); outMsg.writeInt32(0, "unused"); outMsg.writeInt32(0, "unused"); } @@ -234,7 +234,7 @@ void GuildHandler::invite(const Being *const being) const return; createOutPacket(CMSG_GUILD_INVITE); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); outMsg.writeInt32(0, "unused"); outMsg.writeInt32(0, "unused"); } @@ -255,7 +255,7 @@ void GuildHandler::leave(const int guildId) const createOutPacket(CMSG_GUILD_LEAVE); outMsg.writeInt32(guildId, "guild id"); - outMsg.writeInt32(localPlayer->getId(), "account id"); + outMsg.writeBeingId(localPlayer->getId(), "account id"); outMsg.writeInt32(PlayerInfo::getCharId(), "char id"); outMsg.writeString("", 40, "message"); } @@ -268,7 +268,7 @@ void GuildHandler::kick(const GuildMember *restrict const member, createOutPacket(CMSG_GUILD_EXPULSION); outMsg.writeInt32(member->getGuild()->getId(), "guild id"); - outMsg.writeInt32(member->getID(), "account id"); + outMsg.writeBeingId(member->getID(), "account id"); outMsg.writeInt32(member->getCharId(), "char id"); outMsg.writeString(reason, 40, "message"); } @@ -318,7 +318,7 @@ void GuildHandler::changeMemberPostion(const GuildMember *const member, createOutPacket(CMSG_GUILD_CHANGE_MEMBER_POS); outMsg.writeInt16(16, "len"); - outMsg.writeInt32(member->getID(), "account id"); + outMsg.writeBeingId(member->getID(), "account id"); outMsg.writeInt32(member->getCharId(), "char id"); outMsg.writeInt32(level, "position"); } @@ -379,7 +379,7 @@ void GuildHandler::processGuildPositionInfo(Net::MessageIn &msg) void GuildHandler::processGuildMemberLogin(Net::MessageIn &msg) { - const int accountId = msg.readInt32("account id"); + const BeingId accountId = msg.readBeingId("account id"); const int charId = msg.readInt32("char id"); const int online = msg.readInt32("flag"); if (Ea::taGuild) diff --git a/src/net/tmwa/guildmanager.cpp b/src/net/tmwa/guildmanager.cpp index 7931087a9..9b584f14a 100644 --- a/src/net/tmwa/guildmanager.cpp +++ b/src/net/tmwa/guildmanager.cpp @@ -201,7 +201,8 @@ void GuildManager::updateList() const int status = atoi(name.substr(sz - 1).c_str()); name = name.substr(0, sz - 1); - GuildMember *const m = guild->addMember(i, 0, name); + GuildMember *const m = guild->addMember( + fromInt(i, BeingId), 0, name); if (m) { m->setOnline(status & 1); diff --git a/src/net/tmwa/homunculushandler.cpp b/src/net/tmwa/homunculushandler.cpp index 8ffbb6ed4..1a0a89077 100644 --- a/src/net/tmwa/homunculushandler.cpp +++ b/src/net/tmwa/homunculushandler.cpp @@ -54,7 +54,7 @@ void HomunculusHandler::move(const int x A_UNUSED, const int y A_UNUSED) const { } -void HomunculusHandler::attack(const int targetId A_UNUSED, +void HomunculusHandler::attack(const BeingId targetId A_UNUSED, const Keep keep A_UNUSED) const { } diff --git a/src/net/tmwa/homunculushandler.h b/src/net/tmwa/homunculushandler.h index 9aec1eed6..a54079382 100644 --- a/src/net/tmwa/homunculushandler.h +++ b/src/net/tmwa/homunculushandler.h @@ -46,7 +46,8 @@ class HomunculusHandler final : public MessageHandler, void move(const int x, const int y) const override final; - void attack(const int targetId, const Keep keep) const override final; + void attack(const BeingId targetId, + const Keep keep) const override final; void feed() const override final; diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index 28db6fa69..d1b7014f3 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -348,10 +348,10 @@ void InventoryHandler::processPlayerInventoryAdd(Net::MessageIn &msg) const ItemInfo &itemInfo = ItemDB::get(itemId); const unsigned char err = msg.readUInt8("status"); - int floorId; + BeingId floorId; if (mSentPickups.empty()) { - floorId = 0; + floorId = BeingId_zero; } else { diff --git a/src/net/tmwa/itemhandler.cpp b/src/net/tmwa/itemhandler.cpp index 0e74172db..7ad3f733a 100644 --- a/src/net/tmwa/itemhandler.cpp +++ b/src/net/tmwa/itemhandler.cpp @@ -70,7 +70,7 @@ void ItemHandler::handleMessage(Net::MessageIn &msg) void ItemHandler::processItemDropped(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"); diff --git a/src/net/tmwa/mercenaryhandler.cpp b/src/net/tmwa/mercenaryhandler.cpp index aa71c7f69..7b39823f3 100644 --- a/src/net/tmwa/mercenaryhandler.cpp +++ b/src/net/tmwa/mercenaryhandler.cpp @@ -58,7 +58,7 @@ void MercenaryHandler::move(const int x A_UNUSED, const int y A_UNUSED) const { } -void MercenaryHandler::attack(const int targetId A_UNUSED, +void MercenaryHandler::attack(const BeingId targetId A_UNUSED, const Keep keep A_UNUSED) const { } diff --git a/src/net/tmwa/mercenaryhandler.h b/src/net/tmwa/mercenaryhandler.h index f2fe3ecae..eea2a19a2 100644 --- a/src/net/tmwa/mercenaryhandler.h +++ b/src/net/tmwa/mercenaryhandler.h @@ -48,7 +48,8 @@ class MercenaryHandler final : public MessageHandler, void move(const int x, const int y) const override final; - void attack(const int targetId, const Keep keep) const override final; + void attack(const BeingId targetId, + const Keep keep) const override final; void talk(const std::string &restrict text) const override final; diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp index b200729f6..3bb66c6f2 100644 --- a/src/net/tmwa/messagein.cpp +++ b/src/net/tmwa/messagein.cpp @@ -105,6 +105,11 @@ int32_t MessageIn::readInt32(const char *const str) return value; } +BeingId MessageIn::readBeingId(const char *const str) +{ + return fromInt(readInt32(str), BeingId); +} + int64_t MessageIn::readInt64(const char *const str) { int64_t value = -1; diff --git a/src/net/tmwa/messagein.h b/src/net/tmwa/messagein.h index ef542bab2..7d27b1188 100644 --- a/src/net/tmwa/messagein.h +++ b/src/net/tmwa/messagein.h @@ -54,6 +54,8 @@ class MessageIn final : public Net::MessageIn int64_t readInt64(const char *const str) override final; + BeingId readBeingId(const char *const str) override final; + uint16_t readId(); }; diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp index 66379ffda..c0cc0321d 100644 --- a/src/net/tmwa/messageout.cpp +++ b/src/net/tmwa/messageout.cpp @@ -83,6 +83,11 @@ void MessageOut::writeInt32(const int32_t value, const char *const str) PacketCounters::incOutBytes(4); } +void MessageOut::writeBeingId(const BeingId value, const char *const str) +{ + writeInt32(toInt(value, int32_t), str); +} + #define LOBYTE(w) (static_cast(w)) #define HIBYTE(w) (static_cast(( \ static_cast(w)) >> 8U)) diff --git a/src/net/tmwa/messageout.h b/src/net/tmwa/messageout.h index c6aa522cc..c83643c38 100644 --- a/src/net/tmwa/messageout.h +++ b/src/net/tmwa/messageout.h @@ -56,6 +56,9 @@ class MessageOut final : public Net::MessageOut void writeInt32(const int32_t value, const char *const str) override final; + void writeBeingId(const BeingId value, + const char *const str) override final; + /** * Encodes coordinates and direction in 3 bytes. */ diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index 3fd1fed60..b3187687c 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -106,23 +106,23 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) BLOCK_END("NpcHandler::handleMessage") } -void NpcHandler::talk(const int npcId) const +void NpcHandler::talk(const BeingId npcId) const { createOutPacket(CMSG_NPC_TALK); - outMsg.writeInt32(npcId, "npc id"); + outMsg.writeBeingId(npcId, "npc id"); outMsg.writeInt8(0, "unused"); } -void NpcHandler::nextDialog(const int npcId) const +void NpcHandler::nextDialog(const BeingId npcId) const { createOutPacket(CMSG_NPC_NEXT_REQUEST); - outMsg.writeInt32(npcId, "npc id"); + outMsg.writeBeingId(npcId, "npc id"); } -void NpcHandler::closeDialog(const int npcId) +void NpcHandler::closeDialog(const BeingId npcId) { createOutPacket(CMSG_NPC_CLOSE); - outMsg.writeInt32(npcId, "npc id"); + outMsg.writeBeingId(npcId, "npc id"); const NpcDialogs::iterator it = NpcDialog::mNpcDialogs.find(npcId); if (it != NpcDialog::mNpcDialogs.end()) @@ -136,45 +136,50 @@ void NpcHandler::closeDialog(const int npcId) } } -void NpcHandler::listInput(const int npcId, const unsigned char value) const +void NpcHandler::listInput(const BeingId npcId, + const unsigned char value) const { createOutPacket(CMSG_NPC_LIST_CHOICE); - outMsg.writeInt32(npcId, "npc id"); + outMsg.writeBeingId(npcId, "npc id"); outMsg.writeInt8(value, "value"); } -void NpcHandler::integerInput(const int npcId, const int value) const +void NpcHandler::integerInput(const BeingId npcId, + const int value) const { createOutPacket(CMSG_NPC_INT_RESPONSE); - outMsg.writeInt32(npcId, "npc id"); + outMsg.writeBeingId(npcId, "npc id"); outMsg.writeInt32(value, "value"); } -void NpcHandler::stringInput(const int npcId, const std::string &value) const +void NpcHandler::stringInput(const BeingId npcId, + const std::string &value) const { createOutPacket(CMSG_NPC_STR_RESPONSE); outMsg.writeInt16(static_cast(value.length() + 9), "len"); - outMsg.writeInt32(npcId, "npc id"); + outMsg.writeBeingId(npcId, "npc id"); outMsg.writeString(value, static_cast(value.length()), "value"); outMsg.writeInt8(0, "null byte"); } -void NpcHandler::buy(const int beingId) const +void NpcHandler::buy(const BeingId beingId) const { createOutPacket(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(beingId, "npc id"); + outMsg.writeBeingId(beingId, "npc id"); outMsg.writeInt8(0, "action"); } -void NpcHandler::sell(const int beingId) const +void NpcHandler::sell(const BeingId beingId) const { createOutPacket(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(beingId, "npc id"); + outMsg.writeBeingId(beingId, "npc id"); outMsg.writeInt8(1, "action"); } -void NpcHandler::buyItem(const int beingId A_UNUSED, const int itemId, - const unsigned char color, const int amount) const +void NpcHandler::buyItem(const BeingId beingId A_UNUSED, + const int itemId, + const unsigned char color, + const int amount) const { createOutPacket(CMSG_NPC_BUY_REQUEST); if (serverFeatures->haveItemColors()) @@ -193,7 +198,7 @@ void NpcHandler::buyItem(const int beingId A_UNUSED, const int itemId, } } -void NpcHandler::sellItem(const int beingId A_UNUSED, +void NpcHandler::sellItem(const BeingId beingId A_UNUSED, const int itemId, const int amount) const { @@ -242,7 +247,7 @@ void NpcHandler::selectAutoSpell(const int skillId A_UNUSED) const { } -int NpcHandler::getNpc(Net::MessageIn &msg) +BeingId NpcHandler::getNpc(Net::MessageIn &msg) { if (msg.getId() == SMSG_NPC_CHOICE || msg.getId() == SMSG_NPC_MESSAGE @@ -251,7 +256,7 @@ int NpcHandler::getNpc(Net::MessageIn &msg) msg.readInt16("len"); } - const int npcId = msg.readInt32("npc id"); + const BeingId npcId = msg.readBeingId("npc id"); const NpcDialogs::const_iterator diag = NpcDialog::mNpcDialogs.find(npcId); mDialog = nullptr; diff --git a/src/net/tmwa/npchandler.h b/src/net/tmwa/npchandler.h index f8baff5d3..c4880ac15 100644 --- a/src/net/tmwa/npchandler.h +++ b/src/net/tmwa/npchandler.h @@ -39,35 +39,37 @@ class NpcHandler final : public MessageHandler, public Ea::NpcHandler void handleMessage(Net::MessageIn &msg) override final; - void talk(const int npcId) const override final; + void talk(const BeingId npcId) const override final; - void nextDialog(const int npcId) const override final; + void nextDialog(const BeingId npcId) const override final; - void closeDialog(const int npcId) override final; + void closeDialog(const BeingId npcId) override final; - void listInput(const int npcId, + void listInput(const BeingId npcId, const unsigned char value) const override final; - void integerInput(const int npcId, + void integerInput(const BeingId npcId, const int value) const override final; - void stringInput(const int npcId, + void stringInput(const BeingId npcId, const std::string &value) const override final; - void buy(const int beingId) const override final; + void buy(const BeingId beingId) const override final; - void sell(const int beingId) const override final; + void sell(const BeingId beingId) const override final; - void buyItem(const int beingId, const int itemId, + void buyItem(const BeingId beingId, + const int itemId, const unsigned char color, const int amount) const override final; - void sellItem(const int beingId, const int itemId, + void sellItem(const BeingId beingId, + const int itemId, const int amount) const override final; void completeProgressBar() const override final; - int getNpc(Net::MessageIn &msg) override final; + BeingId getNpc(Net::MessageIn &msg) override final; void produceMix(const int nameId, const int materialId1, diff --git a/src/net/tmwa/partyhandler.cpp b/src/net/tmwa/partyhandler.cpp index 6f8787be4..8bb143d75 100644 --- a/src/net/tmwa/partyhandler.cpp +++ b/src/net/tmwa/partyhandler.cpp @@ -128,7 +128,7 @@ void PartyHandler::invite(const std::string &name) const if (being) { createOutPacket(CMSG_PARTY_INVITE); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); } } @@ -139,7 +139,7 @@ void PartyHandler::inviteResponse(const std::string &inviter A_UNUSED, if (localPlayer) { createOutPacket(CMSG_PARTY_INVITED); - outMsg.writeInt32(localPlayer->getId(), "account id"); + outMsg.writeBeingId(localPlayer->getId(), "account id"); outMsg.writeInt32(accept ? 1 : 0, "accept"); } } @@ -154,7 +154,7 @@ void PartyHandler::kick(const Being *const being) const if (being) { createOutPacket(CMSG_PARTY_KICK); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); outMsg.writeString("", 24, "unused"); } } @@ -172,7 +172,7 @@ void PartyHandler::kick(const std::string &name) const } createOutPacket(CMSG_PARTY_KICK); - outMsg.writeInt32(m->getID(), "member id"); + outMsg.writeBeingId(m->getID(), "member id"); outMsg.writeString(name, 24, "unused"); } @@ -265,7 +265,7 @@ void PartyHandler::processPartyInfo(Net::MessageIn &msg) for (int i = 0; i < count; i++) { - const int id = msg.readInt32("id"); + const BeingId id = msg.readBeingId("id"); std::string nick = msg.readString(24, "nick"); std::string map = msg.readString(16, "map"); const bool leader = msg.readUInt8("leader") == 0U; @@ -329,7 +329,7 @@ void PartyHandler::processPartyMessage(Net::MessageIn &msg) if (msgLength <= 0) return; - const int id = msg.readInt32("id"); + const BeingId id = msg.readBeingId("id"); const std::string chatMsg = msg.readString(msgLength, "message"); if (Ea::taParty && partyTab) @@ -386,7 +386,7 @@ void PartyHandler::allowInvite(const bool allow A_UNUSED) const void PartyHandler::processPartyInvited(Net::MessageIn &msg) { - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); const std::string partyName = msg.readString(24, "party name"); std::string nick; @@ -406,7 +406,7 @@ void PartyHandler::processPartyInvited(Net::MessageIn &msg) void PartyHandler::processPartyMove(Net::MessageIn &msg) { - const int id = msg.readInt32("id"); + const BeingId id = msg.readBeingId("id"); PartyMember *m = nullptr; if (Ea::taParty) m = Ea::taParty->getMember(id); @@ -437,7 +437,7 @@ void PartyHandler::processPartyMove(Net::MessageIn &msg) void PartyHandler::processPartyUpdateHp(Net::MessageIn &msg) { - const int id = msg.readInt32("id"); + const BeingId id = msg.readBeingId("id"); const int hp = msg.readInt16("hp"); const int maxhp = msg.readInt16("max hp"); PartyMember *m = nullptr; diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index c78382f27..95b157c00 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -124,10 +124,11 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg) BLOCK_END("PlayerHandler::handleMessage") } -void PlayerHandler::attack(const int id, const Keep keep) const +void PlayerHandler::attack(const BeingId id, + const Keep keep) const { createOutPacket(CMSG_PLAYER_CHANGE_ACT); - outMsg.writeInt32(id, "target id"); + outMsg.writeBeingId(id, "target id"); if (keep == Keep_true) outMsg.writeInt8(7, "action"); else @@ -170,7 +171,7 @@ void PlayerHandler::pickUp(const FloorItem *const floorItem) const return; createOutPacket(CMSG_ITEM_PICKUP); - outMsg.writeInt32(floorItem->getId(), "object id"); + outMsg.writeBeingId(floorItem->getId(), "object id"); TmwAthena::InventoryHandler *const handler = static_cast(inventoryHandler); if (handler) diff --git a/src/net/tmwa/playerhandler.h b/src/net/tmwa/playerhandler.h index f0162c8f2..d8f159e8b 100644 --- a/src/net/tmwa/playerhandler.h +++ b/src/net/tmwa/playerhandler.h @@ -39,7 +39,8 @@ class PlayerHandler final : public MessageHandler, public Ea::PlayerHandler void handleMessage(Net::MessageIn &msg) override final; - void attack(const int id, const Keep keep) const override final; + void attack(const BeingId id, + const Keep keep) const override final; void stopAttack() const override final; void emote(const uint8_t emoteId) const override final; diff --git a/src/net/tmwa/skillhandler.cpp b/src/net/tmwa/skillhandler.cpp index 1b8678682..5e8dd9729 100644 --- a/src/net/tmwa/skillhandler.cpp +++ b/src/net/tmwa/skillhandler.cpp @@ -82,12 +82,12 @@ void SkillHandler::handleMessage(Net::MessageIn &msg) } void SkillHandler::useBeing(const int id, const int level, - const int beingId) const + const BeingId beingId) const { createOutPacket(CMSG_SKILL_USE_BEING); outMsg.writeInt16(static_cast(id), "skill id"); outMsg.writeInt16(static_cast(level), "level"); - outMsg.writeInt32(beingId, "target id"); + outMsg.writeBeingId(beingId, "target id"); } void SkillHandler::usePos(const int id, const int level, diff --git a/src/net/tmwa/skillhandler.h b/src/net/tmwa/skillhandler.h index 047ae6330..62bab67d4 100644 --- a/src/net/tmwa/skillhandler.h +++ b/src/net/tmwa/skillhandler.h @@ -39,13 +39,16 @@ class SkillHandler final : public MessageHandler, public Ea::SkillHandler void handleMessage(Net::MessageIn &msg) override final; - void useBeing(const int id, const int level, - const int beingId) const override final; + void useBeing(const int id, + const int level, + const BeingId beingId) const override final; - void usePos(const int id, const int level, + void usePos(const int id, + const int level, const int x, const int y) const override final; - void usePos(const int id, const int level, + void usePos(const int id, + const int level, const int x, const int y, const std::string &text) const override final; diff --git a/src/net/tmwa/tradehandler.cpp b/src/net/tmwa/tradehandler.cpp index 5962ff89a..4ad803640 100644 --- a/src/net/tmwa/tradehandler.cpp +++ b/src/net/tmwa/tradehandler.cpp @@ -118,7 +118,7 @@ void TradeHandler::request(const Being *const being) const return; createOutPacket(CMSG_TRADE_REQUEST); - outMsg.writeInt32(being->getId(), "player id"); + outMsg.writeBeingId(being->getId(), "player id"); } void TradeHandler::respond(const bool accept) const -- cgit v1.2.3-70-g09d2