diff options
author | David Athay <ko2fan@gmail.com> | 2009-04-23 16:49:32 +0100 |
---|---|---|
committer | David Athay <ko2fan@gmail.com> | 2009-04-23 16:49:32 +0100 |
commit | b31f0bf7e5c4575f57684692f1e1f36aba5eed51 (patch) | |
tree | 49b10e3a2e550a649ed1ea6bf5dad4e8817823a6 /src | |
parent | b4864fb3a210dd2aea1ecfef4d5e34f0d1054cec (diff) | |
download | manaserv-b31f0bf7e5c4575f57684692f1e1f36aba5eed51.tar.gz manaserv-b31f0bf7e5c4575f57684692f1e1f36aba5eed51.tar.bz2 manaserv-b31f0bf7e5c4575f57684692f1e1f36aba5eed51.tar.xz manaserv-b31f0bf7e5c4575f57684692f1e1f36aba5eed51.zip |
Reworked party invites, now sends rejections and checks the invites are valid
Diffstat (limited to 'src')
-rw-r--r-- | src/chat-server/chatclient.hpp | 1 | ||||
-rw-r--r-- | src/chat-server/chathandler.cpp | 5 | ||||
-rw-r--r-- | src/chat-server/chathandler.hpp | 15 | ||||
-rw-r--r-- | src/chat-server/partyhandler.cpp | 93 | ||||
-rw-r--r-- | src/defines.h | 2 |
5 files changed, 101 insertions, 15 deletions
diff --git a/src/chat-server/chatclient.hpp b/src/chat-server/chatclient.hpp index 67d7f7a9..a47945cf 100644 --- a/src/chat-server/chatclient.hpp +++ b/src/chat-server/chatclient.hpp @@ -55,6 +55,7 @@ class ChatClient : public NetComputer Party* party; unsigned char accountLevel; std::map<ChatChannel*, std::string> userModes; + int numInvites; }; #endif diff --git a/src/chat-server/chathandler.cpp b/src/chat-server/chathandler.cpp index 8def67fc..515d56b8 100644 --- a/src/chat-server/chathandler.cpp +++ b/src/chat-server/chathandler.cpp @@ -232,6 +232,11 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message) case PCMSG_PARTY_QUIT: handlePartyQuit(computer); + break; + + case PCMSG_PARTY_REJECT_INVITE: + handlePartyRejection(computer, message); + break; default: LOG_WARN("ChatHandler::processMessage, Invalid message type" diff --git a/src/chat-server/chathandler.hpp b/src/chat-server/chathandler.hpp index f1a84484..c58206d9 100644 --- a/src/chat-server/chathandler.hpp +++ b/src/chat-server/chathandler.hpp @@ -40,6 +40,7 @@ class ChatClient; * @todo <b>b_lindeijer:</b> Extend this class with handling of team chat once * teams are implemented. */ + class ChatHandler : public ConnectionHandler { @@ -52,8 +53,15 @@ class ChatHandler : public ConnectionHandler unsigned char level; }; + struct PartyInvite + { + std::string mInviter; + std::string mInvited; + int mPartyId; + }; + std::map<std::string, ChatClient*> mPlayerMap; - std::vector<std::string> mPartyInvitedUsers; + std::vector<PartyInvite> mPartyInvitedUsers; public: @@ -270,6 +278,11 @@ class ChatHandler : public ConnectionHandler handlePartyQuit(ChatClient &client); /** + * Tell user the invite was rejected + */ + void handlePartyRejection(ChatClient &client, MessageIn &msg); + + /** * Remove user from party */ void diff --git a/src/chat-server/partyhandler.cpp b/src/chat-server/partyhandler.cpp index 9f8dea10..e60c2e0c 100644 --- a/src/chat-server/partyhandler.cpp +++ b/src/chat-server/partyhandler.cpp @@ -102,8 +102,22 @@ void ChatHandler::handlePartyInvite(ChatClient &client, MessageIn &msg) ChatClient *c = getClient(invited); if (c) { + ++client.numInvites; + + // TODO: Check number of invites + // and do something if too many in a short time + // store the invite - mPartyInvitedUsers.push_back(invited); + PartyInvite invite; + invite.mInvited = invited; + invite.mInviter = client.characterName; + if (client.party) + invite.mPartyId = client.party->getId(); + else + invite.mPartyId = 0; + + mPartyInvitedUsers.push_back(invite); + c->send(out); } } @@ -113,24 +127,37 @@ void ChatHandler::handlePartyAcceptInvite(ChatClient &client, MessageIn &msg) { MessageOut out(CPMSG_PARTY_ACCEPT_INVITE_RESPONSE); + std::string inviter = msg.readString(); + // Check that the player was invited - std::vector<std::string>::iterator itr; - itr = std::find(mPartyInvitedUsers.begin(), mPartyInvitedUsers.end(), - client.characterName); - if (itr != mPartyInvitedUsers.end()) + std::vector<PartyInvite>::iterator itr, itr_end; + itr = mPartyInvitedUsers.begin(); + itr_end = mPartyInvitedUsers.end(); + + bool found = false; + + while (itr != itr_end) { - // make them join the party - if (handlePartyJoin(client.characterName, msg.readString())) + if ((*itr).mInvited == client.characterName && + (*itr).mInviter == inviter) { - out.writeByte(ERRMSG_OK); - mPartyInvitedUsers.erase(itr); - } - else - { - out.writeByte(ERRMSG_FAILURE); + // make them join the party + if (handlePartyJoin(client.characterName, inviter)) + { + out.writeByte(ERRMSG_OK); + mPartyInvitedUsers.erase(itr); + } + else + { + out.writeByte(ERRMSG_FAILURE); + } + found = true; } + + ++itr; } - else + + if (!found) { out.writeByte(ERRMSG_FAILURE); } @@ -149,6 +176,44 @@ void ChatHandler::handlePartyQuit(ChatClient &client) updateInfo(&client, 0); } +void ChatHandler::handlePartyRejection(ChatClient &client, MessageIn &msg) +{ + MessageOut out(CPMSG_PARTY_REJECTED); + + std::string inviter = msg.readString(); + + + std::vector<PartyInvite>::iterator itr, itr_end; + + itr = mPartyInvitedUsers.begin(); + itr_end = mPartyInvitedUsers.end(); + bool found = false; + + while (itr != itr_end) + { + // Check that the player was invited + if ((*itr).mInvited == client.characterName && + (*itr).mInviter == inviter) + { + // remove them from invited users list + mPartyInvitedUsers.erase(itr); + found = true; + } + + ++itr; + } + + if (!found) + { + out.writeByte(ERRMSG_FAILURE); + } + + // send rejection to inviter + ChatClient *inviterClient = getClient(inviter); + + inviterClient->send(out); +} + void ChatHandler::removeUserFromParty(ChatClient &client) { if (client.party) diff --git a/src/defines.h b/src/defines.h index a6655447..c657e6ba 100644 --- a/src/defines.h +++ b/src/defines.h @@ -212,6 +212,8 @@ enum { CPMSG_PARTY_INVITED = 0x03A2, // S name PCMSG_PARTY_ACCEPT_INVITE = 0x03A5, // S name CPMSG_PARTY_ACCEPT_INVITE_RESPONSE = 0x03A6, // B error + PCMSG_PARTY_REJECT_INVITE = 0x03A7, // S name + CPMSG_PARTY_REJECTED = 0x03A8, // S name PCMSG_PARTY_QUIT = 0x03AA, // - CPMSG_PARTY_QUIT_RESPONSE = 0x03AB, // B error CPMSG_PARTY_NEW_MEMBER = 0x03B0, // W being id, S name |