summaryrefslogtreecommitdiffstats
path: root/src/chat-server
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2009-04-23 16:49:32 +0100
committerDavid Athay <ko2fan@gmail.com>2009-04-23 16:49:32 +0100
commitb31f0bf7e5c4575f57684692f1e1f36aba5eed51 (patch)
tree49b10e3a2e550a649ed1ea6bf5dad4e8817823a6 /src/chat-server
parentb4864fb3a210dd2aea1ecfef4d5e34f0d1054cec (diff)
downloadmanaserv-b31f0bf7e5c4575f57684692f1e1f36aba5eed51.tar.gz
manaserv-b31f0bf7e5c4575f57684692f1e1f36aba5eed51.tar.xz
manaserv-b31f0bf7e5c4575f57684692f1e1f36aba5eed51.zip
Reworked party invites, now sends rejections and checks the invites are valid
Diffstat (limited to 'src/chat-server')
-rw-r--r--src/chat-server/chatclient.hpp1
-rw-r--r--src/chat-server/chathandler.cpp5
-rw-r--r--src/chat-server/chathandler.hpp15
-rw-r--r--src/chat-server/partyhandler.cpp93
4 files changed, 99 insertions, 15 deletions
diff --git a/src/chat-server/chatclient.hpp b/src/chat-server/chatclient.hpp
index 67d7f7a..a47945c 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 8def67f..515d56b 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 f1a8448..c58206d 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 9f8dea1..e60c2e0 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)