summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2008-04-22 15:21:21 +0000
committerDavid Athay <ko2fan@gmail.com>2008-04-22 15:21:21 +0000
commite2e580fb5d2fadafdfc7776b005dfc4562f5b624 (patch)
tree4ed704a6a73a9e1d60bc6fea26873bc404961324
parentf7fcde7653b352cd4c8c921f01e5f3c99ee80dbb (diff)
downloadmanaserv-e2e580fb5d2fadafdfc7776b005dfc4562f5b624.tar.gz
manaserv-e2e580fb5d2fadafdfc7776b005dfc4562f5b624.tar.bz2
manaserv-e2e580fb5d2fadafdfc7776b005dfc4562f5b624.tar.xz
manaserv-e2e580fb5d2fadafdfc7776b005dfc4562f5b624.zip
Added more support for parties
-rw-r--r--ChangeLog5
-rw-r--r--src/chat-server/chathandler.cpp107
-rw-r--r--src/chat-server/chathandler.hpp27
-rw-r--r--src/defines.h7
4 files changed, 131 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 08af998b..47d8f70f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-04-22 David Athay <ko2fan@gmail.com>
+
+ * src/chat-server/chathandler.cpp, src/chat-server/chathandler.hpp,
+ src/defines.h: Added more support for parties.
+
2008-04-21 Yohann Ferreira <bertram@cegetel.net>
* src/Makefile.am, src/utils/sha2.h, src/utils/sha2.cpp,
diff --git a/src/chat-server/chathandler.cpp b/src/chat-server/chathandler.cpp
index 4170ef13..6f7fac9c 100644
--- a/src/chat-server/chathandler.cpp
+++ b/src/chat-server/chathandler.cpp
@@ -192,12 +192,16 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message)
handleGuildQuit(computer, message);
break;
- case PCMSG_PARTY_CREATE:
- handlePartyCreation(computer, message);
+ case PCMSG_PARTY_INVITE:
+ handlePartyInvite(computer, message);
+ break;
+
+ case PCMSG_PARTY_ACCEPT_INVITE:
+ handlePartyAcceptInvite(computer, message);
break;
case PCMSG_PARTY_QUIT:
- handlePartyQuit(computer, message);
+ handlePartyQuit(computer);
default:
LOG_WARN("ChatHandler::processMessage, Invalid message type"
@@ -906,14 +910,83 @@ void ChatHandler::sendGuildListUpdate(const std::string &guildName,
}
}
-void ChatHandler::handlePartyCreation(ChatClient &client, MessageIn &msg)
+bool ChatHandler::handlePartyJoin(const std::string &invited, const std::string &inviter)
+{
+ MessageOut out(CPMSG_PARTY_INVITE_RESPONSE);
+
+ // Get inviting client
+ ChatClient *c1 = getClient(inviter);
+ if (c1)
+ {
+ // if party doesnt exist, create it
+ if (!c1->party)
+ {
+ c1->party = new Party();
+ }
+
+ // add inviter to the party
+ c1->party->addUser(inviter);
+
+ // Get invited client
+ ChatClient *c2 = getClient(invited);
+ if (c2)
+ {
+ // add invited to the party
+ c1->party->addUser(invited);
+ c2->party = c1->party;
+ // was successful so return success to inviter
+ out.writeByte(ERRMSG_OK);
+ c1->send(out);
+ return true;
+ }
+ }
+
+ // there was an error, return false
+ return false;
+
+}
+
+void ChatHandler::handlePartyInvite(ChatClient &client, MessageIn &msg)
{
- MessageOut out(CPMSG_PARTY_CREATE_RESPONSE);
- if (!client.party)
+ //TODO: Handle errors
+ MessageOut out(CPMSG_PARTY_INVITED);
+
+ out.writeString(client.characterName);
+
+ std::string invited = msg.readString();
+ if (invited != "")
{
- client.party = new Party();
- client.party->addUser(client.characterName);
- out.writeByte(ERRMSG_OK);
+ // Get client and send it the invite
+ ChatClient *c = getClient(invited);
+ if (c)
+ {
+ // store the invite
+ mPartyInvitedUsers.push_back(invited);
+ c->send(out);
+ }
+ }
+}
+
+void ChatHandler::handlePartyAcceptInvite(ChatClient &client, MessageIn &msg)
+{
+ MessageOut out(CPMSG_PARTY_ACCEPT_INVITE_RESPONSE);
+
+ // 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())
+ {
+ // make them join the party
+ if (handlePartyJoin(client.characterName, msg.readString()))
+ {
+ out.writeByte(ERRMSG_OK);
+ mPartyInvitedUsers.erase(itr);
+ }
+ else
+ {
+ out.writeByte(ERRMSG_FAILURE);
+ }
}
else
{
@@ -922,7 +995,7 @@ void ChatHandler::handlePartyCreation(ChatClient &client, MessageIn &msg)
client.send(out);
}
-void ChatHandler::handlePartyQuit(ChatClient &client, MessageIn &msg)
+void ChatHandler::handlePartyQuit(ChatClient &client)
{
removeUserFromParty(client);
MessageOut out(CPMSG_PARTY_QUIT_RESPONSE);
@@ -942,3 +1015,17 @@ void ChatHandler::removeUserFromParty(ChatClient &client)
}
}
}
+
+ChatClient* ChatHandler::getClient(const std::string &name)
+{
+ std::map<std::string, ChatClient*>::iterator itr;
+ itr = mPlayerMap.find(name);
+ if (itr != mPlayerMap.end())
+ {
+ return itr->second;
+ }
+ else
+ {
+ return NULL;
+ }
+}
diff --git a/src/chat-server/chathandler.hpp b/src/chat-server/chathandler.hpp
index 5ea3b969..fd51db4e 100644
--- a/src/chat-server/chathandler.hpp
+++ b/src/chat-server/chathandler.hpp
@@ -53,6 +53,7 @@ class ChatHandler : public ConnectionHandler
};
std::map<std::string, ChatClient*> mPlayerMap;
+ std::vector<std::string> mPartyInvitedUsers;
public:
@@ -226,16 +227,29 @@ class ChatHandler : public ConnectionHandler
handleGuildQuit(ChatClient &client, MessageIn &msg);
/**
- * Deal with creating a party.
+ * Deal with a player joining a party.
+ * @return Returns whether player successfully joined the party
+ */
+ bool
+ handlePartyJoin(const std::string &invited, const std::string &inviter);
+
+ /**
+ * Deal with inviting player to a party
+ */
+ void
+ handlePartyInvite(ChatClient &client, MessageIn &msg);
+
+ /**
+ * Deal with accepting an invite to join a party
*/
void
- handlePartyCreation(ChatClient &client, MessageIn &msg);
+ handlePartyAcceptInvite(ChatClient &client, MessageIn &msg);
/**
* Deal with leaving a party.
*/
void
- handlePartyQuit(ChatClient &client, MessageIn &msg);
+ handlePartyQuit(ChatClient &client);
/**
* Remove user from party
@@ -288,6 +302,13 @@ class ChatHandler : public ConnectionHandler
int joinGuildChannel(const std::string &name, ChatClient &client);
/**
+ * Returns ChatClient from the Player Map
+ * @param The name of the character
+ * @return The Chat Client
+ */
+ ChatClient* getClient(const std::string &name);
+
+ /**
* Container for pending clients and pending connections.
*/
TokenCollector<ChatHandler, ChatClient *, Pending *> mTokenCollector;
diff --git a/src/defines.h b/src/defines.h
index 2ccfa86e..fc6d0469 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -204,8 +204,11 @@ enum {
CPMSG_GUILD_REJOIN = 0x0371, // S name, W guild, B rights, W channel
// Party
- PCMSG_PARTY_CREATE = 0x03A0, // -
- CPMSG_PARTY_CREATE_RESPONSE = 0x03A1, // B error
+ PCMSG_PARTY_INVITE = 0x03A0, // S name
+ CPMSG_PARTY_INVITE_RESPONSE = 0x03A1, // B error
+ CPMSG_PARTY_INVITED = 0x03A2, // S name
+ PCMSG_PARTY_ACCEPT_INVITE = 0x03A5, // S name
+ CPMSG_PARTY_ACCEPT_INVITE_RESPONSE = 0x03A6, // B error
PCMSG_PARTY_QUIT = 0x03AA, // -
CPMSG_PARTY_QUIT_RESPONSE = 0x03AB, // B error