summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChuck Miller <shadowmil@gmail.com>2009-07-20 17:46:18 -0400
committerChuck Miller <shadowmil@gmail.com>2009-07-20 17:46:18 -0400
commit575282d29ac181c990dc76de48c68d86ebd64efe (patch)
tree71430be3751dc84dbf5681f668099efec09cbcb6 /src
parent5c3f23831986dda46d1c41b8316dd901f1bf3164 (diff)
downloadmanaserv-575282d29ac181c990dc76de48c68d86ebd64efe.tar.gz
manaserv-575282d29ac181c990dc76de48c68d86ebd64efe.tar.bz2
manaserv-575282d29ac181c990dc76de48c68d86ebd64efe.tar.xz
manaserv-575282d29ac181c990dc76de48c68d86ebd64efe.zip
Have the game server reconnect with the account-server if account-server is restarted
Diffstat (limited to 'src')
-rw-r--r--src/defines.h3
-rw-r--r--src/game-server/gamehandler.cpp12
-rw-r--r--src/game-server/gamehandler.hpp6
-rw-r--r--src/game-server/main-game.cpp21
-rw-r--r--src/game-server/mapmanager.cpp56
-rw-r--r--src/game-server/mapmanager.hpp5
-rw-r--r--src/game-server/mapreader.cpp8
-rw-r--r--src/game-server/mapreader.hpp5
8 files changed, 98 insertions, 18 deletions
diff --git a/src/defines.h b/src/defines.h
index a3669412..d281be13 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -115,6 +115,8 @@ enum {
PAMSG_RECONNECT = 0x0065, // B*32 token
APMSG_RECONNECT_RESPONSE = 0x0066, // B error
+ GPMSG_ACCOUNT_SERVER_LOST = 0x0067, // -
+
// Game
GPMSG_PLAYER_MAP_CHANGE = 0x0100, // S filename, W x, W y
GPMSG_PLAYER_SERVER_CHANGE = 0x0101, // B*32 token, S game address, W game port
@@ -290,6 +292,7 @@ enum {
ERRMSG_EMAIL_ALREADY_EXISTS, // The Email Address already exists
ERRMSG_ALREADY_TAKEN, // name used was already taken
ERRMSG_SERVER_FULL, // the server is overloaded
+ ERRMSG_SERVER_NON_RESPONDING, // The account server connection is lost
ERRMSG_TIME_OUT, // data failed to arrive in due time
ERRMSG_LIMIT_REACHED // limit reached
};
diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp
index c20e8a2a..1c2e4f94 100644
--- a/src/game-server/gamehandler.cpp
+++ b/src/game-server/gamehandler.cpp
@@ -119,6 +119,18 @@ void GameHandler::completeServerChange(int id, const std::string &token,
}
}
+void GameHandler::disconnectAll()
+{
+ for (NetComputers::const_iterator i = clients.begin(),
+ i_end = clients.end(); i != i_end; ++i)
+ {
+ //FIXME: remove character in a safe way before disconnecting.
+ GameClient *c = static_cast< GameClient * >(*i);
+ MessageOut msg(GPMSG_ACCOUNT_SERVER_LOST);
+ c->disconnect(msg);
+ }
+}
+
void GameHandler::updateCharacter(int charid, int partyid)
{
for (NetComputers::const_iterator i = clients.begin(),
diff --git a/src/game-server/gamehandler.hpp b/src/game-server/gamehandler.hpp
index b3370348..e9d9fb20 100644
--- a/src/game-server/gamehandler.hpp
+++ b/src/game-server/gamehandler.hpp
@@ -81,6 +81,12 @@ class GameHandler: public ConnectionHandler
const std::string &address, int port);
/**
+ * Disconnect every player in case of losing the connection
+ * to the Account server.
+ */
+ void disconnectAll();
+
+ /**
* Updates the party id of the character
*/
void updateCharacter(int charid, int partyid);
diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp
index 12b8c78c..6a223cd0 100644
--- a/src/game-server/main-game.cpp
+++ b/src/game-server/main-game.cpp
@@ -149,7 +149,11 @@ void initialize()
stringFilter = new StringFilter;
ResourceManager::initialize();
- MapManager::initialize(DEFAULT_MAPSDB_FILE);
+ if (MapManager::initialize(DEFAULT_MAPSDB_FILE) < 1)
+ {
+ LOG_FATAL("The Game Server can't find any valid/available maps.");
+ exit(2);
+ }
ItemManager::initialize(DEFAULT_ITEMSDB_FILE);
MonsterManager::initialize(DEFAULT_MONSTERSDB_FILE);
StatusManager::initialize(DEFAULT_STATUSDB_FILE);
@@ -305,6 +309,9 @@ int main(int argc, char *argv[])
// Initialize world timer
worldTimer.start();
+ // Account connection lost flag
+ bool accountServerLost = false;
+
while (running)
{
elapsedWorldTicks = worldTimer.poll();
@@ -327,6 +334,8 @@ int main(int argc, char *argv[])
if (accountHandler->isConnected())
{
+ accountServerLost = false;
+
// Handle all messages that are in the message queues
accountHandler->process();
@@ -346,6 +355,16 @@ int main(int argc, char *argv[])
}
else
{
+ // If the connection to the account server is lost.
+ // Every players have to be logged out
+ if (!accountServerLost)
+ {
+ LOG_WARN("Lost connection to the server account. So disconnect players");
+ gameHandler->disconnectAll();
+ accountServerLost = true;
+ }
+
+ // Try to reconnect every 200 ticks
if (worldTime % 200 == 0)
{
accountHandler->start();
diff --git a/src/game-server/mapmanager.cpp b/src/game-server/mapmanager.cpp
index 0e682afa..390331dc 100644
--- a/src/game-server/mapmanager.cpp
+++ b/src/game-server/mapmanager.cpp
@@ -40,15 +40,18 @@ const MapManager::Maps &MapManager::getMaps()
return maps;
}
-void MapManager::initialize(const std::string &mapReferenceFile)
+unsigned int MapManager::initialize(const std::string &mapReferenceFile)
{
+ // Indicates the number of maps loaded successfully
+ unsigned int loadedMaps = 0;
+
int size;
char *data = ResourceManager::loadFile(mapReferenceFile, size);
if (!data) {
LOG_ERROR("Map Manager: Could not find " << mapReferenceFile << "!");
free(data);
- return;
+ return loadedMaps;
}
xmlDocPtr doc = xmlParseMemory(data, size);
@@ -58,7 +61,7 @@ void MapManager::initialize(const std::string &mapReferenceFile)
{
LOG_ERROR("Map Manager: Error while parsing map database ("
<< mapReferenceFile << ")!");
- return;
+ return loadedMaps;
}
xmlNodePtr node = xmlDocGetRootElement(doc);
@@ -67,7 +70,7 @@ void MapManager::initialize(const std::string &mapReferenceFile)
LOG_ERROR("Map Manager: " << mapReferenceFile
<< " is not a valid database file!");
xmlFreeDoc(doc);
- return;
+ return loadedMaps;
}
LOG_INFO("Loading map reference...");
@@ -79,13 +82,38 @@ void MapManager::initialize(const std::string &mapReferenceFile)
int id = XML::getProperty(node, "id", 0);
std::string name = XML::getProperty(node, "name", std::string());
+ std::string file = "maps/";
+ bool mapFileExists = false;
+ // Test id and map name
if (id != 0 && !name.empty())
{
- maps[id] = new MapComposite(id, name);
+ // Testing if the file is actually in the maps folder
+ file += name + ".tmx";
+ if (!ResourceManager::exists(file))
+ {
+ file += ".gz";
+ if (ResourceManager::exists(file))
+ {
+ mapFileExists = true;
+ }
+ }
+ else
+ {
+ mapFileExists = true;
+ }
+
+ if (mapFileExists)
+ {
+ maps[id] = new MapComposite(id, name);
+ loadedMaps++;
+ }
}
}
xmlFreeDoc(doc);
+ if (loadedMaps > 0)
+ LOG_INFO(loadedMaps << " valid map file references were loaded.");
+ return loadedMaps;
}
void MapManager::deinitialize()
@@ -114,14 +142,14 @@ MapComposite *MapManager::getMap(const std::string &mapName)
return NULL;
}
-void MapManager::raiseActive(int mapId)
+bool MapManager::raiseActive(int mapId)
{
Maps::iterator i = maps.find(mapId);
assert(i != maps.end());
MapComposite *composite = i->second;
if (composite->isActive())
{
- return;
+ return true;
}
std::string file = "maps/" + composite->getName() + ".tmx";
@@ -129,9 +157,17 @@ void MapManager::raiseActive(int mapId)
{
file += ".gz";
}
- MapReader::readMap(file, composite);
-
- LOG_INFO("Activated map \"" << file << "\" (id " << mapId << ")");
+ if (MapReader::readMap(file, composite))
+ {
+ LOG_INFO("Activated map \"" << file << "\" (id " << mapId << ")");
+ return true;
+ }
+ else
+ {
+ LOG_WARN("Couldn't activate invalid map \"" << file << "\" (id " <<
+ mapId << ")");
+ return false;
+ }
}
diff --git a/src/game-server/mapmanager.hpp b/src/game-server/mapmanager.hpp
index 23675974..5abdd78f 100644
--- a/src/game-server/mapmanager.hpp
+++ b/src/game-server/mapmanager.hpp
@@ -34,7 +34,7 @@ namespace MapManager
/**
* Loads map reference file and prepares maps.
*/
- void initialize(const std::string &mapReferenceFile);
+ unsigned int initialize(const std::string &mapReferenceFile);
/**
* Destroy loaded maps.
@@ -60,8 +60,9 @@ namespace MapManager
/**
* Sets the activity status of the map.
+ * @return true if the activation was successful.
*/
- void raiseActive(int mapId);
+ bool raiseActive(int mapId);
}
#endif
diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp
index fdf8e997..a1183cae 100644
--- a/src/game-server/mapreader.cpp
+++ b/src/game-server/mapreader.cpp
@@ -40,7 +40,8 @@
static std::vector< int > tilesetFirstGids;
-void MapReader::readMap(const std::string &filename, MapComposite *composite)
+bool MapReader::readMap(const std::string &filename, MapComposite
+*composite)
{
int fileSize;
char *buffer = ResourceManager::loadFile(filename, fileSize);
@@ -48,7 +49,7 @@ void MapReader::readMap(const std::string &filename, MapComposite *composite)
if (buffer == NULL)
{
LOG_ERROR("Error: Map file not found (" << filename.c_str() << ")");
- return;
+ return false;
}
xmlDocPtr doc = NULL;
@@ -75,7 +76,7 @@ void MapReader::readMap(const std::string &filename, MapComposite *composite)
if (!doc)
{
LOG_ERROR("Error while parsing map file '" << filename << "'!");
- return;
+ return false;
}
Map *map = NULL;
@@ -112,6 +113,7 @@ void MapReader::readMap(const std::string &filename, MapComposite *composite)
s->execute();
}
}
+ return true;
}
Map* MapReader::readMap(xmlNodePtr node, const std::string &path,
diff --git a/src/game-server/mapreader.hpp b/src/game-server/mapreader.hpp
index d5677007..58b9ebab 100644
--- a/src/game-server/mapreader.hpp
+++ b/src/game-server/mapreader.hpp
@@ -1,6 +1,6 @@
/*
* The Mana World
- * Copyright 2004 The Mana World Development Team
+ * Copyright 2004-2009 The Mana World Development Team
*
* This file is part of The Mana World.
*
@@ -39,8 +39,9 @@ class MapReader
public:
/**
* Read an XML map from a file.
+ * @return true if it was successful.
*/
- static void readMap(const std::string &filename,
+ static bool readMap(const std::string &filename,
MapComposite *composite);
private: