summaryrefslogtreecommitdiff
path: root/src/game-server
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2008-09-19 14:39:49 +0000
committerDavid Athay <ko2fan@gmail.com>2008-09-19 14:39:49 +0000
commit712b197ea0fb305905b4762422fdae1c49008710 (patch)
treea063bac5542f1408283d8150bde5346c2e24640d /src/game-server
parent410f448669a2ed843ff0b412924c04c8fbe87458 (diff)
downloadmanaserv-712b197ea0fb305905b4762422fdae1c49008710.tar.gz
manaserv-712b197ea0fb305905b4762422fdae1c49008710.tar.bz2
manaserv-712b197ea0fb305905b4762422fdae1c49008710.tar.xz
manaserv-712b197ea0fb305905b4762422fdae1c49008710.zip
Added post communication between chat and game servers.
Diffstat (limited to 'src/game-server')
-rw-r--r--src/game-server/accountconnection.cpp74
-rw-r--r--src/game-server/accountconnection.hpp10
-rw-r--r--src/game-server/gamehandler.cpp25
-rw-r--r--src/game-server/gamehandler.hpp10
-rw-r--r--src/game-server/main-game.cpp6
-rw-r--r--src/game-server/postman.hpp60
6 files changed, 185 insertions, 0 deletions
diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp
index 67ea9571..80e65730 100644
--- a/src/game-server/accountconnection.cpp
+++ b/src/game-server/accountconnection.cpp
@@ -30,6 +30,7 @@
#include "game-server/map.hpp"
#include "game-server/mapcomposite.hpp"
#include "game-server/mapmanager.hpp"
+#include "game-server/postman.hpp"
#include "game-server/quest.hpp"
#include "game-server/state.hpp"
#include "net/messagein.hpp"
@@ -112,6 +113,56 @@ void AccountConnection::processMessage(MessageIn &msg)
gameHandler->updateCharacter(charid, partyid);
} break;
+ case CGMSG_POST_RESPONSE:
+ {
+ // get the character
+ Character *character = postMan->getCharacter(msg.readLong());
+
+ // check character is still valid
+ if (!character)
+ {
+ break;
+ }
+
+ // create the message
+ MessageOut out(GPMSG_GET_POST_RESPONSE);
+
+ // get all the post for a character
+ while (msg.getUnreadLength())
+ {
+ // write the sender
+ out.writeLong(msg.readLong());
+
+ // write the contents
+ out.writeString(msg.readString());
+
+ // read the number of attachments then
+ // write the attachments
+ for (int i = 0; i < msg.readShort(); ++i)
+ {
+ // write the id and amount
+ out.writeShort(msg.readShort());
+ out.writeShort(msg.readShort());
+ }
+ }
+
+ // send post to character
+ gameHandler->sendTo(character, out);
+ } break;
+
+ case CGMSG_STORE_POST_RESPONSE:
+ {
+ // get character
+ Character *character = postMan->getCharacter(msg.readLong());
+
+ // create message and put error inside
+ MessageOut out(GPMSG_SEND_POST_RESPONSE);
+ out.writeByte(msg.readByte());
+
+ // send message to character
+ gameHandler->sendTo(character, out);
+ } break;
+
default:
LOG_WARN("Invalid message type");
break;
@@ -196,3 +247,26 @@ void AccountConnection::sendStatistics()
send(msg);
}
+void AccountConnection::sendPost(Character *c, MessageIn &msg)
+{
+ // send message to account server with id of sending player,
+ // the id of receiving player, the letter contents, and attachments
+ MessageOut out(GCMSG_STORE_POST);
+ out.writeLong(c->getDatabaseID());
+ out.writeString(msg.readString());
+ out.writeString(msg.readString());
+ while (msg.getUnreadLength())
+ {
+ // write the item id and amount for each attachment
+ out.writeLong(msg.readShort());
+ out.writeLong(msg.readShort());
+ }
+}
+
+void AccountConnection::getPost(Character *c)
+{
+ // send message to account server with id of retrieving player
+ MessageOut out(GCMSG_REQUEST_POST);
+ out.writeLong(c->getDatabaseID());
+ send(out);
+}
diff --git a/src/game-server/accountconnection.hpp b/src/game-server/accountconnection.hpp
index 6bad4651..2aa981ea 100644
--- a/src/game-server/accountconnection.hpp
+++ b/src/game-server/accountconnection.hpp
@@ -71,6 +71,16 @@ class AccountConnection : public Connection
*/
void sendStatistics();
+ /**
+ * Send letter
+ */
+ void sendPost(Character *, MessageIn &);
+
+ /**
+ * Get post
+ */
+ void getPost(Character *);
+
protected:
/**
* Processes server messages.
diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp
index bd5248bd..3540ac51 100644
--- a/src/game-server/gamehandler.cpp
+++ b/src/game-server/gamehandler.cpp
@@ -34,6 +34,7 @@
#include "game-server/map.hpp"
#include "game-server/mapcomposite.hpp"
#include "game-server/npc.hpp"
+#include "game-server/postman.hpp"
#include "game-server/state.hpp"
#include "game-server/trade.hpp"
#include "net/messagein.hpp"
@@ -449,6 +450,16 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message)
computer.character->respawn(); // plausibility check is done by character class
} break;
+ case PGMSG_SEND_POST:
+ {
+ handleSendPost(&computer, message);
+ } break;
+
+ case PGMSG_GET_POST:
+ {
+ handleGetPost(&computer, message);
+ } break;
+
default:
LOG_WARN("Invalid message type");
result.writeShort(XXMSG_INVALID);
@@ -585,3 +596,17 @@ void GameHandler::handleWalk(GameClient *client, MessageIn &message)
client->character->setDestination(dst);
}
+
+void GameHandler::handleSendPost(GameClient *client, MessageIn &message)
+{
+ // add the character so that the post man knows them
+ postMan->addCharacter(client->character);
+ accountHandler->sendPost(client->character, message);
+}
+
+void GameHandler::handleGetPost(GameClient *client, MessageIn &message)
+{
+ // add the character so that the post man knows them
+ postMan->addCharacter(client->character);
+ accountHandler->getPost(client->character);
+}
diff --git a/src/game-server/gamehandler.hpp b/src/game-server/gamehandler.hpp
index 77ba8a29..c41cdfd0 100644
--- a/src/game-server/gamehandler.hpp
+++ b/src/game-server/gamehandler.hpp
@@ -139,6 +139,16 @@ class GameHandler: public ConnectionHandler
*/
void handleWalk(GameClient *client, MessageIn &message);
+ /**
+ * Send a letter
+ */
+ void handleSendPost(GameClient *client, MessageIn &message);
+
+ /**
+ * Retrieve a letter
+ */
+ void handleGetPost(GameClient *client, MessageIn &message);
+
private:
/**
diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp
index 2cf025e7..b1c454e4 100644
--- a/src/game-server/main-game.cpp
+++ b/src/game-server/main-game.cpp
@@ -37,6 +37,7 @@
#include "game-server/itemmanager.hpp"
#include "game-server/mapmanager.hpp"
#include "game-server/monstermanager.hpp"
+#include "game-server/postman.hpp"
#include "game-server/resourcemanager.hpp"
#include "game-server/state.hpp"
#include "net/connectionhandler.hpp"
@@ -66,6 +67,9 @@ GameHandler *gameHandler;
/** Account server message handler */
AccountConnection *accountHandler;
+/** Post Man **/
+PostMan *postMan;
+
/** Callback used when SIGQUIT signal is received. */
void closeGracefully(int)
{
@@ -148,6 +152,7 @@ void initialize()
// singleton or a local variable in the event-loop
gameHandler = new GameHandler;
accountHandler = new AccountConnection;
+ postMan = new PostMan;
// --- Initialize enet.
if (enet_initialize() != 0) {
@@ -183,6 +188,7 @@ void deinitialize()
// Destroy message handlers
delete gameHandler;
delete accountHandler;
+ delete postMan;
// Destroy Managers
delete stringFilter;
diff --git a/src/game-server/postman.hpp b/src/game-server/postman.hpp
new file mode 100644
index 00000000..45963cf9
--- /dev/null
+++ b/src/game-server/postman.hpp
@@ -0,0 +1,60 @@
+/*
+ * The Mana World
+ * Copyright 2008 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMW_POSTMAN_H_
+#define _TMW_POSTMAN_H_
+
+#include <map>
+
+class Character;
+
+class PostMan
+{
+public:
+ Character* getCharacter(int id)
+ {
+ std::map<int, Character*>::iterator itr = mCharacters.find(id);
+ if (itr != mCharacters.end())
+ {
+ return itr->second;
+ }
+
+ return NULL;
+ }
+
+ void addCharacter(Character *player)
+ {
+ std::map<int, Character*>::iterator itr = mCharacters.find(player->getDatabaseID());
+ if (itr == mCharacters.end())
+ {
+ mCharacters.insert(std::pair<int, Character*>(player->getDatabaseID(), player));
+ }
+ }
+
+private:
+ std::map<int, Character*> mCharacters;
+};
+
+extern PostMan *postMan;
+
+#endif