From faab9e8fd3c312c7651398ce68e2e4e4fa36ac78 Mon Sep 17 00:00:00 2001 From: David Athay Date: Tue, 21 Oct 2008 13:11:10 +0000 Subject: Game Server now reconnects to Account Server. Some postal system bugs fixed. --- ChangeLog | 9 +++++++++ src/account-server/dalstorage.cpp | 6 +----- src/account-server/dalstorage.hpp | 33 +++++++++++++++++++++++++-------- src/account-server/dalstoragesql.hpp | 5 ++++- src/account-server/serverhandler.cpp | 18 ++++++++++++------ src/defines.h | 6 +++--- src/game-server/accountconnection.cpp | 11 ++++++++++- src/game-server/main-game.cpp | 20 +++++++++++++++----- 8 files changed, 79 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9f4c365..98ee584 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-10-21 David Athay + + * src/account-server/serverhandler.cpp, + src/account-server/dalstorage.cpp, src/account-server/dalstorage.hpp, + src/account-server/dalstoragesql.hpp, src/defines.h, + src/game-server/accountconnection.cpp, src/game-server/main-game.cpp: The + game server now tries to connect to the account server when disconnected. + Fixed some of the postal system. + 2008-10-17 Andreas Habel * src/sql/sqlite/createTables.sql, src/sql/mysql/createTables.sql: added diff --git a/src/account-server/dalstorage.cpp b/src/account-server/dalstorage.cpp index 2484657..90f157b 100644 --- a/src/account-server/dalstorage.cpp +++ b/src/account-server/dalstorage.cpp @@ -30,6 +30,7 @@ #include "account-server/dalstoragesql.hpp" #include "chat-server/chatchannel.hpp" #include "chat-server/guild.hpp" +#include "chat-server/post.hpp" #include "common/configuration.hpp" #include "dal/dalexcept.h" #include "dal/dataproviderfactory.h" @@ -1037,11 +1038,6 @@ std::string DALStorage::getQuestVar(int id, std::string const &name) return std::string(); } -std::string DALStorage::getWorldStateVar(std::string const &name) -{ - return getWorldStateVar(name, -1); -} - std::string DALStorage::getWorldStateVar(std::string const &name, int map_id) { try diff --git a/src/account-server/dalstorage.hpp b/src/account-server/dalstorage.hpp index 970f550..f67ed26 100644 --- a/src/account-server/dalstorage.hpp +++ b/src/account-server/dalstorage.hpp @@ -33,6 +33,7 @@ class Account; class Character; class ChatChannel; class Guild; +class Letter; /** * A storage class that relies on DAL. @@ -253,20 +254,13 @@ class DALStorage */ void setQuestVar(int id, std::string const &, std::string const &); - /** - * Gets the string value of a world state variable. - * - * @param name Name of the requested world-state variable. - */ - std::string getWorldStateVar(std::string const &name); - /** * Gets the string value of a map specific world state variable. * * @param name Name of the requested world-state variable. * @param map_id Id of the specific map. */ - std::string getWorldStateVar(std::string const &name, int map_id); + std::string getWorldStateVar(std::string const &name, int map_id = -1); /** * Sets the value of a world state variable. @@ -286,6 +280,29 @@ class DALStorage void setWorldStateVar(std::string const &name, int map_id, std::string const &value); + /** + * Store post + * + * @param letter The letter to store + */ + void storePost(Letter *letter); + + /** + * Retrieve post + * + * @param playerId The id of the player requesting his post + */ + Letter* getStoredPost(int playerId); + + /** + * Add item to auction + * + * @param itemId The id of the item for auction + * @param player The player who put the item up for auction + * @param gold The amount of money to buy it + */ + void addAuctionItem(unsigned int itemId, int playerId, unsigned int gold); + private: /** * Copy constructor. diff --git a/src/account-server/dalstoragesql.hpp b/src/account-server/dalstoragesql.hpp index 95c89c0..b08c895 100644 --- a/src/account-server/dalstoragesql.hpp +++ b/src/account-server/dalstoragesql.hpp @@ -105,5 +105,8 @@ static char const *QUESTS_TBL_NAME = "tmw_quests"; */ static char const *WORLD_STATES_TBL_NAME = "tmw_world_states"; - +/** + * TABLE: tmw_auctions + */ +static char const *AUCTION_TBL_NAME = "tmw_auctions"; #endif // _TMWSERV_DALSTORAGE_SQL_H_ diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp index db8d264..5ed771a 100644 --- a/src/account-server/serverhandler.cpp +++ b/src/account-server/serverhandler.cpp @@ -331,8 +331,13 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) LOG_DEBUG("GCMSG_REQUEST_POST"); result.writeShort(CGMSG_POST_RESPONSE); - // get the character + // get the character id int characterId = msg.readLong(); + + // send the character id of sender + result.writeLong(characterId); + + // get the character based on the id Character *ptr = storage->getCharacter(characterId, NULL); if (!ptr) { @@ -344,18 +349,15 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) // get the post for that character Post *post = postalManager->getPost(ptr); - // send the character id of receiver - result.writeLong(characterId); - // send the post if valid if (post) { for (unsigned int i = 0; i < post->getNumberOfLetters(); ++i) { - // get each letter, send the sender's id, + // get each letter, send the sender's name, // the contents and any attachments Letter *letter = post->getLetter(i); - result.writeLong(letter->getSender()->getDatabaseID()); + result.writeString(letter->getSender()->getName()); result.writeString(letter->getContents()); std::vector items = letter->getAttachments(); for (unsigned int j = 0; j < items.size(); ++j) @@ -381,6 +383,9 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) int senderId = msg.readLong(); std::string receiverName = msg.readString(); + // for sending it back + result.writeLong(senderId); + // get their characters Character *sender = storage->getCharacter(senderId, NULL); Character *receiver = storage->getCharacter(receiverName); @@ -402,6 +407,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) } // save the letter + LOG_INFO("Creating letter"); Letter *letter = new Letter(0, sender, receiver); letter->addText(contents); for (unsigned int i = 0; i < items.size(); ++i) diff --git a/src/defines.h b/src/defines.h index 9d5d99d..3f73b1d 100644 --- a/src/defines.h +++ b/src/defines.h @@ -245,7 +245,7 @@ enum { PGMSG_SEND_POST = 0x04A0, // S player, S letter, { W attachment id } GPMSG_SEND_POST_RESPONSE = 0x04A1, // B error PGMSG_GET_POST = 0x04A2, // - GPMSG_GET_POST_RESPONSE = 0x04A3, // { L sender id, S letter, { W attachment id } } + GPMSG_GET_POST_RESPONSE = 0x04A3, // { S sender name, S letter, { W attachment id } } // Inter-server GAMSG_REGISTER = 0x0500, // S address, W port, { W map id }* @@ -262,8 +262,8 @@ enum { GAMSG_STATISTICS = 0x0560, // { W map id, W thing nb, W monster nb, W player nb, { L character id }* }* CGMSG_CHANGED_PARTY = 0x0590, // L character id, L party id GCMSG_REQUEST_POST = 0x05A0, // L character id - CGMSG_POST_RESPONSE = 0x05A1, // L receiver id, { L sender id, S letter, W num attachments { W attachment item id, W quantity } } - GCMSG_STORE_POST = 0x05A5, // L sender id, L receiver id, S letter, { W attachment item id, W quantity } + CGMSG_POST_RESPONSE = 0x05A1, // L receiver id, { S sender name, S letter, W num attachments { W attachment item id, W quantity } } + GCMSG_STORE_POST = 0x05A5, // L sender id, S receiver name, S letter, { W attachment item id, W quantity } CGMSG_STORE_POST_RESPONSE = 0x05A6, // L id, B error diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp index 80e6573..c5da8e2 100644 --- a/src/game-server/accountconnection.cpp +++ b/src/game-server/accountconnection.cpp @@ -131,7 +131,7 @@ void AccountConnection::processMessage(MessageIn &msg) while (msg.getUnreadLength()) { // write the sender - out.writeLong(msg.readLong()); + out.writeString(msg.readString()); // write the contents out.writeString(msg.readString()); @@ -155,6 +155,12 @@ void AccountConnection::processMessage(MessageIn &msg) // get character Character *character = postMan->getCharacter(msg.readLong()); + // check character is valid + if (!character) + { + break; + } + // create message and put error inside MessageOut out(GPMSG_SEND_POST_RESPONSE); out.writeByte(msg.readByte()); @@ -251,6 +257,7 @@ 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 + LOG_DEBUG("Sending GCMSG_STORE_POST."); MessageOut out(GCMSG_STORE_POST); out.writeLong(c->getDatabaseID()); out.writeString(msg.readString()); @@ -261,11 +268,13 @@ void AccountConnection::sendPost(Character *c, MessageIn &msg) out.writeLong(msg.readShort()); out.writeLong(msg.readShort()); } + send(out); } void AccountConnection::getPost(Character *c) { // send message to account server with id of retrieving player + LOG_DEBUG("Sending GCMSG_REQUEST_POST"); MessageOut out(GCMSG_REQUEST_POST); out.writeLong(c->getDatabaseID()); send(out); diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp index b1c454e..898bcb8 100644 --- a/src/game-server/main-game.cpp +++ b/src/game-server/main-game.cpp @@ -276,8 +276,7 @@ int main(int argc, char *argv[]) initialize(); if (!accountHandler->start()) { - LOG_FATAL("Unable to create a connection to an account server."); - return 3; + LOG_INFO("Unable to create a connection to an account server."); } int gameServerPort = @@ -308,11 +307,22 @@ int main(int argc, char *argv[]) // Print world time at 10 second intervals to show we're alive if (worldTime % 100 == 0) { LOG_INFO("World time: " << worldTime); - accountHandler->sendStatistics(); } - // Handle all messages that are in the message queues - accountHandler->process(); + if (accountHandler->isConnected()) + { + // Handle all messages that are in the message queues + accountHandler->process(); + + if (worldTime % 100 == 0) + { + accountHandler->sendStatistics(); + } + } + else + { + accountHandler->start(); + } gameHandler->process(); // Update all active objects/beings GameState::update(); -- cgit