The Battle for Wesnoth  1.15.1+dev
user_handler.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Thomas Baumhauer <thomas.baumhauer@NOSPAMgmail.com>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
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,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 class config;
18 
19 #include "exceptions.hpp"
20 
21 #include <ctime>
22 #include <string>
23 
24 /**
25  * An interface class to handle nick registration
26  * To activate it put a [user_handler] section into the
27  * server configuration file
28  */
29 class user_handler {
30 
31  // public functions are called by the server
32  //
33  // private functions are for convenience as they
34  // will probably be the same for all user_handler
35  // implementations
36 
37  public:
39  {
40  }
41 
42  virtual ~user_handler()
43  {
44  }
45 
46  /**
47  * Return true if the given password matches the password for the given user.
48  *
49  * Password could also be a hash
50  * Seed is not needed for clear text log ins
51  * Currently the login procedure in the server and client code is hardcoded
52  * for the forum_user_handler implementation
53  */
54  virtual bool login(const std::string& name, const std::string& password, const std::string& seed) =0;
55 
56  /** Executed when the user with the given name logged in. */
57  virtual void user_logged_in(const std::string& name) =0;
58 
59  /**
60  * Returns a string containing info like the last login of this user.
61  *
62  * Formatted for user readable output.
63  */
64  virtual std::string user_info(const std::string& name) =0;
65 
66  /** Returns true if a user with the given name exists. */
67  virtual bool user_exists(const std::string& name) =0;
68 
69  /** Returns true if the specified user account is usable for logins. */
70  virtual bool user_is_active(const std::string& name) =0;
71 
72  /** Returns true if this user is a moderator on this server */
73  virtual bool user_is_moderator(const std::string& name) =0;
74 
75  /** Mark this user as a moderator */
76  virtual void set_is_moderator(const std::string& name, const bool& is_moderator) =0;
77 
78  /** Ban type values */
79  enum BAN_TYPE
80  {
81  BAN_NONE, /**< Not a ban */
82  BAN_USER, /**< User account/name ban */
83  BAN_IP, /**< IP address ban */
84  BAN_EMAIL, /**< Account email address ban */
85  };
86 
87  /** Ban status description */
88  struct ban_info
89  {
90  BAN_TYPE type; /**< Ban type */
91  std::time_t duration; /**< Ban duration (0 if permanent) */
92 
94  : type(BAN_NONE)
95  , duration(0)
96  {
97  }
98 
99  ban_info(BAN_TYPE ptype, std::time_t pduration)
100  : type(ptype)
101  , duration(pduration)
102  {
103  }
104  };
105 
106  /**
107  * Returns true if this user account or IP address is banned.
108  *
109  * @note The IP address is only used by the @a forum_user_handler
110  * subclass. Regular IP ban checks are done by @a server_base
111  * instead.
112  */
113  virtual ban_info user_is_banned(const std::string& name, const std::string& addr="") = 0;
114 
115  struct error : public game::error {
116  error(const std::string& message) : game::error(message) {}
117  };
118 
119  /** Create a random string of digits for password encryption. */
120  std::string create_unsecure_nonce(int length = 8);
121  std::string create_secure_nonce();
122 
123  /**
124  * Create custom salt.
125  *
126  * If not needed let it return and empty string or whatever you feel like.
127  */
128  virtual std::string extract_salt(const std::string& username) =0;
129 
130  /**
131  * Does this user_handler want passwords passed encrypted using phpbb's algorithm?
132  *
133  * Let it return true if it does and false if it does not.
134  */
135  virtual bool use_phpbb_encryption() const =0;
136 
137  virtual std::string get_uuid() =0;
138  virtual void db_insert_game_info(const std::string& uuid, int game_id, const std::string& version, const std::string& name) =0;
139  virtual void db_update_game_start(const std::string& uuid, int game_id, const std::string& map_name, const std::string& era_name, int reload) =0;
140  virtual void db_update_game_end(const std::string& uuid, int game_id, const std::string& replay_location) =0;
141  virtual 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) =0;
142  virtual void db_insert_modification_info(const std::string& uuid, int game_id, const std::string& modification_name) =0;
143  virtual void db_set_oos_flag(const std::string& uuid, int game_id) =0;
144 };
std::string create_unsecure_nonce(int length=8)
Create a random string of digits for password encryption.
virtual 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)=0
std::time_t duration
Ban duration (0 if permanent)
virtual void db_set_oos_flag(const std::string &uuid, int game_id)=0
virtual std::string extract_salt(const std::string &username)=0
Create custom salt.
virtual bool use_phpbb_encryption() const =0
Does this user_handler want passwords passed encrypted using phpbb&#39;s algorithm?
virtual void db_update_game_end(const std::string &uuid, int game_id, const std::string &replay_location)=0
virtual bool user_is_moderator(const std::string &name)=0
Returns true if this user is a moderator on this server.
User account/name ban.
static const char * name(const std::vector< SDL_Joystick *> &joysticks, const std::size_t index)
Definition: joystick.cpp:48
virtual void set_is_moderator(const std::string &name, const bool &is_moderator)=0
Mark this user as a moderator.
ban_info(BAN_TYPE ptype, std::time_t pduration)
virtual ~user_handler()
An interface class to handle nick registration To activate it put a [user_handler] section into the s...
virtual ban_info user_is_banned(const std::string &name, const std::string &addr="")=0
Returns true if this user account or IP address is banned.
virtual std::string user_info(const std::string &name)=0
Returns a string containing info like the last login of this user.
virtual bool user_exists(const std::string &name)=0
Returns true if a user with the given name exists.
IP address ban.
Ban status description.
std::string password(const std::string &server, const std::string &login)
virtual bool user_is_active(const std::string &name)=0
Returns true if the specified user account is usable for logins.
BAN_TYPE type
Ban type.
virtual void db_update_game_start(const std::string &uuid, int game_id, const std::string &map_name, const std::string &era_name, int reload)=0
virtual void db_insert_game_info(const std::string &uuid, int game_id, const std::string &version, const std::string &name)=0
Base class for all the errors encountered by the engine.
Definition: exceptions.hpp:29
error(const std::string &message)
virtual void user_logged_in(const std::string &name)=0
Executed when the user with the given name logged in.
BAN_TYPE
Ban type values.
int side_number
Definition: game_info.hpp:39
Account email address ban.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
virtual void db_insert_modification_info(const std::string &uuid, int game_id, const std::string &modification_name)=0
virtual bool login(const std::string &name, const std::string &password, const std::string &seed)=0
Return true if the given password matches the password for the given user.
std::string create_secure_nonce()
virtual std::string get_uuid()=0