diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index f73120b20..c822cd8f9 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -2024,9 +2024,9 @@ void CServer::ConAddSqlServer(IConsole::IResult *pResult, void *pUserData) { CServer *pSelf = (CServer *)pUserData; - if (pResult->NumArguments() != 7) + if (pResult->NumArguments() != 7 && pResult->NumArguments() != 8) { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "7 arguments are required"); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "7 or 8 arguments are required"); return; } @@ -2041,15 +2041,17 @@ void CServer::ConAddSqlServer(IConsole::IResult *pResult, void *pUserData) return; } + bool SetUpDb = pResult->NumArguments() == 8 ? pResult->GetInteger(7) : false; + CSqlServer** apSqlServers = ReadOnly ? pSelf->m_apSqlReadServers : pSelf->m_apSqlWriteServers; for (int i = 0; i < MAX_SQLSERVERS; i++) { if (!apSqlServers[i]) { - apSqlServers[i] = new CSqlServer(pResult->GetString(1), pResult->GetString(2), pResult->GetString(3), pResult->GetString(4), pResult->GetString(5), pResult->GetInteger(6)); + apSqlServers[i] = new CSqlServer(pResult->GetString(1), pResult->GetString(2), pResult->GetString(3), pResult->GetString(4), pResult->GetString(5), pResult->GetInteger(6), SetUpDb); - if(g_Config.m_SvSqlCreateTables == 3 || (g_Config.m_SvSqlCreateTables == 1 && ReadOnly) || (g_Config.m_SvSqlCreateTables == 2 && !ReadOnly)) + if(SetUpDb) { void *TablesThread = thread_init(CreateTablesThread, apSqlServers[i]); thread_detach(TablesThread); @@ -2228,7 +2230,7 @@ void CServer::RegisterCommands() #if defined (CONF_SQL) - Console()->Register("add_sqlserver", "ssssssi", CFGFLAG_SERVER, ConAddSqlServer, this, "add a sqlserver "); + Console()->Register("add_sqlserver", "ssssssi?i", CFGFLAG_SERVER, ConAddSqlServer, this, "add a sqlserver [SetUpDatabase = 0]"); Console()->Register("dump_sqlservers", "i", CFGFLAG_SERVER, ConDumpSqlServers, this, "dumps all sqlservers readservers = r, writeservers = w"); #endif diff --git a/src/engine/server/sql_server.cpp b/src/engine/server/sql_server.cpp index 0112596a8..ee29493c9 100644 --- a/src/engine/server/sql_server.cpp +++ b/src/engine/server/sql_server.cpp @@ -7,8 +7,9 @@ #include "sql_server.h" -CSqlServer::CSqlServer(const char* pDatabase, const char* pPrefix, const char* pUser, const char* pPass, const char* pIp, int Port) : - m_Port(Port) +CSqlServer::CSqlServer(const char* pDatabase, const char* pPrefix, const char* pUser, const char* pPass, const char* pIp, int Port, bool SetUpDb) : + m_Port(Port), + m_SetUpDB(SetUpDb) { str_copy(m_aDatabase, pDatabase, sizeof(m_aDatabase)); str_copy(m_aPrefix, pPrefix, sizeof(m_aPrefix)); @@ -20,7 +21,7 @@ CSqlServer::CSqlServer(const char* pDatabase, const char* pPrefix, const char* p m_pConnection = 0; m_pResults = 0; m_pStatement = 0; - + m_SqlLock = lock_create(); } @@ -42,7 +43,7 @@ CSqlServer::~CSqlServer() UnLock(); } -bool CSqlServer::Connect(bool CreateDatabase) +bool CSqlServer::Connect() { Lock(); @@ -86,7 +87,7 @@ bool CSqlServer::Connect(bool CreateDatabase) // Create Statement m_pStatement = m_pConnection->createStatement(); - if (CreateDatabase) + if (m_SetUpDB) { char aBuf[128]; // create database @@ -157,7 +158,7 @@ void CSqlServer::Disconnect() void CSqlServer::CreateTables() { - if (!Connect(true)) + if (!Connect()) return; try diff --git a/src/engine/server/sql_server.h b/src/engine/server/sql_server.h index e505efc33..cf1b55206 100644 --- a/src/engine/server/sql_server.h +++ b/src/engine/server/sql_server.h @@ -10,10 +10,10 @@ class CSqlServer { public: - CSqlServer(const char* pDatabase, const char* pPrefix, const char* pUser, const char* pPass, const char* pIp, int Port); + CSqlServer(const char* pDatabase, const char* pPrefix, const char* pUser, const char* pPass, const char* pIp, int Port, bool SetUpDb = false); ~CSqlServer(); - bool Connect(bool CreateDatabase = false); + bool Connect(); void Disconnect(); void CreateTables(); @@ -47,6 +47,8 @@ private: char m_aIp[64]; int m_Port; + bool m_SetUpDB; + LOCK m_SqlLock; }; diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index b8572feb9..a2b24f90f 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -217,7 +217,6 @@ MACRO_CONFIG_STR(SvScoreFolder, sv_score_folder, 32, "records", CFGFLAG_SERVER, #if defined(CONF_SQL) MACRO_CONFIG_INT(SvUseSQL, sv_use_sql, 0, 0, 1, CFGFLAG_SERVER, "Enables SQL DB instead of record file") -MACRO_CONFIG_INT(SvSqlCreateTables, sv_sql_create_tables, 0, 0, 3, CFGFLAG_SERVER, "Try to create the SQL tables when starting (O = never, 1 = readserver, 2 = write server, 3 = both)") MACRO_CONFIG_STR(SvSqlServerName, sv_sql_servername, 5, "UNK", CFGFLAG_SERVER, "SQL Server name that is inserted into record table") MACRO_CONFIG_INT(SvSaveGames, sv_savegames, 1, 0, 1, CFGFLAG_SERVER, "Enables savegames (/save and /load)") MACRO_CONFIG_INT(SvSaveGamesDelay, sv_savegames_delay, 60, 0, 10000, CFGFLAG_SERVER, "Delay in seconds for loading a savegame")