mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 18:18:18 +00:00
whether to setup a db can be configured for each server now
This commit is contained in:
parent
1e302aeb70
commit
e35de5a371
|
@ -2024,9 +2024,9 @@ void CServer::ConAddSqlServer(IConsole::IResult *pResult, void *pUserData)
|
||||||
{
|
{
|
||||||
CServer *pSelf = (CServer *)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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2041,15 +2041,17 @@ void CServer::ConAddSqlServer(IConsole::IResult *pResult, void *pUserData)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SetUpDb = pResult->NumArguments() == 8 ? pResult->GetInteger(7) : false;
|
||||||
|
|
||||||
CSqlServer** apSqlServers = ReadOnly ? pSelf->m_apSqlReadServers : pSelf->m_apSqlWriteServers;
|
CSqlServer** apSqlServers = ReadOnly ? pSelf->m_apSqlReadServers : pSelf->m_apSqlWriteServers;
|
||||||
|
|
||||||
for (int i = 0; i < MAX_SQLSERVERS; i++)
|
for (int i = 0; i < MAX_SQLSERVERS; i++)
|
||||||
{
|
{
|
||||||
if (!apSqlServers[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]);
|
void *TablesThread = thread_init(CreateTablesThread, apSqlServers[i]);
|
||||||
thread_detach(TablesThread);
|
thread_detach(TablesThread);
|
||||||
|
@ -2228,7 +2230,7 @@ void CServer::RegisterCommands()
|
||||||
|
|
||||||
#if defined (CONF_SQL)
|
#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");
|
Console()->Register("dump_sqlservers", "i", CFGFLAG_SERVER, ConDumpSqlServers, this, "dumps all sqlservers readservers = r, writeservers = w");
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,8 +7,9 @@
|
||||||
#include "sql_server.h"
|
#include "sql_server.h"
|
||||||
|
|
||||||
|
|
||||||
CSqlServer::CSqlServer(const char* pDatabase, const char* pPrefix, const char* pUser, const char* pPass, const char* pIp, int 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_Port(Port),
|
||||||
|
m_SetUpDB(SetUpDb)
|
||||||
{
|
{
|
||||||
str_copy(m_aDatabase, pDatabase, sizeof(m_aDatabase));
|
str_copy(m_aDatabase, pDatabase, sizeof(m_aDatabase));
|
||||||
str_copy(m_aPrefix, pPrefix, sizeof(m_aPrefix));
|
str_copy(m_aPrefix, pPrefix, sizeof(m_aPrefix));
|
||||||
|
@ -42,7 +43,7 @@ CSqlServer::~CSqlServer()
|
||||||
UnLock();
|
UnLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSqlServer::Connect(bool CreateDatabase)
|
bool CSqlServer::Connect()
|
||||||
{
|
{
|
||||||
Lock();
|
Lock();
|
||||||
|
|
||||||
|
@ -86,7 +87,7 @@ bool CSqlServer::Connect(bool CreateDatabase)
|
||||||
// Create Statement
|
// Create Statement
|
||||||
m_pStatement = m_pConnection->createStatement();
|
m_pStatement = m_pConnection->createStatement();
|
||||||
|
|
||||||
if (CreateDatabase)
|
if (m_SetUpDB)
|
||||||
{
|
{
|
||||||
char aBuf[128];
|
char aBuf[128];
|
||||||
// create database
|
// create database
|
||||||
|
@ -157,7 +158,7 @@ void CSqlServer::Disconnect()
|
||||||
|
|
||||||
void CSqlServer::CreateTables()
|
void CSqlServer::CreateTables()
|
||||||
{
|
{
|
||||||
if (!Connect(true))
|
if (!Connect())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
|
@ -10,10 +10,10 @@
|
||||||
class CSqlServer
|
class CSqlServer
|
||||||
{
|
{
|
||||||
public:
|
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();
|
~CSqlServer();
|
||||||
|
|
||||||
bool Connect(bool CreateDatabase = false);
|
bool Connect();
|
||||||
void Disconnect();
|
void Disconnect();
|
||||||
void CreateTables();
|
void CreateTables();
|
||||||
|
|
||||||
|
@ -47,6 +47,8 @@ private:
|
||||||
char m_aIp[64];
|
char m_aIp[64];
|
||||||
int m_Port;
|
int m_Port;
|
||||||
|
|
||||||
|
bool m_SetUpDB;
|
||||||
|
|
||||||
LOCK m_SqlLock;
|
LOCK m_SqlLock;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -217,7 +217,6 @@ MACRO_CONFIG_STR(SvScoreFolder, sv_score_folder, 32, "records", CFGFLAG_SERVER,
|
||||||
|
|
||||||
#if defined(CONF_SQL)
|
#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(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_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(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")
|
MACRO_CONFIG_INT(SvSaveGamesDelay, sv_savegames_delay, 60, 0, 10000, CFGFLAG_SERVER, "Delay in seconds for loading a savegame")
|
||||||
|
|
Loading…
Reference in a new issue