mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Add sv_sql_bindaddr (fixes #5830)
This commit is contained in:
parent
cef096ecd7
commit
a67e30647e
|
@ -108,6 +108,7 @@ std::unique_ptr<IDbConnection> CreateMysqlConnection(
|
|||
const char *pUser,
|
||||
const char *pPass,
|
||||
const char *pIp,
|
||||
const char *pBindaddr,
|
||||
int Port,
|
||||
bool Setup);
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@ public:
|
|||
const char *pUser,
|
||||
const char *pPass,
|
||||
const char *pIp,
|
||||
const char *pBindaddr,
|
||||
int Port,
|
||||
bool Setup);
|
||||
~CMysqlConnection();
|
||||
|
@ -138,6 +139,7 @@ private:
|
|||
char m_aUser[64];
|
||||
char m_aPass[64];
|
||||
char m_aIp[64];
|
||||
char m_aBindaddr[128];
|
||||
int m_Port;
|
||||
bool m_Setup;
|
||||
|
||||
|
@ -155,6 +157,7 @@ CMysqlConnection::CMysqlConnection(
|
|||
const char *pUser,
|
||||
const char *pPass,
|
||||
const char *pIp,
|
||||
const char *pBindaddr,
|
||||
int Port,
|
||||
bool Setup) :
|
||||
IDbConnection(pPrefix),
|
||||
|
@ -173,6 +176,7 @@ CMysqlConnection::CMysqlConnection(
|
|||
str_copy(m_aUser, pUser, sizeof(m_aUser));
|
||||
str_copy(m_aPass, pPass, sizeof(m_aPass));
|
||||
str_copy(m_aIp, pIp, sizeof(m_aIp));
|
||||
str_copy(m_aBindaddr, pBindaddr, sizeof(m_aBindaddr));
|
||||
}
|
||||
|
||||
CMysqlConnection::~CMysqlConnection()
|
||||
|
@ -217,7 +221,7 @@ void CMysqlConnection::Print(IConsole *pConsole, const char *pMode)
|
|||
|
||||
CMysqlConnection *CMysqlConnection::Copy()
|
||||
{
|
||||
return new CMysqlConnection(m_aDatabase, GetPrefix(), m_aUser, m_aPass, m_aIp, m_Port, m_Setup);
|
||||
return new CMysqlConnection(m_aDatabase, GetPrefix(), m_aUser, m_aPass, m_aIp, m_aBindaddr, m_Port, m_Setup);
|
||||
}
|
||||
|
||||
void CMysqlConnection::ToUnixTimestamp(const char *pTimestamp, char *aBuf, unsigned int BufferSize)
|
||||
|
@ -273,6 +277,10 @@ bool CMysqlConnection::ConnectImpl()
|
|||
mysql_options(&m_Mysql, MYSQL_OPT_WRITE_TIMEOUT, &OptWriteTimeout);
|
||||
mysql_options(&m_Mysql, MYSQL_OPT_RECONNECT, &OptReconnect);
|
||||
mysql_options(&m_Mysql, MYSQL_SET_CHARSET_NAME, "utf8mb4");
|
||||
if(m_aBindaddr[0] != '\0')
|
||||
{
|
||||
mysql_options(&m_Mysql, MYSQL_OPT_BIND, m_aBindaddr);
|
||||
}
|
||||
|
||||
if(!mysql_real_connect(&m_Mysql, m_aIp, m_aUser, m_aPass, nullptr, m_Port, nullptr, CLIENT_IGNORE_SIGPIPE))
|
||||
{
|
||||
|
@ -711,10 +719,11 @@ std::unique_ptr<IDbConnection> CreateMysqlConnection(
|
|||
const char *pUser,
|
||||
const char *pPass,
|
||||
const char *pIp,
|
||||
const char *pBindaddr,
|
||||
int Port,
|
||||
bool Setup)
|
||||
{
|
||||
return std::make_unique<CMysqlConnection>(pDatabase, pPrefix, pUser, pPass, pIp, Port, Setup);
|
||||
return std::make_unique<CMysqlConnection>(pDatabase, pPrefix, pUser, pPass, pIp, pBindaddr, Port, Setup);
|
||||
}
|
||||
#else
|
||||
int MysqlInit()
|
||||
|
@ -730,6 +739,7 @@ std::unique_ptr<IDbConnection> CreateMysqlConnection(
|
|||
const char *pUser,
|
||||
const char *pPass,
|
||||
const char *pIp,
|
||||
const char *pBindaddr,
|
||||
int Port,
|
||||
bool Setup)
|
||||
{
|
||||
|
|
|
@ -3387,8 +3387,8 @@ void CServer::ConAddSqlServer(IConsole::IResult *pResult, void *pUserData)
|
|||
|
||||
auto pMysqlConn = CreateMysqlConnection(
|
||||
pResult->GetString(1), pResult->GetString(2), pResult->GetString(3),
|
||||
pResult->GetString(4), pResult->GetString(5), pResult->GetInteger(6),
|
||||
SetUpDb);
|
||||
pResult->GetString(4), pResult->GetString(5), g_Config.m_SvSqlBindaddr,
|
||||
pResult->GetInteger(6), SetUpDb);
|
||||
|
||||
if(!pMysqlConn)
|
||||
{
|
||||
|
|
|
@ -255,6 +255,7 @@ MACRO_CONFIG_INT(SvSwap, sv_swap, 1, 0, 1, CFGFLAG_SERVER, "Enable /swap")
|
|||
MACRO_CONFIG_INT(SvUseSQL, sv_use_sql, 0, 0, 1, CFGFLAG_SERVER, "Enables MySQL backend instead of SQLite backend (sv_sqlite_file is still used as fallback write server when no MySQL server is reachable)")
|
||||
MACRO_CONFIG_INT(SvSqlQueriesDelay, sv_sql_queries_delay, 1, 0, 20, CFGFLAG_SERVER, "Delay in seconds between SQL queries of a single player")
|
||||
MACRO_CONFIG_STR(SvSqliteFile, sv_sqlite_file, 64, "ddnet-server.sqlite", CFGFLAG_SERVER, "File to store ranks in case sv_use_sql is turned off or used as backup sql server")
|
||||
MACRO_CONFIG_STR(SvSqlBindaddr, sv_sql_bindaddr, 128, "", CFGFLAG_SERVER, "Address to bind the SQL connections to")
|
||||
|
||||
#if defined(CONF_UPNP)
|
||||
MACRO_CONFIG_INT(SvUseUPnP, sv_use_upnp, 0, 0, 1, CFGFLAG_SERVER, "Enables UPnP support. (Requires -DCONF_UPNP=ON when compiling)")
|
||||
|
|
|
@ -515,7 +515,7 @@ TEST_P(RandomMap, UnfinishedDoesntExist)
|
|||
|
||||
auto g_pSqliteConn = CreateSqliteConnection(":memory:", true);
|
||||
#if defined(CONF_TEST_MYSQL)
|
||||
auto g_pMysqlConn = CreateMysqlConnection("ddnet", "record", "ddnet", "thebestpassword", "localhost", 3306, true);
|
||||
auto g_pMysqlConn = CreateMysqlConnection("ddnet", "record", "ddnet", "thebestpassword", "localhost", "", 3306, true);
|
||||
#endif
|
||||
|
||||
auto g_TestValues
|
||||
|
|
Loading…
Reference in a new issue