eqemu_config.cpp code structure cleanup

This commit is contained in:
Akkadius 2014-12-15 21:03:09 -06:00
parent bbea7f4f53
commit 6f747c3678

View File

@ -26,53 +26,54 @@
std::string EQEmuConfig::ConfigFile = "eqemu_config.xml"; std::string EQEmuConfig::ConfigFile = "eqemu_config.xml";
EQEmuConfig *EQEmuConfig::_config = nullptr; EQEmuConfig *EQEmuConfig::_config = nullptr;
void EQEmuConfig::do_world(TiXmlElement *ele) { void EQEmuConfig::do_world(TiXmlElement *ele)
{
const char *text; const char *text;
TiXmlElement * sub_ele;; TiXmlElement * sub_ele;;
text = ParseTextBlock(ele, "shortname"); text = ParseTextBlock(ele, "shortname");
if (text) if (text) {
ShortName = text; ShortName = text;
}
text = ParseTextBlock(ele, "longname"); text = ParseTextBlock(ele, "longname");
if (text) if (text) {
LongName = text; LongName = text;
}
text = ParseTextBlock(ele, "address", true); text = ParseTextBlock(ele, "address", true);
if (text) if (text) {
WorldAddress = text; WorldAddress = text;
}
text = ParseTextBlock(ele, "localaddress", true); text = ParseTextBlock(ele, "localaddress", true);
if (text) if (text) {
LocalAddress = text; LocalAddress = text;
}
text = ParseTextBlock(ele, "maxclients", true); text = ParseTextBlock(ele, "maxclients", true);
if (text) if (text) {
MaxClients = atoi(text); MaxClients = atoi(text);
}
// Get the <key> element // Get the <key> element
text = ParseTextBlock(ele, "key", true); text = ParseTextBlock(ele, "key", true);
if (text) if (text) {
SharedKey = text; SharedKey = text;
}
// Get the <loginserver> element // Get the <loginserver> element
sub_ele = ele->FirstChildElement("loginserver"); sub_ele = ele->FirstChildElement("loginserver");
if (sub_ele) { if (sub_ele) {
text = ParseTextBlock(sub_ele, "host", true); text = ParseTextBlock(sub_ele, "host", true);
if (text) if (text) {
LoginHost = text; LoginHost = text;
}
text = ParseTextBlock(sub_ele, "port", true); text = ParseTextBlock(sub_ele, "port", true);
if (text) if (text) {
LoginPort = atoi(text); LoginPort = atoi(text);
}
text = ParseTextBlock(sub_ele, "account", true); text = ParseTextBlock(sub_ele, "account", true);
if (text) if (text) {
LoginAccount = text; LoginAccount = text;
}
text = ParseTextBlock(sub_ele, "password", true); text = ParseTextBlock(sub_ele, "password", true);
if (text) if (text) {
LoginPassword = text; LoginPassword = text;
}
} else { } else {
char str[32]; char str[32];
do { do {
@ -81,325 +82,369 @@ void EQEmuConfig::do_world(TiXmlElement *ele) {
if (sub_ele) { if (sub_ele) {
LoginConfig* loginconfig = new LoginConfig; LoginConfig* loginconfig = new LoginConfig;
text = ParseTextBlock(sub_ele, "host", true); text = ParseTextBlock(sub_ele, "host", true);
if (text) if (text) {
loginconfig->LoginHost = text; loginconfig->LoginHost = text;
}
text = ParseTextBlock(sub_ele, "port", true); text = ParseTextBlock(sub_ele, "port", true);
if (text) if (text) {
loginconfig->LoginPort = atoi(text); loginconfig->LoginPort = atoi(text);
}
text = ParseTextBlock(sub_ele, "account", true); text = ParseTextBlock(sub_ele, "account", true);
if (text) if (text) {
loginconfig->LoginAccount = text; loginconfig->LoginAccount = text;
}
text = ParseTextBlock(sub_ele, "password", true); text = ParseTextBlock(sub_ele, "password", true);
if (text) if (text) {
loginconfig->LoginPassword = text; loginconfig->LoginPassword = text;
}
loginlist.Insert(loginconfig); loginlist.Insert(loginconfig);
} }
} while (sub_ele); } while (sub_ele);
} }
// Check for locked // Check for locked
sub_ele = ele->FirstChildElement("locked"); sub_ele = ele->FirstChildElement("locked");
if (sub_ele != nullptr) if (sub_ele != nullptr) {
Locked = true; Locked = true;
}
// Get the <tcp> element // Get the <tcp> element
sub_ele = ele->FirstChildElement("tcp"); sub_ele = ele->FirstChildElement("tcp");
if (sub_ele != nullptr) { if (sub_ele != nullptr) {
text = sub_ele->Attribute("ip"); text = sub_ele->Attribute("ip");
if (text) if (text) {
WorldIP = text; WorldIP = text;
text = sub_ele->Attribute("port");
if (text)
WorldTCPPort=atoi(text);
text = sub_ele->Attribute("telnet");
if (text && !strcasecmp(text,"enabled"))
TelnetEnabled=true;
} }
text = sub_ele->Attribute("port");
if (text) {
WorldTCPPort = atoi(text);
}
text = sub_ele->Attribute("telnet");
if (text && !strcasecmp(text, "enabled")) {
TelnetEnabled = true;
}
}
// Get the <http> element // Get the <http> element
sub_ele = ele->FirstChildElement("http"); sub_ele = ele->FirstChildElement("http");
if (sub_ele != nullptr) { if (sub_ele != nullptr) {
// text = sub_ele->Attribute("ip"); // text = sub_ele->Attribute("ip");
// if (text) // if (text)
// WorldIP=text; // WorldIP=text;
text = sub_ele->Attribute("mimefile"); text = sub_ele->Attribute("mimefile");
if (text) if (text) {
WorldHTTPMimeFile = text; WorldHTTPMimeFile = text;
}
text = sub_ele->Attribute("port"); text = sub_ele->Attribute("port");
if (text) if (text) {
WorldHTTPPort = atoi(text); WorldHTTPPort = atoi(text);
}
text = sub_ele->Attribute("enabled"); text = sub_ele->Attribute("enabled");
if (text && !strcasecmp(text,"true")) if (text && !strcasecmp(text, "true")) {
WorldHTTPEnabled = true; WorldHTTPEnabled = true;
}
} }
} }
void EQEmuConfig::do_chatserver(TiXmlElement *ele) { void EQEmuConfig::do_chatserver(TiXmlElement *ele)
{
const char *text; const char *text;
text = ParseTextBlock(ele, "host", true); text = ParseTextBlock(ele, "host", true);
if (text) if (text) {
ChatHost = text; ChatHost = text;
}
text = ParseTextBlock(ele, "port", true); text = ParseTextBlock(ele, "port", true);
if (text) if (text) {
ChatPort = atoi(text); ChatPort = atoi(text);
} }
}
void EQEmuConfig::do_mailserver(TiXmlElement *ele) { void EQEmuConfig::do_mailserver(TiXmlElement *ele)
{
const char *text; const char *text;
text = ParseTextBlock(ele, "host", true); text = ParseTextBlock(ele, "host", true);
if (text) if (text) {
MailHost = text; MailHost = text;
}
text = ParseTextBlock(ele, "port", true); text = ParseTextBlock(ele, "port", true);
if (text) if (text) {
MailPort = atoi(text); MailPort = atoi(text);
} }
}
void EQEmuConfig::do_database(TiXmlElement *ele) { void EQEmuConfig::do_database(TiXmlElement *ele)
{
const char *text; const char *text;
text = ParseTextBlock(ele, "host", true); text = ParseTextBlock(ele, "host", true);
if (text) if (text) {
DatabaseHost = text; DatabaseHost = text;
}
text = ParseTextBlock(ele, "port", true); text = ParseTextBlock(ele, "port", true);
if (text) if (text) {
DatabasePort = atoi(text); DatabasePort = atoi(text);
}
text = ParseTextBlock(ele, "username", true); text = ParseTextBlock(ele, "username", true);
if (text) if (text) {
DatabaseUsername = text; DatabaseUsername = text;
}
text = ParseTextBlock(ele, "password", true); text = ParseTextBlock(ele, "password", true);
if (text) if (text) {
DatabasePassword = text; DatabasePassword = text;
}
text = ParseTextBlock(ele, "db", true); text = ParseTextBlock(ele, "db", true);
if (text) if (text) {
DatabaseDB = text; DatabaseDB = text;
} }
void EQEmuConfig::do_qsdatabase(TiXmlElement *ele) {
const char *text;
text=ParseTextBlock(ele,"host",true);
if (text)
QSDatabaseHost=text;
text=ParseTextBlock(ele,"port",true);
if (text)
QSDatabasePort=atoi(text);
text=ParseTextBlock(ele,"username",true);
if (text)
QSDatabaseUsername=text;
text=ParseTextBlock(ele,"password",true);
if (text)
QSDatabasePassword=text;
text=ParseTextBlock(ele,"db",true);
if (text)
QSDatabaseDB=text;
} }
void EQEmuConfig::do_zones(TiXmlElement *ele) {
void EQEmuConfig::do_qsdatabase(TiXmlElement *ele)
{
const char *text;
text = ParseTextBlock(ele, "host", true);
if (text) {
QSDatabaseHost = text;
}
text = ParseTextBlock(ele, "port", true);
if (text) {
QSDatabasePort = atoi(text);
}
text = ParseTextBlock(ele, "username", true);
if (text) {
QSDatabaseUsername = text;
}
text = ParseTextBlock(ele, "password", true);
if (text) {
QSDatabasePassword = text;
}
text = ParseTextBlock(ele, "db", true);
if (text) {
QSDatabaseDB = text;
}
}
void EQEmuConfig::do_zones(TiXmlElement *ele)
{
const char *text; const char *text;
TiXmlElement *sub_ele; TiXmlElement *sub_ele;
// TiXmlNode *node,*sub_node; // TiXmlNode *node,*sub_node;
text = ParseTextBlock(ele, "defaultstatus", true); text = ParseTextBlock(ele, "defaultstatus", true);
if (text) if (text) {
DefaultStatus = atoi(text); DefaultStatus = atoi(text);
}
// Get the <ports> element // Get the <ports> element
sub_ele = ele->FirstChildElement("ports"); sub_ele = ele->FirstChildElement("ports");
if (sub_ele != nullptr) { if (sub_ele != nullptr) {
text = sub_ele->Attribute("low"); text = sub_ele->Attribute("low");
if (text) if (text) {
ZonePortLow=atoi(text);; ZonePortLow = atoi(text);
};
text = sub_ele->Attribute("high"); text = sub_ele->Attribute("high");
if (text) if (text) {
ZonePortHigh = atoi(text); ZonePortHigh = atoi(text);
} }
} }
}
void EQEmuConfig::do_files(TiXmlElement *ele) { void EQEmuConfig::do_files(TiXmlElement *ele)
{
const char *text; const char *text;
text = ParseTextBlock(ele, "spells", true); text = ParseTextBlock(ele, "spells", true);
if (text) if (text) {
SpellsFile = text; SpellsFile = text;
}
text = ParseTextBlock(ele, "opcodes", true); text = ParseTextBlock(ele, "opcodes", true);
if (text) if (text) {
OpCodesFile = text; OpCodesFile = text;
}
text = ParseTextBlock(ele, "logsettings", true); text = ParseTextBlock(ele, "logsettings", true);
if (text) if (text) {
LogSettingsFile = text; LogSettingsFile = text;
}
text = ParseTextBlock(ele, "eqtime", true); text = ParseTextBlock(ele, "eqtime", true);
if (text) if (text) {
EQTimeFile = text; EQTimeFile = text;
} }
void EQEmuConfig::do_directories(TiXmlElement *ele) {
const char *text;
text=ParseTextBlock(ele,"maps",true);
if (text)
MapDir=text;
text=ParseTextBlock(ele,"quests",true);
if (text)
QuestDir=text;
text=ParseTextBlock(ele,"plugins",true);
if (text)
PluginDir=text;
} }
void EQEmuConfig::do_launcher(TiXmlElement *ele) { void EQEmuConfig::do_directories(TiXmlElement *ele)
{
const char *text;
text = ParseTextBlock(ele, "maps", true);
if (text) {
MapDir = text;
}
text = ParseTextBlock(ele, "quests", true);
if (text) {
QuestDir = text;
}
text = ParseTextBlock(ele, "plugins", true);
if (text) {
PluginDir = text;
}
}
void EQEmuConfig::do_launcher(TiXmlElement *ele)
{
const char *text; const char *text;
TiXmlElement *sub_ele; TiXmlElement *sub_ele;
text = ParseTextBlock(ele, "logprefix", true); text = ParseTextBlock(ele, "logprefix", true);
if (text) if (text) {
LogPrefix = text; LogPrefix = text;
}
text = ParseTextBlock(ele, "logsuffix", true); text = ParseTextBlock(ele, "logsuffix", true);
if (text) if (text) {
LogSuffix = text; LogSuffix = text;
}
// Get the <exe> element // Get the <exe> element
text = ParseTextBlock(ele, "exe", true); text = ParseTextBlock(ele, "exe", true);
if (text) if (text) {
ZoneExe = text; ZoneExe = text;
}
// Get the <timers> element // Get the <timers> element
sub_ele = ele->FirstChildElement("timers"); sub_ele = ele->FirstChildElement("timers");
if (sub_ele != nullptr) { if (sub_ele != nullptr) {
text = sub_ele->Attribute("restart"); text = sub_ele->Attribute("restart");
if (text) if (text) {
RestartWait = atoi(text); RestartWait = atoi(text);
}
text = sub_ele->Attribute("reterminate"); text = sub_ele->Attribute("reterminate");
if (text) if (text) {
TerminateWait = atoi(text); TerminateWait = atoi(text);
}
text = sub_ele->Attribute("initial"); text = sub_ele->Attribute("initial");
if (text) if (text) {
InitialBootWait = atoi(text); InitialBootWait = atoi(text);
}
text = sub_ele->Attribute("interval"); text = sub_ele->Attribute("interval");
if (text) if (text) {
ZoneBootInterval = atoi(text); ZoneBootInterval = atoi(text);
} }
} }
}
std::string EQEmuConfig::GetByName(const std::string &var_name) const { std::string EQEmuConfig::GetByName(const std::string &var_name) const
if(var_name == "ShortName") {
if (var_name == "ShortName") {
return (ShortName); return (ShortName);
if(var_name == "LongName") }
if (var_name == "LongName") {
return (LongName); return (LongName);
if(var_name == "WorldAddress") }
if (var_name == "WorldAddress") {
return (WorldAddress); return (WorldAddress);
if(var_name == "LoginHost") }
if (var_name == "LoginHost") {
return (LoginHost); return (LoginHost);
if(var_name == "LoginAccount") }
if (var_name == "LoginAccount") {
return (LoginAccount); return (LoginAccount);
if(var_name == "LoginPassword") }
if (var_name == "LoginPassword") {
return (LoginPassword); return (LoginPassword);
if(var_name == "LoginPort") }
if (var_name == "LoginPort") {
return (itoa(LoginPort)); return (itoa(LoginPort));
if(var_name == "Locked") }
if (var_name == "Locked") {
return (Locked ? "true" : "false"); return (Locked ? "true" : "false");
if(var_name == "WorldTCPPort") }
if (var_name == "WorldTCPPort") {
return (itoa(WorldTCPPort)); return (itoa(WorldTCPPort));
if(var_name == "WorldIP") }
if (var_name == "WorldIP") {
return (WorldIP); return (WorldIP);
if(var_name == "TelnetEnabled") }
if (var_name == "TelnetEnabled") {
return (TelnetEnabled ? "true" : "false"); return (TelnetEnabled ? "true" : "false");
if(var_name == "WorldHTTPPort") }
if (var_name == "WorldHTTPPort") {
return (itoa(WorldHTTPPort)); return (itoa(WorldHTTPPort));
if(var_name == "WorldHTTPMimeFile") }
if (var_name == "WorldHTTPMimeFile") {
return (WorldHTTPMimeFile); return (WorldHTTPMimeFile);
if(var_name == "WorldHTTPEnabled") }
if (var_name == "WorldHTTPEnabled") {
return (WorldHTTPEnabled ? "true" : "false"); return (WorldHTTPEnabled ? "true" : "false");
if(var_name == "ChatHost") }
if (var_name == "ChatHost") {
return (ChatHost); return (ChatHost);
if(var_name == "ChatPort") }
if (var_name == "ChatPort") {
return (itoa(ChatPort)); return (itoa(ChatPort));
if(var_name == "MailHost") }
if (var_name == "MailHost") {
return (MailHost); return (MailHost);
if(var_name == "MailPort") }
if (var_name == "MailPort") {
return (itoa(MailPort)); return (itoa(MailPort));
if(var_name == "DatabaseHost") }
if (var_name == "DatabaseHost") {
return (DatabaseHost); return (DatabaseHost);
if(var_name == "DatabaseUsername") }
if (var_name == "DatabaseUsername") {
return (DatabaseUsername); return (DatabaseUsername);
if(var_name == "DatabasePassword") }
if (var_name == "DatabasePassword") {
return (DatabasePassword); return (DatabasePassword);
if(var_name == "DatabaseDB") }
if (var_name == "DatabaseDB") {
return (DatabaseDB); return (DatabaseDB);
if(var_name == "DatabasePort") }
if (var_name == "DatabasePort") {
return (itoa(DatabasePort)); return (itoa(DatabasePort));
if(var_name == "QSDatabaseHost") }
if (var_name == "QSDatabaseHost") {
return (QSDatabaseHost); return (QSDatabaseHost);
if(var_name == "QSDatabaseUsername") }
if (var_name == "QSDatabaseUsername") {
return (QSDatabaseUsername); return (QSDatabaseUsername);
if(var_name == "QSDatabasePassword") }
if (var_name == "QSDatabasePassword") {
return (QSDatabasePassword); return (QSDatabasePassword);
if(var_name == "QSDatabaseDB") }
if (var_name == "QSDatabaseDB") {
return (QSDatabaseDB); return (QSDatabaseDB);
if(var_name == "QSDatabasePort") }
if (var_name == "QSDatabasePort") {
return (itoa(QSDatabasePort)); return (itoa(QSDatabasePort));
if(var_name == "SpellsFile") }
if (var_name == "SpellsFile") {
return (SpellsFile); return (SpellsFile);
if(var_name == "OpCodesFile") }
if (var_name == "OpCodesFile") {
return (OpCodesFile); return (OpCodesFile);
if(var_name == "EQTimeFile") }
if (var_name == "EQTimeFile") {
return (EQTimeFile); return (EQTimeFile);
if(var_name == "LogSettingsFile") }
if (var_name == "LogSettingsFile") {
return (LogSettingsFile); return (LogSettingsFile);
if(var_name == "MapDir") }
if (var_name == "MapDir") {
return (MapDir); return (MapDir);
if(var_name == "QuestDir") }
if (var_name == "QuestDir") {
return (QuestDir); return (QuestDir);
if(var_name == "PluginDir") }
if (var_name == "PluginDir") {
return (PluginDir); return (PluginDir);
if(var_name == "LogPrefix") }
if (var_name == "LogPrefix") {
return (LogPrefix); return (LogPrefix);
if(var_name == "LogSuffix") }
if (var_name == "LogSuffix") {
return (LogSuffix); return (LogSuffix);
if(var_name == "ZoneExe") }
if (var_name == "ZoneExe") {
return (ZoneExe); return (ZoneExe);
if(var_name == "ZonePortLow") }
if (var_name == "ZonePortLow") {
return (itoa(ZonePortLow)); return (itoa(ZonePortLow));
if(var_name == "ZonePortHigh") }
if (var_name == "ZonePortHigh") {
return (itoa(ZonePortHigh)); return (itoa(ZonePortHigh));
if(var_name == "DefaultStatus") }
if (var_name == "DefaultStatus") {
return (itoa(DefaultStatus)); return (itoa(DefaultStatus));
}
// if(var_name == "DynamicCount") // if(var_name == "DynamicCount")
// return(itoa(DynamicCount)); // return(itoa(DynamicCount));
return (""); return ("");