Allow using empty ban table name to disable its functionality

This commit is contained in:
Benau 2019-05-09 13:09:50 +08:00
parent c90d32e35d
commit fce5827c7d
2 changed files with 56 additions and 48 deletions

View File

@ -186,10 +186,12 @@ void ServerLobby::initDatabase()
return;
}
const std::string ip_ban_table = ServerConfig::m_ip_ban_table;
if (!ip_ban_table.empty())
{
std::string query = StringUtils::insertValues(
"SELECT count(type) FROM sqlite_master "
"WHERE type='table' AND name='%s';",
ServerConfig::m_ip_ban_table.c_str());
"WHERE type='table' AND name='%s';", ip_ban_table.c_str());
ret = sqlite3_prepare_v2(m_db, query.c_str(), -1, &stmt, 0);
if (ret == SQLITE_OK)
@ -201,7 +203,7 @@ void ServerLobby::initDatabase()
if (number == 1)
{
Log::info("ServerLobby", "%s ip ban table will used.",
ServerConfig::m_ip_ban_table.c_str());
ip_ban_table.c_str());
m_ip_ban_table_exists = true;
}
}
@ -213,18 +215,22 @@ void ServerLobby::initDatabase()
sqlite3_errmsg(m_db));
}
}
if (!m_ip_ban_table_exists)
}
if (!m_ip_ban_table_exists && !ip_ban_table.empty())
{
Log::warn("ServerLobby", "%s ip ban table not found in database.",
ServerConfig::m_ip_ban_table.c_str());
ip_ban_table.c_str());
}
query = StringUtils::insertValues(
const std::string online_id_ban_table =
ServerConfig::m_online_id_ban_table;
if (!online_id_ban_table.empty())
{
std::string query = StringUtils::insertValues(
"SELECT count(type) FROM sqlite_master "
"WHERE type='table' AND name='%s';",
ServerConfig::m_online_id_ban_table.c_str());
"WHERE type='table' AND name='%s';", online_id_ban_table.c_str());
ret = sqlite3_prepare_v2(m_db, query.c_str(), -1, &stmt, 0);
int ret = sqlite3_prepare_v2(m_db, query.c_str(), -1, &stmt, 0);
if (ret == SQLITE_OK)
{
ret = sqlite3_step(stmt);
@ -233,8 +239,9 @@ void ServerLobby::initDatabase()
int number = sqlite3_column_int(stmt, 0);
if (number == 1)
{
Log::info("ServerLobby", "%s online id ban table will used.",
ServerConfig::m_online_id_ban_table.c_str());
Log::info("ServerLobby",
"%s online id ban table will used.",
online_id_ban_table.c_str());
m_online_id_ban_table_exists = true;
}
}
@ -246,11 +253,12 @@ void ServerLobby::initDatabase()
query.c_str(), sqlite3_errmsg(m_db));
}
}
if (!m_online_id_ban_table_exists)
}
if (!m_online_id_ban_table_exists && !online_id_ban_table.empty())
{
Log::warn("ServerLobby",
"%s online id ban table not found in database.",
ServerConfig::m_online_id_ban_table.c_str());
online_id_ban_table.c_str());
}
#endif
} // initDatabase

View File

@ -337,13 +337,13 @@ namespace ServerConfig
SERVER_CFG_DEFAULT(StringServerConfigParam("ipban",
"ip-ban-table",
"Ip ban list table name, you need to create the table first, see "
"NETWORKING.md for details."));
"NETWORKING.md for details, empty to disable."));
SERVER_CFG_PREFIX StringServerConfigParam m_online_id_ban_table
SERVER_CFG_DEFAULT(StringServerConfigParam("onlineidban",
"online-id-ban-table",
"Online ID ban list table name, you need to create the table first, "
"see NETWORKING.md for details."));
"see NETWORKING.md for details, empty to disable."));
// ========================================================================
/** Server version, will be advanced if there are protocol changes. */