summaryrefslogtreecommitdiffstats
path: root/src/account-server
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-03-12 22:18:22 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-03-13 21:53:25 +0100
commit1afbfb7e5fb5c133924ed8d376c6064575fc1c36 (patch)
treee5ec51d13fe20350a0d6a450bc92df4080f1691d /src/account-server
parent90fde5774f1e6ee1a3b649753fa7338e386a3c45 (diff)
downloadmanaserv-1afbfb7e5fb5c133924ed8d376c6064575fc1c36.tar.gz
manaserv-1afbfb7e5fb5c133924ed8d376c6064575fc1c36.tar.xz
manaserv-1afbfb7e5fb5c133924ed8d376c6064575fc1c36.zip
Fixed problems with map-bound world state variables
Due to a wrong primary key, which covered only the state name, it was impossible to use the same state name on different maps. This has now been fixed. Another problem was that the map variables were being included in the global variables, because the related database query did not filter on the map_id column properly. While fixing that, the map_id column now allows explicitly marking a state variable as global (with the value 0) or system variables (with the value -1). System variables are currently not accessible from scripts, but that could be changed later. Reviewed-by: Yohann Ferreira Reviewed-by: Erik Schilling
Diffstat (limited to 'src/account-server')
-rw-r--r--src/account-server/main-account.cpp6
-rw-r--r--src/account-server/serverhandler.cpp6
-rw-r--r--src/account-server/storage.cpp38
-rw-r--r--src/account-server/storage.h37
4 files changed, 35 insertions, 52 deletions
diff --git a/src/account-server/main-account.cpp b/src/account-server/main-account.cpp
index b0373db..44e65c4 100644
--- a/src/account-server/main-account.cpp
+++ b/src/account-server/main-account.cpp
@@ -369,9 +369,11 @@ int main(int argc, char *argv[])
const time_t startup = time(NULL);
std::stringstream timestamp;
timestamp << startup;
- storage->setWorldStateVar("accountserver_startup", timestamp.str());
+ storage->setWorldStateVar("accountserver_startup", timestamp.str(),
+ Storage::SystemMap);
const std::string revision = "$Revision$";
- storage->setWorldStateVar("accountserver_version", revision);
+ storage->setWorldStateVar("accountserver_version", revision,
+ Storage::SystemMap);
// -------------------------------------------------------------------------
while (running)
diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp
index c5104b8..9224338 100644
--- a/src/account-server/serverhandler.cpp
+++ b/src/account-server/serverhandler.cpp
@@ -208,7 +208,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
// transmit global world state variables
std::map<std::string, std::string> variables;
- variables = storage->getAllWorldStateVars(0);
+ variables = storage->getAllWorldStateVars(Storage::WorldMap);
for (std::map<std::string, std::string>::iterator i = variables.begin();
i != variables.end();
i++)
@@ -385,7 +385,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
std::string name = msg.readString();
std::string value = msg.readString();
// save the new value to the database
- storage->setWorldStateVar(name, value);
+ storage->setWorldStateVar(name, value, Storage::WorldMap);
// relay the new value to all gameservers
for (ServerHandler::NetComputers::iterator i = clients.begin();
i != clients.end();
@@ -403,7 +403,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
int mapid = msg.readInt32();
std::string name = msg.readString();
std::string value = msg.readString();
- storage->setWorldStateVar(name, mapid, value);
+ storage->setWorldStateVar(name, value, mapid);
} break;
case GAMSG_BAN_PLAYER:
diff --git a/src/account-server/storage.cpp b/src/account-server/storage.cpp
index ea3cee3..da51697 100644
--- a/src/account-server/storage.cpp
+++ b/src/account-server/storage.cpp
@@ -122,7 +122,7 @@ void Storage::open()
// Check database version here
int dbversion = utils::stringToInt(
- getWorldStateVar(DB_VERSION_PARAMETER));
+ getWorldStateVar(DB_VERSION_PARAMETER, SystemMap));
int supportedDbVersion = ManaServ::SUPPORTED_DB_VERSION;
if (dbversion != supportedDbVersion)
{
@@ -1666,14 +1666,8 @@ std::map<std::string, std::string> Storage::getAllWorldStateVars(int mapId)
}
void Storage::setWorldStateVar(const std::string &name,
- const std::string &value)
-{
- return setWorldStateVar(name, -1, value);
-}
-
-void Storage::setWorldStateVar(const std::string &name,
- int mapId,
- const std::string &value)
+ const std::string &value,
+ int mapId)
{
try
{
@@ -1682,12 +1676,8 @@ void Storage::setWorldStateVar(const std::string &name,
{
std::ostringstream deleteStateVar;
deleteStateVar << "DELETE FROM " << WORLD_STATES_TBL_NAME
- << " WHERE state_name = '" << name << "'";
-
- if (mapId >= 0)
- deleteStateVar << " AND map_id = '" << mapId << "'";
-
- deleteStateVar << ";";
+ << " WHERE state_name = '" << name << "'"
+ << " AND map_id = '" << mapId << "';";
mDb->execSql(deleteStateVar.str());
return;
}
@@ -1697,12 +1687,8 @@ void Storage::setWorldStateVar(const std::string &name,
updateStateVar << "UPDATE " << WORLD_STATES_TBL_NAME
<< " SET value = '" << value << "', "
<< " moddate = '" << time(0) << "' "
- << " WHERE state_name = '" << name << "'";
-
- if (mapId >= 0)
- updateStateVar << " AND map_id = '" << mapId << "'";
-
- updateStateVar << ";";
+ << " WHERE state_name = '" << name << "'"
+ << " AND map_id = '" << mapId << "';";
mDb->execSql(updateStateVar.str());
// If we updated a row, were finished here
@@ -1713,13 +1699,9 @@ void Storage::setWorldStateVar(const std::string &name,
std::ostringstream insertStateVar;
insertStateVar << "INSERT INTO " << WORLD_STATES_TBL_NAME
<< " (state_name, map_id, value , moddate) VALUES ("
- << "'" << name << "', ";
- if (mapId >= 0)
- insertStateVar << "'" << mapId << "', ";
- else
- insertStateVar << "0 , ";
-
- insertStateVar << "'" << value << "', "
+ << "'" << name << "', "
+ << "'" << mapId << "', "
+ << "'" << value << "', "
<< "'" << time(0) << "');";
mDb->execSql(insertStateVar.str());
}
diff --git a/src/account-server/storage.h b/src/account-server/storage.h
index 8135124..d6fb3ed 100644
--- a/src/account-server/storage.h
+++ b/src/account-server/storage.h
@@ -344,35 +344,34 @@ class Storage
*/
void setQuestVar(int id, const std::string &, const std::string &);
- /**
- * 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(const std::string &name, int mapId = -1);
+ enum SpecialMapId {
+ WorldMap = 0,
+ SystemMap = -1
+ };
/**
- * Sets the value of a world state variable.
+ * Gets the string value of a world state variable. The \a mapId should
+ * be a valid map ID or either WorldMap or SystemMap.
*
- * @param name Name of the world-state vairable.
- * @param value New value of the world-state variable.
+ * @param name Name of the requested world variable.
+ * @param mapId ID of the specific map.
*/
- void setWorldStateVar(const std::string &name,
- const std::string &value);
+ std::string getWorldStateVar(const std::string &name, int mapId);
/**
- * Sets the value of a world state variable of a specific map.
+ * Sets the value of a world state variable. The \a mapId should be a
+ * valid map ID or either WorldMap or SystemMap.
*
- * @param name Name of the world-state vairable.
- * @param mapId ID of the specific map
- * @param value New value of the world-state variable.
+ * @param name Name of the world vairable.
+ * @param value New value of the world variable.
*/
- void setWorldStateVar(const std::string &name, int mapId,
- const std::string &value);
+ void setWorldStateVar(const std::string &name,
+ const std::string &value,
+ int mapId);
/**
- * Gets the value of all world state variable of a specific map.
+ * Gets the value of all world state variables of a specific map. The
+ * \a mapId should be a valid map ID or either WorldMap or SystemMap.
*
* @param mapId ID of the specific map
*/