summaryrefslogtreecommitdiffstats
path: root/src/game-server
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2010-05-13 13:39:52 +0200
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2010-05-16 23:25:19 +0200
commite5c7ef4573adcdcafec7523a77724b171456b215 (patch)
tree797833ddc766d92131da86096de81741a94f4d20 /src/game-server
parent0a48f0d41653d0a0758fc84fd6a18830bd37da18 (diff)
downloadmanaserv-e5c7ef4573adcdcafec7523a77724b171456b215.tar.gz
manaserv-e5c7ef4573adcdcafec7523a77724b171456b215.tar.xz
manaserv-e5c7ef4573adcdcafec7523a77724b171456b215.zip
Changed and split up the default location for loading data
Instead of loading data from a 'data' directory in the current working directory, the server now uses clientDataPath and serverDataPath as specified in the configuration. This removes the need to set up symbolic links in order to merge these two types of data. The default values point to example/clientdata and example/serverdata, where a minimal example world can be developed to make setting up an initial server quick and easy. The XML::Document convenience class was copied over from the client. Also, the ResourceManager is now shared between both servers, since the account client is reading items.xml. Reviewed-by: Jared Adams
Diffstat (limited to 'src/game-server')
-rw-r--r--src/game-server/itemmanager.cpp7
-rw-r--r--src/game-server/main-game.cpp2
-rw-r--r--src/game-server/mapmanager.cpp6
-rw-r--r--src/game-server/mapreader.cpp6
-rw-r--r--src/game-server/monster.cpp2
-rw-r--r--src/game-server/monstermanager.cpp6
-rw-r--r--src/game-server/resourcemanager.cpp175
-rw-r--r--src/game-server/resourcemanager.hpp53
-rw-r--r--src/game-server/skillmanager.cpp2
-rw-r--r--src/game-server/statusmanager.cpp7
10 files changed, 18 insertions, 248 deletions
diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp
index 5c946a4..96f9c21 100644
--- a/src/game-server/itemmanager.cpp
+++ b/src/game-server/itemmanager.cpp
@@ -18,19 +18,18 @@
* along with The Mana Server. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <map>
-#include <set>
-
#include "game-server/itemmanager.hpp"
#include "defines.h"
+#include "common/resourcemanager.hpp"
#include "game-server/item.hpp"
-#include "game-server/resourcemanager.hpp"
#include "game-server/skillmanager.hpp"
#include "scripting/script.hpp"
#include "utils/logger.h"
#include "utils/xml.hpp"
+#include <map>
+#include <set>
#include <sstream>
typedef std::map< int, ItemClass * > ItemClasses;
diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp
index 36da4c3..1e01bcb 100644
--- a/src/game-server/main-game.cpp
+++ b/src/game-server/main-game.cpp
@@ -37,6 +37,7 @@
#include "common/configuration.hpp"
#include "common/permissionmanager.hpp"
+#include "common/resourcemanager.hpp"
#include "game-server/accountconnection.hpp"
#include "game-server/gamehandler.hpp"
#include "game-server/skillmanager.hpp"
@@ -45,7 +46,6 @@
#include "game-server/monstermanager.hpp"
#include "game-server/statusmanager.hpp"
#include "game-server/postman.hpp"
-#include "game-server/resourcemanager.hpp"
#include "game-server/state.hpp"
#include "net/bandwidth.hpp"
#include "net/connectionhandler.hpp"
diff --git a/src/game-server/mapmanager.cpp b/src/game-server/mapmanager.cpp
index b27348b..ced6b58 100644
--- a/src/game-server/mapmanager.cpp
+++ b/src/game-server/mapmanager.cpp
@@ -18,17 +18,17 @@
* along with The Mana Server. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <cassert>
-
#include "game-server/mapmanager.hpp"
+#include "common/resourcemanager.hpp"
#include "game-server/map.hpp"
#include "game-server/mapcomposite.hpp"
#include "game-server/mapreader.hpp"
-#include "game-server/resourcemanager.hpp"
#include "utils/logger.h"
#include "utils/xml.hpp"
+#include <cassert>
+
/**
* List of all the game maps, be they present or not on this server.
*/
diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp
index 30e73bf..8088582 100644
--- a/src/game-server/mapreader.cpp
+++ b/src/game-server/mapreader.cpp
@@ -18,15 +18,13 @@
* along with The Mana Server. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <cstring>
-
#include "game-server/mapreader.hpp"
+#include "common/resourcemanager.hpp"
#include "game-server/map.hpp"
#include "game-server/mapcomposite.hpp"
#include "game-server/mapmanager.hpp"
#include "game-server/monstermanager.hpp"
-#include "game-server/resourcemanager.hpp"
#include "game-server/spawnarea.hpp"
#include "game-server/trigger.hpp"
#include "scripting/script.hpp"
@@ -37,6 +35,8 @@
#include "utils/zlib.hpp"
#include "utils/string.hpp"
+#include <cstring>
+
static std::vector< int > tilesetFirstGids;
bool MapReader::readMap(const std::string &filename, MapComposite
diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp
index 5bd56cc..2489e73 100644
--- a/src/game-server/monster.cpp
+++ b/src/game-server/monster.cpp
@@ -21,10 +21,10 @@
#include "game-server/monster.hpp"
#include "common/configuration.hpp"
+#include "common/resourcemanager.hpp"
#include "game-server/character.hpp"
#include "game-server/collisiondetection.hpp"
#include "game-server/item.hpp"
-#include "game-server/resourcemanager.hpp"
#include "game-server/mapcomposite.hpp"
#include "game-server/state.hpp"
#include "scripting/script.hpp"
diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp
index e3beda7..af6f3a2 100644
--- a/src/game-server/monstermanager.cpp
+++ b/src/game-server/monstermanager.cpp
@@ -18,16 +18,16 @@
* along with The Mana Server. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <map>
-
#include "game-server/monstermanager.hpp"
+#include "common/resourcemanager.hpp"
#include "game-server/itemmanager.hpp"
#include "game-server/monster.hpp"
-#include "game-server/resourcemanager.hpp"
#include "utils/logger.h"
#include "utils/xml.hpp"
+#include <map>
+
typedef std::map< int, MonsterClass * > MonsterClasses;
static MonsterClasses monsterClasses; /**< Monster reference */
static std::string monsterReferenceFile;
diff --git a/src/game-server/resourcemanager.cpp b/src/game-server/resourcemanager.cpp
deleted file mode 100644
index 3545484..0000000
--- a/src/game-server/resourcemanager.cpp
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * The Mana Server
- * Copyright (C) 2004-2010 The Mana World Development Team
- *
- * This file is part of The Mana Server.
- *
- * The Mana Server 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 Server 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 Server. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <cstdlib>
-#include <cstring>
-
-#ifdef _WIN32
-#include <io.h>
-#include <direct.h>
-#else
-#include <unistd.h>
-#include <dirent.h>
-#endif
-
-#include <physfs.h>
-
-#include "game-server/resourcemanager.hpp"
-
-#include "utils/logger.h"
-
-#define PKG_DATADIR ""
-
-void ResourceManager::initialize()
-{
- PHYSFS_permitSymbolicLinks(1);
- // Add the main data directory to our PhysicsFS search path
- PHYSFS_addToSearchPath("data", 1);
- PHYSFS_addToSearchPath(PKG_DATADIR "data", 1);
-
-#ifdef _WIN32
- // Define the path in which to search
- std::string searchString = std::string("data/*.zip");
-
- // Create our find file data structure
- struct _finddata_t findFileInfo;
-
- // Find the first zipped file
- long handle =
- static_cast<long>(::_findfirst(searchString.c_str(), &findFileInfo));
- long file = handle;
-
- // Loop until all files we're searching for are found
- while (file >= 0) {
- // Define the file path string
- std::string filePath = std::string("data/") +
- std::string(findFileInfo.name);
-
- LOG_INFO("Adding to PhysicsFS: " << findFileInfo.name);
-
- // Add the zip file to our PhysicsFS search path
- PHYSFS_addToSearchPath(filePath.c_str(), 1);
-
- // Find the next file
- file = ::_findnext(handle, &findFileInfo);
- }
-
- // Shutdown findfile stuff
- ::_findclose(handle);
-#else
- // Retrieve the current path
- char programPath[256];
- if (!getcwd(programPath, 256))
- strcpy(programPath, ".");
- strncat(programPath, "/data", 256 - strlen(programPath) - 1);
-
- // Create our directory structure
- DIR *dir = opendir(programPath);
-
- // Return if the directory is invalid
- if (dir == NULL) {
- return;
- }
-
- struct dirent *direntry;
- while ((direntry = readdir(dir)) != NULL)
- {
- char *ext = strstr(direntry->d_name, ".zip");
-
- if (ext != NULL && strcmp(ext, ".zip") == 0)
- {
- // Define the file path string
- std::string filePath = std::string(programPath) +
- std::string("/") + std::string(direntry->d_name);
-
- LOG_INFO("Adding to PhysicsFS: " << filePath);
-
- // Add the zip file to our PhysicsFS search path
- PHYSFS_addToSearchPath(filePath.c_str(), 1);
- }
- }
-
- closedir(dir);
-#endif
-}
-
-bool ResourceManager::exists(const std::string &path)
-{
- return PHYSFS_exists(path.c_str());
-}
-
-char *ResourceManager::loadFile(const std::string &fileName, int &fileSize,
- bool removeBOM)
-{
- // Attempt to open the specified file using PhysicsFS
- PHYSFS_file* file = PHYSFS_openRead(fileName.c_str());
-
- // If the handler is an invalid pointer indicate failure
- if (file == NULL)
- {
- LOG_WARN("Failed to load '" << fileName << "': "
- << PHYSFS_getLastError());
- return NULL;
- }
-
- // Get the size of the file
- fileSize = PHYSFS_fileLength(file);
-
- if (removeBOM)
- {
- // Inspired by BOMstrip from Peter Pentchev, 2008, public domain.
- const char utf8Bom[] = "\xef\xbb\xbf";
- const int bomLength = sizeof(utf8Bom);
- char bomBuffer[bomLength];
- PHYSFS_read(file, bomBuffer, 1, bomLength);
-
- std::istringstream iss(std::string(bomBuffer, bomLength));
- std::string line;
-
- // if we find a BOM, then we remove it from the buffer
- if (std::getline(iss, line) && !line.substr(0, 3).compare(utf8Bom))
- {
- LOG_INFO("Found a Byte Order Mask (BOM) in '" << fileName);
- fileSize = fileSize - bomLength;
- }
- else
- {
- // No BOM, we get back to the file start.
- PHYSFS_seek(file, 0);
- }
- }
-
- // Allocate memory and load the file
- char *buffer = (char *) malloc(fileSize + 1);
- if (PHYSFS_read(file, buffer, 1, fileSize) != fileSize)
- {
- free(buffer);
- LOG_WARN("Failed to load '" << fileName << "': "
- << PHYSFS_getLastError());
- return NULL;
- }
-
- // Close the file and let the user deallocate the memory
- PHYSFS_close(file);
-
- // Add a trailing null character, so that the file can be used as a string
- buffer[fileSize] = 0;
- return buffer;
-}
diff --git a/src/game-server/resourcemanager.hpp b/src/game-server/resourcemanager.hpp
deleted file mode 100644
index 74c4189..0000000
--- a/src/game-server/resourcemanager.hpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * The Mana Server
- * Copyright (C) 2004-2010 The Mana World Development Team
- *
- * This file is part of The Mana Server.
- *
- * The Mana Server 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 Server 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 Server. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef RESOURCE_MANAGER_H
-#define RESOURCE_MANAGER_H
-
-#include <string>
-
-namespace ResourceManager
-{
- /**
- * Searches for zip files and adds them to PhysFS search path.
- */
- void initialize();
-
- /**
- * Checks whether the given file or directory exists in the search path
- */
- bool exists(const std::string &path);
-
- /**
- * Allocates data into a buffer pointer for raw data loading. The
- * returned data is expected to be freed using <code>free()</code>.
- *
- * @param fileName The name of the file to be loaded.
- * @param fileSize The size of the file that was loaded.
- *
- * @return An allocated byte array containing the data that was loaded,
- * or <code>NULL</code> on failure.
- * @note The array contains an extra \0 character at position fileSize.
- */
- char *loadFile(const std::string &fileName, int &fileSize,
- bool removeBOM = false);
-}
-
-#endif
diff --git a/src/game-server/skillmanager.cpp b/src/game-server/skillmanager.cpp
index c4a18e5..ea29e58 100644
--- a/src/game-server/skillmanager.cpp
+++ b/src/game-server/skillmanager.cpp
@@ -20,7 +20,7 @@
#include "game-server/skillmanager.hpp"
-#include "game-server/resourcemanager.hpp"
+#include "common/resourcemanager.hpp"
#include "utils/string.hpp" // for the toupper function
#include "utils/logger.h"
#include "utils/xml.hpp"
diff --git a/src/game-server/statusmanager.cpp b/src/game-server/statusmanager.cpp
index 3472ae7..173996d 100644
--- a/src/game-server/statusmanager.cpp
+++ b/src/game-server/statusmanager.cpp
@@ -18,17 +18,16 @@
* along with The Mana Server. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <map>
-#include <set>
-
#include "game-server/statusmanager.hpp"
+#include "common/resourcemanager.hpp"
#include "game-server/statuseffect.hpp"
-#include "game-server/resourcemanager.hpp"
#include "scripting/script.hpp"
#include "utils/logger.h"
#include "utils/xml.hpp"
+#include <map>
+#include <set>
#include <sstream>
typedef std::map< int, StatusEffect * > StatusEffects;