The Battle for Wesnoth  1.19.5+dev
ban_check.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2020 - 2024
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 #ifdef HAVE_MYSQLPP
16 
19 #include "serialization/chrono.hpp"
20 
22  : ban_type(user_handler::BAN_TYPE::BAN_NONE)
23  , ban_duration(0)
24  , user_id(0)
25  , email()
26 {
27 }
28 
29 ban_check::ban_check(const mariadb::result_set& rslt)
30  : ban_type(rslt.get_signed32("ban_type"))
31  , ban_duration(0)
32  , user_id(rslt.get_signed32("ban_userid"))
33  , email(rslt.get_string("ban_email"))
34 {
35  auto ban_end = rslt.get_signed32("ban_end");
36  if(ban_end == 0) return;
37 
38  auto time_remaining = chrono::parse_timestamp(ban_end) - std::chrono::system_clock::now();
39  ban_duration = std::chrono::duration_cast<std::chrono::seconds>(time_remaining);
40 }
41 
42 void ban_check::read(mariadb::result_set_ref rslt)
43 {
44  if(rslt->next()) { *this = ban_check{*rslt}; }
45 }
46 
48 {
49  return ban_type;
50 }
51 
52 std::chrono::seconds ban_check::get_ban_duration()
53 {
54  return ban_duration;
55 }
56 
58 {
59  return user_id;
60 }
61 
62 std::string ban_check::get_email()
63 {
64  return email;
65 }
66 
67 #endif //HAVE_MYSQLPP
std::string get_email()
long get_ban_type()
std::chrono::seconds ban_duration
Definition: ban_check.hpp:36
std::chrono::seconds get_ban_duration()
void read(mariadb::result_set_ref rslt) override
std::string email
Definition: ban_check.hpp:38
int get_user_id()
int user_id
Definition: ban_check.hpp:37
long ban_type
Definition: ban_check.hpp:35
An interface class to handle nick registration To activate it put a [user_handler] section into the s...
auto parse_timestamp(long long val)
Definition: chrono.hpp:46