whether to setup a db can be configured for each server now

This commit is contained in:
H-M-H 2015-12-20 16:07:32 +01:00
parent 1e302aeb70
commit e35de5a371
4 changed files with 18 additions and 14 deletions

View file

@ -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 <read = r, write = w> <Database> <Prefix> <User> <Password> <IP> <Port>");
Console()->Register("add_sqlserver", "ssssssi?i", CFGFLAG_SERVER, ConAddSqlServer, this, "add a sqlserver <read = r, write = w> <Database> <Prefix> <User> <Password> <IP> <Port> [SetUpDatabase = 0]");
Console()->Register("dump_sqlservers", "i", CFGFLAG_SERVER, ConDumpSqlServers, this, "dumps all sqlservers readservers = r, writeservers = w");
#endif

View file

@ -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));
@ -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

View file

@ -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;
};

View file

@ -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")