wesnothd: indent fixes (no functional changes)
This commit is contained in:
parent
55eef0dbef
commit
6fa92f9553
7 changed files with 415 additions and 373 deletions
|
@ -38,297 +38,339 @@ typedef std::vector<std::variant<bool, int, long, unsigned long long, std::strin
|
|||
*/
|
||||
class dbconn
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Initializes the synchronous query connection as well as the account object that has the connection settings.
|
||||
*
|
||||
* @param c The config object to read information from.
|
||||
*/
|
||||
dbconn(const config& c);
|
||||
public:
|
||||
/**
|
||||
* Initializes the synchronous query connection as well as the account object that has the connection settings.
|
||||
*
|
||||
* @param c The config object to read information from.
|
||||
*/
|
||||
dbconn(const config& c);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::async_test_query().
|
||||
*/
|
||||
int async_test_query(int limit);
|
||||
/**
|
||||
* @see forum_user_handler::async_test_query().
|
||||
*/
|
||||
int async_test_query(int limit);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::get_uuid().
|
||||
*/
|
||||
std::string get_uuid();
|
||||
/**
|
||||
* @see forum_user_handler::get_uuid().
|
||||
*/
|
||||
std::string get_uuid();
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::get_tournaments().
|
||||
*/
|
||||
std::string get_tournaments();
|
||||
/**
|
||||
* @see forum_user_handler::get_tournaments().
|
||||
*/
|
||||
std::string get_tournaments();
|
||||
|
||||
/**
|
||||
* This is an asynchronous query that is executed on a separate connection to retrieve the game history for the provided player.
|
||||
*
|
||||
* @param player_id The forum ID of the player to get the game history for.
|
||||
* @param offset The offset to provide to the database for where to start returning rows from.
|
||||
* @param search_game_name Query for games matching this name. Supports leading and/or trailing wildcards.
|
||||
* @param search_content_type The content type to query for (ie: scenario)
|
||||
* @param search_content Query for games using this content ID. Supports leading and/or trailing wildcards.
|
||||
* @return The simple_wml document containing the query results, or simply the @a error attribute if an exception is thrown.
|
||||
*/
|
||||
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 for the
|
||||
* provided player.
|
||||
*
|
||||
* @param player_id The forum ID of the player to get the game history for.
|
||||
* @param offset The offset to provide to the database for where to start returning rows from.
|
||||
* @param search_game_name Query for games matching this name. Supports leading and/or trailing wildcards.
|
||||
* @param search_content_type The content type to query for (ie: scenario)
|
||||
* @param search_content Query for games using this content ID. Supports leading and/or trailing wildcards.
|
||||
* @return The simple_wml document containing the query results, or simply the @a error attribute if an exception is
|
||||
* thrown.
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::user_exists().
|
||||
*/
|
||||
bool user_exists(const std::string& name);
|
||||
/**
|
||||
* @see forum_user_handler::user_exists().
|
||||
*/
|
||||
bool user_exists(const std::string& name);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::get_forum_id().
|
||||
*/
|
||||
long get_forum_id(const std::string& name);
|
||||
/**
|
||||
* @see forum_user_handler::get_forum_id().
|
||||
*/
|
||||
long get_forum_id(const std::string& name);
|
||||
|
||||
/**
|
||||
* @param name The player's username.
|
||||
* @return Whether the player has a row in the extra table.
|
||||
*/
|
||||
bool extra_row_exists(const std::string& name);
|
||||
/**
|
||||
* @param name The player's username.
|
||||
* @return Whether the player has a row in the extra table.
|
||||
*/
|
||||
bool extra_row_exists(const std::string& name);
|
||||
|
||||
/**
|
||||
* @param name The player's username.
|
||||
* @param group_id The forum group ID to check if the user is part of.
|
||||
* @return Whether the user is a member of the forum group.
|
||||
*/
|
||||
bool is_user_in_group(const std::string& name, int group_id);
|
||||
/**
|
||||
* @param name The player's username.
|
||||
* @param group_id The forum group ID to check if the user is part of.
|
||||
* @return Whether the user is a member of the forum group.
|
||||
*/
|
||||
bool is_user_in_group(const std::string& name, int group_id);
|
||||
|
||||
/**
|
||||
* @param table The table that will be queried.
|
||||
* @param column The column that will be selected.
|
||||
* @param name The player's username.
|
||||
* @return The string value in the provided table and column for the provided username.
|
||||
*/
|
||||
std::string get_user_string(const std::string& table, const std::string& column, const std::string& name);
|
||||
/**
|
||||
* @param table The table that will be queried.
|
||||
* @param column The column that will be selected.
|
||||
* @param name The player's username.
|
||||
* @return The string value in the provided table and column for the provided username.
|
||||
*/
|
||||
std::string get_user_string(const std::string& table, const std::string& column, const std::string& name);
|
||||
|
||||
/**
|
||||
* @param table The table that will be queried.
|
||||
* @param column The column that will be selected.
|
||||
* @param name The player's username.
|
||||
* @return The int value in the provided table and column for the provided username.
|
||||
*/
|
||||
int get_user_int(const std::string& table, const std::string& column, const std::string& name);
|
||||
/**
|
||||
* @param table The table that will be queried.
|
||||
* @param column The column that will be selected.
|
||||
* @param name The player's username.
|
||||
* @return The int value in the provided table and column for the provided username.
|
||||
*/
|
||||
int get_user_int(const std::string& table, const std::string& column, const std::string& name);
|
||||
|
||||
/**
|
||||
* The provided value is updated if a row exists or a new row inserted otherwise.
|
||||
*
|
||||
* @param column The column that the value will be put into.
|
||||
* @param name The player's username.
|
||||
* @param value The value to be put into the column.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @param column The column that the value will be put into.
|
||||
* @param name The player's username.
|
||||
* @param value The value to be put into the column.
|
||||
*/
|
||||
void write_user_int(const std::string& column, const std::string& name, int value);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::user_is_banned().
|
||||
*/
|
||||
ban_check get_ban_info(const std::string& name, const std::string& ip);
|
||||
/**
|
||||
* @see forum_user_handler::user_is_banned().
|
||||
*/
|
||||
ban_check get_ban_info(const std::string& name, const std::string& ip);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::db_insert_game_info().
|
||||
*/
|
||||
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);
|
||||
/**
|
||||
* @see forum_user_handler::db_insert_game_info().
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::db_update_game_end().
|
||||
*/
|
||||
void update_game_end(const std::string& uuid, int game_id, const std::string& replay_location);
|
||||
/**
|
||||
* @see forum_user_handler::db_update_game_end().
|
||||
*/
|
||||
void update_game_end(const std::string& uuid, int game_id, const std::string& replay_location);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::db_insert_game_player_info().
|
||||
*/
|
||||
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, const std::string& leaders);
|
||||
/**
|
||||
* @see forum_user_handler::db_insert_game_player_info().
|
||||
*/
|
||||
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,
|
||||
const std::string& leaders);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::db_insert_game_content_info().
|
||||
*/
|
||||
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);
|
||||
/**
|
||||
* @see forum_user_handler::db_insert_game_content_info().
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::db_set_oos_flag().
|
||||
*/
|
||||
void set_oos_flag(const std::string& uuid, int game_id);
|
||||
/**
|
||||
* @see forum_user_handler::db_set_oos_flag().
|
||||
*/
|
||||
void set_oos_flag(const std::string& uuid, int game_id);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::db_topic_id_exists().
|
||||
*/
|
||||
bool topic_id_exists(int topic_id);
|
||||
/**
|
||||
* @see forum_user_handler::db_topic_id_exists().
|
||||
*/
|
||||
bool topic_id_exists(int topic_id);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::db_insert_addon_info().
|
||||
*/
|
||||
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);
|
||||
/**
|
||||
* @see forum_user_handler::db_insert_addon_info().
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::db_insert_login().
|
||||
*/
|
||||
unsigned long long insert_login(const std::string& username, const std::string& ip, const std::string& version);
|
||||
/**
|
||||
* @see forum_user_handler::db_insert_login().
|
||||
*/
|
||||
unsigned long long insert_login(const std::string& username, const std::string& ip, const std::string& version);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::db_update_logout().
|
||||
*/
|
||||
void update_logout(unsigned long long login_id);
|
||||
/**
|
||||
* @see forum_user_handler::db_update_logout().
|
||||
*/
|
||||
void update_logout(unsigned long long login_id);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::get_users_for_ip().
|
||||
*/
|
||||
void get_users_for_ip(const std::string& ip, std::ostringstream* out);
|
||||
/**
|
||||
* @see forum_user_handler::get_users_for_ip().
|
||||
*/
|
||||
void get_users_for_ip(const std::string& ip, std::ostringstream* out);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::get_ips_for_users().
|
||||
*/
|
||||
void get_ips_for_user(const std::string& username, std::ostringstream* out);
|
||||
/**
|
||||
* @see forum_user_handler::get_ips_for_users().
|
||||
*/
|
||||
void get_ips_for_user(const std::string& username, std::ostringstream* out);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::db_update_addon_download_count().
|
||||
*/
|
||||
void update_addon_download_count(const std::string& instance_version, const std::string& id, const std::string& version);
|
||||
/**
|
||||
* @see forum_user_handler::db_update_addon_download_count().
|
||||
*/
|
||||
void update_addon_download_count(
|
||||
const std::string& instance_version, const std::string& id, const std::string& version);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::is_user_primary_author().
|
||||
* @see forum_user_handler::is_user_secondary_author().
|
||||
*/
|
||||
bool is_user_author(const std::string& instance_version, const std::string& id, const std::string& username, int is_primary);
|
||||
/**
|
||||
* @see forum_user_handler::is_user_primary_author().
|
||||
* @see forum_user_handler::is_user_secondary_author().
|
||||
*/
|
||||
bool is_user_author(
|
||||
const std::string& instance_version, const std::string& id, const std::string& username, int is_primary);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::db_delete_addon_authors().
|
||||
*/
|
||||
void delete_addon_authors(const std::string& instance_version, const std::string& id);
|
||||
/**
|
||||
* @see forum_user_handler::db_delete_addon_authors().
|
||||
*/
|
||||
void delete_addon_authors(const std::string& instance_version, const std::string& id);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::db_insert_addon_authors().
|
||||
*/
|
||||
void insert_addon_author(const std::string& instance_version, const std::string& id, const std::string author, int is_primary);
|
||||
/**
|
||||
* @see forum_user_handler::db_insert_addon_authors().
|
||||
*/
|
||||
void insert_addon_author(
|
||||
const std::string& instance_version, const std::string& id, const std::string author, int is_primary);
|
||||
|
||||
/**
|
||||
* @see forum_user_handler::do_any_authors_exist().
|
||||
*/
|
||||
bool do_any_authors_exist(const std::string& instance_version, const std::string& id);
|
||||
/**
|
||||
* @see forum_user_handler::do_any_authors_exist().
|
||||
*/
|
||||
bool do_any_authors_exist(const std::string& instance_version, const std::string& id);
|
||||
|
||||
private:
|
||||
/**
|
||||
* The account used to connect to the database.
|
||||
* Also contains the connection settings.
|
||||
* @note settings put on the connection, rather than the account, are NOT kept if a reconnect occurs!
|
||||
*/
|
||||
mariadb::account_ref account_;
|
||||
/** The actual connection to the database. */
|
||||
mariadb::connection_ref connection_;
|
||||
private:
|
||||
/**
|
||||
* The account used to connect to the database.
|
||||
* Also contains the connection settings.
|
||||
* @note settings put on the connection, rather than the account, are NOT kept if a reconnect occurs!
|
||||
*/
|
||||
mariadb::account_ref account_;
|
||||
/** The actual connection to the database. */
|
||||
mariadb::connection_ref connection_;
|
||||
|
||||
/** The name of the table that contains forum user information. */
|
||||
std::string db_users_table_;
|
||||
/** The name of the table that contains forum ban information. */
|
||||
std::string db_banlist_table_;
|
||||
/** The name of the table that contains additional user information. */
|
||||
std::string db_extra_table_;
|
||||
/** The name of the table that contains game-level information. */
|
||||
std::string db_game_info_table_;
|
||||
/** The name of the table that contains player-level information per game. */
|
||||
std::string db_game_player_info_table_;
|
||||
/** The name of the table that contains game content information. */
|
||||
std::string db_game_content_info_table_;
|
||||
/** The name of the table that contains forum group information. */
|
||||
std::string db_user_group_table_;
|
||||
/** The text of the SQL query to use to retrieve any currently active tournaments. */
|
||||
std::string db_tournament_query_;
|
||||
/** The name of the table that contains phpbb forum thread information */
|
||||
std::string db_topics_table_;
|
||||
/** The name of the table that contains add-on information. */
|
||||
std::string db_addon_info_table_;
|
||||
/** The name of the table that contains user connection history. */
|
||||
std::string db_connection_history_table_;
|
||||
/** The name of the table that contains the add-on authors information */
|
||||
std::string db_addon_authors_table_;
|
||||
/** The name of the table that contains forum user information. */
|
||||
std::string db_users_table_;
|
||||
/** The name of the table that contains forum ban information. */
|
||||
std::string db_banlist_table_;
|
||||
/** The name of the table that contains additional user information. */
|
||||
std::string db_extra_table_;
|
||||
/** The name of the table that contains game-level information. */
|
||||
std::string db_game_info_table_;
|
||||
/** The name of the table that contains player-level information per game. */
|
||||
std::string db_game_player_info_table_;
|
||||
/** The name of the table that contains game content information. */
|
||||
std::string db_game_content_info_table_;
|
||||
/** The name of the table that contains forum group information. */
|
||||
std::string db_user_group_table_;
|
||||
/** The text of the SQL query to use to retrieve any currently active tournaments. */
|
||||
std::string db_tournament_query_;
|
||||
/** The name of the table that contains phpbb forum thread information */
|
||||
std::string db_topics_table_;
|
||||
/** The name of the table that contains add-on information. */
|
||||
std::string db_addon_info_table_;
|
||||
/** The name of the table that contains user connection history. */
|
||||
std::string db_connection_history_table_;
|
||||
/** The name of the table that contains the add-on authors information */
|
||||
std::string db_addon_authors_table_;
|
||||
|
||||
/**
|
||||
* This is used to write out error text when an SQL-related exception occurs.
|
||||
*
|
||||
* @param text Some custom text to log.
|
||||
* @param e The exception that occurred which has information about what went wrong.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @param text Some custom text to log.
|
||||
* @param e The exception that occurred which has information about what went wrong.
|
||||
*/
|
||||
void log_sql_exception(const std::string& text, const mariadb::exception::base& e);
|
||||
|
||||
/**
|
||||
* Creates a new connection object from the account.
|
||||
*/
|
||||
mariadb::connection_ref create_connection();
|
||||
/**
|
||||
* Creates a new connection object from the account.
|
||||
*/
|
||||
mariadb::connection_ref create_connection();
|
||||
|
||||
/**
|
||||
* Queries can return data with various types that can't be easily fit into a pre-determined structure.
|
||||
* Therefore for queries that can return multiple rows with multiple columns, a class that extends @ref rs_base handles reading the results.
|
||||
*
|
||||
* @param connection The database connecion that will be used to execute the query.
|
||||
* @param base The class that will handle reading the results.
|
||||
* @param sql The SQL text to be executed.
|
||||
* @param params The parameterized values to be inserted into the query.
|
||||
*/
|
||||
void get_complex_results(mariadb::connection_ref connection, rs_base& base, const std::string& sql, const sql_parameters& params);
|
||||
/**
|
||||
* Queries can return data with various types that can't be easily fit into a pre-determined structure.
|
||||
* Therefore for queries that can return multiple rows with multiple columns, a class that extends @ref rs_base
|
||||
* handles reading the results.
|
||||
*
|
||||
* @param connection The database connection that will be used to execute the query.
|
||||
* @param base The class that will handle reading the results.
|
||||
* @param sql The SQL text to be executed.
|
||||
* @param params The parameterized values to be inserted into the query.
|
||||
*/
|
||||
void get_complex_results(
|
||||
mariadb::connection_ref connection, rs_base& base, const std::string& sql, const sql_parameters& params);
|
||||
|
||||
/**
|
||||
* @param connection The database connecion that will be used to execute the query.
|
||||
* @param sql The SQL text to be executed.
|
||||
* @param params The parameterized values to be inserted into the query.
|
||||
* @return The single string value queried.
|
||||
* @throws mariadb::exception::base when the query finds no value to be retrieved.
|
||||
*/
|
||||
std::string get_single_string(mariadb::connection_ref connection, const std::string& sql, const sql_parameters& params);
|
||||
/**
|
||||
* @param connection The database connection that will be used to execute the query.
|
||||
* @param sql The SQL text to be executed.
|
||||
* @param params The parameterized values to be inserted into the query.
|
||||
* @return The single string value queried.
|
||||
* @throws mariadb::exception::base when the query finds no value to be retrieved.
|
||||
*/
|
||||
std::string get_single_string(
|
||||
mariadb::connection_ref connection, const std::string& sql, const sql_parameters& params);
|
||||
|
||||
/**
|
||||
* @param connection The database connecion that will be used to execute the query.
|
||||
* @param sql The SQL text to be executed.
|
||||
* @param params The parameterized values to be inserted into the query.
|
||||
* @return The single long value queried.
|
||||
* @throws mariadb::exception::base when the query finds no value to be retrieved.
|
||||
*/
|
||||
long get_single_long(mariadb::connection_ref connection, const std::string& sql, const sql_parameters& params);
|
||||
/**
|
||||
* @param connection The database connection that will be used to execute the query.
|
||||
* @param sql The SQL text to be executed.
|
||||
* @param params The parameterized values to be inserted into the query.
|
||||
* @return The single long value queried.
|
||||
* @throws mariadb::exception::base when the query finds no value to be retrieved.
|
||||
*/
|
||||
long get_single_long(mariadb::connection_ref connection, const std::string& sql, const sql_parameters& params);
|
||||
|
||||
/**
|
||||
* @param connection The database connecion that will be used to execute the query.
|
||||
* @param sql The SQL text to be executed.
|
||||
* @param params The parameterized values to be inserted into the query.
|
||||
* @return True if any data was returned by the query, otherwise false.
|
||||
*/
|
||||
bool exists(mariadb::connection_ref connection, const std::string& sql, const sql_parameters& params);
|
||||
/**
|
||||
* @param connection The database connection that will be used to execute the query.
|
||||
* @param sql The SQL text to be executed.
|
||||
* @param params The parameterized values to be inserted into the query.
|
||||
* @return True if any data was returned by the query, otherwise false.
|
||||
*/
|
||||
bool exists(mariadb::connection_ref connection, const std::string& sql, const sql_parameters& params);
|
||||
|
||||
/**
|
||||
* Executes a select statement.
|
||||
*
|
||||
* @param connection The database connecion that will be used to execute the query.
|
||||
* @param sql The SQL text to be executed.
|
||||
* @param params The parameterized values to be inserted into the query.
|
||||
* @return A result set containing the results of the select statement executed.
|
||||
*/
|
||||
mariadb::result_set_ref select(mariadb::connection_ref connection, const std::string& sql, const sql_parameters& params);
|
||||
/**
|
||||
* Executes a select statement.
|
||||
*
|
||||
* @param connection The database connection that will be used to execute the query.
|
||||
* @param sql The SQL text to be executed.
|
||||
* @param params The parameterized values to be inserted into the query.
|
||||
* @return A result set containing the results of the select statement executed.
|
||||
*/
|
||||
mariadb::result_set_ref select(
|
||||
mariadb::connection_ref connection, const std::string& sql, const sql_parameters& params);
|
||||
|
||||
/**
|
||||
* Executes non-select statements (ie: insert, update, delete).
|
||||
*
|
||||
* @param connection The database connecion that will be used to execute the query.
|
||||
* @param sql The SQL text to be executed.
|
||||
* @param params The parameterized values to be inserted into the query.
|
||||
* @return The number of rows modified.
|
||||
*/
|
||||
unsigned long long modify(mariadb::connection_ref connection, const std::string& sql, const sql_parameters& params);
|
||||
/**
|
||||
* Executes non-select statements (ie: insert, update, delete).
|
||||
*
|
||||
* @param connection The database connection that will be used to execute the query.
|
||||
* @param sql The SQL text to be executed.
|
||||
* @param params The parameterized values to be inserted into the query.
|
||||
* @return The number of rows modified.
|
||||
*/
|
||||
unsigned long long modify(mariadb::connection_ref connection, const std::string& sql, const sql_parameters& params);
|
||||
|
||||
/**
|
||||
* Executes non-select statements (ie: insert, update, delete), but primarily intended for inserts that return a generated ID.
|
||||
*
|
||||
* @param connection The database connecion that will be used to execute the query.
|
||||
* @param sql The SQL text to be executed.
|
||||
* @param params The parameterized values to be inserted into the query.
|
||||
* @return The value of an AUTO_INCREMENT column on the table being modified.
|
||||
*/
|
||||
unsigned long long modify_get_id(mariadb::connection_ref connection, const std::string& sql, const sql_parameters& params);
|
||||
/**
|
||||
* Executes non-select statements (ie: insert, update, delete), but primarily intended for inserts that return a
|
||||
* generated ID.
|
||||
*
|
||||
* @param connection The database connection that will be used to execute the query.
|
||||
* @param sql The SQL text to be executed.
|
||||
* @param params The parameterized values to be inserted into the query.
|
||||
* @return The value of an AUTO_INCREMENT column on the table being modified.
|
||||
*/
|
||||
unsigned long long modify_get_id(
|
||||
mariadb::connection_ref connection, const std::string& sql, const sql_parameters& params);
|
||||
|
||||
/**
|
||||
* For a given connection, set the provided SQL and parameters on a statement.
|
||||
*
|
||||
* @param connection The database connecion that will be used to execute the query.
|
||||
* @param sql The SQL text to be executed.
|
||||
* @param params The parameterized values to be inserted into the query.
|
||||
* @return A statement ready to be executed.
|
||||
*/
|
||||
mariadb::statement_ref query(mariadb::connection_ref connection, const std::string& sql, const sql_parameters& params);
|
||||
/**
|
||||
* For a given connection, set the provided SQL and parameters on a statement.
|
||||
*
|
||||
* @param connection The database connection that will be used to execute the query.
|
||||
* @param sql The SQL text to be executed.
|
||||
* @param params The parameterized values to be inserted into the query.
|
||||
* @return A statement ready to be executed.
|
||||
*/
|
||||
mariadb::statement_ref query(
|
||||
mariadb::connection_ref connection, const std::string& sql, const sql_parameters& params);
|
||||
};
|
||||
|
|
|
@ -19,49 +19,49 @@
|
|||
#include "serialization/chrono.hpp"
|
||||
|
||||
ban_check::ban_check()
|
||||
: ban_type(user_handler::BAN_TYPE::BAN_NONE)
|
||||
, ban_duration(0)
|
||||
, user_id(0)
|
||||
, email()
|
||||
: ban_type(user_handler::BAN_TYPE::BAN_NONE)
|
||||
, ban_duration(0)
|
||||
, user_id(0)
|
||||
, email()
|
||||
{
|
||||
}
|
||||
|
||||
ban_check::ban_check(const mariadb::result_set& rslt)
|
||||
: ban_type(rslt.get_signed32("ban_type"))
|
||||
, ban_duration(0)
|
||||
, user_id(rslt.get_signed32("ban_userid"))
|
||||
, email(rslt.get_string("ban_email"))
|
||||
: ban_type(rslt.get_signed32("ban_type"))
|
||||
, ban_duration(0)
|
||||
, user_id(rslt.get_signed32("ban_userid"))
|
||||
, email(rslt.get_string("ban_email"))
|
||||
{
|
||||
auto ban_end = rslt.get_signed32("ban_end");
|
||||
if(ban_end == 0) return;
|
||||
auto ban_end = rslt.get_signed32("ban_end");
|
||||
if(ban_end == 0) return;
|
||||
|
||||
auto time_remaining = chrono::parse_timestamp(ban_end) - std::chrono::system_clock::now();
|
||||
ban_duration = std::chrono::duration_cast<std::chrono::seconds>(time_remaining);
|
||||
auto time_remaining = chrono::parse_timestamp(ban_end) - std::chrono::system_clock::now();
|
||||
ban_duration = std::chrono::duration_cast<std::chrono::seconds>(time_remaining);
|
||||
}
|
||||
|
||||
void ban_check::read(mariadb::result_set_ref rslt)
|
||||
{
|
||||
if(rslt->next()) { *this = ban_check{*rslt}; }
|
||||
if(rslt->next()) { *this = ban_check{*rslt}; }
|
||||
}
|
||||
|
||||
long ban_check::get_ban_type()
|
||||
{
|
||||
return ban_type;
|
||||
return ban_type;
|
||||
}
|
||||
|
||||
std::chrono::seconds ban_check::get_ban_duration()
|
||||
{
|
||||
return ban_duration;
|
||||
return ban_duration;
|
||||
}
|
||||
|
||||
int ban_check::get_user_id()
|
||||
{
|
||||
return user_id;
|
||||
return user_id;
|
||||
}
|
||||
|
||||
std::string ban_check::get_email()
|
||||
{
|
||||
return email;
|
||||
return email;
|
||||
}
|
||||
|
||||
#endif //HAVE_MYSQLPP
|
||||
|
|
|
@ -22,18 +22,18 @@
|
|||
|
||||
class ban_check : public rs_base
|
||||
{
|
||||
public:
|
||||
ban_check();
|
||||
explicit ban_check(const mariadb::result_set& rslt);
|
||||
void read(mariadb::result_set_ref rslt) override;
|
||||
long get_ban_type();
|
||||
std::chrono::seconds get_ban_duration();
|
||||
int get_user_id();
|
||||
std::string get_email();
|
||||
public:
|
||||
ban_check();
|
||||
explicit ban_check(const mariadb::result_set& rslt);
|
||||
void read(mariadb::result_set_ref rslt) override;
|
||||
long get_ban_type();
|
||||
std::chrono::seconds get_ban_duration();
|
||||
int get_user_id();
|
||||
std::string get_email();
|
||||
|
||||
private:
|
||||
long ban_type;
|
||||
std::chrono::seconds ban_duration;
|
||||
int user_id;
|
||||
std::string email;
|
||||
private:
|
||||
long ban_type;
|
||||
std::chrono::seconds ban_duration;
|
||||
int user_id;
|
||||
std::string email;
|
||||
};
|
||||
|
|
|
@ -23,60 +23,60 @@ static lg::log_domain log_sql_handler("sql_executor");
|
|||
|
||||
void game_history::read(mariadb::result_set_ref rslt)
|
||||
{
|
||||
while(rslt->next())
|
||||
{
|
||||
result r;
|
||||
r.game_name = rslt->get_string("GAME_NAME");
|
||||
r.game_start = rslt->get_date_time("START_TIME").str();
|
||||
r.scenario_name = rslt->get_string("SCENARIO_NAME");
|
||||
r.era_name = rslt->get_string("ERA_NAME");
|
||||
for(const auto& player_info : utils::split(rslt->get_string("PLAYERS")))
|
||||
{
|
||||
std::vector<std::string> info = utils::split(player_info, ':');
|
||||
if(info.size() == 2)
|
||||
{
|
||||
r.players.emplace_back(player{ info[0], info[1] });
|
||||
}
|
||||
else
|
||||
{
|
||||
ERR_SQL << "Expected player information to split into two fields, instead found the value `" << player_info << "`.";
|
||||
}
|
||||
}
|
||||
r.modification_names = utils::split(rslt->get_string("MODIFICATION_NAMES"));
|
||||
r.replay_url = rslt->get_string("REPLAY_URL");
|
||||
r.version = rslt->get_string("VERSION");
|
||||
results.push_back(std::move(r));
|
||||
}
|
||||
while(rslt->next())
|
||||
{
|
||||
result r;
|
||||
r.game_name = rslt->get_string("GAME_NAME");
|
||||
r.game_start = rslt->get_date_time("START_TIME").str();
|
||||
r.scenario_name = rslt->get_string("SCENARIO_NAME");
|
||||
r.era_name = rslt->get_string("ERA_NAME");
|
||||
for(const auto& player_info : utils::split(rslt->get_string("PLAYERS")))
|
||||
{
|
||||
std::vector<std::string> info = utils::split(player_info, ':');
|
||||
if(info.size() == 2)
|
||||
{
|
||||
r.players.emplace_back(player{ info[0], info[1] });
|
||||
}
|
||||
else
|
||||
{
|
||||
ERR_SQL << "Expected player information to split into two fields, instead found the value `" << player_info << "`.";
|
||||
}
|
||||
}
|
||||
r.modification_names = utils::split(rslt->get_string("MODIFICATION_NAMES"));
|
||||
r.replay_url = rslt->get_string("REPLAY_URL");
|
||||
r.version = rslt->get_string("VERSION");
|
||||
results.push_back(std::move(r));
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<simple_wml::document> game_history::to_doc()
|
||||
{
|
||||
auto doc = std::make_unique<simple_wml::document>();
|
||||
auto doc = std::make_unique<simple_wml::document>();
|
||||
|
||||
simple_wml::node& results_wml = doc->root().add_child("game_history_results");
|
||||
simple_wml::node& results_wml = doc->root().add_child("game_history_results");
|
||||
|
||||
for(const auto& result : results)
|
||||
{
|
||||
simple_wml::node& ghr = results_wml.add_child("game_history_result");
|
||||
ghr.set_attr_dup("game_name", result.game_name.c_str());
|
||||
ghr.set_attr_dup("game_start", result.game_start.c_str());
|
||||
ghr.set_attr_dup("scenario_name", result.scenario_name.c_str());
|
||||
ghr.set_attr_dup("era_name", result.era_name.c_str());
|
||||
ghr.set_attr_dup("replay_url", result.replay_url.c_str());
|
||||
ghr.set_attr_dup("version", result.version.c_str());
|
||||
for(const auto& player : result.players)
|
||||
{
|
||||
simple_wml::node& p = ghr.add_child("player");
|
||||
p.set_attr_dup("name", player.name.c_str());
|
||||
p.set_attr_dup("faction", player.faction.c_str());
|
||||
}
|
||||
for(const auto& mod : result.modification_names)
|
||||
{
|
||||
simple_wml::node& m = ghr.add_child("modification");
|
||||
m.set_attr_dup("name", mod.c_str());
|
||||
}
|
||||
}
|
||||
return doc;
|
||||
for(const auto& result : results)
|
||||
{
|
||||
simple_wml::node& ghr = results_wml.add_child("game_history_result");
|
||||
ghr.set_attr_dup("game_name", result.game_name.c_str());
|
||||
ghr.set_attr_dup("game_start", result.game_start.c_str());
|
||||
ghr.set_attr_dup("scenario_name", result.scenario_name.c_str());
|
||||
ghr.set_attr_dup("era_name", result.era_name.c_str());
|
||||
ghr.set_attr_dup("replay_url", result.replay_url.c_str());
|
||||
ghr.set_attr_dup("version", result.version.c_str());
|
||||
for(const auto& player : result.players)
|
||||
{
|
||||
simple_wml::node& p = ghr.add_child("player");
|
||||
p.set_attr_dup("name", player.name.c_str());
|
||||
p.set_attr_dup("faction", player.faction.c_str());
|
||||
}
|
||||
for(const auto& mod : result.modification_names)
|
||||
{
|
||||
simple_wml::node& m = ghr.add_child("modification");
|
||||
m.set_attr_dup("name", mod.c_str());
|
||||
}
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
#endif //HAVE_MYSQLPP
|
||||
|
|
|
@ -23,28 +23,28 @@
|
|||
|
||||
class game_history : public rs_base
|
||||
{
|
||||
struct player
|
||||
{
|
||||
std::string name;
|
||||
std::string faction;
|
||||
};
|
||||
struct player
|
||||
{
|
||||
std::string name;
|
||||
std::string faction;
|
||||
};
|
||||
|
||||
struct result
|
||||
{
|
||||
std::string game_name;
|
||||
std::string game_start;
|
||||
std::string scenario_name;
|
||||
std::string era_name;
|
||||
std::vector<player> players;
|
||||
std::vector<std::string> modification_names;
|
||||
std::string replay_url;
|
||||
std::string version;
|
||||
};
|
||||
struct result
|
||||
{
|
||||
std::string game_name;
|
||||
std::string game_start;
|
||||
std::string scenario_name;
|
||||
std::string era_name;
|
||||
std::vector<player> players;
|
||||
std::vector<std::string> modification_names;
|
||||
std::string replay_url;
|
||||
std::string version;
|
||||
};
|
||||
|
||||
public:
|
||||
void read(mariadb::result_set_ref rslt);
|
||||
std::unique_ptr<simple_wml::document> to_doc();
|
||||
public:
|
||||
void read(mariadb::result_set_ref rslt);
|
||||
std::unique_ptr<simple_wml::document> to_doc();
|
||||
|
||||
private:
|
||||
std::vector<result> results;
|
||||
private:
|
||||
std::vector<result> results;
|
||||
};
|
||||
|
|
|
@ -18,20 +18,20 @@
|
|||
|
||||
void tournaments::read(mariadb::result_set_ref rslt)
|
||||
{
|
||||
while(rslt->next())
|
||||
{
|
||||
rows.push_back(data{ rslt->get_string("TITLE"), rslt->get_string("STATUS"), rslt->get_string("URL") });
|
||||
}
|
||||
while(rslt->next())
|
||||
{
|
||||
rows.push_back(data{ rslt->get_string("TITLE"), rslt->get_string("STATUS"), rslt->get_string("URL") });
|
||||
}
|
||||
}
|
||||
|
||||
std::string tournaments::str()
|
||||
{
|
||||
std::string text;
|
||||
for(const auto& row : rows)
|
||||
{
|
||||
text += "\nThe tournament "+row.title+" is "+row.status+". More information can be found at "+row.url;
|
||||
}
|
||||
return text;
|
||||
std::string text;
|
||||
for(const auto& row : rows)
|
||||
{
|
||||
text += "\nThe tournament "+row.title+" is "+row.status+". More information can be found at "+row.url;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
#endif //HAVE_MYSQLPP
|
||||
|
|
|
@ -22,17 +22,17 @@
|
|||
|
||||
class tournaments : public rs_base
|
||||
{
|
||||
struct data
|
||||
{
|
||||
std::string title;
|
||||
std::string status;
|
||||
std::string url;
|
||||
};
|
||||
struct data
|
||||
{
|
||||
std::string title;
|
||||
std::string status;
|
||||
std::string url;
|
||||
};
|
||||
|
||||
public:
|
||||
void read(mariadb::result_set_ref rslt);
|
||||
std::string str();
|
||||
public:
|
||||
void read(mariadb::result_set_ref rslt);
|
||||
std::string str();
|
||||
|
||||
private:
|
||||
std::vector<data> rows;
|
||||
private:
|
||||
std::vector<data> rows;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue