summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Dombrowski <stefan@uni-bonn.de>2011-05-30 23:18:00 +0200
committerStefan Dombrowski <stefan@uni-bonn.de>2011-05-30 23:18:00 +0200
commit0e04885bcef86a571a0c3069b4706422f9af2566 (patch)
tree1702fff382fae7ff64be7423ee349e0eb2780224 /src
parent406be26dd7a12795a4a2702aabe2ef46a5e0a6bb (diff)
downloadmanaserv-0e04885bcef86a571a0c3069b4706422f9af2566.tar.gz
manaserv-0e04885bcef86a571a0c3069b4706422f9af2566.tar.bz2
manaserv-0e04885bcef86a571a0c3069b4706422f9af2566.tar.xz
manaserv-0e04885bcef86a571a0c3069b4706422f9af2566.zip
Routing party invite through the map server
The player sends party invites to the game server. If the invitee is within the visual range of the inviter, the game server forwards the invite to the chat server. Reviewed-by: Bjorn, Jaxad0127
Diffstat (limited to 'src')
-rw-r--r--src/account-server/serverhandler.cpp5
-rw-r--r--src/chat-server/chathandler.cpp4
-rw-r--r--src/chat-server/chathandler.h3
-rw-r--r--src/chat-server/partyhandler.cpp52
-rw-r--r--src/common/manaserv_protocol.h8
-rw-r--r--src/game-server/gamehandler.cpp43
-rw-r--r--src/game-server/gamehandler.h2
7 files changed, 82 insertions, 35 deletions
diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp
index 1d2f9e0d..e5bfdc40 100644
--- a/src/account-server/serverhandler.cpp
+++ b/src/account-server/serverhandler.cpp
@@ -28,6 +28,7 @@
#include "account-server/accounthandler.h"
#include "account-server/character.h"
#include "account-server/storage.h"
+#include "chat-server/chathandler.h"
#include "chat-server/post.h"
#include "common/configuration.h"
#include "common/manaserv_protocol.h"
@@ -544,6 +545,10 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
storage->addTransaction(trans);
} break;
+ case GCMSG_PARTY_INVITE:
+ chatHandler->handlePartyInvite(msg);
+ break;
+
default:
LOG_WARN("ServerHandler::processMessage, Invalid message type: "
<< msg.getId());
diff --git a/src/chat-server/chathandler.cpp b/src/chat-server/chathandler.cpp
index 73eede6b..1f6cfdbd 100644
--- a/src/chat-server/chathandler.cpp
+++ b/src/chat-server/chathandler.cpp
@@ -227,10 +227,6 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message)
handleGuildQuit(computer, message);
break;
- case PCMSG_PARTY_INVITE:
- handlePartyInvite(computer, message);
- break;
-
case PCMSG_PARTY_ACCEPT_INVITE:
handlePartyAcceptInvite(computer, message);
break;
diff --git a/src/chat-server/chathandler.h b/src/chat-server/chathandler.h
index 392f053a..c969a9ae 100644
--- a/src/chat-server/chathandler.h
+++ b/src/chat-server/chathandler.h
@@ -101,6 +101,8 @@ class ChatHandler : public ConnectionHandler
const std::string &characterName,
char eventId);
+ void handlePartyInvite(MessageIn &msg);
+
protected:
/**
* Process chat related messages.
@@ -162,7 +164,6 @@ class ChatHandler : public ConnectionHandler
void handleGuildKickMember(ChatClient &client, MessageIn &msg);
void handleGuildQuit(ChatClient &client, MessageIn &msg);
- void handlePartyInvite(ChatClient &client, MessageIn &msg);
void handlePartyAcceptInvite(ChatClient &client, MessageIn &msg);
void handlePartyQuit(ChatClient &client);
// TODO: Merge with handlePartyAcceptInvite?
diff --git a/src/chat-server/partyhandler.cpp b/src/chat-server/partyhandler.cpp
index 52eb89a3..40862755 100644
--- a/src/chat-server/partyhandler.cpp
+++ b/src/chat-server/partyhandler.cpp
@@ -87,43 +87,41 @@ bool ChatHandler::handlePartyJoin(const std::string &invited, const std::string
}
-void ChatHandler::handlePartyInvite(ChatClient &client, MessageIn &msg)
+void ChatHandler::handlePartyInvite(MessageIn &msg)
{
- //TODO: Handle errors
- MessageOut out(CPMSG_PARTY_INVITED);
+ std::string inviterName = msg.readString();
+ std::string inviteeName = msg.readString();
+ ChatClient *inviter = getClient(inviterName);
+
+ if (!inviter)
+ return;
- out.writeString(client.characterName);
+ ChatClient *invitee = getClient(inviteeName);
- const std::string invited = msg.readString();
- if (invited == client.characterName)
+ if (!invitee)
{
+ // TODO: Send error message
return;
}
- if (!invited.empty())
- {
- // Get client and send it the invite
- ChatClient *c = getClient(invited);
- if (c)
- {
- ++client.numInvites;
- // TODO: Check number of invites
- // and do something if too many in a short time
+ ++invitee->numInvites;
+ // TODO: Check number of invites
+ // and do something if too many in a short time
- // store the invite
- PartyInvite invite;
- invite.mInvited = invited;
- invite.mInviter = client.characterName;
- if (client.party)
- invite.mPartyId = client.party->getId();
- else
- invite.mPartyId = 0;
+ // store the invite
+ PartyInvite invite;
+ invite.mInvited = inviteeName;
+ invite.mInviter = inviterName;
+ if (inviter->party)
+ invite.mPartyId = inviter->party->getId();
+ else
+ invite.mPartyId = 0;
- mPartyInvitedUsers.push_back(invite);
+ mPartyInvitedUsers.push_back(invite);
- c->send(out);
- }
- }
+ MessageOut out(CPMSG_PARTY_INVITED);
+ out.writeString(inviterName);
+ invitee->send(out);
}
void ChatHandler::handlePartyAcceptInvite(ChatClient &client, MessageIn &msg)
diff --git a/src/common/manaserv_protocol.h b/src/common/manaserv_protocol.h
index 3205d004..c758fd45 100644
--- a/src/common/manaserv_protocol.h
+++ b/src/common/manaserv_protocol.h
@@ -186,9 +186,11 @@ enum {
CPMSG_GUILD_REJOIN = 0x0389, // S name, W guild, W rights, W channel, S announce
// Party
- PCMSG_PARTY_INVITE = 0x03A0, // S name
- CPMSG_PARTY_INVITE_RESPONSE = 0x03A1, // B error, S name
- CPMSG_PARTY_INVITED = 0x03A2, // S name
+ PGMSG_PARTY_INVITE = 0x03A0, // S name
+ GPMSG_PARTY_INVITE_ERROR = 0x03A1, // S name
+ GCMSG_PARTY_INVITE = 0x03A2, // S inviter, S invitee
+ CPMSG_PARTY_INVITE_RESPONSE = 0x03A3, // B error, S name
+ CPMSG_PARTY_INVITED = 0x03A4, // S name
PCMSG_PARTY_ACCEPT_INVITE = 0x03A5, // S name
CPMSG_PARTY_ACCEPT_INVITE_RESPONSE = 0x03A6, // B error, { S name }
PCMSG_PARTY_REJECT_INVITE = 0x03A7, // S name
diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp
index 49089699..58d289f0 100644
--- a/src/game-server/gamehandler.cpp
+++ b/src/game-server/gamehandler.cpp
@@ -23,6 +23,7 @@
#include "game-server/gamehandler.h"
+#include "common/configuration.h"
#include "common/transaction.h"
#include "game-server/accountconnection.h"
#include "game-server/buysell.h"
@@ -278,6 +279,10 @@ void GameHandler::processMessage(NetComputer *computer, MessageIn &message)
handleNpcPostSend(client, message);
break;
+ case PGMSG_PARTY_INVITE:
+ handlePartyInvite(client, message);
+ break;
+
default:
LOG_WARN("Invalid message type");
client.send(MessageOut(XXMSG_INVALID));
@@ -801,6 +806,44 @@ void GameHandler::handleNpcPostSend(GameClient &client, MessageIn &message)
accountHandler->sendPost(client.character, message);
}
+void GameHandler::handlePartyInvite(GameClient &client, MessageIn &message)
+{
+ MapComposite *map = client.character->getMap();
+ const int visualRange = Configuration::getValue("game_visualRange", 448);
+ std::string invitee = message.readString();
+
+ if (invitee == client.character->getName())
+ return;
+
+ for (CharacterIterator it(map->getWholeMapIterator()); it; ++it)
+ {
+ if ((*it)->getName() == invitee)
+ {
+ // calculate if the invitee is within the visual range
+ const int xInviter = client.character->getPosition().x;
+ const int yInviter = client.character->getPosition().y;
+ const int xInvitee = (*it)->getPosition().x;
+ const int yInvitee = (*it)->getPosition().y;
+ const int dx = std::abs(xInviter - xInvitee);
+ const int dy = std::abs(yInviter - yInvitee);
+ if (visualRange > std::max(dx, dy))
+ {
+ MessageOut out(GCMSG_PARTY_INVITE);
+ out.writeString(client.character->getName());
+ out.writeString(invitee);
+ accountHandler->send(out);
+ return;
+ }
+ break;
+ }
+ }
+
+ // Invitee was not found or is too far away
+ MessageOut out(GPMSG_PARTY_INVITE_ERROR);
+ out.writeString(invitee);
+ client.send(out);
+}
+
void GameHandler::sendNpcError(GameClient &client, int id,
const std::string &errorMsg)
{
diff --git a/src/game-server/gamehandler.h b/src/game-server/gamehandler.h
index 9c03d3d8..81e2b81d 100644
--- a/src/game-server/gamehandler.h
+++ b/src/game-server/gamehandler.h
@@ -149,6 +149,8 @@ class GameHandler: public ConnectionHandler
void handleNpcPostSend(GameClient &client, MessageIn &message);
+ void handlePartyInvite(GameClient &client, MessageIn &message);
+
void sendNpcError(GameClient &client, int id,
const std::string &errorMsg);