2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
// cAuthenticator.h
|
|
|
|
|
|
|
|
// Interfaces to the cAuthenticator class representing the thread that authenticates users against the official MC server
|
|
|
|
// Authentication prevents "hackers" from joining with an arbitrary username (possibly impersonating the server admins)
|
|
|
|
// For more info, see http://wiki.vg/Session#Server_operation
|
|
|
|
// In MCS, authentication is implemented as a single thread that receives queued auth requests and dispatches them one by one.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#ifndef CAUTHENTICATOR_H_INCLUDED
|
|
|
|
#define CAUTHENTICATOR_H_INCLUDED
|
|
|
|
|
2014-04-13 07:04:56 -04:00
|
|
|
#include "../OSSupport/IsThread.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fwd: "cRoot.h"
|
|
|
|
class cRoot;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cAuthenticator :
|
|
|
|
public cIsThread
|
|
|
|
{
|
|
|
|
typedef cIsThread super;
|
2014-04-13 07:04:56 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
public:
|
|
|
|
cAuthenticator(void);
|
|
|
|
~cAuthenticator();
|
|
|
|
|
2014-04-13 07:04:56 -04:00
|
|
|
/** (Re-)read server and address from INI: */
|
2013-10-26 13:47:12 -04:00
|
|
|
void ReadINI(cIniFile & IniFile);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-04-13 07:04:56 -04:00
|
|
|
/** Queues a request for authenticating a user. If the auth fails, the user will be kicked */
|
2012-06-14 09:06:06 -04:00
|
|
|
void Authenticate(int a_ClientID, const AString & a_UserName, const AString & a_ServerHash);
|
|
|
|
|
2014-04-13 07:04:56 -04:00
|
|
|
/** Starts the authenticator thread. The thread may be started and stopped repeatedly */
|
2013-10-26 13:47:12 -04:00
|
|
|
void Start(cIniFile & IniFile);
|
2014-04-13 07:04:56 -04:00
|
|
|
|
|
|
|
/** Stops the authenticator thread. The thread may be started and stopped repeatedly */
|
2012-06-14 09:06:06 -04:00
|
|
|
void Stop(void);
|
2014-04-13 07:04:56 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
private:
|
|
|
|
|
|
|
|
class cUser
|
|
|
|
{
|
|
|
|
public:
|
2012-09-06 13:36:59 -04:00
|
|
|
int m_ClientID;
|
|
|
|
AString m_Name;
|
|
|
|
AString m_ServerID;
|
2014-04-13 07:04:56 -04:00
|
|
|
|
2012-09-06 13:36:59 -04:00
|
|
|
cUser(int a_ClientID, const AString & a_Name, const AString & a_ServerID) :
|
|
|
|
m_ClientID(a_ClientID),
|
|
|
|
m_Name(a_Name),
|
|
|
|
m_ServerID(a_ServerID)
|
|
|
|
{
|
|
|
|
}
|
2014-04-13 07:04:56 -04:00
|
|
|
};
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
typedef std::deque<cUser> cUserList;
|
2014-04-13 07:04:56 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
cCriticalSection m_CS;
|
|
|
|
cUserList m_Queue;
|
|
|
|
cEvent m_QueueNonempty;
|
2014-04-13 07:04:56 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
AString m_Server;
|
|
|
|
AString m_Address;
|
|
|
|
bool m_ShouldAuthenticate;
|
2014-04-13 07:04:56 -04:00
|
|
|
|
|
|
|
/** cIsThread override: */
|
2012-06-14 09:06:06 -04:00
|
|
|
virtual void Execute(void) override;
|
2014-04-13 07:04:56 -04:00
|
|
|
|
|
|
|
/** Returns true if the user authenticated okay, false on error; iLevel is the recursion deptht (bails out if too deep) */
|
|
|
|
bool AuthWithYggdrasil(AString & a_UserName, const AString & a_ServerId, AString & a_UUID);
|
2012-06-14 09:06:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // CAUTHENTICATOR_H_INCLUDED
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|