The Battle for Wesnoth  1.19.4+dev
Public Member Functions | Private Member Functions | Private Attributes | List of all members
fuh Class Reference

A class to handle the non-SQL logic for connecting to the phpbb forum database. More...

#include <forum_user_handler.hpp>

Inheritance diagram for fuh:

Public Member Functions

 fuh (const config &c)
 Reads wesnothd's config for the data needed to initialize this class and dbconn. More...
 
bool login (const std::string &name, const std::string &password)
 Retrieves the player's hashed password from the phpbb forum database and checks if it matches the hashed password sent by the client. More...
 
std::string extract_salt (const std::string &name)
 Needed because the hashing algorithm used by phpbb requires some info from the original hash to recreate the same hash. More...
 
void user_logged_in (const std::string &name)
 Sets the last login time to the current time. More...
 
bool user_exists (const std::string &name)
 
long get_forum_id (const std::string &name)
 
bool user_is_active (const std::string &name)
 
bool user_is_moderator (const std::string &name)
 
void set_is_moderator (const std::string &name, const bool &is_moderator)
 Sets or unsets whether the player should be considered a moderator in the extra table. More...
 
ban_info user_is_banned (const std::string &name, const std::string &addr)
 
std::string user_info (const std::string &name)
 
std::string get_uuid ()
 
std::string get_tournaments ()
 
void async_get_and_send_game_history (boost::asio::io_service &io_service, wesnothd::server &s, wesnothd::player_iterator player, int player_id, int offset, std::string &search_game_name, int search_content_type, std::string &search_content)
 Runs an asynchronous query to fetch the user's game history data. More...
 
void db_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)
 Inserts game related information. More...
 
void db_update_game_end (const std::string &uuid, int game_id, const std::string &replay_location)
 Update the game related information when the game ends. More...
 
void db_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)
 Inserts player information per side. More...
 
unsigned long long db_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)
 Inserts information about the content being played. More...
 
void db_set_oos_flag (const std::string &uuid, int game_id)
 Sets the OOS flag in the database if wesnothd is told by a client it has detected an OOS error. More...
 
void async_test_query (boost::asio::io_service &io_service, int limit)
 A simple test query for running a query asynchronously. More...
 
bool db_topic_id_exists (int topic_id)
 Checks whether a forum thread with topic_id exists. More...
 
void db_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)
 Inserts information about an uploaded add-on into the database. More...
 
unsigned long long db_insert_login (const std::string &username, const std::string &ip, const std::string &version)
 Inserts into the database for when a player logs in. More...
 
void db_update_logout (unsigned long long login_id)
 Updates the database for when a player logs out. More...
 
void get_users_for_ip (const std::string &ip, std::ostringstream *out)
 Searches for all players that logged in using the ip address. More...
 
void get_ips_for_user (const std::string &username, std::ostringstream *out)
 Searches for all ip addresses used by the player. More...
 
std::string get_user_email (const std::string &user)
 
void db_update_addon_download_count (const std::string &instance_version, const std::string &id, const std::string &version)
 Increments the download count for this add-on for the specific version. More...
 
bool db_is_user_primary_author (const std::string &instance_version, const std::string &id, const std::string &username)
 Checks whether the provided username is the primary author of the add-on. More...
 
bool db_is_user_secondary_author (const std::string &instance_version, const std::string &id, const std::string &username)
 Checks whether the provided username is a secondary author of the add-on. More...
 
void db_delete_addon_authors (const std::string &instance_version, const std::string &id)
 Removes the authors information from addon_author for a particular addon and version. More...
 
void db_insert_addon_authors (const std::string &instance_version, const std::string &id, const std::string &primary_author, const std::vector< std::string > &secondary_authors)
 Inserts rows for the primary and secondary authors for a particular addon and version. More...
 
bool db_do_any_authors_exist (const std::string &instance_version, const std::string &id)
 Checks whether any author information exists for a particular addon and version, since if there's no author information then of course no primary or secondary authors will ever be found. More...
 
- Public Member Functions inherited from user_handler
 user_handler ()
 
virtual ~user_handler ()
 

Private Member Functions

std::string get_hashed_password_from_db (const std::string &user)
 
std::time_t get_lastlogin (const std::string &user)
 
std::time_t get_registrationdate (const std::string &user)
 

Private Attributes

dbconn conn_
 An instance of the class responsible for executing the queries and handling the database connection. More...
 
std::string db_users_table_
 The name of the phpbb users table. More...
 
std::string db_extra_table_
 The name of the extras custom table, not part of a phpbb database. More...
 
int mp_mod_group_
 The group ID of the forums MP Moderators group. More...
 

Additional Inherited Members

- Public Types inherited from user_handler
enum  BAN_TYPE { BAN_NONE = 0 , BAN_IP = 1 , BAN_USER = 2 , BAN_EMAIL = 3 }
 Ban type values. More...
 

Detailed Description

A class to handle the non-SQL logic for connecting to the phpbb forum database.

Definition at line 28 of file forum_user_handler.hpp.

Constructor & Destructor Documentation

◆ fuh()

fuh::fuh ( const config c)

Reads wesnothd's config for the data needed to initialize this class and dbconn.

Member Function Documentation

◆ async_get_and_send_game_history()

void fuh::async_get_and_send_game_history ( boost::asio::io_service &  io_service,
wesnothd::server s,
wesnothd::player_iterator  player,
int  player_id,
int  offset,
std::string &  search_game_name,
int  search_content_type,
std::string &  search_content 
)
virtual

Runs an asynchronous query to fetch the user's game history data.

The result is then posted back to the main boost::asio thread to be sent to the requesting player.

Parameters
io_serviceThe boost io_service to use to post the query results back to the main boost::asio thread.
sThe server instance the player is connected to.
playerThe player iterator used to communicate with the player's client.
player_idThe forum ID of the player to get the game history for.
offsetWhere to start returning rows to the client from the query results.
search_game_nameQuery for games matching this name. Supports leading and/or trailing wildcards.
search_content_typeThe content type to query for (ie: scenario)
search_contentQuery for games using this content ID. Supports leading and/or trailing wildcards.

Implements user_handler.

◆ async_test_query()

void fuh::async_test_query ( boost::asio::io_service &  io_service,
int  limit 
)
virtual

A simple test query for running a query asynchronously.

The main point is that it takes a meaningful amount of time to complete so that it's easy to see that multiple are running at once and are finishing out of order.

Parameters
io_serviceThe boost io_service to use to post the query results back to the main boost::asio thread.
limitHow many recursions to make in the query.

Implements user_handler.

◆ db_delete_addon_authors()

void fuh::db_delete_addon_authors ( const std::string &  instance_version,
const std::string &  id 
)
virtual

Removes the authors information from addon_author for a particular addon and version.

Parameters
instance_versionWhich major version this is for (1.16, 1.17, etc).
idThe ID of the add-on.

Implements user_handler.

◆ db_do_any_authors_exist()

bool fuh::db_do_any_authors_exist ( const std::string &  instance_version,
const std::string &  id 
)
virtual

Checks whether any author information exists for a particular addon and version, since if there's no author information then of course no primary or secondary authors will ever be found.

Parameters
instance_versionWhich major version this is for (1.16, 1.17, etc).
idThe ID of the add-on.
Returns
true if any author information exists for this addon, false otherwise.

Implements user_handler.

◆ db_insert_addon_authors()

void fuh::db_insert_addon_authors ( const std::string &  instance_version,
const std::string &  id,
const std::string &  primary_author,
const std::vector< std::string > &  secondary_authors 
)
virtual

Inserts rows for the primary and secondary authors for a particular addon and version.

Parameters
instance_versionWhich major version this is for (1.16, 1.17, etc).
idThe ID of the add-on.
primary_authorThe primary author of the add-on.
secondary_authorsThe secondary authors of the add-on.

Implements user_handler.

◆ db_insert_addon_info()

void fuh::db_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 
)
virtual

Inserts information about an uploaded add-on into the database.

Parameters
instance_versionThe version of campaignd the add-on was uploaded to.
idThe add-on's ID (aka directory name).
nameThe add-on's name from the pbl.
typeThe add-on's type from the pbl.
versionThe add-on's version from the pbl.
forum_authWhether the provided author and password should be matched a forum account or not.
topic_idThe forum topic ID of the add-on's feedback thread, 0 if not present.
uploaderThe person uploading this version of the add-on.

Implements user_handler.

◆ db_insert_game_content_info()

unsigned long long fuh::db_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 
)
virtual

Inserts information about the content being played.

Parameters
uuidThe value returned by get_uuid().
game_idThe game's db_id.
typeThe add-on content's type (ie: era, scenario, etc).
nameThe name of the content.
idThe id of the content.
addon_idThe id of the addon that the content is from.
addon_versionThe version of the add-on.
Returns
The number of rows inserted which should always be 1.

Implements user_handler.

◆ db_insert_game_info()

void fuh::db_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 
)
virtual

Inserts game related information.

Parameters
uuidThe value returned by get_uuid().
game_idThe game's db_id.
versionThe version of wesnothd running this game.
nameThe game's name as entered by the user.
reloadWhether this game was loaded from the save of a previous game.
observersWhether observers are allowed.
is_publicWhether the game's replay will be publicly available.
has_passwordWhether the game has a password.

Implements user_handler.

◆ db_insert_game_player_info()

void fuh::db_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 
)
virtual

Inserts player information per side.

Parameters
uuidThe value returned by get_uuid().
game_idThe game's db_id.
usernameThe username of the player who owns this side.
side_numberThis side's side number.
is_hostWhether this player is the host.
factionThe name of this side's faction.
versionThe version of Wesnoth this player is using.
sourceThe source where this player downloaded Wesnoth (ie: Steam, SourceForge, etc).
current_userThe player currently in control of this side.
leadersThe comma-delimited list of leader unit types for that side.

Implements user_handler.

◆ db_insert_login()

unsigned long long fuh::db_insert_login ( const std::string &  username,
const std::string &  ip,
const std::string &  version 
)
virtual

Inserts into the database for when a player logs in.

Parameters
usernameThe username of who logged in. The username is converted to lower case when inserting in order to allow index usage when querying.
ipThe ip address of who logged in.
versionThe version of the client that logged in.

Implements user_handler.

◆ db_is_user_primary_author()

bool fuh::db_is_user_primary_author ( const std::string &  instance_version,
const std::string &  id,
const std::string &  username 
)
virtual

Checks whether the provided username is the primary author of the add-on.

Parameters
instance_versionWhich major version this is for (1.16, 1.17, etc).
idThe ID of the add-on.
usernameThe username attempting to do something with the add-on.
Returns
true if the user is the primary author of an addon, false otherwise.

Implements user_handler.

◆ db_is_user_secondary_author()

bool fuh::db_is_user_secondary_author ( const std::string &  instance_version,
const std::string &  id,
const std::string &  username 
)
virtual

Checks whether the provided username is a secondary author of the add-on.

Parameters
instance_versionWhich major version this is for (1.16, 1.17, etc).
idThe ID of the add-on.
usernameThe username attempting to do something with the add-on.
Returns
true if the user is a secondary author of an addon, false otherwise.

Implements user_handler.

◆ db_set_oos_flag()

void fuh::db_set_oos_flag ( const std::string &  uuid,
int  game_id 
)
virtual

Sets the OOS flag in the database if wesnothd is told by a client it has detected an OOS error.

Parameters
uuidThe value returned by get_uuid().
game_idThe game's db_id.

Implements user_handler.

◆ db_topic_id_exists()

bool fuh::db_topic_id_exists ( int  topic_id)
virtual

Checks whether a forum thread with topic_id exists.

Parameters
topic_idThe topic id to check for.
Returns
True if the thread exists or there was a database failure, false if the topic wasn't found.

Implements user_handler.

◆ db_update_addon_download_count()

void fuh::db_update_addon_download_count ( const std::string &  instance_version,
const std::string &  id,
const std::string &  version 
)
virtual

Increments the download count for this add-on for the specific version.

Parameters
instance_versionThe version of campaignd the add-on was uploaded to.
idThe add-on's ID (aka directory name).
versionThe version of the add-on being downloaded. May not be the most recent version.

Implements user_handler.

◆ db_update_game_end()

void fuh::db_update_game_end ( const std::string &  uuid,
int  game_id,
const std::string &  replay_location 
)
virtual

Update the game related information when the game ends.

Parameters
uuidThe value returned by get_uuid().
game_idThe game's db_id.
replay_locationThe location of the game's publicly available replay.

Implements user_handler.

◆ db_update_logout()

void fuh::db_update_logout ( unsigned long long  login_id)
virtual

Updates the database for when a player logs out.

Parameters
login_idThe generated ID that uniquely identifies the row to be updated.

Implements user_handler.

◆ extract_salt()

std::string fuh::extract_salt ( const std::string &  name)
virtual

Needed because the hashing algorithm used by phpbb requires some info from the original hash to recreate the same hash.

Returns
the salt, or an empty string if an error occurs.

Implements user_handler.

◆ get_forum_id()

long fuh::get_forum_id ( const std::string &  name)
virtual
Parameters
nameThe player's username.
Returns
The phpbb USER_ID value created when the player registers on the forums.
Note
wesnothd allows the same player to login with multiple clients using the same username but with different case letters (ie: abc and ABC). This means that this value is not necessarily unique among all connected clients.

Implements user_handler.

◆ get_hashed_password_from_db()

std::string fuh::get_hashed_password_from_db ( const std::string &  user)
private
Parameters
userThe player's username.
Returns
The player's hashed password from the phpbb forum database.

◆ get_ips_for_user()

void fuh::get_ips_for_user ( const std::string &  username,
std::ostringstream *  out 
)
virtual

Searches for all ip addresses used by the player.

The username is converted to lower case to allow a case insensitive select query to be executed while still using an index. The '' wildcard can be used to search for partial usernames.

Parameters
usernameThe username to search for.
outWhere to output the results.

Implements user_handler.

◆ get_lastlogin()

std::time_t fuh::get_lastlogin ( const std::string &  user)
private
Parameters
userThe player's username.
Returns
The player's last login time.

◆ get_registrationdate()

std::time_t fuh::get_registrationdate ( const std::string &  user)
private
Parameters
userThe player's username.
Returns
The player's forum registration date.

◆ get_tournaments()

std::string fuh::get_tournaments ( )
virtual
Returns
A list of active tournaments pulled from the Tournaments subforum.

Implements user_handler.

◆ get_user_email()

std::string fuh::get_user_email ( const std::string &  user)
virtual
Parameters
userThe player's username.
Returns
The player's email address from the phpbb forum database.

Implements user_handler.

◆ get_users_for_ip()

void fuh::get_users_for_ip ( const std::string &  ip,
std::ostringstream *  out 
)
virtual

Searches for all players that logged in using the ip address.

The '' wildcard can be used to search for partial ip addresses.

Parameters
ipThe ip address to search for.
outWhere to output the results.

Implements user_handler.

◆ get_uuid()

std::string fuh::get_uuid ( )
virtual
Returns
A unique UUID from the backing database.

Implements user_handler.

◆ login()

bool fuh::login ( const std::string &  name,
const std::string &  password 
)
virtual

Retrieves the player's hashed password from the phpbb forum database and checks if it matches the hashed password sent by the client.

Parameters
nameThe username used to login.
passwordThe hashed password sent by the client.
See also
server::send_password_request().
Returns
Whether the hashed password sent by the client matches the hash retrieved from the phpbb database.

Implements user_handler.

◆ set_is_moderator()

void fuh::set_is_moderator ( const std::string &  name,
const bool &  is_moderator 
)
virtual

Sets or unsets whether the player should be considered a moderator in the extra table.

Parameters
nameThe player's username.
is_moderatorThe moderator value to set.

Implements user_handler.

◆ user_exists()

bool fuh::user_exists ( const std::string &  name)
virtual
Parameters
nameThe player's username.
Returns
Whether the player's username is exists in the forum database.

Implements user_handler.

◆ user_info()

std::string fuh::user_info ( const std::string &  name)
virtual
Parameters
nameThe player's username.
Returns
A string containing basic information about the player.

Implements user_handler.

◆ user_is_active()

bool fuh::user_is_active ( const std::string &  name)
virtual
Parameters
nameThe player's username.
Returns
Whether the username has been activated.

Implements user_handler.

◆ user_is_banned()

ban_info fuh::user_is_banned ( const std::string &  name,
const std::string &  addr 
)
virtual
Parameters
nameThe player's username.
addrThe IP address being checked.
Returns
Whether the user is banned, and if so then how long. See also user_handler::ban_info().
Note
This checks for bans by username, the email associated to the username, and IP address.
Glob IP and email address bans are NOT supported yet since they require a different kind of query that isn't supported by our prepared SQL statement API right now. However, they are basically never used on forums.wesnoth.org, so this shouldn't be a problem.

Implements user_handler.

◆ user_is_moderator()

bool fuh::user_is_moderator ( const std::string &  name)
virtual
Parameters
nameThe player's username.
Returns
Whether the user is a moderator or not.
Note
This can be either from the extra table or whether the player is a member of the MP Moderators groups.

Implements user_handler.

◆ user_logged_in()

void fuh::user_logged_in ( const std::string &  name)
virtual

Sets the last login time to the current time.

Parameters
nameThe player's username.

Implements user_handler.

Member Data Documentation

◆ conn_

dbconn fuh::conn_
private

An instance of the class responsible for executing the queries and handling the database connection.

Definition at line 329 of file forum_user_handler.hpp.

◆ db_extra_table_

std::string fuh::db_extra_table_
private

The name of the extras custom table, not part of a phpbb database.

Definition at line 333 of file forum_user_handler.hpp.

◆ db_users_table_

std::string fuh::db_users_table_
private

The name of the phpbb users table.

Definition at line 331 of file forum_user_handler.hpp.

◆ mp_mod_group_

int fuh::mp_mod_group_
private

The group ID of the forums MP Moderators group.

Definition at line 335 of file forum_user_handler.hpp.


The documentation for this class was generated from the following file: