The Battle for Wesnoth  1.17.0-dev
user_handler.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2021
3  by Thomas Baumhauer <thomas.baumhauer@NOSPAMgmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 class config;
19 
20 #include "exceptions.hpp"
21 
22 #include <ctime>
23 #include <string>
24 
25 #include <boost/asio/io_service.hpp>
26 
28 
29 namespace wesnothd
30 {
31  class server;
32 }
33 
34 /**
35  * An interface class to handle nick registration
36  * To activate it put a [user_handler] section into the
37  * server configuration file
38  */
40 {
41 // public functions are called by the server
42 //
43 // private functions are for convenience as they
44 // will probably be the same for all user_handler
45 // implementations
46 
47 public:
49  {
50  }
51 
52  virtual ~user_handler()
53  {
54  }
55 
56  /**
57  * Return true if the given password matches the password for the given user.
58  *
59  * Password could also be a hash
60  * Seed is not needed for clear text log ins
61  * Currently the login procedure in the server and client code is hardcoded
62  * for the forum_user_handler implementation
63  */
64  virtual bool login(const std::string& name, const std::string& password) = 0;
65 
66  /** Executed when the user with the given name logged in. */
67  virtual void user_logged_in(const std::string& name) = 0;
68 
69  /**
70  * Returns a string containing info like the last login of this user.
71  *
72  * Formatted for user readable output.
73  */
74  virtual std::string user_info(const std::string& name) = 0;
75 
76  /** Returns true if a user with the given name exists. */
77  virtual bool user_exists(const std::string& name) = 0;
78 
79  /** Returns the forum user id for the given username */
80  virtual long get_forum_id(const std::string& name) = 0;
81 
82  /** Returns true if the specified user account is usable for logins. */
83  virtual bool user_is_active(const std::string& name) = 0;
84 
85  /** Returns true if this user is a moderator on this server */
86  virtual bool user_is_moderator(const std::string& name) = 0;
87 
88  /** Mark this user as a moderator */
89  virtual void set_is_moderator(const std::string& name, const bool& is_moderator) = 0;
90 
91  /** Ban type values */
92  enum BAN_TYPE
93  {
94  BAN_NONE = 0, /**< Not a ban */
95  BAN_IP = 1, /**< IP address ban */
96  BAN_USER = 2, /**< User account/name ban */
97  BAN_EMAIL = 3, /**< Account email address ban */
98  };
99 
100  /** Ban status description */
101  struct ban_info
102  {
103  BAN_TYPE type; /**< Ban type */
104  std::time_t duration; /**< Ban duration (0 if permanent) */
105 
107  : type(BAN_NONE)
108  , duration(0)
109  {
110  }
111 
112  ban_info(BAN_TYPE ptype, std::time_t pduration)
113  : type(ptype)
114  , duration(pduration)
115  {
116  }
117  };
118 
119  /**
120  * Returns true if this user account or IP address is banned.
121  *
122  * @note The IP address is only used by the @a forum_user_handler
123  * subclass. Regular IP ban checks are done by @a server_base
124  * instead.
125  */
126  virtual ban_info user_is_banned(const std::string& name, const std::string& addr="") = 0;
127 
128  struct error : public game::error {
129  error(const std::string& message) : game::error(message) {}
130  };
131 
132  /**
133  * Create custom salt.
134  */
135  virtual std::string extract_salt(const std::string& username) = 0;
136 
137  virtual std::string get_uuid() = 0;
138  virtual std::string get_tournaments() = 0;
139  virtual 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) =0;
140  virtual 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) = 0;
141  virtual void db_update_game_end(const std::string& uuid, int game_id, const std::string& replay_location) = 0;
142  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, const std::string& version, const std::string& source, const std::string& current_user) = 0;
143  virtual void 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& source, const std::string& version) = 0;
144  virtual void db_set_oos_flag(const std::string& uuid, int game_id) = 0;
145  virtual void async_test_query(boost::asio::io_service& io_service, int limit) = 0;
146  virtual bool db_topic_id_exists(int topic_id) = 0;
147  virtual 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) = 0;
148  virtual unsigned long long db_insert_login(const std::string& username, const std::string& ip, const std::string& version) = 0;
149  virtual void db_update_logout(unsigned long long login_id) = 0;
150  virtual void get_users_for_ip(const std::string& ip, std::ostringstream* out) = 0;
151  virtual void get_ips_for_user(const std::string& username, std::ostringstream* out) = 0;
152 };
std::time_t duration
Ban duration (0 if permanent)
player_connections::const_iterator player_iterator
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...
std::string login()
static map_location::DIRECTION s
Ban status description.
std::string password(const std::string &server, const std::string &login)
BAN_TYPE type
Ban type.
Base class for all the errors encountered by the engine.
Definition: exceptions.hpp:28
error(const std::string &message)
BAN_TYPE
Ban type values.
int side_number
Definition: game_info.hpp:40
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61