]> git.lizzy.rs Git - dragonfireclient.git/blob - src/auth.h
removed furnace menu because it is not needed anymore
[dragonfireclient.git] / src / auth.h
1 /*
2 Minetest-c55
3 Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
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
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef AUTH_HEADER
21 #define AUTH_HEADER
22
23 #include <string>
24 #include <jthread.h>
25 #include <jmutex.h>
26 #include "common_irrlicht.h"
27 #include "exceptions.h"
28
29 // Player privileges. These form a bitmask stored in the privs field
30 // of the player, and define things they're allowed to do. See also
31 // the static methods Player::privsToString and stringToPrivs that
32 // convert these to human-readable form.
33 const u64 PRIV_BUILD = 1;            // Can build - i.e. modify the world
34 const u64 PRIV_TELEPORT = 2;         // Can teleport
35 const u64 PRIV_SETTIME = 4;          // Can set the time
36 const u64 PRIV_PRIVS = 8;            // Can grant and revoke privileges
37 const u64 PRIV_SERVER = 16;          // Can manage the server (e.g. shutodwn
38                                      // ,settings)
39 const u64 PRIV_SHOUT = 32;           // Can broadcast chat messages to all
40                                      // players
41
42 // Default privileges - these can be overriden for new players using the
43 // config option "default_privs" - however, this value still applies for
44 // players that existed before the privileges system was added.
45 const u64 PRIV_DEFAULT = PRIV_BUILD|PRIV_SHOUT;
46 const u64 PRIV_ALL = 0x7FFFFFFFFFFFFFFFULL;
47 const u64 PRIV_INVALID = 0x8000000000000000ULL;
48
49 // Convert a privileges value into a human-readable string,
50 // with each component separated by a comma.
51 std::string privsToString(u64 privs);
52
53 // Converts a comma-seperated list of privilege values into a
54 // privileges value. The reverse of privsToString(). Returns
55 // PRIV_INVALID if there is anything wrong with the input.
56 u64 stringToPrivs(std::string str);
57
58 struct AuthData
59 {
60         std::string pwd;
61         u64 privs;
62
63         AuthData():
64                 privs(PRIV_DEFAULT)
65         {
66         }
67 };
68
69 class AuthNotFoundException : public BaseException
70 {
71 public:
72         AuthNotFoundException(const char *s):
73                 BaseException(s)
74         {}
75 };
76
77 class AuthManager
78 {
79 public:
80         AuthManager(const std::string &authfilepath);
81         ~AuthManager();
82         void load();
83         void save();
84         bool exists(const std::string &username);
85         void set(const std::string &username, AuthData ad);
86         void add(const std::string &username);
87         std::string getPassword(const std::string &username);
88         void setPassword(const std::string &username,
89                         const std::string &password);
90         u64 getPrivs(const std::string &username);
91         void setPrivs(const std::string &username, u64 privs);
92         bool isModified();
93 private:
94         JMutex m_mutex;
95         std::string m_authfilepath;
96         core::map<std::string, AuthData> m_authdata;
97         bool m_modified;
98 };
99
100 #endif
101