summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
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 1d2f9e0..e5bfdc4 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 73eede6..1f6cfdb 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 392f053..c969a9a 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 52eb89a..4086275 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 3205d00..c758fd4 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 4908969..58d289f 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 9c03d3d..81e2b81 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);