summaryrefslogtreecommitdiff
path: root/src/account-server/storage.cpp
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/storage.cpp
parent90fde5774f1e6ee1a3b649753fa7338e386a3c45 (diff)
downloadmanaserv-1afbfb7e5fb5c133924ed8d376c6064575fc1c36.tar.gz
manaserv-1afbfb7e5fb5c133924ed8d376c6064575fc1c36.tar.bz2
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/storage.cpp')
-rw-r--r--src/account-server/storage.cpp38
1 files changed, 10 insertions, 28 deletions
diff --git a/src/account-server/storage.cpp b/src/account-server/storage.cpp
index ea3cee39..da516979 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());
}