1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
/*
* The Mana Server
* Copyright (C) 2013 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 "game-server/settingsmanager.h"
#include "common/defines.h"
#include "common/resourcemanager.h"
#include "game-server/abilitymanager.h"
#include "game-server/attributemanager.h"
#include "game-server/emotemanager.h"
#include "game-server/itemmanager.h"
#include "game-server/mapmanager.h"
#include "game-server/monstermanager.h"
#include "game-server/statusmanager.h"
#include "utils/logger.h"
#include "utils/xml.h"
/**
* Initialize all managers and load configuration into them.
*
* Fatal errors will call exit()
*/
void SettingsManager::initialize()
{
// initialize all managers in correct order
MapManager::initialize();
attributeManager->initialize();
abilityManager->initialize();
itemManager->initialize();
monsterManager->initialize();
emoteManager->initialize();
StatusManager::initialize();
loadFile(mSettingsFile);
checkStatus();
}
/**
* Reload managers with new configuration.
*
* @note This code is untested, some of the managers didn't even have empty implementations
* of reload().
*/
void SettingsManager::reload()
{
MapManager::reload();
attributeManager->reload();
abilityManager->reload();
itemManager->reload();
monsterManager->reload();
emoteManager->reload();
StatusManager::reload();
loadFile(mSettingsFile);
checkStatus();
}
/**
* Load a configuration file.
*/
void SettingsManager::loadFile(const std::string &filename)
{
LOG_INFO("Loading game settings from " << filename);
XML::Document doc(filename);
xmlNodePtr node = doc.rootNode();
// add file to include set
mIncludedFiles.insert(filename);
// FIXME: check root node's name when bjorn decides it's time
if (!node /*|| !xmlStrEqual(node->name, BAD_CAST "settings") */)
{
LOG_FATAL("Settings Manager: " << filename << " is not a valid database file!");
exit(EXIT_XML_BAD_PARAMETER);
}
// go through every node
for_each_xml_child_node(childNode, node)
{
if (childNode->type != XML_ELEMENT_NODE)
continue;
if (xmlStrEqual(childNode->name, BAD_CAST "include"))
{
// include an other file
const std::string includeFile = XML::getProperty(childNode, "file", std::string());
// check if file property was given
if (!includeFile.empty())
{
// build absolute path path
const ResourceManager::splittedPath splittedPath = ResourceManager::splitFileNameAndPath(filename);
const std::string realIncludeFile = ResourceManager::cleanPath(
ResourceManager::joinPaths(splittedPath.path, includeFile));
// check if we're not entering a loop
if (mIncludedFiles.find(realIncludeFile) != mIncludedFiles.end())
{
LOG_ERROR("Circular include loop detecting while including " << includeFile << " from " << filename);
}
else
{
// include that file
loadFile(realIncludeFile);
}
}
}
else if (xmlStrEqual(childNode->name, BAD_CAST "map"))
{
// map config
MapManager::readMapNode(childNode);
}
else if (xmlStrEqual(childNode->name, BAD_CAST "attribute"))
{
// attribute config
attributeManager->readAttributeNode(childNode);
}
else if (xmlStrEqual(childNode->name, BAD_CAST "ability"))
{
// ability config
abilityManager->readAbilityNode(childNode, filename);
}
else if (xmlStrEqual(childNode->name, BAD_CAST "slot"))
{
// equipement slot config
itemManager->readEquipSlotNode(childNode);
}
else if (xmlStrEqual(childNode->name, BAD_CAST "item"))
{
// item config
itemManager->readItemNode(childNode, filename);
}
else if (xmlStrEqual(childNode->name, BAD_CAST "monster"))
{
// monster config
monsterManager->readMonsterNode(childNode, filename);
}
else if (xmlStrEqual(childNode->name, BAD_CAST "emote"))
{
// emote config
emoteManager->readEmoteNode(childNode, filename);
}
else if (xmlStrEqual(childNode->name, BAD_CAST "status-effect"))
{
// status effects config
StatusManager::readStatusNode(childNode, filename);
}
else
{
// since the client and server share settings, don't be too strict
// LOG_WARN("Unexpected tag <" << childNode->name << "> in " << filename);
}
}
// remove this file from include stack
mIncludedFiles.erase(filename);
}
/**
* Finalize the configuration loading and check if all managers are happy with it.
*/
void SettingsManager::checkStatus()
{
MapManager::checkStatus();
attributeManager->checkStatus();
abilityManager->checkStatus();
itemManager->checkStatus();
monsterManager->checkStatus();
emoteManager->checkStatus();
StatusManager::checkStatus();
}
|