diff options
Diffstat (limited to 'src/net/manaserv')
38 files changed, 272 insertions, 114 deletions
diff --git a/src/net/manaserv/adminhandler.cpp b/src/net/manaserv/adminhandler.cpp index ab49037d..8928a33d 100644 --- a/src/net/manaserv/adminhandler.cpp +++ b/src/net/manaserv/adminhandler.cpp @@ -41,7 +41,7 @@ AdminHandler::AdminHandler() adminHandler = this; } -void AdminHandler::handleMessage(Net::MessageIn &msg) +void AdminHandler::handleMessage(MessageIn &msg) { } diff --git a/src/net/manaserv/adminhandler.h b/src/net/manaserv/adminhandler.h index 9c68c620..83fbb854 100644 --- a/src/net/manaserv/adminhandler.h +++ b/src/net/manaserv/adminhandler.h @@ -33,7 +33,7 @@ class AdminHandler : public Net::AdminHandler, public MessageHandler public: AdminHandler(); - void handleMessage(Net::MessageIn &msg); + void handleMessage(MessageIn &msg); void announce(const std::string &text); diff --git a/src/net/manaserv/beinghandler.cpp b/src/net/manaserv/beinghandler.cpp index b319fa37..b744e53c 100644 --- a/src/net/manaserv/beinghandler.cpp +++ b/src/net/manaserv/beinghandler.cpp @@ -32,9 +32,9 @@ #include "gui/okdialog.h" #include "net/net.h" -#include "net/messagein.h" #include "net/manaserv/inventoryhandler.h" +#include "net/manaserv/messagein.h" #include "net/manaserv/playerhandler.h" #include "net/manaserv/manaserv_protocol.h" @@ -62,7 +62,7 @@ BeingHandler::BeingHandler() handledMessages = _messages; } -void BeingHandler::handleMessage(Net::MessageIn &msg) +void BeingHandler::handleMessage(MessageIn &msg) { switch (msg.getId()) { @@ -93,7 +93,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) } } -static void handleLooks(Being *being, Net::MessageIn &msg) +static void handleLooks(Being *being, MessageIn &msg) { int lookChanges = msg.readInt8(); @@ -109,7 +109,7 @@ static void handleLooks(Being *being, Net::MessageIn &msg) } } -void BeingHandler::handleBeingEnterMessage(Net::MessageIn &msg) +void BeingHandler::handleBeingEnterMessage(MessageIn &msg) { int type = msg.readInt8(); int id = msg.readInt16(); @@ -165,7 +165,7 @@ void BeingHandler::handleBeingEnterMessage(Net::MessageIn &msg) being->setAction(action); } -void BeingHandler::handleBeingLeaveMessage(Net::MessageIn &msg) +void BeingHandler::handleBeingLeaveMessage(MessageIn &msg) { Being *being = actorSpriteManager->findBeing(msg.readInt16()); if (!being) @@ -174,7 +174,7 @@ void BeingHandler::handleBeingLeaveMessage(Net::MessageIn &msg) actorSpriteManager->destroy(being); } -void BeingHandler::handleBeingsMoveMessage(Net::MessageIn &msg) +void BeingHandler::handleBeingsMoveMessage(MessageIn &msg) { while (msg.getUnreadLength()) { @@ -233,7 +233,7 @@ void BeingHandler::handleBeingsMoveMessage(Net::MessageIn &msg) } } -void BeingHandler::handleBeingAttackMessage(Net::MessageIn &msg) +void BeingHandler::handleBeingAttackMessage(MessageIn &msg) { Being *being = actorSpriteManager->findBeing(msg.readInt16()); const BeingDirection direction = (BeingDirection) msg.readInt8(); @@ -247,7 +247,7 @@ void BeingHandler::handleBeingAttackMessage(Net::MessageIn &msg) being->setAction(Being::ATTACK, attackId); } -void BeingHandler::handleBeingsDamageMessage(Net::MessageIn &msg) +void BeingHandler::handleBeingsDamageMessage(MessageIn &msg) { while (msg.getUnreadLength()) { @@ -260,7 +260,7 @@ void BeingHandler::handleBeingsDamageMessage(Net::MessageIn &msg) } } -void BeingHandler::handleBeingActionChangeMessage(Net::MessageIn &msg) +void BeingHandler::handleBeingActionChangeMessage(MessageIn &msg) { Being *being = actorSpriteManager->findBeing(msg.readInt16()); Being::Action action = (Being::Action) msg.readInt8(); @@ -299,7 +299,7 @@ void BeingHandler::handleBeingActionChangeMessage(Net::MessageIn &msg) } } -void BeingHandler::handleBeingLooksChangeMessage(Net::MessageIn &msg) +void BeingHandler::handleBeingLooksChangeMessage(MessageIn &msg) { Being *being = actorSpriteManager->findBeing(msg.readInt16()); if (!being || being->getType() != ActorSprite::PLAYER) @@ -314,7 +314,7 @@ void BeingHandler::handleBeingLooksChangeMessage(Net::MessageIn &msg) } } -void BeingHandler::handleBeingDirChangeMessage(Net::MessageIn &msg) +void BeingHandler::handleBeingDirChangeMessage(MessageIn &msg) { Being *being = actorSpriteManager->findBeing(msg.readInt16()); if (!being) diff --git a/src/net/manaserv/beinghandler.h b/src/net/manaserv/beinghandler.h index f33afbc1..94cf20c4 100644 --- a/src/net/manaserv/beinghandler.h +++ b/src/net/manaserv/beinghandler.h @@ -43,17 +43,17 @@ class BeingHandler : public MessageHandler public: BeingHandler(); - void handleMessage(Net::MessageIn &msg); + void handleMessage(MessageIn &msg); private: - void handleBeingAttackMessage(Net::MessageIn &msg); - void handleBeingEnterMessage(Net::MessageIn &msg); - void handleBeingLeaveMessage(Net::MessageIn &msg); - void handleBeingsMoveMessage(Net::MessageIn &msg); - void handleBeingsDamageMessage(Net::MessageIn &msg); - void handleBeingActionChangeMessage(Net::MessageIn &msg); - void handleBeingLooksChangeMessage(Net::MessageIn &msg); - void handleBeingDirChangeMessage(Net::MessageIn &msg); + void handleBeingAttackMessage(MessageIn &msg); + void handleBeingEnterMessage(MessageIn &msg); + void handleBeingLeaveMessage(MessageIn &msg); + void handleBeingsMoveMessage(MessageIn &msg); + void handleBeingsDamageMessage(MessageIn &msg); + void handleBeingActionChangeMessage(MessageIn &msg); + void handleBeingLooksChangeMessage(MessageIn &msg); + void handleBeingDirChangeMessage(MessageIn &msg); }; } // namespace ManaServ diff --git a/src/net/manaserv/buysellhandler.cpp b/src/net/manaserv/buysellhandler.cpp index f9ebb147..2e7cf26d 100644 --- a/src/net/manaserv/buysellhandler.cpp +++ b/src/net/manaserv/buysellhandler.cpp @@ -28,10 +28,8 @@ #include "gui/buydialog.h" #include "gui/selldialog.h" -#include "net/messagein.h" - #include "net/manaserv/manaserv_protocol.h" - +#include "net/manaserv/messagein.h" namespace ManaServ { @@ -45,7 +43,7 @@ BuySellHandler::BuySellHandler() handledMessages = _messages; } -void BuySellHandler::handleMessage(Net::MessageIn &msg) +void BuySellHandler::handleMessage(MessageIn &msg) { Being *being = actorSpriteManager->findBeing(msg.readInt16()); if (!being || being->getType() != ActorSprite::NPC) diff --git a/src/net/manaserv/buysellhandler.h b/src/net/manaserv/buysellhandler.h index f7c7e1f7..88432842 100644 --- a/src/net/manaserv/buysellhandler.h +++ b/src/net/manaserv/buysellhandler.h @@ -31,7 +31,7 @@ class BuySellHandler : public MessageHandler public: BuySellHandler(); - void handleMessage(Net::MessageIn &msg); + void handleMessage(MessageIn &msg); }; } // namespace ManaServ diff --git a/src/net/manaserv/charhandler.cpp b/src/net/manaserv/charhandler.cpp index c05e9320..e809bfac 100644 --- a/src/net/manaserv/charhandler.cpp +++ b/src/net/manaserv/charhandler.cpp @@ -76,7 +76,7 @@ CharHandler::~CharHandler() clear(); } -void CharHandler::handleMessage(Net::MessageIn &msg) +void CharHandler::handleMessage(MessageIn &msg) { switch (msg.getId()) { @@ -98,7 +98,7 @@ void CharHandler::handleMessage(Net::MessageIn &msg) } } -void CharHandler::handleCharacterInfo(Net::MessageIn &msg) +void CharHandler::handleCharacterInfo(MessageIn &msg) { CachedCharacterInfo info; info.slot = msg.readInt8(); @@ -126,7 +126,7 @@ void CharHandler::handleCharacterInfo(Net::MessageIn &msg) updateCharacters(); } -void CharHandler::handleCharacterCreateResponse(Net::MessageIn &msg) +void CharHandler::handleCharacterCreateResponse(MessageIn &msg) { const int errMsg = msg.readInt8(); @@ -192,7 +192,7 @@ void CharHandler::handleCharacterCreateResponse(Net::MessageIn &msg) } } -void CharHandler::handleCharacterDeleteResponse(Net::MessageIn &msg) +void CharHandler::handleCharacterDeleteResponse(MessageIn &msg) { int errMsg = msg.readInt8(); if (errMsg == ERRMSG_OK) @@ -232,7 +232,7 @@ void CharHandler::handleCharacterDeleteResponse(Net::MessageIn &msg) unlockCharSelectDialog(); } -void CharHandler::handleCharacterSelectResponse(Net::MessageIn &msg) +void CharHandler::handleCharacterSelectResponse(MessageIn &msg) { int errMsg = msg.readInt8(); diff --git a/src/net/manaserv/charhandler.h b/src/net/manaserv/charhandler.h index e3098c09..d2159204 100644 --- a/src/net/manaserv/charhandler.h +++ b/src/net/manaserv/charhandler.h @@ -44,7 +44,7 @@ class CharHandler : public MessageHandler, public Net::CharHandler ~CharHandler(); - void handleMessage(Net::MessageIn &msg); + void handleMessage(MessageIn &msg); void setCharSelectDialog(CharSelectDialog *window); @@ -108,10 +108,10 @@ class CharHandler : public MessageHandler, public Net::CharHandler CachedAttributes attribute; }; - void handleCharacterInfo(Net::MessageIn &msg); - void handleCharacterCreateResponse(Net::MessageIn &msg); - void handleCharacterDeleteResponse(Net::MessageIn &msg); - void handleCharacterSelectResponse(Net::MessageIn &msg); + void handleCharacterInfo(MessageIn &msg); + void handleCharacterCreateResponse(MessageIn &msg); + void handleCharacterDeleteResponse(MessageIn &msg); + void handleCharacterSelectResponse(MessageIn &msg); void updateCharacters(); diff --git a/src/net/manaserv/chathandler.cpp b/src/net/manaserv/chathandler.cpp index 8241baa7..d777fa35 100644 --- a/src/net/manaserv/chathandler.cpp +++ b/src/net/manaserv/chathandler.cpp @@ -74,7 +74,7 @@ ChatHandler::ChatHandler() chatHandler = this; } -void ChatHandler::handleMessage(Net::MessageIn &msg) +void ChatHandler::handleMessage(MessageIn &msg) { switch (msg.getId()) { @@ -143,7 +143,7 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) } } -void ChatHandler::handleGameChatMessage(Net::MessageIn &msg) +void ChatHandler::handleGameChatMessage(MessageIn &msg) { short id = msg.readInt16(); std::string chatMsg = msg.readString(); @@ -177,7 +177,7 @@ void ChatHandler::handleGameChatMessage(Net::MessageIn &msg) event.trigger(Event::ChatChannel); } -void ChatHandler::handleEnterChannelResponse(Net::MessageIn &msg) +void ChatHandler::handleEnterChannelResponse(MessageIn &msg) { if (msg.readInt8() == ERRMSG_OK) { @@ -212,7 +212,7 @@ void ChatHandler::handleEnterChannelResponse(Net::MessageIn &msg) } } -void ChatHandler::handleListChannelsResponse(Net::MessageIn &msg) +void ChatHandler::handleListChannelsResponse(MessageIn &msg) { SERVER_NOTICE(_("Listing channels.")) while (msg.getUnreadLength()) @@ -229,7 +229,7 @@ void ChatHandler::handleListChannelsResponse(Net::MessageIn &msg) SERVER_NOTICE(_("End of channel list.")) } -void ChatHandler::handlePrivateMessage(Net::MessageIn &msg) +void ChatHandler::handlePrivateMessage(MessageIn &msg) { std::string userNick = msg.readString(); std::string chatMsg = msg.readString(); @@ -240,7 +240,7 @@ void ChatHandler::handlePrivateMessage(Net::MessageIn &msg) event.trigger(Event::ChatChannel); } -void ChatHandler::handleAnnouncement(Net::MessageIn &msg) +void ChatHandler::handleAnnouncement(MessageIn &msg) { std::string chatMsg = msg.readString(); std::string sender = msg.readString(); @@ -249,7 +249,7 @@ void ChatHandler::handleAnnouncement(Net::MessageIn &msg) event.trigger(Event::ChatChannel); } -void ChatHandler::handleChatMessage(Net::MessageIn &msg) +void ChatHandler::handleChatMessage(MessageIn &msg) { short channelId = msg.readInt16(); std::string userNick = msg.readString(); @@ -266,7 +266,7 @@ void ChatHandler::handleChatMessage(Net::MessageIn &msg) } } -void ChatHandler::handleQuitChannelResponse(Net::MessageIn &msg) +void ChatHandler::handleQuitChannelResponse(MessageIn &msg) { if (msg.readInt8() == ERRMSG_OK) { @@ -276,7 +276,7 @@ void ChatHandler::handleQuitChannelResponse(Net::MessageIn &msg) } } -void ChatHandler::handleListChannelUsersResponse(Net::MessageIn &msg) +void ChatHandler::handleListChannelUsersResponse(MessageIn &msg) { std::string channelName = msg.readString(); std::string userNick; @@ -299,7 +299,7 @@ void ChatHandler::handleListChannelUsersResponse(Net::MessageIn &msg) } } -void ChatHandler::handleChannelEvent(Net::MessageIn &msg) +void ChatHandler::handleChannelEvent(MessageIn &msg) { short channelId = msg.readInt16(); char eventId = msg.readInt8(); @@ -353,7 +353,7 @@ void ChatHandler::handleChannelEvent(Net::MessageIn &msg) } } -void ChatHandler::handleWhoResponse(Net::MessageIn &msg) +void ChatHandler::handleWhoResponse(MessageIn &msg) { std::string userNick; diff --git a/src/net/manaserv/chathandler.h b/src/net/manaserv/chathandler.h index e0288412..7ae4227b 100644 --- a/src/net/manaserv/chathandler.h +++ b/src/net/manaserv/chathandler.h @@ -37,7 +37,7 @@ class ChatHandler : public MessageHandler, public Net::ChatHandler /** * Handle the given message appropriately. */ - void handleMessage(Net::MessageIn &msg); + void handleMessage(MessageIn &msg); void connect(); @@ -75,52 +75,52 @@ class ChatHandler : public MessageHandler, public Net::ChatHandler /** * Handle chat messages sent from the game server. */ - void handleGameChatMessage(Net::MessageIn &msg); + void handleGameChatMessage(MessageIn &msg); /** * Handle channel entry responses. */ - void handleEnterChannelResponse(Net::MessageIn &msg); + void handleEnterChannelResponse(MessageIn &msg); /** * Handle list channels responses. */ - void handleListChannelsResponse(Net::MessageIn &msg); + void handleListChannelsResponse(MessageIn &msg); /** * Handle private messages. */ - void handlePrivateMessage(Net::MessageIn &msg); + void handlePrivateMessage(MessageIn &msg); /** * Handle announcements. */ - void handleAnnouncement(Net::MessageIn &msg); + void handleAnnouncement(MessageIn &msg); /** * Handle chat messages. */ - void handleChatMessage(Net::MessageIn &msg); + void handleChatMessage(MessageIn &msg); /** * Handle quit channel responses. */ - void handleQuitChannelResponse(Net::MessageIn &msg); + void handleQuitChannelResponse(MessageIn &msg); /** * Handle list channel users responses. */ - void handleListChannelUsersResponse(Net::MessageIn &msg); + void handleListChannelUsersResponse(MessageIn &msg); /** * Handle channel events. */ - void handleChannelEvent(Net::MessageIn &msg); + void handleChannelEvent(MessageIn &msg); /** * Handle who responses. */ - void handleWhoResponse(Net::MessageIn &msg); + void handleWhoResponse(MessageIn &msg); }; } // namespace ManaServ diff --git a/src/net/manaserv/effecthandler.cpp b/src/net/manaserv/effecthandler.cpp index 06533be6..d0aaf081 100644 --- a/src/net/manaserv/effecthandler.cpp +++ b/src/net/manaserv/effecthandler.cpp @@ -27,9 +27,8 @@ #include "gui/viewport.h" -#include "net/messagein.h" - #include "net/manaserv/manaserv_protocol.h" +#include "net/manaserv/messagein.h" namespace ManaServ { @@ -44,7 +43,7 @@ EffectHandler::EffectHandler() handledMessages = _messages; } -void EffectHandler::handleMessage(Net::MessageIn &msg) +void EffectHandler::handleMessage(MessageIn &msg) { switch (msg.getId()) { @@ -62,7 +61,7 @@ void EffectHandler::handleMessage(Net::MessageIn &msg) } } -void EffectHandler::handleCreateEffectPos(Net::MessageIn &msg) +void EffectHandler::handleCreateEffectPos(MessageIn &msg) { int id = msg.readInt16(); uint16_t x = msg.readInt16(); @@ -70,7 +69,7 @@ void EffectHandler::handleCreateEffectPos(Net::MessageIn &msg) effectManager->trigger(id, x, y); } -void EffectHandler::handleCreateEffectBeing(Net::MessageIn &msg) +void EffectHandler::handleCreateEffectBeing(MessageIn &msg) { int eid = msg.readInt16(); int bid = msg.readInt16(); @@ -81,7 +80,7 @@ void EffectHandler::handleCreateEffectBeing(Net::MessageIn &msg) logger->log("Warning: CreateEffect called for unknown being #%d", bid); } -void EffectHandler::handleShake(Net::MessageIn &msg) +void EffectHandler::handleShake(MessageIn &msg) { int16_t intensityX = 0; int16_t intensityY = 0; diff --git a/src/net/manaserv/effecthandler.h b/src/net/manaserv/effecthandler.h index 712bded3..de81fea9 100644 --- a/src/net/manaserv/effecthandler.h +++ b/src/net/manaserv/effecthandler.h @@ -31,12 +31,12 @@ class EffectHandler : public MessageHandler public: EffectHandler(); - void handleMessage(Net::MessageIn &msg); + void handleMessage(MessageIn &msg); private: - void handleCreateEffectPos(Net::MessageIn &msg); - void handleCreateEffectBeing(Net::MessageIn &msg); - void handleShake(Net::MessageIn &msg); + void handleCreateEffectPos(MessageIn &msg); + void handleCreateEffectBeing(MessageIn &msg); + void handleShake(MessageIn &msg); }; } // namespace ManaServ diff --git a/src/net/manaserv/gamehandler.cpp b/src/net/manaserv/gamehandler.cpp index 89b80e68..265c0d8a 100644 --- a/src/net/manaserv/gamehandler.cpp +++ b/src/net/manaserv/gamehandler.cpp @@ -26,6 +26,7 @@ #include "net/manaserv/chathandler.h" #include "net/manaserv/connection.h" +#include "net/manaserv/messagein.h" #include "net/manaserv/messageout.h" extern Net::GameHandler *gameHandler; @@ -50,7 +51,7 @@ GameHandler::GameHandler() gameHandler = this; } -void GameHandler::handleMessage(Net::MessageIn &msg) +void GameHandler::handleMessage(MessageIn &msg) { switch (msg.getId()) { diff --git a/src/net/manaserv/gamehandler.h b/src/net/manaserv/gamehandler.h index 2d33710e..454cae43 100644 --- a/src/net/manaserv/gamehandler.h +++ b/src/net/manaserv/gamehandler.h @@ -36,7 +36,7 @@ class GameHandler : public MessageHandler, public Net::GameHandler public: GameHandler(); - void handleMessage(Net::MessageIn &msg); + void handleMessage(MessageIn &msg); void connect(); diff --git a/src/net/manaserv/guildhandler.cpp b/src/net/manaserv/guildhandler.cpp index 1378d205..cd22fcec 100644 --- a/src/net/manaserv/guildhandler.cpp +++ b/src/net/manaserv/guildhandler.cpp @@ -32,7 +32,6 @@ #include "gui/widgets/channeltab.h" -#include "net/messagein.h" #include "net/net.h" #include "net/manaserv/connection.h" @@ -70,7 +69,7 @@ GuildHandler::GuildHandler() guildHandler = this; } -void GuildHandler::handleMessage(Net::MessageIn &msg) +void GuildHandler::handleMessage(MessageIn &msg) { switch (msg.getId()) { @@ -265,7 +264,7 @@ void GuildHandler::handleMessage(Net::MessageIn &msg) } } -void GuildHandler::joinedGuild(Net::MessageIn &msg) +void GuildHandler::joinedGuild(MessageIn &msg) { std::string guildName = msg.readString(); short guildId = msg.readInt16(); diff --git a/src/net/manaserv/guildhandler.h b/src/net/manaserv/guildhandler.h index 0d3da7bf..d1232a6f 100644 --- a/src/net/manaserv/guildhandler.h +++ b/src/net/manaserv/guildhandler.h @@ -35,7 +35,7 @@ public: bool isSupported() { return true; } - void handleMessage(Net::MessageIn &msg); + void handleMessage(MessageIn &msg); void create(const std::string &name); @@ -63,7 +63,7 @@ public: void endAlliance(int guildId, int otherGuildId); protected: - void joinedGuild(Net::MessageIn &msg); + void joinedGuild(MessageIn &msg); }; } // namespace ManaServ diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp index 0ece6e11..b306869e 100644 --- a/src/net/manaserv/inventoryhandler.cpp +++ b/src/net/manaserv/inventoryhandler.cpp @@ -328,7 +328,7 @@ InventoryHandler::InventoryHandler() listen(Event::ItemChannel); } -void InventoryHandler::handleMessage(Net::MessageIn &msg) +void InventoryHandler::handleMessage(MessageIn &msg) { switch (msg.getId()) { diff --git a/src/net/manaserv/inventoryhandler.h b/src/net/manaserv/inventoryhandler.h index 0a07c38d..808acb96 100644 --- a/src/net/manaserv/inventoryhandler.h +++ b/src/net/manaserv/inventoryhandler.h @@ -125,7 +125,7 @@ class InventoryHandler : public MessageHandler, Net::InventoryHandler, public: InventoryHandler(); - void handleMessage(Net::MessageIn &msg); + void handleMessage(MessageIn &msg); void event(Event::Channel channel, const Event &event); diff --git a/src/net/manaserv/itemhandler.cpp b/src/net/manaserv/itemhandler.cpp index 5e46b9eb..4e29bb4f 100644 --- a/src/net/manaserv/itemhandler.cpp +++ b/src/net/manaserv/itemhandler.cpp @@ -40,7 +40,7 @@ ItemHandler::ItemHandler() handledMessages = _messages; } -void ItemHandler::handleMessage(Net::MessageIn &msg) +void ItemHandler::handleMessage(MessageIn &msg) { switch (msg.getId()) { diff --git a/src/net/manaserv/itemhandler.h b/src/net/manaserv/itemhandler.h index fef2fa53..e45db269 100644 --- a/src/net/manaserv/itemhandler.h +++ b/src/net/manaserv/itemhandler.h @@ -31,7 +31,7 @@ class ItemHandler : public MessageHandler public: ItemHandler(); - void handleMessage(Net::MessageIn &msg); + void handleMessage(MessageIn &msg); }; } // namespace ManaServ diff --git a/src/net/manaserv/loginhandler.cpp b/src/net/manaserv/loginhandler.cpp index 18fea9de..416e9422 100644 --- a/src/net/manaserv/loginhandler.cpp +++ b/src/net/manaserv/loginhandler.cpp @@ -59,7 +59,7 @@ LoginHandler::LoginHandler() loginHandler = this; } -void LoginHandler::handleMessage(Net::MessageIn &msg) +void LoginHandler::handleMessage(MessageIn &msg) { switch (msg.getId()) { @@ -250,13 +250,13 @@ void LoginHandler::handleMessage(Net::MessageIn &msg) } } -void LoginHandler::handleLoginRandomResponse(Net::MessageIn &msg) +void LoginHandler::handleLoginRandomResponse(MessageIn &msg) { mLoginData->randomSeed = msg.readString(); loginAccountContinue(); } -void LoginHandler::handleLoginResponse(Net::MessageIn &msg) +void LoginHandler::handleLoginResponse(MessageIn &msg) { const int errMsg = msg.readInt8(); @@ -294,7 +294,7 @@ void LoginHandler::handleLoginResponse(Net::MessageIn &msg) } } -void LoginHandler::handleRegisterResponse(Net::MessageIn &msg) +void LoginHandler::handleRegisterResponse(MessageIn &msg) { const int errMsg = msg.readInt8(); @@ -331,7 +331,7 @@ void LoginHandler::handleRegisterResponse(Net::MessageIn &msg) } } -void LoginHandler::readServerInfo(Net::MessageIn &msg) +void LoginHandler::readServerInfo(MessageIn &msg) { // Safety check for outdated manaserv versions (remove me later) if (msg.getUnreadLength() == 0) diff --git a/src/net/manaserv/loginhandler.h b/src/net/manaserv/loginhandler.h index 3145beab..33cc83ad 100644 --- a/src/net/manaserv/loginhandler.h +++ b/src/net/manaserv/loginhandler.h @@ -36,7 +36,7 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler public: LoginHandler(); - void handleMessage(Net::MessageIn &msg); + void handleMessage(MessageIn &msg); void connect(); @@ -77,11 +77,11 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler void reconnect(); private: - void handleLoginRandomResponse(Net::MessageIn &msg); - void handleLoginResponse(Net::MessageIn &msg); - void handleRegisterResponse(Net::MessageIn &msg); + void handleLoginRandomResponse(MessageIn &msg); + void handleLoginResponse(MessageIn &msg); + void handleRegisterResponse(MessageIn &msg); - void readServerInfo(Net::MessageIn &msg); + void readServerInfo(MessageIn &msg); void loginAccountContinue(); diff --git a/src/net/manaserv/messagehandler.cpp b/src/net/manaserv/messagehandler.cpp index 79d6667c..6ebd8c3c 100644 --- a/src/net/manaserv/messagehandler.cpp +++ b/src/net/manaserv/messagehandler.cpp @@ -32,4 +32,4 @@ MessageHandler::~MessageHandler() unregisterHandler(this); } -} +} // namespace ManaServ diff --git a/src/net/manaserv/messagehandler.h b/src/net/manaserv/messagehandler.h index 97708415..6e0221cb 100644 --- a/src/net/manaserv/messagehandler.h +++ b/src/net/manaserv/messagehandler.h @@ -24,8 +24,12 @@ #include "net/messagehandler.h" +#include <memory> + namespace ManaServ { +class MessageIn; + /** * \ingroup Network */ @@ -34,10 +38,11 @@ class MessageHandler : public Net::MessageHandler public: ~MessageHandler(); + virtual void handleMessage(MessageIn &msg) = 0; }; typedef const std::auto_ptr<MessageHandler> MessageHandlerPtr; -} +} // namespace ManaServ #endif // NET_MANASERV_MESSAGEHANDLER_H diff --git a/src/net/manaserv/messagein.cpp b/src/net/manaserv/messagein.cpp index 4994de4c..aeb02b8d 100644 --- a/src/net/manaserv/messagein.cpp +++ b/src/net/manaserv/messagein.cpp @@ -27,12 +27,25 @@ namespace ManaServ { MessageIn::MessageIn(const char *data, unsigned int length): - Net::MessageIn(data, length) + mData(data), + mLength(length), + mPos(0) { // Read the message ID mId = readInt16(); } +uint8_t MessageIn::readInt8() +{ + uint8_t value = 0; + if (mPos < mLength) + { + value = mData[mPos]; + } + mPos++; + return value; +} + uint16_t MessageIn::readInt16() { uint16_t value = 0; @@ -59,4 +72,26 @@ uint32_t MessageIn::readInt32() return value; } +std::string MessageIn::readString(int length) +{ + // Get string length + if (length < 0) + length = readInt16(); + + // Make sure the string isn't erroneous + if (length < 0 || mPos + length > mLength) + { + mPos = mLength + 1; + return ""; + } + + // Read the string + char const *stringBeg = mData + mPos; + char const *stringEnd = (char const *)memchr(stringBeg, '\0', length); + std::string readString(stringBeg, + stringEnd ? stringEnd - stringBeg : length); + mPos += length; + return readString; } + +} // ManaServ diff --git a/src/net/manaserv/messagein.h b/src/net/manaserv/messagein.h index 97e68812..ef0c29bf 100644 --- a/src/net/manaserv/messagein.h +++ b/src/net/manaserv/messagein.h @@ -22,24 +22,71 @@ #ifndef NET_MANASERV_MESSAGEIN_H #define NET_MANASERV_MESSAGEIN_H -#include "net/messagein.h" +#include <cstdint> +#include <string> namespace ManaServ { /** - * Used for parsing an incoming message. + * Used for parsing an incoming message from manaserv. * * \ingroup Network */ -class MessageIn : public Net::MessageIn +class MessageIn { public: MessageIn(const char *data, unsigned int length); + /** + * Returns the message ID. + */ + uint16_t getId() const { return mId; } + + /** + * Returns the message length. + */ + unsigned int getLength() const { return mLength; } + + /** + * Returns the length of unread data. + */ + unsigned int getUnreadLength() const { return mLength - mPos; } + + /** + * Reads an unsigned 8-bit integer from the message. + */ + uint8_t readInt8(); + + /** + * Reads an unsigned 16-bit integer from the message. + */ uint16_t readInt16(); + + /** + * Reads an unsigned 32-bit integer from the message. + */ uint32_t readInt32(); + + /** + * Reads a string. If a length is not given (-1), it is assumed + * that the length of the string is stored in a short at the + * start of the string. + */ + std::string readString(int length = -1); + + private: + const char *mData; /**< The message data. */ + unsigned int mLength; /**< The length of the data. */ + unsigned short mId; /**< The message ID. */ + + /** + * Actual position in the packet. From 0 to packet->length. + * A value bigger than packet->length means EOP was reached when + * reading it. + */ + unsigned int mPos; }; -} +} // namespace ManaServ #endif // NET_MANASERV_MESSAGEIN_H diff --git a/src/net/manaserv/messageout.cpp b/src/net/manaserv/messageout.cpp index 6a8482e8..7cecc03d 100644 --- a/src/net/manaserv/messageout.cpp +++ b/src/net/manaserv/messageout.cpp @@ -28,7 +28,9 @@ namespace ManaServ { MessageOut::MessageOut(uint16_t id): - Net::MessageOut(id) + mData(0), + mDataSize(0), + mPos(0) { writeInt16(id); } @@ -44,6 +46,13 @@ void MessageOut::expand(size_t bytes) mDataSize = mPos + bytes; } +void MessageOut::writeInt8(uint8_t value) +{ + expand(1); + mData[mPos] = value; + mPos += 1; +} + void MessageOut::writeInt16(uint16_t value) { expand(2); @@ -60,4 +69,31 @@ void MessageOut::writeInt32(uint32_t value) mPos += 4; } +void MessageOut::writeString(const std::string &string, int length) +{ + int stringLength = string.length(); + if (length < 0) + { + // Write the length at the start if not fixed + writeInt16(stringLength); + length = stringLength; + } + else if (length < stringLength) + { + // Make sure the length of the string is no longer than specified + stringLength = length; + } + expand(length); + + // Write the actual string + memcpy(mData + mPos, string.data(), stringLength); + + // Pad remaining space with zeros + if (length > stringLength) + { + memset(mData + mPos + stringLength, '\0', length - stringLength); + } + mPos += length; +} + } // namespace ManaServ diff --git a/src/net/manaserv/messageout.h b/src/net/manaserv/messageout.h index 59fc148f..9a87cf1c 100644 --- a/src/net/manaserv/messageout.h +++ b/src/net/manaserv/messageout.h @@ -22,21 +22,55 @@ #ifndef NET_MANASERV_MESSAGEOUT_H #define NET_MANASERV_MESSAGEOUT_H -#include "net/messageout.h" +#include <cstdint> +#include <string> namespace ManaServ { -class MessageOut : public Net::MessageOut +/** + * Used for building an outgoing message to manaserv. + * + * \ingroup Network + */ +class MessageOut { public: MessageOut(uint16_t id); ~MessageOut(); + /** + * Writes an unsigned 8-bit integer to the message. + */ + void writeInt8(uint8_t value); + + /** + * Writes an unsigned 16-bit integer to the message. + */ void writeInt16(uint16_t value); + + /** + * Writes an unsigned 32-bit integer to the message. + */ void writeInt32(uint32_t value); - protected: + /** + * Writes a string. If a fixed length is not given (-1), it is stored + * as a short at the start of the string. + */ + void writeString(const std::string &string, int length = -1); + + /** + * Returns the content of the message. + */ + char *getData() const { return mData; } + + /** + * Returns the length of the data. + */ + unsigned int getDataSize() const { return mDataSize; } + + private: /** * Expand the packet data to be able to hold more data. * @@ -45,8 +79,12 @@ class MessageOut : public Net::MessageOut * added. */ void expand(size_t size); + + char *mData; /**< Data building up. */ + unsigned int mDataSize; /**< Size of data. */ + unsigned int mPos; /**< Position in the data. */ }; -} +} // namespace ManaServ #endif // NET_MANASERV_MESSAGEOUT_H diff --git a/src/net/manaserv/npchandler.cpp b/src/net/manaserv/npchandler.cpp index 71b761ab..6b79fb90 100644 --- a/src/net/manaserv/npchandler.cpp +++ b/src/net/manaserv/npchandler.cpp @@ -53,7 +53,7 @@ NpcHandler::NpcHandler() npcHandler = this; } -void NpcHandler::handleMessage(Net::MessageIn &msg) +void NpcHandler::handleMessage(MessageIn &msg) { Being *being = actorSpriteManager->findBeing(msg.readInt16()); if (!being || being->getType() != ActorSprite::NPC) diff --git a/src/net/manaserv/npchandler.h b/src/net/manaserv/npchandler.h index 29821da5..0f42385d 100644 --- a/src/net/manaserv/npchandler.h +++ b/src/net/manaserv/npchandler.h @@ -37,7 +37,7 @@ class NpcHandler : public MessageHandler, public Net::NpcHandler public: NpcHandler(); - void handleMessage(Net::MessageIn &msg); + void handleMessage(MessageIn &msg); void startShopping(int beingId); diff --git a/src/net/manaserv/partyhandler.cpp b/src/net/manaserv/partyhandler.cpp index 2bb688e0..a0d4b6d9 100644 --- a/src/net/manaserv/partyhandler.cpp +++ b/src/net/manaserv/partyhandler.cpp @@ -65,7 +65,7 @@ PartyHandler::PartyHandler(): mParty->setName("Party"); } -void PartyHandler::handleMessage(Net::MessageIn &msg) +void PartyHandler::handleMessage(MessageIn &msg) { switch (msg.getId()) { diff --git a/src/net/manaserv/partyhandler.h b/src/net/manaserv/partyhandler.h index 4b316bd2..6c526f73 100644 --- a/src/net/manaserv/partyhandler.h +++ b/src/net/manaserv/partyhandler.h @@ -37,7 +37,7 @@ class PartyHandler : public MessageHandler, public Net::PartyHandler public: PartyHandler(); - void handleMessage(Net::MessageIn &msg); + void handleMessage(MessageIn &msg); void create(const std::string &name = ""); diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index adb60fb3..841ead56 100644 --- a/src/net/manaserv/playerhandler.cpp +++ b/src/net/manaserv/playerhandler.cpp @@ -85,7 +85,7 @@ PlayerHandler::PlayerHandler() playerHandler = this; } -void PlayerHandler::handleMessage(Net::MessageIn &msg) +void PlayerHandler::handleMessage(MessageIn &msg) { switch (msg.getId()) { @@ -277,7 +277,7 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg) } } -void PlayerHandler::handleMapChangeMessage(Net::MessageIn &msg) +void PlayerHandler::handleMapChangeMessage(MessageIn &msg) { const std::string mapName = msg.readString(); const unsigned short x = msg.readInt16(); diff --git a/src/net/manaserv/playerhandler.h b/src/net/manaserv/playerhandler.h index 28342f2d..abb29e9b 100644 --- a/src/net/manaserv/playerhandler.h +++ b/src/net/manaserv/playerhandler.h @@ -41,7 +41,7 @@ class PlayerHandler : public MessageHandler, public Net::PlayerHandler public: PlayerHandler(); - void handleMessage(Net::MessageIn &msg); + void handleMessage(MessageIn &msg); void attack(int id); void emote(int emoteId); @@ -73,7 +73,7 @@ class PlayerHandler : public MessageHandler, public Net::PlayerHandler { return true; } private: - void handleMapChangeMessage(Net::MessageIn &msg); + void handleMapChangeMessage(MessageIn &msg); }; } // namespace ManaServ diff --git a/src/net/manaserv/specialhandler.cpp b/src/net/manaserv/specialhandler.cpp index 4cd0ce2b..0a477ff8 100644 --- a/src/net/manaserv/specialhandler.cpp +++ b/src/net/manaserv/specialhandler.cpp @@ -37,7 +37,7 @@ SpecialHandler::SpecialHandler() specialHandler = this; } -void SpecialHandler::handleMessage(Net::MessageIn &msg) +void SpecialHandler::handleMessage(MessageIn &msg) { // TODO } diff --git a/src/net/manaserv/specialhandler.h b/src/net/manaserv/specialhandler.h index 29de76bb..ee26b3b7 100644 --- a/src/net/manaserv/specialhandler.h +++ b/src/net/manaserv/specialhandler.h @@ -33,7 +33,7 @@ class SpecialHandler : public MessageHandler, public Net::SpecialHandler public: SpecialHandler(); - void handleMessage(Net::MessageIn &msg); + void handleMessage(MessageIn &msg); void use(int id); diff --git a/src/net/manaserv/tradehandler.cpp b/src/net/manaserv/tradehandler.cpp index b5d526ae..ff7849ff 100644 --- a/src/net/manaserv/tradehandler.cpp +++ b/src/net/manaserv/tradehandler.cpp @@ -97,7 +97,7 @@ void TradeHandler::setAcceptTradeRequests(bool acceptTradeRequests) SERVER_NOTICE(_("Ignoring incoming trade requests.")) } -void TradeHandler::handleMessage(Net::MessageIn &msg) +void TradeHandler::handleMessage(MessageIn &msg) { switch (msg.getId()) { diff --git a/src/net/manaserv/tradehandler.h b/src/net/manaserv/tradehandler.h index 321b942f..5d20c14e 100644 --- a/src/net/manaserv/tradehandler.h +++ b/src/net/manaserv/tradehandler.h @@ -33,7 +33,7 @@ class TradeHandler : public MessageHandler, public Net::TradeHandler public: TradeHandler(); - void handleMessage(Net::MessageIn &msg); + void handleMessage(MessageIn &msg); /** * Returns whether trade requests are accepted. |