diff options
Diffstat (limited to 'src/net/manaserv/partyhandler.cpp')
-rw-r--r-- | src/net/manaserv/partyhandler.cpp | 97 |
1 files changed, 68 insertions, 29 deletions
diff --git a/src/net/manaserv/partyhandler.cpp b/src/net/manaserv/partyhandler.cpp index ec153fa8..e1bcb624 100644 --- a/src/net/manaserv/partyhandler.cpp +++ b/src/net/manaserv/partyhandler.cpp @@ -21,17 +21,16 @@ #include "net/manaserv/partyhandler.h" +#include "event.h" #include "log.h" #include "localplayer.h" #include "gui/socialwindow.h" -#include "gui/widgets/chattab.h" - #include "net/manaserv/connection.h" #include "net/manaserv/messagein.h" #include "net/manaserv/messageout.h" -#include "net/manaserv/protocol.h" +#include "net/manaserv/manaserv_protocol.h" #include "utils/gettext.h" #include "utils/stringutils.h" @@ -45,14 +44,15 @@ extern Net::PartyHandler *partyHandler; namespace ManaServ { extern Connection *chatServerConnection; +extern Connection *gameServerConnection; PartyHandler::PartyHandler(): mParty(Party::getParty(PARTY_ID)) { static const Uint16 _messages[] = { - CPMSG_PARTY_INVITE_RESPONSE, + GPMSG_PARTY_INVITE_ERROR, CPMSG_PARTY_INVITED, - CPMSG_PARTY_ACCEPT_INVITE_RESPONSE, + CPMSG_PARTY_INVITE_ANSWER_RESPONSE, CPMSG_PARTY_QUIT_RESPONSE, CPMSG_PARTY_NEW_MEMBER, CPMSG_PARTY_MEMBER_LEFT, @@ -61,18 +61,20 @@ PartyHandler::PartyHandler(): }; handledMessages = _messages; partyHandler = this; + + mParty->setName("Party"); } void PartyHandler::handleMessage(Net::MessageIn &msg) { switch (msg.getId()) { - case CPMSG_PARTY_INVITE_RESPONSE: + case GPMSG_PARTY_INVITE_ERROR: { - if (msg.readInt8() == ERRMSG_OK) - { - - } + std::string name = msg.readString(); + SERVER_NOTICE(strprintf(_("Party invite failed, because no player " + "called %s is within the visual range."), + name.c_str())); } break; case CPMSG_PARTY_INVITED: @@ -80,14 +82,31 @@ void PartyHandler::handleMessage(Net::MessageIn &msg) socialWindow->showPartyInvite(msg.readString()); } break; - case CPMSG_PARTY_ACCEPT_INVITE_RESPONSE: + case CPMSG_PARTY_INVITE_ANSWER_RESPONSE: { - if (msg.readInt8() == ERRMSG_OK) + switch (msg.readInt8()) { - // - localChatTab->chatLog(_("Joined party.")); + case ERRMSG_OK: + player_node->setParty(mParty); + while (msg.getUnreadLength()) + { + std::string name = msg.readString(); + mParty->addMember(0, name); + } + break; + case ERRMSG_TIME_OUT: + SERVER_NOTICE(_("Joining party failed, because the " + "invitation has timed out on the server.")); + break; + case ERRMSG_FAILURE: + SERVER_NOTICE(_("Joining party failed, because the " + "inviter has left the game.")); + break; + default: + logger->log("Unknown CPMSG_PARTY_INVITE_ANSWER_RESPONSE."); + break; } - } + } break; case CPMSG_PARTY_QUIT_RESPONSE: { @@ -100,28 +119,48 @@ void PartyHandler::handleMessage(Net::MessageIn &msg) case CPMSG_PARTY_NEW_MEMBER: { - int id = msg.readInt16(); // being id std::string name = msg.readString(); + std::string inviter = msg.readString(); + std::string s; + if (!inviter.empty()) + s = strprintf(_(" on invitation from %s"), inviter.c_str()); - localChatTab->chatLog(strprintf(_("%s joined the party."), - name.c_str())); + SERVER_NOTICE(strprintf(_("%s joined the party%s."), + name.c_str(), s.c_str())); - if (id == player_node->getId()) + if (name == player_node->getName()) player_node->setParty(mParty); - mParty->addMember(id, name); + mParty->addMember(0, name); } break; case CPMSG_PARTY_MEMBER_LEFT: { - mParty->removeMember(msg.readString()); + // mParty->removeMember(msg.readString()); } break; case CPMSG_PARTY_REJECTED: { std::string name = msg.readString(); - localChatTab->chatLog(strprintf(_("%s rejected your invite."), + switch (msg.readInt8()) + { + case ERRMSG_OK: + SERVER_NOTICE(strprintf(_("%s rejected your invite."), name.c_str())); + break; + case ERRMSG_LIMIT_REACHED: + SERVER_NOTICE(_("Party invitation rejected by server, " + "because of too many invitations in a " + "short time.")); + break; + case ERRMSG_FAILURE: + SERVER_NOTICE(strprintf(_("%s is already in a party."), + name.c_str())); + break; + default: + logger->log("Unknown CPMSG_PARTY_REJECTED."); + break; + } } break; } } @@ -136,26 +175,26 @@ void PartyHandler::join(int partyId) // TODO } -void PartyHandler::invite(Player *player) +void PartyHandler::invite(Being *being) { - invite(player->getName()); + invite(being->getName()); } void PartyHandler::invite(const std::string &name) { - MessageOut msg(PCMSG_PARTY_INVITE); + MessageOut msg(PGMSG_PARTY_INVITE); msg.writeString(name); - chatServerConnection->send(msg); + gameServerConnection->send(msg); } void PartyHandler::inviteResponse(const std::string &inviter, bool accept) { - MessageOut msg = MessageOut(accept ? PCMSG_PARTY_ACCEPT_INVITE : - PCMSG_PARTY_REJECT_INVITE); + MessageOut msg = MessageOut(PCMSG_PARTY_INVITE_ANSWER); msg.writeString(inviter); + msg.writeInt8(accept); chatServerConnection->send(msg); } @@ -167,7 +206,7 @@ void PartyHandler::leave() chatServerConnection->send(msg); } -void PartyHandler::kick(Player *player) +void PartyHandler::kick(Being *being) { // TODO } |