1
0
Fork 0

Player properties are now retrieved

This commit is contained in:
Tiger Wang 2014-07-14 19:49:31 +01:00
parent 6484e9814a
commit 4e24f711ab
11 changed files with 216 additions and 116 deletions

View File

@ -290,17 +290,18 @@ void cClientHandle::Kick(const AString & a_Reason)
void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID)
void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, const AString & a_Properties)
{
if (m_State != csAuthenticating)
{
return;
}
ASSERT( m_Player == NULL );
ASSERT(m_Player == NULL);
m_Username = a_Name;
m_UUID = a_UUID;
m_Properties = a_Properties;
// Send login success (if the protocol supports it):
m_Protocol->SendLoginSuccess();
@ -324,7 +325,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID)
if (!cRoot::Get()->GetPluginManager()->CallHookPlayerJoined(*m_Player))
{
cRoot::Get()->BroadcastChatJoin(Printf("%s has joined the game", GetUsername().c_str()));
LOGINFO("Player %s has joined the game.", m_Username.c_str());
LOGINFO("Player %s has joined the game", m_Username.c_str());
}
m_ConfirmPosition = m_Player->GetPosition();

View File

@ -67,6 +67,8 @@ public:
const AString & GetUUID(void) const { return m_UUID; } // tolua_export
void SetUUID(const AString & a_UUID) { m_UUID = a_UUID; }
const AString & GetProperties(void) const { return m_Properties; }
/** Generates an UUID based on the username stored for this client, and stores it in the m_UUID member.
This is used for the offline (non-auth) mode, when there's no UUID source.
@ -92,7 +94,7 @@ public:
static AString FormatChatPrefix(bool ShouldAppendChatPrefixes, AString a_ChatPrefixS, AString m_Color1, AString m_Color2);
void Kick(const AString & a_Reason); // tolua_export
void Authenticate(const AString & a_Name, const AString & a_UUID); // Called by cAuthenticator when the user passes authentication
void Authenticate(const AString & a_Name, const AString & a_UUID, const AString & a_Properties); // Called by cAuthenticator when the user passes authentication
void StreamChunks(void);
@ -280,6 +282,7 @@ private:
AString m_Username;
AString m_Password;
AString m_Properties;
cCriticalSection m_CSChunkLists;
cChunkCoordsList m_LoadedChunks; // Chunks that the player belongs to

View File

@ -130,7 +130,7 @@ cPlayer::~cPlayer(void)
if (!cRoot::Get()->GetPluginManager()->CallHookPlayerDestroyed(*this))
{
cRoot::Get()->BroadcastChatLeave(Printf("%s has left the game", GetName().c_str()));
LOGINFO("Player %s has left the game.", GetName().c_str());
LOGINFO("Player %s has left the game", GetName().c_str());
}
LOGD("Deleting cPlayer \"%s\" at %p, ID %d", GetName().c_str(), this, GetUniqueID());
@ -1804,7 +1804,7 @@ bool cPlayer::LoadFromFile(const AString & a_FileName)
cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), GetName(), &m_Stats);
StatSerializer.Load();
LOGD("Player \"%s\" was read from file \"%s\", spawning at {%.2f, %.2f, %.2f} in world \"%s\"",
LOGD("Player %s was read from file \"%s\", spawning at {%.2f, %.2f, %.2f} in world \"%s\"",
GetName().c_str(), a_FileName.c_str(), GetPosX(), GetPosY(), GetPosZ(), m_LoadedWorldName.c_str()
);

View File

@ -11,15 +11,67 @@
#include "PolarSSL++/BlockingSslClientSocket.h"
#include <sstream>
#include <iomanip>
#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/ */
static const AString gStarfieldCACert(
// G2 cert
"-----BEGIN CERTIFICATE-----\n"
"MIID3TCCAsWgAwIBAgIBADANBgkqhkiG9w0BAQsFADCBjzELMAkGA1UEBhMCVVMx\n"
"EDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxJTAjBgNVBAoT\n"
"HFN0YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAMTKVN0YXJmaWVs\n"
"ZCBSb290IENlcnRpZmljYXRlIEF1dGhvc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bVazc1xDCDqmI56FspGowaDELMAkGA1UEBhMCVVMxJTAjBgNVBAoTHFN0\n"
"YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAsTKVN0YXJmaWVsZCBD\n"
"bGFzcyAyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5ggEAMAwGA1UdEwQFMAMBAf8w\n"
"DQYJKoZIhvcNAQEFBQADggEBAAWdP4id0ckaVaGsafPzWdqbAYcaT1epoXkJKtv3\n"
"L7IezMdeatiDh6GX70k1PncGQVhiv45YuApnP+yz3SFmH8lU+nLMPUxA2IGvd56D\n"
"eruix/U0F47ZEUD0/CwqTRV/p2JdLiXTAAsgGh1o+Re49L2L7ShZ3U0WixeDyLJl\n"
"xy16paq8U4Zt3VekyvggQQto8PT7dL5WXXp59fkdheMtlb71cZBDzI0fmgAKhynp\n"
"VSJYACPq4xJDKVtHCN2MQWplBqjlIapBtJUhlbl90TSrE9atvNziPTnNvT51cKEY\n"
"WQPJIrSPnNVeKtelttQKbfi3QBFGmh95DmK/D5fs4C8fF5Q=\n"
"-----END CERTIFICATE-----\n"
);
@ -29,6 +81,7 @@ cAuthenticator::cAuthenticator(void) :
super("cAuthenticator"),
m_Server(DEFAULT_AUTH_SERVER),
m_Address(DEFAULT_AUTH_ADDRESS),
m_PropertiesAddress(DEFAULT_PROPERTIES_ADDRESS),
m_ShouldAuthenticate(true)
{
}
@ -50,6 +103,7 @@ 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);
}
@ -123,8 +177,26 @@ void cAuthenticator::Execute(void)
AString UUID;
if (AuthWithYggdrasil(NewUserName, ServerID, UUID))
{
LOGINFO("User %s authenticated with UUID '%s'", NewUserName.c_str(), UUID.c_str());
cRoot::Get()->AuthenticateUser(ClientID, NewUserName, UUID);
AString 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, "-");
}
cRoot::Get()->AuthenticateUser(ClientID, NewUserName, UUID, Properties);
}
else
{
@ -137,97 +209,27 @@ void cAuthenticator::Execute(void)
bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_ServerId, AString & a_UUID)
bool cAuthenticator::ConnectSecurelyToAddress(const AString & a_CACerts, const AString & a_ExpectedPeerName, const AString & a_Data, AString & a_Response)
{
LOGD("Trying to auth user %s", a_UserName.c_str());
int ret;
unsigned char buf[1024];
/* Initialize certificates */
// 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/
static const AString StarfieldCACert(
// G2 cert
"-----BEGIN CERTIFICATE-----\n"
"MIID3TCCAsWgAwIBAgIBADANBgkqhkiG9w0BAQsFADCBjzELMAkGA1UEBhMCVVMx\n"
"EDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxJTAjBgNVBAoT\n"
"HFN0YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAMTKVN0YXJmaWVs\n"
"ZCBSb290IENlcnRpZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTA5MDkwMTAwMDAw\n"
"MFoXDTM3MTIzMTIzNTk1OVowgY8xCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdBcml6\n"
"b25hMRMwEQYDVQQHEwpTY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
"bGFzcyAyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5ggEAMAwGA1UdEwQFMAMBAf8w\n"
"DQYJKoZIhvcNAQEFBQADggEBAAWdP4id0ckaVaGsafPzWdqbAYcaT1epoXkJKtv3\n"
"L7IezMdeatiDh6GX70k1PncGQVhiv45YuApnP+yz3SFmH8lU+nLMPUxA2IGvd56D\n"
"eruix/U0F47ZEUD0/CwqTRV/p2JdLiXTAAsgGh1o+Re49L2L7ShZ3U0WixeDyLJl\n"
"xy16paq8U4Zt3VekyvggQQto8PT7dL5WXXp59fkdheMtlb71cZBDzI0fmgAKhynp\n"
"VSJYACPq4xJDKVtHCN2MQWplBqjlIapBtJUhlbl90TSrE9atvNziPTnNvT51cKEY\n"
"WQPJIrSPnNVeKtelttQKbfi3QBFGmh95DmK/D5fs4C8fF5Q=\n"
"-----END CERTIFICATE-----\n"
);
// Connect the socket:
cBlockingSslClientSocket Socket;
Socket.SetTrustedRootCertsFromString(StarfieldCACert, m_Server);
if (!Socket.Connect(m_Server, 443))
Socket.SetTrustedRootCertsFromString(a_CACerts, a_ExpectedPeerName);
if (!Socket.Connect(a_ExpectedPeerName, 443))
{
LOGWARNING("cAuthenticator: Can't connect to %s: %s", m_Server.c_str(), Socket.GetLastErrorText().c_str());
LOGWARNING("cAuthenticator: Can't connect to %s: %s", a_ExpectedPeerName.c_str(), Socket.GetLastErrorText().c_str());
return false;
}
// Create the GET request:
AString ActualAddress = m_Address;
ReplaceString(ActualAddress, "%USERNAME%", a_UserName);
ReplaceString(ActualAddress, "%SERVERID%", a_ServerId);
AString Request;
Request += "GET " + ActualAddress + " HTTP/1.0\r\n";
Request += "Host: " + m_Server + "\r\n";
Request += "User-Agent: MCServer\r\n";
Request += "Connection: close\r\n";
Request += "\r\n";
if (!Socket.Send(Request.c_str(), Request.size()))
if (!Socket.Send(a_Data.c_str(), a_Data.size()))
{
LOGWARNING("cAuthenticator: Writing SSL data failed: %s", Socket.GetLastErrorText().c_str());
return false;
}
// Read the HTTP response:
std::string Response;
int ret;
unsigned char buf[1024];
for (;;)
{
ret = Socket.Receive(buf, sizeof(buf));
@ -235,7 +237,7 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
if ((ret == POLARSSL_ERR_NET_WANT_READ) || (ret == POLARSSL_ERR_NET_WANT_WRITE))
{
// This value should never be returned, it is handled internally by cBlockingSslClientSocket
LOGWARNING("cAuthenticator: SSL reading failed internally.");
LOGWARNING("cAuthenticator: SSL reading failed internally");
return false;
}
if (ret == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY)
@ -252,18 +254,46 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
break;
}
Response.append((const char *)buf, (size_t)ret);
a_Response.append((const char *)buf, (size_t)ret);
}
Socket.Disconnect();
return true;
}
bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_ServerId, AString & a_UUID)
{
LOGD("Trying to authenticate user %s", a_UserName.c_str());
// Create the GET request:
AString ActualAddress = m_Address;
ReplaceString(ActualAddress, "%USERNAME%", a_UserName);
ReplaceString(ActualAddress, "%SERVERID%", a_ServerId);
AString Request;
Request += "GET " + ActualAddress + " HTTP/1.0\r\n";
Request += "Host: " + m_Server + "\r\n";
Request += "User-Agent: MCServer\r\n";
Request += "Connection: close\r\n";
Request += "\r\n";
AString Response;
if (!ConnectSecurelyToAddress(gStarfieldCACert, m_Server, Request, Response))
{
return false;
}
// Check the HTTP status line:
AString prefix("HTTP/1.1 200 OK");
const AString Prefix("HTTP/1.1 200 OK");
AString HexDump;
if (Response.compare(0, prefix.size(), prefix))
if (Response.compare(0, Prefix.size(), Prefix))
{
LOGINFO("User %s failed to auth, bad http status line received", a_UserName.c_str());
LOG("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
LOGINFO("User %s failed to auth, bad HTTP status line received", a_UserName.c_str());
LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
return false;
}
@ -271,8 +301,8 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
size_t idxHeadersEnd = Response.find("\r\n\r\n");
if (idxHeadersEnd == AString::npos)
{
LOGINFO("User %s failed to authenticate, bad http response header received", a_UserName.c_str());
LOG("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
LOGINFO("User %s failed to authenticate, bad HTTP response header received", a_UserName.c_str());
LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
return false;
}
Response.erase(0, idxHeadersEnd + 4);
@ -286,20 +316,12 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
Json::Reader reader;
if (!reader.parse(Response, root, false))
{
LOGWARNING("cAuthenticator: Cannot parse Received Data to json!");
LOGWARNING("cAuthenticator: Cannot parse received data (authentication) to JSON!");
return false;
}
a_UserName = root.get("name", "Unknown").asString();
a_UUID = root.get("id", "").asString();
// 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;
}
@ -307,3 +329,60 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
bool cAuthenticator::GetPlayerProperties(const AString & a_UUID, AString & a_Properties)
{
LOGD("Trying to get properties for user %s", a_UUID.c_str());
// Create the GET request:
AString ActualAddress = m_PropertiesAddress;
ReplaceString(ActualAddress, "%UUID%", a_UUID);
AString Request;
Request += "GET " + ActualAddress + " HTTP/1.0\r\n";
Request += "Host: " + m_Server + "\r\n";
Request += "User-Agent: MCServer\r\n";
Request += "Connection: close\r\n";
Request += "\r\n";
AString Response;
if (!ConnectSecurelyToAddress(gStarfieldCACert, m_Server, Request, Response))
{
return false;
}
// Check the HTTP status line:
const AString Prefix("HTTP/1.1 200 OK");
AString HexDump;
if (Response.compare(0, Prefix.size(), Prefix))
{
LOGINFO("Failed to get properties for user %s, bad HTTP status line received", a_UUID.c_str());
LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
return false;
}
// Erase the HTTP headers from the response:
size_t idxHeadersEnd = Response.find("\r\n\r\n");
if (idxHeadersEnd == AString::npos)
{
LOGINFO("Failed to get properties for user %s, bad HTTP response header received", a_UUID.c_str());
LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
return false;
}
Response.erase(0, idxHeadersEnd + 4);
// Parse the Json response:
if (Response.empty())
{
return false;
}
Json::Value root;
Json::Reader reader;
if (!reader.parse(Response, root, false))
{
LOGWARNING("cAuthenticator: Cannot parse received properties data to JSON!");
return false;
}
a_Properties = root["properties"].toStyledString();
return true;
}

View File

@ -73,13 +73,18 @@ private:
AString m_Server;
AString m_Address;
AString m_PropertiesAddress;
bool m_ShouldAuthenticate;
/** cIsThread override: */
virtual void Execute(void) override;
bool ConnectSecurelyToAddress(const AString & a_CACerts, const AString & a_ExpectedPeerName, const AString & a_Data, 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);
bool GetPlayerProperties(const AString & a_UUID, AString & a_Properties);
};

View File

@ -3015,7 +3015,19 @@ void cProtocol176::SendPlayerSpawn(const cPlayer & a_Player)
Pkt.WriteVarInt(a_Player.GetUniqueID());
Pkt.WriteString(a_Player.GetClientHandle()->GetUUID());
Pkt.WriteString(a_Player.GetName());
Pkt.WriteVarInt(0); // We have no data to send here
Json::Value root;
Json::Reader reader;
reader.parse(m_Client->GetProperties(), root);
Pkt.WriteVarInt(root.size());
for (Json::Value::iterator itr = root.begin(); itr != root.end(); ++itr)
{
Pkt.WriteString(((Json::Value)*itr).get("name", "").toStyledString());
Pkt.WriteString(((Json::Value)*itr).get("value", "").toStyledString());
Pkt.WriteString(((Json::Value)*itr).get("signature", "").toStyledString());
}
Pkt.WriteFPInt(a_Player.GetPosX());
Pkt.WriteFPInt(a_Player.GetPosY());
Pkt.WriteFPInt(a_Player.GetPosZ());

View File

@ -499,9 +499,9 @@ void cRoot::KickUser(int a_ClientID, const AString & a_Reason)
void cRoot::AuthenticateUser(int a_ClientID, const AString & a_Name, const AString & a_UUID)
void cRoot::AuthenticateUser(int a_ClientID, const AString & a_Name, const AString & a_UUID, const AString & a_Properties)
{
m_Server->AuthenticateUser(a_ClientID, a_Name, a_UUID);
m_Server->AuthenticateUser(a_ClientID, a_Name, a_UUID, a_Properties);
}

View File

@ -89,7 +89,7 @@ public:
void KickUser(int a_ClientID, const AString & a_Reason);
/// Called by cAuthenticator to auth the specified user
void AuthenticateUser(int a_ClientID, const AString & a_Name, const AString & a_UUID);
void AuthenticateUser(int a_ClientID, const AString & a_Name, const AString & a_UUID, const AString & a_Properties = "");
/// Executes commands queued in the command queue
void TickCommands(void);

View File

@ -656,14 +656,14 @@ void cServer::KickUser(int a_ClientID, const AString & a_Reason)
void cServer::AuthenticateUser(int a_ClientID, const AString & a_Name, const AString & a_UUID)
void cServer::AuthenticateUser(int a_ClientID, const AString & a_Name, const AString & a_UUID, const AString & a_Properties)
{
cCSLock Lock(m_CSClients);
for (ClientList::iterator itr = m_Clients.begin(); itr != m_Clients.end(); ++itr)
{
if ((*itr)->GetUniqueID() == a_ClientID)
{
(*itr)->Authenticate(a_Name, a_UUID);
(*itr)->Authenticate(a_Name, a_UUID, a_Properties);
return;
}
} // for itr - m_Clients[]

View File

@ -37,7 +37,7 @@
class cPlayer;
class cClientHandle;
class cIniFile;
class cCommandOutputCallback ;
class cCommandOutputCallback;
typedef std::list<cClientHandle *> cClientHandleList;
@ -83,7 +83,7 @@ public: // tolua_export
void Shutdown(void);
void KickUser(int a_ClientID, const AString & a_Reason);
void AuthenticateUser(int a_ClientID, const AString & a_Name, const AString & a_UUID); // Called by cAuthenticator to auth the specified user
void AuthenticateUser(int a_ClientID, const AString & a_Name, const AString & a_UUID, const AString & a_Properties); // Called by cAuthenticator to auth the specified user
const AString & GetServerID(void) const { return m_ServerID; } // tolua_export

View File

@ -2363,7 +2363,7 @@ void cWorld::RemovePlayer(cPlayer * a_Player)
}
{
cCSLock Lock(m_CSPlayers);
LOGD("Removing player \"%s\" from world \"%s\".", a_Player->GetName().c_str(), m_WorldName.c_str());
LOGD("Removing player %s from world \"%s\"", a_Player->GetName().c_str(), m_WorldName.c_str());
m_Players.remove(a_Player);
}