diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-07-30 01:02:50 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-07-30 05:02:46 +0300 |
commit | 0e9ef0640cab30431bef8a4683a5da549d5c8f88 (patch) | |
tree | b3866e49869019a3278a71290fc78209bac51972 /src/net/tmwa/partyhandler.cpp | |
parent | c8b18b47abbb325b6cc4b34abbad52b03825e4f9 (diff) | |
download | manaplus-0e9ef0640cab30431bef8a4683a5da549d5c8f88.tar.gz manaplus-0e9ef0640cab30431bef8a4683a5da549d5c8f88.tar.bz2 manaplus-0e9ef0640cab30431bef8a4683a5da549d5c8f88.tar.xz manaplus-0e9ef0640cab30431bef8a4683a5da549d5c8f88.zip |
Extract shared logic from guildhandler and partyhandler netcode to ea namespace.
Diffstat (limited to 'src/net/tmwa/partyhandler.cpp')
-rw-r--r-- | src/net/tmwa/partyhandler.cpp | 414 |
1 files changed, 20 insertions, 394 deletions
diff --git a/src/net/tmwa/partyhandler.cpp b/src/net/tmwa/partyhandler.cpp index 1526100f6..5bbf8baf3 100644 --- a/src/net/tmwa/partyhandler.cpp +++ b/src/net/tmwa/partyhandler.cpp @@ -21,36 +21,26 @@ #include "net/tmwa/partyhandler.h" #include "actorspritemanager.h" -#include "event.h" #include "localplayer.h" #include "log.h" -#include "gui/socialwindow.h" - #include "net/messagein.h" -#include "net/messageout.h" #include "net/tmwa/protocol.h" #include "net/tmwa/gui/partytab.h" #include "utils/gettext.h" -#include "utils/stringutils.h" #include "debug.h" -#define PARTY_ID 1 - extern Net::PartyHandler *partyHandler; namespace TmwAthena { -PartyTab *partyTab = 0; -Party *taParty; - -PartyHandler::PartyHandler(): - mShareExp(PARTY_SHARE_UNKNOWN), mShareItems(PARTY_SHARE_UNKNOWN) +PartyHandler::PartyHandler() : + Ea::PartyHandler() { static const Uint16 _messages[] = { @@ -68,13 +58,10 @@ PartyHandler::PartyHandler(): }; handledMessages = _messages; partyHandler = this; - taParty = Party::getParty(1); } PartyHandler::~PartyHandler() { - delete partyTab; - partyTab = 0; } void PartyHandler::handleMessage(Net::MessageIn &msg) @@ -82,374 +69,34 @@ void PartyHandler::handleMessage(Net::MessageIn &msg) switch (msg.getId()) { case SMSG_PARTY_CREATE: - if (msg.readInt8()) - SERVER_NOTICE(_("Could not create party.")) - else - SERVER_NOTICE(_("Party successfully created.")) + processPartyCreate(msg); break; case SMSG_PARTY_INFO: - { - bool oldParty = false; - std::set<std::string> names; - if (!taParty) - { - logger->log1("error: party empty in SMSG_PARTY_INFO"); - taParty = Party::getParty(1); - } - if (taParty) - { - if (taParty->getNumberOfElements() > 1) - { - oldParty = true; - - taParty->getNamesSet(names); - } - } - - if (!player_node) - logger->log1("error: player_node==0 in SMSG_PARTY_INFO"); - - if (taParty) - taParty->clearMembers(); - - int length = msg.readInt16(); - if (taParty) - taParty->setName(msg.readString(24)); - - int count = (length - 28) / 46; - if (player_node && taParty) - { - player_node->setParty(taParty); - player_node->setPartyName(taParty->getName()); - } - - for (int i = 0; i < count; i++) - { - int id = msg.readInt32(); - std::string nick = msg.readString(24); - std::string map = msg.readString(16); - bool leader = msg.readInt8() == 0; - bool online = msg.readInt8() == 0; - - if (taParty) - { - PartyMember *member = 0; - if (oldParty) - { - //member = taParty->getMember(id); - if (partyTab && names.find(nick) == names.end()) - { - partyTab->chatLog(strprintf( - _("%s has joined your party."), - nick.c_str()), BY_SERVER); - } - } - member = taParty->addMember(id, nick); - - if (member) - { - member->setLeader(leader); - member->setOnline(online); - member->setMap(map); - } - } - } - - if (taParty) - taParty->sort(); - - if (player_node && taParty) - { - player_node->setParty(taParty); - player_node->setPartyName(taParty->getName()); - } - } + processPartyInfo(msg); break; case SMSG_PARTY_INVITE_RESPONSE: - { - if (!partyTab) - break; - - std::string nick = msg.readString(24); - - switch (msg.readInt8()) - { - case 0: - partyTab->chatLog(strprintf( - _("%s is already a member of a party."), - nick.c_str()), BY_SERVER); - break; - case 1: - partyTab->chatLog(strprintf( - _("%s refused your invitation."), - nick.c_str()), BY_SERVER); - break; - case 2: - partyTab->chatLog(strprintf( - _("%s is now a member of your party."), - nick.c_str()), BY_SERVER); - break; - case 3: - partyTab->chatLog(strprintf( - _("%s can't join your party because party is " - "full."), nick.c_str()), BY_SERVER); - break; - default: - partyTab->chatLog(strprintf( - _("QQQ Unknown invite response for %s."), - nick.c_str()), BY_SERVER); - break; - } - break; - } + processPartyInviteResponse(msg); + break; case SMSG_PARTY_INVITED: - { - int id = msg.readInt32(); - std::string partyName = msg.readString(24); - std::string nick = ""; - Being *being; - - if (actorSpriteManager) - { - if ((being = actorSpriteManager->findBeing(id))) - { - if (being && being->getType() == Being::PLAYER) - nick = being->getName(); - } - } - - if (socialWindow) - socialWindow->showPartyInvite(partyName, nick); - break; - } + processPartyInvited(msg); + break; case SMSG_PARTY_SETTINGS: - { - if (!partyTab) - { - if (!chatWindow) - break; - - partyTab = new PartyTab(); - } - - // These seem to indicate the sharing mode for exp and items - short exp = msg.readInt16(); - short item = msg.readInt16(); - - if (!partyTab) - break; - - switch (exp) - { - case PARTY_SHARE: - if (mShareExp == PARTY_SHARE) - break; - mShareExp = PARTY_SHARE; - if (partyTab) - { - partyTab->chatLog( - _("Experience sharing enabled."), BY_SERVER); - } - break; - case PARTY_SHARE_NO: - if (mShareExp == PARTY_SHARE_NO) - break; - mShareExp = PARTY_SHARE_NO; - if (partyTab) - { - partyTab->chatLog( - _("Experience sharing disabled."), BY_SERVER); - } - break; - case PARTY_SHARE_NOT_POSSIBLE: - if (mShareExp == PARTY_SHARE_NOT_POSSIBLE) - break; - mShareExp = PARTY_SHARE_NOT_POSSIBLE; - if (partyTab) - { - partyTab->chatLog( - _("Experience sharing not possible."), - BY_SERVER); - } - break; - default: - logger->log("QQQ Unknown party exp option: %d\n", exp); - break; - } - - switch (item) - { - case PARTY_SHARE: - if (mShareItems == PARTY_SHARE) - break; - mShareItems = PARTY_SHARE; - if (partyTab) - { - partyTab->chatLog( - _("Item sharing enabled."), BY_SERVER); - } - break; - case PARTY_SHARE_NO: - if (mShareItems == PARTY_SHARE_NO) - break; - mShareItems = PARTY_SHARE_NO; - if (partyTab) - { - partyTab->chatLog( - _("Item sharing disabled."), BY_SERVER); - } - break; - case PARTY_SHARE_NOT_POSSIBLE: - if (mShareItems == PARTY_SHARE_NOT_POSSIBLE) - break; - mShareItems = PARTY_SHARE_NOT_POSSIBLE; - if (partyTab) - { - partyTab->chatLog( - _("Item sharing not possible."), BY_SERVER); - } - break; - default: - logger->log("QQQ Unknown party item option: %d\n", - exp); - break; - } - break; - } + processPartySettings(msg); + break; case SMSG_PARTY_MOVE: - { - int id = msg.readInt32(); // id - PartyMember *m = 0; - if (taParty) - m = taParty->getMember(id); - if (m) - { - msg.skip(4); - m->setX(msg.readInt16()); // x - m->setY(msg.readInt16()); // y - m->setOnline(msg.readInt8()); // online (if 0) - msg.readString(24); // party - msg.readString(24); // nick - m->setMap(msg.readString(16)); // map - } - else - { - msg.skip(4); - msg.readInt16(); // x - msg.readInt16(); // y - msg.readInt8(); // online (if 0) - msg.readString(24); // party - msg.readString(24); // nick - msg.readString(16); // map - } - } + processPartyMove(msg); break; case SMSG_PARTY_LEAVE: - { - int id = msg.readInt32(); - std::string nick = msg.readString(24); - msg.readInt8(); // fail - if (player_node && id == player_node->getId()) - { - if (taParty) - { - taParty->removeFromMembers(); - taParty->clearMembers(); - } - SERVER_NOTICE(_("You have left the party.")) - delete partyTab; - partyTab = 0; - - if (socialWindow && taParty) - socialWindow->removeTab(taParty); - } - else - { - if (partyTab) - { - partyTab->chatLog(strprintf( - _("%s has left your party."), - nick.c_str()), BY_SERVER); - } - if (actorSpriteManager) - { - Being *b = actorSpriteManager->findBeing(id); - if (b && b->getType() == Being::PLAYER) - b->setParty(0); - } - if (taParty) - taParty->removeMember(id); - } - break; - } + processPartyLeave(msg); + break; case SMSG_PARTY_UPDATE_HP: - { - int id = msg.readInt32(); - int hp = msg.readInt16(); - int maxhp = msg.readInt16(); - PartyMember *m = 0; - if (taParty) - m = taParty->getMember(id); - if (m) - { - m->setHp(hp); - m->setMaxHp(maxhp); - } - - // The server only sends this when the member is in range, so - // lets make sure they get the party hilight. - if (actorSpriteManager && taParty) - { - if (Being *b = actorSpriteManager->findBeing(id)) - b->setParty(taParty); - } - } + processPartyUpdateHp(msg); break; case SMSG_PARTY_UPDATE_COORDS: - { - int id = msg.readInt32(); // id - PartyMember *m = 0; - if (taParty) - m = taParty->getMember(id); - if (m) - { - m->setX(msg.readInt16()); // x - m->setY(msg.readInt16()); // y - } - else - { - msg.readInt16(); // x - msg.readInt16(); // y - } - } + processPartyUpdateCoords(msg); break; case SMSG_PARTY_MESSAGE: - { - int msgLength = msg.readInt16() - 8; - if (msgLength <= 0) - return; - - int id = msg.readInt32(); - std::string chatMsg = msg.readString(msgLength); - - if (taParty) - { - PartyMember *member = taParty->getMember(id); - if (partyTab) - { - if (member) - { - partyTab->chatLog(member->getName(), chatMsg); - } - else - { - partyTab->chatLog(strprintf( - _("An unknown member tried to say: %s"), - chatMsg.c_str()), BY_SERVER); - } - } - } - } + processPartyMessage(msg); break; default: @@ -463,11 +110,6 @@ void PartyHandler::create(const std::string &name) outMsg.writeString(name.substr(0, 23), 24); } -void PartyHandler::join(int partyId A_UNUSED) -{ - // TODO? -} - void PartyHandler::invite(Being *being) { if (being) @@ -518,15 +160,15 @@ void PartyHandler::kick(Being *being) void PartyHandler::kick(const std::string &name) { - if (!taParty) + if (!Ea::taParty) return; - PartyMember *m = taParty->getMember(name); + PartyMember *m = Ea::taParty->getMember(name); if (!m) { - if (partyTab) + if (Ea::partyTab) { - partyTab->chatLog(strprintf(_("%s is not in your party!"), + Ea::partyTab->chatLog(strprintf(_("%s is not in your party!"), name.c_str()), BY_SERVER); } return; @@ -544,12 +186,6 @@ void PartyHandler::chat(const std::string &text) outMsg.writeString(text, static_cast<int>(text.length())); } -void PartyHandler::requestPartyMembers() const -{ - // Our eAthena doesn't have this message - // Not needed anyways -} - void PartyHandler::setShareExperience(PartyShare share) { if (share == PARTY_SHARE_NOT_POSSIBLE) @@ -570,14 +206,4 @@ void PartyHandler::setShareItems(PartyShare share) outMsg.writeInt16(share); } -void PartyHandler::reload() -{ - taParty = Party::getParty(1); -} - -void PartyHandler::clear() -{ - taParty = 0; -} - } // namespace TmwAthena |