Cuberite
A lightweight, fast and extensible game server for Minecraft
Authenticator.h
Go to the documentation of this file.
1 
2 // cAuthenticator.h
3 
4 // Interfaces to the cAuthenticator class representing the thread that authenticates users against the official Mojang servers
5 // Authentication prevents "hackers" from joining with an arbitrary username (possibly impersonating the server admins)
6 // For more info, see http://wiki.vg/Session
7 // In Cuberite, authentication is implemented as a single thread that receives queued auth requests and dispatches them one by one.
8 
9 
10 
11 
12 
13 #pragma once
14 
15 #include "../OSSupport/IsThread.h"
16 
17 // fwd:
18 class cUUID;
20 
21 namespace Json
22 {
23  class Value;
24 }
25 
26 
27 
28 
29 
31  public cIsThread
32 {
33  using Super = cIsThread;
34 
35 public:
36 
38  virtual ~cAuthenticator() override;
39 
41  void ReadSettings(cSettingsRepositoryInterface & a_Settings);
42 
44  void Authenticate(int a_ClientID, std::string_view a_Username, std::string_view a_ServerHash);
45 
47  void Start(cSettingsRepositoryInterface & a_Settings);
48 
50  void Stop(void);
51 
52 private:
53 
54  class cUser
55  {
56  public:
60 
61  cUser(int a_ClientID, const std::string_view a_Name, const std::string_view a_ServerID) :
62  m_ClientID(a_ClientID),
63  m_Name(a_Name),
64  m_ServerID(a_ServerID)
65  {
66  }
67  };
68 
69  using cUserList = std::deque<cUser>;
70 
74 
77 
83 
86 
88  virtual void Execute(void) override;
89 
92  bool AuthWithYggdrasil(AString & a_UserName, const AString & a_ServerId, cUUID & a_UUID, Json::Value & a_Properties) const;
93 };
94 
95 
96 
97 
std::string AString
Definition: StringUtils.h:11
Definition: Inventory.h:11
Definition: Event.h:18
cIsThread(AString &&a_ThreadName)
Definition: IsThread.cpp:16
void Start(void)
Starts the thread; returns without waiting for the actual start.
Definition: IsThread.cpp:35
cCriticalSection m_CS
Definition: Authenticator.h:71
bool m_ShouldAuthenticate
Definition: Authenticator.h:85
AString m_PropertiesAddress
Definition: Authenticator.h:84
cEvent m_QueueNonempty
Definition: Authenticator.h:73
void ReadSettings(cSettingsRepositoryInterface &a_Settings)
(Re-)read server and address from INI:
void Stop(void)
Stops the authenticator thread.
AString m_Server
The server that is to be contacted for auth / UUID conversions.
Definition: Authenticator.h:76
virtual ~cAuthenticator() override
virtual void Execute(void) override
cIsThread override:
AString m_Address
The URL to use for auth, without server part.
Definition: Authenticator.h:82
bool AuthWithYggdrasil(AString &a_UserName, const AString &a_ServerId, cUUID &a_UUID, Json::Value &a_Properties) const
Returns true if the user authenticated okay, false on error Returns the case-corrected username,...
void Authenticate(int a_ClientID, std::string_view a_Username, std::string_view a_ServerHash)
Queues a request for authenticating a user.
std::deque< cUser > cUserList
Definition: Authenticator.h:69
cUserList m_Queue
Definition: Authenticator.h:72
cUser(int a_ClientID, const std::string_view a_Name, const std::string_view a_ServerID)
Definition: Authenticator.h:61
Definition: UUID.h:11