The Battle for Wesnoth  1.15.3+dev
dbconn.hpp
Go to the documentation of this file.
1 /*
2  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10 
11  See the COPYING file for more details.
12 */
13 
14 #pragma once
15 
16 #include "config.hpp"
17 #include "resultsets/rs_base.hpp"
18 #include "resultsets/ban_check.hpp"
19 
20 #include <mysql/mysql.h>
21 #include "mariadb++/account.hpp"
22 #include "mariadb++/connection.hpp"
23 #include "mariadb++/statement.hpp"
24 #include "mariadb++/result_set.hpp"
25 #include "mariadb++/exceptions.hpp"
26 
27 #include <vector>
28 #include <unordered_map>
29 
30 class dbconn
31 {
32  public:
33  dbconn(const config& c);
36  bool user_exists(const std::string& name);
37  bool extra_row_exists(const std::string& name);
38  bool is_user_in_group(const std::string& name, int group_id);
39  std::string get_user_string(const std::string& table, const std::string& column, const std::string& name);
40  int get_user_int(const std::string& table, const std::string& column, const std::string& name);
41  void write_user_int(const std::string& column, const std::string& name, int value);
42  ban_check get_ban_info(const std::string& name, const std::string& ip);
43  void insert_game_info(const std::string& uuid, int game_id, const std::string& version, const std::string& name, const std::string& map_name, const std::string& era_name, int reload, int observers, int is_public, int has_password, const std::string& map_source, const std::string& map_version, const std::string& era_source, const std::string& era_version);
44  void update_game_end(const std::string& uuid, int game_id, const std::string& replay_location);
45  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& current_user);
46  void insert_modification_info(const std::string& uuid, int game_id, const std::string& modification_name, const std::string& modification_source, const std::string& modification_version);
47  void set_oos_flag(const std::string& uuid, int game_id);
48 
49  private:
52 
61 
62  void log_sql_exception(const std::string& text, const mariadb::exception::base& e);
63 
64  template<typename... Args>
65  void get_complex_results(rs_base& base, const std::string& sql, Args&&... args);
66 
67  template<typename... Args>
68  std::string get_single_string(const std::string& sql, Args&&... args);
69 
70  template<typename... Args>
71  int get_single_int(const std::string& sql, Args&&... args);
72 
73  template<typename... Args>
74  bool exists(const std::string& sql, Args&&... args);
75 
76  template<typename... Args>
77  mariadb::result_set_ref select(const std::string& sql, Args&&... args);
78 
79  template<typename... Args>
80  int modify(const std::string& sql, Args&&... args);
81 
82  template<typename... Args>
83  mariadb::statement_ref query(const std::string& sql, Args&&... args);
84 
85  template<typename Arg, typename... Args>
86  void prepare(mariadb::statement_ref stmt, int i, Arg arg, Args&&... args);
87 
88  template<typename Arg>
89  int prepare(mariadb::statement_ref stmt, int i, Arg arg);
90 
91  void prepare(mariadb::statement_ref stmt, int i);
92 };
std::string db_tournament_query_
Definition: dbconn.hpp:60
void prepare(mariadb::statement_ref stmt, int i, Arg arg, Args &&... args)
std::shared_ptr< result_set > result_set_ref
Definition: result_set.hpp:219
std::string get_user_string(const std::string &table, const std::string &column, const std::string &name)
std::string db_game_info_table_
Definition: dbconn.hpp:56
std::shared_ptr< account > account_ref
Definition: account.hpp:19
std::string get_tournaments()
void insert_modification_info(const std::string &uuid, int game_id, const std::string &modification_name, const std::string &modification_source, const std::string &modification_version)
std::string db_banlist_table_
Definition: dbconn.hpp:54
int get_user_int(const std::string &table, const std::string &column, const std::string &name)
int modify(const std::string &sql, Args &&... args)
std::string get_single_string(const std::string &sql, Args &&... args)
Definitions for the interface to Wesnoth Markup Language (WML).
dbconn(const config &c)
mariadb::statement_ref query(const std::string &sql, Args &&... args)
void insert_game_info(const std::string &uuid, int game_id, const std::string &version, const std::string &name, const std::string &map_name, const std::string &era_name, int reload, int observers, int is_public, int has_password, const std::string &map_source, const std::string &map_version, const std::string &era_source, const std::string &era_version)
mariadb::connection_ref connection_
Definition: dbconn.hpp:51
void write_user_int(const std::string &column, const std::string &name, int value)
mariadb::account_ref account_
Definition: dbconn.hpp:50
mariadb::result_set_ref select(const std::string &sql, Args &&... args)
bool is_user_in_group(const std::string &name, int group_id)
std::string db_game_player_info_table_
Definition: dbconn.hpp:57
std::string get_uuid()
std::size_t i
Definition: function.cpp:933
void set_oos_flag(const std::string &uuid, int game_id)
void get_complex_results(rs_base &base, const std::string &sql, Args &&... args)
bool user_exists(const std::string &name)
std::string db_game_modification_info_table_
Definition: dbconn.hpp:58
std::string db_user_group_table_
Definition: dbconn.hpp:59
void log_sql_exception(const std::string &text, const mariadb::exception::base &e)
std::string db_users_table_
Definition: dbconn.hpp:53
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 &current_user)
std::shared_ptr< connection > connection_ref
Definition: statement.hpp:33
#define e
int side_number
Definition: game_info.hpp:39
ban_check get_ban_info(const std::string &name, const std::string &ip)
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
std::shared_ptr< statement > statement_ref
Definition: statement.hpp:109
mock_char c
bool exists(const std::string &sql, Args &&... args)
int get_single_int(const std::string &sql, Args &&... args)
std::string db_extra_table_
Definition: dbconn.hpp:55
void update_game_end(const std::string &uuid, int game_id, const std::string &replay_location)
bool extra_row_exists(const std::string &name)