]> git.stg.codes - stg.git/blob - include/stg/admin.h
Non-virtual admin.
[stg.git] / include / stg / admin.h
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18  *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
19  */
20
21 #pragma once
22
23 #include "admin_conf.h"
24
25 #include "stg/common.h"
26
27 #include <string>
28 #include <cstdint>
29
30 namespace STG
31 {
32
33 class Admin
34 {
35     public:
36           Admin() noexcept : Admin(AdminConf{}) {}
37           Admin(const Priv& priv,
38                 const std::string& login,
39                 const std::string& password) noexcept
40               : Admin(AdminConf{priv, login, password})
41           {}
42           explicit Admin(const AdminConf& ac) noexcept : m_conf(ac), m_ip(0) {}
43
44           Admin(const Admin&) = default;
45           Admin& operator=(const Admin&) = default;
46           Admin(Admin&&) = default;
47           Admin& operator=(Admin&&) = default;
48
49           Admin& operator=(const AdminConf& ac) noexcept { m_conf = ac; return *this; }
50           bool   operator==(const Admin& rhs) const noexcept { return m_conf.login == rhs.m_conf.login; }
51           bool   operator!=(const Admin& rhs) const noexcept { return !(*this == rhs); }
52           bool   operator<(const Admin& rhs) const noexcept { return m_conf.login < rhs.m_conf.login; }
53
54           const std::string& password() const { return m_conf.password; }
55           const std::string& login() const { return m_conf.login; }
56           const Priv&        priv() const { return m_conf.priv; }
57           uint32_t           privAsInt() const { return m_conf.priv.toInt(); }
58           const AdminConf&   conf() const { return m_conf; }
59           uint32_t           IP() const { return m_ip; }
60           std::string        IPStr() const { return inet_ntostring(m_ip); }
61           void               setIP(uint32_t v) { m_ip = v; }
62           const std::string  logStr() const { return "Admin \'" + m_conf.login + "\', " + IPStr() + ":"; }
63
64     private:
65           AdminConf m_conf;
66           uint32_t  m_ip;
67 };
68
69 }