The Battle for Wesnoth  1.15.1+dev
sample_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 #include "server/user_handler.hpp"
18 
19 #include <map>
20 #include <vector>
21 
22 /**
23  * An example of how to implement user_handler.
24  * If you use this on anything real, you are insane.
25  */
26 class suh : public user_handler {
27  public:
28  suh(config c);
29 
30  void add_user(const std::string& name, const std::string& mail, const std::string& password);
31  void remove_user(const std::string& name);
32 
33  void clean_up();
34 
35  bool login(const std::string& name, const std::string& password, const std::string&);
36  void user_logged_in(const std::string& name);
37 
38  bool user_exists(const std::string& name);
39  bool user_is_active(const std::string& name);
40 
41  bool user_is_moderator(const std::string& name);
42  void set_is_moderator(const std::string& name, const bool& is_moderator);
43 
44  ban_info user_is_banned(const std::string& name, const std::string&);
45 
46  std::string user_info(const std::string& name);
47 
48  struct user {
49  user() :
50  password(),
51  realname(),
52  mail(),
53  lastlogin(std::time(nullptr)),
54  registrationdate(std::time(nullptr)),
55  is_moderator(false) {}
56  std::string password;
57  std::string realname;
58  std::string mail;
59  std::time_t lastlogin;
60  std::time_t registrationdate;
62  };
63 
64  void set_user_detail(const std::string& user, const std::string& detail, const std::string& value);
65  std::string get_valid_details();
66 
67  std::string extract_salt(const std::string&) { return ""; }
68  bool use_phpbb_encryption() const { return false; }
69 
70  std::string get_uuid();
71  void db_insert_game_info(const std::string& uuid, int game_id, const std::string& version, const std::string& name);
72  void db_update_game_start(const std::string& uuid, int game_id, const std::string& map_name, const std::string& era_name);
73  void db_update_game_end(const std::string& uuid, int game_id, const std::string& replay_location);
74  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);
75  void db_insert_modification_info(const std::string& uuid, int game_id, const std::string& modification_name);
76  void db_set_oos_flag(const std::string& uuid, int game_id);
77 
78  private:
79  std::string get_mail(const std::string& user);
80  std::string get_password(const std::string& user);
81  std::string get_realname(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 
85  void check_name(const std::string& name);
86  void check_mail(const std::string& mail);
87  void check_password(const std::string& password);
88  void check_realname(const std::string& realname);
89 
90  void set_mail(const std::string& user, const std::string& mail);
91  void set_password(const std::string& user, const std::string& password);
92  void set_realname(const std::string& user, const std::string& realname);
93 
94  void set_lastlogin(const std::string& user, const std::time_t& lastlogin);
95 
97 
98  std::map <std::string,user> users_;
99  std::vector<std::string> users();
100 };
void set_mail(const std::string &user, const std::string &mail)
void check_mail(const std::string &mail)
bool user_is_moderator(const std::string &name)
Returns true if this user is a moderator on this server.
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)
void db_insert_game_info(const std::string &uuid, int game_id, const std::string &version, const std::string &name)
std::string extract_salt(const std::string &)
Create custom salt.
std::time_t lastlogin
std::time_t get_registrationdate(const std::string &user)
void clean_up()
Called by the server once a day.
bool login(const std::string &name, const std::string &password, const std::string &)
Return true if the given password matches the password for the given user.
STL namespace.
ban_info user_is_banned(const std::string &name, const std::string &)
Returns true if this user account or IP address is banned.
suh(config c)
bool use_phpbb_encryption() const
Does this user_handler want passwords passed encrypted using phpbb&#39;s algorithm?
An example of how to implement user_handler.
std::string get_valid_details()
List of details that can be set for this user_handler.
static const char * name(const std::vector< SDL_Joystick *> &joysticks, const std::size_t index)
Definition: joystick.cpp:48
void check_realname(const std::string &realname)
void check_name(const std::string &name)
std::map< std::string, user > users_
std::string password
void set_realname(const std::string &user, const std::string &realname)
An interface class to handle nick registration To activate it put a [user_handler] section into the s...
void db_update_game_start(const std::string &uuid, int game_id, const std::string &map_name, const std::string &era_name)
void user_logged_in(const std::string &name)
Executed when the user with the given name logged in.
std::time_t registrationdate
void set_password(const std::string &user, const std::string &password)
bool user_exists(const std::string &name)
Returns true if a user with the given name exists.
std::time_t get_lastlogin(const std::string &user)
void check_password(const std::string &password)
std::vector< std::string > users()
void db_set_oos_flag(const std::string &uuid, int game_id)
Ban status description.
std::string get_mail(const std::string &user)
Used in send_mail().
std::string password(const std::string &server, const std::string &login)
void set_lastlogin(const std::string &user, const std::time_t &lastlogin)
std::string get_uuid()
std::string get_password(const std::string &user)
void set_is_moderator(const std::string &name, const bool &is_moderator)
Mark this user as a moderator.
void set_user_detail(const std::string &user, const std::string &detail, const std::string &value)
Set data for a given user name.
std::string mail
bool user_is_active(const std::string &name)
Returns true if the specified user account is usable for logins.
std::string get_realname(const std::string &user)
void db_insert_modification_info(const std::string &uuid, int game_id, const std::string &modification_name)
int side_number
Definition: game_info.hpp:39
void remove_user(const std::string &name)
Removes a user.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
mock_char c
void add_user(const std::string &name, const std::string &mail, const std::string &password)
Adds a user.
int user_expiration_
std::string realname
std::string user_info(const std::string &name)
Returns a string containing info like the last login of this user.
void db_update_game_end(const std::string &uuid, int game_id, const std::string &replay_location)