From a3635c94a9f1074736f243b0f7de7ab1c8aa14d0 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 10 Apr 2013 15:47:42 +0300 Subject: Improve partyhandler class. --- src/net/ea/partyhandler.cpp | 49 ++++++++++++++++------------------------ src/net/ea/partyhandler.h | 32 ++++++++++++-------------- src/net/eathena/partyhandler.cpp | 20 ++++++++-------- src/net/eathena/partyhandler.h | 23 ++++++++++--------- src/net/partyhandler.h | 26 ++++++++++----------- src/net/tmwa/partyhandler.cpp | 20 ++++++++-------- src/net/tmwa/partyhandler.h | 23 ++++++++++--------- 7 files changed, 91 insertions(+), 102 deletions(-) diff --git a/src/net/ea/partyhandler.cpp b/src/net/ea/partyhandler.cpp index 92cf48a2d..642688ddb 100644 --- a/src/net/ea/partyhandler.cpp +++ b/src/net/ea/partyhandler.cpp @@ -49,28 +49,21 @@ PartyHandler::~PartyHandler() partyTab = nullptr; } -void PartyHandler::join(int partyId A_UNUSED) +void PartyHandler::join(const int partyId A_UNUSED) const { - // TODO? } -void PartyHandler::requestPartyMembers() const -{ - // Our eAthena doesn't have this message - // Not needed anyways -} - -void PartyHandler::reload() +void PartyHandler::reload() const { taParty = Party::getParty(1); } -void PartyHandler::clear() +void PartyHandler::clear() const { taParty = nullptr; } -void PartyHandler::processPartyCreate(Net::MessageIn &msg) +void PartyHandler::processPartyCreate(Net::MessageIn &msg) const { if (msg.readInt8()) NotifyManager::notify(NotifyManager::PARTY_CREATE_FAILED); @@ -78,7 +71,7 @@ void PartyHandler::processPartyCreate(Net::MessageIn &msg) NotifyManager::notify(NotifyManager::PARTY_CREATED); } -void PartyHandler::processPartyInfo(Net::MessageIn &msg) +void PartyHandler::processPartyInfo(Net::MessageIn &msg) const { bool oldParty = false; std::set names; @@ -126,15 +119,13 @@ void PartyHandler::processPartyInfo(Net::MessageIn &msg) { if (oldParty) { - //member = Ea::taParty->getMember(id); if (names.find(nick) == names.end()) { NotifyManager::notify(NotifyManager::PARTY_USER_JOINED, nick); } } - PartyMember *member = Ea::taParty->addMember(id, nick); - + PartyMember *const member = Ea::taParty->addMember(id, nick); if (member) { member->setLeader(leader); @@ -154,12 +145,12 @@ void PartyHandler::processPartyInfo(Net::MessageIn &msg) } } -void PartyHandler::processPartyInviteResponse(Net::MessageIn &msg) +void PartyHandler::processPartyInviteResponse(Net::MessageIn &msg) const { if (!Ea::partyTab) return; - std::string nick = msg.readString(24); + const std::string nick = msg.readString(24); switch (msg.readInt8()) { @@ -183,16 +174,16 @@ void PartyHandler::processPartyInviteResponse(Net::MessageIn &msg) } } -void PartyHandler::processPartyInvited(Net::MessageIn &msg) +void PartyHandler::processPartyInvited(Net::MessageIn &msg) const { const int id = msg.readInt32(); - std::string partyName = msg.readString(24); - std::string nick(""); - const Being *being; + const std::string partyName = msg.readString(24); + std::string nick; if (actorSpriteManager) { - if ((being = actorSpriteManager->findBeing(id))) + const Being *const being = actorSpriteManager->findBeing(id); + if (being) { if (being->getType() == Being::PLAYER) nick = being->getName(); @@ -273,7 +264,7 @@ void PartyHandler::processPartySettings(Net::MessageIn &msg) } } -void PartyHandler::processPartyMove(Net::MessageIn &msg) +void PartyHandler::processPartyMove(Net::MessageIn &msg) const { const int id = msg.readInt32(); // id PartyMember *m = nullptr; @@ -301,10 +292,10 @@ void PartyHandler::processPartyMove(Net::MessageIn &msg) } } -void PartyHandler::processPartyLeave(Net::MessageIn &msg) +void PartyHandler::processPartyLeave(Net::MessageIn &msg) const { const int id = msg.readInt32(); - std::string nick = msg.readString(24); + const std::string nick = msg.readString(24); msg.readInt8(); // fail if (!player_node) return; @@ -341,7 +332,7 @@ void PartyHandler::processPartyLeave(Net::MessageIn &msg) } } -void PartyHandler::processPartyUpdateHp(Net::MessageIn &msg) +void PartyHandler::processPartyUpdateHp(Net::MessageIn &msg) const { const int id = msg.readInt32(); const int hp = msg.readInt16(); @@ -364,7 +355,7 @@ void PartyHandler::processPartyUpdateHp(Net::MessageIn &msg) } } -void PartyHandler::processPartyUpdateCoords(Net::MessageIn &msg) +void PartyHandler::processPartyUpdateCoords(Net::MessageIn &msg) const { const int id = msg.readInt32(); // id PartyMember *m = nullptr; @@ -382,14 +373,14 @@ void PartyHandler::processPartyUpdateCoords(Net::MessageIn &msg) } } -void PartyHandler::processPartyMessage(Net::MessageIn &msg) +void PartyHandler::processPartyMessage(Net::MessageIn &msg) const { const int msgLength = msg.readInt16() - 8; if (msgLength <= 0) return; const int id = msg.readInt32(); - std::string chatMsg = msg.readString(msgLength); + const std::string chatMsg = msg.readString(msgLength); if (Ea::taParty && Ea::partyTab) { diff --git a/src/net/ea/partyhandler.h b/src/net/ea/partyhandler.h index c113a6a3b..62d08034a 100644 --- a/src/net/ea/partyhandler.h +++ b/src/net/ea/partyhandler.h @@ -42,41 +42,39 @@ class PartyHandler : public Net::PartyHandler ~PartyHandler(); - void join(int partyId); + void join(const int partyId) const override; - void requestPartyMembers() const; - - PartyShare getShareExperience() const A_WARN_UNUSED + PartyShare getShareExperience() const override A_WARN_UNUSED { return mShareExp; } - PartyShare getShareItems() const A_WARN_UNUSED + PartyShare getShareItems() const override A_WARN_UNUSED { return mShareItems; } - void reload(); + void reload() const; - void clear(); + void clear() const override; - ChatTab *getTab(); + ChatTab *getTab() override; - virtual void processPartyCreate(Net::MessageIn &msg); + virtual void processPartyCreate(Net::MessageIn &msg) const; - virtual void processPartyInfo(Net::MessageIn &msg); + virtual void processPartyInfo(Net::MessageIn &msg) const; - virtual void processPartyInviteResponse(Net::MessageIn &msg); + virtual void processPartyInviteResponse(Net::MessageIn &msg) const; - virtual void processPartyInvited(Net::MessageIn &msg); + virtual void processPartyInvited(Net::MessageIn &msg) const; virtual void processPartySettings(Net::MessageIn &msg); - virtual void processPartyMove(Net::MessageIn &msg); + virtual void processPartyMove(Net::MessageIn &msg) const; - virtual void processPartyLeave(Net::MessageIn &msg); + virtual void processPartyLeave(Net::MessageIn &msg) const; - virtual void processPartyUpdateHp(Net::MessageIn &msg); + virtual void processPartyUpdateHp(Net::MessageIn &msg) const; - virtual void processPartyUpdateCoords(Net::MessageIn &msg); + virtual void processPartyUpdateCoords(Net::MessageIn &msg) const; - virtual void processPartyMessage(Net::MessageIn &msg); + virtual void processPartyMessage(Net::MessageIn &msg) const; protected: PartyShare mShareExp; diff --git a/src/net/eathena/partyhandler.cpp b/src/net/eathena/partyhandler.cpp index 9f7772757..b128d3879 100644 --- a/src/net/eathena/partyhandler.cpp +++ b/src/net/eathena/partyhandler.cpp @@ -102,13 +102,13 @@ void PartyHandler::handleMessage(Net::MessageIn &msg) } } -void PartyHandler::create(const std::string &name) +void PartyHandler::create(const std::string &name) const { MessageOut outMsg(CMSG_PARTY_CREATE); outMsg.writeString(name.substr(0, 23), 24); } -void PartyHandler::invite(Being *being) +void PartyHandler::invite(Being *const being) const { if (being) { @@ -117,7 +117,7 @@ void PartyHandler::invite(Being *being) } } -void PartyHandler::invite(const std::string &name) +void PartyHandler::invite(const std::string &name) const { if (!actorSpriteManager) return; @@ -132,7 +132,7 @@ void PartyHandler::invite(const std::string &name) } void PartyHandler::inviteResponse(const std::string &inviter A_UNUSED, - bool accept) + const bool accept) const { if (player_node) { @@ -142,12 +142,12 @@ void PartyHandler::inviteResponse(const std::string &inviter A_UNUSED, } } -void PartyHandler::leave() +void PartyHandler::leave() const { MessageOut outMsg(CMSG_PARTY_LEAVE); } -void PartyHandler::kick(Being *being) +void PartyHandler::kick(Being *const being) const { if (being) { @@ -157,7 +157,7 @@ void PartyHandler::kick(Being *being) } } -void PartyHandler::kick(const std::string &name) +void PartyHandler::kick(const std::string &name) const { if (!Ea::taParty) return; @@ -174,14 +174,14 @@ void PartyHandler::kick(const std::string &name) outMsg.writeString(name, 24); //Unused } -void PartyHandler::chat(const std::string &text) +void PartyHandler::chat(const std::string &text) const { MessageOut outMsg(CMSG_PARTY_MESSAGE); outMsg.writeInt16(static_cast(text.length() + 4)); outMsg.writeString(text, static_cast(text.length())); } -void PartyHandler::setShareExperience(PartyShare share) +void PartyHandler::setShareExperience(const PartyShare share) const { if (share == PARTY_SHARE_NOT_POSSIBLE) return; @@ -191,7 +191,7 @@ void PartyHandler::setShareExperience(PartyShare share) outMsg.writeInt16(mShareItems); } -void PartyHandler::setShareItems(PartyShare share) +void PartyHandler::setShareItems(const PartyShare share) const { if (share == PARTY_SHARE_NOT_POSSIBLE) return; diff --git a/src/net/eathena/partyhandler.h b/src/net/eathena/partyhandler.h index bf58b58aa..7e3e6630b 100644 --- a/src/net/eathena/partyhandler.h +++ b/src/net/eathena/partyhandler.h @@ -41,27 +41,28 @@ class PartyHandler final : public MessageHandler, public Ea::PartyHandler ~PartyHandler(); - void handleMessage(Net::MessageIn &msg); + void handleMessage(Net::MessageIn &msg) override; - void create(const std::string &name); + void create(const std::string &name) const override; - void invite(Being *being); + void invite(Being *const being) const override; - void invite(const std::string &name); + void invite(const std::string &name) const override; - void inviteResponse(const std::string &inviter, bool accept); + void inviteResponse(const std::string &inviter, + const bool accept) const override; - void leave(); + void leave() const override; - void kick(Being *being); + void kick(Being *const being) const override; - void kick(const std::string &name); + void kick(const std::string &name) const override; - void chat(const std::string &text); + void chat(const std::string &text) const override; - void setShareExperience(PartyShare share); + void setShareExperience(const PartyShare share) const override; - void setShareItems(PartyShare share); + void setShareItems(const PartyShare share) const override; }; } // namespace EAthena diff --git a/src/net/partyhandler.h b/src/net/partyhandler.h index 553f73e83..4929fc6da 100644 --- a/src/net/partyhandler.h +++ b/src/net/partyhandler.h @@ -48,36 +48,34 @@ class PartyHandler virtual ~PartyHandler() { } - virtual void create(const std::string &name) = 0; + virtual void create(const std::string &name) const = 0; - virtual void join(int partyId) = 0; + virtual void join(const int partyId) const = 0; - virtual void invite(Being *player) = 0; + virtual void invite(Being *const player) const = 0; - virtual void invite(const std::string &name) = 0; + virtual void invite(const std::string &name) const = 0; virtual void inviteResponse(const std::string &inviter, - bool accept) = 0; + const bool accept) const = 0; - virtual void leave() = 0; + virtual void leave() const = 0; - virtual void kick(Being *player) = 0; + virtual void kick(Being *const player) const = 0; - virtual void kick(const std::string &name) = 0; + virtual void kick(const std::string &name) const = 0; - virtual void chat(const std::string &text) = 0; - - virtual void requestPartyMembers() const = 0; + virtual void chat(const std::string &text) const = 0; virtual PartyShare getShareExperience() const A_WARN_UNUSED = 0; - virtual void setShareExperience(PartyShare share) = 0; + virtual void setShareExperience(const PartyShare share) const = 0; virtual PartyShare getShareItems() const A_WARN_UNUSED = 0; - virtual void setShareItems(PartyShare share) = 0; + virtual void setShareItems(const PartyShare share) const = 0; - virtual void clear() = 0; + virtual void clear() const = 0; virtual ChatTab *getTab() = 0; }; diff --git a/src/net/tmwa/partyhandler.cpp b/src/net/tmwa/partyhandler.cpp index 583bfa60f..f86e030d1 100644 --- a/src/net/tmwa/partyhandler.cpp +++ b/src/net/tmwa/partyhandler.cpp @@ -104,13 +104,13 @@ void PartyHandler::handleMessage(Net::MessageIn &msg) BLOCK_END("PartyHandler::handleMessage") } -void PartyHandler::create(const std::string &name) +void PartyHandler::create(const std::string &name) const { MessageOut outMsg(CMSG_PARTY_CREATE); outMsg.writeString(name.substr(0, 23), 24); } -void PartyHandler::invite(Being *being) +void PartyHandler::invite(Being *const being) const { if (being) { @@ -119,7 +119,7 @@ void PartyHandler::invite(Being *being) } } -void PartyHandler::invite(const std::string &name) +void PartyHandler::invite(const std::string &name) const { if (!actorSpriteManager) return; @@ -134,7 +134,7 @@ void PartyHandler::invite(const std::string &name) } void PartyHandler::inviteResponse(const std::string &inviter A_UNUSED, - bool accept) + const bool accept) const { if (player_node) { @@ -144,12 +144,12 @@ void PartyHandler::inviteResponse(const std::string &inviter A_UNUSED, } } -void PartyHandler::leave() +void PartyHandler::leave() const { MessageOut outMsg(CMSG_PARTY_LEAVE); } -void PartyHandler::kick(Being *being) +void PartyHandler::kick(Being *const being) const { if (being) { @@ -159,7 +159,7 @@ void PartyHandler::kick(Being *being) } } -void PartyHandler::kick(const std::string &name) +void PartyHandler::kick(const std::string &name) const { if (!Ea::taParty) return; @@ -176,14 +176,14 @@ void PartyHandler::kick(const std::string &name) outMsg.writeString(name, 24); //Unused } -void PartyHandler::chat(const std::string &text) +void PartyHandler::chat(const std::string &text) const { MessageOut outMsg(CMSG_PARTY_MESSAGE); outMsg.writeInt16(static_cast(text.length() + 4)); outMsg.writeString(text, static_cast(text.length())); } -void PartyHandler::setShareExperience(PartyShare share) +void PartyHandler::setShareExperience(const PartyShare share) const { if (share == PARTY_SHARE_NOT_POSSIBLE) return; @@ -193,7 +193,7 @@ void PartyHandler::setShareExperience(PartyShare share) outMsg.writeInt16(static_cast(mShareItems)); } -void PartyHandler::setShareItems(PartyShare share) +void PartyHandler::setShareItems(const PartyShare share) const { if (share == PARTY_SHARE_NOT_POSSIBLE) return; diff --git a/src/net/tmwa/partyhandler.h b/src/net/tmwa/partyhandler.h index 352e57d7d..6efd87868 100644 --- a/src/net/tmwa/partyhandler.h +++ b/src/net/tmwa/partyhandler.h @@ -41,27 +41,28 @@ class PartyHandler final : public MessageHandler, public Ea::PartyHandler ~PartyHandler(); - void handleMessage(Net::MessageIn &msg); + void handleMessage(Net::MessageIn &msg) override; - void create(const std::string &name); + void create(const std::string &name) const override; - void invite(Being *being); + void invite(Being *const being) const override; - void invite(const std::string &name); + void invite(const std::string &name) const override; - void inviteResponse(const std::string &inviter, bool accept); + void inviteResponse(const std::string &inviter, + const bool accept) const override; - void leave(); + void leave() const override; - void kick(Being *being); + void kick(Being *const being) const override; - void kick(const std::string &name); + void kick(const std::string &name) const override; - void chat(const std::string &text); + void chat(const std::string &text) const override; - void setShareExperience(PartyShare share); + void setShareExperience(const PartyShare share) const override; - void setShareItems(PartyShare share); + void setShareItems(const PartyShare share) const override; }; } // namespace TmwAthena -- cgit v1.2.3-70-g09d2