summaryrefslogtreecommitdiffstats
path: root/src/Protocol
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-07-16 12:21:02 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-07-16 12:21:02 +0200
commitf2c4f56ccd1862fb6d02f6f2dfb3230123f465cf (patch)
treeda771b9b54e3ec3ea775f96343dd8b7d3d36b401 /src/Protocol
parentStore properties as Json::Value (diff)
downloadcuberite-f2c4f56ccd1862fb6d02f6f2dfb3230123f465cf.tar
cuberite-f2c4f56ccd1862fb6d02f6f2dfb3230123f465cf.tar.gz
cuberite-f2c4f56ccd1862fb6d02f6f2dfb3230123f465cf.tar.bz2
cuberite-f2c4f56ccd1862fb6d02f6f2dfb3230123f465cf.tar.lz
cuberite-f2c4f56ccd1862fb6d02f6f2dfb3230123f465cf.tar.xz
cuberite-f2c4f56ccd1862fb6d02f6f2dfb3230123f465cf.tar.zst
cuberite-f2c4f56ccd1862fb6d02f6f2dfb3230123f465cf.zip
Diffstat (limited to 'src/Protocol')
-rw-r--r--src/Protocol/Authenticator.cpp51
-rw-r--r--src/Protocol/Authenticator.h11
2 files changed, 28 insertions, 34 deletions
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);
};