From 0c2b307eab67b7f37d82a7862a6acbcd96b45adb Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 20 Jan 2014 18:22:08 +0100 Subject: first changes for enchanting (not finished) - added enchanting table block handler and added it to the blockhandler - added enchanting window - drop item in the slot 0 when the player close the window - added enchanting packet (1.7 only) - some more... --- src/Protocol/Protocol17x.cpp | 17 +++++++++++++++++ src/Protocol/Protocol17x.h | 1 + 2 files changed, 18 insertions(+) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index e5a380f8a..d120d8d91 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1143,6 +1143,7 @@ bool cProtocol172::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) case 0x0e: HandlePacketWindowClick (a_ByteBuffer); return true; case 0x0f: // Confirm transaction - not used in MCS case 0x10: HandlePacketCreativeInventoryAction(a_ByteBuffer); return true; + case 0x11: HandlePacketEnchanting (a_ByteBuffer); return true; case 0x12: HandlePacketUpdateSign (a_ByteBuffer); return true; case 0x13: HandlePacketPlayerAbilities (a_ByteBuffer); return true; case 0x14: HandlePacketTabComplete (a_ByteBuffer); return true; @@ -1545,6 +1546,22 @@ void cProtocol172::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer) +void cProtocol172::HandlePacketEnchanting(cByteBuffer & a_ByteBuffer) +{ + HANDLE_READ(a_ByteBuffer, ReadByte, Byte, WindowID); + HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Enchantment); + + //TODO: EnchantItem (getWindow, getItem, Enchant) + + + + LOG("Enchantment Paket empfangen!"); +} + + + + + void cProtocol172::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer) { HANDLE_READ(a_ByteBuffer, ReadChar, char, WindowID); diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 3ae774c18..04d65910c 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -258,6 +258,7 @@ protected: void HandlePacketTabComplete (cByteBuffer & a_ByteBuffer); void HandlePacketUpdateSign (cByteBuffer & a_ByteBuffer); void HandlePacketUseEntity (cByteBuffer & a_ByteBuffer); + void HandlePacketEnchanting (cByteBuffer & a_ByteBuffer); void HandlePacketWindowClick (cByteBuffer & a_ByteBuffer); void HandlePacketWindowClose (cByteBuffer & a_ByteBuffer); -- cgit v1.2.3 From bfac00f2807a6740e876adebd689cc3ae6e075ed Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Fri, 24 Jan 2014 20:01:21 +0100 Subject: Some updates for enchanting --- src/Protocol/Protocol17x.cpp | 14 +++++++++++--- src/Protocol/Protocol17x.h | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index d120d8d91..f302da2ad 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1143,7 +1143,7 @@ bool cProtocol172::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) case 0x0e: HandlePacketWindowClick (a_ByteBuffer); return true; case 0x0f: // Confirm transaction - not used in MCS case 0x10: HandlePacketCreativeInventoryAction(a_ByteBuffer); return true; - case 0x11: HandlePacketEnchanting (a_ByteBuffer); return true; + case 0x11: HandlePacketEnchanting (a_ByteBuffer); return true; case 0x12: HandlePacketUpdateSign (a_ByteBuffer); return true; case 0x13: HandlePacketPlayerAbilities (a_ByteBuffer); return true; case 0x14: HandlePacketTabComplete (a_ByteBuffer); return true; @@ -1551,11 +1551,19 @@ void cProtocol172::HandlePacketEnchanting(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadByte, Byte, WindowID); HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Enchantment); - //TODO: EnchantItem (getWindow, getItem, Enchant) + LOGWARN("Enchantment Packet received!"); + //Get Item from Window Slot + cItem EnchantItem = *m_Client->GetPlayer()->GetWindow()->GetSlot(*m_Client->GetPlayer(), 0); + //Enchant item with Sharpness 5 + EnchantItem.m_Enchantments.SetLevel(cEnchantments::enchSharpness, 5); - LOG("Enchantment Paket empfangen!"); + //Set Enchanted Item to Window Slot + m_Client->GetPlayer()->GetWindow()->SetSlot(*m_Client->GetPlayer(), 0, EnchantItem); + + LOGWARN("Item enchanted!"); + } diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 04d65910c..7877e783a 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -258,7 +258,7 @@ protected: void HandlePacketTabComplete (cByteBuffer & a_ByteBuffer); void HandlePacketUpdateSign (cByteBuffer & a_ByteBuffer); void HandlePacketUseEntity (cByteBuffer & a_ByteBuffer); - void HandlePacketEnchanting (cByteBuffer & a_ByteBuffer); + void HandlePacketEnchanting (cByteBuffer & a_ByteBuffer); void HandlePacketWindowClick (cByteBuffer & a_ByteBuffer); void HandlePacketWindowClose (cByteBuffer & a_ByteBuffer); -- cgit v1.2.3 From 5609fed3602b4da3c22ca042819561c2b9b21715 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Fri, 24 Jan 2014 21:53:27 +0100 Subject: removed hook from enchanting commit --- src/Protocol/Protocol17x.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index f302da2ad..949498734 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1563,7 +1563,7 @@ void cProtocol172::HandlePacketEnchanting(cByteBuffer & a_ByteBuffer) m_Client->GetPlayer()->GetWindow()->SetSlot(*m_Client->GetPlayer(), 0, EnchantItem); LOGWARN("Item enchanted!"); - + } -- cgit v1.2.3 From 36120db400691be75199ff404e35f5c289b8818f Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Fri, 31 Jan 2014 19:46:51 +0100 Subject: Some updates for enchanting (2) --- src/Protocol/Protocol125.cpp | 15 +++++++++++++++ src/Protocol/Protocol125.h | 1 + src/Protocol/Protocol17x.cpp | 17 ++++------------- src/Protocol/Protocol17x.h | 2 +- 4 files changed, 21 insertions(+), 14 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 323a13992..b2b61acc9 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1535,6 +1535,21 @@ int cProtocol125::ParseUseEntity(void) +int cProtocol125::ParseEnchantItem(void) +{ + HANDLE_PACKET_READ(ReadByte, byte, WindowID); + HANDLE_PACKET_READ(ReadByte, byte, Enchantment); + + // TODO: Enchant Handling for older Protocols + + + return PARSE_OK; +} + + + + + int cProtocol125::ParseWindowClick(void) { HANDLE_PACKET_READ(ReadChar, char, WindowID); diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h index 310f9dd78..e3c8765b1 100644 --- a/src/Protocol/Protocol125.h +++ b/src/Protocol/Protocol125.h @@ -133,6 +133,7 @@ protected: virtual int ParseSlotSelected (void); virtual int ParseUpdateSign (void); virtual int ParseUseEntity (void); + virtual int ParseEnchantItem (void); virtual int ParseWindowClick (void); virtual int ParseWindowClose (void); diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 949498734..05b7ebd45 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1143,7 +1143,7 @@ bool cProtocol172::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) case 0x0e: HandlePacketWindowClick (a_ByteBuffer); return true; case 0x0f: // Confirm transaction - not used in MCS case 0x10: HandlePacketCreativeInventoryAction(a_ByteBuffer); return true; - case 0x11: HandlePacketEnchanting (a_ByteBuffer); return true; + case 0x11: HandlePacketEnchantItem (a_ByteBuffer); return true; case 0x12: HandlePacketUpdateSign (a_ByteBuffer); return true; case 0x13: HandlePacketPlayerAbilities (a_ByteBuffer); return true; case 0x14: HandlePacketTabComplete (a_ByteBuffer); return true; @@ -1546,23 +1546,14 @@ void cProtocol172::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer) -void cProtocol172::HandlePacketEnchanting(cByteBuffer & a_ByteBuffer) +void cProtocol172::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer) { HANDLE_READ(a_ByteBuffer, ReadByte, Byte, WindowID); HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Enchantment); - LOGWARN("Enchantment Packet received!"); + LOGWARN("Protocol 1.7: Enchantment Packet received!"); - //Get Item from Window Slot - cItem EnchantItem = *m_Client->GetPlayer()->GetWindow()->GetSlot(*m_Client->GetPlayer(), 0); - - //Enchant item with Sharpness 5 - EnchantItem.m_Enchantments.SetLevel(cEnchantments::enchSharpness, 5); - - //Set Enchanted Item to Window Slot - m_Client->GetPlayer()->GetWindow()->SetSlot(*m_Client->GetPlayer(), 0, EnchantItem); - - LOGWARN("Item enchanted!"); + m_Client->HandleEnchantItem(WindowID, Enchantment); } diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 7877e783a..1f3039edb 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -258,7 +258,7 @@ protected: void HandlePacketTabComplete (cByteBuffer & a_ByteBuffer); void HandlePacketUpdateSign (cByteBuffer & a_ByteBuffer); void HandlePacketUseEntity (cByteBuffer & a_ByteBuffer); - void HandlePacketEnchanting (cByteBuffer & a_ByteBuffer); + void HandlePacketEnchantItem (cByteBuffer & a_ByteBuffer); void HandlePacketWindowClick (cByteBuffer & a_ByteBuffer); void HandlePacketWindowClose (cByteBuffer & a_ByteBuffer); -- cgit v1.2.3 From 7735a1104ff4861fd02609aefaa63ea4587c3649 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sat, 1 Feb 2014 13:09:28 +0100 Subject: added EnchantItemPacket to older Protocols --- src/Protocol/Protocol125.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index b2b61acc9..2df2a695b 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -94,6 +94,7 @@ enum PACKET_INVENTORY_WHOLE = 0x68, PACKET_WINDOW_PROPERTY = 0x69, PACKET_CREATIVE_INVENTORY_ACTION = 0x6B, + PACKET_ENCHANT_ITEM = 0x6C, PACKET_UPDATE_SIGN = 0x82, PACKET_PLAYER_LIST_ITEM = 0xC9, PACKET_PLAYER_ABILITIES = 0xca, @@ -1170,6 +1171,7 @@ int cProtocol125::ParsePacket(unsigned char a_PacketType) case PACKET_SLOT_SELECTED: return ParseSlotSelected(); case PACKET_UPDATE_SIGN: return ParseUpdateSign(); case PACKET_USE_ENTITY: return ParseUseEntity(); + case PACKET_ENCHANT_ITEM: return ParseEnchantItem(); case PACKET_WINDOW_CLICK: return ParseWindowClick(); case PACKET_WINDOW_CLOSE: return ParseWindowClose(); } @@ -1540,8 +1542,9 @@ int cProtocol125::ParseEnchantItem(void) HANDLE_PACKET_READ(ReadByte, byte, WindowID); HANDLE_PACKET_READ(ReadByte, byte, Enchantment); - // TODO: Enchant Handling for older Protocols + LOGWARN("Older Protocol: Enchantment Packet received!"); + m_Client->HandleEnchantItem(WindowID, Enchantment); return PARSE_OK; } -- cgit v1.2.3 From de3df0a71fbde1630775c0daa592d6f2c1ba679f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 6 Apr 2014 22:15:49 +0200 Subject: Fixed crash in protocols sending 64-bit ints. Fixes #855. --- src/Protocol/Protocol.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index ae06f2f9e..939170f0e 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -177,7 +177,7 @@ protected: void WriteInt64 (Int64 a_Value) { UInt64 Value = HostToNetwork8(&a_Value); - SendData((const char *)Value, 8); + SendData((const char *)&Value, 8); } void WriteFloat (float a_Value) -- cgit v1.2.3 From 95fb90eaa642b76915a117495b472d7f7e141cde Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 6 Apr 2014 22:28:41 +0200 Subject: Fixed 1.6.4 client crash on composite chat messages. --- src/Protocol/Protocol16x.cpp | 13 +++++++++++++ src/Protocol/Protocol16x.h | 1 + 2 files changed, 14 insertions(+) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol16x.cpp b/src/Protocol/Protocol16x.cpp index bf7d9a0b1..3da23a1dc 100644 --- a/src/Protocol/Protocol16x.cpp +++ b/src/Protocol/Protocol16x.cpp @@ -18,6 +18,7 @@ Implements the 1.6.x protocol classes: #include "../Entities/Entity.h" #include "../Entities/Player.h" #include "../UI/Window.h" +#include "../CompositeChat.h" @@ -89,6 +90,18 @@ void cProtocol161::SendChat(const AString & a_Message) +void cProtocol161::SendChat(const cCompositeChat & a_Message) +{ + // This protocol version doesn't support composite messages to the full + // Just extract each part's text and use it: + + super::SendChat(Printf("{\"text\":\"%s\"}", EscapeString(a_Message.ExtractText()).c_str())); +} + + + + + void cProtocol161::SendEditSign(int a_BlockX, int a_BlockY, int a_BlockZ) { cCSLock Lock(m_CSPacket); diff --git a/src/Protocol/Protocol16x.h b/src/Protocol/Protocol16x.h index 325e41c5a..ae1388649 100644 --- a/src/Protocol/Protocol16x.h +++ b/src/Protocol/Protocol16x.h @@ -37,6 +37,7 @@ protected: // cProtocol150 overrides: virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) override; virtual void SendChat (const AString & a_Message) override; + virtual void SendChat (const cCompositeChat & a_Message) override; virtual void SendEditSign (int a_BlockX, int a_BlockY, int a_BlockZ) override; ///< Request the client to open up the sign editor for the sign (1.6+) virtual void SendGameMode (eGameMode a_GameMode) override; virtual void SendHealth (void) override; -- cgit v1.2.3 From 1dfd2b1c5fe125757aeb084c163aec5b25a55fc2 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 7 Apr 2014 20:25:30 +0200 Subject: Fixed Errors --- src/Protocol/Protocol125.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 867cf3ef3..26f109918 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1601,8 +1601,8 @@ int cProtocol125::ParseUseEntity(void) int cProtocol125::ParseEnchantItem(void) { - HANDLE_PACKET_READ(ReadByte, byte, WindowID); - HANDLE_PACKET_READ(ReadByte, byte, Enchantment); + HANDLE_PACKET_READ(ReadByte, Byte, WindowID); + HANDLE_PACKET_READ(ReadByte, Byte, Enchantment); LOGWARN("Older Protocol: Enchantment Packet received!"); -- cgit v1.2.3 From b506a7407661c0527255466cf8b315824b0003c0 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sun, 13 Apr 2014 13:04:56 +0200 Subject: Added Yggdrasil Authentication System Code by Howaner. Fixes/Changes by me. --- src/Protocol/Authenticator.cpp | 325 +++++++++++++++++++++++++++++++++++++++++ src/Protocol/Authenticator.h | 93 ++++++++++++ 2 files changed, 418 insertions(+) create mode 100644 src/Protocol/Authenticator.cpp create mode 100644 src/Protocol/Authenticator.h (limited to 'src/Protocol') diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp new file mode 100644 index 000000000..ba435e9ce --- /dev/null +++ b/src/Protocol/Authenticator.cpp @@ -0,0 +1,325 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Authenticator.h" +#include "OSSupport/BlockingTCPLink.h" +#include "Root.h" +#include "Server.h" + +#include "inifile/iniFile.h" +#include "json/json.h" + +#include "polarssl/config.h" +#include "polarssl/net.h" +#include "polarssl/ssl.h" +#include "polarssl/entropy.h" +#include "polarssl/ctr_drbg.h" +#include "polarssl/error.h" +#include "polarssl/certs.h" + +#include +#include + + + + + +#define DEFAULT_AUTH_SERVER "sessionserver.mojang.com" +#define DEFAULT_AUTH_ADDRESS "/session/minecraft/hasJoined?username=%USERNAME%&serverId=%SERVERID%" +#define MAX_REDIRECTS 10 + + + + + +cAuthenticator::cAuthenticator(void) : +super("cAuthenticator"), +m_Server(DEFAULT_AUTH_SERVER), +m_Address(DEFAULT_AUTH_ADDRESS), +m_ShouldAuthenticate(true) +{ +} + + + + + +cAuthenticator::~cAuthenticator() +{ + Stop(); +} + + + + + +void cAuthenticator::ReadINI(cIniFile & IniFile) +{ + m_Server = IniFile.GetValueSet("Authentication", "Server", DEFAULT_AUTH_SERVER); + m_Address = IniFile.GetValueSet("Authentication", "Address", DEFAULT_AUTH_ADDRESS); + m_ShouldAuthenticate = IniFile.GetValueSetB("Authentication", "Authenticate", true); +} + + + + + +void cAuthenticator::Authenticate(int a_ClientID, const AString & a_UserName, const AString & a_ServerHash) +{ + if (!m_ShouldAuthenticate) + { + cRoot::Get()->AuthenticateUser(a_ClientID, a_UserName, Printf("%d", a_ClientID)); + return; + } + + cCSLock LOCK(m_CS); + m_Queue.push_back(cUser(a_ClientID, a_UserName, a_ServerHash)); + m_QueueNonempty.Set(); +} + + + + + +void cAuthenticator::Start(cIniFile & IniFile) +{ + ReadINI(IniFile); + m_ShouldTerminate = false; + super::Start(); +} + + + + + +void cAuthenticator::Stop(void) +{ + m_ShouldTerminate = true; + m_QueueNonempty.Set(); + Wait(); +} + + + + + +void cAuthenticator::Execute(void) +{ + for (;;) + { + cCSLock Lock(m_CS); + while (!m_ShouldTerminate && (m_Queue.size() == 0)) + { + cCSUnlock Unlock(Lock); + m_QueueNonempty.Wait(); + } + if (m_ShouldTerminate) + { + return; + } + ASSERT(!m_Queue.empty()); + + int ClientID = m_Queue.front().m_ClientID; + AString UserName = m_Queue.front().m_Name; + AString ServerID = m_Queue.front().m_ServerID; + m_Queue.pop_front(); + Lock.Unlock(); + + AString NewUserName = UserName; + 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); + } + else + { + cRoot::Get()->KickUser(ClientID, "Failed to authenticate account!"); + } + } // for (-ever) +} + + + + + +bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_ServerId, AString & a_UUID) +{ + AString REQUEST; + int ret, len, server_fd = -1; + unsigned char buf[1024]; + const char *pers = "cAuthenticator"; + + entropy_context entropy; + ctr_drbg_context ctr_drbg; + ssl_context ssl; + x509_crt cacert; + + /* Initialize the RNG and the session data */ + memset(&ssl, 0, sizeof(ssl_context)); + x509_crt_init(&cacert); + + entropy_init(&entropy); + if ((ret = ctr_drbg_init(&ctr_drbg, entropy_func, &entropy, (const unsigned char *)pers, strlen(pers))) != 0) + { + LOGERROR("cAuthenticator: ctr_drbg_init returned %d", ret); + return false; + } + + /* Initialize certificates */ + +#if defined(POLARSSL_CERTS_C) + ret = x509_crt_parse(&cacert, (const unsigned char *)test_ca_list, strlen(test_ca_list)); +#else + ret = 1; + LOGWARNING("cAuthenticator: POLARSSL_CERTS_C is not defined."); +#endif + + if (ret < 0) + { + LOGERROR("cAuthenticator: x509_crt_parse returned -0x%x", -ret); + return false; + } + + /* Connect */ + if ((ret = net_connect(&server_fd, m_Server.c_str(), 443)) != 0) + { + LOGERROR("cAuthenticator: Can't connect to %s: %d", m_Server.c_str(), ret); + return false; + } + + /* Setup */ + if ((ret = ssl_init(&ssl)) != 0) + { + LOGERROR("cAuthenticator: ssl_init returned %d", ret); + return false; + } + ssl_set_endpoint(&ssl, SSL_IS_CLIENT); + ssl_set_authmode(&ssl, SSL_VERIFY_OPTIONAL); + ssl_set_ca_chain(&ssl, &cacert, NULL, "PolarSSL Server 1"); + ssl_set_rng(&ssl, ctr_drbg_random, &ctr_drbg); + ssl_set_bio(&ssl, net_recv, &server_fd, net_send, &server_fd); + + /* Handshake */ + while ((ret = ssl_handshake(&ssl)) != 0) + { + if (ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE) + { + LOGERROR("cAuthenticator: ssl_handshake returned -0x%x", -ret); + return false; + } + } + + /* Write the GET request */ + AString ActualAddress = m_Address; + ReplaceString(ActualAddress, "%USERNAME%", a_UserName); + ReplaceString(ActualAddress, "%SERVERID%", a_ServerId); + + REQUEST += "GET " + ActualAddress + " HTTP/1.1\r\n"; + REQUEST += "Host: " + m_Server + "\r\n"; + REQUEST += "User-Agent: MCServer\r\n"; + REQUEST += "Connection: close\r\n"; + REQUEST += "\r\n"; + + len = sprintf_s((char *)buf, sizeof(buf), REQUEST.c_str()); + + while ((ret = ssl_write(&ssl, buf, len)) <= 0) + { + if (ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE) + { + LOGERROR("cAuthenticator: ssl_write returned %d", ret); + return false; + } + } + + /* Read the HTTP response */ + std::string Builder; + for (;;) + { + len = sizeof(buf)-1; + memset(buf, 0, sizeof(buf)); + ret = ssl_read(&ssl, buf, len); + if (ret > 0) + { + buf[ret] = '\0'; + } + + if (ret == POLARSSL_ERR_NET_WANT_READ || ret == POLARSSL_ERR_NET_WANT_WRITE) + continue; + if (ret == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) + break; + if (ret < 0) + { + LOGERROR("cAuthenticator: ssl_read returned %d", ret); + break; + } + if (ret == 0) + { + LOGERROR("cAuthenticator: EOF"); + break; + } + + std::string str; + str.append(reinterpret_cast(buf)); + Builder += str; + } + + ssl_close_notify(&ssl); + x509_crt_free(&cacert); + net_close(server_fd); + ssl_free(&ssl); + entropy_free(&entropy); + memset(&ssl, 0, sizeof(ssl)); + + std::string prefix("HTTP/1.1 200 OK"); + if (Builder.compare(0, prefix.size(), prefix)) + return false; + + std::stringstream ResponseBuilder; + bool NewLine = false; + bool IsNewLine = false; + for (std::string::const_iterator i = Builder.begin(); i <= Builder.end(); ++i) + { + if (NewLine) + { + ResponseBuilder << *i; + } + else if (!NewLine && *i == '\n') + { + if (IsNewLine) + { + NewLine = true; + } + else + { + IsNewLine = true; + } + } + else if (*i != '\r') + { + IsNewLine = false; + } + } + + AString RESPONSE = ResponseBuilder.str(); + + if (RESPONSE.empty()) + return false; + + Json::Value root; + Json::Reader reader; + if (!reader.parse(RESPONSE, root, false)) + { + LOGWARNING("cAuthenticator: Cannot parse Received Data to json!"); + return false; + } + + a_UserName = root.get("name", "Unknown").asString(); + a_UUID = root.get("id", "").asString(); + return true; +} + + + + + diff --git a/src/Protocol/Authenticator.h b/src/Protocol/Authenticator.h new file mode 100644 index 000000000..211f51394 --- /dev/null +++ b/src/Protocol/Authenticator.h @@ -0,0 +1,93 @@ + +// 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 + +#include "../OSSupport/IsThread.h" + + + + + +// fwd: "cRoot.h" +class cRoot; + + + + + +class cAuthenticator : + public cIsThread +{ + typedef cIsThread super; + +public: + cAuthenticator(void); + ~cAuthenticator(); + + /** (Re-)read server and address from INI: */ + void ReadINI(cIniFile & IniFile); + + /** Queues a request for authenticating a user. If the auth fails, the user will be kicked */ + void Authenticate(int a_ClientID, const AString & a_UserName, const AString & a_ServerHash); + + /** Starts the authenticator thread. The thread may be started and stopped repeatedly */ + void Start(cIniFile & IniFile); + + /** Stops the authenticator thread. The thread may be started and stopped repeatedly */ + void Stop(void); + +private: + + class cUser + { + public: + int m_ClientID; + AString m_Name; + AString m_ServerID; + + cUser(int a_ClientID, const AString & a_Name, const AString & a_ServerID) : + m_ClientID(a_ClientID), + m_Name(a_Name), + m_ServerID(a_ServerID) + { + } + }; + + typedef std::deque cUserList; + + cCriticalSection m_CS; + cUserList m_Queue; + cEvent m_QueueNonempty; + + AString m_Server; + AString m_Address; + bool m_ShouldAuthenticate; + + /** cIsThread override: */ + virtual void Execute(void) override; + + /** 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); +}; + + + + + +#endif // CAUTHENTICATOR_H_INCLUDED + + + + -- cgit v1.2.3 From 3733ee2c0ee84c054bb98d714dad49d0384208a0 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sun, 13 Apr 2014 15:32:15 +0200 Subject: Code Update --- src/Protocol/Authenticator.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp index ba435e9ce..24695b726 100644 --- a/src/Protocol/Authenticator.cpp +++ b/src/Protocol/Authenticator.cpp @@ -26,7 +26,6 @@ #define DEFAULT_AUTH_SERVER "sessionserver.mojang.com" #define DEFAULT_AUTH_ADDRESS "/session/minecraft/hasJoined?username=%USERNAME%&serverId=%SERVERID%" -#define MAX_REDIRECTS 10 @@ -146,8 +145,9 @@ void cAuthenticator::Execute(void) bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_ServerId, AString & a_UUID) { AString REQUEST; - int ret, len, server_fd = -1; - unsigned char buf[1024]; + int ret, server_fd = -1; + size_t len = -1; + unsigned char * buf; const char *pers = "cAuthenticator"; entropy_context entropy; @@ -221,7 +221,8 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S REQUEST += "Connection: close\r\n"; REQUEST += "\r\n"; - len = sprintf_s((char *)buf, sizeof(buf), REQUEST.c_str()); + len = REQUEST.size(); + buf = (unsigned char *)REQUEST.c_str(); while ((ret = ssl_write(&ssl, buf, len)) <= 0) { -- cgit v1.2.3 From d258be678a7ea2d027434c2acc51243dd2253beb Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sun, 13 Apr 2014 16:15:57 +0200 Subject: Fixed Error? --- src/Protocol/Authenticator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp index 24695b726..a79f0b7e0 100644 --- a/src/Protocol/Authenticator.cpp +++ b/src/Protocol/Authenticator.cpp @@ -147,7 +147,7 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S AString REQUEST; int ret, server_fd = -1; size_t len = -1; - unsigned char * buf; + unsigned char buf[1024]; const char *pers = "cAuthenticator"; entropy_context entropy; @@ -222,7 +222,7 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S REQUEST += "\r\n"; len = REQUEST.size(); - buf = (unsigned char *)REQUEST.c_str(); + strcpy((char *)buf, REQUEST.c_str()); while ((ret = ssl_write(&ssl, buf, len)) <= 0) { -- cgit v1.2.3 From 2618569e0100fdfdbf07f98da8f3e0f83e82b822 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sun, 13 Apr 2014 17:09:18 +0200 Subject: Fixed mistake --- src/Protocol/Authenticator.cpp | 2 +- src/Protocol/Protocol17x.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp index a79f0b7e0..8943b3c21 100644 --- a/src/Protocol/Authenticator.cpp +++ b/src/Protocol/Authenticator.cpp @@ -146,7 +146,7 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S { AString REQUEST; int ret, server_fd = -1; - size_t len = -1; + size_t len = 0; unsigned char buf[1024]; const char *pers = "cAuthenticator"; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index a4319df37..6c1af61fa 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1559,7 +1559,7 @@ void cProtocol172::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffe // Send login success: { cPacketizer Pkt(*this, 0x02); // Login success packet - Pkt.WriteString(Printf("%d", m_Client->GetUniqueID())); // TODO: proper UUID + Pkt.WriteString(m_Client->GetUUID()); Pkt.WriteString(m_Client->GetUsername()); } -- cgit v1.2.3 From 856e900bf8e74cb478904d6322dcb6310ff7a3b2 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 14 Apr 2014 11:48:12 +0200 Subject: Bug fixes --- src/Protocol/Protocol17x.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 785dbf935..a31643ccf 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1918,10 +1918,7 @@ void cProtocol172::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadByte, Byte, WindowID); HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Enchantment); - LOGWARN("Protocol 1.7: Enchantment Packet received!"); - m_Client->HandleEnchantItem(WindowID, Enchantment); - } -- cgit v1.2.3 From 0f55dcf036381f951fb22219158182729453f841 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 14 Apr 2014 18:52:21 +0200 Subject: Initial 1.7.6 protocol support. Doesn't work yet because of missing UUIDs. --- src/Protocol/Protocol17x.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/Protocol/Protocol17x.h | 17 +++++++++++++++++ src/Protocol/ProtocolRecognizer.cpp | 13 +++++++++++++ src/Protocol/ProtocolRecognizer.h | 5 +++-- 4 files changed, 69 insertions(+), 2 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index a4319df37..57cc9118f 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -2755,3 +2755,39 @@ void cProtocol172::cPacketizer::WriteEntityProperties(const cEntity & a_Entity) + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cProtocol176: + +cProtocol176::cProtocol176(cClientHandle * a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) : + super(a_Client, a_ServerAddress, a_ServerPort, a_State) +{ +} + + + + + +void cProtocol176::SendPlayerSpawn(const cPlayer & a_Player) +{ + // Called to spawn another player for the client + cPacketizer Pkt(*this, 0x0c); // Spawn Player packet + Pkt.WriteVarInt(a_Player.GetUniqueID()); + Pkt.WriteString(Printf("00000000-0000-3000-8000-aaaa%08x", a_Player.GetUniqueID())); // TODO: Proper UUID + Pkt.WriteString(a_Player.GetName()); + Pkt.WriteVarInt(0); // We have no data to send here + Pkt.WriteFPInt(a_Player.GetPosX()); + Pkt.WriteFPInt(a_Player.GetPosY()); + Pkt.WriteFPInt(a_Player.GetPosZ()); + Pkt.WriteByteAngle(a_Player.GetYaw()); + Pkt.WriteByteAngle(a_Player.GetPitch()); + short ItemType = a_Player.GetEquippedItem().IsEmpty() ? 0 : a_Player.GetEquippedItem().m_ItemType; + Pkt.WriteShort(ItemType); + Pkt.WriteByte((3 << 5) | 6); // Metadata: float + index 6 + Pkt.WriteFloat((float)a_Player.GetHealth()); + Pkt.WriteByte(0x7f); // Metadata: end +} + + + + diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 91186b270..7d0196a21 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -306,3 +306,20 @@ protected: + +/** The version 5 lengthed protocol, used by 1.7.6 through 1.7.9. */ +class cProtocol176 : + public cProtocol172 +{ + typedef cProtocol172 super; + +public: + cProtocol176(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State); + + // cProtocol172 overrides: + virtual void SendPlayerSpawn(const cPlayer & a_Player) override; +} ; + + + + diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index 3f7d7b254..6a1f2fbbd 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -59,6 +59,7 @@ AString cProtocolRecognizer::GetVersionTextFromInt(int a_ProtocolVersion) case PROTO_VERSION_1_6_3: return "1.6.3"; case PROTO_VERSION_1_6_4: return "1.6.4"; case PROTO_VERSION_1_7_2: return "1.7.2"; + case PROTO_VERSION_1_7_6: return "1.7.6"; } ASSERT(!"Unknown protocol version"); return Printf("Unknown protocol (%d)", a_ProtocolVersion); @@ -965,6 +966,18 @@ bool cProtocolRecognizer::TryRecognizeLengthedProtocol(UInt32 a_PacketLengthRema m_Protocol = new cProtocol172(m_Client, ServerAddress, (UInt16)ServerPort, NextState); return true; } + case PROTO_VERSION_1_7_6: + { + AString ServerAddress; + short ServerPort; + UInt32 NextState; + m_Buffer.ReadVarUTF8String(ServerAddress); + m_Buffer.ReadBEShort(ServerPort); + m_Buffer.ReadVarInt(NextState); + m_Buffer.CommitRead(); + m_Protocol = new cProtocol176(m_Client, ServerAddress, (UInt16)ServerPort, NextState); + return true; + } } LOGINFO("Client \"%s\" uses an unsupported protocol (lengthed, version %u)", m_Client->GetIPString().c_str(), ProtocolVersion diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index 072d7c2d2..e53fc9514 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -18,8 +18,8 @@ // Adjust these if a new protocol is added or an old one is removed: -#define MCS_CLIENT_VERSIONS "1.2.4, 1.2.5, 1.3.1, 1.3.2, 1.4.2, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.5, 1.5.1, 1.5.2, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.7.2, 1.7.4" -#define MCS_PROTOCOL_VERSIONS "29, 39, 47, 49, 51, 60, 61, 73, 74, 77, 78, 4" +#define MCS_CLIENT_VERSIONS "1.2.4, 1.2.5, 1.3.1, 1.3.2, 1.4.2, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.5, 1.5.1, 1.5.2, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.7.2, 1.7.4, 1.7.5, 1.7.6, 1.7.7, 1.7.8, 1.7.9" +#define MCS_PROTOCOL_VERSIONS "29, 39, 47, 49, 51, 60, 61, 73, 74, 77, 78, 4, 5" @@ -50,6 +50,7 @@ public: // These will be kept "under" the next / latest, because the next and latest are only needed for previous protocols PROTO_VERSION_1_7_2 = 4, + PROTO_VERSION_1_7_6 = 5, } ; cProtocolRecognizer(cClientHandle * a_Client); -- cgit v1.2.3 From d505ffc704d85cc1b31ae87647ba979fda84f46f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 14 Apr 2014 20:21:00 +0200 Subject: A client UUID is generated when the server is in offline mode. 1.7.9 client works with these changes in offline mode. --- src/Protocol/Protocol17x.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 278b29485..b44c9f919 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -88,8 +88,9 @@ cProtocol172::cProtocol172(cClientHandle * a_Client, const AString & a_ServerAdd // Create the comm log file, if so requested: if (g_ShouldLogCommIn || g_ShouldLogCommOut) { + static int sCounter = 0; cFile::CreateFolder("CommLogs"); - AString FileName = Printf("CommLogs/%x__%s.log", (unsigned)time(NULL), a_Client->GetIPString().c_str()); + AString FileName = Printf("CommLogs/%x_%d__%s.log", (unsigned)time(NULL), sCounter++, a_Client->GetIPString().c_str()); m_CommLogFile.Open(FileName, cFile::fmWrite); } } @@ -796,7 +797,7 @@ void cProtocol172::SendPlayerSpawn(const cPlayer & a_Player) // Called to spawn another player for the client cPacketizer Pkt(*this, 0x0c); // Spawn Player packet Pkt.WriteVarInt(a_Player.GetUniqueID()); - Pkt.WriteString(Printf("%d", a_Player.GetUniqueID())); // TODO: Proper UUID + Pkt.WriteString(a_Player.GetClientHandle()->GetUUID()); Pkt.WriteString(a_Player.GetName()); Pkt.WriteFPInt(a_Player.GetPosX()); Pkt.WriteFPInt(a_Player.GetPosY()); @@ -1556,6 +1557,7 @@ void cProtocol172::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffe StartEncryption(DecryptedKey); + /* // Send login success: { cPacketizer Pkt(*this, 0x02); // Login success packet @@ -1565,6 +1567,7 @@ void cProtocol172::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffe m_State = 3; // State = Game m_Client->HandleLogin(4, m_Client->GetUsername()); + */ } @@ -1596,10 +1599,13 @@ void cProtocol172::HandlePacketLoginStart(cByteBuffer & a_ByteBuffer) return; } + // Generate an offline UUID for the player: + m_Client->GenerateOfflineUUID(); + // Send login success: { cPacketizer Pkt(*this, 0x02); // Login success packet - Pkt.WriteString(Printf("%d", m_Client->GetUniqueID())); // TODO: proper UUID + Pkt.WriteString(m_Client->GetUUID()); Pkt.WriteString(Username); } @@ -2773,7 +2779,7 @@ void cProtocol176::SendPlayerSpawn(const cPlayer & a_Player) // Called to spawn another player for the client cPacketizer Pkt(*this, 0x0c); // Spawn Player packet Pkt.WriteVarInt(a_Player.GetUniqueID()); - Pkt.WriteString(Printf("00000000-0000-3000-8000-aaaa%08x", a_Player.GetUniqueID())); // TODO: Proper UUID + Pkt.WriteString(a_Player.GetClientHandle()->GetUUID()); Pkt.WriteString(a_Player.GetName()); Pkt.WriteVarInt(0); // We have no data to send here Pkt.WriteFPInt(a_Player.GetPosX()); -- cgit v1.2.3 From d12d7b671523f79f760403f3f4c0ef4efb497c79 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 14 Apr 2014 22:52:59 +0200 Subject: Implemented the 1.7.6 protocol and authenticator. Server works both in online and offline modes with 1.7.9. --- src/Protocol/Authenticator.cpp | 147 ++++++++++++++++-------------------- src/Protocol/Protocol.h | 1 + src/Protocol/Protocol125.cpp | 42 +++++++++++ src/Protocol/Protocol125.h | 20 +---- src/Protocol/Protocol17x.cpp | 62 +++++++++------ src/Protocol/Protocol17x.h | 5 +- src/Protocol/ProtocolRecognizer.cpp | 10 +++ src/Protocol/ProtocolRecognizer.h | 1 + 8 files changed, 169 insertions(+), 119 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp index 8943b3c21..a30131b36 100644 --- a/src/Protocol/Authenticator.cpp +++ b/src/Protocol/Authenticator.cpp @@ -2,9 +2,10 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Authenticator.h" -#include "OSSupport/BlockingTCPLink.h" -#include "Root.h" -#include "Server.h" +#include "../OSSupport/BlockingTCPLink.h" +#include "../Root.h" +#include "../Server.h" +#include "../ClientHandle.h" #include "inifile/iniFile.h" #include "json/json.h" @@ -32,10 +33,10 @@ cAuthenticator::cAuthenticator(void) : -super("cAuthenticator"), -m_Server(DEFAULT_AUTH_SERVER), -m_Address(DEFAULT_AUTH_ADDRESS), -m_ShouldAuthenticate(true) + super("cAuthenticator"), + m_Server(DEFAULT_AUTH_SERVER), + m_Address(DEFAULT_AUTH_ADDRESS), + m_ShouldAuthenticate(true) { } @@ -67,7 +68,7 @@ void cAuthenticator::Authenticate(int a_ClientID, const AString & a_UserName, co { if (!m_ShouldAuthenticate) { - cRoot::Get()->AuthenticateUser(a_ClientID, a_UserName, Printf("%d", a_ClientID)); + cRoot::Get()->AuthenticateUser(a_ClientID, a_UserName, cClientHandle::GenerateOfflineUUID(a_UserName)); return; } @@ -144,9 +145,9 @@ void cAuthenticator::Execute(void) bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_ServerId, AString & a_UUID) { - AString REQUEST; + LOGD("Trying to auth user %s", a_UserName.c_str()); + int ret, server_fd = -1; - size_t len = 0; unsigned char buf[1024]; const char *pers = "cAuthenticator"; @@ -162,36 +163,31 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S entropy_init(&entropy); if ((ret = ctr_drbg_init(&ctr_drbg, entropy_func, &entropy, (const unsigned char *)pers, strlen(pers))) != 0) { - LOGERROR("cAuthenticator: ctr_drbg_init returned %d", ret); + LOGWARNING("cAuthenticator: ctr_drbg_init returned %d", ret); return false; } /* Initialize certificates */ - -#if defined(POLARSSL_CERTS_C) + // TODO: Grab the sessionserver's root CA and any intermediates and hard-code them here, instead of test_ca_list ret = x509_crt_parse(&cacert, (const unsigned char *)test_ca_list, strlen(test_ca_list)); -#else - ret = 1; - LOGWARNING("cAuthenticator: POLARSSL_CERTS_C is not defined."); -#endif if (ret < 0) { - LOGERROR("cAuthenticator: x509_crt_parse returned -0x%x", -ret); + LOGWARNING("cAuthenticator: x509_crt_parse returned -0x%x", -ret); return false; } /* Connect */ if ((ret = net_connect(&server_fd, m_Server.c_str(), 443)) != 0) { - LOGERROR("cAuthenticator: Can't connect to %s: %d", m_Server.c_str(), ret); + LOGWARNING("cAuthenticator: Can't connect to %s: %d", m_Server.c_str(), ret); return false; } /* Setup */ if ((ret = ssl_init(&ssl)) != 0) { - LOGERROR("cAuthenticator: ssl_init returned %d", ret); + LOGWARNING("cAuthenticator: ssl_init returned %d", ret); return false; } ssl_set_endpoint(&ssl, SSL_IS_CLIENT); @@ -203,9 +199,9 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S /* Handshake */ while ((ret = ssl_handshake(&ssl)) != 0) { - if (ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE) + if ((ret != POLARSSL_ERR_NET_WANT_READ) && (ret != POLARSSL_ERR_NET_WANT_WRITE)) { - LOGERROR("cAuthenticator: ssl_handshake returned -0x%x", -ret); + LOGWARNING("cAuthenticator: ssl_handshake returned -0x%x", -ret); return false; } } @@ -215,54 +211,47 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S ReplaceString(ActualAddress, "%USERNAME%", a_UserName); ReplaceString(ActualAddress, "%SERVERID%", a_ServerId); - REQUEST += "GET " + ActualAddress + " HTTP/1.1\r\n"; - REQUEST += "Host: " + m_Server + "\r\n"; - REQUEST += "User-Agent: MCServer\r\n"; - REQUEST += "Connection: close\r\n"; - REQUEST += "\r\n"; - - len = REQUEST.size(); - strcpy((char *)buf, REQUEST.c_str()); + AString Request; + Request += "GET " + ActualAddress + " HTTP/1.1\r\n"; + Request += "Host: " + m_Server + "\r\n"; + Request += "User-Agent: MCServer\r\n"; + Request += "Connection: close\r\n"; + Request += "\r\n"; - while ((ret = ssl_write(&ssl, buf, len)) <= 0) + ret = ssl_write(&ssl, (const unsigned char *)Request.c_str(), Request.size()); + if (ret <= 0) { - if (ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE) - { - LOGERROR("cAuthenticator: ssl_write returned %d", ret); - return false; - } + LOGWARNING("cAuthenticator: ssl_write returned %d", ret); + return false; } /* Read the HTTP response */ - std::string Builder; + std::string Response; for (;;) { - len = sizeof(buf)-1; memset(buf, 0, sizeof(buf)); - ret = ssl_read(&ssl, buf, len); - if (ret > 0) - { - buf[ret] = '\0'; - } + ret = ssl_read(&ssl, buf, sizeof(buf)); - if (ret == POLARSSL_ERR_NET_WANT_READ || ret == POLARSSL_ERR_NET_WANT_WRITE) + if ((ret == POLARSSL_ERR_NET_WANT_READ) || (ret == POLARSSL_ERR_NET_WANT_WRITE)) + { continue; + } if (ret == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) + { break; + } if (ret < 0) { - LOGERROR("cAuthenticator: ssl_read returned %d", ret); + LOGWARNING("cAuthenticator: ssl_read returned %d", ret); break; } if (ret == 0) { - LOGERROR("cAuthenticator: EOF"); + LOGWARNING("cAuthenticator: EOF"); break; } - std::string str; - str.append(reinterpret_cast(buf)); - Builder += str; + Response.append((const char *)buf, ret); } ssl_close_notify(&ssl); @@ -272,51 +261,49 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S entropy_free(&entropy); memset(&ssl, 0, sizeof(ssl)); - std::string prefix("HTTP/1.1 200 OK"); - if (Builder.compare(0, prefix.size(), prefix)) + // Check the HTTP status line: + AString prefix("HTTP/1.1 200 OK"); + AString HexDump; + 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()); return false; + } - std::stringstream ResponseBuilder; - bool NewLine = false; - bool IsNewLine = false; - for (std::string::const_iterator i = Builder.begin(); i <= Builder.end(); ++i) + // Erase the HTTP headers from the response: + size_t idxHeadersEnd = Response.find("\r\n\r\n"); + if (idxHeadersEnd == AString::npos) { - if (NewLine) - { - ResponseBuilder << *i; - } - else if (!NewLine && *i == '\n') - { - if (IsNewLine) - { - NewLine = true; - } - else - { - IsNewLine = true; - } - } - else if (*i != '\r') - { - IsNewLine = false; - } + 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()); + return false; } + Response.erase(0, idxHeadersEnd + 4); - AString RESPONSE = ResponseBuilder.str(); - - if (RESPONSE.empty()) + // Parse the Json response: + if (Response.empty()) + { return false; - + } Json::Value root; Json::Reader reader; - if (!reader.parse(RESPONSE, root, false)) + if (!reader.parse(Response, root, false)) { LOGWARNING("cAuthenticator: Cannot parse Received Data 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; } diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index 939170f0e..2fbeef0fa 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -83,6 +83,7 @@ public: virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) = 0; virtual void SendKeepAlive (int a_PingID) = 0; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) = 0; + virtual void SendLoginSuccess (void) = 0; virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) = 0; virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators) = 0; virtual void SendMapInfo (int a_ID, unsigned int a_Scale) = 0; diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index bf946ef19..af1b1c604 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -594,6 +594,15 @@ void cProtocol125::SendLogin(const cPlayer & a_Player, const cWorld & a_World) +void cProtocol125::SendLoginSuccess(void) +{ + // Not supported in this protocol version +} + + + + + void cProtocol125::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) { cCSLock Lock(m_CSPacket); @@ -642,6 +651,17 @@ void cProtocol125::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decor +void cProtocol125::SendMapInfo(int a_ID, unsigned int a_Scale) +{ + // This protocol doesn't support such message + UNUSED(a_ID); + UNUSED(a_Scale); +} + + + + + void cProtocol125::SendPickupSpawn(const cPickup & a_Pickup) { cCSLock Lock(m_CSPacket); @@ -683,6 +703,16 @@ void cProtocol125::SendParticleEffect(const AString & a_ParticleName, float a_Sr +void cProtocol125::SendPaintingSpawn(const cPainting & a_Painting) +{ + // Not implemented in this protocol version + UNUSED(a_Painting); +} + + + + + void cProtocol125::SendPlayerListItem(const cPlayer & a_Player, bool a_IsOnline) { cCSLock Lock(m_CSPacket); @@ -842,6 +872,18 @@ void cProtocol125::SendExperienceOrb(const cExpOrb & a_ExpOrb) +void cProtocol125::SendScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) +{ + // This protocol version doesn't support such message + UNUSED(a_Name); + UNUSED(a_DisplayName); + UNUSED(a_Mode); +} + + + + + void cProtocol125::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) { // Not needed in this protocol version diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h index 08d3ebbe9..16f31bd0e 100644 --- a/src/Protocol/Protocol125.h +++ b/src/Protocol/Protocol125.h @@ -56,19 +56,12 @@ public: virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; + virtual void SendLoginSuccess (void) override; virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) override; virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators) override; - virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override - { - // This protocol doesn't support such message - UNUSED(a_ID); - UNUSED(a_Scale); - } + virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override; virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) override; - virtual void SendPaintingSpawn (const cPainting & a_Painting) override - { - UNUSED(a_Painting); - }; + virtual void SendPaintingSpawn (const cPainting & a_Painting) override; virtual void SendPickupSpawn (const cPickup & a_Pickup) override; virtual void SendPlayerAbilities (void) override {} // This protocol doesn't support such message virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override; @@ -82,12 +75,7 @@ public: virtual void SendRespawn (void) override; virtual void SendExperience (void) override; virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override; - virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override - { - UNUSED(a_Name); - UNUSED(a_DisplayName); - UNUSED(a_Mode); - } // This protocol doesn't support such message + virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override; virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override {} // This protocol doesn't support such message virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override {} // This protocol doesn't support such message virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; // a_Src coords are Block * 8 diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index b44c9f919..c8105c03a 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -574,6 +574,21 @@ void cProtocol172::SendLogin(const cPlayer & a_Player, const cWorld & a_World) +void cProtocol172::SendLoginSuccess(void) +{ + ASSERT(m_State == 2); // State: login? + + cPacketizer Pkt(*this, 0x02); // Login success packet + Pkt.WriteString(m_Client->GetUUID()); + Pkt.WriteString(m_Client->GetUsername()); + + m_State = 3; // State = Game +} + + + + + void cProtocol172::SendPaintingSpawn(const cPainting & a_Painting) { cPacketizer Pkt(*this, 0x10); // Spawn Painting packet @@ -1556,18 +1571,7 @@ void cProtocol172::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffe } StartEncryption(DecryptedKey); - - /* - // Send login success: - { - cPacketizer Pkt(*this, 0x02); // Login success packet - Pkt.WriteString(m_Client->GetUUID()); - Pkt.WriteString(m_Client->GetUsername()); - } - - m_State = 3; // State = Game m_Client->HandleLogin(4, m_Client->GetUsername()); - */ } @@ -1599,17 +1603,6 @@ void cProtocol172::HandlePacketLoginStart(cByteBuffer & a_ByteBuffer) return; } - // Generate an offline UUID for the player: - m_Client->GenerateOfflineUUID(); - - // Send login success: - { - cPacketizer Pkt(*this, 0x02); // Login success packet - Pkt.WriteString(m_Client->GetUUID()); - Pkt.WriteString(Username); - } - - m_State = 3; // State = Game m_Client->HandleLogin(4, Username); } @@ -2797,3 +2790,28 @@ void cProtocol176::SendPlayerSpawn(const cPlayer & a_Player) + +void cProtocol176::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) +{ + // Send the response: + AString Response = "{\"version\":{\"name\":\"1.7.6\",\"protocol\":5},\"players\":{"; + AppendPrintf(Response, "\"max\":%u,\"online\":%u,\"sample\":[]},", + cRoot::Get()->GetServer()->GetMaxPlayers(), + cRoot::Get()->GetServer()->GetNumPlayers() + ); + AppendPrintf(Response, "\"description\":{\"text\":\"%s\"},", + cRoot::Get()->GetServer()->GetDescription().c_str() + ); + AppendPrintf(Response, "\"favicon\":\"data:image/png;base64,%s\"", + cRoot::Get()->GetServer()->GetFaviconData().c_str() + ); + Response.append("}"); + + cPacketizer Pkt(*this, 0x00); // Response packet + Pkt.WriteString(Response); +} + + + + + diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 7d0196a21..5cafc4722 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -87,6 +87,7 @@ public: virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; + virtual void SendLoginSuccess (void) override; virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) override; virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators) override; virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override; @@ -252,7 +253,7 @@ protected: // Packet handlers while in the Status state (m_State == 1): void HandlePacketStatusPing (cByteBuffer & a_ByteBuffer); - void HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer); + virtual void HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer); // Packet handlers while in the Login state (m_State == 2): void HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffer); @@ -318,6 +319,8 @@ public: // cProtocol172 overrides: virtual void SendPlayerSpawn(const cPlayer & a_Player) override; + virtual void HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) override; + } ; diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index 6a1f2fbbd..8a97b9713 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -397,6 +397,16 @@ void cProtocolRecognizer::SendLogin(const cPlayer & a_Player, const cWorld & a_W +void cProtocolRecognizer::SendLoginSuccess(void) +{ + ASSERT(m_Protocol != NULL); + m_Protocol->SendLoginSuccess(); +} + + + + + void cProtocolRecognizer::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) { ASSERT(m_Protocol != NULL); diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index e53fc9514..408109ef4 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -91,6 +91,7 @@ public: virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; + virtual void SendLoginSuccess (void) override; virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) override; virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators) override; virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override; -- cgit v1.2.3 From 99e4225269776d4e79b7d0d14dc8bbe11a2ad32d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 15 Apr 2014 23:40:06 +0200 Subject: Attempted fix for the client crash with the new protocols. --- src/Protocol/Protocol17x.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index c8105c03a..aae87f994 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -538,6 +538,13 @@ void cProtocol172::SendInventorySlot(char a_WindowID, short a_SlotNum, const cIt void cProtocol172::SendKeepAlive(int a_PingID) { + // Drop the packet if the protocol is not in the Game state yet (caused a client crash): + if (m_State != 3) + { + LOGWARNING("Trying to send a KeepAlive packet to a player who's not yet fully logged in (%d). The protocol class prevented the packet.", m_State); + return; + } + cPacketizer Pkt(*this, 0x00); // Keep Alive packet Pkt.WriteInt(a_PingID); } -- cgit v1.2.3 From 09866bb382cde2fda6fb3ebcf0c71d49ae6e3429 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 16 Apr 2014 18:10:48 +0200 Subject: Added asserts for proper game state. This is to help hunt #889. --- src/Protocol/Protocol17x.cpp | 136 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 131 insertions(+), 5 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index aae87f994..403046760 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -125,6 +125,8 @@ void cProtocol172::DataReceived(const char * a_Data, size_t a_Size) void cProtocol172::SendAttachEntity(const cEntity & a_Entity, const cEntity * a_Vehicle) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x1b); // Attach Entity packet Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteInt((a_Vehicle != NULL) ? a_Vehicle->GetUniqueID() : 0); @@ -137,6 +139,8 @@ void cProtocol172::SendAttachEntity(const cEntity & a_Entity, const cEntity * a_ void cProtocol172::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x24); // Block Action packet Pkt.WriteInt(a_BlockX); Pkt.WriteShort(a_BlockY); @@ -152,6 +156,8 @@ void cProtocol172::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, cha void cProtocol172::SendBlockBreakAnim(int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x25); // Block Break Animation packet Pkt.WriteVarInt(a_EntityID); Pkt.WriteInt(a_BlockX); @@ -166,6 +172,8 @@ void cProtocol172::SendBlockBreakAnim(int a_EntityID, int a_BlockX, int a_BlockY void cProtocol172::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x23); // Block Change packet Pkt.WriteInt(a_BlockX); Pkt.WriteByte(a_BlockY); @@ -180,6 +188,8 @@ void cProtocol172::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLO void cProtocol172::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x22); // Multi Block Change packet Pkt.WriteInt(a_ChunkX); Pkt.WriteInt(a_ChunkZ); @@ -199,6 +209,8 @@ void cProtocol172::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockV void cProtocol172::SendChat(const AString & a_Message) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x02); // Chat Message packet Pkt.WriteString(Printf("{\"text\":\"%s\"}", EscapeString(a_Message).c_str())); } @@ -209,6 +221,8 @@ void cProtocol172::SendChat(const AString & a_Message) void cProtocol172::SendChat(const cCompositeChat & a_Message) { + ASSERT(m_State == 3); // In game mode? + // Compose the complete Json string to send: Json::Value msg; msg["text"] = ""; // The client crashes without this @@ -281,6 +295,8 @@ void cProtocol172::SendChat(const cCompositeChat & a_Message) void cProtocol172::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) { + ASSERT(m_State == 3); // In game mode? + // Serialize first, before creating the Packetizer (the packetizer locks a CS) // This contains the flags and bitmasks, too const AString & ChunkData = a_Serializer.Serialize(cChunkDataSerializer::RELEASE_1_3_2); @@ -297,6 +313,8 @@ void cProtocol172::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerialize void cProtocol172::SendCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x0d); // Collect Item packet Pkt.WriteInt(a_Pickup.GetUniqueID()); Pkt.WriteInt(a_Player.GetUniqueID()); @@ -308,6 +326,8 @@ void cProtocol172::SendCollectPickup(const cPickup & a_Pickup, const cPlayer & a void cProtocol172::SendDestroyEntity(const cEntity & a_Entity) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x13); // Destroy Entities packet Pkt.WriteByte(1); Pkt.WriteInt(a_Entity.GetUniqueID()); @@ -344,6 +364,8 @@ void cProtocol172::SendDisconnect(const AString & a_Reason) void cProtocol172::SendEditSign(int a_BlockX, int a_BlockY, int a_BlockZ) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x36); // Sign Editor Open packet Pkt.WriteInt(a_BlockX); Pkt.WriteInt(a_BlockY); @@ -356,6 +378,8 @@ void cProtocol172::SendEditSign(int a_BlockX, int a_BlockY, int a_BlockZ) void cProtocol172::SendEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x1D); // Entity Effect packet Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteByte(a_EffectID); @@ -369,6 +393,8 @@ void cProtocol172::SendEntityEffect(const cEntity & a_Entity, int a_EffectID, in void cProtocol172::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x04); // Entity Equipment packet Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteShort(a_SlotNum); @@ -381,6 +407,8 @@ void cProtocol172::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum void cProtocol172::SendEntityHeadLook(const cEntity & a_Entity) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x19); // Entity Head Look packet Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteByteAngle(a_Entity.GetHeadYaw()); @@ -392,6 +420,8 @@ void cProtocol172::SendEntityHeadLook(const cEntity & a_Entity) void cProtocol172::SendEntityLook(const cEntity & a_Entity) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x16); // Entity Look packet Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteByteAngle(a_Entity.GetYaw()); @@ -404,6 +434,8 @@ void cProtocol172::SendEntityLook(const cEntity & a_Entity) void cProtocol172::SendEntityMetadata(const cEntity & a_Entity) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x1c); // Entity Metadata packet Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteEntityMetadata(a_Entity); @@ -416,6 +448,8 @@ void cProtocol172::SendEntityMetadata(const cEntity & a_Entity) void cProtocol172::SendEntityProperties(const cEntity & a_Entity) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x20); // Entity Properties packet Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteEntityProperties(a_Entity); @@ -427,6 +461,8 @@ void cProtocol172::SendEntityProperties(const cEntity & a_Entity) void cProtocol172::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x15); // Entity Relative Move packet Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteByte(a_RelX); @@ -440,6 +476,8 @@ void cProtocol172::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, char void cProtocol172::SendEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x17); // Entity Look And Relative Move packet Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteByte(a_RelX); @@ -455,6 +493,8 @@ void cProtocol172::SendEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, void cProtocol172::SendEntityStatus(const cEntity & a_Entity, char a_Status) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x1a); // Entity Status packet Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteChar(a_Status); @@ -466,6 +506,8 @@ void cProtocol172::SendEntityStatus(const cEntity & a_Entity, char a_Status) void cProtocol172::SendEntityVelocity(const cEntity & a_Entity) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x12); // Entity Velocity packet Pkt.WriteInt(a_Entity.GetUniqueID()); // 400 = 8000 / 20 ... Conversion from our speed in m/s to 8000 m/tick @@ -480,6 +522,8 @@ void cProtocol172::SendEntityVelocity(const cEntity & a_Entity) void cProtocol172::SendExplosion(double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x27); // Explosion packet Pkt.WriteFloat((float)a_BlockX); Pkt.WriteFloat((float)a_BlockY); @@ -503,6 +547,8 @@ void cProtocol172::SendExplosion(double a_BlockX, double a_BlockY, double a_Bloc void cProtocol172::SendGameMode(eGameMode a_GameMode) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x2b); // Change Game State packet Pkt.WriteByte(3); // Reason: Change game mode Pkt.WriteFloat((float)a_GameMode); @@ -514,6 +560,8 @@ void cProtocol172::SendGameMode(eGameMode a_GameMode) void cProtocol172::SendHealth(void) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x06); // Update Health packet Pkt.WriteFloat((float)m_Client->GetPlayer()->GetHealth()); Pkt.WriteShort(m_Client->GetPlayer()->GetFoodLevel()); @@ -526,6 +574,8 @@ void cProtocol172::SendHealth(void) void cProtocol172::SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem & a_Item) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x2f); // Set Slot packet Pkt.WriteChar(a_WindowID); Pkt.WriteShort(a_SlotNum); @@ -598,6 +648,8 @@ void cProtocol172::SendLoginSuccess(void) void cProtocol172::SendPaintingSpawn(const cPainting & a_Painting) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x10); // Spawn Painting packet Pkt.WriteVarInt(a_Painting.GetUniqueID()); Pkt.WriteString(a_Painting.GetName().c_str()); @@ -613,6 +665,8 @@ void cProtocol172::SendPaintingSpawn(const cPainting & a_Painting) void cProtocol172::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x34); Pkt.WriteVarInt(a_ID); Pkt.WriteShort (3 + a_Length); @@ -633,6 +687,8 @@ void cProtocol172::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colo void cProtocol172::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x34); Pkt.WriteVarInt(a_ID); Pkt.WriteShort (1 + (3 * a_Decorators.size())); @@ -653,6 +709,8 @@ void cProtocol172::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decor void cProtocol172::SendMapInfo(int a_ID, unsigned int a_Scale) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x34); Pkt.WriteVarInt(a_ID); Pkt.WriteShort (2); @@ -668,6 +726,8 @@ void cProtocol172::SendMapInfo(int a_ID, unsigned int a_Scale) void cProtocol172::SendPickupSpawn(const cPickup & a_Pickup) { + ASSERT(m_State == 3); // In game mode? + { cPacketizer Pkt(*this, 0x0e); // Spawn Object packet Pkt.WriteVarInt(a_Pickup.GetUniqueID()); @@ -694,6 +754,8 @@ void cProtocol172::SendPickupSpawn(const cPickup & a_Pickup) void cProtocol172::SendPlayerAbilities(void) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x39); // Player Abilities packet Byte Flags = 0; if (m_Client->GetPlayer()->IsGameModeCreative()) @@ -720,6 +782,8 @@ void cProtocol172::SendPlayerAbilities(void) void cProtocol172::SendEntityAnimation(const cEntity & a_Entity, char a_Animation) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x0b); // Animation packet Pkt.WriteVarInt(a_Entity.GetUniqueID()); Pkt.WriteChar(a_Animation); @@ -731,6 +795,8 @@ void cProtocol172::SendEntityAnimation(const cEntity & a_Entity, char a_Animatio void cProtocol172::SendParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x2A); Pkt.WriteString(a_ParticleName); Pkt.WriteFloat(a_SrcX); @@ -749,6 +815,8 @@ void cProtocol172::SendParticleEffect(const AString & a_ParticleName, float a_Sr void cProtocol172::SendPlayerListItem(const cPlayer & a_Player, bool a_IsOnline) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x38); // Playerlist Item packet Pkt.WriteString(a_Player.GetName()); Pkt.WriteBool(a_IsOnline); @@ -761,6 +829,8 @@ void cProtocol172::SendPlayerListItem(const cPlayer & a_Player, bool a_IsOnline) void cProtocol172::SendPlayerMaxSpeed(void) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x20); // Entity Properties Pkt.WriteInt(m_Client->GetPlayer()->GetUniqueID()); Pkt.WriteInt(1); // Count @@ -787,6 +857,8 @@ void cProtocol172::SendPlayerMaxSpeed(void) void cProtocol172::SendPlayerMoveLook(void) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x08); // Player Position And Look packet Pkt.WriteDouble(m_Client->GetPlayer()->GetPosX()); @@ -816,6 +888,8 @@ void cProtocol172::SendPlayerPosition(void) void cProtocol172::SendPlayerSpawn(const cPlayer & a_Player) { + ASSERT(m_State == 3); // In game mode? + // Called to spawn another player for the client cPacketizer Pkt(*this, 0x0c); // Spawn Player packet Pkt.WriteVarInt(a_Player.GetUniqueID()); @@ -839,6 +913,8 @@ void cProtocol172::SendPlayerSpawn(const cPlayer & a_Player) void cProtocol172::SendPluginMessage(const AString & a_Channel, const AString & a_Message) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x3f); Pkt.WriteString(a_Channel); Pkt.WriteShort((short)a_Message.size()); @@ -851,7 +927,9 @@ void cProtocol172::SendPluginMessage(const AString & a_Channel, const AString & void cProtocol172::SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID) { - cPacketizer Pkt(*this, 0x1E); + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x1e); Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteByte(a_EffectID); } @@ -875,7 +953,9 @@ void cProtocol172::SendRespawn(void) void cProtocol172::SendExperience (void) { - cPacketizer Pkt(*this, 0x1F); //Experience Packet + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x1f); // Experience Packet Pkt.WriteFloat(m_Client->GetPlayer()->GetXpPercentage()); Pkt.WriteShort(m_Client->GetPlayer()->GetXpLevel()); Pkt.WriteShort(m_Client->GetPlayer()->GetCurrentXp()); @@ -887,6 +967,8 @@ void cProtocol172::SendExperience (void) void cProtocol172::SendExperienceOrb(const cExpOrb & a_ExpOrb) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x11); Pkt.WriteVarInt(a_ExpOrb.GetUniqueID()); Pkt.WriteInt((int) a_ExpOrb.GetPosX()); @@ -901,7 +983,9 @@ void cProtocol172::SendExperienceOrb(const cExpOrb & a_ExpOrb) void cProtocol172::SendScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) { - cPacketizer Pkt(*this, 0x3B); + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x3b); Pkt.WriteString(a_Name); Pkt.WriteString(a_DisplayName); Pkt.WriteByte(a_Mode); @@ -913,7 +997,9 @@ void cProtocol172::SendScoreboardObjective(const AString & a_Name, const AString void cProtocol172::SendScoreUpdate(const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) { - cPacketizer Pkt(*this, 0x3C); + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x3c); Pkt.WriteString(a_Player); Pkt.WriteByte(a_Mode); @@ -930,7 +1016,9 @@ void cProtocol172::SendScoreUpdate(const AString & a_Objective, const AString & void cProtocol172::SendDisplayObjective(const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) { - cPacketizer Pkt(*this, 0x3D); + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x3d); Pkt.WriteByte((int) a_Display); Pkt.WriteString(a_Objective); } @@ -941,6 +1029,8 @@ void cProtocol172::SendDisplayObjective(const AString & a_Objective, cScoreboard void cProtocol172::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) // a_Src coords are Block * 8 { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x29); // Sound Effect packet Pkt.WriteString(a_SoundName); Pkt.WriteInt(a_SrcX); @@ -956,6 +1046,8 @@ void cProtocol172::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int void cProtocol172::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x28); // Effect packet Pkt.WriteInt(a_EffectID); Pkt.WriteInt(a_SrcX); @@ -971,6 +1063,8 @@ void cProtocol172::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_Src void cProtocol172::SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x0e); // Spawn Object packet Pkt.WriteVarInt(a_FallingBlock.GetUniqueID()); Pkt.WriteByte(70); // Falling block @@ -991,6 +1085,8 @@ void cProtocol172::SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock) void cProtocol172::SendSpawnMob(const cMonster & a_Mob) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x0f); // Spawn Mob packet Pkt.WriteVarInt(a_Mob.GetUniqueID()); Pkt.WriteByte((Byte)a_Mob.GetMobType()); @@ -1013,6 +1109,8 @@ void cProtocol172::SendSpawnMob(const cMonster & a_Mob) void cProtocol172::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0xe); // Spawn Object packet Pkt.WriteVarInt(a_Entity.GetUniqueID()); Pkt.WriteByte(a_ObjectType); @@ -1036,6 +1134,8 @@ void cProtocol172::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, void cProtocol172::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0xe); // Spawn Object packet Pkt.WriteVarInt(a_Vehicle.GetUniqueID()); Pkt.WriteByte(a_VehicleType); @@ -1059,6 +1159,8 @@ void cProtocol172::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleTyp void cProtocol172::SendTabCompletionResults(const AStringVector & a_Results) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x3a); // Tab-Complete packet Pkt.WriteVarInt(a_Results.size()); @@ -1074,6 +1176,8 @@ void cProtocol172::SendTabCompletionResults(const AStringVector & a_Results) void cProtocol172::SendTeleportEntity(const cEntity & a_Entity) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x18); Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteFPInt(a_Entity.GetPosX()); @@ -1089,6 +1193,8 @@ void cProtocol172::SendTeleportEntity(const cEntity & a_Entity) void cProtocol172::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x2c); // Spawn Global Entity packet Pkt.WriteVarInt(0); // EntityID = 0, always Pkt.WriteByte(1); // Type = Thunderbolt @@ -1103,6 +1209,8 @@ void cProtocol172::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) void cProtocol172::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x03); Pkt.WriteInt64(a_WorldAge); Pkt.WriteInt64(a_TimeOfDay); @@ -1114,6 +1222,8 @@ void cProtocol172::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay) void cProtocol172::SendUnloadChunk(int a_ChunkX, int a_ChunkZ) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x21); // Chunk Data packet Pkt.WriteInt(a_ChunkX); Pkt.WriteInt(a_ChunkZ); @@ -1128,6 +1238,8 @@ void cProtocol172::SendUnloadChunk(int a_ChunkX, int a_ChunkZ) void cProtocol172::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x35); // Update tile entity packet Pkt.WriteInt(a_BlockEntity.GetPosX()); Pkt.WriteShort(a_BlockEntity.GetPosY()); @@ -1153,6 +1265,8 @@ void cProtocol172::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) void cProtocol172::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x33); Pkt.WriteInt(a_BlockX); Pkt.WriteShort((short)a_BlockY); @@ -1170,6 +1284,8 @@ void cProtocol172::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, cons void cProtocol172::SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x0a); Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteInt(a_BlockX); @@ -1183,6 +1299,8 @@ void cProtocol172::SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_Bloc void cProtocol172::SendWeather(eWeather a_Weather) { + ASSERT(m_State == 3); // In game mode? + { cPacketizer Pkt(*this, 0x2b); // Change Game State packet Pkt.WriteByte((a_Weather == wSunny) ? 1 : 2); // End rain / begin rain @@ -1198,6 +1316,8 @@ void cProtocol172::SendWeather(eWeather a_Weather) void cProtocol172::SendWholeInventory(const cWindow & a_Window) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x30); // Window Items packet Pkt.WriteChar(a_Window.GetWindowID()); Pkt.WriteShort(a_Window.GetNumSlots()); @@ -1215,6 +1335,8 @@ void cProtocol172::SendWholeInventory(const cWindow & a_Window) void cProtocol172::SendWindowClose(const cWindow & a_Window) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x2e); Pkt.WriteChar(a_Window.GetWindowID()); } @@ -1225,6 +1347,8 @@ void cProtocol172::SendWindowClose(const cWindow & a_Window) void cProtocol172::SendWindowOpen(const cWindow & a_Window) { + ASSERT(m_State == 3); // In game mode? + if (a_Window.GetWindowType() < 0) { // Do not send this packet for player inventory windows @@ -1249,6 +1373,8 @@ void cProtocol172::SendWindowOpen(const cWindow & a_Window) void cProtocol172::SendWindowProperty(const cWindow & a_Window, short a_Property, short a_Value) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x31); // Window Property packet Pkt.WriteChar(a_Window.GetWindowID()); Pkt.WriteShort(a_Property); -- cgit v1.2.3 From f9343a8490b50cb28a62c7327c0013da48ca2745 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Thu, 17 Apr 2014 13:15:35 +0200 Subject: Modified many things --- src/Protocol/Protocol125.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 6cf611d90..9b8db0b7b 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1646,8 +1646,6 @@ int cProtocol125::ParseEnchantItem(void) HANDLE_PACKET_READ(ReadByte, Byte, WindowID); HANDLE_PACKET_READ(ReadByte, Byte, Enchantment); - LOGWARN("Older Protocol: Enchantment Packet received!"); - m_Client->HandleEnchantItem(WindowID, Enchantment); return PARSE_OK; -- cgit v1.2.3 From 013da806ec20b62a742aded9a9d2b8131193f30d Mon Sep 17 00:00:00 2001 From: jfhumann Date: Fri, 18 Apr 2014 21:09:44 +0200 Subject: Did some static analysis, fixed some bugs and optimized a lot of code --- src/Protocol/Protocol125.cpp | 32 ++++++++------ src/Protocol/Protocol132.cpp | 18 +++++--- src/Protocol/Protocol14x.cpp | 12 +++--- src/Protocol/Protocol16x.cpp | 17 +++++--- src/Protocol/Protocol17x.cpp | 85 +++++++++++++++++++++---------------- src/Protocol/ProtocolRecognizer.cpp | 13 +++--- 6 files changed, 100 insertions(+), 77 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index bf946ef19..7ae359e10 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -537,9 +537,10 @@ void cProtocol125::SendHealth(void) { cCSLock Lock(m_CSPacket); WriteByte (PACKET_UPDATE_HEALTH); - WriteShort((short)m_Client->GetPlayer()->GetHealth()); - WriteShort((short)m_Client->GetPlayer()->GetFoodLevel()); - WriteFloat((float)m_Client->GetPlayer()->GetFoodSaturationLevel()); + cPlayer * Player = m_Client->GetPlayer(); + WriteShort((short)Player->GetHealth()); + WriteShort((short)Player->GetFoodLevel()); + WriteFloat((float)Player->GetFoodSaturationLevel()); Flush(); } @@ -647,13 +648,14 @@ void cProtocol125::SendPickupSpawn(const cPickup & a_Pickup) cCSLock Lock(m_CSPacket); WriteByte (PACKET_PICKUP_SPAWN); WriteInt (a_Pickup.GetUniqueID()); - WriteShort (a_Pickup.GetItem().m_ItemType); - WriteChar (a_Pickup.GetItem().m_ItemCount); - WriteShort (a_Pickup.GetItem().m_ItemDamage); + const cItem & Item = a_Pickup.GetItem(); + WriteShort (Item.m_ItemType); + WriteChar (Item.m_ItemCount); + WriteShort (Item.m_ItemDamage); WriteVectorI((Vector3i)(a_Pickup.GetPosition() * 32)); - WriteByte ((char)(a_Pickup.GetSpeed().x * 8)); - WriteByte ((char)(a_Pickup.GetSpeed().y * 8)); - WriteByte ((char)(a_Pickup.GetSpeed().z * 8)); + WriteByte ((char)(a_Pickup.GetSpeedX() * 8)); + WriteByte ((char)(a_Pickup.GetSpeedY() * 8)); + WriteByte ((char)(a_Pickup.GetSpeedZ() * 8)); Flush(); } @@ -800,10 +802,11 @@ void cProtocol125::SendRemoveEntityEffect(const cEntity & a_Entity, int a_Effect void cProtocol125::SendRespawn(void) { cCSLock Lock(m_CSPacket); + cPlayer * Player = m_Client->GetPlayer(); WriteByte (PACKET_RESPAWN); - WriteInt ((int)(m_Client->GetPlayer()->GetWorld()->GetDimension())); + WriteInt ((int)(Player->GetWorld()->GetDimension())); WriteByte (2); // TODO: Difficulty; 2 = Normal - WriteChar ((char)m_Client->GetPlayer()->GetGameMode()); + WriteChar ((char)Player->GetGameMode()); WriteShort (256); // Current world height WriteString("default"); } @@ -815,10 +818,11 @@ void cProtocol125::SendRespawn(void) void cProtocol125::SendExperience(void) { cCSLock Lock(m_CSPacket); + cPlayer * Player = m_Client->GetPlayer(); WriteByte (PACKET_EXPERIENCE); - WriteFloat (m_Client->GetPlayer()->GetXpPercentage()); - WriteShort (m_Client->GetPlayer()->GetXpLevel()); - WriteShort (m_Client->GetPlayer()->GetCurrentXp()); + WriteFloat (Player->GetXpPercentage()); + WriteShort (Player->GetXpLevel()); + WriteShort (Player->GetCurrentXp()); Flush(); } diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp index ce5942a5c..1ef92b8f0 100644 --- a/src/Protocol/Protocol132.cpp +++ b/src/Protocol/Protocol132.cpp @@ -408,7 +408,8 @@ void cProtocol132::SendWholeInventory(const cWindow & a_Window) super::SendWholeInventory(a_Window); // Send the player inventory and hotbar: - const cInventory & Inventory = m_Client->GetPlayer()->GetInventory(); + cPlayer * Player = m_Client->GetPlayer(); + const cInventory & Inventory = Player->GetInventory(); int BaseOffset = a_Window.GetNumSlots() - (cInventory::invNumSlots - cInventory::invInventoryOffset); // Number of non-inventory slots char WindowID = a_Window.GetWindowID(); for (short i = 0; i < cInventory::invInventoryCount; i++) @@ -422,7 +423,7 @@ void cProtocol132::SendWholeInventory(const cWindow & a_Window) } // for i - Hotbar[] // Send even the item being dragged: - SendInventorySlot(-1, -1, m_Client->GetPlayer()->GetDraggingItem()); + SendInventorySlot(-1, -1, Player->GetDraggingItem()); } @@ -800,10 +801,12 @@ void cProtocol132::SendCompass(const cWorld & a_World) void cProtocol132::SendEncryptionKeyRequest(void) { cCSLock Lock(m_CSPacket); + cServer * Server = cRoot::Get()->GetServer(); WriteByte(0xfd); - WriteString(cRoot::Get()->GetServer()->GetServerID()); - WriteShort((short)(cRoot::Get()->GetServer()->GetPublicKeyDER().size())); - SendData(cRoot::Get()->GetServer()->GetPublicKeyDER().data(), cRoot::Get()->GetServer()->GetPublicKeyDER().size()); + WriteString(Server->GetServerID()); + const AString & PublicKeyDER = Server->GetPublicKeyDER(); + WriteShort((short) (PublicKeyDER.size())); + SendData(PublicKeyDER.data(), PublicKeyDER.size()); WriteShort(4); WriteInt((int)(intptr_t)this); // Using 'this' as the cryptographic nonce, so that we don't have to generate one each time :) Flush(); @@ -874,10 +877,11 @@ void cProtocol132::StartEncryption(const Byte * a_Key) // Prepare the m_AuthServerID: cSHA1Checksum Checksum; - AString ServerID = cRoot::Get()->GetServer()->GetServerID(); + cServer * Server = cRoot::Get()->GetServer(); + AString ServerID = Server->GetServerID(); Checksum.Update((const Byte *)ServerID.c_str(), ServerID.length()); Checksum.Update(a_Key, 16); - Checksum.Update((const Byte *)cRoot::Get()->GetServer()->GetPublicKeyDER().data(), cRoot::Get()->GetServer()->GetPublicKeyDER().size()); + Checksum.Update((const Byte *) Server->GetPublicKeyDER().data(), Server->GetPublicKeyDER().size()); Byte Digest[20]; Checksum.Finalize(Digest); cSHA1Checksum::DigestToJava(Digest, m_AuthServerID); diff --git a/src/Protocol/Protocol14x.cpp b/src/Protocol/Protocol14x.cpp index f694af1eb..d6a103d35 100644 --- a/src/Protocol/Protocol14x.cpp +++ b/src/Protocol/Protocol14x.cpp @@ -103,9 +103,9 @@ void cProtocol142::SendPickupSpawn(const cPickup & a_Pickup) WriteInt (a_Pickup.GetUniqueID()); WriteItem (a_Pickup.GetItem()); WriteVectorI((Vector3i)(a_Pickup.GetPosition() * 32)); - WriteChar ((char)(a_Pickup.GetSpeed().x * 8)); - WriteChar ((char)(a_Pickup.GetSpeed().y * 8)); - WriteChar ((char)(a_Pickup.GetSpeed().z * 8)); + WriteChar((char) (a_Pickup.GetSpeedX() * 8)); + WriteChar((char) (a_Pickup.GetSpeedY() * 8)); + WriteChar((char) (a_Pickup.GetSpeedZ() * 8)); Flush(); } @@ -170,9 +170,9 @@ void cProtocol146::SendPickupSpawn(const cPickup & a_Pickup) WriteInt ((int)(a_Pickup.GetPosY() * 32)); WriteInt ((int)(a_Pickup.GetPosZ() * 32)); WriteInt (1); - WriteShort((short)(a_Pickup.GetSpeed().x * 32)); - WriteShort((short)(a_Pickup.GetSpeed().y * 32)); - WriteShort((short)(a_Pickup.GetSpeed().z * 32)); + WriteShort((short)(a_Pickup.GetSpeedX() * 32)); + WriteShort((short) (a_Pickup.GetSpeedY() * 32)); + WriteShort((short) (a_Pickup.GetSpeedZ() * 32)); WriteByte(0); WriteByte(0); diff --git a/src/Protocol/Protocol16x.cpp b/src/Protocol/Protocol16x.cpp index 3da23a1dc..35bc8665d 100644 --- a/src/Protocol/Protocol16x.cpp +++ b/src/Protocol/Protocol16x.cpp @@ -131,9 +131,10 @@ void cProtocol161::SendHealth(void) { cCSLock Lock(m_CSPacket); WriteByte (PACKET_UPDATE_HEALTH); - WriteFloat((float)m_Client->GetPlayer()->GetHealth()); - WriteShort((short)m_Client->GetPlayer()->GetFoodLevel()); - WriteFloat((float)m_Client->GetPlayer()->GetFoodSaturationLevel()); + cPlayer * Player = m_Client->GetPlayer(); + WriteFloat((float)Player->GetHealth()); + WriteShort((short)Player->GetFoodLevel()); + WriteFloat((float)Player->GetFoodSaturationLevel()); Flush(); } @@ -144,11 +145,12 @@ void cProtocol161::SendHealth(void) void cProtocol161::SendPlayerMaxSpeed(void) { cCSLock Lock(m_CSPacket); + cPlayer * Player = m_Client->GetPlayer(); WriteByte(PACKET_ENTITY_PROPERTIES); - WriteInt(m_Client->GetPlayer()->GetUniqueID()); + WriteInt(Player->GetUniqueID()); WriteInt(1); WriteString("generic.movementSpeed"); - WriteDouble(0.1 * m_Client->GetPlayer()->GetMaxSpeed()); + WriteDouble(0.1 * Player->GetMaxSpeed()); Flush(); } @@ -276,11 +278,12 @@ cProtocol162::cProtocol162(cClientHandle * a_Client) : void cProtocol162::SendPlayerMaxSpeed(void) { cCSLock Lock(m_CSPacket); + cPlayer * Player = m_Client->GetPlayer(); WriteByte(PACKET_ENTITY_PROPERTIES); - WriteInt(m_Client->GetPlayer()->GetUniqueID()); + WriteInt(Player->GetUniqueID()); WriteInt(1); WriteString("generic.movementSpeed"); - WriteDouble(0.1 * m_Client->GetPlayer()->GetMaxSpeed()); + WriteDouble(0.1 * Player->GetMaxSpeed()); WriteShort(0); Flush(); } diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index a4319df37..135518b67 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -514,9 +514,10 @@ void cProtocol172::SendGameMode(eGameMode a_GameMode) void cProtocol172::SendHealth(void) { cPacketizer Pkt(*this, 0x06); // Update Health packet - Pkt.WriteFloat((float)m_Client->GetPlayer()->GetHealth()); - Pkt.WriteShort(m_Client->GetPlayer()->GetFoodLevel()); - Pkt.WriteFloat((float)m_Client->GetPlayer()->GetFoodSaturationLevel()); + cPlayer * Player = m_Client->GetPlayer(); + Pkt.WriteFloat((float)Player->GetHealth()); + Pkt.WriteShort(Player->GetFoodLevel()); + Pkt.WriteFloat((float)Player->GetFoodSaturationLevel()); } @@ -549,12 +550,13 @@ void cProtocol172::SendLogin(const cPlayer & a_Player, const cWorld & a_World) { // Send the Join Game packet: { + cServer * Server = cRoot::Get()->GetServer(); cPacketizer Pkt(*this, 0x01); // Join Game packet Pkt.WriteInt(a_Player.GetUniqueID()); - Pkt.WriteByte((Byte)a_Player.GetEffectiveGameMode() | (cRoot::Get()->GetServer()->IsHardcore() ? 0x08 : 0)); // Hardcore flag bit 4 + Pkt.WriteByte((Byte)a_Player.GetEffectiveGameMode() | (Server->IsHardcore() ? 0x08 : 0)); // Hardcore flag bit 4 Pkt.WriteChar((char)a_World.GetDimension()); Pkt.WriteByte(2); // TODO: Difficulty (set to Normal) - Pkt.WriteByte(std::min(cRoot::Get()->GetServer()->GetMaxPlayers(), 60)); + Pkt.WriteByte(std::min(Server->GetMaxPlayers(), 60)); Pkt.WriteString("default"); // Level type - wtf? } @@ -673,22 +675,23 @@ void cProtocol172::SendPlayerAbilities(void) { cPacketizer Pkt(*this, 0x39); // Player Abilities packet Byte Flags = 0; - if (m_Client->GetPlayer()->IsGameModeCreative()) + cPlayer * Player = m_Client->GetPlayer(); + if (Player->IsGameModeCreative()) { Flags |= 0x01; Flags |= 0x08; // Godmode, used for creative } - if (m_Client->GetPlayer()->IsFlying()) + if (Player->IsFlying()) { Flags |= 0x02; } - if (m_Client->GetPlayer()->CanFly()) + if (Player->CanFly()) { Flags |= 0x04; } Pkt.WriteByte(Flags); - Pkt.WriteFloat((float)(0.05 * m_Client->GetPlayer()->GetFlyingMaxSpeed())); - Pkt.WriteFloat((float)(0.1 * m_Client->GetPlayer()->GetMaxSpeed())); + Pkt.WriteFloat((float)(0.05 * Player->GetFlyingMaxSpeed())); + Pkt.WriteFloat((float)(0.1 * Player->GetMaxSpeed())); } @@ -739,17 +742,18 @@ void cProtocol172::SendPlayerListItem(const cPlayer & a_Player, bool a_IsOnline) void cProtocol172::SendPlayerMaxSpeed(void) { cPacketizer Pkt(*this, 0x20); // Entity Properties - Pkt.WriteInt(m_Client->GetPlayer()->GetUniqueID()); + cPlayer * Player = m_Client->GetPlayer(); + Pkt.WriteInt(Player->GetUniqueID()); Pkt.WriteInt(1); // Count Pkt.WriteString("generic.movementSpeed"); // The default game speed is 0.1, multiply that value by the relative speed: - Pkt.WriteDouble(0.1 * m_Client->GetPlayer()->GetNormalMaxSpeed()); - if (m_Client->GetPlayer()->IsSprinting()) + Pkt.WriteDouble(0.1 * Player->GetNormalMaxSpeed()); + if (Player->IsSprinting()) { Pkt.WriteShort(1); // Modifier count Pkt.WriteInt64(0x662a6b8dda3e4c1c); Pkt.WriteInt64(0x881396ea6097278d); // UUID of the modifier - Pkt.WriteDouble(m_Client->GetPlayer()->GetSprintingMaxSpeed() - m_Client->GetPlayer()->GetNormalMaxSpeed()); + Pkt.WriteDouble(Player->GetSprintingMaxSpeed() - Player->GetNormalMaxSpeed()); Pkt.WriteByte(2); } else @@ -765,16 +769,17 @@ void cProtocol172::SendPlayerMaxSpeed(void) void cProtocol172::SendPlayerMoveLook(void) { cPacketizer Pkt(*this, 0x08); // Player Position And Look packet - Pkt.WriteDouble(m_Client->GetPlayer()->GetPosX()); + cPlayer * Player = m_Client->GetPlayer(); + Pkt.WriteDouble(Player->GetPosX()); // Protocol docs say this is PosY, but #323 says this is eye-pos // Moreover, the "+ 0.001" is there because otherwise the player falls through the block they were standing on. - Pkt.WriteDouble(m_Client->GetPlayer()->GetStance() + 0.001); + Pkt.WriteDouble(Player->GetStance() + 0.001); - Pkt.WriteDouble(m_Client->GetPlayer()->GetPosZ()); - Pkt.WriteFloat((float)m_Client->GetPlayer()->GetYaw()); - Pkt.WriteFloat((float)m_Client->GetPlayer()->GetPitch()); - Pkt.WriteBool(m_Client->GetPlayer()->IsOnGround()); + Pkt.WriteDouble(Player->GetPosZ()); + Pkt.WriteFloat((float)Player->GetYaw()); + Pkt.WriteFloat((float)Player->GetPitch()); + Pkt.WriteBool(Player->IsOnGround()); } @@ -840,9 +845,10 @@ void cProtocol172::SendRemoveEntityEffect(const cEntity & a_Entity, int a_Effect void cProtocol172::SendRespawn(void) { cPacketizer Pkt(*this, 0x07); // Respawn packet - Pkt.WriteInt(m_Client->GetPlayer()->GetWorld()->GetDimension()); + cPlayer * Player = m_Client->GetPlayer(); + Pkt.WriteInt(Player->GetWorld()->GetDimension()); Pkt.WriteByte(2); // TODO: Difficulty (set to Normal) - Pkt.WriteByte((Byte)m_Client->GetPlayer()->GetEffectiveGameMode()); + Pkt.WriteByte((Byte)Player->GetEffectiveGameMode()); Pkt.WriteString("default"); } @@ -853,9 +859,10 @@ void cProtocol172::SendRespawn(void) void cProtocol172::SendExperience (void) { cPacketizer Pkt(*this, 0x1F); //Experience Packet - Pkt.WriteFloat(m_Client->GetPlayer()->GetXpPercentage()); - Pkt.WriteShort(m_Client->GetPlayer()->GetXpLevel()); - Pkt.WriteShort(m_Client->GetPlayer()->GetCurrentXp()); + cPlayer * Player = m_Client->GetPlayer(); + Pkt.WriteFloat(Player->GetXpPercentage()); + Pkt.WriteShort(Player->GetXpLevel()); + Pkt.WriteShort(Player->GetCurrentXp()); } @@ -1485,15 +1492,16 @@ void cProtocol172::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) { // Send the response: AString Response = "{\"version\":{\"name\":\"1.7.2\",\"protocol\":4},\"players\":{"; + cServer * Server = cRoot::Get()->GetServer(); AppendPrintf(Response, "\"max\":%u,\"online\":%u,\"sample\":[]},", - cRoot::Get()->GetServer()->GetMaxPlayers(), - cRoot::Get()->GetServer()->GetNumPlayers() + Server->GetMaxPlayers(), + Server->GetNumPlayers() ); AppendPrintf(Response, "\"description\":{\"text\":\"%s\"},", - cRoot::Get()->GetServer()->GetDescription().c_str() + Server->GetDescription().c_str() ); AppendPrintf(Response, "\"favicon\":\"data:image/png;base64,%s\"", - cRoot::Get()->GetServer()->GetFaviconData().c_str() + Server->GetFaviconData().c_str() ); Response.append("}"); @@ -1582,12 +1590,13 @@ void cProtocol172::HandlePacketLoginStart(cByteBuffer & a_ByteBuffer) return; } + cServer * Server = cRoot::Get()->GetServer(); // If auth is required, then send the encryption request: - if (cRoot::Get()->GetServer()->ShouldAuthenticate()) + if (Server->ShouldAuthenticate()) { cPacketizer Pkt(*this, 0x01); - Pkt.WriteString(cRoot::Get()->GetServer()->GetServerID()); - const AString & PubKeyDer = cRoot::Get()->GetServer()->GetPublicKeyDER(); + Pkt.WriteString(Server->GetServerID()); + const AString & PubKeyDer = Server->GetPublicKeyDER(); Pkt.WriteShort(PubKeyDer.size()); Pkt.WriteBuf(PubKeyDer.data(), PubKeyDer.size()); Pkt.WriteShort(4); @@ -2136,10 +2145,11 @@ void cProtocol172::StartEncryption(const Byte * a_Key) // Prepare the m_AuthServerID: cSHA1Checksum Checksum; - const AString & ServerID = cRoot::Get()->GetServer()->GetServerID(); + cServer * Server = cRoot::Get()->GetServer(); + const AString & ServerID = Server->GetServerID(); Checksum.Update((const Byte *)ServerID.c_str(), ServerID.length()); Checksum.Update(a_Key, 16); - Checksum.Update((const Byte *)cRoot::Get()->GetServer()->GetPublicKeyDER().data(), cRoot::Get()->GetServer()->GetPublicKeyDER().size()); + Checksum.Update((const Byte *)Server->GetPublicKeyDER().data(), Server->GetPublicKeyDER().size()); Byte Digest[20]; Checksum.Finalize(Digest); cSHA1Checksum::DigestToJava(Digest, m_AuthServerID); @@ -2481,11 +2491,12 @@ void cProtocol172::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity) if (((cMinecart &)a_Entity).GetPayload() == cMinecart::mpNone) { cRideableMinecart & RideableMinecart = ((cRideableMinecart &)a_Entity); - if (!RideableMinecart.GetContent().IsEmpty()) + const cItem & MinecartContent = RideableMinecart.GetContent(); + if (!MinecartContent.IsEmpty()) { WriteByte(0x54); - int Content = RideableMinecart.GetContent().m_ItemType; - Content |= RideableMinecart.GetContent().m_ItemDamage << 8; + int Content = MinecartContent.m_ItemType; + Content |= MinecartContent.m_ItemDamage << 8; WriteInt(Content); WriteByte(0x55); WriteInt(RideableMinecart.GetBlockHeight()); diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index 3f7d7b254..f9a7ba92b 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -980,6 +980,7 @@ bool cProtocolRecognizer::TryRecognizeLengthedProtocol(UInt32 a_PacketLengthRema void cProtocolRecognizer::SendLengthlessServerPing(void) { AString Reply; + cServer * Server = cRoot::Get()->GetServer(); switch (cRoot::Get()->GetPrimaryServerVersion()) { case PROTO_VERSION_1_2_5: @@ -987,11 +988,11 @@ void cProtocolRecognizer::SendLengthlessServerPing(void) { // http://wiki.vg/wiki/index.php?title=Protocol&oldid=3099#Server_List_Ping_.280xFE.29 Printf(Reply, "%s%s%i%s%i", - cRoot::Get()->GetServer()->GetDescription().c_str(), + Server->GetDescription().c_str(), cChatColor::Delimiter.c_str(), - cRoot::Get()->GetServer()->GetNumPlayers(), + Server->GetNumPlayers(), cChatColor::Delimiter.c_str(), - cRoot::Get()->GetServer()->GetMaxPlayers() + Server->GetMaxPlayers() ); break; } @@ -1021,9 +1022,9 @@ void cProtocolRecognizer::SendLengthlessServerPing(void) // http://wiki.vg/wiki/index.php?title=Server_List_Ping&oldid=3100 AString NumPlayers; - Printf(NumPlayers, "%d", cRoot::Get()->GetServer()->GetNumPlayers()); + Printf(NumPlayers, "%d", Server->GetNumPlayers()); AString MaxPlayers; - Printf(MaxPlayers, "%d", cRoot::Get()->GetServer()->GetMaxPlayers()); + Printf(MaxPlayers, "%d", Server->GetMaxPlayers()); AString ProtocolVersionNum; Printf(ProtocolVersionNum, "%d", cRoot::Get()->GetPrimaryServerVersion()); @@ -1037,7 +1038,7 @@ void cProtocolRecognizer::SendLengthlessServerPing(void) Reply.push_back(0); Reply.append(ProtocolVersionTxt); Reply.push_back(0); - Reply.append(cRoot::Get()->GetServer()->GetDescription()); + Reply.append(Server->GetDescription()); Reply.push_back(0); Reply.append(NumPlayers); Reply.push_back(0); -- cgit v1.2.3 From fde1555352727387cefe90c3393ef352475ffa20 Mon Sep 17 00:00:00 2001 From: jfhumann Date: Fri, 18 Apr 2014 22:20:24 +0200 Subject: Small style changes --- src/Protocol/Protocol132.cpp | 4 ++-- src/Protocol/Protocol14x.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp index 1ef92b8f0..53d8c1561 100644 --- a/src/Protocol/Protocol132.cpp +++ b/src/Protocol/Protocol132.cpp @@ -805,7 +805,7 @@ void cProtocol132::SendEncryptionKeyRequest(void) WriteByte(0xfd); WriteString(Server->GetServerID()); const AString & PublicKeyDER = Server->GetPublicKeyDER(); - WriteShort((short) (PublicKeyDER.size())); + WriteShort((short)(PublicKeyDER.size())); SendData(PublicKeyDER.data(), PublicKeyDER.size()); WriteShort(4); WriteInt((int)(intptr_t)this); // Using 'this' as the cryptographic nonce, so that we don't have to generate one each time :) @@ -881,7 +881,7 @@ void cProtocol132::StartEncryption(const Byte * a_Key) AString ServerID = Server->GetServerID(); Checksum.Update((const Byte *)ServerID.c_str(), ServerID.length()); Checksum.Update(a_Key, 16); - Checksum.Update((const Byte *) Server->GetPublicKeyDER().data(), Server->GetPublicKeyDER().size()); + Checksum.Update((const Byte *)Server->GetPublicKeyDER().data(), Server->GetPublicKeyDER().size()); Byte Digest[20]; Checksum.Finalize(Digest); cSHA1Checksum::DigestToJava(Digest, m_AuthServerID); diff --git a/src/Protocol/Protocol14x.cpp b/src/Protocol/Protocol14x.cpp index d6a103d35..f60e756fd 100644 --- a/src/Protocol/Protocol14x.cpp +++ b/src/Protocol/Protocol14x.cpp @@ -103,9 +103,9 @@ void cProtocol142::SendPickupSpawn(const cPickup & a_Pickup) WriteInt (a_Pickup.GetUniqueID()); WriteItem (a_Pickup.GetItem()); WriteVectorI((Vector3i)(a_Pickup.GetPosition() * 32)); - WriteChar((char) (a_Pickup.GetSpeedX() * 8)); - WriteChar((char) (a_Pickup.GetSpeedY() * 8)); - WriteChar((char) (a_Pickup.GetSpeedZ() * 8)); + WriteChar((char)(a_Pickup.GetSpeedX() * 8)); + WriteChar((char)(a_Pickup.GetSpeedY() * 8)); + WriteChar((char)(a_Pickup.GetSpeedZ() * 8)); Flush(); } @@ -171,8 +171,8 @@ void cProtocol146::SendPickupSpawn(const cPickup & a_Pickup) WriteInt ((int)(a_Pickup.GetPosZ() * 32)); WriteInt (1); WriteShort((short)(a_Pickup.GetSpeedX() * 32)); - WriteShort((short) (a_Pickup.GetSpeedY() * 32)); - WriteShort((short) (a_Pickup.GetSpeedZ() * 32)); + WriteShort((short)(a_Pickup.GetSpeedY() * 32)); + WriteShort((short)(a_Pickup.GetSpeedZ() * 32)); WriteByte(0); WriteByte(0); -- cgit v1.2.3 From 9f58046b5b6f5a0814461ad68d7612343dc3c2f5 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Mon, 21 Apr 2014 08:22:25 +0200 Subject: Allow 1.6.4 Forge clients to log in. Fixes #913. --- src/Protocol/Protocol16x.cpp | 19 +++++++++++++++++++ src/Protocol/Protocol16x.h | 1 + 2 files changed, 20 insertions(+) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol16x.cpp b/src/Protocol/Protocol16x.cpp index 3da23a1dc..8d79213af 100644 --- a/src/Protocol/Protocol16x.cpp +++ b/src/Protocol/Protocol16x.cpp @@ -214,6 +214,25 @@ int cProtocol161::ParseEntityAction(void) +int cProtocol161::ParseLogin(void) +{ + // The login packet is sent by Forge clients only + // Only parse the packet, do no extra processing + // Note that the types and the names have been only guessed and are not verified at all! + HANDLE_PACKET_READ(ReadBEInt, int, Int1); + HANDLE_PACKET_READ(ReadBEUTF16String16, AString, String1); + HANDLE_PACKET_READ(ReadChar, char, Char1); + HANDLE_PACKET_READ(ReadChar, char, Char2); + HANDLE_PACKET_READ(ReadChar, char, Char3); + HANDLE_PACKET_READ(ReadByte, Byte, Byte1); + HANDLE_PACKET_READ(ReadByte, Byte, Byte2); + return PARSE_OK; +} + + + + + int cProtocol161::ParsePlayerAbilities(void) { HANDLE_PACKET_READ(ReadByte, Byte, Flags); diff --git a/src/Protocol/Protocol16x.h b/src/Protocol/Protocol16x.h index ae1388649..8eedce8d5 100644 --- a/src/Protocol/Protocol16x.h +++ b/src/Protocol/Protocol16x.h @@ -46,6 +46,7 @@ protected: virtual void SendWindowOpen (const cWindow & a_Window) override; virtual int ParseEntityAction (void) override; + virtual int ParseLogin (void) override; virtual int ParsePlayerAbilities(void) override; // New packets: -- cgit v1.2.3 From c4b4447a3ada43d4333bba329e89700527870332 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 24 Apr 2014 21:51:19 +0200 Subject: Authenticator uses some C++ SSL objects. --- src/Protocol/Authenticator.cpp | 59 ++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 19 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp index e0fcc0007..ccc994e36 100644 --- a/src/Protocol/Authenticator.cpp +++ b/src/Protocol/Authenticator.cpp @@ -13,10 +13,12 @@ #include "polarssl/config.h" #include "polarssl/net.h" #include "polarssl/ssl.h" -#include "polarssl/entropy.h" #include "polarssl/ctr_drbg.h" #include "polarssl/error.h" -#include "polarssl/certs.h" + +#include "PolarSSL++/EntropyContext.h" +#include "PolarSSL++/CtrDrbgContext.h" +#include "PolarSSL++/X509Cert.h" #include #include @@ -150,31 +152,52 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S int ret, server_fd = -1; unsigned char buf[1024]; - const char *pers = "cAuthenticator"; + const char pers[] = "cAuthenticator"; - entropy_context entropy; - ctr_drbg_context ctr_drbg; + cCtrDrbgContext CtrDrbg; ssl_context ssl; - x509_crt cacert; + cX509Cert CACert; /* Initialize the RNG and the session data */ memset(&ssl, 0, sizeof(ssl_context)); - x509_crt_init(&cacert); - entropy_init(&entropy); - if ((ret = ctr_drbg_init(&ctr_drbg, entropy_func, &entropy, (const unsigned char *)pers, strlen(pers))) != 0) + if ((ret = CtrDrbg.Initialize(pers, sizeof(pers))) != 0) { - LOGWARNING("cAuthenticator: ctr_drbg_init returned %d", ret); + LOGWARNING("cAuthenticator: CtrDrbg.Initialize() returned %d", ret); return false; } /* Initialize certificates */ - // TODO: Grab the sessionserver's root CA and any intermediates and hard-code them here, instead of test_ca_list - ret = x509_crt_parse(&cacert, (const unsigned char *)test_ca_list, strlen(test_ca_list)); - + // This is the root cert for Starfield Technologies, the CA that signed sessionserver.mojang.com's cert: + static const char StarfieldCACert[] = + "-----BEGIN CERTIFICATE-----\n" + "MIID3TCCAsWgAwIBAgIBADANBgkqhkiG9w0BAQsFADCBjzELMAkGA1UEBhMCVVMx\n" + "EDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxJTAjBgNVBAoT\n" + "HFN0YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAMTKVN0YXJmaWVs\n" + "ZCBSb290IENlcnRpZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTA5MDkwMTAwMDAw\n" + "MFoXDTM3MTIzMTIzNTk1OVowgY8xCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdBcml6\n" + "b25hMRMwEQYDVQQHEwpTY290dHNkYWxlMSUwIwYDVQQKExxTdGFyZmllbGQgVGVj\n" + "aG5vbG9naWVzLCBJbmMuMTIwMAYDVQQDEylTdGFyZmllbGQgUm9vdCBDZXJ0aWZp\n" + "Y2F0ZSBBdXRob3JpdHkgLSBHMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC\n" + "ggEBAL3twQP89o/8ArFvW59I2Z154qK3A2FWGMNHttfKPTUuiUP3oWmb3ooa/RMg\n" + "nLRJdzIpVv257IzdIvpy3Cdhl+72WoTsbhm5iSzchFvVdPtrX8WJpRBSiUZV9Lh1\n" + "HOZ/5FSuS/hVclcCGfgXcVnrHigHdMWdSL5stPSksPNkN3mSwOxGXn/hbVNMYq/N\n" + "Hwtjuzqd+/x5AJhhdM8mgkBj87JyahkNmcrUDnXMN/uLicFZ8WJ/X7NfZTD4p7dN\n" + "dloedl40wOiWVpmKs/B/pM293DIxfJHP4F8R+GuqSVzRmZTRouNjWwl2tVZi4Ut0\n" + "HZbUJtQIBFnQmA4O5t78w+wfkPECAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAO\n" + "BgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFHwMMh+n2TB/xH1oo2Kooc6rB1snMA0G\n" + "CSqGSIb3DQEBCwUAA4IBAQARWfolTwNvlJk7mh+ChTnUdgWUXuEok21iXQnCoKjU\n" + "sHU48TRqneSfioYmUeYs0cYtbpUgSpIB7LiKZ3sx4mcujJUDJi5DnUox9g61DLu3\n" + "4jd/IroAow57UvtruzvE03lRTs2Q9GcHGcg8RnoNAX3FWOdt5oUwF5okxBDgBPfg\n" + "8n/Uqgr/Qh037ZTlZFkSIHc40zI+OIF1lnP6aI+xy84fxez6nH7PfrHxBy22/L/K\n" + "pL/QlwVKvOoYKAKQvVR4CSFx09F9HdkWsKlhPdAKACL8x3vLCWRFCztAgfd9fDL1\n" + "mMpYjn0q7pBZc2T5NnReJaH1ZgUufzkVqSr7UIuOhWn0\n" + "-----END CERTIFICATE-----"; + // Parse the Starfield CA and add it to "trusted root certs" + ret = CACert.Parse(StarfieldCACert, sizeof(StarfieldCACert) - 1); if (ret < 0) { - LOGWARNING("cAuthenticator: x509_crt_parse returned -0x%x", -ret); + LOGWARNING("cAuthenticator: CACert.Parse returned -0x%x", -ret); return false; } @@ -193,8 +216,8 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S } ssl_set_endpoint(&ssl, SSL_IS_CLIENT); ssl_set_authmode(&ssl, SSL_VERIFY_OPTIONAL); - ssl_set_ca_chain(&ssl, &cacert, NULL, "PolarSSL Server 1"); - ssl_set_rng(&ssl, ctr_drbg_random, &ctr_drbg); + ssl_set_ca_chain(&ssl, CACert.Get(), NULL, "PolarSSL Server 1"); + ssl_set_rng(&ssl, ctr_drbg_random, CtrDrbg.Get()); ssl_set_bio(&ssl, net_recv, &server_fd, net_send, &server_fd); /* Handshake */ @@ -253,13 +276,11 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S } Response.append((const char *)buf, ret); - } + } ssl_close_notify(&ssl); - x509_crt_free(&cacert); net_close(server_fd); ssl_free(&ssl); - entropy_free(&entropy); memset(&ssl, 0, sizeof(ssl)); // Check the HTTP status line: -- cgit v1.2.3 From e47dab84f3f6606d6d6e95774b16d7d4e8d7daa6 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 09:56:15 -0700 Subject: Cmake generated projects for IDEs include headers in project files. --- src/Protocol/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Protocol') diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt index 107b79627..849ec27ca 100644 --- a/src/Protocol/CMakeLists.txt +++ b/src/Protocol/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../") file(GLOB SOURCE "*.cpp" + "*.h" ) add_library(Protocol ${SOURCE}) -- cgit v1.2.3 From f2b7cb138f6ad271d3312ff6c20ed4448f9b0d50 Mon Sep 17 00:00:00 2001 From: jfhumann Date: Sat, 26 Apr 2014 01:21:06 +0200 Subject: Fixes resource leaks in the yggdrasil authenticator. (CID 43617) --- src/Protocol/Authenticator.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/Protocol') diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp index e0fcc0007..bbc656eda 100644 --- a/src/Protocol/Authenticator.cpp +++ b/src/Protocol/Authenticator.cpp @@ -165,6 +165,10 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S if ((ret = ctr_drbg_init(&ctr_drbg, entropy_func, &entropy, (const unsigned char *)pers, strlen(pers))) != 0) { LOGWARNING("cAuthenticator: ctr_drbg_init returned %d", ret); + + // Free all resources which have been initialized up to this line + x509_crt_free(&cacert); + entropy_free(&entropy); return false; } @@ -175,6 +179,10 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S if (ret < 0) { LOGWARNING("cAuthenticator: x509_crt_parse returned -0x%x", -ret); + + // Free all resources which have been initialized up to this line + x509_crt_free(&cacert); + entropy_free(&entropy); return false; } @@ -182,6 +190,10 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S if ((ret = net_connect(&server_fd, m_Server.c_str(), 443)) != 0) { LOGWARNING("cAuthenticator: Can't connect to %s: %d", m_Server.c_str(), ret); + + // Free all resources which have been initialized up to this line + x509_crt_free(&cacert); + entropy_free(&entropy); return false; } @@ -189,6 +201,13 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S if ((ret = ssl_init(&ssl)) != 0) { LOGWARNING("cAuthenticator: ssl_init returned %d", ret); + + // Free all resources which have been initialized up to this line + x509_crt_free(&cacert); + net_close(server_fd); + ssl_free(&ssl); + entropy_free(&entropy); + memset(&ssl, 0, sizeof(ssl)); return false; } ssl_set_endpoint(&ssl, SSL_IS_CLIENT); @@ -203,6 +222,13 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S if ((ret != POLARSSL_ERR_NET_WANT_READ) && (ret != POLARSSL_ERR_NET_WANT_WRITE)) { LOGWARNING("cAuthenticator: ssl_handshake returned -0x%x", -ret); + + // Free all resources which have been initialized up to this line + x509_crt_free(&cacert); + net_close(server_fd); + ssl_free(&ssl); + entropy_free(&entropy); + memset(&ssl, 0, sizeof(ssl)); return false; } } @@ -223,6 +249,13 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S if (ret <= 0) { LOGWARNING("cAuthenticator: ssl_write returned %d", ret); + + // Free all resources which have been initialized up to this line + x509_crt_free(&cacert); + net_close(server_fd); + ssl_free(&ssl); + entropy_free(&entropy); + memset(&ssl, 0, sizeof(ssl)); return false; } -- cgit v1.2.3 From 49f6819829b437f776ea08f50c92cc506ee9ddcb Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 26 Apr 2014 16:44:15 +0200 Subject: Fixes --- src/Protocol/Protocol125.cpp | 2 +- src/Protocol/Protocol17x.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 3282a827f..a23afb29a 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -2013,7 +2013,7 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) case cMonster::mtWither: { WriteByte(0x54); // Int at index 20 - WriteInt((Int32)((const cWither &)a_Mob).GetNumInvulnerableTicks()); + WriteInt((Int32)((const cWither &)a_Mob).GetWitherInvulnerableTicks()); WriteByte(0x66); // Float at index 6 WriteFloat((float)(a_Mob.GetHealth())); break; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index e57b551cb..80b161e3e 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -2820,7 +2820,7 @@ void cProtocol172::cPacketizer::WriteMobMetadata(const cMonster & a_Mob) case cMonster::mtWither: { WriteByte(0x54); // Int at index 20 - WriteInt(((const cWither &)a_Mob).GetNumInvulnerableTicks()); + WriteInt(((const cWither &)a_Mob).GetWitherInvulnerableTicks()); WriteByte(0x66); // Float at index 6 WriteFloat((float)(a_Mob.GetHealth())); break; -- cgit v1.2.3 From d50f8f6f11f69e7e1e56be92fb2d72a5014a3e34 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 26 Apr 2014 17:47:25 +0200 Subject: Changed the old invulnerable methods from the wither to the new. --- src/Protocol/Protocol125.cpp | 9 ++++++++- src/Protocol/Protocol17x.cpp | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index a23afb29a..3951eb3e4 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -2013,7 +2013,14 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) case cMonster::mtWither: { WriteByte(0x54); // Int at index 20 - WriteInt((Int32)((const cWither &)a_Mob).GetWitherInvulnerableTicks()); + if (((const cWither &)a_Mob).IsSpawnInvulnerable()) + { + WriteInt((Int32)((const cWither &)a_Mob).GetInvulnerableTicks()); + } + else + { + WriteInt((Int32)0); + } WriteByte(0x66); // Float at index 6 WriteFloat((float)(a_Mob.GetHealth())); break; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 80b161e3e..311e770f9 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -2820,7 +2820,14 @@ void cProtocol172::cPacketizer::WriteMobMetadata(const cMonster & a_Mob) case cMonster::mtWither: { WriteByte(0x54); // Int at index 20 - WriteInt(((const cWither &)a_Mob).GetWitherInvulnerableTicks()); + if (((const cWither &)a_Mob).IsSpawnInvulnerable()) + { + WriteInt(((const cWither &)a_Mob).GetInvulnerableTicks()); + } + else + { + WriteInt(0); + } WriteByte(0x66); // Float at index 6 WriteFloat((float)(a_Mob.GetHealth())); break; -- cgit v1.2.3 From 477b3e7861ca03aec5c46b4c192f5cc1b5f07c4d Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 16:45:39 -0700 Subject: Moved cArrowEntity out of ProjectileEntity.h --- src/Protocol/Protocol125.cpp | 2 +- src/Protocol/Protocol17x.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 3282a827f..2f57d3cf1 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -26,7 +26,7 @@ Documentation: #include "../Root.h" #include "../Server.h" -#include "../Entities/ProjectileEntity.h" +#include "../Entities/ProjectileArrow.h" #include "../Entities/Minecart.h" #include "../Entities/FallingBlock.h" diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index e57b551cb..4f2fb7158 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -31,6 +31,7 @@ Implements the 1.7.x protocol classes: #include "../BlockEntities/MobHeadEntity.h" #include "../BlockEntities/FlowerPotEntity.h" #include "../CompositeChat.h" +#include "../Entities/ProjectileArrow.h" -- cgit v1.2.3 From e3c3795aa40e59af86d90b45b209f367563942fb Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 17:50:05 -0700 Subject: Moved cFireworkEntity out of ProjectileEntity.h --- src/Protocol/Protocol17x.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 4f2fb7158..468c4cf2b 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -32,6 +32,7 @@ Implements the 1.7.x protocol classes: #include "../BlockEntities/FlowerPotEntity.h" #include "../CompositeChat.h" #include "../Entities/ProjectileArrow.h" +#include "../Entities/ProjectileFirework.h" -- cgit v1.2.3 From fdac27c63d2587793de40d9d78eb76386c823b31 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 27 Apr 2014 17:31:40 +0200 Subject: Another attempt at #889. The packet was being sent after the state was adjusted, so another thread *may* have sent another packet in the meantime. --- src/Protocol/Protocol17x.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index e57b551cb..8f9e3abd8 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -637,9 +637,11 @@ void cProtocol172::SendLoginSuccess(void) { ASSERT(m_State == 2); // State: login? - cPacketizer Pkt(*this, 0x02); // Login success packet - Pkt.WriteString(m_Client->GetUUID()); - Pkt.WriteString(m_Client->GetUsername()); + { + cPacketizer Pkt(*this, 0x02); // Login success packet + Pkt.WriteString(m_Client->GetUUID()); + Pkt.WriteString(m_Client->GetUsername()); + } m_State = 3; // State = Game } -- cgit v1.2.3 From dd52719c2d34aa251e90fafb87448af7086e2658 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 27 Apr 2014 22:28:14 +0200 Subject: Rewritten cAuthenticator to use the new PolarSSL++ wrapper classes. --- src/Protocol/Authenticator.cpp | 136 ++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 91 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp index ccc994e36..efeb6c41c 100644 --- a/src/Protocol/Authenticator.cpp +++ b/src/Protocol/Authenticator.cpp @@ -16,9 +16,7 @@ #include "polarssl/ctr_drbg.h" #include "polarssl/error.h" -#include "PolarSSL++/EntropyContext.h" -#include "PolarSSL++/CtrDrbgContext.h" -#include "PolarSSL++/X509Cert.h" +#include "PolarSSL++/BlockingSslClientSocket.h" #include #include @@ -150,87 +148,47 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S { LOGD("Trying to auth user %s", a_UserName.c_str()); - int ret, server_fd = -1; + int ret; unsigned char buf[1024]; - const char pers[] = "cAuthenticator"; - - cCtrDrbgContext CtrDrbg; - ssl_context ssl; - cX509Cert CACert; - - /* Initialize the RNG and the session data */ - memset(&ssl, 0, sizeof(ssl_context)); - - if ((ret = CtrDrbg.Initialize(pers, sizeof(pers))) != 0) - { - LOGWARNING("cAuthenticator: CtrDrbg.Initialize() returned %d", ret); - return false; - } /* Initialize certificates */ // This is the root cert for Starfield Technologies, the CA that signed sessionserver.mojang.com's cert: - static const char StarfieldCACert[] = - "-----BEGIN CERTIFICATE-----\n" - "MIID3TCCAsWgAwIBAgIBADANBgkqhkiG9w0BAQsFADCBjzELMAkGA1UEBhMCVVMx\n" - "EDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxJTAjBgNVBAoT\n" - "HFN0YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAMTKVN0YXJmaWVs\n" - "ZCBSb290IENlcnRpZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTA5MDkwMTAwMDAw\n" - "MFoXDTM3MTIzMTIzNTk1OVowgY8xCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdBcml6\n" - "b25hMRMwEQYDVQQHEwpTY290dHNkYWxlMSUwIwYDVQQKExxTdGFyZmllbGQgVGVj\n" - "aG5vbG9naWVzLCBJbmMuMTIwMAYDVQQDEylTdGFyZmllbGQgUm9vdCBDZXJ0aWZp\n" - "Y2F0ZSBBdXRob3JpdHkgLSBHMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC\n" - "ggEBAL3twQP89o/8ArFvW59I2Z154qK3A2FWGMNHttfKPTUuiUP3oWmb3ooa/RMg\n" - "nLRJdzIpVv257IzdIvpy3Cdhl+72WoTsbhm5iSzchFvVdPtrX8WJpRBSiUZV9Lh1\n" - "HOZ/5FSuS/hVclcCGfgXcVnrHigHdMWdSL5stPSksPNkN3mSwOxGXn/hbVNMYq/N\n" - "Hwtjuzqd+/x5AJhhdM8mgkBj87JyahkNmcrUDnXMN/uLicFZ8WJ/X7NfZTD4p7dN\n" - "dloedl40wOiWVpmKs/B/pM293DIxfJHP4F8R+GuqSVzRmZTRouNjWwl2tVZi4Ut0\n" - "HZbUJtQIBFnQmA4O5t78w+wfkPECAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAO\n" - "BgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFHwMMh+n2TB/xH1oo2Kooc6rB1snMA0G\n" - "CSqGSIb3DQEBCwUAA4IBAQARWfolTwNvlJk7mh+ChTnUdgWUXuEok21iXQnCoKjU\n" - "sHU48TRqneSfioYmUeYs0cYtbpUgSpIB7LiKZ3sx4mcujJUDJi5DnUox9g61DLu3\n" - "4jd/IroAow57UvtruzvE03lRTs2Q9GcHGcg8RnoNAX3FWOdt5oUwF5okxBDgBPfg\n" - "8n/Uqgr/Qh037ZTlZFkSIHc40zI+OIF1lnP6aI+xy84fxez6nH7PfrHxBy22/L/K\n" - "pL/QlwVKvOoYKAKQvVR4CSFx09F9HdkWsKlhPdAKACL8x3vLCWRFCztAgfd9fDL1\n" - "mMpYjn0q7pBZc2T5NnReJaH1ZgUufzkVqSr7UIuOhWn0\n" - "-----END CERTIFICATE-----"; - // Parse the Starfield CA and add it to "trusted root certs" - ret = CACert.Parse(StarfieldCACert, sizeof(StarfieldCACert) - 1); - if (ret < 0) - { - LOGWARNING("cAuthenticator: CACert.Parse returned -0x%x", -ret); - return false; - } - - /* Connect */ - if ((ret = net_connect(&server_fd, m_Server.c_str(), 443)) != 0) - { - LOGWARNING("cAuthenticator: Can't connect to %s: %d", m_Server.c_str(), ret); - return false; - } - - /* Setup */ - if ((ret = ssl_init(&ssl)) != 0) + static const AString StarfieldCACert( + "-----BEGIN CERTIFICATE-----\n" + "MIID3TCCAsWgAwIBAgIBADANBgkqhkiG9w0BAQsFADCBjzELMAkGA1UEBhMCVVMx\n" + "EDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxJTAjBgNVBAoT\n" + "HFN0YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAMTKVN0YXJmaWVs\n" + "ZCBSb290IENlcnRpZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTA5MDkwMTAwMDAw\n" + "MFoXDTM3MTIzMTIzNTk1OVowgY8xCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdBcml6\n" + "b25hMRMwEQYDVQQHEwpTY290dHNkYWxlMSUwIwYDVQQKExxTdGFyZmllbGQgVGVj\n" + "aG5vbG9naWVzLCBJbmMuMTIwMAYDVQQDEylTdGFyZmllbGQgUm9vdCBDZXJ0aWZp\n" + "Y2F0ZSBBdXRob3JpdHkgLSBHMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC\n" + "ggEBAL3twQP89o/8ArFvW59I2Z154qK3A2FWGMNHttfKPTUuiUP3oWmb3ooa/RMg\n" + "nLRJdzIpVv257IzdIvpy3Cdhl+72WoTsbhm5iSzchFvVdPtrX8WJpRBSiUZV9Lh1\n" + "HOZ/5FSuS/hVclcCGfgXcVnrHigHdMWdSL5stPSksPNkN3mSwOxGXn/hbVNMYq/N\n" + "Hwtjuzqd+/x5AJhhdM8mgkBj87JyahkNmcrUDnXMN/uLicFZ8WJ/X7NfZTD4p7dN\n" + "dloedl40wOiWVpmKs/B/pM293DIxfJHP4F8R+GuqSVzRmZTRouNjWwl2tVZi4Ut0\n" + "HZbUJtQIBFnQmA4O5t78w+wfkPECAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAO\n" + "BgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFHwMMh+n2TB/xH1oo2Kooc6rB1snMA0G\n" + "CSqGSIb3DQEBCwUAA4IBAQARWfolTwNvlJk7mh+ChTnUdgWUXuEok21iXQnCoKjU\n" + "sHU48TRqneSfioYmUeYs0cYtbpUgSpIB7LiKZ3sx4mcujJUDJi5DnUox9g61DLu3\n" + "4jd/IroAow57UvtruzvE03lRTs2Q9GcHGcg8RnoNAX3FWOdt5oUwF5okxBDgBPfg\n" + "8n/Uqgr/Qh037ZTlZFkSIHc40zI+OIF1lnP6aI+xy84fxez6nH7PfrHxBy22/L/K\n" + "pL/QlwVKvOoYKAKQvVR4CSFx09F9HdkWsKlhPdAKACL8x3vLCWRFCztAgfd9fDL1\n" + "mMpYjn0q7pBZc2T5NnReJaH1ZgUufzkVqSr7UIuOhWn0\n" + "-----END CERTIFICATE-----" + ); + + // Connect the socket: + cBlockingSslClientSocket Socket; + Socket.SetTrustedRootCertsFromString(StarfieldCACert, m_Server); + if (!Socket.Connect(m_Server, 443)) { - LOGWARNING("cAuthenticator: ssl_init returned %d", ret); + LOGWARNING("cAuthenticator: Can't connect to %s: %s", m_Server.c_str(), Socket.GetLastErrorText().c_str()); return false; } - ssl_set_endpoint(&ssl, SSL_IS_CLIENT); - ssl_set_authmode(&ssl, SSL_VERIFY_OPTIONAL); - ssl_set_ca_chain(&ssl, CACert.Get(), NULL, "PolarSSL Server 1"); - ssl_set_rng(&ssl, ctr_drbg_random, CtrDrbg.Get()); - ssl_set_bio(&ssl, net_recv, &server_fd, net_send, &server_fd); - - /* Handshake */ - while ((ret = ssl_handshake(&ssl)) != 0) - { - if ((ret != POLARSSL_ERR_NET_WANT_READ) && (ret != POLARSSL_ERR_NET_WANT_WRITE)) - { - LOGWARNING("cAuthenticator: ssl_handshake returned -0x%x", -ret); - return false; - } - } - /* Write the GET request */ + // Create the GET request: AString ActualAddress = m_Address; ReplaceString(ActualAddress, "%USERNAME%", a_UserName); ReplaceString(ActualAddress, "%SERVERID%", a_ServerId); @@ -242,23 +200,23 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S Request += "Connection: close\r\n"; Request += "\r\n"; - ret = ssl_write(&ssl, (const unsigned char *)Request.c_str(), Request.size()); - if (ret <= 0) + if (!Socket.Send(Request.c_str(), Request.size())) { - LOGWARNING("cAuthenticator: ssl_write returned %d", ret); + LOGWARNING("cAuthenticator: Writing SSL data failed: %s", Socket.GetLastErrorText().c_str()); return false; } - /* Read the HTTP response */ + // Read the HTTP response: std::string Response; for (;;) { - memset(buf, 0, sizeof(buf)); - ret = ssl_read(&ssl, buf, sizeof(buf)); + ret = Socket.Receive(buf, sizeof(buf)); if ((ret == POLARSSL_ERR_NET_WANT_READ) || (ret == POLARSSL_ERR_NET_WANT_WRITE)) { - continue; + // This value should never be returned, it is handled internally by cBlockingSslClientSocket + LOGWARNING("cAuthenticator: SSL reading failed internally."); + return false; } if (ret == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) { @@ -266,22 +224,18 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S } if (ret < 0) { - LOGWARNING("cAuthenticator: ssl_read returned %d", ret); - break; + LOGWARNING("cAuthenticator: SSL reading failed: -0x%x", -ret); + return false; } if (ret == 0) { - LOGWARNING("cAuthenticator: EOF"); break; } - Response.append((const char *)buf, ret); + Response.append((const char *)buf, (size_t)ret); } - ssl_close_notify(&ssl); - net_close(server_fd); - ssl_free(&ssl); - memset(&ssl, 0, sizeof(ssl)); + Socket.Disconnect(); // Check the HTTP status line: AString prefix("HTTP/1.1 200 OK"); -- cgit v1.2.3 From 9b0cb3fd97701370915a9a5b3d5b237fa7f90e06 Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 27 Apr 2014 17:03:06 -0700 Subject: Fixed projectile source filenames, indentations --- src/Protocol/Protocol125.cpp | 2 +- src/Protocol/Protocol17x.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 2f57d3cf1..9502f9bec 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -26,7 +26,7 @@ Documentation: #include "../Root.h" #include "../Server.h" -#include "../Entities/ProjectileArrow.h" +#include "../Entities/ArrowEntity.h" #include "../Entities/Minecart.h" #include "../Entities/FallingBlock.h" diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 468c4cf2b..2cc0adbfb 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -31,8 +31,8 @@ Implements the 1.7.x protocol classes: #include "../BlockEntities/MobHeadEntity.h" #include "../BlockEntities/FlowerPotEntity.h" #include "../CompositeChat.h" -#include "../Entities/ProjectileArrow.h" -#include "../Entities/ProjectileFirework.h" +#include "../Entities/ArrowEntity.h" +#include "../Entities/FireworkEntity.h" -- cgit v1.2.3 From 26e935cb2028e041623424d474ccf1b127d55e97 Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 28 Apr 2014 13:51:22 +0200 Subject: Revert "Changed the old invulnerable methods from the wither to the new." This reverts commit d50f8f6f11f69e7e1e56be92fb2d72a5014a3e34. --- src/Protocol/Protocol125.cpp | 9 +-------- src/Protocol/Protocol17x.cpp | 9 +-------- 2 files changed, 2 insertions(+), 16 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 3951eb3e4..a23afb29a 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -2013,14 +2013,7 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) case cMonster::mtWither: { WriteByte(0x54); // Int at index 20 - if (((const cWither &)a_Mob).IsSpawnInvulnerable()) - { - WriteInt((Int32)((const cWither &)a_Mob).GetInvulnerableTicks()); - } - else - { - WriteInt((Int32)0); - } + WriteInt((Int32)((const cWither &)a_Mob).GetWitherInvulnerableTicks()); WriteByte(0x66); // Float at index 6 WriteFloat((float)(a_Mob.GetHealth())); break; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 311e770f9..80b161e3e 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -2820,14 +2820,7 @@ void cProtocol172::cPacketizer::WriteMobMetadata(const cMonster & a_Mob) case cMonster::mtWither: { WriteByte(0x54); // Int at index 20 - if (((const cWither &)a_Mob).IsSpawnInvulnerable()) - { - WriteInt(((const cWither &)a_Mob).GetInvulnerableTicks()); - } - else - { - WriteInt(0); - } + WriteInt(((const cWither &)a_Mob).GetWitherInvulnerableTicks()); WriteByte(0x66); // Float at index 6 WriteFloat((float)(a_Mob.GetHealth())); break; -- cgit v1.2.3 From bab3a3cd31c26d7c8c195888675b31ece5ab80b7 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 28 Apr 2014 21:16:52 +0200 Subject: Added the G1 root cert. Now the authenticator finally works. --- src/Protocol/Authenticator.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp index efeb6c41c..f7008a5c4 100644 --- a/src/Protocol/Authenticator.cpp +++ b/src/Protocol/Authenticator.cpp @@ -152,8 +152,10 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S unsigned char buf[1024]; /* Initialize certificates */ - // This is the root cert for Starfield Technologies, the CA that signed sessionserver.mojang.com's cert: + // 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" @@ -176,7 +178,32 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S "8n/Uqgr/Qh037ZTlZFkSIHc40zI+OIF1lnP6aI+xy84fxez6nH7PfrHxBy22/L/K\n" "pL/QlwVKvOoYKAKQvVR4CSFx09F9HdkWsKlhPdAKACL8x3vLCWRFCztAgfd9fDL1\n" "mMpYjn0q7pBZc2T5NnReJaH1ZgUufzkVqSr7UIuOhWn0\n" - "-----END CERTIFICATE-----" + "-----END CERTIFICATE-----\n\n" + // Original (G1) cert: + "-----BEGIN CERTIFICATE-----\n" + "MIIEDzCCAvegAwIBAgIBADANBgkqhkiG9w0BAQUFADBoMQswCQYDVQQGEwJVUzEl\n" + "MCMGA1UEChMcU3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAGA1UECxMp\n" + "U3RhcmZpZWxkIENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMDQw\n" + "NjI5MTczOTE2WhcNMzQwNjI5MTczOTE2WjBoMQswCQYDVQQGEwJVUzElMCMGA1UE\n" + "ChMcU3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAGA1UECxMpU3RhcmZp\n" + "ZWxkIENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwggEgMA0GCSqGSIb3\n" + "DQEBAQUAA4IBDQAwggEIAoIBAQC3Msj+6XGmBIWtDBFk385N78gDGIc/oav7PKaf\n" + "8MOh2tTYbitTkPskpD6E8J7oX+zlJ0T1KKY/e97gKvDIr1MvnsoFAZMej2YcOadN\n" + "+lq2cwQlZut3f+dZxkqZJRRU6ybH838Z1TBwj6+wRir/resp7defqgSHo9T5iaU0\n" + "X9tDkYI22WY8sbi5gv2cOj4QyDvvBmVmepsZGD3/cVE8MC5fvj13c7JdBmzDI1aa\n" + "K4UmkhynArPkPw2vCHmCuDY96pzTNbO8acr1zJ3o/WSNF4Azbl5KXZnJHoe0nRrA\n" + "1W4TNSNe35tfPe/W93bC6j67eA0cQmdrBNj41tpvi/JEoAGrAgEDo4HFMIHCMB0G\n" + "A1UdDgQWBBS/X7fRzt0fhvRbVazc1xDCDqmI5zCBkgYDVR0jBIGKMIGHgBS/X7fR\n" + "zt0fhvRbVazc1xDCDqmI56FspGowaDELMAkGA1UEBhMCVVMxJTAjBgNVBAoTHFN0\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" ); // Connect the socket: -- cgit v1.2.3 From ec33bbe2949010e1ed377b9dcc1ace56a0126bfe Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 29 Apr 2014 11:04:54 +0200 Subject: Moved cRsaPrivateKey to PolarSSL++, rewritten using existing objects. --- src/Protocol/Protocol132.cpp | 2 +- src/Protocol/Protocol17x.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp index 53d8c1561..acfa5e811 100644 --- a/src/Protocol/Protocol132.cpp +++ b/src/Protocol/Protocol132.cpp @@ -819,7 +819,7 @@ void cProtocol132::SendEncryptionKeyRequest(void) void cProtocol132::HandleEncryptionKeyResponse(const AString & a_EncKey, const AString & a_EncNonce) { // Decrypt EncNonce using privkey - cRSAPrivateKey & rsaDecryptor = cRoot::Get()->GetServer()->GetPrivateKey(); + cRsaPrivateKey & rsaDecryptor = cRoot::Get()->GetServer()->GetPrivateKey(); Int32 DecryptedNonce[MAX_ENC_LEN / sizeof(Int32)]; int res = rsaDecryptor.Decrypt((const Byte *)a_EncNonce.data(), a_EncNonce.size(), (Byte *)DecryptedNonce, sizeof(DecryptedNonce)); diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index a04d8ac3c..001b8c219 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1690,7 +1690,7 @@ void cProtocol172::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffe } // Decrypt EncNonce using privkey - cRSAPrivateKey & rsaDecryptor = cRoot::Get()->GetServer()->GetPrivateKey(); + cRsaPrivateKey & rsaDecryptor = cRoot::Get()->GetServer()->GetPrivateKey(); Int32 DecryptedNonce[MAX_ENC_LEN / sizeof(Int32)]; int res = rsaDecryptor.Decrypt((const Byte *)EncNonce.data(), EncNonce.size(), (Byte *)DecryptedNonce, sizeof(DecryptedNonce)); if (res != 4) -- cgit v1.2.3 From 6cb2d2461f869d5c9d986cccec5edf1021878df2 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 29 Apr 2014 17:37:15 +0200 Subject: Moved the rest of the Crypto objects into their own respective files. --- src/Protocol/Protocol132.cpp | 18 +++--------------- src/Protocol/Protocol132.h | 7 ++++--- src/Protocol/Protocol17x.cpp | 5 +++-- src/Protocol/Protocol17x.h | 7 ++++--- 4 files changed, 14 insertions(+), 23 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp index acfa5e811..f4717f592 100644 --- a/src/Protocol/Protocol132.cpp +++ b/src/Protocol/Protocol132.cpp @@ -18,19 +18,7 @@ #include "../WorldStorage/FastNBT.h" #include "../WorldStorage/EnchantmentSerializer.h" #include "../StringCompression.h" - -#ifdef _MSC_VER - #pragma warning(push) - #pragma warning(disable:4127) - #pragma warning(disable:4244) - #pragma warning(disable:4231) - #pragma warning(disable:4189) - #pragma warning(disable:4702) -#endif - -#ifdef _MSC_VER - #pragma warning(pop) -#endif +#include "PolarSSL++/Sha1Checksum.h" @@ -876,7 +864,7 @@ void cProtocol132::StartEncryption(const Byte * a_Key) m_IsEncrypted = true; // Prepare the m_AuthServerID: - cSHA1Checksum Checksum; + cSha1Checksum Checksum; cServer * Server = cRoot::Get()->GetServer(); AString ServerID = Server->GetServerID(); Checksum.Update((const Byte *)ServerID.c_str(), ServerID.length()); @@ -884,7 +872,7 @@ void cProtocol132::StartEncryption(const Byte * a_Key) Checksum.Update((const Byte *)Server->GetPublicKeyDER().data(), Server->GetPublicKeyDER().size()); Byte Digest[20]; Checksum.Finalize(Digest); - cSHA1Checksum::DigestToJava(Digest, m_AuthServerID); + cSha1Checksum::DigestToJava(Digest, m_AuthServerID); } diff --git a/src/Protocol/Protocol132.h b/src/Protocol/Protocol132.h index b280c8a41..32bc7d581 100644 --- a/src/Protocol/Protocol132.h +++ b/src/Protocol/Protocol132.h @@ -24,7 +24,8 @@ #pragma warning(pop) #endif -#include "../Crypto.h" +#include "PolarSSL++/AesCfb128Decryptor.h" +#include "PolarSSL++/AesCfb128Encryptor.h" @@ -79,8 +80,8 @@ public: protected: bool m_IsEncrypted; - cAESCFBDecryptor m_Decryptor; - cAESCFBEncryptor m_Encryptor; + cAesCfb128Decryptor m_Decryptor; + cAesCfb128Encryptor m_Encryptor; AString m_DataToSend; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 001b8c219..a6d566625 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -33,6 +33,7 @@ Implements the 1.7.x protocol classes: #include "../CompositeChat.h" #include "../Entities/ArrowEntity.h" #include "../Entities/FireworkEntity.h" +#include "PolarSSL++/Sha1Checksum.h" @@ -2293,7 +2294,7 @@ void cProtocol172::StartEncryption(const Byte * a_Key) m_IsEncrypted = true; // Prepare the m_AuthServerID: - cSHA1Checksum Checksum; + cSha1Checksum Checksum; cServer * Server = cRoot::Get()->GetServer(); const AString & ServerID = Server->GetServerID(); Checksum.Update((const Byte *)ServerID.c_str(), ServerID.length()); @@ -2301,7 +2302,7 @@ void cProtocol172::StartEncryption(const Byte * a_Key) Checksum.Update((const Byte *)Server->GetPublicKeyDER().data(), Server->GetPublicKeyDER().size()); Byte Digest[20]; Checksum.Finalize(Digest); - cSHA1Checksum::DigestToJava(Digest, m_AuthServerID); + cSha1Checksum::DigestToJava(Digest, m_AuthServerID); } diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 6a3e81eff..3f9c93357 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -30,7 +30,8 @@ Declares the 1.7.x protocol classes: #pragma warning(pop) #endif -#include "../Crypto.h" +#include "PolarSSL++/AesCfb128Decryptor.h" +#include "PolarSSL++/AesCfb128Encryptor.h" @@ -236,8 +237,8 @@ protected: bool m_IsEncrypted; - cAESCFBDecryptor m_Decryptor; - cAESCFBEncryptor m_Encryptor; + cAesCfb128Decryptor m_Decryptor; + cAesCfb128Decryptor m_Encryptor; /** The logfile where the comm is logged, when g_ShouldLogComm is true */ cFile m_CommLogFile; -- cgit v1.2.3 From c045bb3f4ccea1c357a726d73cd75d699cfe901c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 29 Apr 2014 17:45:20 +0200 Subject: Removed unneeded #includes. --- src/Protocol/Authenticator.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp index f7008a5c4..8100b6395 100644 --- a/src/Protocol/Authenticator.cpp +++ b/src/Protocol/Authenticator.cpp @@ -10,12 +10,6 @@ #include "inifile/iniFile.h" #include "json/json.h" -#include "polarssl/config.h" -#include "polarssl/net.h" -#include "polarssl/ssl.h" -#include "polarssl/ctr_drbg.h" -#include "polarssl/error.h" - #include "PolarSSL++/BlockingSslClientSocket.h" #include -- cgit v1.2.3 From 58929a994830329120c68bf43cf6fcb8a90be960 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 30 Apr 2014 17:06:31 +0200 Subject: Removed the unused cBlockingTCPLink class. --- src/Protocol/Authenticator.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp index 8100b6395..41d614e58 100644 --- a/src/Protocol/Authenticator.cpp +++ b/src/Protocol/Authenticator.cpp @@ -2,7 +2,6 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Authenticator.h" -#include "../OSSupport/BlockingTCPLink.h" #include "../Root.h" #include "../Server.h" #include "../ClientHandle.h" -- cgit v1.2.3 From ed75d3a8364f360b213956c40c51729ea53f3616 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 1 May 2014 22:58:58 +0200 Subject: Fixed warnings in ClientHandle. --- src/Protocol/Protocol.h | 2 +- src/Protocol/Protocol125.cpp | 2 +- src/Protocol/Protocol125.h | 2 +- src/Protocol/Protocol17x.cpp | 2 +- src/Protocol/Protocol17x.h | 2 +- src/Protocol/ProtocolRecognizer.cpp | 2 +- src/Protocol/ProtocolRecognizer.h | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index 2fbeef0fa..8f152ad37 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -123,7 +123,7 @@ public: virtual void SendWholeInventory (const cWindow & a_Window) = 0; virtual void SendWindowClose (const cWindow & a_Window) = 0; virtual void SendWindowOpen (const cWindow & a_Window) = 0; - virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) = 0; + virtual void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value) = 0; /// Returns the ServerID used for authentication through session.minecraft.net virtual AString GetAuthServerID(void) = 0; diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 35ab72bfc..e7873cf7a 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1175,7 +1175,7 @@ void cProtocol125::SendWindowOpen(const cWindow & a_Window) -void cProtocol125::SendWindowProperty(const cWindow & a_Window, short a_Property, short a_Value) +void cProtocol125::SendWindowProperty(const cWindow & a_Window, int a_Property, int a_Value) { cCSLock Lock(m_CSPacket); WriteByte (PACKET_WINDOW_PROPERTY); diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h index 89e64f386..423e58d67 100644 --- a/src/Protocol/Protocol125.h +++ b/src/Protocol/Protocol125.h @@ -96,7 +96,7 @@ public: virtual void SendWholeInventory (const cWindow & a_Window) override; virtual void SendWindowClose (const cWindow & a_Window) override; virtual void SendWindowOpen (const cWindow & a_Window) override; - virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) override; + virtual void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value) override; virtual AString GetAuthServerID(void) override; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index a6d566625..bc9aff0c0 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1383,7 +1383,7 @@ void cProtocol172::SendWindowOpen(const cWindow & a_Window) -void cProtocol172::SendWindowProperty(const cWindow & a_Window, short a_Property, short a_Value) +void cProtocol172::SendWindowProperty(const cWindow & a_Window, int a_Property, int a_Value) { ASSERT(m_State == 3); // In game mode? diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 3f9c93357..eed761a4a 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -128,7 +128,7 @@ public: virtual void SendWholeInventory (const cWindow & a_Window) override; virtual void SendWindowClose (const cWindow & a_Window) override; virtual void SendWindowOpen (const cWindow & a_Window) override; - virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) override; + virtual void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value) override; virtual AString GetAuthServerID(void) override { return m_AuthServerID; } diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index 2ccb9f197..22dfe7c88 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -357,7 +357,7 @@ void cProtocolRecognizer::SendHealth(void) -void cProtocolRecognizer::SendWindowProperty(const cWindow & a_Window, short a_Property, short a_Value) +void cProtocolRecognizer::SendWindowProperty(const cWindow & a_Window, int a_Property, int a_Value) { ASSERT(m_Protocol != NULL); m_Protocol->SendWindowProperty(a_Window, a_Property, a_Value); diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index 408109ef4..37f47379d 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -131,7 +131,7 @@ public: virtual void SendWholeInventory (const cWindow & a_Window) override; virtual void SendWindowClose (const cWindow & a_Window) override; virtual void SendWindowOpen (const cWindow & a_Window) override; - virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) override; + virtual void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value) override; virtual AString GetAuthServerID(void) override; -- cgit v1.2.3 From eaf3dcb9f7430bb76b737c1eb32ce68ca4835916 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 3 May 2014 23:46:04 +0200 Subject: Fixed connection encryption. Fixes #975. --- src/Protocol/Protocol17x.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index eed761a4a..dc111e737 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -238,7 +238,7 @@ protected: bool m_IsEncrypted; cAesCfb128Decryptor m_Decryptor; - cAesCfb128Decryptor m_Encryptor; + cAesCfb128Encryptor m_Encryptor; /** The logfile where the comm is logged, when g_ShouldLogComm is true */ cFile m_CommLogFile; -- cgit v1.2.3 From 383fe0cc1e8236852ee714ee1c65ab68571d5809 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 3 May 2014 23:59:45 +0200 Subject: Hotfixed Chunked transfer encoding in Yggdrasil. By using HTTP/1.0, we're disabling the support for the Chunked encoding on the server. This is a hotfix for #979, a proper parser implementation is still needed. --- src/Protocol/Authenticator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp index 41d614e58..2050393c2 100644 --- a/src/Protocol/Authenticator.cpp +++ b/src/Protocol/Authenticator.cpp @@ -214,7 +214,7 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S ReplaceString(ActualAddress, "%SERVERID%", a_ServerId); AString Request; - Request += "GET " + ActualAddress + " HTTP/1.1\r\n"; + 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"; -- cgit v1.2.3