diff --git a/src/arcemu-logonserver/LogonConfigParser.cpp b/src/arcemu-logonserver/LogonConfigParser.cpp index 0a54506f3d..be73480abd 100644 --- a/src/arcemu-logonserver/LogonConfigParser.cpp +++ b/src/arcemu-logonserver/LogonConfigParser.cpp @@ -2,24 +2,84 @@ #include #include +enum LogonConfigError +{ + ERR_ALL_OK, + ERR_CANNOT_OPEN_FILE, + ERR_NOT_A_CONFIG_FILE, + ERR_NOT_LOGON_CONFIG, + ERR_WRONG_VERSION, + ERR_DB_NO_HOST, + ERR_DB_NO_USERNAME, + ERR_DB_NO_PASSWORD, + ERR_DB_NO_DB, + ERR_HOST_NO_LOGON_ADDR, + ERR_HOST_NO_LOGON_PORT, + ERR_HOST_NO_IS_ADDR, + ERR_HOST_NO_IS_PORT, + ERR_SEC_NO_PASSWORD, + ERR_SEC_NO_IP, + ERR_SEC_NO_MOD_IP, + ERR_NO_DB_SETTINGS, + ERR_NO_HOST_SETTINGS, + ERR_NO_SECURITY_SETTINGS, + MAX_ERROR +}; + +const char* errorString[] = +{ + "No error.", + "Cannot open file", + "Not a config file", + "Not a logon config file", + "Logon database, hostname couldn't be loaded", + "Logon database, username couldn't be loaded", + "Logon database, password couldn't be loaded", + "Logon database, database name couldn't be loaded", + "Host, logon address couldn't be loaded", + "Host, logon port couldn't be loaded", + "Host, interserver address couldn't be loaded", + "Host, interserver port couldn't be loaded", + "Security, remote password couldn't be loaded", + "Security, allowed ip ranges couldn't be loaded", + "Security, allowed mod ip ranges couldn't be loaded", + "Database connection settings couldn't be loaded", + "Host settings couldn't be loaded", + "Security settings couldn't be loaded", + "Wrong version" +}; + LogonConfigParser::LogonConfigParser() { + lastError = ERR_ALL_OK; + dbPartDone = false; + hostPartDone = false; + securityPartDone = false; } LogonConfigParser::~LogonConfigParser() { } +const char* LogonConfigParser::getLastError() const +{ + return errorString[ lastError ]; +} + bool LogonConfigParser::parseFile( const std::string &name ) { xmlDocPtr document = xmlParseFile( name.c_str() ); if( document == NULL ) + { + lastError = ERR_CANNOT_OPEN_FILE; return false; + } xmlNodePtr root = xmlDocGetRootElement( document ); if( root == NULL ) { xmlFreeDoc( document ); + lastError = ERR_NOT_A_CONFIG_FILE; return false; } @@ -56,6 +116,27 @@ bool LogonConfigParser::parseFile( const std::string &name ) } xmlFreeDoc( document ); + + if( !ok ) + return false; + + if( !dbPartDone ) + { + lastError = ERR_NO_DB_SETTINGS; + ok = false; + } + else + if( !hostPartDone ) + { + lastError = ERR_NO_HOST_SETTINGS; + ok = false; + } + else + if( !securityPartDone ) + { + lastError = ERR_NO_SECURITY_SETTINGS; + ok = false; + } if( !ok ) return false; @@ -66,21 +147,36 @@ bool LogonConfigParser::parseFile( const std::string &name ) bool LogonConfigParser::isConfig( _xmlNode *node ) { if( xmlStrcmp( node->name, BAD_CAST "config" ) != 0 ) + { + lastError = ERR_NOT_A_CONFIG_FILE; return false; + } xmlChar *prop = NULL; prop = xmlGetProp( node, BAD_CAST "type" ); if( prop == NULL ) + { + lastError = ERR_NOT_A_CONFIG_FILE; return false; + } if( xmlStrcmp( prop, BAD_CAST "logon" ) != 0 ) + { + lastError = ERR_NOT_LOGON_CONFIG; return false; + } prop = xmlGetProp( node, BAD_CAST "version" ); if( prop == NULL ) + { + lastError = ERR_NOT_A_CONFIG_FILE; return false; + } if( xmlStrcmp( prop, BAD_CAST requiredVersion.c_str() ) ) + { + lastError = ERR_WRONG_VERSION; return false; + } return true; } @@ -91,22 +187,34 @@ bool LogonConfigParser::parseDBPart( _xmlNode *node ) prop = xmlGetProp( node, BAD_CAST "hostname" ); if( prop == NULL ) + { + lastError = ERR_DB_NO_HOST; return false; + } data.logondb.host = reinterpret_cast< char* >( prop ); prop = xmlGetProp( node, BAD_CAST "username" ); if( prop == NULL ) + { + lastError = ERR_DB_NO_USERNAME; return false; + } data.logondb.username = reinterpret_cast< char* >( prop ); prop = xmlGetProp( node, BAD_CAST "password" ); if( prop == NULL ) + { + lastError = ERR_DB_NO_PASSWORD; return false; + } data.logondb.password = reinterpret_cast< char* >( prop ); prop = xmlGetProp( node, BAD_CAST "database" ); if( prop == NULL ) + { + lastError = ERR_DB_NO_DB; return false; + } data.logondb.database = reinterpret_cast< char* >( prop ); prop = xmlGetProp( node, BAD_CAST "port" ); @@ -115,6 +223,7 @@ bool LogonConfigParser::parseDBPart( _xmlNode *node ) else data.logondb.port = static_cast< unsigned int >( atoi( reinterpret_cast< char* >( prop ) ) ); + dbPartDone = true; return true; } @@ -124,24 +233,37 @@ bool LogonConfigParser::parseHostPart( _xmlNode *node ) prop = xmlGetProp( node, BAD_CAST "logon_address" ); if( prop == NULL ) + { + lastError = ERR_HOST_NO_LOGON_ADDR; return false; + } data.host.logon_address = reinterpret_cast< char* >( prop ); prop = xmlGetProp( node, BAD_CAST "logon_port" ); if( prop == NULL ) + { + lastError = ERR_HOST_NO_LOGON_PORT; return false; + } data.host.logon_port = static_cast< unsigned int >( atoi( reinterpret_cast< char* >( prop ) ) ); prop = xmlGetProp( node, BAD_CAST "is_address" ); if( prop == NULL ) + { + lastError = ERR_HOST_NO_IS_ADDR; return false; + } data.host.is_address = reinterpret_cast< char* >( prop ); prop = xmlGetProp( node, BAD_CAST "is_port" ); if( prop == NULL ) + { + lastError = ERR_HOST_NO_IS_PORT; return false; + } data.host.is_port = static_cast< unsigned int >( atoi( reinterpret_cast< char* >( prop ) ) ); + hostPartDone = false; return true; } @@ -173,19 +295,29 @@ bool LogonConfigParser::parseSecurityPart( _xmlNode *node ) prop = xmlGetProp( node, BAD_CAST "remote_password" ); if( prop == NULL ) + { + lastError = ERR_SEC_NO_PASSWORD; return false; + } data.security.remote_password = reinterpret_cast< char* >( prop ); prop = xmlGetProp( node, BAD_CAST "allowed_ip_ranges" ); if( prop == NULL ) + { + lastError = ERR_SEC_NO_IP; return false; + } data.security.allowed_ip_ranges = reinterpret_cast< char* >( prop ); prop = xmlGetProp( node, BAD_CAST "allowed_mod_ip_ranges" ); if( prop == NULL ) + { + lastError = ERR_SEC_NO_MOD_IP; return false; + } data.security.allowed_mod_ip_ranges = reinterpret_cast< char* >( prop ); + securityPartDone = true; return true; } diff --git a/src/arcemu-logonserver/LogonConfigParser.h b/src/arcemu-logonserver/LogonConfigParser.h index eb949f2a68..b2f4001c14 100644 --- a/src/arcemu-logonserver/LogonConfigParser.h +++ b/src/arcemu-logonserver/LogonConfigParser.h @@ -14,6 +14,7 @@ class LogonConfigParser bool parseFile( const std::string &name ); const LogonConfigData& getData() const{ return data; } void setRequiredVersion( const std::string &s ){ requiredVersion = s; } + const char* getLastError() const; private: bool isConfig( _xmlNode *node ); @@ -25,6 +26,11 @@ class LogonConfigParser LogonConfigData data; std::string requiredVersion; + unsigned long lastError; + + bool dbPartDone; + bool hostPartDone; + bool securityPartDone; }; #endif diff --git a/src/arcemu-logonserver/Main.cpp b/src/arcemu-logonserver/Main.cpp index 56dc1d92f3..881b3654b8 100644 --- a/src/arcemu-logonserver/Main.cpp +++ b/src/arcemu-logonserver/Main.cpp @@ -170,6 +170,7 @@ bool rehash2() if( !configParser.parseFile( config_file ) ) { LOG_ERROR("Config file could not be loaded."); + LOG_ERROR("ERROR: %s",configParser.getLastError() ); return false; } configFile = configParser.getData(); @@ -306,7 +307,10 @@ void LogonServer::Run(int argc, char** argv) if( parser.parseFile( "configs/logon.conf.xml" ) ) LOG_BASIC(" Passed without errors."); else + { LOG_BASIC(" Encountered one or more errors."); + LOG_BASIC("ERROR: %s", parser.getLastError() ); + } sLog.Close(); return;