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