summaryrefslogtreecommitdiff
path: root/src/game-server/gamehandler.cpp
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/game-server/gamehandler.cpp
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/game-server/gamehandler.cpp')
-rw-r--r--src/game-server/gamehandler.cpp43
1 files changed, 43 insertions, 0 deletions
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)
{