The Battle for Wesnoth  1.15.1+dev
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Thomas Baumhauer <>
3  Part of the Battle for Wesnoth Project
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
12  See the COPYING file for more details.
13 */
15 #pragma once
17 #include "server/user_handler.hpp"
19 #include <vector>
20 #include <memory>
21 #include <ctime>
23 #include <mysql/mysql.h>
25 // The [user_handler] section in the server configuration
26 // file could look like this:
27 //
28 //[user_handler]
29 // db_name=phpbb3
30 // db_host=localhost
31 // db_user=root
32 // db_password=secret
33 // db_users_table=users
34 // db_banlist_table=banlist
35 // db_extra_table=extra_data
36 //[/user_handler]
38 /**
39  * A user_handler implementation to link the server with a phpbb3 forum.
40  */
41 class fuh : public user_handler {
42  public:
43  fuh(const config& c);
44  ~fuh();
46  bool login(const std::string& name, const std::string& password, const std::string& seed);
48  /**
49  * Needed because the hashing algorithm used by phpbb requires some info
50  * from the original hash to recreate the same hash
51  *
52  * Return an empty string if an error occurs
53  */
54  std::string extract_salt(const std::string& name);
56  void user_logged_in(const std::string& name);
58  bool user_exists(const std::string& name);
60  bool user_is_active(const std::string& name);
62  bool user_is_moderator(const std::string& name);
63  void set_is_moderator(const std::string& name, const bool& is_moderator);
65  ban_info user_is_banned(const std::string& name, const std::string& addr);
67  // Throws user_handler::error
68  std::string user_info(const std::string& name);
70  bool use_phpbb_encryption() const { return true; }
72  std::string get_uuid();
73  void db_insert_game_info(const std::string& uuid, int game_id, const std::string& version, const std::string& name);
74  void db_update_game_start(const std::string& uuid, int game_id, const std::string& map_name, const std::string& era_name);
75  void db_update_game_end(const std::string& uuid, int game_id, const std::string& replay_location);
76  void db_insert_game_player_info(const std::string& uuid, int game_id, const std::string& username, int side_number, const std::string& is_host, const std::string& faction);
77  void db_insert_modification_info(const std::string& uuid, int game_id, const std::string& modification_name);
78  void db_set_oos_flag(const std::string& uuid, int game_id);
80  private:
81  std::string get_hash(const std::string& user);
82  std::time_t get_lastlogin(const std::string& user);
83  std::time_t get_registrationdate(const std::string& user);
84  bool is_inactive(const std::string& user);
86  void set_lastlogin(const std::string& user, const std::time_t& lastlogin);
88  template<typename T>
91  std::time_t retrieve_ban_duration_internal(const std::string& col, const std::string& detail);
92  std::time_t retrieve_ban_duration_internal(const std::string& col, unsigned int detail);
95  unsigned int mp_mod_group_;
97  MYSQL *conn;
99  template<typename T, typename... Args>
100  inline T prepared_statement(const std::string& sql, Args&&...);
101  // Query a detail for a particular user from the database
102  template<typename T>
103  T get_detail_for_user(const std::string& name, const std::string& detail);
104  template<typename T>
105  T get_writable_detail_for_user(const std::string& name, const std::string& detail);
107  // Write something to the write table
108  template<typename T>
109  void write_detail(const std::string& name, const std::string& detail, T&& value);
111  // Same as user_exists() but checks if we have a row for this user in the extra table
112  bool extra_row_exists(const std::string& name);
114  bool is_user_in_group(const std::string& name, unsigned int group_id);
115 };
std::string get_hash(const std::string &user)
std::string db_host_
bool is_inactive(const std::string &user)
std::string get_uuid()
void user_logged_in(const std::string &name)
Executed when the user with the given name logged in.
std::string db_name_
T prepared_statement(const std::string &sql, Args &&...)
std::string db_game_info_table_
std::time_t get_lastlogin(const std::string &user)
std::string db_game_player_info_table_
std::string db_group_table_
std::string db_game_modification_info_table_
std::string user_info(const std::string &name)
Returns a string containing info like the last login of this user.
ban_info retrieve_ban_info(BAN_TYPE, T detail)
bool user_exists(const std::string &name)
Returns true if a user with the given name exists.
void set_is_moderator(const std::string &name, const bool &is_moderator)
Mark this user as a moderator.
fuh(const config &c)
T get_detail_for_user(const std::string &name, const std::string &detail)
static const char * name(const std::vector< SDL_Joystick *> &joysticks, const std::size_t index)
Definition: joystick.cpp:48
void db_insert_game_player_info(const std::string &uuid, int game_id, const std::string &username, int side_number, const std::string &is_host, const std::string &faction)
A user_handler implementation to link the server with a phpbb3 forum.
bool is_user_in_group(const std::string &name, unsigned int group_id)
bool extra_row_exists(const std::string &name)
ban_info user_is_banned(const std::string &name, const std::string &addr)
Returns true if this user account or IP address is banned.
void db_insert_modification_info(const std::string &uuid, int game_id, const std::string &modification_name)
An interface class to handle nick registration To activate it put a [user_handler] section into the s...
std::string db_password_
bool login(const std::string &name, const std::string &password, const std::string &seed)
Return true if the given password matches the password for the given user.
void db_set_oos_flag(const std::string &uuid, int game_id)
std::string db_extra_table_
void db_insert_game_info(const std::string &uuid, int game_id, const std::string &version, const std::string &name)
bool user_is_active(const std::string &name)
Returns true if the specified user account is usable for logins.
Ban status description.
std::string password(const std::string &server, const std::string &login)
std::time_t get_registrationdate(const std::string &user)
std::string db_users_table_
bool user_is_moderator(const std::string &name)
Returns true if this user is a moderator on this server.
void write_detail(const std::string &name, const std::string &detail, T &&value)
std::string db_user_
bool use_phpbb_encryption() const
Does this user_handler want passwords passed encrypted using phpbb&#39;s algorithm?
std::time_t retrieve_ban_duration_internal(const std::string &col, const std::string &detail)
T get_writable_detail_for_user(const std::string &name, const std::string &detail)
void db_update_game_start(const std::string &uuid, int game_id, const std::string &map_name, const std::string &era_name)
std::string db_banlist_table_
void set_lastlogin(const std::string &user, const std::time_t &lastlogin)
Ban type values.
int side_number
Definition: game_info.hpp:39
MYSQL * conn
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
std::string extract_salt(const std::string &name)
Needed because the hashing algorithm used by phpbb requires some info from the original hash to recre...
mock_char c
unsigned int mp_mod_group_
void db_update_game_end(const std::string &uuid, int game_id, const std::string &replay_location)