The Battle for Wesnoth  1.17.0-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 #include <boost/asio/io_service.hpp>
25 
27 
28 namespace wesnothd
29 {
30  class server;
31 }
32 
33 /**
34  * An interface class to handle nick registration
35  * To activate it put a [user_handler] section into the
36  * server configuration file
37  */
39 {
40 // public functions are called by the server
41 //
42 // private functions are for convenience as they
43 // will probably be the same for all user_handler
44 // implementations
45 
46 public:
48  {
49  }
50 
51  virtual ~user_handler()
52  {
53  }
54 
55  /**
56  * Return true if the given password matches the password for the given user.
57  *
58  * Password could also be a hash
59  * Seed is not needed for clear text log ins
60  * Currently the login procedure in the server and client code is hardcoded
61  * for the forum_user_handler implementation
62  */
63  virtual bool login(const std::string& name, const std::string& password) = 0;
64 
65  /** Executed when the user with the given name logged in. */
66  virtual void user_logged_in(const std::string& name) = 0;
67 
68  /**
69  * Returns a string containing info like the last login of this user.
70  *
71  * Formatted for user readable output.
72  */
73  virtual std::string user_info(const std::string& name) = 0;
74 
75  /** Returns true if a user with the given name exists. */
76  virtual bool user_exists(const std::string& name) = 0;
77 
78  /** Returns the forum user id for the given username */
79  virtual long get_forum_id(const std::string& name) = 0;
80 
81  /** Returns true if the specified user account is usable for logins. */
82  virtual bool user_is_active(const std::string& name) = 0;
83 
84  /** Returns true if this user is a moderator on this server */
85  virtual bool user_is_moderator(const std::string& name) = 0;
86 
87  /** Mark this user as a moderator */
88  virtual void set_is_moderator(const std::string& name, const bool& is_moderator) = 0;
89 
90  /** Ban type values */
91  enum BAN_TYPE
92  {
93  BAN_NONE = 0, /**< Not a ban */
94  BAN_IP = 1, /**< IP address ban */
95  BAN_USER = 2, /**< User account/name ban */
96  BAN_EMAIL = 3, /**< Account email address ban */
97  };
98 
99  /** Ban status description */
100  struct ban_info
101  {
102  BAN_TYPE type; /**< Ban type */
103  std::time_t duration; /**< Ban duration (0 if permanent) */
104 
106  : type(BAN_NONE)
107  , duration(0)
108  {
109  }
110 
111  ban_info(BAN_TYPE ptype, std::time_t pduration)
112  : type(ptype)
113  , duration(pduration)
114  {
115  }
116  };
117 
118  /**
119  * Returns true if this user account or IP address is banned.
120  *
121  * @note The IP address is only used by the @a forum_user_handler
122  * subclass. Regular IP ban checks are done by @a server_base
123  * instead.
124  */
125  virtual ban_info user_is_banned(const std::string& name, const std::string& addr="") = 0;
126 
127  struct error : public game::error {
128  error(const std::string& message) : game::error(message) {}
129  };
130 
131  /**
132  * Create custom salt.
133  */
134  virtual std::string extract_salt(const std::string& username) = 0;
135 
136  virtual std::string get_uuid() = 0;
137  virtual std::string get_tournaments() = 0;
138  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;
139  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;
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, const std::string& version, const std::string& source, const std::string& current_user) = 0;
142  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;
143  virtual void db_set_oos_flag(const std::string& uuid, int game_id) = 0;
144  virtual void async_test_query(boost::asio::io_service& io_service, int limit) = 0;
145  virtual bool db_topic_id_exists(int topic_id) = 0;
146  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;
147  virtual unsigned long long db_insert_login(const std::string& username, const std::string& ip, const std::string& version) = 0;
148  virtual void db_update_logout(unsigned long long login_id) = 0;
149  virtual void get_users_for_ip(const std::string& ip, std::ostringstream* out) = 0;
150  virtual void get_ips_for_user(const std::string& username, std::ostringstream* out) = 0;
151 };
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:27
error(const std::string &message)
BAN_TYPE
Ban type values.
int side_number
Definition: game_info.hpp:39
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59