25 #define ERR_SQL LOG_STREAM(err, log_sql_handler)
26 #define WRN_SQL LOG_STREAM(warn, log_sql_handler)
27 #define LOG_SQL LOG_STREAM(info, log_sql_handler)
28 #define DBG_SQL LOG_STREAM(debug, log_sql_handler)
31 : db_users_table_(
c[
"db_users_table"].str())
32 , db_banlist_table_(
c[
"db_banlist_table"].str())
33 , db_extra_table_(
c[
"db_extra_table"].str())
34 , db_game_info_table_(
c[
"db_game_info_table"].str())
35 , db_game_player_info_table_(
c[
"db_game_player_info_table"].str())
36 , db_game_content_info_table_(
c[
"db_game_content_info_table"].str())
37 , db_user_group_table_(
c[
"db_user_group_table"].str())
38 , db_tournament_query_(
c[
"db_tournament_query"].str())
39 , db_topics_table_(
c[
"db_topics_table"].str())
40 , db_addon_info_table_(
c[
"db_addon_info_table"].str())
41 , db_connection_history_table_(
c[
"db_connection_history_table"].str())
42 , db_addon_authors_table_(
c[
"db_addon_authors_table"].str())
46 account_ = mariadb::account::create(
c[
"db_host"].str(),
c[
"db_user"].str(),
c[
"db_password"].str());
47 account_->set_connect_option(mysql_option::MYSQL_SET_CHARSET_NAME, std::string(
"utf8mb4"));
48 account_->set_schema(
c[
"db_name"].str());
50 connection_ = create_connection();
52 catch(
const mariadb::exception::base&
e)
54 log_sql_exception(
"Failed to connect to the database!",
e);
60 ERR_SQL << text <<
'\n'
61 <<
"what: " <<
e.what() <<
'\n'
62 <<
"error id: " <<
e.error_id();
67 return mariadb::connection::create(
account_);
75 std::string sql =
"with recursive TEST(T) as "
79 "select T+1 from TEST where T < ? "
81 "select count(*) from TEST";
92 catch(
const mariadb::exception::base&
e)
106 auto tournaments_handler = [](
const mariadb::result_set_ref& rslt) {
109 while(rslt->next()) {
110 config& child =
c.add_child(
"tournament");
111 child[
"title"] = rslt->get_string(
"TITLE");
112 child[
"status"] = rslt->get_string(
"STATUS");
113 child[
"url"] = rslt->get_string(
"URL");
123 for(
const auto& child :
t.child_range(
"tournament"))
125 text +=
"\nThe tournament "+child[
"title"].str()+
" is "+child[
"status"].str()+
". More information can be found at "+child[
"url"].str();
129 catch(
const mariadb::exception::base&
e)
136 std::unique_ptr<simple_wml::document>
dbconn::get_game_history(
int player_id,
int offset, std::string search_game_name,
int search_content_type, std::string search_content)
138 auto game_history_handler = [](
const mariadb::result_set_ref& rslt) {
143 config& child =
c.add_child(
"game");
144 child[
"game_name"] = rslt->get_string(
"GAME_NAME");
145 child[
"game_start"] = rslt->get_date_time(
"START_TIME").str();
146 child[
"scenario_name"] = rslt->get_string(
"SCENARIO_NAME");
147 child[
"era_name"] = rslt->get_string(
"ERA_NAME");
148 for(
const auto& player_info :
utils::split(rslt->get_string(
"PLAYERS")))
154 pchild[
"name"] =
info[0];
155 pchild[
"faction"] =
info[1];
159 ERR_SQL <<
"Expected player information to split into two fields, instead found the value `" << player_info <<
"`.";
162 for(
const std::string& mod :
utils::split(rslt->get_string(
"MODIFICATION_NAMES")))
165 mchild[
"name"] = mod;
167 child[
"replay_url"] = rslt->get_string(
"REPLAY_URL");
168 child[
"version"] = rslt->get_string(
"VERSION");
177 if(player_id == 0 && search_game_name.empty() && search_content.empty())
179 ERR_SQL <<
"Skipping game history query due to lack of search parameters.";
180 auto doc = std::make_unique<simple_wml::document>();
181 doc->set_attr(
"error",
"No search parameters provided.");
187 std::string game_history_query =
"select "
190 " GROUP_CONCAT(CONCAT(player.USER_NAME, ':', player.FACTION)) as PLAYERS, "
191 " IFNULL(scenario.NAME, '') as SCENARIO_NAME, "
192 " IFNULL(era.NAME, '') as ERA_NAME, "
193 " IFNULL((select GROUP_CONCAT(distinct mods.NAME) from "+
db_game_content_info_table_+
" mods where mods.TYPE = 'modification' and mods.INSTANCE_UUID = game.INSTANCE_UUID and mods.GAME_ID = game.GAME_ID), '') as MODIFICATION_NAMES, "
195 " when game.PUBLIC = 1 and game.INSTANCE_VERSION != 'trunk' "
196 " then concat('https://replays.wesnoth.org/', substring(game.INSTANCE_VERSION, 1, 4), '/', year(game.END_TIME), '/', lpad(month(game.END_TIME), 2, '0'), '/', lpad(day(game.END_TIME), 2, '0'), '/', game.REPLAY_NAME) "
197 " when game.PUBLIC = 1 and game.INSTANCE_VERSION = 'trunk' "
198 " then concat('https://replays.wesnoth.org/', game.INSTANCE_VERSION, '/', year(game.END_TIME), '/', lpad(month(game.END_TIME), 2, '0'), '/', lpad(day(game.END_TIME), 2, '0'), '/', game.REPLAY_NAME) "
200 " end as REPLAY_URL, "
202 " when game.INSTANCE_VERSION != 'trunk' "
203 " then SUBSTRING(game.INSTANCE_VERSION, 1, 4) "
208 if(search_content_type == 2 && !search_content.empty())
211 " where mods.TYPE = 'modification' "
212 " and mods.INSTANCE_UUID = game.INSTANCE_UUID "
213 " and mods.GAME_ID = game.GAME_ID "
214 " and mods.ID like ? ";
217 params.emplace_back(search_content);
222 game_history_query +=
"where true ";
225 game_history_query +=
"and exists "
229 " where game.INSTANCE_UUID = player1.INSTANCE_UUID "
230 " and game.GAME_ID = player1.GAME_ID ";
234 game_history_query +=
" and player1.USER_ID = ? ";
235 params.emplace_back(player_id);
238 game_history_query +=
" ) "
239 " and game.INSTANCE_UUID = player.INSTANCE_UUID "
240 " and game.GAME_ID = player.GAME_ID "
241 " and player.USER_ID != -1 "
242 " and game.END_TIME is not NULL "
243 " and scenario.TYPE = 'scenario' "
244 " and scenario.INSTANCE_UUID = game.INSTANCE_UUID "
245 " and scenario.GAME_ID = game.GAME_ID "
246 " and era.TYPE = 'era' "
247 " and era.INSTANCE_UUID = game.INSTANCE_UUID "
248 " and era.GAME_ID = game.GAME_ID ";
250 if(!search_game_name.empty())
252 game_history_query +=
"and game.GAME_NAME like ? ";
255 params.emplace_back(search_game_name);
259 if(search_content_type == 0 && !search_content.empty())
261 game_history_query +=
"and scenario.ID like ? ";
264 params.emplace_back(search_content);
268 if(search_content_type == 1 && !search_content.empty())
270 game_history_query +=
"and era.ID like ? ";
273 params.emplace_back(search_content);
276 game_history_query +=
"group by game.INSTANCE_UUID, game.GAME_ID, SCENARIO_NAME, ERA_NAME "
277 "order by game.START_TIME desc "
278 "limit 11 offset ? ";
279 params.emplace_back(offset);
281 DBG_SQL <<
"before getting connection for game history query for player " << player_id;
285 DBG_SQL <<
"game history query text for player " << player_id <<
": " << game_history_query;
289 DBG_SQL <<
"after game history query for player " << player_id;
291 auto doc = std::make_unique<simple_wml::document>();
295 for(
const auto& result : history.
child_range(
"game"))
298 ghr.
set_attr_dup(
"game_name", result[
"game_name"].str().c_str());
299 ghr.
set_attr_dup(
"game_start", result[
"game_start"].str().c_str());
300 ghr.
set_attr_dup(
"scenario_name", result[
"scenario_name"].str().c_str());
301 ghr.
set_attr_dup(
"era_name", result[
"era_name"].str().c_str());
302 ghr.
set_attr_dup(
"replay_url", result[
"replay_url"].str().c_str());
303 ghr.
set_attr_dup(
"version", result[
"version"].str().c_str());
304 for(
const auto& player : result.child_range(
"player"))
307 p.set_attr_dup(
"name", player[
"name"].str().c_str());
308 p.set_attr_dup(
"faction", player[
"faction"].str().c_str());
310 for(
const auto& mod : result.child_range(
"modification"))
317 DBG_SQL <<
"after parsing results of game history query for player " << player_id;
321 catch(
const mariadb::exception::base&
e)
323 log_sql_exception(
"Could not retrieve the game history for forum ID `"+std::to_string(player_id)+
"`!",
e);
324 auto doc = std::make_unique<simple_wml::document>();
325 doc->set_attr(
"error",
"Error retrieving game history.");
336 catch(
const mariadb::exception::base&
e)
349 catch(
const mariadb::exception::base&
e)
362 catch(
const mariadb::exception::base&
e)
371 std::vector<std::string> group_params;
374 params.emplace_back(name);
375 for(
int group_id : group_ids) {
376 group_params.emplace_back(
"?");
377 params.emplace_back(group_id);
385 catch(
const mariadb::exception::base&
e)
395 auto ban_info_handler = [](
const mariadb::result_set_ref& rslt) {
399 c[
"ban_type"] = rslt->get_signed32(
"ban_type");
400 c[
"ban_end"] = rslt->get_signed32(
"ban_end");
401 c[
"user_id"] = rslt->get_signed32(
"ban_userid");
402 c[
"email"] = rslt->get_string(
"ban_email");
410 return get_complex_results(
connection_, &ban_info_handler,
"select ban_userid, ban_email, case when ban_ip != '' then 1 when ban_userid != 0 then 2 when ban_email != '' then 3 end as ban_type, ban_end from `"+
db_banlist_table_+
"` where (ban_ip = ? or ban_userid = (select user_id from `"+
db_users_table_+
"` where UPPER(username) = UPPER(?)) or UPPER(ban_email) = (select UPPER(user_email) from `"+
db_users_table_+
"` where UPPER(username) = UPPER(?))) AND ban_exclude = 0 AND (ban_end = 0 OR ban_end >= ?)",
411 { ip, name, name, std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()) });
413 catch(
const mariadb::exception::base&
e)
415 log_sql_exception(
"Failed to check ban info for user '"+name+
"' connecting from ip '"+ip+
"'!",
e);
420 std::string
dbconn::get_user_string(
const std::string& table,
const std::string& column,
const std::string& name)
426 catch(
const mariadb::exception::base&
e)
428 log_sql_exception(
"Unable to query column `"+column+
"` from table `"+table+
"` for user `"+name+
"`",
e);
432 int dbconn::get_user_int(
const std::string& table,
const std::string& column,
const std::string& name)
436 return static_cast<int>(
get_single_long(
connection_,
"SELECT `"+column+
"` from `"+table+
"` WHERE UPPER(username)=UPPER(?)", { name }));
438 catch(
const mariadb::exception::base&
e)
440 log_sql_exception(
"Unable to query column `"+column+
"` from table `"+table+
"` for user `"+name+
"`",
e);
454 catch(
const mariadb::exception::base&
e)
460 void dbconn::insert_game_info(
const std::string& uuid,
int game_id,
const std::string& version,
const std::string& name,
int reload,
int observers,
int is_public,
int has_password)
464 modify(
connection_,
"INSERT INTO `"+
db_game_info_table_+
"`(INSTANCE_UUID, GAME_ID, INSTANCE_VERSION, GAME_NAME, RELOAD, OBSERVERS, PUBLIC, PASSWORD) VALUES(?, ?, ?, ?, ?, ?, ?, ?)",
465 { uuid, game_id, version, name, reload, observers, is_public, has_password });
467 catch(
const mariadb::exception::base&
e)
469 log_sql_exception(
"Failed to insert game info row for UUID `"+uuid+
"` and game ID `"+std::to_string(game_id)+
"`",
e);
477 { replay_location, uuid, game_id });
479 catch(
const mariadb::exception::base&
e)
481 log_sql_exception(
"Failed to update the game end for game info row for UUID `"+uuid+
"` and game ID `"+std::to_string(game_id)+
"`",
e);
484 void dbconn::insert_game_player_info(
const std::string& uuid,
int game_id,
const std::string& username,
int side_number,
int is_host,
const std::string& faction,
const std::string& version,
const std::string& source,
const std::string& current_user,
const std::string& leaders)
488 modify(
connection_,
"INSERT INTO `"+
db_game_player_info_table_+
"`(INSTANCE_UUID, GAME_ID, USER_ID, SIDE_NUMBER, IS_HOST, FACTION, CLIENT_VERSION, CLIENT_SOURCE, USER_NAME, LEADERS) VALUES(?, ?, IFNULL((SELECT user_id FROM `"+
db_users_table_+
"` WHERE username = ?), -1), ?, ?, ?, ?, ?, ?, ?)",
489 { uuid, game_id, username,
side_number, is_host, faction, version, source, current_user, leaders });
491 catch(
const mariadb::exception::base&
e)
493 log_sql_exception(
"Failed to insert game player info row for UUID `"+uuid+
"` and game ID `"+std::to_string(game_id)+
"`",
e);
496 unsigned long long dbconn::insert_game_content_info(
const std::string& uuid,
int game_id,
const std::string&
type,
const std::string& name,
const std::string&
id,
const std::string& addon_id,
const std::string& addon_version)
500 return modify(
connection_,
"INSERT INTO `"+
db_game_content_info_table_+
"`(INSTANCE_UUID, GAME_ID, TYPE, NAME, ID, ADDON_ID, ADDON_VERSION) VALUES(?, ?, ?, ?, ?, ?, ?)",
501 { uuid, game_id,
type, name,
id, addon_id, addon_version });
503 catch(
const mariadb::exception::base&
e)
505 log_sql_exception(
"Failed to insert game content info row for UUID `"+uuid+
"` and game ID `"+std::to_string(game_id)+
"`",
e);
516 catch(
const mariadb::exception::base&
e)
518 log_sql_exception(
"Failed to set the OOS flag for UUID `"+uuid+
"` and game ID `"+std::to_string(game_id)+
"`",
e);
528 catch(
const mariadb::exception::base&
e)
530 log_sql_exception(
"Unable to check whether `"+std::to_string(topic_id)+
"` exists.",
e);
535 void dbconn::insert_addon_info(
const std::string& instance_version,
const std::string&
id,
const std::string& name,
const std::string&
type,
const std::string& version,
bool forum_auth,
int topic_id,
const std::string& uploader)
539 modify(
connection_,
"INSERT INTO `"+
db_addon_info_table_+
"`(INSTANCE_VERSION, ADDON_ID, ADDON_NAME, TYPE, VERSION, FORUM_AUTH, FEEDBACK_TOPIC, UPLOADER) VALUES(?, ?, ?, ?, ?, ?, ?, ?)",
540 { instance_version,
id, name,
type, version, forum_auth, topic_id, uploader });
542 catch(
const mariadb::exception::base&
e)
544 log_sql_exception(
"Unable to insert add-on info for add-on `"+
id+
"` for instance `"+instance_version+
"`.",
e);
548 unsigned long long dbconn::insert_login(
const std::string& username,
const std::string& ip,
const std::string& version)
553 { username, ip, version });
555 catch(
const mariadb::exception::base&
e)
557 log_sql_exception(
"Unable to insert login row user `"+username+
"` and ip `"+ip+
"`.",
e);
569 catch(
const mariadb::exception::base&
e)
579 mariadb::result_set_ref rslt =
select(
connection_,
"SELECT USER_NAME, IP, date_format(LOGIN_TIME, '%Y/%m/%d %h:%i:%s'), coalesce(date_format(LOGOUT_TIME, '%Y/%m/%d %h:%i:%s'), '(not set)') FROM `"+
db_connection_history_table_+
"` WHERE IP LIKE ? order by LOGIN_TIME",
582 *out <<
"\nCount of results for ip: " << rslt->row_count();
586 *out <<
"\nFound user " << rslt->get_string(0) <<
" with ip " << rslt->get_string(1)
587 <<
", logged in at " << rslt->get_string(2) <<
" and logged out at " << rslt->get_string(3);
590 catch(
const mariadb::exception::base&
e)
600 mariadb::result_set_ref rslt =
select(
connection_,
"SELECT USER_NAME, IP, date_format(LOGIN_TIME, '%Y/%m/%d %h:%i:%s'), coalesce(date_format(LOGOUT_TIME, '%Y/%m/%d %h:%i:%s'), '(not set)') FROM `"+
db_connection_history_table_+
"` WHERE USER_NAME LIKE ? order by LOGIN_TIME",
603 *out <<
"\nCount of results for user: " << rslt->row_count();
607 *out <<
"\nFound user " << rslt->get_string(0) <<
" with ip " << rslt->get_string(1)
608 <<
", logged in at " << rslt->get_string(2) <<
" and logged out at " << rslt->get_string(3);
611 catch(
const mariadb::exception::base&
e)
622 { instance_version,
id, version });
624 catch(
const mariadb::exception::base&
e)
626 log_sql_exception(
"Unable to update download count for add-on "+
id+
" with version "+version+
".",
e);
630 bool dbconn::is_user_author(
const std::string& instance_version,
const std::string&
id,
const std::string& username,
int is_primary) {
634 { instance_version,
id, username, is_primary });
636 catch(
const mariadb::exception::base&
e)
638 log_sql_exception(
"Unable to check whether `"+username+
"` is an author of "+
id+
" for version "+instance_version+
".",
e);
647 { instance_version,
id });
649 catch(
const mariadb::exception::base&
e)
651 log_sql_exception(
"Unable to delete addon authors for "+
id+
" and version "+instance_version+
".",
e);
655 void dbconn::insert_addon_author(
const std::string& instance_version,
const std::string&
id,
const std::string& author,
int is_primary) {
659 { instance_version,
id, author, is_primary });
661 catch(
const mariadb::exception::base&
e)
663 log_sql_exception(
"Unable to delete addon authors for "+
id+
" and version "+instance_version+
".",
e);
671 { instance_version,
id });
673 catch(
const mariadb::exception::base&
e)
675 log_sql_exception(
"Unable to check whether authors exist for "+
id+
" for version "+instance_version+
".",
e);
681 auto addon_downloads_handler = [](
const mariadb::result_set_ref& rslt) {
684 while(rslt->next()) {
685 config& child =
c.add_child(
"download_info");
686 child[
"name"] = rslt->get_string(
"ADDON_NAME");
687 child[
"version"] = rslt->get_string(
"VERSION");
688 child[
"uploaded"] = rslt->get_date_time(
"UPLOADED_ON").str();
689 child[
"downloads"] = rslt->get_unsigned32(
"DOWNLOAD_COUNT");
698 { instance_version,
id });
700 catch(
const mariadb::exception::base&
e)
708 auto forum_auth_usage_handler = [](
const mariadb::result_set_ref& rslt) {
712 c[
"all_count"] = rslt->get_signed64(
"ALL_COUNT");
713 c[
"forum_auth_count"] = rslt->get_signed64(
"FORUM_AUTH_COUNT");
715 throw mariadb::exception::base(
"Count query somehow returned no rows!");
724 "(select count(distinct ADDON_ID) from "+
db_addon_info_table_+
" where INSTANCE_VERSION = ? and FORUM_AUTH = 1) as FORUM_AUTH_COUNT from dual",
725 { instance_version, instance_version });
727 catch(
const mariadb::exception::base&
e)
735 auto addon_admin_handler = [](
const mariadb::result_set_ref& rslt) {
738 while(rslt->next()) {
739 config& child =
c.add_child(
"admin");
740 child[
"username"] = rslt->get_string(
"USERNAME");
749 { site_admin_group, forum_admin_group });
751 catch(
const mariadb::exception::base&
e)
753 log_sql_exception(
"Failed to get addon admins for groups '"+std::to_string(site_admin_group)+
"' and '"+std::to_string(forum_admin_group)+
"'!",
e);
761 template <
typename F>
764 mariadb::result_set_ref rslt =
select(connection, sql, params);
773 mariadb::result_set_ref rslt =
select(connection, sql, params);
776 return rslt->get_string(0);
780 throw mariadb::exception::base(
"No string value found in the database!");
785 mariadb::result_set_ref rslt =
select(connection, sql, params);
791 switch(rslt->column_type(0))
793 case mariadb::value::type::decimal:
794 return static_cast<long>(rslt->get_decimal(0).float32());
795 case mariadb::value::type::unsigned8:
796 case mariadb::value::type::signed8:
797 return rslt->get_signed8(0);
798 case mariadb::value::type::unsigned16:
799 case mariadb::value::type::signed16:
800 return rslt->get_signed16(0);
801 case mariadb::value::type::unsigned32:
802 case mariadb::value::type::signed32:
803 return rslt->get_signed32(0);
804 case mariadb::value::type::unsigned64:
805 case mariadb::value::type::signed64:
806 return rslt->get_signed64(0);
808 throw mariadb::exception::base(
"Value retrieved was not a long!");
813 throw mariadb::exception::base(
"No long value found in the database!");
818 mariadb::result_set_ref rslt =
select(connection, sql, params);
829 mariadb::statement_ref stmt =
query(connection, sql, params);
830 mariadb::result_set_ref rslt = mariadb::result_set_ref(stmt->query());
833 catch(
const mariadb::exception::base&
e)
835 ERR_SQL <<
"SQL query failed for query: `"+sql+
"`";
843 mariadb::statement_ref stmt =
query(connection, sql, params);
844 unsigned long long count = stmt->execute();
847 catch(
const mariadb::exception::base&
e)
849 ERR_SQL <<
"SQL query failed for query: `"+sql+
"`";
857 mariadb::statement_ref stmt =
query(connection, sql, params);
858 unsigned long long count = stmt->insert();
861 catch(
const mariadb::exception::base&
e)
863 ERR_SQL <<
"SQL query failed for query: `"+sql+
"`";
868 mariadb::statement_ref
dbconn::query(
const mariadb::connection_ref& connection,
const std::string& sql,
const sql_parameters& params)
870 mariadb::statement_ref stmt = connection->create_statement(sql);
873 for(
const auto& param : params)
875 if(std::holds_alternative<bool>(param))
877 stmt->set_boolean(
i, std::get<bool>(param));
879 else if(std::holds_alternative<int>(param))
881 stmt->set_signed32(
i, std::get<int>(param));
883 else if(std::holds_alternative<unsigned long long>(param))
885 stmt->set_signed64(
i, std::get<unsigned long long>(param));
887 else if(std::holds_alternative<std::string>(param))
889 stmt->set_string(
i, std::get<std::string>(param));
891 else if(std::holds_alternative<const char*>(param))
893 stmt->set_string(
i, std::get<const char*>(param));
A config object defines a single node in a WML file, with access to child nodes.
child_itors child_range(config_key_type key)
config & add_child(config_key_type key)
void delete_addon_authors(const std::string &instance_version, const std::string &id)
void insert_addon_author(const std::string &instance_version, const std::string &id, const std::string &author, int is_primary)
bool do_any_authors_exist(const std::string &instance_version, const std::string &id)
void update_addon_download_count(const std::string &instance_version, const std::string &id, const std::string &version)
config get_addon_downloads_info(const std::string &instance_version, const std::string &id)
std::string db_tournament_query_
The text of the SQL query to use to retrieve any currently active tournaments.
bool topic_id_exists(int topic_id)
bool is_user_in_groups(const std::string &name, const std::vector< int > &group_ids)
int async_test_query(int limit)
bool is_user_author(const std::string &instance_version, const std::string &id, const std::string &username, int is_primary)
mariadb::connection_ref connection_
The actual connection to the database.
bool exists(const mariadb::connection_ref &connection, const std::string &sql, const sql_parameters ¶ms)
long get_forum_id(const std::string &name)
config get_addon_admins(int site_admin_group, int forum_admin_group)
std::unique_ptr< simple_wml::document > get_game_history(int player_id, int offset, std::string search_game_name, int search_content_type, std::string search_content)
This is an asynchronous query that is executed on a separate connection to retrieve the game history ...
void get_ips_for_user(const std::string &username, std::ostringstream *out)
std::string db_addon_authors_table_
The name of the table that contains the add-on authors information.
bool user_exists(const std::string &name)
void get_users_for_ip(const std::string &ip, std::ostringstream *out)
long get_single_long(const mariadb::connection_ref &connection, const std::string &sql, const sql_parameters ¶ms)
std::string get_single_string(const mariadb::connection_ref &connection, const std::string &sql, const sql_parameters ¶ms)
std::string db_banlist_table_
The name of the table that contains forum ban information.
config get_complex_results(const mariadb::connection_ref &connection, F *handler, const std::string &sql, const sql_parameters ¶ms)
unsigned long long insert_login(const std::string &username, const std::string &ip, const std::string &version)
mariadb::connection_ref create_connection()
Creates a new connection object from the account.
std::string db_extra_table_
The name of the table that contains additional user information.
void update_logout(unsigned long long login_id)
std::string db_addon_info_table_
The name of the table that contains add-on information.
void write_user_int(const std::string &column, const std::string &name, int value)
The provided value is updated if a row exists or a new row inserted otherwise.
std::string db_game_content_info_table_
The name of the table that contains game content information.
bool extra_row_exists(const std::string &name)
void log_sql_exception(const std::string &text, const mariadb::exception::base &e)
This is used to write out error text when an SQL-related exception occurs.
std::string db_user_group_table_
The name of the table that contains forum group information.
mariadb::account_ref account_
The account used to connect to the database.
config get_ban_info(const std::string &name, const std::string &ip)
void set_oos_flag(const std::string &uuid, int game_id)
void update_game_end(const std::string &uuid, int game_id, const std::string &replay_location)
std::string db_game_info_table_
The name of the table that contains game-level information.
std::string db_game_player_info_table_
The name of the table that contains player-level information per game.
mariadb::statement_ref query(const mariadb::connection_ref &connection, const std::string &sql, const sql_parameters ¶ms)
For a given connection, set the provided SQL and parameters on a statement.
std::string db_connection_history_table_
The name of the table that contains user connection history.
int get_user_int(const std::string &table, const std::string &column, const std::string &name)
unsigned long long modify(const mariadb::connection_ref &connection, const std::string &sql, const sql_parameters ¶ms)
Executes non-select statements (ie: insert, update, delete).
void insert_addon_info(const std::string &instance_version, const std::string &id, const std::string &name, const std::string &type, const std::string &version, bool forum_auth, int topic_id, const std::string &uploader)
unsigned long long modify_get_id(const mariadb::connection_ref &connection, const std::string &sql, const sql_parameters ¶ms)
Executes non-select statements (ie: insert, update, delete), but primarily intended for inserts that ...
std::string db_topics_table_
The name of the table that contains phpbb forum thread information.
std::string get_user_string(const std::string &table, const std::string &column, const std::string &name)
std::string db_users_table_
The name of the table that contains forum user information.
dbconn(const config &c)
Initializes the synchronous query connection as well as the account object that has the connection se...
void insert_game_info(const std::string &uuid, int game_id, const std::string &version, const std::string &name, int reload, int observers, int is_public, int has_password)
config get_forum_auth_usage(const std::string &instance_version)
void insert_game_player_info(const std::string &uuid, int game_id, const std::string &username, int side_number, int is_host, const std::string &faction, const std::string &version, const std::string &source, const std::string ¤t_user, const std::string &leaders)
mariadb::result_set_ref select(const mariadb::connection_ref &connection, const std::string &sql, const sql_parameters ¶ms)
Executes a select statement.
std::string get_tournaments()
unsigned long long insert_game_content_info(const std::string &uuid, int game_id, const std::string &type, const std::string &name, const std::string &id, const std::string &addon_id, const std::string &addon_version)
node & add_child(const char *name)
node & set_attr_dup(const char *key, const char *value)
std::vector< std::variant< bool, int, long, unsigned long long, std::string, const char * > > sql_parameters
std::string id
Text to match against addon_info.tags()
std::string lowercase(std::string_view s)
Returns a lowercased version of the string.
void to_sql_wildcards(std::string &str, bool underscores)
Converts '*' to '' and optionally escapes '_'.
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::vector< std::string > split(const config_attribute_value &val)