From f2c4f56ccd1862fb6d02f6f2dfb3230123f465cf Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 16 Jul 2014 11:21:02 +0100 Subject: Unified functions Thanks @Howaner! --- src/Protocol/Authenticator.cpp | 51 +++++++++++++++++++----------------------- src/Protocol/Authenticator.h | 11 +++++---- 2 files changed, 28 insertions(+), 34 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp index c01d748c6..28df0f882 100644 --- a/src/Protocol/Authenticator.cpp +++ b/src/Protocol/Authenticator.cpp @@ -17,7 +17,6 @@ #define DEFAULT_AUTH_SERVER "sessionserver.mojang.com" #define DEFAULT_AUTH_ADDRESS "/session/minecraft/hasJoined?username=%USERNAME%&serverId=%SERVERID%" -#define DEFAULT_PROPERTIES_ADDRESS "/session/minecraft/profile/%UUID%" /** This is the data of the root certs for Starfield Technologies, the CA that signed sessionserver.mojang.com's cert: Downloaded from http://certs.starfieldtech.com/repository/ */ @@ -81,7 +80,6 @@ cAuthenticator::cAuthenticator(void) : super("cAuthenticator"), m_Server(DEFAULT_AUTH_SERVER), m_Address(DEFAULT_AUTH_ADDRESS), - m_PropertiesAddress(DEFAULT_PROPERTIES_ADDRESS), m_ShouldAuthenticate(true) { } @@ -103,7 +101,6 @@ void cAuthenticator::ReadINI(cIniFile & IniFile) { m_Server = IniFile.GetValueSet("Authentication", "Server", DEFAULT_AUTH_SERVER); m_Address = IniFile.GetValueSet("Authentication", "Address", DEFAULT_AUTH_ADDRESS); - m_PropertiesAddress = IniFile.GetValueSet("Authentication", "PlayerPropertiesAddress", DEFAULT_PROPERTIES_ADDRESS); m_ShouldAuthenticate = IniFile.GetValueSetB("Authentication", "Authenticate", true); } @@ -176,27 +173,10 @@ void cAuthenticator::Execute(void) AString NewUserName = UserName; AString UUID; - if (AuthWithYggdrasil(NewUserName, ServerID, UUID)) + Json::Value Properties; + if (AuthWithYggdrasil(NewUserName, ServerID, UUID, Properties)) { - Json::Value Properties; - if (!GetPlayerProperties(UUID, Properties)) - { - LOGINFO("User %s authenticated with UUID %s but property getting failed", NewUserName.c_str(), UUID.c_str()); - } - else - { - LOGINFO("User %s authenticated with UUID %s", NewUserName.c_str(), UUID.c_str()); - } - - // If the UUID doesn't contain the hashes, insert them at the proper places: - if (UUID.size() == 32) - { - UUID.insert(8, "-"); - UUID.insert(13, "-"); - UUID.insert(18, "-"); - UUID.insert(23, "-"); - } - + LOGINFO("User %s authenticated with UUID %s", NewUserName.c_str(), UUID.c_str()); cRoot::Get()->AuthenticateUser(ClientID, NewUserName, UUID, Properties); } else @@ -266,7 +246,7 @@ bool cAuthenticator::ConnectSecurelyToAddress(const AString & a_CACerts, const A -bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_ServerId, AString & a_UUID) +bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_ServerId, AString & a_UUID, Json::Value & a_Properties) { LOGD("Trying to authenticate user %s", a_UserName.c_str()); @@ -322,6 +302,16 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S } a_UserName = root.get("name", "Unknown").asString(); a_UUID = root.get("id", "").asString(); + a_Properties = root["properties"]; + + // If the UUID doesn't contain the hashes, insert them at the proper places: + if (a_UUID.size() == 32) + { + a_UUID.insert(8, "-"); + a_UUID.insert(13, "-"); + a_UUID.insert(18, "-"); + a_UUID.insert(23, "-"); + } return true; } @@ -330,6 +320,13 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S +/* In case we want to export this function to the plugin API later - don't forget to add the relevant INI configuration lines for DEFAULT_PROPERTIES_ADDRESS + +#define DEFAULT_PROPERTIES_ADDRESS "/session/minecraft/profile/%UUID%" + +// Gets the properties, such as skin, of a player based on their UUID via Mojang's API +bool GetPlayerProperties(const AString & a_UUID, Json::Value & a_Properties); + bool cAuthenticator::GetPlayerProperties(const AString & a_UUID, Json::Value & a_Properties) { LOGD("Trying to get properties for user %s", a_UUID.c_str()); @@ -376,6 +373,7 @@ bool cAuthenticator::GetPlayerProperties(const AString & a_UUID, Json::Value & a { return false; } + Json::Value root; Json::Reader reader; if (!reader.parse(Response, root, false)) @@ -387,7 +385,4 @@ bool cAuthenticator::GetPlayerProperties(const AString & a_UUID, Json::Value & a a_Properties = root["properties"]; return true; } - - - - +*/ diff --git a/src/Protocol/Authenticator.h b/src/Protocol/Authenticator.h index 9f6dd60ca..9c2405315 100644 --- a/src/Protocol/Authenticator.h +++ b/src/Protocol/Authenticator.h @@ -85,13 +85,12 @@ private: virtual void Execute(void) override; /** Connects to a hostname using SSL, sends given data, and sets the response, returning whether all was successful or not */ - bool ConnectSecurelyToAddress(const AString & a_CACerts, const AString & a_ExpectedPeerName, const AString & a_Data, AString & a_Response); + bool ConnectSecurelyToAddress(const AString & a_CACerts, const AString & a_ExpectedPeerName, const AString & a_Request, AString & a_Response); - /** 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); - - /** Gets the properties, such as skin, of a player based on their UUID via Mojang's API */ - bool GetPlayerProperties(const AString & a_UUID, Json::Value & a_Properties); + /** Returns true if the user authenticated okay, false on error + Sets the username, UUID, and properties (i.e. skin) fields + */ + bool AuthWithYggdrasil(AString & a_UserName, const AString & a_ServerId, AString & a_UUID, Json::Value & a_Properties); }; -- cgit v1.2.3