From a53734e0d207b25b2af65ed9549d0a4505274fa6 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 10:51:47 -0700 Subject: [PATCH 001/166] Send modinfo/modList in 1.12 ping response --- src/Protocol/Protocol_1_12.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp index 904b31ca0c..7405131f0c 100644 --- a/src/Protocol/Protocol_1_12.cpp +++ b/src/Protocol/Protocol_1_12.cpp @@ -393,12 +393,22 @@ void cProtocol_1_12::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) // Description: Json::Value Description; Description["text"] = ServerDescription.c_str(); - + + // modinfo: + // TODO: only send if mods enabled + Json::Value Modinfo; + Modinfo["type"] = "FML"; + + Json::Value ModList(Json::arrayValue); + // TODO: customizable modList + Modinfo["modList"] = ModList; + // Create the response: Json::Value ResponseValue; ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; + ResponseValue["modinfo"] = Modinfo; if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); From 376c525266aef38c27ace36940e1a5e2c86ebc7a Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 11:22:13 -0700 Subject: [PATCH 002/166] Refactor to new ForgeHandshake class --- src/Protocol/CMakeLists.txt | 2 ++ src/Protocol/ForgeHandshake.cpp | 23 +++++++++++++++++++++++ src/Protocol/Protocol_1_12.cpp | 13 +++---------- 3 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 src/Protocol/ForgeHandshake.cpp diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt index f21c81f831..562ab555bc 100644 --- a/src/Protocol/CMakeLists.txt +++ b/src/Protocol/CMakeLists.txt @@ -13,6 +13,7 @@ SET (SRCS Protocol_1_11.cpp Protocol_1_12.cpp ProtocolRecognizer.cpp + ForgeHandshake.cpp ) SET (HDRS @@ -27,6 +28,7 @@ SET (HDRS Protocol_1_11.h Protocol_1_12.h ProtocolRecognizer.h + ForgeHandshake.h ) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp new file mode 100644 index 0000000000..c7e35b76de --- /dev/null +++ b/src/Protocol/ForgeHandshake.cpp @@ -0,0 +1,23 @@ + +// ForgeHandshake.cpp + +// Implements Forge protocol handshaking + +#include "ForgeHandshake.h" + +#include "json/json.h" + +void ForgeHandshake::augmentServerListPing(Json::Value & ResponseValue) +{ + // modinfo: + // TODO: only send if mods enabled + Json::Value Modinfo; + Modinfo["type"] = "FML"; + + Json::Value ModList(Json::arrayValue); + // TODO: customizable modList + Modinfo["modList"] = ModList; + + // Augment the response: + ResponseValue["modinfo"] = Modinfo; +} diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp index 7405131f0c..3a254515f8 100644 --- a/src/Protocol/Protocol_1_12.cpp +++ b/src/Protocol/Protocol_1_12.cpp @@ -10,6 +10,7 @@ Implements the 1.12 protocol classes: #include "Protocol_1_12.h" #include "ProtocolRecognizer.h" #include "Packetizer.h" +#include "ForgeHandshake.h" #include "../Entities/Boat.h" #include "../Entities/Minecart.h" @@ -394,21 +395,13 @@ void cProtocol_1_12::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) Json::Value Description; Description["text"] = ServerDescription.c_str(); - // modinfo: - // TODO: only send if mods enabled - Json::Value Modinfo; - Modinfo["type"] = "FML"; - - Json::Value ModList(Json::arrayValue); - // TODO: customizable modList - Modinfo["modList"] = ModList; - // Create the response: Json::Value ResponseValue; ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - ResponseValue["modinfo"] = Modinfo; + ForgeHandshake::augmentServerListPing(ResponseValue); + if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); From 5f4f050eb68eabca870f296dbaf38819073c4947 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 11:33:31 -0700 Subject: [PATCH 003/166] Add modinfo to ping response of all protocol versions --- src/Protocol/Protocol.h | 1 + src/Protocol/Protocol_1_10.cpp | 1 + src/Protocol/Protocol_1_11.cpp | 2 ++ src/Protocol/Protocol_1_12.cpp | 2 -- src/Protocol/Protocol_1_8.cpp | 1 + src/Protocol/Protocol_1_9.cpp | 4 ++++ 6 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index d20c37a29d..de3c4236af 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -16,6 +16,7 @@ #include "../Map.h" #include "../ByteBuffer.h" #include "../EffectID.h" +#include "ForgeHandshake.h" #include diff --git a/src/Protocol/Protocol_1_10.cpp b/src/Protocol/Protocol_1_10.cpp index 16c1b3277d..ba8bbb0b79 100644 --- a/src/Protocol/Protocol_1_10.cpp +++ b/src/Protocol/Protocol_1_10.cpp @@ -346,6 +346,7 @@ void cProtocol_1_10_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; + ForgeHandshake::augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_11.cpp b/src/Protocol/Protocol_1_11.cpp index e4aaa8f6fe..bed1b924c9 100644 --- a/src/Protocol/Protocol_1_11.cpp +++ b/src/Protocol/Protocol_1_11.cpp @@ -586,6 +586,7 @@ void cProtocol_1_11_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; + ForgeHandshake::augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -1191,6 +1192,7 @@ void cProtocol_1_11_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; + ForgeHandshake::augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp index 3a254515f8..1409b1abc5 100644 --- a/src/Protocol/Protocol_1_12.cpp +++ b/src/Protocol/Protocol_1_12.cpp @@ -10,7 +10,6 @@ Implements the 1.12 protocol classes: #include "Protocol_1_12.h" #include "ProtocolRecognizer.h" #include "Packetizer.h" -#include "ForgeHandshake.h" #include "../Entities/Boat.h" #include "../Entities/Minecart.h" @@ -401,7 +400,6 @@ void cProtocol_1_12::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["players"] = Players; ResponseValue["description"] = Description; ForgeHandshake::augmentServerListPing(ResponseValue); - if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp index ee2172eaf7..9a6d40c45b 100644 --- a/src/Protocol/Protocol_1_8.cpp +++ b/src/Protocol/Protocol_1_8.cpp @@ -2135,6 +2135,7 @@ void cProtocol_1_8_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; + ForgeHandshake::augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index 5c3be674f4..ca1c4efc8a 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -2160,6 +2160,7 @@ void cProtocol_1_9_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; + ForgeHandshake::augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4161,6 +4162,7 @@ void cProtocol_1_9_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; + ForgeHandshake::augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4218,6 +4220,7 @@ void cProtocol_1_9_2::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; + ForgeHandshake::augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4275,6 +4278,7 @@ void cProtocol_1_9_4::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; + ForgeHandshake::augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); From 24adfe94c0556839dd17f9b1d89f7aa79cc71065 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 11:40:03 -0700 Subject: [PATCH 004/166] Move cForgeHandshake to instance variable of Protocol --- src/Protocol/ForgeHandshake.cpp | 2 +- src/Protocol/Protocol.h | 3 +++ src/Protocol/Protocol_1_10.cpp | 2 +- src/Protocol/Protocol_1_11.cpp | 4 ++-- src/Protocol/Protocol_1_12.cpp | 2 +- src/Protocol/Protocol_1_8.cpp | 2 +- src/Protocol/Protocol_1_9.cpp | 8 ++++---- 7 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index c7e35b76de..90c095baf0 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -7,7 +7,7 @@ #include "json/json.h" -void ForgeHandshake::augmentServerListPing(Json::Value & ResponseValue) +void cForgeHandshake::augmentServerListPing(Json::Value & ResponseValue) { // modinfo: // TODO: only send if mods enabled diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index de3c4236af..9914a19e61 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -167,6 +167,9 @@ class cProtocol /** Buffer for composing packet length (so that each cPacketizer instance doesn't allocate a new cPacketBuffer) */ cByteBuffer m_OutPacketLenBuffer; + + /** Forge protocol handshaking */ + cForgeHandshake m_ForgeHandshake; /** A generic data-sending routine, all outgoing packet data needs to be routed through this so that descendants may override it. */ virtual void SendData(const char * a_Data, size_t a_Size) = 0; diff --git a/src/Protocol/Protocol_1_10.cpp b/src/Protocol/Protocol_1_10.cpp index ba8bbb0b79..246b4f99a3 100644 --- a/src/Protocol/Protocol_1_10.cpp +++ b/src/Protocol/Protocol_1_10.cpp @@ -346,7 +346,7 @@ void cProtocol_1_10_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - ForgeHandshake::augmentServerListPing(ResponseValue); + m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_11.cpp b/src/Protocol/Protocol_1_11.cpp index bed1b924c9..d720e4bc45 100644 --- a/src/Protocol/Protocol_1_11.cpp +++ b/src/Protocol/Protocol_1_11.cpp @@ -586,7 +586,7 @@ void cProtocol_1_11_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - ForgeHandshake::augmentServerListPing(ResponseValue); + m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -1192,7 +1192,7 @@ void cProtocol_1_11_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - ForgeHandshake::augmentServerListPing(ResponseValue); + m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp index 1409b1abc5..e38872e59c 100644 --- a/src/Protocol/Protocol_1_12.cpp +++ b/src/Protocol/Protocol_1_12.cpp @@ -399,7 +399,7 @@ void cProtocol_1_12::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - ForgeHandshake::augmentServerListPing(ResponseValue); + m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp index 9a6d40c45b..b930bc25ea 100644 --- a/src/Protocol/Protocol_1_8.cpp +++ b/src/Protocol/Protocol_1_8.cpp @@ -2135,7 +2135,7 @@ void cProtocol_1_8_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - ForgeHandshake::augmentServerListPing(ResponseValue); + m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index ca1c4efc8a..64fa28a291 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -2160,7 +2160,7 @@ void cProtocol_1_9_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - ForgeHandshake::augmentServerListPing(ResponseValue); + m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4162,7 +4162,7 @@ void cProtocol_1_9_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - ForgeHandshake::augmentServerListPing(ResponseValue); + m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4220,7 +4220,7 @@ void cProtocol_1_9_2::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - ForgeHandshake::augmentServerListPing(ResponseValue); + m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4278,7 +4278,7 @@ void cProtocol_1_9_4::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - ForgeHandshake::augmentServerListPing(ResponseValue); + m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); From 2c0dd69af618165369cb6ef4db419ff017b319de Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 12:03:33 -0700 Subject: [PATCH 005/166] Detect Forge client connection (\0FML\0 in server name) http://wiki.vg/Minecraft_Forge_Handshake#Connection_to_a_forge_server --- src/Protocol/Protocol_1_9.cpp | 36 +++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index 64fa28a291..9332a2ef01 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -121,18 +121,34 @@ cProtocol_1_9_0::cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_Ser m_ReceivedData(32 KiB), m_IsEncrypted(false) { - - // BungeeCord handling: - // If BC is setup with ip_forward == true, it sends additional data in the login packet's ServerAddress field: - // hostname\00ip-address\00uuid\00profile-properties-as-json + AStringVector Params; - if (cRoot::Get()->GetServer()->ShouldAllowBungeeCord() && SplitZeroTerminatedStrings(a_ServerAddress, Params) && (Params.size() == 4)) - { - LOGD("Player at %s connected via BungeeCord", Params[1].c_str()); + SplitZeroTerminatedStrings(a_ServerAddress, Params); + + if (Params.size() >= 2) { m_ServerAddress = Params[0]; - m_Client->SetIPString(Params[1]); - m_Client->SetUUID(cMojangAPI::MakeUUIDShort(Params[2])); - m_Client->SetProperties(Params[3]); + + if (Params[1] == "FML") { + LOG("Forge client connected!"); + // TODO + } else if (Params.size() == 4) { + if (cRoot::Get()->GetServer()->ShouldAllowBungeeCord()) { + // BungeeCord handling: + // If BC is setup with ip_forward == true, it sends additional data in the login packet's ServerAddress field: + // hostname\00ip-address\00uuid\00profile-properties-as-json + + LOGD("Player at %s connected via BungeeCord", Params[1].c_str()); + + m_Client->SetIPString(Params[1]); + m_Client->SetUUID(cMojangAPI::MakeUUIDShort(Params[2])); + m_Client->SetProperties(Params[3]); + } else { + LOG("BungeeCord is disabled, but client sent additional data, set AllowBungeeCord=1 if you want to allow it"); + } + } else { + LOG("Unknown additional data sent in server address (BungeeCord/FML?): %zu parameters", Params.size()); + // TODO: support FML + BungeeCord? (what parameters does it send in that case?) https://github.com/SpigotMC/BungeeCord/issues/899 + } } // Create the comm log file, if so requested: From c6eff1df8a31c3a5da9293261ba090a30629c818 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 12:41:04 -0700 Subject: [PATCH 006/166] Send plugin channel registration to Forge client after login success --- src/Protocol/Protocol_1_9.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index 9332a2ef01..0bc48a9f56 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -130,7 +130,7 @@ cProtocol_1_9_0::cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_Ser if (Params[1] == "FML") { LOG("Forge client connected!"); - // TODO + m_ForgeHandshake.isForgeClient = true; } else if (Params.size() == 4) { if (cRoot::Get()->GetServer()->ShouldAllowBungeeCord()) { // BungeeCord handling: @@ -713,6 +713,21 @@ void cProtocol_1_9_0::SendLoginSuccess(void) Pkt.WriteString(cMojangAPI::MakeUUIDDashed(m_Client->GetUUID())); Pkt.WriteString(m_Client->GetUsername()); } + + if (m_ForgeHandshake.isForgeClient) { + AStringVector channels = { "FML|HS", "FML", "FML|MP", "FML", "FORGE" }; + AString channelsString; + + for (AStringVector::iterator itr = channels.begin(); itr != channels.end(); ++itr) + { + channelsString.append(*itr); + channelsString.push_back('\0'); + } + + m_Client->SendPluginMessage("REGISTER", channelsString); + //m_Client->RegisterPluginChannels(channels); // private and only adds to internal data structures, not sending messages + // TODO: send ServerHello + } } From e73c227c2cdd83520bc66eaf266014aebd90ac0f Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 12:59:26 -0700 Subject: [PATCH 007/166] Refactor sending plugin channels into cForgeHandshake::onLoginSuccess --- src/Protocol/ForgeHandshake.cpp | 20 ++++++++++++++++++++ src/Protocol/Protocol_1_9.cpp | 15 +-------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 90c095baf0..0dd041ad9f 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -5,7 +5,9 @@ #include "ForgeHandshake.h" +#include "Globals.h" #include "json/json.h" +#include "../ClientHandle.h" void cForgeHandshake::augmentServerListPing(Json::Value & ResponseValue) { @@ -21,3 +23,21 @@ void cForgeHandshake::augmentServerListPing(Json::Value & ResponseValue) // Augment the response: ResponseValue["modinfo"] = Modinfo; } + +void cForgeHandshake::onLoginSuccess(cClientHandle * Client) +{ + if (isForgeClient) { + AStringVector channels = { "FML|HS", "FML", "FML|MP", "FML", "FORGE" }; + AString channelsString; + + for (AStringVector::iterator itr = channels.begin(); itr != channels.end(); ++itr) + { + channelsString.append(*itr); + channelsString.push_back('\0'); + } + + Client->SendPluginMessage("REGISTER", channelsString); + //m_Client->RegisterPluginChannels(channels); // private and only adds to internal data structures, not sending messages + // TODO: send ServerHello + } +} diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index 0bc48a9f56..f60883b9d0 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -714,20 +714,7 @@ void cProtocol_1_9_0::SendLoginSuccess(void) Pkt.WriteString(m_Client->GetUsername()); } - if (m_ForgeHandshake.isForgeClient) { - AStringVector channels = { "FML|HS", "FML", "FML|MP", "FML", "FORGE" }; - AString channelsString; - - for (AStringVector::iterator itr = channels.begin(); itr != channels.end(); ++itr) - { - channelsString.append(*itr); - channelsString.push_back('\0'); - } - - m_Client->SendPluginMessage("REGISTER", channelsString); - //m_Client->RegisterPluginChannels(channels); // private and only adds to internal data structures, not sending messages - // TODO: send ServerHello - } + m_ForgeHandshake.onLoginSuccess(m_Client); } From 3950cdab6c4fd7937a99fb22d3b5f804edb80d76 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 13:39:16 -0700 Subject: [PATCH 008/166] Send FML|HS ServerHello to Forge clients --- src/Protocol/ForgeHandshake.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 0dd041ad9f..0821171942 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -38,6 +38,22 @@ void cForgeHandshake::onLoginSuccess(cClientHandle * Client) Client->SendPluginMessage("REGISTER", channelsString); //m_Client->RegisterPluginChannels(channels); // private and only adds to internal data structures, not sending messages - // TODO: send ServerHello + + SendServerHello(Client); } } + +void cForgeHandshake::SendServerHello(cClientHandle * Client) +{ + AString message; + message.push_back('\0'); // Discriminator Byte Always 0 for ServerHello + message.push_back('\2'); // FML protocol Version Byte Determined from NetworkRegistery. Currently 2. + // Dimension TODO + message.push_back('\0'); + message.push_back('\0'); + message.push_back('\0'); + message.push_back('\0'); + + + Client->SendPluginMessage("FML|HS", message); +} From 60fedd77d15727a81f5338fd0be2f6340d9aa84a Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 14:35:09 -0700 Subject: [PATCH 009/166] Listen for FML|HS in ForgeDataReceived, client hello --- src/ClientHandle.cpp | 4 ++ src/Protocol/ForgeHandshake.cpp | 80 ++++++++++++++++++++++++++++++++- src/Protocol/Protocol.h | 4 ++ src/Protocol/Protocol_1_9.cpp | 2 +- 4 files changed, 87 insertions(+), 3 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 1b63153d27..d4a4cbe465 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -852,6 +852,10 @@ void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString { UnregisterPluginChannels(BreakApartPluginChannels(a_Message)); } + else if (a_Channel == "FML|HS") + { + m_Protocol->ForgeDataReceived(a_Message.c_str(), a_Message.size()); + } else if (!HasPluginChannel(a_Channel)) { // Ignore if client sent something but didn't register the channel first diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 0821171942..9afec399c4 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -9,6 +9,13 @@ #include "json/json.h" #include "../ClientHandle.h" +cForgeHandshake::cForgeHandshake() +{ + LOG("Initializing new cForgeHandshake %p", static_cast(this)); + isForgeClient = false; + stage = UNKNOWN; +} + void cForgeHandshake::augmentServerListPing(Json::Value & ResponseValue) { // modinfo: @@ -24,6 +31,13 @@ void cForgeHandshake::augmentServerListPing(Json::Value & ResponseValue) ResponseValue["modinfo"] = Modinfo; } +void cForgeHandshake::setIsForgeClient(bool flag) +{ + LOG("Setting isForgeClient = %d of %p", flag, static_cast(this)); + isForgeClient = flag; +} + + void cForgeHandshake::onLoginSuccess(cClientHandle * Client) { if (isForgeClient) { @@ -39,6 +53,7 @@ void cForgeHandshake::onLoginSuccess(cClientHandle * Client) Client->SendPluginMessage("REGISTER", channelsString); //m_Client->RegisterPluginChannels(channels); // private and only adds to internal data structures, not sending messages + stage = START; SendServerHello(Client); } } @@ -46,7 +61,7 @@ void cForgeHandshake::onLoginSuccess(cClientHandle * Client) void cForgeHandshake::SendServerHello(cClientHandle * Client) { AString message; - message.push_back('\0'); // Discriminator Byte Always 0 for ServerHello + message.push_back(Discriminator_ServerHello); // Discriminator Byte Always 0 for ServerHello message.push_back('\2'); // FML protocol Version Byte Determined from NetworkRegistery. Currently 2. // Dimension TODO message.push_back('\0'); @@ -54,6 +69,67 @@ void cForgeHandshake::SendServerHello(cClientHandle * Client) message.push_back('\0'); message.push_back('\0'); - + stage = HELLO; Client->SendPluginMessage("FML|HS", message); } + +void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) +{ + /// XXX TODO: fix this, there are two cForgeHandshake instances, one in cProtocolRecognizer another in cProtocol_1_9 (both inherit cProtocol), + // and the wrong one has the Forge client set, so it is not recognized here! + if (!isForgeClient) { + LOG("Received unexpected Forge data from non-Forge client (%zu bytes)", a_Size); + return; + } + + LOG("Received Forge data: %zu bytes: %s", a_Size, a_Data); + + if (a_Size <= 1) { + LOG("Received unexpectedly short Forge data (%zu bytes)", a_Size); + return; + } + + int discriminator = a_Data[0]; + + switch (stage) + { + case HELLO: + { + switch (discriminator) + { + case Discriminator_ClientHello: + { + LOG("Received ClientHello"); + if (a_Size == 2) + { + int fmlProtocolVersion = a_Data[1]; + LOG("Unsupported FML client protocol version received in ClientHello: %d", fmlProtocolVersion); + stage = ERROR; + } + else + { + LOG("Unexpectedly short ClientHello received"); + stage = ERROR; + } + + break; + } + + case Discriminator_ModList: + LOG("Received ModList"); + // TODO: parse client ModList + // TODO: send server ModList + break; + + default: + LOG("Unexpected Forge packet %d received in %d stage", discriminator, stage); + stage = ERROR; + return; + } + } + + default: + { + } + } +} diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index 9914a19e61..4077ed4ffc 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -63,6 +63,10 @@ class cProtocol /** Called when client sends some data */ virtual void DataReceived(const char * a_Data, size_t a_Size) = 0; + void ForgeDataReceived(const char * a_Data, size_t a_Size) + { + m_ForgeHandshake.DataReceived(a_Data, a_Size); + } // Sending stuff to clients (alphabetically sorted): virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity & a_Vehicle) = 0; diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index f60883b9d0..28c9453622 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -130,7 +130,7 @@ cProtocol_1_9_0::cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_Ser if (Params[1] == "FML") { LOG("Forge client connected!"); - m_ForgeHandshake.isForgeClient = true; + m_ForgeHandshake.setIsForgeClient(true); } else if (Params.size() == 4) { if (cRoot::Get()->GetServer()->ShouldAllowBungeeCord()) { // BungeeCord handling: From 9dc47b24583f67d88cb2864cba5cb27a46e7a8aa Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 14:47:56 -0700 Subject: [PATCH 010/166] Move cForgeHandshake instance to cClientHandle to fix duplication causing state discrepancy between cProtocolRecognizer and cProtocol_1_9_0, both cProtocol subclasses --- src/ClientHandle.h | 3 +++ src/Protocol/Protocol.h | 7 ++----- src/Protocol/Protocol_1_10.cpp | 2 +- src/Protocol/Protocol_1_11.cpp | 4 ++-- src/Protocol/Protocol_1_12.cpp | 2 +- src/Protocol/Protocol_1_8.cpp | 2 +- src/Protocol/Protocol_1_9.cpp | 12 ++++++------ 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 4c37262c2a..6dad0f9669 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -21,6 +21,7 @@ #include "json/json.h" #include "ChunkSender.h" #include "EffectID.h" +#include "Protocol/ForgeHandshake.h" #include @@ -376,6 +377,8 @@ class cClientHandle // tolua_export void InvalidateCachedSentChunk(); bool IsPlayerChunkSent(); + + cForgeHandshake m_ForgeHandshake; private: /** The dimension that was last sent to a player in a Respawn or Login packet. diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index 4077ed4ffc..eaba6c3135 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -16,7 +16,7 @@ #include "../Map.h" #include "../ByteBuffer.h" #include "../EffectID.h" -#include "ForgeHandshake.h" +#include "../ClientHandle.h" #include @@ -65,7 +65,7 @@ class cProtocol virtual void DataReceived(const char * a_Data, size_t a_Size) = 0; void ForgeDataReceived(const char * a_Data, size_t a_Size) { - m_ForgeHandshake.DataReceived(a_Data, a_Size); + m_Client->m_ForgeHandshake.DataReceived(a_Data, a_Size); } // Sending stuff to clients (alphabetically sorted): @@ -171,9 +171,6 @@ class cProtocol /** Buffer for composing packet length (so that each cPacketizer instance doesn't allocate a new cPacketBuffer) */ cByteBuffer m_OutPacketLenBuffer; - - /** Forge protocol handshaking */ - cForgeHandshake m_ForgeHandshake; /** A generic data-sending routine, all outgoing packet data needs to be routed through this so that descendants may override it. */ virtual void SendData(const char * a_Data, size_t a_Size) = 0; diff --git a/src/Protocol/Protocol_1_10.cpp b/src/Protocol/Protocol_1_10.cpp index 246b4f99a3..3f3e7ad93e 100644 --- a/src/Protocol/Protocol_1_10.cpp +++ b/src/Protocol/Protocol_1_10.cpp @@ -346,7 +346,7 @@ void cProtocol_1_10_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_11.cpp b/src/Protocol/Protocol_1_11.cpp index d720e4bc45..2e6ab787f5 100644 --- a/src/Protocol/Protocol_1_11.cpp +++ b/src/Protocol/Protocol_1_11.cpp @@ -586,7 +586,7 @@ void cProtocol_1_11_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -1192,7 +1192,7 @@ void cProtocol_1_11_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp index e38872e59c..185a30aa6a 100644 --- a/src/Protocol/Protocol_1_12.cpp +++ b/src/Protocol/Protocol_1_12.cpp @@ -399,7 +399,7 @@ void cProtocol_1_12::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp index b930bc25ea..100e8b6164 100644 --- a/src/Protocol/Protocol_1_8.cpp +++ b/src/Protocol/Protocol_1_8.cpp @@ -2135,7 +2135,7 @@ void cProtocol_1_8_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index 28c9453622..cc0f5a8b92 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -130,7 +130,7 @@ cProtocol_1_9_0::cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_Ser if (Params[1] == "FML") { LOG("Forge client connected!"); - m_ForgeHandshake.setIsForgeClient(true); + m_Client->m_ForgeHandshake.setIsForgeClient(true); } else if (Params.size() == 4) { if (cRoot::Get()->GetServer()->ShouldAllowBungeeCord()) { // BungeeCord handling: @@ -714,7 +714,7 @@ void cProtocol_1_9_0::SendLoginSuccess(void) Pkt.WriteString(m_Client->GetUsername()); } - m_ForgeHandshake.onLoginSuccess(m_Client); + m_Client->m_ForgeHandshake.onLoginSuccess(m_Client); } @@ -2178,7 +2178,7 @@ void cProtocol_1_9_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4180,7 +4180,7 @@ void cProtocol_1_9_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4238,7 +4238,7 @@ void cProtocol_1_9_2::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4296,7 +4296,7 @@ void cProtocol_1_9_4::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); From 506bebd919598ab5a1a902d52c0932d3d074d1d8 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 14:48:58 -0700 Subject: [PATCH 011/166] Fix recognizing FML protocol version 2 in ClientHello field --- src/Protocol/ForgeHandshake.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 9afec399c4..e7636270cf 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -99,12 +99,14 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) { case Discriminator_ClientHello: { - LOG("Received ClientHello"); if (a_Size == 2) { int fmlProtocolVersion = a_Data[1]; - LOG("Unsupported FML client protocol version received in ClientHello: %d", fmlProtocolVersion); - stage = ERROR; + LOG("Received ClientHello with FML protocol version %d", fmlProtocolVersion); + if (fmlProtocolVersion != 2) { + LOG("Unsupported FML client protocol version received in ClientHello: %d", fmlProtocolVersion); + stage = ERROR; + } } else { From e299ad36c5ac10af170732837878fb6a0cd740f1 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 15:03:59 -0700 Subject: [PATCH 012/166] Add m_Client member to m_ForgeHandshake, move from parameters --- src/ClientHandle.cpp | 1 + src/Protocol/ForgeHandshake.cpp | 43 ++++++++++++++++++--------------- src/Protocol/Protocol_1_9.cpp | 2 +- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index d4a4cbe465..4b579a6f3c 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -64,6 +64,7 @@ float cClientHandle::FASTBREAK_PERCENTAGE; // cClientHandle: cClientHandle::cClientHandle(const AString & a_IPString, int a_ViewDistance) : + m_ForgeHandshake(this), m_LastSentDimension(dimNotSet), m_CurrentViewDistance(a_ViewDistance), m_RequestedViewDistance(a_ViewDistance), diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index e7636270cf..78474d4c0e 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -9,13 +9,14 @@ #include "json/json.h" #include "../ClientHandle.h" -cForgeHandshake::cForgeHandshake() +cForgeHandshake::cForgeHandshake(cClientHandle *client) : m_Client(client), m_isForgeClient(false), m_stage(UNKNOWN) { - LOG("Initializing new cForgeHandshake %p", static_cast(this)); - isForgeClient = false; - stage = UNKNOWN; } + + + + void cForgeHandshake::augmentServerListPing(Json::Value & ResponseValue) { // modinfo: @@ -34,13 +35,13 @@ void cForgeHandshake::augmentServerListPing(Json::Value & ResponseValue) void cForgeHandshake::setIsForgeClient(bool flag) { LOG("Setting isForgeClient = %d of %p", flag, static_cast(this)); - isForgeClient = flag; + m_isForgeClient = flag; } -void cForgeHandshake::onLoginSuccess(cClientHandle * Client) +void cForgeHandshake::onLoginSuccess() { - if (isForgeClient) { + if (m_isForgeClient) { AStringVector channels = { "FML|HS", "FML", "FML|MP", "FML", "FORGE" }; AString channelsString; @@ -50,15 +51,15 @@ void cForgeHandshake::onLoginSuccess(cClientHandle * Client) channelsString.push_back('\0'); } - Client->SendPluginMessage("REGISTER", channelsString); + m_Client->SendPluginMessage("REGISTER", channelsString); //m_Client->RegisterPluginChannels(channels); // private and only adds to internal data structures, not sending messages - stage = START; - SendServerHello(Client); + m_stage = START; + SendServerHello(); } } -void cForgeHandshake::SendServerHello(cClientHandle * Client) +void cForgeHandshake::SendServerHello() { AString message; message.push_back(Discriminator_ServerHello); // Discriminator Byte Always 0 for ServerHello @@ -69,15 +70,15 @@ void cForgeHandshake::SendServerHello(cClientHandle * Client) message.push_back('\0'); message.push_back('\0'); - stage = HELLO; - Client->SendPluginMessage("FML|HS", message); + m_stage = HELLO; + m_Client->SendPluginMessage("FML|HS", message); } void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) { /// XXX TODO: fix this, there are two cForgeHandshake instances, one in cProtocolRecognizer another in cProtocol_1_9 (both inherit cProtocol), // and the wrong one has the Forge client set, so it is not recognized here! - if (!isForgeClient) { + if (!m_isForgeClient) { LOG("Received unexpected Forge data from non-Forge client (%zu bytes)", a_Size); return; } @@ -91,7 +92,7 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) int discriminator = a_Data[0]; - switch (stage) + switch (m_stage) { case HELLO: { @@ -105,27 +106,31 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) LOG("Received ClientHello with FML protocol version %d", fmlProtocolVersion); if (fmlProtocolVersion != 2) { LOG("Unsupported FML client protocol version received in ClientHello: %d", fmlProtocolVersion); - stage = ERROR; + m_stage = ERROR; } } else { LOG("Unexpectedly short ClientHello received"); - stage = ERROR; + m_stage = ERROR; } break; } case Discriminator_ModList: + { LOG("Received ModList"); // TODO: parse client ModList + // TODO: send server ModList + break; + } default: - LOG("Unexpected Forge packet %d received in %d stage", discriminator, stage); - stage = ERROR; + LOG("Unexpected Forge packet %d received in %d stage", discriminator, m_stage); + m_stage = ERROR; return; } } diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index cc0f5a8b92..1d36f8ae56 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -714,7 +714,7 @@ void cProtocol_1_9_0::SendLoginSuccess(void) Pkt.WriteString(m_Client->GetUsername()); } - m_Client->m_ForgeHandshake.onLoginSuccess(m_Client); + m_Client->m_ForgeHandshake.onLoginSuccess(); } From 62b57cc9f193bd8674ac76190a35817e1fc41410 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 15:27:08 -0700 Subject: [PATCH 013/166] Send client modlist back in server modlist packet --- src/Protocol/ForgeHandshake.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 78474d4c0e..9a85cabdb1 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -76,8 +76,6 @@ void cForgeHandshake::SendServerHello() void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) { - /// XXX TODO: fix this, there are two cForgeHandshake instances, one in cProtocolRecognizer another in cProtocol_1_9 (both inherit cProtocol), - // and the wrong one has the Forge client set, so it is not recognized here! if (!m_isForgeClient) { LOG("Received unexpected Forge data from non-Forge client (%zu bytes)", a_Size); return; @@ -124,7 +122,17 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) // TODO: parse client ModList // TODO: send server ModList + AString serverModList; + /* + serverModList.push_back(Discriminator_ModList); + serverModList.push_back('\0'); // TODO: number of mods varint + // TODO: array of strings of mod name and version + // TODO: this should match ModList sent in status packet + */ + serverModList.assign(a_Data, a_Size); // just echoing back client's mods for now + // TODO: fix + m_Client->SendPluginMessage("FML|HS", serverModList); break; } From 91e908d2f6ad2654f6cb94972572c64674b6e6dc Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 16:52:46 -0700 Subject: [PATCH 014/166] Send encoded server ModList --- src/Protocol/ForgeHandshake.cpp | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 9a85cabdb1..f265ef5e1d 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -121,16 +121,30 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) LOG("Received ModList"); // TODO: parse client ModList - // TODO: send server ModList + // Send server ModList + + cByteBuffer buf(1024); // TODO: max size? + + // TODO: allow plugins to register mods, for now, using based on what my test client sent + struct { + AString name; + AString version; + } mods[] = { + { "minecraft", "1.12" }, + { "FML", "8.0.99.999.forge" }, + { "forge", "14.21.1.2387.mcp-XXX" }, + { "ironchest", "1.12-7.0.31.818" }, + }; + int modCount = sizeof(mods) / sizeof(mods[0]); + + buf.WriteBEInt8(Discriminator_ModList); + buf.WriteVarInt32(modCount); + for (int i = 0; i < modCount; ++i) { + buf.WriteVarUTF8String(mods[i].name); + buf.WriteVarUTF8String(mods[i].version); + } AString serverModList; - /* - serverModList.push_back(Discriminator_ModList); - serverModList.push_back('\0'); // TODO: number of mods varint - // TODO: array of strings of mod name and version - // TODO: this should match ModList sent in status packet - */ - serverModList.assign(a_Data, a_Size); // just echoing back client's mods for now - // TODO: fix + buf.ReadAll(serverModList); m_Client->SendPluginMessage("FML|HS", serverModList); break; From 86d8c2768e43b8311256327b1c0c4c3a5e394203 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 17:01:46 -0700 Subject: [PATCH 015/166] Receive HandshakeAck packets with phase byte --- src/Protocol/ForgeHandshake.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index f265ef5e1d..80008aea0b 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -146,6 +146,7 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) AString serverModList; buf.ReadAll(serverModList); + m_stage = WAITINGCACK; m_Client->SendPluginMessage("FML|HS", serverModList); break; } @@ -157,8 +158,33 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) } } + case WAITINGCACK: + { + switch (discriminator) + { + case Discriminator_HandshakeAck: + { + if (a_Size != 2) + { + LOG("Unexpected HandshakeAck packet length: %zu", a_Size); + m_stage = ERROR; + break; + } + + int phase = a_Data[1]; + LOG("Received client HandshakeAck with phase=%d", phase); + // TODO: if phase=2 WAITINGSERVERDATA then send RegistryData + break; + } + default: + LOG("Unknown packet received in WAITINGCACK: %d", discriminator); + } + break; + } + default: { + LOG("Forge client/server state invalidated: %d", m_stage); } } } From 3b0dbab33ddccdd5e3f63787bf498017e5440292 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 17:08:40 -0700 Subject: [PATCH 016/166] Simplify ForgeHandshake switch on discriminator --- src/Protocol/ForgeHandshake.cpp | 144 ++++++++++++++------------------ 1 file changed, 62 insertions(+), 82 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 80008aea0b..adc20a8a65 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -90,101 +90,81 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) int discriminator = a_Data[0]; - switch (m_stage) + switch (discriminator) { - case HELLO: + case Discriminator_ClientHello: { - switch (discriminator) + if (a_Size == 2) { - case Discriminator_ClientHello: - { - if (a_Size == 2) - { - int fmlProtocolVersion = a_Data[1]; - LOG("Received ClientHello with FML protocol version %d", fmlProtocolVersion); - if (fmlProtocolVersion != 2) { - LOG("Unsupported FML client protocol version received in ClientHello: %d", fmlProtocolVersion); - m_stage = ERROR; - } - } - else - { - LOG("Unexpectedly short ClientHello received"); - m_stage = ERROR; - } - - break; - } - - case Discriminator_ModList: - { - LOG("Received ModList"); - // TODO: parse client ModList - - // Send server ModList - - cByteBuffer buf(1024); // TODO: max size? - - // TODO: allow plugins to register mods, for now, using based on what my test client sent - struct { - AString name; - AString version; - } mods[] = { - { "minecraft", "1.12" }, - { "FML", "8.0.99.999.forge" }, - { "forge", "14.21.1.2387.mcp-XXX" }, - { "ironchest", "1.12-7.0.31.818" }, - }; - int modCount = sizeof(mods) / sizeof(mods[0]); - - buf.WriteBEInt8(Discriminator_ModList); - buf.WriteVarInt32(modCount); - for (int i = 0; i < modCount; ++i) { - buf.WriteVarUTF8String(mods[i].name); - buf.WriteVarUTF8String(mods[i].version); - } - AString serverModList; - buf.ReadAll(serverModList); - - m_stage = WAITINGCACK; - m_Client->SendPluginMessage("FML|HS", serverModList); - break; - } - - default: - LOG("Unexpected Forge packet %d received in %d stage", discriminator, m_stage); + int fmlProtocolVersion = a_Data[1]; + LOG("Received ClientHello with FML protocol version %d", fmlProtocolVersion); + if (fmlProtocolVersion != 2) { + LOG("Unsupported FML client protocol version received in ClientHello: %d", fmlProtocolVersion); m_stage = ERROR; - return; + } } + else + { + LOG("Unexpectedly short ClientHello received"); + m_stage = ERROR; + } + + break; } - case WAITINGCACK: + case Discriminator_ModList: { - switch (discriminator) - { - case Discriminator_HandshakeAck: - { - if (a_Size != 2) - { - LOG("Unexpected HandshakeAck packet length: %zu", a_Size); - m_stage = ERROR; - break; - } - - int phase = a_Data[1]; - LOG("Received client HandshakeAck with phase=%d", phase); - // TODO: if phase=2 WAITINGSERVERDATA then send RegistryData - break; - } - default: - LOG("Unknown packet received in WAITINGCACK: %d", discriminator); + LOG("Received ModList"); + // TODO: parse client ModList + + // Send server ModList + + cByteBuffer buf(1024); // TODO: max size? + + // TODO: allow plugins to register mods, for now, using based on what my test client sent + struct { + AString name; + AString version; + } mods[] = { + { "minecraft", "1.12" }, + { "FML", "8.0.99.999.forge" }, + { "forge", "14.21.1.2387.mcp-XXX" }, + { "ironchest", "1.12-7.0.31.818" }, + }; + int modCount = sizeof(mods) / sizeof(mods[0]); + + buf.WriteBEInt8(Discriminator_ModList); + buf.WriteVarInt32(modCount); + for (int i = 0; i < modCount; ++i) { + buf.WriteVarUTF8String(mods[i].name); + buf.WriteVarUTF8String(mods[i].version); } + AString serverModList; + buf.ReadAll(serverModList); + + m_stage = WAITINGCACK; + m_Client->SendPluginMessage("FML|HS", serverModList); break; } - default: + case Discriminator_HandshakeAck: { - LOG("Forge client/server state invalidated: %d", m_stage); + if (a_Size != 2) + { + LOG("Unexpected HandshakeAck packet length: %zu", a_Size); + m_stage = ERROR; + break; + } + + int phase = a_Data[1]; + LOG("Received client HandshakeAck with phase=%d", phase); + // TODO: if phase=2 WAITINGSERVERDATA then send RegistryData + break; } + + default: + LOG("Unexpected Forge packet %d received in %d stage", discriminator, m_stage); + m_stage = ERROR; + return; } } From f9b337b45d6e37f75b9ba18e54fe0355785175b7 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 17:33:21 -0700 Subject: [PATCH 017/166] Call BeginForgeHandshake() in cClientHandle::Authenticate() instead --- src/ClientHandle.cpp | 5 ++++ src/Protocol/ForgeHandshake.cpp | 41 +++++++++++++++------------------ src/Protocol/Protocol_1_9.cpp | 4 +--- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 4b579a6f3c..f83ed5ea48 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -353,6 +353,11 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, // Send login success (if the protocol supports it): m_Protocol->SendLoginSuccess(); + + if (m_ForgeHandshake.m_isForgeClient) { + m_ForgeHandshake.BeginForgeHandshake(); + // TODO: only continue below after Forge handshake completes! + } // Spawn player (only serversided, so data is loaded) m_Player = new cPlayer(m_Self, GetUsername()); diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index adc20a8a65..f08dc192c6 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -9,7 +9,7 @@ #include "json/json.h" #include "../ClientHandle.h" -cForgeHandshake::cForgeHandshake(cClientHandle *client) : m_Client(client), m_isForgeClient(false), m_stage(UNKNOWN) +cForgeHandshake::cForgeHandshake(cClientHandle *client) : m_isForgeClient(false), m_Client(client), m_stage(UNKNOWN) { } @@ -32,31 +32,28 @@ void cForgeHandshake::augmentServerListPing(Json::Value & ResponseValue) ResponseValue["modinfo"] = Modinfo; } -void cForgeHandshake::setIsForgeClient(bool flag) -{ - LOG("Setting isForgeClient = %d of %p", flag, static_cast(this)); - m_isForgeClient = flag; -} -void cForgeHandshake::onLoginSuccess() + + +void cForgeHandshake::BeginForgeHandshake() { - if (m_isForgeClient) { - AStringVector channels = { "FML|HS", "FML", "FML|MP", "FML", "FORGE" }; - AString channelsString; - - for (AStringVector::iterator itr = channels.begin(); itr != channels.end(); ++itr) - { - channelsString.append(*itr); - channelsString.push_back('\0'); - } - - m_Client->SendPluginMessage("REGISTER", channelsString); - //m_Client->RegisterPluginChannels(channels); // private and only adds to internal data structures, not sending messages - - m_stage = START; - SendServerHello(); + ASSERT(m_isForgeClient); + + AStringVector channels = { "FML|HS", "FML", "FML|MP", "FML", "FORGE" }; + AString channelsString; + + for (AStringVector::iterator itr = channels.begin(); itr != channels.end(); ++itr) + { + channelsString.append(*itr); + channelsString.push_back('\0'); } + + m_Client->SendPluginMessage("REGISTER", channelsString); + //m_Client->RegisterPluginChannels(channels); // private and only adds to internal data structures, not sending messages + + m_stage = START; + SendServerHello(); } void cForgeHandshake::SendServerHello() diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index 1d36f8ae56..07098094b1 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -130,7 +130,7 @@ cProtocol_1_9_0::cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_Ser if (Params[1] == "FML") { LOG("Forge client connected!"); - m_Client->m_ForgeHandshake.setIsForgeClient(true); + m_Client->m_ForgeHandshake.m_isForgeClient = true; } else if (Params.size() == 4) { if (cRoot::Get()->GetServer()->ShouldAllowBungeeCord()) { // BungeeCord handling: @@ -713,8 +713,6 @@ void cProtocol_1_9_0::SendLoginSuccess(void) Pkt.WriteString(cMojangAPI::MakeUUIDDashed(m_Client->GetUUID())); Pkt.WriteString(m_Client->GetUsername()); } - - m_Client->m_ForgeHandshake.onLoginSuccess(); } From 31887fde52278ec445617e651825523f99c3bcbe Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 17:53:06 -0700 Subject: [PATCH 018/166] Try using a cCriticalSection, but not locked by current thread --- src/Protocol/ForgeHandshake.cpp | 35 +++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index f08dc192c6..f51bbc9f1b 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -3,9 +3,8 @@ // Implements Forge protocol handshaking -#include "ForgeHandshake.h" - #include "Globals.h" +#include "ForgeHandshake.h" #include "json/json.h" #include "../ClientHandle.h" @@ -53,9 +52,20 @@ void cForgeHandshake::BeginForgeHandshake() //m_Client->RegisterPluginChannels(channels); // private and only adds to internal data structures, not sending messages m_stage = START; + LOG("BeginForgeHandshake lock1"); + m_CSLock.Lock(); + SendServerHello(); + + LOG("BeginForgeHandshake lock2"); + m_CSLock.Lock(); + // wait until received } + + + + void cForgeHandshake::SendServerHello() { AString message; @@ -97,13 +107,13 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) LOG("Received ClientHello with FML protocol version %d", fmlProtocolVersion); if (fmlProtocolVersion != 2) { LOG("Unsupported FML client protocol version received in ClientHello: %d", fmlProtocolVersion); - m_stage = ERROR; + SetError(); } } else { LOG("Unexpectedly short ClientHello received"); - m_stage = ERROR; + SetError(); } break; @@ -149,19 +159,32 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) if (a_Size != 2) { LOG("Unexpected HandshakeAck packet length: %zu", a_Size); - m_stage = ERROR; + SetError(); break; } int phase = a_Data[1]; LOG("Received client HandshakeAck with phase=%d", phase); // TODO: if phase=2 WAITINGSERVERDATA then send RegistryData + + // continue + LOG("Continuing"); + m_CSLock.Unlock(); break; } default: LOG("Unexpected Forge packet %d received in %d stage", discriminator, m_stage); - m_stage = ERROR; + SetError(); return; } } + + + + + +void cForgeHandshake::SetError() { + m_stage = ERROR; + //TODO if (m_CSLock.IsLocked()) m_CSLock.Unlock(); +} From 40551e1a14f0a311716e0f079dbabbcf9f40b92f Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 17:54:22 -0700 Subject: [PATCH 019/166] Remove broken m_CSLock in cForgeHandshake --- src/Protocol/ForgeHandshake.cpp | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index f51bbc9f1b..1a50a0c809 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -50,16 +50,6 @@ void cForgeHandshake::BeginForgeHandshake() m_Client->SendPluginMessage("REGISTER", channelsString); //m_Client->RegisterPluginChannels(channels); // private and only adds to internal data structures, not sending messages - - m_stage = START; - LOG("BeginForgeHandshake lock1"); - m_CSLock.Lock(); - - SendServerHello(); - - LOG("BeginForgeHandshake lock2"); - m_CSLock.Lock(); - // wait until received } @@ -166,11 +156,6 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) int phase = a_Data[1]; LOG("Received client HandshakeAck with phase=%d", phase); // TODO: if phase=2 WAITINGSERVERDATA then send RegistryData - - // continue - LOG("Continuing"); - m_CSLock.Unlock(); - break; } default: From ad5cb6843d3aedab8aea1aca9fc8aea2bb0d680d Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 18:31:20 -0700 Subject: [PATCH 020/166] Move second half of Authenticate into PostAuthenticate --- src/ClientHandle.cpp | 15 +++++++++++++-- src/ClientHandle.h | 3 +++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index f83ed5ea48..8f8715406b 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -323,7 +323,6 @@ void cClientHandle::Kick(const AString & a_Reason) void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties) { - cWorld * World; { cCSLock lock(m_CSState); /* @@ -354,11 +353,23 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, // Send login success (if the protocol supports it): m_Protocol->SendLoginSuccess(); - if (m_ForgeHandshake.m_isForgeClient) { + if (m_ForgeHandshake.m_isForgeClient) { m_ForgeHandshake.BeginForgeHandshake(); // TODO: only continue below after Forge handshake completes! } + + PostAuthenticate(a_Name, a_UUID, a_Properties); + } +} + + + + +void cClientHandle::PostAuthenticate(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties) +{ + cWorld * World; + { // Spawn player (only serversided, so data is loaded) m_Player = new cPlayer(m_Self, GetUsername()); /* diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 6dad0f9669..34698490f2 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -534,6 +534,9 @@ class cClientHandle // tolua_export cClientHandlePtr m_Self; float m_BreakProgress; + + /** Finish logging the user in after authenticating. */ + void PostAuthenticate(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties); /** Returns true if the rate block interactions is within a reasonable limit (bot protection) */ bool CheckBlockInteractionsRate(void); From 8969bd6f65da5832da0387311d103f5254ff04a7 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 19:09:44 -0700 Subject: [PATCH 021/166] cForgeHandshake calls PostAuthenticate after completing --- src/ClientHandle.cpp | 10 ++++++---- src/ClientHandle.h | 3 ++- src/Protocol/ForgeHandshake.cpp | 9 +++++++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 8f8715406b..b46fee37d4 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -349,16 +349,18 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, { m_Properties = a_Properties; } - + // Send login success (if the protocol supports it): m_Protocol->SendLoginSuccess(); if (m_ForgeHandshake.m_isForgeClient) { - m_ForgeHandshake.BeginForgeHandshake(); + m_ForgeHandshake.BeginForgeHandshake(a_Name, a_UUID, a_Properties); // TODO: only continue below after Forge handshake completes! } - - PostAuthenticate(a_Name, a_UUID, a_Properties); + else + { + PostAuthenticate(a_Name, a_UUID, a_Properties); + } } } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 34698490f2..d072a7ea64 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -386,7 +386,8 @@ class cClientHandle // tolua_export eDimension m_LastSentDimension; friend class cServer; // Needs access to SetSelf() - + + friend class cForgeHandshake; // Needs access to PostAuthenticate() /** The type used for storing the names of registered plugin channels. */ typedef std::set cChannels; diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 1a50a0c809..230b2695dd 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -35,10 +35,14 @@ void cForgeHandshake::augmentServerListPing(Json::Value & ResponseValue) -void cForgeHandshake::BeginForgeHandshake() +void cForgeHandshake::BeginForgeHandshake(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties) { ASSERT(m_isForgeClient); + m_Name = &a_Name; + m_UUID = &a_UUID; + m_Properties = &a_Properties; + AStringVector channels = { "FML|HS", "FML", "FML|MP", "FML", "FORGE" }; AString channelsString; @@ -49,7 +53,6 @@ void cForgeHandshake::BeginForgeHandshake() } m_Client->SendPluginMessage("REGISTER", channelsString); - //m_Client->RegisterPluginChannels(channels); // private and only adds to internal data structures, not sending messages } @@ -156,6 +159,8 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) int phase = a_Data[1]; LOG("Received client HandshakeAck with phase=%d", phase); // TODO: if phase=2 WAITINGSERVERDATA then send RegistryData + + m_Client->PostAuthenticate(*m_Name, *m_UUID, *m_Properties); } default: From 61d191927f613152d9f2b6a65ef18513747e0eab Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 19:09:57 -0700 Subject: [PATCH 022/166] Add missing SendServerHello() in BeginForgeHandshake() --- src/Protocol/ForgeHandshake.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 230b2695dd..0c388a0cce 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -53,6 +53,7 @@ void cForgeHandshake::BeginForgeHandshake(const AString & a_Name, const AString } m_Client->SendPluginMessage("REGISTER", channelsString); + SendServerHello(); } From bff3bc7a28ca8b1620c7a2f073cc30c449f161af Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 19:12:56 -0700 Subject: [PATCH 023/166] Add missing ForgeHandshake.h --- src/Protocol/ForgeHandshake.h | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/Protocol/ForgeHandshake.h diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h new file mode 100644 index 0000000000..5f366c2605 --- /dev/null +++ b/src/Protocol/ForgeHandshake.h @@ -0,0 +1,58 @@ + +// ForgeHandshake.h + +// Implements Forge protocol handshaking + +#pragma once + +#include + +// fwd: +namespace Json +{ + class Value; +} +class cClientHandle; + +class cForgeHandshake +{ +public: + cForgeHandshake(cClientHandle * client); + + void augmentServerListPing(Json::Value & ResponseValue); + void BeginForgeHandshake(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties); + + void SendServerHello(); + void DataReceived(const char * a_Data, size_t a_Size); + + bool m_isForgeClient; + +private: + void SetError(); + + cClientHandle * m_Client; + + const AString * m_Name; + const AString * m_UUID; + const Json::Value * m_Properties; + + + enum Stage { + UNKNOWN, + START, + HELLO, + WAITINGCACK, + COMPLETE, + DONE, + ERROR, + } m_stage; + + enum { + Discriminator_ServerHello = 0, + Discriminator_ClientHello = 1, + Discriminator_ModList = 2, + Discriminator_RegistryData = 3, + Discriminator_HandshakeReset = 254, + Discriminator_HandshakeAck = 255, + }; +}; From 1fe784eeb2d9fd26300e1fe5783e7c9655ded974 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 19:13:08 -0700 Subject: [PATCH 024/166] Fixed signedness error in discriminator, -1 not 255 --- src/Protocol/ForgeHandshake.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index 5f366c2605..75042be252 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -52,7 +52,7 @@ class cForgeHandshake Discriminator_ClientHello = 1, Discriminator_ModList = 2, Discriminator_RegistryData = 3, - Discriminator_HandshakeReset = 254, - Discriminator_HandshakeAck = 255, + Discriminator_HandshakeReset = -2, + Discriminator_HandshakeAck = -1, }; }; From 6906315418aefaa2904643a07ab3ffe4c5dace48 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 19:15:37 -0700 Subject: [PATCH 025/166] Rename PostAuthenticate to FinishAuthenticate since it actually sets the authenticated state --- src/ClientHandle.cpp | 4 ++-- src/ClientHandle.h | 2 +- src/Protocol/ForgeHandshake.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index b46fee37d4..40a83d6b74 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -359,7 +359,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, } else { - PostAuthenticate(a_Name, a_UUID, a_Properties); + FinishAuthenticate(a_Name, a_UUID, a_Properties); } } } @@ -368,7 +368,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, -void cClientHandle::PostAuthenticate(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties) +void cClientHandle::FinishAuthenticate(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties) { cWorld * World; { diff --git a/src/ClientHandle.h b/src/ClientHandle.h index d072a7ea64..8bef0389b5 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -537,7 +537,7 @@ class cClientHandle // tolua_export float m_BreakProgress; /** Finish logging the user in after authenticating. */ - void PostAuthenticate(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties); + void FinishAuthenticate(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties); /** Returns true if the rate block interactions is within a reasonable limit (bot protection) */ bool CheckBlockInteractionsRate(void); diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 0c388a0cce..6306b82c2f 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -161,7 +161,7 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) LOG("Received client HandshakeAck with phase=%d", phase); // TODO: if phase=2 WAITINGSERVERDATA then send RegistryData - m_Client->PostAuthenticate(*m_Name, *m_UUID, *m_Properties); + m_Client->FinishAuthenticate(*m_Name, *m_UUID, *m_Properties); } default: From 367f2c1c8e22ebf7b07b58e9a73a36293b55af50 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 19:27:46 -0700 Subject: [PATCH 026/166] Implement the pending/completion acknowledgments, send stub registry --- src/Protocol/ForgeHandshake.cpp | 54 +++++++++++++++++++++++++++++++-- src/Protocol/ForgeHandshake.h | 20 ++++++++++-- 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 6306b82c2f..371005286a 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -159,9 +159,59 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) int phase = a_Data[1]; LOG("Received client HandshakeAck with phase=%d", phase); - // TODO: if phase=2 WAITINGSERVERDATA then send RegistryData - m_Client->FinishAuthenticate(*m_Name, *m_UUID, *m_Properties); + switch (phase) + { + case ClientPhase_WAITINGSERVERDATA: + { + cByteBuffer buf(1024); + buf.WriteBEInt8(Discriminator_RegistryData); + + // TODO: send real registry data + bool hasMore = false; + AString registryName = "nothing"; + int numIDs = 0; + int numSubstitutions = 0; + int numDummies = 0; + + buf.WriteBool(hasMore); + buf.WriteVarUTF8String(registryName); + buf.WriteVarInt32(numIDs); + buf.WriteVarInt32(numSubstitutions); + buf.WriteVarInt32(numDummies); + + AString registryData; + buf.ReadAll(registryData); + m_Client->SendPluginMessage("FML|HS", registryData); + break; + } + + case ClientPhase_WAITINGSERVERCOMPLETE: + { + LOG("Client finished receiving registry data; acknowledging"); + + + AString ack; + ack.push_back(Discriminator_HandshakeAck); + ack.push_back(ServerPhase_WAITINGCACK); + m_Client->SendPluginMessage("FML|HS", ack); + break; + } + + case ClientPhase_PENDINGCOMPLETE: + { + LOG("Client is pending completion; sending complete ack"); + + AString ack; + ack.push_back(Discriminator_HandshakeAck); + ack.push_back(ServerPhase_COMPLETE); + m_Client->SendPluginMessage("FML|HS", ack); + + // Now finish logging in + m_Client->FinishAuthenticate(*m_Name, *m_UUID, *m_Properties); + break; + } + } } default: diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index 75042be252..11c510e47f 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -37,7 +37,8 @@ class cForgeHandshake const Json::Value * m_Properties; - enum Stage { + enum Stage + { UNKNOWN, START, HELLO, @@ -47,7 +48,8 @@ class cForgeHandshake ERROR, } m_stage; - enum { + enum + { Discriminator_ServerHello = 0, Discriminator_ClientHello = 1, Discriminator_ModList = 2, @@ -55,4 +57,18 @@ class cForgeHandshake Discriminator_HandshakeReset = -2, Discriminator_HandshakeAck = -1, }; + + enum + { + ClientPhase_WAITINGSERVERDATA = 2, + ClientPhase_WAITINGSERVERCOMPLETE = 3, + ClientPhase_PENDINGCOMPLETE = 4, + ClientPhase_COMPLETE = 5, + }; + + enum + { + ServerPhase_WAITINGCACK = 2, + ServerPhase_COMPLETE = 3, + }; }; From 6b73390f38b9f5d87577f0ff96e87a2b4a234926 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 19:38:34 -0700 Subject: [PATCH 027/166] Use a valid registry id name, potions --- src/Protocol/ForgeHandshake.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 371005286a..c37d37e993 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -169,7 +169,7 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) // TODO: send real registry data bool hasMore = false; - AString registryName = "nothing"; + AString registryName = "potions"; int numIDs = 0; int numSubstitutions = 0; int numDummies = 0; From 3c5fca77555dde6533eac12e37748ea7fdd69a67 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 19:53:29 -0700 Subject: [PATCH 028/166] Remove semi-unused Stage enum --- src/Protocol/ForgeHandshake.cpp | 11 +++++------ src/Protocol/ForgeHandshake.h | 13 +------------ 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index c37d37e993..19722acb95 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -8,7 +8,7 @@ #include "json/json.h" #include "../ClientHandle.h" -cForgeHandshake::cForgeHandshake(cClientHandle *client) : m_isForgeClient(false), m_Client(client), m_stage(UNKNOWN) +cForgeHandshake::cForgeHandshake(cClientHandle *client) : m_isForgeClient(false), m_Errored(false), m_Client(client) { } @@ -71,7 +71,6 @@ void cForgeHandshake::SendServerHello() message.push_back('\0'); message.push_back('\0'); - m_stage = HELLO; m_Client->SendPluginMessage("FML|HS", message); } @@ -82,6 +81,8 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) return; } + // TODO: handle errors + LOG("Received Forge data: %zu bytes: %s", a_Size, a_Data); if (a_Size <= 1) { @@ -143,7 +144,6 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) AString serverModList; buf.ReadAll(serverModList); - m_stage = WAITINGCACK; m_Client->SendPluginMessage("FML|HS", serverModList); break; } @@ -215,7 +215,7 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) } default: - LOG("Unexpected Forge packet %d received in %d stage", discriminator, m_stage); + LOG("Unexpected Forge packet %d received", discriminator); SetError(); return; } @@ -226,6 +226,5 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) void cForgeHandshake::SetError() { - m_stage = ERROR; - //TODO if (m_CSLock.IsLocked()) m_CSLock.Unlock(); + m_Errored = true; } diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index 11c510e47f..2d843b7ec6 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -29,6 +29,7 @@ class cForgeHandshake private: void SetError(); + bool m_Errored; cClientHandle * m_Client; @@ -36,18 +37,6 @@ class cForgeHandshake const AString * m_UUID; const Json::Value * m_Properties; - - enum Stage - { - UNKNOWN, - START, - HELLO, - WAITINGCACK, - COMPLETE, - DONE, - ERROR, - } m_stage; - enum { Discriminator_ServerHello = 0, From 442d8f17283068dea7c248406eae54062b8d7341 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 9 Jul 2017 21:22:59 -0700 Subject: [PATCH 029/166] Fix signedness compile errors in counts in RegistryData --- src/Protocol/ForgeHandshake.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 19722acb95..d2e1974644 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -133,11 +133,11 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) { "forge", "14.21.1.2387.mcp-XXX" }, { "ironchest", "1.12-7.0.31.818" }, }; - int modCount = sizeof(mods) / sizeof(mods[0]); + UInt32 modCount = sizeof(mods) / sizeof(mods[0]); buf.WriteBEInt8(Discriminator_ModList); buf.WriteVarInt32(modCount); - for (int i = 0; i < modCount; ++i) { + for (size_t i = 0; i < modCount; ++i) { buf.WriteVarUTF8String(mods[i].name); buf.WriteVarUTF8String(mods[i].version); } @@ -170,9 +170,9 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) // TODO: send real registry data bool hasMore = false; AString registryName = "potions"; - int numIDs = 0; - int numSubstitutions = 0; - int numDummies = 0; + UInt32 numIDs = 0; + UInt32 numSubstitutions = 0; + UInt32 numDummies = 0; buf.WriteBool(hasMore); buf.WriteVarUTF8String(registryName); From 8b1eac59517f5f02b5809d7736e01cb35e7f3f99 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 11 Jul 2017 20:00:45 -0700 Subject: [PATCH 030/166] Add missing break in case Discriminator_HandshakeAck --- Server/Plugins/Core | 2 +- src/Protocol/ForgeHandshake.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Server/Plugins/Core b/Server/Plugins/Core index 3e8b70dcb1..68430458a3 160000 --- a/Server/Plugins/Core +++ b/Server/Plugins/Core @@ -1 +1 @@ -Subproject commit 3e8b70dcb11c7d5f8c6f68494b108b14c9fca141 +Subproject commit 68430458a3ea695cac85bc82136941bc83253e1e diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index d2e1974644..ce3908918c 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -212,6 +212,7 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) break; } } + break; } default: From d0a5426da179e5227b5e03c807f46cc64a5e8190 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 11 Jul 2017 20:10:01 -0700 Subject: [PATCH 031/166] Parse number of mods from client ModList --- src/Protocol/ForgeHandshake.cpp | 18 ++++++++++++++++++ src/Protocol/ForgeHandshake.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index ce3908918c..9a6711a70f 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -74,6 +74,23 @@ void cForgeHandshake::SendServerHello() m_Client->SendPluginMessage("FML|HS", message); } +void cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) +{ + cByteBuffer buf(a_Size); + buf.Write(a_Data, a_Size); + + Int8 discriminator; + buf.ReadBEInt8(discriminator); + LOG("ParseModList disc = %d", discriminator); + + ASSERT(discriminator == 2); + + UInt32 numMods; + buf.ReadVarInt32(numMods); + + LOG("ParseModList numMods = %d", numMods); +} + void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) { if (!m_isForgeClient) { @@ -118,6 +135,7 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) { LOG("Received ModList"); // TODO: parse client ModList + ParseModList(a_Data, a_Size); // Send server ModList diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index 2d843b7ec6..9f4f5af10b 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -25,6 +25,8 @@ class cForgeHandshake void SendServerHello(); void DataReceived(const char * a_Data, size_t a_Size); + void ParseModList(const char * a_Data, size_t a_Size); + bool m_isForgeClient; private: From 7fac6249c76a5eacaa937d16ff51e5d94700ebb4 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 11 Jul 2017 20:14:41 -0700 Subject: [PATCH 032/166] Parse mod name/version from client ModList --- src/Protocol/ForgeHandshake.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 9a6711a70f..aab46f7e39 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -89,6 +89,16 @@ void cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) buf.ReadVarInt32(numMods); LOG("ParseModList numMods = %d", numMods); + + for (size_t i = 0; i < numMods; ++i) + { + AString name, version; + buf.ReadVarUTF8String(name); + buf.ReadVarUTF8String(version); + + LOG("ParseModList name=%s, version=%s", name.c_str(), version.c_str()); + // TODO: add to map and return, AStringPairs? + } } void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) From 934c8a39951817060ad51d024453ba6e87595241 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 11 Jul 2017 20:23:46 -0700 Subject: [PATCH 033/166] Show client mod list on connecting, AStringMap --- src/Protocol/ForgeHandshake.cpp | 30 +++++++++++++++++++++++------- src/Protocol/ForgeHandshake.h | 2 +- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index aab46f7e39..ef7b24d6dc 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -74,21 +74,23 @@ void cForgeHandshake::SendServerHello() m_Client->SendPluginMessage("FML|HS", message); } -void cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) +AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) { cByteBuffer buf(a_Size); buf.Write(a_Data, a_Size); Int8 discriminator; buf.ReadBEInt8(discriminator); - LOG("ParseModList disc = %d", discriminator); + //LOG("ParseModList disc = %d", discriminator); ASSERT(discriminator == 2); UInt32 numMods; buf.ReadVarInt32(numMods); - LOG("ParseModList numMods = %d", numMods); + //LOG("ParseModList numMods = %d", numMods); + + AStringMap mods; for (size_t i = 0; i < numMods; ++i) { @@ -96,9 +98,12 @@ void cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) buf.ReadVarUTF8String(name); buf.ReadVarUTF8String(version); - LOG("ParseModList name=%s, version=%s", name.c_str(), version.c_str()); - // TODO: add to map and return, AStringPairs? + mods.insert(std::pair(name, version)); + + //LOG("ParseModList name=%s, version=%s", name.c_str(), version.c_str()); } + + return mods; } void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) @@ -144,8 +149,19 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) case Discriminator_ModList: { LOG("Received ModList"); - // TODO: parse client ModList - ParseModList(a_Data, a_Size); + + AStringMap clientMods = ParseModList(a_Data, a_Size); + AString clientModsString; + for (auto& item: clientMods) + { + clientModsString.append(item.first); + clientModsString.append("@"); + clientModsString.append(item.second); + clientModsString.append(", "); + } + + LOG("Client connected with %zu mods: %s", clientMods.size(), clientModsString.c_str()); + // TODO: call API to let plugins reject mods? // Send server ModList diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index 9f4f5af10b..70a9c7563a 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -25,7 +25,7 @@ class cForgeHandshake void SendServerHello(); void DataReceived(const char * a_Data, size_t a_Size); - void ParseModList(const char * a_Data, size_t a_Size); + AStringMap ParseModList(const char * a_Data, size_t a_Size); bool m_isForgeClient; From 07f82d1bb66c774be70382aa3e5e97e71c663c67 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Thu, 13 Jul 2017 21:36:39 -0700 Subject: [PATCH 034/166] Add HOOK_PLAYER_FORGE_MODS Lua API hook, call with mods, allow plugins to reject --- src/Bindings/Plugin.h | 1 + src/Bindings/PluginLua.cpp | 12 +++++++++++- src/Bindings/PluginLua.h | 1 + src/Bindings/PluginManager.cpp | 19 +++++++++++++++++++ src/Bindings/PluginManager.h | 2 ++ src/Protocol/ForgeHandshake.cpp | 12 ++++++++++-- src/Protocol/ForgeHandshake.h | 2 +- src/Protocol/Protocol.h | 2 +- 8 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index 3276fde677..a5cb41f0ec 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -69,6 +69,7 @@ class cPlugin virtual bool OnKilled (cEntity & a_Victim, TakeDamageInfo & a_TDI, AString & a_DeathMessage) = 0; virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer, TakeDamageInfo & a_TDI) = 0; virtual bool OnLogin (cClientHandle & a_Client, UInt32 a_ProtocolVersion, const AString & a_Username) = 0; + virtual bool OnPlayerForgeMods (cClientHandle & a_Client, AStringMap & a_Mods) = 0; virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) = 0; virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index e3aa63aa19..495664aa8a 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -550,6 +550,15 @@ bool cPluginLua::OnLogin(cClientHandle & a_Client, UInt32 a_ProtocolVersion, con +bool cPluginLua::OnPlayerForgeMods(cClientHandle & a_Client, AStringMap & a_Mods) +{ + return CallSimpleHooks(cPluginManager::HOOK_PLAYER_FORGE_MODS, &a_Client, &a_Mods); +} + + + + + bool cPluginLua::OnPlayerAnimation(cPlayer & a_Player, int a_Animation) { return CallSimpleHooks(cPluginManager::HOOK_PLAYER_ANIMATION, &a_Player, a_Animation); @@ -1083,7 +1092,8 @@ const char * cPluginLua::GetHookFnName(int a_HookType) case cPluginManager::HOOK_WEATHER_CHANGED: return "OnWeatherChanged"; case cPluginManager::HOOK_WEATHER_CHANGING: return "OnWeatherChanging"; case cPluginManager::HOOK_WORLD_TICK: return "OnWorldTick"; - + case cPluginManager::HOOK_PLAYER_FORGE_MODS: return "OnPlayerForgeMods"; + case cPluginManager::HOOK_NUM_HOOKS: { // Satisfy a warning that all enum values should be used in a switch diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index af336f0a04..7ce515dc3b 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -96,6 +96,7 @@ class cPluginLua : virtual bool OnKilled (cEntity & a_Victim, TakeDamageInfo & a_TDI, AString & a_DeathMessage) override; virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer, TakeDamageInfo & a_TDI) override; virtual bool OnLogin (cClientHandle & a_Client, UInt32 a_ProtocolVersion, const AString & a_Username) override; + virtual bool OnPlayerForgeMods (cClientHandle & a_Client, AStringMap & a_Mods) override; virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) override; virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index 066ccf9d70..c2001a0654 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -789,6 +789,25 @@ bool cPluginManager::CallHookLogin(cClientHandle & a_Client, UInt32 a_ProtocolVe +bool cPluginManager::CallHookPlayerForgeMods(cClientHandle & a_Client, AStringMap & a_Mods) +{ + FIND_HOOK(HOOK_PLAYER_FORGE_MODS) + VERIFY_HOOK; + + for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) + { + if ((*itr)->OnPlayerForgeMods(a_Client, a_Mods)) + { + return true; + } + } + return false; +} + + + + + bool cPluginManager::CallHookPlayerAnimation(cPlayer & a_Player, int a_Animation) { diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index 7c818ca2d2..921181d06e 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -142,6 +142,7 @@ class cPluginManager HOOK_WEATHER_CHANGING, HOOK_WORLD_STARTED, HOOK_WORLD_TICK, + HOOK_PLAYER_FORGE_MODS, // tolua_end @@ -246,6 +247,7 @@ class cPluginManager bool CallHookKilled (cEntity & a_Victim, TakeDamageInfo & a_TDI, AString & a_DeathMessage); bool CallHookKilling (cEntity & a_Victim, cEntity * a_Killer, TakeDamageInfo & a_TDI); bool CallHookLogin (cClientHandle & a_Client, UInt32 a_ProtocolVersion, const AString & a_Username); + bool CallHookPlayerForgeMods (cClientHandle & a_Client, AStringMap & a_Mods); bool CallHookPlayerAnimation (cPlayer & a_Player, int a_Animation); bool CallHookPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); bool CallHookPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index ef7b24d6dc..d4ea08ea4b 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -6,7 +6,9 @@ #include "Globals.h" #include "ForgeHandshake.h" #include "json/json.h" +#include "../Bindings/PluginManager.h" #include "../ClientHandle.h" +#include "../Root.h" cForgeHandshake::cForgeHandshake(cClientHandle *client) : m_isForgeClient(false), m_Errored(false), m_Client(client) { @@ -106,7 +108,7 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) return mods; } -void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) +void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data, size_t a_Size) { if (!m_isForgeClient) { LOG("Received unexpected Forge data from non-Forge client (%zu bytes)", a_Size); @@ -161,7 +163,13 @@ void cForgeHandshake::DataReceived(const char * a_Data, size_t a_Size) } LOG("Client connected with %zu mods: %s", clientMods.size(), clientModsString.c_str()); - // TODO: call API to let plugins reject mods? + // Let the plugins know about this event, they may refuse the player: + if (cRoot::Get()->GetPluginManager()->CallHookPlayerForgeMods(*a_Client, clientMods)) + { + LOG("Modded client refused by plugin"); + SetError(); + return; + } // Send server ModList diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index 70a9c7563a..1803b26f7b 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -23,7 +23,7 @@ class cForgeHandshake void BeginForgeHandshake(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties); void SendServerHello(); - void DataReceived(const char * a_Data, size_t a_Size); + void DataReceived(cClientHandle * a_Client, const char * a_Data, size_t a_Size); AStringMap ParseModList(const char * a_Data, size_t a_Size); diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index eaba6c3135..6f0a59ad8d 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -65,7 +65,7 @@ class cProtocol virtual void DataReceived(const char * a_Data, size_t a_Size) = 0; void ForgeDataReceived(const char * a_Data, size_t a_Size) { - m_Client->m_ForgeHandshake.DataReceived(a_Data, a_Size); + m_Client->m_ForgeHandshake.DataReceived(m_Client, a_Data, a_Size); } // Sending stuff to clients (alphabetically sorted): From 2813628a811422f8e146dc0f8d68995ba5f3907b Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 14 Jul 2017 22:26:38 -0700 Subject: [PATCH 035/166] Add new cForgeMods class representing a list of Forge mods+versions --- src/ClientHandle.cpp | 6 +++ src/ClientHandle.h | 7 +++- src/Protocol/CMakeLists.txt | 2 + src/Protocol/ForgeHandshake.cpp | 8 ++++ src/Protocol/ForgeMods.cpp | 67 +++++++++++++++++++++++++++++++++ src/Protocol/ForgeMods.h | 41 ++++++++++++++++++++ 6 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 src/Protocol/ForgeMods.cpp create mode 100644 src/Protocol/ForgeMods.h diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 40a83d6b74..59df9bd026 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -65,6 +65,7 @@ float cClientHandle::FASTBREAK_PERCENTAGE; cClientHandle::cClientHandle(const AString & a_IPString, int a_ViewDistance) : m_ForgeHandshake(this), + m_ForgeMods(0), m_LastSentDimension(dimNotSet), m_CurrentViewDistance(a_ViewDistance), m_RequestedViewDistance(a_ViewDistance), @@ -138,6 +139,11 @@ cClientHandle::~cClientHandle() delete m_Player; m_Player = nullptr; } + + if (m_ForgeMods != nullptr) + { + delete m_ForgeMods; + } if (!m_HasSentDC) { diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 8bef0389b5..ee9deea3ee 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -22,6 +22,7 @@ #include "ChunkSender.h" #include "EffectID.h" #include "Protocol/ForgeHandshake.h" +#include "Protocol/ForgeMods.h" #include @@ -91,6 +92,8 @@ class cClientHandle // tolua_export void SetUUID(const AString & a_UUID) { ASSERT(a_UUID.size() == 32); m_UUID = a_UUID; } const Json::Value & GetProperties(void) const { return m_Properties; } + + const cForgeMods & GetForgeMods(void) const { return m_ForgeMods ? *m_ForgeMods : cForgeMods::Unmodded(); } // tolua_export /** Sets the player's properties, such as skin image and signature. Used mainly by BungeeCord compatibility code - property querying is done on the BungeeCord server @@ -379,6 +382,8 @@ class cClientHandle // tolua_export bool IsPlayerChunkSent(); cForgeHandshake m_ForgeHandshake; + + cForgeMods * m_ForgeMods; private: /** The dimension that was last sent to a player in a Respawn or Login packet. @@ -388,7 +393,7 @@ class cClientHandle // tolua_export friend class cServer; // Needs access to SetSelf() friend class cForgeHandshake; // Needs access to PostAuthenticate() - + /** The type used for storing the names of registered plugin channels. */ typedef std::set cChannels; diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt index 562ab555bc..732801322c 100644 --- a/src/Protocol/CMakeLists.txt +++ b/src/Protocol/CMakeLists.txt @@ -14,6 +14,7 @@ SET (SRCS Protocol_1_12.cpp ProtocolRecognizer.cpp ForgeHandshake.cpp + ForgeMods.cpp ) SET (HDRS @@ -29,6 +30,7 @@ SET (HDRS Protocol_1_12.h ProtocolRecognizer.h ForgeHandshake.h + ForgeMods.h ) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index d4ea08ea4b..dedb40e3f9 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -163,6 +163,14 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data } LOG("Client connected with %zu mods: %s", clientMods.size(), clientModsString.c_str()); + + if (m_Client->m_ForgeMods != nullptr) + { + delete m_Client->m_ForgeMods; + } + + m_Client->m_ForgeMods = new cForgeMods(clientMods); + // Let the plugins know about this event, they may refuse the player: if (cRoot::Get()->GetPluginManager()->CallHookPlayerForgeMods(*a_Client, clientMods)) { diff --git a/src/Protocol/ForgeMods.cpp b/src/Protocol/ForgeMods.cpp new file mode 100644 index 0000000000..51e7be75a5 --- /dev/null +++ b/src/Protocol/ForgeMods.cpp @@ -0,0 +1,67 @@ + +// ForgeMods.cpp + +// Data structure listing the Forge mods name and versions + +#include "Globals.h" +#include "ForgeMods.h" + +cForgeMods::cForgeMods(AStringMap a):m_Mods(a) +{ + for (auto const & item: a) + { + m_ModNames.push_back(item.first); + m_ModVersions.push_back(item.second); + } +} + + + + +const cForgeMods & cForgeMods::Unmodded(void) +{ + static AStringMap empty; + static cForgeMods unmodded(empty); + + return unmodded; +} + + + + +size_t cForgeMods::GetNumMods(void) const +{ + return m_Mods.size(); +} + + + +bool cForgeMods::HasMod(AString & name) const +{ + return m_Mods.find(name) != m_Mods.end(); +} + + + + +const AString & cForgeMods::GetModVersion(AString & name) const +{ + return m_Mods.find(name)->second; +} + + + + +const AString & cForgeMods::GetModNameAt(size_t i) const +{ + return m_ModNames[i]; +} + + + + + +const AString & cForgeMods::GetModVersionAt(size_t i) const +{ + return m_ModVersions[i]; +} diff --git a/src/Protocol/ForgeMods.h b/src/Protocol/ForgeMods.h new file mode 100644 index 0000000000..437b210b15 --- /dev/null +++ b/src/Protocol/ForgeMods.h @@ -0,0 +1,41 @@ + +// ForgeMods.h + +// Data structure listing the Forge mods name and versions + +#pragma once + +#include + +// tolua_begin +class cForgeMods +{ +public: + cForgeMods(AStringMap a); + + static const cForgeMods & Unmodded(void); + + // TODO: can tolua++ bridge AStringMap (etc.) as a Lua table? or non-fixedsize arrays? + + /** Returns the number of Forge mods. */ + size_t GetNumMods(void) const; + + /** Returns true if the mod name is installed. */ + bool HasMod(AString & name) const; + + /** Returns the version of the mod name given. */ + const AString & GetModVersion(AString & name) const; + + /** Returns the name of the Forge mod at the given index. */ + const AString & GetModNameAt(size_t i) const; + + /** Returns the version of the Forge mod at the given index. */ + const AString & GetModVersionAt(size_t i) const; + + // tolua_end + +private: + AStringMap m_Mods; + AStringVector m_ModNames; + AStringVector m_ModVersions; +}; From ead2601165457e677ca220b63be35eaacfeb4ee2 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 14 Jul 2017 22:36:05 -0700 Subject: [PATCH 036/166] Try to document GetForgeMods() --- src/ClientHandle.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ClientHandle.h b/src/ClientHandle.h index ee9deea3ee..f9c260179c 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -93,8 +93,6 @@ class cClientHandle // tolua_export const Json::Value & GetProperties(void) const { return m_Properties; } - const cForgeMods & GetForgeMods(void) const { return m_ForgeMods ? *m_ForgeMods : cForgeMods::Unmodded(); } // tolua_export - /** Sets the player's properties, such as skin image and signature. Used mainly by BungeeCord compatibility code - property querying is done on the BungeeCord server and the results are passed to MCS running in offline mode. */ @@ -267,6 +265,9 @@ class cClientHandle // tolua_export /** Returns the client brand received in the MC|Brand plugin message or set by a plugin. */ const AString & GetClientBrand(void) const { return m_ClientBrand; } + + /** Returns the Forge mods installed on the client. */ + const cForgeMods & GetForgeMods(void) const { return m_ForgeMods ? *m_ForgeMods : cForgeMods::Unmodded(); } // tolua_end From 66c52f0c8b228ff0dd058ffe6ab5332c642cbfe7 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 14 Jul 2017 22:47:03 -0700 Subject: [PATCH 037/166] Move // tolua_end comment to end of file --- src/Protocol/ForgeMods.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Protocol/ForgeMods.h b/src/Protocol/ForgeMods.h index 437b210b15..2796ae5397 100644 --- a/src/Protocol/ForgeMods.h +++ b/src/Protocol/ForgeMods.h @@ -32,10 +32,9 @@ class cForgeMods /** Returns the version of the Forge mod at the given index. */ const AString & GetModVersionAt(size_t i) const; - // tolua_end - private: AStringMap m_Mods; AStringVector m_ModNames; AStringVector m_ModVersions; }; +// tolua_end From a12fa5d311dd4d2b0f8c3786a7bbc316fbe3595c Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 14 Jul 2017 22:47:24 -0700 Subject: [PATCH 038/166] Remove unbridgeable AStringMap mods list from HOOK_PLAYER_FORGE_MODS in favor of GetForgeMods() --- src/Bindings/Plugin.h | 2 +- src/Bindings/PluginLua.cpp | 4 ++-- src/Bindings/PluginLua.h | 2 +- src/Bindings/PluginManager.cpp | 4 ++-- src/Bindings/PluginManager.h | 2 +- src/Protocol/ForgeHandshake.cpp | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index a5cb41f0ec..2e99d18e42 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -69,7 +69,7 @@ class cPlugin virtual bool OnKilled (cEntity & a_Victim, TakeDamageInfo & a_TDI, AString & a_DeathMessage) = 0; virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer, TakeDamageInfo & a_TDI) = 0; virtual bool OnLogin (cClientHandle & a_Client, UInt32 a_ProtocolVersion, const AString & a_Username) = 0; - virtual bool OnPlayerForgeMods (cClientHandle & a_Client, AStringMap & a_Mods) = 0; + virtual bool OnPlayerForgeMods (cClientHandle & a_Client) = 0; virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) = 0; virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 495664aa8a..5d6032d69a 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -550,9 +550,9 @@ bool cPluginLua::OnLogin(cClientHandle & a_Client, UInt32 a_ProtocolVersion, con -bool cPluginLua::OnPlayerForgeMods(cClientHandle & a_Client, AStringMap & a_Mods) +bool cPluginLua::OnPlayerForgeMods(cClientHandle & a_Client) { - return CallSimpleHooks(cPluginManager::HOOK_PLAYER_FORGE_MODS, &a_Client, &a_Mods); + return CallSimpleHooks(cPluginManager::HOOK_PLAYER_FORGE_MODS, &a_Client); } diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index 7ce515dc3b..d73c25790c 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -96,7 +96,7 @@ class cPluginLua : virtual bool OnKilled (cEntity & a_Victim, TakeDamageInfo & a_TDI, AString & a_DeathMessage) override; virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer, TakeDamageInfo & a_TDI) override; virtual bool OnLogin (cClientHandle & a_Client, UInt32 a_ProtocolVersion, const AString & a_Username) override; - virtual bool OnPlayerForgeMods (cClientHandle & a_Client, AStringMap & a_Mods) override; + virtual bool OnPlayerForgeMods (cClientHandle & a_Client) override; virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) override; virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index c2001a0654..78d32ab2d1 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -789,14 +789,14 @@ bool cPluginManager::CallHookLogin(cClientHandle & a_Client, UInt32 a_ProtocolVe -bool cPluginManager::CallHookPlayerForgeMods(cClientHandle & a_Client, AStringMap & a_Mods) +bool cPluginManager::CallHookPlayerForgeMods(cClientHandle & a_Client) { FIND_HOOK(HOOK_PLAYER_FORGE_MODS) VERIFY_HOOK; for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) { - if ((*itr)->OnPlayerForgeMods(a_Client, a_Mods)) + if ((*itr)->OnPlayerForgeMods(a_Client)) { return true; } diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index 921181d06e..298a5feb64 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -247,7 +247,7 @@ class cPluginManager bool CallHookKilled (cEntity & a_Victim, TakeDamageInfo & a_TDI, AString & a_DeathMessage); bool CallHookKilling (cEntity & a_Victim, cEntity * a_Killer, TakeDamageInfo & a_TDI); bool CallHookLogin (cClientHandle & a_Client, UInt32 a_ProtocolVersion, const AString & a_Username); - bool CallHookPlayerForgeMods (cClientHandle & a_Client, AStringMap & a_Mods); + bool CallHookPlayerForgeMods (cClientHandle & a_Client); bool CallHookPlayerAnimation (cPlayer & a_Player, int a_Animation); bool CallHookPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); bool CallHookPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index dedb40e3f9..d15843d298 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -172,7 +172,7 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data m_Client->m_ForgeMods = new cForgeMods(clientMods); // Let the plugins know about this event, they may refuse the player: - if (cRoot::Get()->GetPluginManager()->CallHookPlayerForgeMods(*a_Client, clientMods)) + if (cRoot::Get()->GetPluginManager()->CallHookPlayerForgeMods(*a_Client)) { LOG("Modded client refused by plugin"); SetError(); From d669b75b2b1c37b93df0cbca631bb6741e160bf8 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 14 Jul 2017 22:53:54 -0700 Subject: [PATCH 039/166] Rename hook to HOOK_LOGIN_FORGE --- src/Bindings/Plugin.h | 2 +- src/Bindings/PluginLua.cpp | 6 +++--- src/Bindings/PluginLua.h | 2 +- src/Bindings/PluginManager.cpp | 6 +++--- src/Bindings/PluginManager.h | 4 ++-- src/Protocol/ForgeHandshake.cpp | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index 2e99d18e42..fe4616fe54 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -69,7 +69,7 @@ class cPlugin virtual bool OnKilled (cEntity & a_Victim, TakeDamageInfo & a_TDI, AString & a_DeathMessage) = 0; virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer, TakeDamageInfo & a_TDI) = 0; virtual bool OnLogin (cClientHandle & a_Client, UInt32 a_ProtocolVersion, const AString & a_Username) = 0; - virtual bool OnPlayerForgeMods (cClientHandle & a_Client) = 0; + virtual bool OnLoginForge (cClientHandle & a_Client) = 0; virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) = 0; virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 5d6032d69a..424e412f1d 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -550,9 +550,9 @@ bool cPluginLua::OnLogin(cClientHandle & a_Client, UInt32 a_ProtocolVersion, con -bool cPluginLua::OnPlayerForgeMods(cClientHandle & a_Client) +bool cPluginLua::OnLoginForge(cClientHandle & a_Client) { - return CallSimpleHooks(cPluginManager::HOOK_PLAYER_FORGE_MODS, &a_Client); + return CallSimpleHooks(cPluginManager::HOOK_LOGIN_FORGE, &a_Client); } @@ -1059,6 +1059,7 @@ const char * cPluginLua::GetHookFnName(int a_HookType) case cPluginManager::HOOK_HANDSHAKE: return "OnHandshake"; case cPluginManager::HOOK_KILLING: return "OnKilling"; case cPluginManager::HOOK_LOGIN: return "OnLogin"; + case cPluginManager::HOOK_LOGIN_FORGE: return "OnLoginForge"; case cPluginManager::HOOK_PLAYER_BREAKING_BLOCK: return "OnPlayerBreakingBlock"; case cPluginManager::HOOK_PLAYER_BROKEN_BLOCK: return "OnPlayerBrokenBlock"; case cPluginManager::HOOK_PLAYER_EATING: return "OnPlayerEating"; @@ -1092,7 +1093,6 @@ const char * cPluginLua::GetHookFnName(int a_HookType) case cPluginManager::HOOK_WEATHER_CHANGED: return "OnWeatherChanged"; case cPluginManager::HOOK_WEATHER_CHANGING: return "OnWeatherChanging"; case cPluginManager::HOOK_WORLD_TICK: return "OnWorldTick"; - case cPluginManager::HOOK_PLAYER_FORGE_MODS: return "OnPlayerForgeMods"; case cPluginManager::HOOK_NUM_HOOKS: { diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index d73c25790c..b1aa33dcfa 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -96,7 +96,7 @@ class cPluginLua : virtual bool OnKilled (cEntity & a_Victim, TakeDamageInfo & a_TDI, AString & a_DeathMessage) override; virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer, TakeDamageInfo & a_TDI) override; virtual bool OnLogin (cClientHandle & a_Client, UInt32 a_ProtocolVersion, const AString & a_Username) override; - virtual bool OnPlayerForgeMods (cClientHandle & a_Client) override; + virtual bool OnLoginForge (cClientHandle & a_Client) override; virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) override; virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index 78d32ab2d1..219876adb3 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -789,14 +789,14 @@ bool cPluginManager::CallHookLogin(cClientHandle & a_Client, UInt32 a_ProtocolVe -bool cPluginManager::CallHookPlayerForgeMods(cClientHandle & a_Client) +bool cPluginManager::CallHookLoginForge(cClientHandle & a_Client) { - FIND_HOOK(HOOK_PLAYER_FORGE_MODS) + FIND_HOOK(HOOK_LOGIN_FORGE) VERIFY_HOOK; for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) { - if ((*itr)->OnPlayerForgeMods(a_Client)) + if ((*itr)->OnLoginForge(a_Client)) { return true; } diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index 298a5feb64..3820bcbd99 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -142,7 +142,7 @@ class cPluginManager HOOK_WEATHER_CHANGING, HOOK_WORLD_STARTED, HOOK_WORLD_TICK, - HOOK_PLAYER_FORGE_MODS, + HOOK_LOGIN_FORGE, // tolua_end @@ -247,7 +247,7 @@ class cPluginManager bool CallHookKilled (cEntity & a_Victim, TakeDamageInfo & a_TDI, AString & a_DeathMessage); bool CallHookKilling (cEntity & a_Victim, cEntity * a_Killer, TakeDamageInfo & a_TDI); bool CallHookLogin (cClientHandle & a_Client, UInt32 a_ProtocolVersion, const AString & a_Username); - bool CallHookPlayerForgeMods (cClientHandle & a_Client); + bool CallHookLoginForge (cClientHandle & a_Client); bool CallHookPlayerAnimation (cPlayer & a_Player, int a_Animation); bool CallHookPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); bool CallHookPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index d15843d298..df92316f24 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -172,7 +172,7 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data m_Client->m_ForgeMods = new cForgeMods(clientMods); // Let the plugins know about this event, they may refuse the player: - if (cRoot::Get()->GetPluginManager()->CallHookPlayerForgeMods(*a_Client)) + if (cRoot::Get()->GetPluginManager()->CallHookLoginForge(*a_Client)) { LOG("Modded client refused by plugin"); SetError(); From df6e37fb90ead01d8b4e773b43127c6e2a85f73e Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 14 Jul 2017 23:11:39 -0700 Subject: [PATCH 040/166] Add cForgeMods to Lua plugins bindings --- src/Bindings/AllToLua.pkg | 1 + src/Bindings/CMakeLists.txt | 1 + src/Protocol/ForgeMods.h | 14 +++++++------- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index a109913e25..1b435fc022 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -69,6 +69,7 @@ $cfile "../MapManager.h" $cfile "../Scoreboard.h" $cfile "../Statistics.h" $cfile "../Protocol/MojangAPI.h" +$cfile "../Protocol/ForgeMods.h" // Entities: $cfile "../Entities/Entity.h" diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt index da7c8bbe87..f40cd9e716 100644 --- a/src/Bindings/CMakeLists.txt +++ b/src/Bindings/CMakeLists.txt @@ -131,6 +131,7 @@ set(BINDING_DEPENDENCIES ../Mobs/MonsterTypes.h ../OSSupport/File.h ../Protocol/MojangAPI.h + ../Protocol/ForgeMods.h ../Root.h ../Scoreboard.h ../Server.h diff --git a/src/Protocol/ForgeMods.h b/src/Protocol/ForgeMods.h index 2796ae5397..09f129f499 100644 --- a/src/Protocol/ForgeMods.h +++ b/src/Protocol/ForgeMods.h @@ -11,10 +11,6 @@ class cForgeMods { public: - cForgeMods(AStringMap a); - - static const cForgeMods & Unmodded(void); - // TODO: can tolua++ bridge AStringMap (etc.) as a Lua table? or non-fixedsize arrays? /** Returns the number of Forge mods. */ @@ -31,10 +27,14 @@ class cForgeMods /** Returns the version of the Forge mod at the given index. */ const AString & GetModVersionAt(size_t i) const; - + // tolua_end + + cForgeMods(AStringMap a); + + static const cForgeMods & Unmodded(void); + private: AStringMap m_Mods; AStringVector m_ModNames; AStringVector m_ModVersions; -}; -// tolua_end +} ; // tolua_export From bf5f2119cfe5c0d64847bae7a50994f44b5138fa Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 15 Jul 2017 12:51:28 -0700 Subject: [PATCH 041/166] Pass protocol version string to AugmentServerListPing() --- src/Protocol/ForgeHandshake.cpp | 3 ++- src/Protocol/ForgeHandshake.h | 2 +- src/Protocol/Protocol_1_10.cpp | 2 +- src/Protocol/Protocol_1_11.cpp | 4 ++-- src/Protocol/Protocol_1_12.cpp | 2 +- src/Protocol/Protocol_1_8.cpp | 2 +- src/Protocol/Protocol_1_9.cpp | 8 ++++---- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index df92316f24..521686aba5 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -18,10 +18,11 @@ cForgeHandshake::cForgeHandshake(cClientHandle *client) : m_isForgeClient(false) -void cForgeHandshake::augmentServerListPing(Json::Value & ResponseValue) +void cForgeHandshake::AugmentServerListPing(const char * ProtocolVersion, Json::Value & ResponseValue) { // modinfo: // TODO: only send if mods enabled + // TODO: pass ProtocolVersion to allow different mods from versions Json::Value Modinfo; Modinfo["type"] = "FML"; diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index 1803b26f7b..412539263f 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -19,7 +19,7 @@ class cForgeHandshake public: cForgeHandshake(cClientHandle * client); - void augmentServerListPing(Json::Value & ResponseValue); + void AugmentServerListPing(const char * ProtocolVersion, Json::Value & ResponseValue); void BeginForgeHandshake(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties); void SendServerHello(); diff --git a/src/Protocol/Protocol_1_10.cpp b/src/Protocol/Protocol_1_10.cpp index 3f3e7ad93e..e84e055918 100644 --- a/src/Protocol/Protocol_1_10.cpp +++ b/src/Protocol/Protocol_1_10.cpp @@ -346,7 +346,7 @@ void cProtocol_1_10_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.AugmentServerListPing("1.10.0", ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_11.cpp b/src/Protocol/Protocol_1_11.cpp index ea1bb7e403..ae23c5978a 100644 --- a/src/Protocol/Protocol_1_11.cpp +++ b/src/Protocol/Protocol_1_11.cpp @@ -586,7 +586,7 @@ void cProtocol_1_11_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.AugmentServerListPing("1.11.0", ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -1210,7 +1210,7 @@ void cProtocol_1_11_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.AugmentServerListPing("1.11.1", ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp index 8794e3a2d7..80548d9e84 100644 --- a/src/Protocol/Protocol_1_12.cpp +++ b/src/Protocol/Protocol_1_12.cpp @@ -399,7 +399,7 @@ void cProtocol_1_12::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.AugmentServerListPing("1.12", ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp index 2831a189e8..fc2e690200 100644 --- a/src/Protocol/Protocol_1_8.cpp +++ b/src/Protocol/Protocol_1_8.cpp @@ -2135,7 +2135,7 @@ void cProtocol_1_8_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.AugmentServerListPing("1.8.0", ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index d698c92cda..9cf829b334 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -2176,7 +2176,7 @@ void cProtocol_1_9_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.AugmentServerListPing("1.9.0", ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4181,7 +4181,7 @@ void cProtocol_1_9_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.AugmentServerListPing("1.9.1", ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4239,7 +4239,7 @@ void cProtocol_1_9_2::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.AugmentServerListPing("1.9.2", ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4297,7 +4297,7 @@ void cProtocol_1_9_4::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.AugmentServerListPing("1.9.4", ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); From f2d6ec1ba92d160512315faf4d9092e7e799acb6 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 15 Jul 2017 12:54:49 -0700 Subject: [PATCH 042/166] Revert "Pass protocol version string to AugmentServerListPing()" This reverts commit bf5f2119cfe5c0d64847bae7a50994f44b5138fa. --- src/Protocol/ForgeHandshake.cpp | 3 +-- src/Protocol/ForgeHandshake.h | 2 +- src/Protocol/Protocol_1_10.cpp | 2 +- src/Protocol/Protocol_1_11.cpp | 4 ++-- src/Protocol/Protocol_1_12.cpp | 2 +- src/Protocol/Protocol_1_8.cpp | 2 +- src/Protocol/Protocol_1_9.cpp | 8 ++++---- 7 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 521686aba5..df92316f24 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -18,11 +18,10 @@ cForgeHandshake::cForgeHandshake(cClientHandle *client) : m_isForgeClient(false) -void cForgeHandshake::AugmentServerListPing(const char * ProtocolVersion, Json::Value & ResponseValue) +void cForgeHandshake::augmentServerListPing(Json::Value & ResponseValue) { // modinfo: // TODO: only send if mods enabled - // TODO: pass ProtocolVersion to allow different mods from versions Json::Value Modinfo; Modinfo["type"] = "FML"; diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index 412539263f..1803b26f7b 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -19,7 +19,7 @@ class cForgeHandshake public: cForgeHandshake(cClientHandle * client); - void AugmentServerListPing(const char * ProtocolVersion, Json::Value & ResponseValue); + void augmentServerListPing(Json::Value & ResponseValue); void BeginForgeHandshake(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties); void SendServerHello(); diff --git a/src/Protocol/Protocol_1_10.cpp b/src/Protocol/Protocol_1_10.cpp index e84e055918..3f3e7ad93e 100644 --- a/src/Protocol/Protocol_1_10.cpp +++ b/src/Protocol/Protocol_1_10.cpp @@ -346,7 +346,7 @@ void cProtocol_1_10_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.AugmentServerListPing("1.10.0", ResponseValue); + m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_11.cpp b/src/Protocol/Protocol_1_11.cpp index ae23c5978a..ea1bb7e403 100644 --- a/src/Protocol/Protocol_1_11.cpp +++ b/src/Protocol/Protocol_1_11.cpp @@ -586,7 +586,7 @@ void cProtocol_1_11_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.AugmentServerListPing("1.11.0", ResponseValue); + m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -1210,7 +1210,7 @@ void cProtocol_1_11_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.AugmentServerListPing("1.11.1", ResponseValue); + m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp index 80548d9e84..8794e3a2d7 100644 --- a/src/Protocol/Protocol_1_12.cpp +++ b/src/Protocol/Protocol_1_12.cpp @@ -399,7 +399,7 @@ void cProtocol_1_12::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.AugmentServerListPing("1.12", ResponseValue); + m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp index fc2e690200..2831a189e8 100644 --- a/src/Protocol/Protocol_1_8.cpp +++ b/src/Protocol/Protocol_1_8.cpp @@ -2135,7 +2135,7 @@ void cProtocol_1_8_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.AugmentServerListPing("1.8.0", ResponseValue); + m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index 9cf829b334..d698c92cda 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -2176,7 +2176,7 @@ void cProtocol_1_9_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.AugmentServerListPing("1.9.0", ResponseValue); + m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4181,7 +4181,7 @@ void cProtocol_1_9_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.AugmentServerListPing("1.9.1", ResponseValue); + m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4239,7 +4239,7 @@ void cProtocol_1_9_2::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.AugmentServerListPing("1.9.2", ResponseValue); + m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4297,7 +4297,7 @@ void cProtocol_1_9_4::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.AugmentServerListPing("1.9.4", ResponseValue); + m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); From b916c77f9369622232fa63b28fb47581092c297e Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 15 Jul 2017 13:00:51 -0700 Subject: [PATCH 043/166] Log protocol version received in augmentServerListPing() - available in m_Client, no need to pass --- src/Protocol/ForgeHandshake.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index df92316f24..606997d2bf 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -20,6 +20,11 @@ cForgeHandshake::cForgeHandshake(cClientHandle *client) : m_isForgeClient(false) void cForgeHandshake::augmentServerListPing(Json::Value & ResponseValue) { + UInt32 ProtocolVersion = m_Client->GetProtocolVersion(); + + LOG("Received server ping from version: %d", ProtocolVersion); + // TODO: pass ProtocolVersion to allow different mods per version + // modinfo: // TODO: only send if mods enabled Json::Value Modinfo; From 5b868996bf57da5ddcb6fe2fbe45025f398be2cb Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 15 Jul 2017 13:01:12 -0700 Subject: [PATCH 044/166] Fix capitalization of AugmentServerListPing() --- src/Protocol/ForgeHandshake.cpp | 2 +- src/Protocol/ForgeHandshake.h | 2 +- src/Protocol/Protocol_1_10.cpp | 2 +- src/Protocol/Protocol_1_11.cpp | 4 ++-- src/Protocol/Protocol_1_12.cpp | 2 +- src/Protocol/Protocol_1_8.cpp | 2 +- src/Protocol/Protocol_1_9.cpp | 8 ++++---- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 606997d2bf..5792ec019a 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -18,7 +18,7 @@ cForgeHandshake::cForgeHandshake(cClientHandle *client) : m_isForgeClient(false) -void cForgeHandshake::augmentServerListPing(Json::Value & ResponseValue) +void cForgeHandshake::AugmentServerListPing(Json::Value & ResponseValue) { UInt32 ProtocolVersion = m_Client->GetProtocolVersion(); diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index 1803b26f7b..9a2773bcb6 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -19,7 +19,7 @@ class cForgeHandshake public: cForgeHandshake(cClientHandle * client); - void augmentServerListPing(Json::Value & ResponseValue); + void AugmentServerListPing(Json::Value & ResponseValue); void BeginForgeHandshake(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties); void SendServerHello(); diff --git a/src/Protocol/Protocol_1_10.cpp b/src/Protocol/Protocol_1_10.cpp index 3f3e7ad93e..2519a5b12f 100644 --- a/src/Protocol/Protocol_1_10.cpp +++ b/src/Protocol/Protocol_1_10.cpp @@ -346,7 +346,7 @@ void cProtocol_1_10_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.AugmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_11.cpp b/src/Protocol/Protocol_1_11.cpp index ea1bb7e403..73278e0078 100644 --- a/src/Protocol/Protocol_1_11.cpp +++ b/src/Protocol/Protocol_1_11.cpp @@ -586,7 +586,7 @@ void cProtocol_1_11_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.AugmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -1210,7 +1210,7 @@ void cProtocol_1_11_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.AugmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp index 8794e3a2d7..8106bbbe66 100644 --- a/src/Protocol/Protocol_1_12.cpp +++ b/src/Protocol/Protocol_1_12.cpp @@ -399,7 +399,7 @@ void cProtocol_1_12::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.AugmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp index 2831a189e8..a948dd0deb 100644 --- a/src/Protocol/Protocol_1_8.cpp +++ b/src/Protocol/Protocol_1_8.cpp @@ -2135,7 +2135,7 @@ void cProtocol_1_8_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.AugmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index d698c92cda..8b81cf1096 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -2176,7 +2176,7 @@ void cProtocol_1_9_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.AugmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4181,7 +4181,7 @@ void cProtocol_1_9_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.AugmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4239,7 +4239,7 @@ void cProtocol_1_9_2::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.AugmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4297,7 +4297,7 @@ void cProtocol_1_9_4::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.augmentServerListPing(ResponseValue); + m_Client->m_ForgeHandshake.AugmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); From 734de89c1b4a20340a3d34aad072a7156bd0261d Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 15 Jul 2017 15:04:07 -0700 Subject: [PATCH 045/166] Add RegisterForgeMod() Lua API to cServer --- src/Protocol/ForgeHandshake.cpp | 14 +++++++-- src/Protocol/ForgeMods.cpp | 21 ++++++++++++-- src/Protocol/ForgeMods.h | 5 ++++ src/Server.cpp | 51 +++++++++++++++++++++++++++++++++ src/Server.h | 23 +++++++++++++-- 5 files changed, 107 insertions(+), 7 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 5792ec019a..bcb45d1b8c 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -6,6 +6,7 @@ #include "Globals.h" #include "ForgeHandshake.h" #include "json/json.h" +#include "../Server.h" #include "../Bindings/PluginManager.h" #include "../ClientHandle.h" #include "../Root.h" @@ -23,7 +24,6 @@ void cForgeHandshake::AugmentServerListPing(Json::Value & ResponseValue) UInt32 ProtocolVersion = m_Client->GetProtocolVersion(); LOG("Received server ping from version: %d", ProtocolVersion); - // TODO: pass ProtocolVersion to allow different mods per version // modinfo: // TODO: only send if mods enabled @@ -31,7 +31,17 @@ void cForgeHandshake::AugmentServerListPing(Json::Value & ResponseValue) Modinfo["type"] = "FML"; Json::Value ModList(Json::arrayValue); - // TODO: customizable modList + + cForgeMods & mods = cRoot::Get()->GetServer()->GetRegisteredForgeMods(ProtocolVersion); + + for (auto& item: mods.GetMods()) + { + Json::Value Mod; + Mod["modid"] = item.first; + Mod["version"] = item.second; + ModList.append(Mod); + } + Modinfo["modList"] = ModList; // Augment the response: diff --git a/src/Protocol/ForgeMods.cpp b/src/Protocol/ForgeMods.cpp index 51e7be75a5..3d72280884 100644 --- a/src/Protocol/ForgeMods.cpp +++ b/src/Protocol/ForgeMods.cpp @@ -6,6 +6,14 @@ #include "Globals.h" #include "ForgeMods.h" +cForgeMods::cForgeMods() +{ +} + + + + + cForgeMods::cForgeMods(AStringMap a):m_Mods(a) { for (auto const & item: a) @@ -20,8 +28,7 @@ cForgeMods::cForgeMods(AStringMap a):m_Mods(a) const cForgeMods & cForgeMods::Unmodded(void) { - static AStringMap empty; - static cForgeMods unmodded(empty); + static cForgeMods unmodded; return unmodded; } @@ -65,3 +72,13 @@ const AString & cForgeMods::GetModVersionAt(size_t i) const { return m_ModVersions[i]; } + + + + +void cForgeMods::Add(AString & a_Name, AString & a_Version) +{ + m_ModNames.push_back(a_Name); + m_ModVersions.push_back(a_Version); + m_Mods.insert(std::make_pair(a_Name, a_Version)); +} diff --git a/src/Protocol/ForgeMods.h b/src/Protocol/ForgeMods.h index 09f129f499..320196cd2f 100644 --- a/src/Protocol/ForgeMods.h +++ b/src/Protocol/ForgeMods.h @@ -29,10 +29,15 @@ class cForgeMods const AString & GetModVersionAt(size_t i) const; // tolua_end + cForgeMods(); cForgeMods(AStringMap a); static const cForgeMods & Unmodded(void); + void Add(AString & a_Name, AString & a_Version); + + AStringMap GetMods() { return m_Mods; } + private: AStringMap m_Mods; AStringVector m_ModNames; diff --git a/src/Server.cpp b/src/Server.cpp index fd707e61ae..6a9f0a8830 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -255,6 +255,57 @@ int cServer::GetNumPlayers(void) const +void cServer::RegisterForgeMod(int a_Protocol, AString & a_Name, AString & a_Version) +{ + // TODO: refactor + switch(a_Protocol) + { + case cProtocolRecognizer::PROTO_VERSION_1_8_0: m_ForgeMods_1_8_0.Add(a_Name, a_Version); break; + case cProtocolRecognizer::PROTO_VERSION_1_9_0: m_ForgeMods_1_9_0.Add(a_Name, a_Version); break; + case cProtocolRecognizer::PROTO_VERSION_1_9_1: m_ForgeMods_1_9_1.Add(a_Name, a_Version); break; + case cProtocolRecognizer::PROTO_VERSION_1_9_2: m_ForgeMods_1_9_2.Add(a_Name, a_Version); break; + case cProtocolRecognizer::PROTO_VERSION_1_9_4: m_ForgeMods_1_9_4.Add(a_Name, a_Version); break; + case cProtocolRecognizer::PROTO_VERSION_1_10_0: m_ForgeMods_1_10_0.Add(a_Name, a_Version); break; + case cProtocolRecognizer::PROTO_VERSION_1_11_0: m_ForgeMods_1_11_0.Add(a_Name, a_Version); break; + case cProtocolRecognizer::PROTO_VERSION_1_11_1: m_ForgeMods_1_11_1.Add(a_Name, a_Version); break; + case cProtocolRecognizer::PROTO_VERSION_1_12: m_ForgeMods_1_12.Add(a_Name, a_Version); break; + case 0: + default: + m_ForgeMods_1_8_0.Add(a_Name, a_Version); + m_ForgeMods_1_9_0.Add(a_Name, a_Version); + m_ForgeMods_1_9_1.Add(a_Name, a_Version); + m_ForgeMods_1_9_2.Add(a_Name, a_Version); + m_ForgeMods_1_9_4.Add(a_Name, a_Version); + m_ForgeMods_1_10_0.Add(a_Name, a_Version); + m_ForgeMods_1_11_0.Add(a_Name, a_Version); + m_ForgeMods_1_11_1.Add(a_Name, a_Version); + m_ForgeMods_1_12.Add(a_Name, a_Version); + break; + } +} + + + + +cForgeMods & cServer::GetRegisteredForgeMods(UInt32 a_Protocol) +{ + switch(a_Protocol) + { + case cProtocolRecognizer::PROTO_VERSION_1_8_0: return m_ForgeMods_1_8_0; + case cProtocolRecognizer::PROTO_VERSION_1_9_0: return m_ForgeMods_1_9_0; + case cProtocolRecognizer::PROTO_VERSION_1_9_1: return m_ForgeMods_1_9_1; + case cProtocolRecognizer::PROTO_VERSION_1_9_2: return m_ForgeMods_1_9_2; + case cProtocolRecognizer::PROTO_VERSION_1_9_4: return m_ForgeMods_1_9_4; + case cProtocolRecognizer::PROTO_VERSION_1_10_0: return m_ForgeMods_1_10_0; + case cProtocolRecognizer::PROTO_VERSION_1_11_0: return m_ForgeMods_1_11_0; + case cProtocolRecognizer::PROTO_VERSION_1_11_1: return m_ForgeMods_1_11_1; + default: + case cProtocolRecognizer::PROTO_VERSION_1_12: return m_ForgeMods_1_12; + } +} + + + bool cServer::IsPlayerInQueue(AString a_Username) { diff --git a/src/Server.h b/src/Server.h index bb9b7f511d..0825fec1d1 100644 --- a/src/Server.h +++ b/src/Server.h @@ -12,6 +12,7 @@ #include "RCONServer.h" #include "OSSupport/IsThread.h" #include "OSSupport/Network.h" +#include "Protocol/ForgeMods.h" #ifdef _MSC_VER #pragma warning(push) @@ -70,6 +71,8 @@ class cServer int GetMaxPlayers(void) const { return m_MaxPlayers; } int GetNumPlayers(void) const; void SetMaxPlayers(int a_MaxPlayers) { m_MaxPlayers = a_MaxPlayers; } + + void RegisterForgeMod(int a_Protocol, AString & a_ModName, AString & a_ModVersion); /** Check if the player is queued to be transferred to a World. Returns true is Player is found in queue. */ @@ -83,7 +86,7 @@ class cServer bool IsHardcore(void) const { return m_bIsHardcore; } // tolua_end - + bool Start(void); bool Command(cClientHandle & a_Client, AString & a_Cmd); @@ -147,7 +150,9 @@ class cServer /** Returns true if usernames should be completed across worlds. This is read from the settings. */ bool ShouldAllowMultiWorldTabCompletion(void) const { return m_ShouldAllowMultiWorldTabCompletion; } - + + cForgeMods & GetRegisteredForgeMods(UInt32 a_Protocol); + private: friend class cRoot; // so cRoot can create and destroy cServer @@ -213,7 +218,19 @@ class cServer AString m_FaviconData; int m_MaxPlayers; bool m_bIsHardcore; - + + // TODO: std::map data structure? + cForgeMods m_ForgeMods_1_8_0; + cForgeMods m_ForgeMods_1_9_0; + cForgeMods m_ForgeMods_1_9_1; + cForgeMods m_ForgeMods_1_9_2; + cForgeMods m_ForgeMods_1_9_4; + cForgeMods m_ForgeMods_1_10_0; + cForgeMods m_ForgeMods_1_10_1; + cForgeMods m_ForgeMods_1_11_0; + cForgeMods m_ForgeMods_1_11_1; + cForgeMods m_ForgeMods_1_12; + /** True - allow same username to login more than once False - only once */ bool m_bAllowMultiLogin; From 2b33a3072a619b61256f14fc83363291b65c49cb Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 15 Jul 2017 15:14:25 -0700 Subject: [PATCH 046/166] Change RegisterForgeMod() to register for all versions, add RegisterForgeModForProtocol() --- src/Server.cpp | 46 ++++++++++++++++++++-------------------------- src/Server.h | 3 ++- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/Server.cpp b/src/Server.cpp index 6a9f0a8830..b5f9edde25 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -254,34 +254,28 @@ int cServer::GetNumPlayers(void) const - -void cServer::RegisterForgeMod(int a_Protocol, AString & a_Name, AString & a_Version) +void cServer::RegisterForgeMod(AString & a_Name, AString & a_Version) { // TODO: refactor - switch(a_Protocol) - { - case cProtocolRecognizer::PROTO_VERSION_1_8_0: m_ForgeMods_1_8_0.Add(a_Name, a_Version); break; - case cProtocolRecognizer::PROTO_VERSION_1_9_0: m_ForgeMods_1_9_0.Add(a_Name, a_Version); break; - case cProtocolRecognizer::PROTO_VERSION_1_9_1: m_ForgeMods_1_9_1.Add(a_Name, a_Version); break; - case cProtocolRecognizer::PROTO_VERSION_1_9_2: m_ForgeMods_1_9_2.Add(a_Name, a_Version); break; - case cProtocolRecognizer::PROTO_VERSION_1_9_4: m_ForgeMods_1_9_4.Add(a_Name, a_Version); break; - case cProtocolRecognizer::PROTO_VERSION_1_10_0: m_ForgeMods_1_10_0.Add(a_Name, a_Version); break; - case cProtocolRecognizer::PROTO_VERSION_1_11_0: m_ForgeMods_1_11_0.Add(a_Name, a_Version); break; - case cProtocolRecognizer::PROTO_VERSION_1_11_1: m_ForgeMods_1_11_1.Add(a_Name, a_Version); break; - case cProtocolRecognizer::PROTO_VERSION_1_12: m_ForgeMods_1_12.Add(a_Name, a_Version); break; - case 0: - default: - m_ForgeMods_1_8_0.Add(a_Name, a_Version); - m_ForgeMods_1_9_0.Add(a_Name, a_Version); - m_ForgeMods_1_9_1.Add(a_Name, a_Version); - m_ForgeMods_1_9_2.Add(a_Name, a_Version); - m_ForgeMods_1_9_4.Add(a_Name, a_Version); - m_ForgeMods_1_10_0.Add(a_Name, a_Version); - m_ForgeMods_1_11_0.Add(a_Name, a_Version); - m_ForgeMods_1_11_1.Add(a_Name, a_Version); - m_ForgeMods_1_12.Add(a_Name, a_Version); - break; - } + m_ForgeMods_1_8_0.Add(a_Name, a_Version); + m_ForgeMods_1_9_0.Add(a_Name, a_Version); + m_ForgeMods_1_9_1.Add(a_Name, a_Version); + m_ForgeMods_1_9_2.Add(a_Name, a_Version); + m_ForgeMods_1_9_4.Add(a_Name, a_Version); + m_ForgeMods_1_10_0.Add(a_Name, a_Version); + m_ForgeMods_1_11_0.Add(a_Name, a_Version); + m_ForgeMods_1_11_1.Add(a_Name, a_Version); + m_ForgeMods_1_12.Add(a_Name, a_Version); +} + + + + + +void cServer::RegisterForgeModForProtocol(AString & a_Name, AString & a_Version, UInt32 a_Protocol) +{ + cForgeMods & mods = GetRegisteredForgeMods(a_Protocol); + mods.Add(a_Name, a_Version); } diff --git a/src/Server.h b/src/Server.h index 0825fec1d1..ea04164e65 100644 --- a/src/Server.h +++ b/src/Server.h @@ -72,7 +72,8 @@ class cServer int GetNumPlayers(void) const; void SetMaxPlayers(int a_MaxPlayers) { m_MaxPlayers = a_MaxPlayers; } - void RegisterForgeMod(int a_Protocol, AString & a_ModName, AString & a_ModVersion); + void RegisterForgeMod(AString & a_ModName, AString & a_ModVersion); + void RegisterForgeModForProtocol(AString & a_ModName, AString & a_ModVersion, UInt32 a_Protocol); /** Check if the player is queued to be transferred to a World. Returns true is Player is found in queue. */ From 02dc012c5ab47f88158ec36eb7f1c38af17769fe Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 15 Jul 2017 16:14:45 -0700 Subject: [PATCH 047/166] Server ping list doesn't include modinfo unless Forge mods were registered --- src/Protocol/ForgeHandshake.cpp | 8 ++++++-- src/Protocol/ForgeMods.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index bcb45d1b8c..0e38f6a56c 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -22,6 +22,12 @@ cForgeHandshake::cForgeHandshake(cClientHandle *client) : m_isForgeClient(false) void cForgeHandshake::AugmentServerListPing(Json::Value & ResponseValue) { UInt32 ProtocolVersion = m_Client->GetProtocolVersion(); + cForgeMods & mods = cRoot::Get()->GetServer()->GetRegisteredForgeMods(ProtocolVersion); + + if (!mods.IsModded()) + { + return; + } LOG("Received server ping from version: %d", ProtocolVersion); @@ -32,8 +38,6 @@ void cForgeHandshake::AugmentServerListPing(Json::Value & ResponseValue) Json::Value ModList(Json::arrayValue); - cForgeMods & mods = cRoot::Get()->GetServer()->GetRegisteredForgeMods(ProtocolVersion); - for (auto& item: mods.GetMods()) { Json::Value Mod; diff --git a/src/Protocol/ForgeMods.h b/src/Protocol/ForgeMods.h index 320196cd2f..62d977fbde 100644 --- a/src/Protocol/ForgeMods.h +++ b/src/Protocol/ForgeMods.h @@ -38,6 +38,8 @@ class cForgeMods AStringMap GetMods() { return m_Mods; } + bool IsModded() { return m_Mods.size() != 0; } + private: AStringMap m_Mods; AStringVector m_ModNames; From c8f5b14c74ad7ee32adcd7836d276217b890e597 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 15 Jul 2017 16:16:35 -0700 Subject: [PATCH 048/166] Remove some unnecessary whitespace changes --- src/Protocol/Protocol_1_12.cpp | 2 +- src/Server.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp index 8106bbbe66..78c9151f7c 100644 --- a/src/Protocol/Protocol_1_12.cpp +++ b/src/Protocol/Protocol_1_12.cpp @@ -393,7 +393,7 @@ void cProtocol_1_12::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) // Description: Json::Value Description; Description["text"] = ServerDescription.c_str(); - + // Create the response: Json::Value ResponseValue; ResponseValue["version"] = Version; diff --git a/src/Server.h b/src/Server.h index ea04164e65..14c5437f4a 100644 --- a/src/Server.h +++ b/src/Server.h @@ -87,7 +87,7 @@ class cServer bool IsHardcore(void) const { return m_bIsHardcore; } // tolua_end - + bool Start(void); bool Command(cClientHandle & a_Client, AString & a_Cmd); @@ -219,7 +219,7 @@ class cServer AString m_FaviconData; int m_MaxPlayers; bool m_bIsHardcore; - + // TODO: std::map data structure? cForgeMods m_ForgeMods_1_8_0; cForgeMods m_ForgeMods_1_9_0; From 6705990724d2d61bf8a47d21942dfb7566cf01d6 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 15 Jul 2017 16:17:38 -0700 Subject: [PATCH 049/166] Revert submodule Core checkout change --- Server/Plugins/Core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/Plugins/Core b/Server/Plugins/Core index 68430458a3..3e8b70dcb1 160000 --- a/Server/Plugins/Core +++ b/Server/Plugins/Core @@ -1 +1 @@ -Subproject commit 68430458a3ea695cac85bc82136941bc83253e1e +Subproject commit 3e8b70dcb11c7d5f8c6f68494b108b14c9fca141 From 280113e0f36188c37fe46e80bbcf03cebf3a1d7b Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 22 Jul 2017 12:49:37 -0700 Subject: [PATCH 050/166] Add cClientHandle IsModded() --- src/ClientHandle.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ClientHandle.h b/src/ClientHandle.h index f9c260179c..0a229fa6f5 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -268,6 +268,9 @@ class cClientHandle // tolua_export /** Returns the Forge mods installed on the client. */ const cForgeMods & GetForgeMods(void) const { return m_ForgeMods ? *m_ForgeMods : cForgeMods::Unmodded(); } + + /** Returns true if the client is modded with Forge. */ + bool IsModded(void) const { return m_ForgeHandshake.m_isForgeClient; } // tolua_end From 8910218c7d310873a2e92610f8611d5c3563b0f2 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 22 Jul 2017 21:22:10 -0700 Subject: [PATCH 051/166] Revert unnecessary whitespace changes --- src/Bindings/PluginLua.cpp | 2 +- src/ClientHandle.cpp | 2 +- src/ClientHandle.h | 2 +- src/Protocol/Protocol_1_9.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 424e412f1d..5951192b0e 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -1093,7 +1093,7 @@ const char * cPluginLua::GetHookFnName(int a_HookType) case cPluginManager::HOOK_WEATHER_CHANGED: return "OnWeatherChanged"; case cPluginManager::HOOK_WEATHER_CHANGING: return "OnWeatherChanging"; case cPluginManager::HOOK_WORLD_TICK: return "OnWorldTick"; - + case cPluginManager::HOOK_NUM_HOOKS: { // Satisfy a warning that all enum values should be used in a switch diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 59df9bd026..bfab14b5cc 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -355,7 +355,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, { m_Properties = a_Properties; } - + // Send login success (if the protocol supports it): m_Protocol->SendLoginSuccess(); diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 0a229fa6f5..962bdab601 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -92,7 +92,7 @@ class cClientHandle // tolua_export void SetUUID(const AString & a_UUID) { ASSERT(a_UUID.size() == 32); m_UUID = a_UUID; } const Json::Value & GetProperties(void) const { return m_Properties; } - + /** Sets the player's properties, such as skin image and signature. Used mainly by BungeeCord compatibility code - property querying is done on the BungeeCord server and the results are passed to MCS running in offline mode. */ diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index 8b81cf1096..ecb2e2cf07 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -121,7 +121,7 @@ cProtocol_1_9_0::cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_Ser m_ReceivedData(32 KiB), m_IsEncrypted(false) { - + AStringVector Params; SplitZeroTerminatedStrings(a_ServerAddress, Params); From c2c575e95ac5666ea2c63c42a07ce73bccec466c Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 22 Jul 2017 21:31:24 -0700 Subject: [PATCH 052/166] Remove outdated comment --- src/ClientHandle.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index bfab14b5cc..ee4ed3cb60 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -359,9 +359,9 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, // Send login success (if the protocol supports it): m_Protocol->SendLoginSuccess(); - if (m_ForgeHandshake.m_isForgeClient) { + if (m_ForgeHandshake.m_isForgeClient) + { m_ForgeHandshake.BeginForgeHandshake(a_Name, a_UUID, a_Properties); - // TODO: only continue below after Forge handshake completes! } else { From 78a094e082d825b9decb84498d6357f1bb693a0f Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 22 Jul 2017 21:54:37 -0700 Subject: [PATCH 053/166] Add documentation for new Lua API --- Server/Plugins/APIDump/APIDesc.lua | 108 +++++++++++++++++++++++++++++ src/Protocol/ForgeMods.h | 4 +- 2 files changed, 110 insertions(+), 2 deletions(-) diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua index 58a79fb664..6accf556cb 100644 --- a/Server/Plugins/APIDump/APIDesc.lua +++ b/Server/Plugins/APIDump/APIDesc.lua @@ -1348,6 +1348,16 @@ end }, Notes = "Returns the brand that the client has sent in their MC|Brand plugin message.", }, + GetForgeMods = + { + Returns = + { + { + Type = "cForgeMods", + }, + }, + Notes = "Returns the Forge mods installed on the client.", + }, GetIPString = { Returns = @@ -1466,6 +1476,16 @@ end }, Notes = "Returns true if the client has registered to receive messages on the specified plugin channel.", }, + IsModded = + { + Returns = + { + { + Type = "boolean", + }, + }, + Notes = "Returns true if the client is modded with Forge.", + }, IsUUIDOnline = { IsStatic = true, @@ -4819,6 +4839,94 @@ cFile:DeleteFile("/usr/bin/virus.exe"); }, Inherits = "cEntity", }, + cForgeMods = + { + Desc = [[ + Data structure listing the Forge mods name and versions. + ]], + Functions = + { + GetModNameAt = + { + Params = + { + { + Name = "i", + Type = "number", + }, + }, + Returns = + { + { + Type = "string", + }, + }, + Notes = "Returns the name of the Forge mod at the given index.", + }, + GetModVersion = + { + Params = + { + { + Name = "name", + Type = "string", + }, + }, + Returns = + { + { + Type = "string", + }, + }, + Notes = "Returns the version of the mod name given.", + + }, + GetModVersionAt = + { + Params = + { + { + Name = "i", + Type = "number", + }, + }, + Returns = + { + { + Type = "string", + }, + }, + Notes = "Returns the version of the Forge mod at the given index.", + }, + GetNumMods = + { + Returns = + { + { + Type = "number", + }, + }, + Notes = "Returns the number of Forge mods.", + }, + HasMod = + { + Params = + { + { + Name = "name", + Type = "string", + }, + }, + Returns = + { + { + Type = "boolean", + }, + }, + Notes = "Returns true if the mod with the given name is installed.", + }, + }, + }, cHangingEntity = { Functions = diff --git a/src/Protocol/ForgeMods.h b/src/Protocol/ForgeMods.h index 62d977fbde..34846d2a34 100644 --- a/src/Protocol/ForgeMods.h +++ b/src/Protocol/ForgeMods.h @@ -1,7 +1,7 @@ // ForgeMods.h -// Data structure listing the Forge mods name and versions +// Data structure listing the Forge mods name and versions. #pragma once @@ -16,7 +16,7 @@ class cForgeMods /** Returns the number of Forge mods. */ size_t GetNumMods(void) const; - /** Returns true if the mod name is installed. */ + /** Returns true if the mod with the given name is installed. */ bool HasMod(AString & name) const; /** Returns the version of the mod name given. */ From d7f8fe94b42c9d6f800e845283db71f6780772f3 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 22 Jul 2017 22:07:22 -0700 Subject: [PATCH 054/166] Add cServer mod registration Lua API documentation --- Server/Plugins/APIDump/APIDesc.lua | 34 ++++++++++++++++++++++++++++++ src/Server.cpp | 6 +++--- src/Server.h | 5 ++++- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua index 6accf556cb..9b3d45c758 100644 --- a/Server/Plugins/APIDump/APIDesc.lua +++ b/Server/Plugins/APIDump/APIDesc.lua @@ -11797,6 +11797,40 @@ end }, Notes = "Returns true if the specified player is queued to be transferred to a World.", }, + RegisterForgeMod = + { + Params = + { + { + Name = "ModName", + Type = "string", + }, + { + Name = "ModVersion", + Type = "string", + }, + }, + Notes = "Add a Forge mod name/version to the server ping list.", + }, + RegisterForgeModForProtocol = + { + Params = + { + { + Name = "ModName", + Type = "string", + }, + { + Name = "ModVersion", + Type = "string", + }, + { + Name = "ProtocolVersionNumber", + Type = "number", + }, + }, + Notes = "Add a Forge mod name/version to the server ping list for all protocol versions.", + }, SetMaxPlayers = { Params = diff --git a/src/Server.cpp b/src/Server.cpp index b5f9edde25..b07c30829f 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -272,10 +272,10 @@ void cServer::RegisterForgeMod(AString & a_Name, AString & a_Version) -void cServer::RegisterForgeModForProtocol(AString & a_Name, AString & a_Version, UInt32 a_Protocol) +void cServer::RegisterForgeModForProtocol(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber) { - cForgeMods & mods = GetRegisteredForgeMods(a_Protocol); - mods.Add(a_Name, a_Version); + cForgeMods & mods = GetRegisteredForgeMods(a_ProtocolVersionNumber); + mods.Add(a_ModName, a_ModVersion); } diff --git a/src/Server.h b/src/Server.h index 14c5437f4a..76f019af37 100644 --- a/src/Server.h +++ b/src/Server.h @@ -72,8 +72,11 @@ class cServer int GetNumPlayers(void) const; void SetMaxPlayers(int a_MaxPlayers) { m_MaxPlayers = a_MaxPlayers; } + /** Add a Forge mod name/version to the server ping list. */ void RegisterForgeMod(AString & a_ModName, AString & a_ModVersion); - void RegisterForgeModForProtocol(AString & a_ModName, AString & a_ModVersion, UInt32 a_Protocol); + + /** Add a Forge mod name/version to the server ping list for one protocol version. */ + void RegisterForgeModForProtocol(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber); /** Check if the player is queued to be transferred to a World. Returns true is Player is found in queue. */ From 117a555cbf246ee77321025c72f18fe9476908f9 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 22 Jul 2017 22:21:02 -0700 Subject: [PATCH 055/166] Add mod unregistration APIs --- Server/Plugins/APIDump/APIDesc.lua | 26 ++++++++++++++++++++++++++ src/Protocol/ForgeMods.cpp | 16 ++++++++++++++++ src/Protocol/ForgeMods.h | 2 ++ src/Server.cpp | 27 +++++++++++++++++++++++++++ src/Server.h | 6 ++++++ 5 files changed, 77 insertions(+) diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua index 9b3d45c758..fd35326660 100644 --- a/Server/Plugins/APIDump/APIDesc.lua +++ b/Server/Plugins/APIDump/APIDesc.lua @@ -11852,6 +11852,32 @@ end }, Notes = "Returns true iff the server is set to authenticate players (\"online mode\").", }, + UnregisterForgeMod = + { + Params = + { + { + Name = "ModName", + Type = "string", + }, + }, + Notes = "Remove a Forge mod name/version from the server ping list.", + }, + UnregisterForgeModForProtocol = + { + Params = + { + { + Name = "ModName", + Type = "string", + }, + { + Name = "ProtocolVersionNumber", + Type = "number", + }, + }, + Notes = "Remove a Forge mod name/version from the server ping list.", + }, }, }, cStringCompression = diff --git a/src/Protocol/ForgeMods.cpp b/src/Protocol/ForgeMods.cpp index 3d72280884..924adabf49 100644 --- a/src/Protocol/ForgeMods.cpp +++ b/src/Protocol/ForgeMods.cpp @@ -82,3 +82,19 @@ void cForgeMods::Add(AString & a_Name, AString & a_Version) m_ModVersions.push_back(a_Version); m_Mods.insert(std::make_pair(a_Name, a_Version)); } + + + + + +void cForgeMods::Remove(AString & a_Name) +{ + auto it = std::find(m_ModNames.begin(), m_ModNames.end(), a_Name); + if (it != m_ModNames.end()) + { + m_ModNames.erase(it); + m_ModVersions.erase(it); + } + + m_Mods.erase(a_Name); +} diff --git a/src/Protocol/ForgeMods.h b/src/Protocol/ForgeMods.h index 34846d2a34..af8d821a5a 100644 --- a/src/Protocol/ForgeMods.h +++ b/src/Protocol/ForgeMods.h @@ -36,6 +36,8 @@ class cForgeMods void Add(AString & a_Name, AString & a_Version); + void Remove(AString & a_Name); + AStringMap GetMods() { return m_Mods; } bool IsModded() { return m_Mods.size() != 0; } diff --git a/src/Server.cpp b/src/Server.cpp index b07c30829f..c16cfc55ff 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -281,6 +281,33 @@ void cServer::RegisterForgeModForProtocol(AString & a_ModName, AString & a_ModVe + +void cServer::UnregisterForgeMod(AString &a_Name) +{ + // TODO: refactor + m_ForgeMods_1_8_0.Remove(a_Name); + m_ForgeMods_1_9_0.Remove(a_Name); + m_ForgeMods_1_9_1.Remove(a_Name); + m_ForgeMods_1_9_2.Remove(a_Name); + m_ForgeMods_1_9_4.Remove(a_Name); + m_ForgeMods_1_10_0.Remove(a_Name); + m_ForgeMods_1_11_0.Remove(a_Name); + m_ForgeMods_1_11_1.Remove(a_Name); + m_ForgeMods_1_12.Remove(a_Name); +} + + + + +void cServer::UnregisterForgeModForProtocol(AString &a_ModName, UInt32 a_ProtocolVersionNumber) +{ + cForgeMods & mods = GetRegisteredForgeMods(a_ProtocolVersionNumber); + mods.Remove(a_ModName); +} + + + + cForgeMods & cServer::GetRegisteredForgeMods(UInt32 a_Protocol) { switch(a_Protocol) diff --git a/src/Server.h b/src/Server.h index 76f019af37..5e43bbaec2 100644 --- a/src/Server.h +++ b/src/Server.h @@ -77,6 +77,12 @@ class cServer /** Add a Forge mod name/version to the server ping list for one protocol version. */ void RegisterForgeModForProtocol(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber); + + /** Remove a Forge mod name/version from the server ping list. */ + void UnregisterForgeMod(AString & a_ModName); + + /** Remove a Forge mod name/version to the server ping list for one protocol version. */ + void UnregisterForgeModForProtocol(AString & a_ModName, UInt32 a_ProtocolVersionNumber); /** Check if the player is queued to be transferred to a World. Returns true is Player is found in queue. */ From 8af34c0e5bdf22b98e7f80ffdb0ae339ee3fc882 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 22 Jul 2017 22:29:35 -0700 Subject: [PATCH 056/166] Remove another outdated comment (unmodded checked above) --- src/Protocol/ForgeHandshake.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 0e38f6a56c..a0b801e10b 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -32,7 +32,6 @@ void cForgeHandshake::AugmentServerListPing(Json::Value & ResponseValue) LOG("Received server ping from version: %d", ProtocolVersion); // modinfo: - // TODO: only send if mods enabled Json::Value Modinfo; Modinfo["type"] = "FML"; From 81d4d71ff787c15284065e92a1c62c06e692b53b Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 22 Jul 2017 22:31:11 -0700 Subject: [PATCH 057/166] Rename to HasMods clarifying no mods on server, versus modded but possibly empty client (IsModded) --- src/Protocol/ForgeHandshake.cpp | 2 +- src/Protocol/ForgeMods.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index a0b801e10b..7dbe488ed3 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -24,7 +24,7 @@ void cForgeHandshake::AugmentServerListPing(Json::Value & ResponseValue) UInt32 ProtocolVersion = m_Client->GetProtocolVersion(); cForgeMods & mods = cRoot::Get()->GetServer()->GetRegisteredForgeMods(ProtocolVersion); - if (!mods.IsModded()) + if (!mods.HasMods()) { return; } diff --git a/src/Protocol/ForgeMods.h b/src/Protocol/ForgeMods.h index af8d821a5a..344e8f13be 100644 --- a/src/Protocol/ForgeMods.h +++ b/src/Protocol/ForgeMods.h @@ -40,7 +40,7 @@ class cForgeMods AStringMap GetMods() { return m_Mods; } - bool IsModded() { return m_Mods.size() != 0; } + bool HasMods() { return m_Mods.size() != 0; } private: AStringMap m_Mods; From caafd128a1365585a137190bd3015dd2fe96b5ab Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 22 Jul 2017 22:40:16 -0700 Subject: [PATCH 058/166] Send plugin-registered server-side Forge mods in FML|HS ModList packet --- src/Protocol/ForgeHandshake.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 7dbe488ed3..c20b3e8a7f 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -201,23 +201,16 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data cByteBuffer buf(1024); // TODO: max size? - // TODO: allow plugins to register mods, for now, using based on what my test client sent - struct { - AString name; - AString version; - } mods[] = { - { "minecraft", "1.12" }, - { "FML", "8.0.99.999.forge" }, - { "forge", "14.21.1.2387.mcp-XXX" }, - { "ironchest", "1.12-7.0.31.818" }, - }; - UInt32 modCount = sizeof(mods) / sizeof(mods[0]); + // Send server-side Forge mods registered by plugins + auto &serverMods = m_Client->GetForgeMods(); + + UInt32 modCount = serverMods.GetNumMods(); buf.WriteBEInt8(Discriminator_ModList); buf.WriteVarInt32(modCount); for (size_t i = 0; i < modCount; ++i) { - buf.WriteVarUTF8String(mods[i].name); - buf.WriteVarUTF8String(mods[i].version); + buf.WriteVarUTF8String(serverMods.GetModNameAt(i)); + buf.WriteVarUTF8String(serverMods.GetModVersionAt(i)); } AString serverModList; buf.ReadAll(serverModList); From 3158c152ee633c7cfc8c5ded5b75f42fabcf6d3d Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 22 Jul 2017 22:43:08 -0700 Subject: [PATCH 059/166] Fix cForgeMods Remove() iterator erasing from versions vector --- src/Protocol/ForgeMods.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Protocol/ForgeMods.cpp b/src/Protocol/ForgeMods.cpp index 924adabf49..c36b2867c4 100644 --- a/src/Protocol/ForgeMods.cpp +++ b/src/Protocol/ForgeMods.cpp @@ -92,8 +92,10 @@ void cForgeMods::Remove(AString & a_Name) auto it = std::find(m_ModNames.begin(), m_ModNames.end(), a_Name); if (it != m_ModNames.end()) { - m_ModNames.erase(it); - m_ModVersions.erase(it); + size_t index = std::distance(m_ModNames.begin(), it); + + m_ModNames.erase(m_ModNames.begin() + index); + m_ModVersions.erase(m_ModVersions.begin() + index); } m_Mods.erase(a_Name); From 2950468d278b0e9c5d59ee008c109cc726ef93a0 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 22 Jul 2017 23:17:31 -0700 Subject: [PATCH 060/166] Fix trailing whitespace style violations --- src/Bindings/PluginManager.cpp | 2 +- src/ClientHandle.cpp | 4 +- src/ClientHandle.h | 14 ++--- src/Protocol/ForgeHandshake.cpp | 100 ++++++++++++++++---------------- src/Protocol/ForgeHandshake.h | 20 +++---- src/Protocol/ForgeMods.cpp | 6 +- src/Protocol/ForgeMods.h | 18 +++--- src/Protocol/Protocol_1_9.cpp | 8 +-- src/Server.h | 12 ++-- 9 files changed, 92 insertions(+), 92 deletions(-) diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index 219876adb3..37259ff4bc 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -793,7 +793,7 @@ bool cPluginManager::CallHookLoginForge(cClientHandle & a_Client) { FIND_HOOK(HOOK_LOGIN_FORGE) VERIFY_HOOK; - + for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) { if ((*itr)->OnLoginForge(a_Client)) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index ee4ed3cb60..72a2b6f33f 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -139,7 +139,7 @@ cClientHandle::~cClientHandle() delete m_Player; m_Player = nullptr; } - + if (m_ForgeMods != nullptr) { delete m_ForgeMods; @@ -358,7 +358,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, // Send login success (if the protocol supports it): m_Protocol->SendLoginSuccess(); - + if (m_ForgeHandshake.m_isForgeClient) { m_ForgeHandshake.BeginForgeHandshake(a_Name, a_UUID, a_Properties); diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 962bdab601..32fa287bb1 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -265,10 +265,10 @@ class cClientHandle // tolua_export /** Returns the client brand received in the MC|Brand plugin message or set by a plugin. */ const AString & GetClientBrand(void) const { return m_ClientBrand; } - + /** Returns the Forge mods installed on the client. */ const cForgeMods & GetForgeMods(void) const { return m_ForgeMods ? *m_ForgeMods : cForgeMods::Unmodded(); } - + /** Returns true if the client is modded with Forge. */ bool IsModded(void) const { return m_ForgeHandshake.m_isForgeClient; } @@ -384,9 +384,9 @@ class cClientHandle // tolua_export void InvalidateCachedSentChunk(); bool IsPlayerChunkSent(); - + cForgeHandshake m_ForgeHandshake; - + cForgeMods * m_ForgeMods; private: @@ -395,9 +395,9 @@ class cClientHandle // tolua_export eDimension m_LastSentDimension; friend class cServer; // Needs access to SetSelf() - + friend class cForgeHandshake; // Needs access to PostAuthenticate() - + /** The type used for storing the names of registered plugin channels. */ typedef std::set cChannels; @@ -544,7 +544,7 @@ class cClientHandle // tolua_export cClientHandlePtr m_Self; float m_BreakProgress; - + /** Finish logging the user in after authenticating. */ void FinishAuthenticate(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties); diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index c20b3e8a7f..145423784a 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -23,20 +23,20 @@ void cForgeHandshake::AugmentServerListPing(Json::Value & ResponseValue) { UInt32 ProtocolVersion = m_Client->GetProtocolVersion(); cForgeMods & mods = cRoot::Get()->GetServer()->GetRegisteredForgeMods(ProtocolVersion); - + if (!mods.HasMods()) { return; } - + LOG("Received server ping from version: %d", ProtocolVersion); - + // modinfo: Json::Value Modinfo; Modinfo["type"] = "FML"; Json::Value ModList(Json::arrayValue); - + for (auto& item: mods.GetMods()) { Json::Value Mod; @@ -44,7 +44,7 @@ void cForgeHandshake::AugmentServerListPing(Json::Value & ResponseValue) Mod["version"] = item.second; ModList.append(Mod); } - + Modinfo["modList"] = ModList; // Augment the response: @@ -58,20 +58,20 @@ void cForgeHandshake::AugmentServerListPing(Json::Value & ResponseValue) void cForgeHandshake::BeginForgeHandshake(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties) { ASSERT(m_isForgeClient); - + m_Name = &a_Name; m_UUID = &a_UUID; m_Properties = &a_Properties; - + AStringVector channels = { "FML|HS", "FML", "FML|MP", "FML", "FORGE" }; AString channelsString; - + for (AStringVector::iterator itr = channels.begin(); itr != channels.end(); ++itr) { channelsString.append(*itr); channelsString.push_back('\0'); } - + m_Client->SendPluginMessage("REGISTER", channelsString); SendServerHello(); } @@ -90,7 +90,7 @@ void cForgeHandshake::SendServerHello() message.push_back('\0'); message.push_back('\0'); message.push_back('\0'); - + m_Client->SendPluginMessage("FML|HS", message); } @@ -98,31 +98,31 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) { cByteBuffer buf(a_Size); buf.Write(a_Data, a_Size); - + Int8 discriminator; buf.ReadBEInt8(discriminator); //LOG("ParseModList disc = %d", discriminator); - + ASSERT(discriminator == 2); - + UInt32 numMods; buf.ReadVarInt32(numMods); - + //LOG("ParseModList numMods = %d", numMods); - + AStringMap mods; - + for (size_t i = 0; i < numMods; ++i) { AString name, version; buf.ReadVarUTF8String(name); buf.ReadVarUTF8String(version); - + mods.insert(std::pair(name, version)); - + //LOG("ParseModList name=%s, version=%s", name.c_str(), version.c_str()); } - + return mods; } @@ -132,18 +132,18 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data LOG("Received unexpected Forge data from non-Forge client (%zu bytes)", a_Size); return; } - + // TODO: handle errors - + LOG("Received Forge data: %zu bytes: %s", a_Size, a_Data); - + if (a_Size <= 1) { LOG("Received unexpectedly short Forge data (%zu bytes)", a_Size); return; } - + int discriminator = a_Data[0]; - + switch (discriminator) { case Discriminator_ClientHello: @@ -162,14 +162,14 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data LOG("Unexpectedly short ClientHello received"); SetError(); } - + break; } - + case Discriminator_ModList: { LOG("Received ModList"); - + AStringMap clientMods = ParseModList(a_Data, a_Size); AString clientModsString; for (auto& item: clientMods) @@ -179,16 +179,16 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data clientModsString.append(item.second); clientModsString.append(", "); } - + LOG("Client connected with %zu mods: %s", clientMods.size(), clientModsString.c_str()); - + if (m_Client->m_ForgeMods != nullptr) { delete m_Client->m_ForgeMods; } - + m_Client->m_ForgeMods = new cForgeMods(clientMods); - + // Let the plugins know about this event, they may refuse the player: if (cRoot::Get()->GetPluginManager()->CallHookLoginForge(*a_Client)) { @@ -196,16 +196,16 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data SetError(); return; } - + // Send server ModList - + cByteBuffer buf(1024); // TODO: max size? - + // Send server-side Forge mods registered by plugins auto &serverMods = m_Client->GetForgeMods(); - + UInt32 modCount = serverMods.GetNumMods(); - + buf.WriteBEInt8(Discriminator_ModList); buf.WriteVarInt32(modCount); for (size_t i = 0; i < modCount; ++i) { @@ -214,11 +214,11 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data } AString serverModList; buf.ReadAll(serverModList); - + m_Client->SendPluginMessage("FML|HS", serverModList); break; } - + case Discriminator_HandshakeAck: { if (a_Size != 2) @@ -227,57 +227,57 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data SetError(); break; } - + int phase = a_Data[1]; LOG("Received client HandshakeAck with phase=%d", phase); - + switch (phase) { case ClientPhase_WAITINGSERVERDATA: { cByteBuffer buf(1024); buf.WriteBEInt8(Discriminator_RegistryData); - + // TODO: send real registry data bool hasMore = false; AString registryName = "potions"; UInt32 numIDs = 0; UInt32 numSubstitutions = 0; UInt32 numDummies = 0; - + buf.WriteBool(hasMore); buf.WriteVarUTF8String(registryName); buf.WriteVarInt32(numIDs); buf.WriteVarInt32(numSubstitutions); buf.WriteVarInt32(numDummies); - + AString registryData; buf.ReadAll(registryData); m_Client->SendPluginMessage("FML|HS", registryData); break; } - + case ClientPhase_WAITINGSERVERCOMPLETE: { LOG("Client finished receiving registry data; acknowledging"); - - + + AString ack; ack.push_back(Discriminator_HandshakeAck); ack.push_back(ServerPhase_WAITINGCACK); m_Client->SendPluginMessage("FML|HS", ack); break; } - + case ClientPhase_PENDINGCOMPLETE: { LOG("Client is pending completion; sending complete ack"); - + AString ack; ack.push_back(Discriminator_HandshakeAck); ack.push_back(ServerPhase_COMPLETE); m_Client->SendPluginMessage("FML|HS", ack); - + // Now finish logging in m_Client->FinishAuthenticate(*m_Name, *m_UUID, *m_Properties); break; @@ -285,7 +285,7 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data } break; } - + default: LOG("Unexpected Forge packet %d received", discriminator); SetError(); diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index 9a2773bcb6..9d906ff9c6 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -18,27 +18,27 @@ class cForgeHandshake { public: cForgeHandshake(cClientHandle * client); - + void AugmentServerListPing(Json::Value & ResponseValue); void BeginForgeHandshake(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties); - + void SendServerHello(); void DataReceived(cClientHandle * a_Client, const char * a_Data, size_t a_Size); - + AStringMap ParseModList(const char * a_Data, size_t a_Size); - + bool m_isForgeClient; - + private: void SetError(); bool m_Errored; - + cClientHandle * m_Client; - + const AString * m_Name; const AString * m_UUID; const Json::Value * m_Properties; - + enum { Discriminator_ServerHello = 0, @@ -48,7 +48,7 @@ class cForgeHandshake Discriminator_HandshakeReset = -2, Discriminator_HandshakeAck = -1, }; - + enum { ClientPhase_WAITINGSERVERDATA = 2, @@ -56,7 +56,7 @@ class cForgeHandshake ClientPhase_PENDINGCOMPLETE = 4, ClientPhase_COMPLETE = 5, }; - + enum { ServerPhase_WAITINGCACK = 2, diff --git a/src/Protocol/ForgeMods.cpp b/src/Protocol/ForgeMods.cpp index c36b2867c4..f371f3f792 100644 --- a/src/Protocol/ForgeMods.cpp +++ b/src/Protocol/ForgeMods.cpp @@ -29,7 +29,7 @@ cForgeMods::cForgeMods(AStringMap a):m_Mods(a) const cForgeMods & cForgeMods::Unmodded(void) { static cForgeMods unmodded; - + return unmodded; } @@ -93,10 +93,10 @@ void cForgeMods::Remove(AString & a_Name) if (it != m_ModNames.end()) { size_t index = std::distance(m_ModNames.begin(), it); - + m_ModNames.erase(m_ModNames.begin() + index); m_ModVersions.erase(m_ModVersions.begin() + index); } - + m_Mods.erase(a_Name); } diff --git a/src/Protocol/ForgeMods.h b/src/Protocol/ForgeMods.h index 344e8f13be..d5851a7fcc 100644 --- a/src/Protocol/ForgeMods.h +++ b/src/Protocol/ForgeMods.h @@ -15,10 +15,10 @@ class cForgeMods /** Returns the number of Forge mods. */ size_t GetNumMods(void) const; - + /** Returns true if the mod with the given name is installed. */ bool HasMod(AString & name) const; - + /** Returns the version of the mod name given. */ const AString & GetModVersion(AString & name) const; @@ -28,20 +28,20 @@ class cForgeMods /** Returns the version of the Forge mod at the given index. */ const AString & GetModVersionAt(size_t i) const; // tolua_end - + cForgeMods(); cForgeMods(AStringMap a); - + static const cForgeMods & Unmodded(void); - + void Add(AString & a_Name, AString & a_Version); - + void Remove(AString & a_Name); - + AStringMap GetMods() { return m_Mods; } - + bool HasMods() { return m_Mods.size() != 0; } - + private: AStringMap m_Mods; AStringVector m_ModNames; diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index ecb2e2cf07..3876df80c5 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -124,10 +124,10 @@ cProtocol_1_9_0::cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_Ser AStringVector Params; SplitZeroTerminatedStrings(a_ServerAddress, Params); - + if (Params.size() >= 2) { m_ServerAddress = Params[0]; - + if (Params[1] == "FML") { LOG("Forge client connected!"); m_Client->m_ForgeHandshake.m_isForgeClient = true; @@ -136,9 +136,9 @@ cProtocol_1_9_0::cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_Ser // BungeeCord handling: // If BC is setup with ip_forward == true, it sends additional data in the login packet's ServerAddress field: // hostname\00ip-address\00uuid\00profile-properties-as-json - + LOGD("Player at %s connected via BungeeCord", Params[1].c_str()); - + m_Client->SetIPString(Params[1]); m_Client->SetUUID(cMojangAPI::MakeUUIDShort(Params[2])); m_Client->SetProperties(Params[3]); diff --git a/src/Server.h b/src/Server.h index 5e43bbaec2..37af4ef941 100644 --- a/src/Server.h +++ b/src/Server.h @@ -71,16 +71,16 @@ class cServer int GetMaxPlayers(void) const { return m_MaxPlayers; } int GetNumPlayers(void) const; void SetMaxPlayers(int a_MaxPlayers) { m_MaxPlayers = a_MaxPlayers; } - + /** Add a Forge mod name/version to the server ping list. */ void RegisterForgeMod(AString & a_ModName, AString & a_ModVersion); /** Add a Forge mod name/version to the server ping list for one protocol version. */ void RegisterForgeModForProtocol(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber); - + /** Remove a Forge mod name/version from the server ping list. */ void UnregisterForgeMod(AString & a_ModName); - + /** Remove a Forge mod name/version to the server ping list for one protocol version. */ void UnregisterForgeModForProtocol(AString & a_ModName, UInt32 a_ProtocolVersionNumber); @@ -160,9 +160,9 @@ class cServer /** Returns true if usernames should be completed across worlds. This is read from the settings. */ bool ShouldAllowMultiWorldTabCompletion(void) const { return m_ShouldAllowMultiWorldTabCompletion; } - + cForgeMods & GetRegisteredForgeMods(UInt32 a_Protocol); - + private: friend class cRoot; // so cRoot can create and destroy cServer @@ -240,7 +240,7 @@ class cServer cForgeMods m_ForgeMods_1_11_0; cForgeMods m_ForgeMods_1_11_1; cForgeMods m_ForgeMods_1_12; - + /** True - allow same username to login more than once False - only once */ bool m_bAllowMultiLogin; From e865cf7530059c4582d414c1b12fb023751cec1d Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 22 Jul 2017 23:19:45 -0700 Subject: [PATCH 061/166] Fixed signedness errors not caught with Xcode cmake target --- src/Protocol/ForgeHandshake.cpp | 4 ++-- src/Protocol/ForgeMods.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 145423784a..b816b42489 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -204,10 +204,10 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data // Send server-side Forge mods registered by plugins auto &serverMods = m_Client->GetForgeMods(); - UInt32 modCount = serverMods.GetNumMods(); + size_t modCount = serverMods.GetNumMods(); buf.WriteBEInt8(Discriminator_ModList); - buf.WriteVarInt32(modCount); + buf.WriteVarInt32(static_cast(modCount)); for (size_t i = 0; i < modCount; ++i) { buf.WriteVarUTF8String(serverMods.GetModNameAt(i)); buf.WriteVarUTF8String(serverMods.GetModVersionAt(i)); diff --git a/src/Protocol/ForgeMods.cpp b/src/Protocol/ForgeMods.cpp index f371f3f792..c90beffa45 100644 --- a/src/Protocol/ForgeMods.cpp +++ b/src/Protocol/ForgeMods.cpp @@ -92,7 +92,7 @@ void cForgeMods::Remove(AString & a_Name) auto it = std::find(m_ModNames.begin(), m_ModNames.end(), a_Name); if (it != m_ModNames.end()) { - size_t index = std::distance(m_ModNames.begin(), it); + auto index = std::distance(m_ModNames.begin(), it); m_ModNames.erase(m_ModNames.begin() + index); m_ModVersions.erase(m_ModVersions.begin() + index); From 82caf1b5068c5a658c181b9f76e5cf83d8f6bac6 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 22 Jul 2017 23:28:45 -0700 Subject: [PATCH 062/166] Fix style violations in ForgeHandshake and ForgeMods --- src/Protocol/ForgeHandshake.cpp | 52 +++++++++++++++++---------------- src/Protocol/ForgeMods.cpp | 2 +- src/Protocol/ForgeMods.h | 2 +- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index b816b42489..0d7e73f536 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -19,12 +19,12 @@ cForgeHandshake::cForgeHandshake(cClientHandle *client) : m_isForgeClient(false) -void cForgeHandshake::AugmentServerListPing(Json::Value & ResponseValue) +void cForgeHandshake::AugmentServerListPing(Json::Value & a_ResponseValue) { UInt32 ProtocolVersion = m_Client->GetProtocolVersion(); - cForgeMods & mods = cRoot::Get()->GetServer()->GetRegisteredForgeMods(ProtocolVersion); + cForgeMods & Mods = cRoot::Get()->GetServer()->GetRegisteredForgeMods(ProtocolVersion); - if (!mods.HasMods()) + if (!Mods.HasMods()) { return; } @@ -37,7 +37,7 @@ void cForgeHandshake::AugmentServerListPing(Json::Value & ResponseValue) Json::Value ModList(Json::arrayValue); - for (auto& item: mods.GetMods()) + for (auto & item: Mods.GetMods()) { Json::Value Mod; Mod["modid"] = item.first; @@ -48,7 +48,7 @@ void cForgeHandshake::AugmentServerListPing(Json::Value & ResponseValue) Modinfo["modList"] = ModList; // Augment the response: - ResponseValue["modinfo"] = Modinfo; + a_ResponseValue["modinfo"] = Modinfo; } @@ -83,8 +83,10 @@ void cForgeHandshake::BeginForgeHandshake(const AString & a_Name, const AString void cForgeHandshake::SendServerHello() { AString message; - message.push_back(Discriminator_ServerHello); // Discriminator Byte Always 0 for ServerHello - message.push_back('\2'); // FML protocol Version Byte Determined from NetworkRegistery. Currently 2. + // Discriminator | Byte | Always 0 for ServerHello + message.push_back(Discriminator_ServerHello); + // FML protocol Version | Byte | Determined from NetworkRegistery. Currently 2. + message.push_back('\2'); // Dimension TODO message.push_back('\0'); message.push_back('\0'); @@ -101,15 +103,12 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) Int8 discriminator; buf.ReadBEInt8(discriminator); - //LOG("ParseModList disc = %d", discriminator); ASSERT(discriminator == 2); UInt32 numMods; buf.ReadVarInt32(numMods); - //LOG("ParseModList numMods = %d", numMods); - AStringMap mods; for (size_t i = 0; i < numMods; ++i) @@ -120,7 +119,7 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) mods.insert(std::pair(name, version)); - //LOG("ParseModList name=%s, version=%s", name.c_str(), version.c_str()); + LOGD("ParseModList name=%s, version=%s", name.c_str(), version.c_str()); } return mods; @@ -128,16 +127,16 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data, size_t a_Size) { - if (!m_isForgeClient) { + if (!m_isForgeClient) + { LOG("Received unexpected Forge data from non-Forge client (%zu bytes)", a_Size); return; } - // TODO: handle errors + LOGD("Received Forge data: %zu bytes: %s", a_Size, a_Data); - LOG("Received Forge data: %zu bytes: %s", a_Size, a_Data); - - if (a_Size <= 1) { + if (a_Size <= 1) + { LOG("Received unexpectedly short Forge data (%zu bytes)", a_Size); return; } @@ -151,8 +150,9 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data if (a_Size == 2) { int fmlProtocolVersion = a_Data[1]; - LOG("Received ClientHello with FML protocol version %d", fmlProtocolVersion); - if (fmlProtocolVersion != 2) { + LOGD("Received ClientHello with FML protocol version %d", fmlProtocolVersion); + if (fmlProtocolVersion != 2) + { LOG("Unsupported FML client protocol version received in ClientHello: %d", fmlProtocolVersion); SetError(); } @@ -168,11 +168,11 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data case Discriminator_ModList: { - LOG("Received ModList"); + LOGD("Received ModList"); AStringMap clientMods = ParseModList(a_Data, a_Size); AString clientModsString; - for (auto& item: clientMods) + for (auto & item: clientMods) { clientModsString.append(item.first); clientModsString.append("@"); @@ -199,7 +199,8 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data // Send server ModList - cByteBuffer buf(1024); // TODO: max size? + // TODO: max size? + cByteBuffer buf(1024); // Send server-side Forge mods registered by plugins auto &serverMods = m_Client->GetForgeMods(); @@ -208,7 +209,8 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data buf.WriteBEInt8(Discriminator_ModList); buf.WriteVarInt32(static_cast(modCount)); - for (size_t i = 0; i < modCount; ++i) { + for (size_t i = 0; i < modCount; ++i) + { buf.WriteVarUTF8String(serverMods.GetModNameAt(i)); buf.WriteVarUTF8String(serverMods.GetModVersionAt(i)); } @@ -229,7 +231,7 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data } int phase = a_Data[1]; - LOG("Received client HandshakeAck with phase=%d", phase); + LOGD("Received client HandshakeAck with phase=%d", phase); switch (phase) { @@ -261,7 +263,6 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data { LOG("Client finished receiving registry data; acknowledging"); - AString ack; ack.push_back(Discriminator_HandshakeAck); ack.push_back(ServerPhase_WAITINGCACK); @@ -297,6 +298,7 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data -void cForgeHandshake::SetError() { +void cForgeHandshake::SetError() +{ m_Errored = true; } diff --git a/src/Protocol/ForgeMods.cpp b/src/Protocol/ForgeMods.cpp index c90beffa45..d36bd1b727 100644 --- a/src/Protocol/ForgeMods.cpp +++ b/src/Protocol/ForgeMods.cpp @@ -16,7 +16,7 @@ cForgeMods::cForgeMods() cForgeMods::cForgeMods(AStringMap a):m_Mods(a) { - for (auto const & item: a) + for (const auto & item: a) { m_ModNames.push_back(item.first); m_ModVersions.push_back(item.second); diff --git a/src/Protocol/ForgeMods.h b/src/Protocol/ForgeMods.h index d5851a7fcc..356ac45961 100644 --- a/src/Protocol/ForgeMods.h +++ b/src/Protocol/ForgeMods.h @@ -46,4 +46,4 @@ class cForgeMods AStringMap m_Mods; AStringVector m_ModNames; AStringVector m_ModVersions; -} ; // tolua_export +} ; // tolua_export From e70b0f32fc5cd5a615985f6c7afc00ca259a4c5c Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 22 Jul 2017 23:32:10 -0700 Subject: [PATCH 063/166] Fix remaining style violations caught by src/CheckBasicStyle.lua --- src/Protocol/Protocol_1_9.cpp | 21 +++++++++++++++------ src/Server.cpp | 2 +- src/Server.h | 8 ++++---- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index 3876df80c5..8fdbd37bc8 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -125,14 +125,19 @@ cProtocol_1_9_0::cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_Ser AStringVector Params; SplitZeroTerminatedStrings(a_ServerAddress, Params); - if (Params.size() >= 2) { + if (Params.size() >= 2) + { m_ServerAddress = Params[0]; - if (Params[1] == "FML") { + if (Params[1] == "FML") + { LOG("Forge client connected!"); m_Client->m_ForgeHandshake.m_isForgeClient = true; - } else if (Params.size() == 4) { - if (cRoot::Get()->GetServer()->ShouldAllowBungeeCord()) { + } + else if (Params.size() == 4) + { + if (cRoot::Get()->GetServer()->ShouldAllowBungeeCord()) + { // BungeeCord handling: // If BC is setup with ip_forward == true, it sends additional data in the login packet's ServerAddress field: // hostname\00ip-address\00uuid\00profile-properties-as-json @@ -142,10 +147,14 @@ cProtocol_1_9_0::cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_Ser m_Client->SetIPString(Params[1]); m_Client->SetUUID(cMojangAPI::MakeUUIDShort(Params[2])); m_Client->SetProperties(Params[3]); - } else { + } + else + { LOG("BungeeCord is disabled, but client sent additional data, set AllowBungeeCord=1 if you want to allow it"); } - } else { + } + else + { LOG("Unknown additional data sent in server address (BungeeCord/FML?): %zu parameters", Params.size()); // TODO: support FML + BungeeCord? (what parameters does it send in that case?) https://github.com/SpigotMC/BungeeCord/issues/899 } diff --git a/src/Server.cpp b/src/Server.cpp index c16cfc55ff..b72539ed94 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -310,7 +310,7 @@ void cServer::UnregisterForgeModForProtocol(AString &a_ModName, UInt32 a_Protoco cForgeMods & cServer::GetRegisteredForgeMods(UInt32 a_Protocol) { - switch(a_Protocol) + switch (a_Protocol) { case cProtocolRecognizer::PROTO_VERSION_1_8_0: return m_ForgeMods_1_8_0; case cProtocolRecognizer::PROTO_VERSION_1_9_0: return m_ForgeMods_1_9_0; diff --git a/src/Server.h b/src/Server.h index 37af4ef941..16226d1bd9 100644 --- a/src/Server.h +++ b/src/Server.h @@ -72,16 +72,16 @@ class cServer int GetNumPlayers(void) const; void SetMaxPlayers(int a_MaxPlayers) { m_MaxPlayers = a_MaxPlayers; } - /** Add a Forge mod name/version to the server ping list. */ + /** Add a Forge mod to the server ping list. */ void RegisterForgeMod(AString & a_ModName, AString & a_ModVersion); - /** Add a Forge mod name/version to the server ping list for one protocol version. */ + /** Add a Forge mod to the server ping list for one protocol version. */ void RegisterForgeModForProtocol(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber); - /** Remove a Forge mod name/version from the server ping list. */ + /** Remove a Forge mod from the server ping list. */ void UnregisterForgeMod(AString & a_ModName); - /** Remove a Forge mod name/version to the server ping list for one protocol version. */ + /** Remove a Forge mod to the server ping list for one protocol version. */ void UnregisterForgeModForProtocol(AString & a_ModName, UInt32 a_ProtocolVersionNumber); /** Check if the player is queued to be transferred to a World. From 46593e38f3f1b7b79c25f9c32e9d912755fb8766 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 22 Jul 2017 23:37:10 -0700 Subject: [PATCH 064/166] Fix capitalization on m_IsForgeClient member variable --- src/ClientHandle.cpp | 2 +- src/ClientHandle.h | 2 +- src/Protocol/ForgeHandshake.cpp | 6 +++--- src/Protocol/ForgeHandshake.h | 2 +- src/Protocol/Protocol_1_9.cpp | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 72a2b6f33f..19278b1342 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -359,7 +359,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, // Send login success (if the protocol supports it): m_Protocol->SendLoginSuccess(); - if (m_ForgeHandshake.m_isForgeClient) + if (m_ForgeHandshake.m_IsForgeClient) { m_ForgeHandshake.BeginForgeHandshake(a_Name, a_UUID, a_Properties); } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 32fa287bb1..b2d4a9ae99 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -270,7 +270,7 @@ class cClientHandle // tolua_export const cForgeMods & GetForgeMods(void) const { return m_ForgeMods ? *m_ForgeMods : cForgeMods::Unmodded(); } /** Returns true if the client is modded with Forge. */ - bool IsModded(void) const { return m_ForgeHandshake.m_isForgeClient; } + bool IsModded(void) const { return m_ForgeHandshake.m_IsForgeClient; } // tolua_end diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 0d7e73f536..ea10ada8fe 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -11,7 +11,7 @@ #include "../ClientHandle.h" #include "../Root.h" -cForgeHandshake::cForgeHandshake(cClientHandle *client) : m_isForgeClient(false), m_Errored(false), m_Client(client) +cForgeHandshake::cForgeHandshake(cClientHandle *client) : m_IsForgeClient(false), m_Errored(false), m_Client(client) { } @@ -57,7 +57,7 @@ void cForgeHandshake::AugmentServerListPing(Json::Value & a_ResponseValue) void cForgeHandshake::BeginForgeHandshake(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties) { - ASSERT(m_isForgeClient); + ASSERT(m_IsForgeClient); m_Name = &a_Name; m_UUID = &a_UUID; @@ -127,7 +127,7 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data, size_t a_Size) { - if (!m_isForgeClient) + if (!m_IsForgeClient) { LOG("Received unexpected Forge data from non-Forge client (%zu bytes)", a_Size); return; diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index 9d906ff9c6..5cd513e709 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -27,7 +27,7 @@ class cForgeHandshake AStringMap ParseModList(const char * a_Data, size_t a_Size); - bool m_isForgeClient; + bool m_IsForgeClient; private: void SetError(); diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index 8fdbd37bc8..a29c97cb17 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -132,7 +132,7 @@ cProtocol_1_9_0::cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_Ser if (Params[1] == "FML") { LOG("Forge client connected!"); - m_Client->m_ForgeHandshake.m_isForgeClient = true; + m_Client->m_ForgeHandshake.m_IsForgeClient = true; } else if (Params.size() == 4) { From 6c2d1778247e15d8a10354242ba6c1174ff65316 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 22 Jul 2017 23:47:16 -0700 Subject: [PATCH 065/166] Fix new variable names to CamelCase convention --- src/Protocol/ForgeHandshake.cpp | 168 ++++++++++++++++---------------- src/Protocol/ForgeMods.cpp | 4 +- 2 files changed, 86 insertions(+), 86 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index ea10ada8fe..439e197591 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -63,16 +63,16 @@ void cForgeHandshake::BeginForgeHandshake(const AString & a_Name, const AString m_UUID = &a_UUID; m_Properties = &a_Properties; - AStringVector channels = { "FML|HS", "FML", "FML|MP", "FML", "FORGE" }; - AString channelsString; + AStringVector Channels = { "FML|HS", "FML", "FML|MP", "FML", "FORGE" }; + AString ChannelsString; - for (AStringVector::iterator itr = channels.begin(); itr != channels.end(); ++itr) + for (AStringVector::iterator itr = Channels.begin(); itr != Channels.end(); ++itr) { - channelsString.append(*itr); - channelsString.push_back('\0'); + ChannelsString.append(*itr); + ChannelsString.push_back('\0'); } - m_Client->SendPluginMessage("REGISTER", channelsString); + m_Client->SendPluginMessage("REGISTER", ChannelsString); SendServerHello(); } @@ -82,47 +82,47 @@ void cForgeHandshake::BeginForgeHandshake(const AString & a_Name, const AString void cForgeHandshake::SendServerHello() { - AString message; + AString Message; // Discriminator | Byte | Always 0 for ServerHello - message.push_back(Discriminator_ServerHello); + Message.push_back(Discriminator_ServerHello); // FML protocol Version | Byte | Determined from NetworkRegistery. Currently 2. - message.push_back('\2'); + Message.push_back('\2'); // Dimension TODO - message.push_back('\0'); - message.push_back('\0'); - message.push_back('\0'); - message.push_back('\0'); + Message.push_back('\0'); + Message.push_back('\0'); + Message.push_back('\0'); + Message.push_back('\0'); - m_Client->SendPluginMessage("FML|HS", message); + m_Client->SendPluginMessage("FML|HS", Message); } AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) { - cByteBuffer buf(a_Size); - buf.Write(a_Data, a_Size); + cByteBuffer Buf(a_Size); + Buf.Write(a_Data, a_Size); - Int8 discriminator; - buf.ReadBEInt8(discriminator); + Int8 Discriminator; + Buf.ReadBEInt8(Discriminator); - ASSERT(discriminator == 2); + ASSERT(Discriminator == 2); - UInt32 numMods; - buf.ReadVarInt32(numMods); + UInt32 NumMods; + Buf.ReadVarInt32(NumMods); - AStringMap mods; + AStringMap Mods; - for (size_t i = 0; i < numMods; ++i) + for (size_t i = 0; i < NumMods; ++i) { - AString name, version; - buf.ReadVarUTF8String(name); - buf.ReadVarUTF8String(version); + AString Name, Version; + Buf.ReadVarUTF8String(Name); + Buf.ReadVarUTF8String(Version); - mods.insert(std::pair(name, version)); + Mods.insert(std::pair(Name, Version)); - LOGD("ParseModList name=%s, version=%s", name.c_str(), version.c_str()); + LOGD("ParseModList name=%s, version=%s", Name.c_str(), Version.c_str()); } - return mods; + return Mods; } void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data, size_t a_Size) @@ -141,19 +141,19 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data return; } - int discriminator = a_Data[0]; + int Discriminator = a_Data[0]; - switch (discriminator) + switch (Discriminator) { case Discriminator_ClientHello: { if (a_Size == 2) { - int fmlProtocolVersion = a_Data[1]; - LOGD("Received ClientHello with FML protocol version %d", fmlProtocolVersion); - if (fmlProtocolVersion != 2) + int FmlProtocolVersion = a_Data[1]; + LOGD("Received ClientHello with FML protocol version %d", FmlProtocolVersion); + if (FmlProtocolVersion != 2) { - LOG("Unsupported FML client protocol version received in ClientHello: %d", fmlProtocolVersion); + LOG("Unsupported FML client protocol version received in ClientHello: %d", FmlProtocolVersion); SetError(); } } @@ -170,24 +170,24 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data { LOGD("Received ModList"); - AStringMap clientMods = ParseModList(a_Data, a_Size); - AString clientModsString; - for (auto & item: clientMods) + AStringMap ClientMods = ParseModList(a_Data, a_Size); + AString ClientModsString; + for (auto & item: ClientMods) { - clientModsString.append(item.first); - clientModsString.append("@"); - clientModsString.append(item.second); - clientModsString.append(", "); + ClientModsString.append(item.first); + ClientModsString.append("@"); + ClientModsString.append(item.second); + ClientModsString.append(", "); } - LOG("Client connected with %zu mods: %s", clientMods.size(), clientModsString.c_str()); + LOG("Client connected with %zu mods: %s", ClientMods.size(), ClientModsString.c_str()); if (m_Client->m_ForgeMods != nullptr) { delete m_Client->m_ForgeMods; } - m_Client->m_ForgeMods = new cForgeMods(clientMods); + m_Client->m_ForgeMods = new cForgeMods(ClientMods); // Let the plugins know about this event, they may refuse the player: if (cRoot::Get()->GetPluginManager()->CallHookLoginForge(*a_Client)) @@ -200,24 +200,24 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data // Send server ModList // TODO: max size? - cByteBuffer buf(1024); + cByteBuffer Buf(1024); // Send server-side Forge mods registered by plugins - auto &serverMods = m_Client->GetForgeMods(); + auto &ServerMods = m_Client->GetForgeMods(); - size_t modCount = serverMods.GetNumMods(); + size_t ModCount = ServerMods.GetNumMods(); - buf.WriteBEInt8(Discriminator_ModList); - buf.WriteVarInt32(static_cast(modCount)); - for (size_t i = 0; i < modCount; ++i) + Buf.WriteBEInt8(Discriminator_ModList); + Buf.WriteVarInt32(static_cast(ModCount)); + for (size_t i = 0; i < ModCount; ++i) { - buf.WriteVarUTF8String(serverMods.GetModNameAt(i)); - buf.WriteVarUTF8String(serverMods.GetModVersionAt(i)); + Buf.WriteVarUTF8String(ServerMods.GetModNameAt(i)); + Buf.WriteVarUTF8String(ServerMods.GetModVersionAt(i)); } - AString serverModList; - buf.ReadAll(serverModList); + AString ServerModList; + Buf.ReadAll(ServerModList); - m_Client->SendPluginMessage("FML|HS", serverModList); + m_Client->SendPluginMessage("FML|HS", ServerModList); break; } @@ -230,32 +230,32 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data break; } - int phase = a_Data[1]; - LOGD("Received client HandshakeAck with phase=%d", phase); + int Phase = a_Data[1]; + LOGD("Received client HandshakeAck with phase=%d", Phase); - switch (phase) + switch (Phase) { case ClientPhase_WAITINGSERVERDATA: { - cByteBuffer buf(1024); - buf.WriteBEInt8(Discriminator_RegistryData); + cByteBuffer Buf(1024); + Buf.WriteBEInt8(Discriminator_RegistryData); // TODO: send real registry data - bool hasMore = false; - AString registryName = "potions"; - UInt32 numIDs = 0; - UInt32 numSubstitutions = 0; - UInt32 numDummies = 0; - - buf.WriteBool(hasMore); - buf.WriteVarUTF8String(registryName); - buf.WriteVarInt32(numIDs); - buf.WriteVarInt32(numSubstitutions); - buf.WriteVarInt32(numDummies); - - AString registryData; - buf.ReadAll(registryData); - m_Client->SendPluginMessage("FML|HS", registryData); + bool HasMore = false; + AString RegistryName = "potions"; + UInt32 NumIDs = 0; + UInt32 NumSubstitutions = 0; + UInt32 NumDummies = 0; + + Buf.WriteBool(HasMore); + Buf.WriteVarUTF8String(RegistryName); + Buf.WriteVarInt32(NumIDs); + Buf.WriteVarInt32(NumSubstitutions); + Buf.WriteVarInt32(NumDummies); + + AString RegistryData; + Buf.ReadAll(RegistryData); + m_Client->SendPluginMessage("FML|HS", RegistryData); break; } @@ -263,10 +263,10 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data { LOG("Client finished receiving registry data; acknowledging"); - AString ack; - ack.push_back(Discriminator_HandshakeAck); - ack.push_back(ServerPhase_WAITINGCACK); - m_Client->SendPluginMessage("FML|HS", ack); + AString Ack; + Ack.push_back(Discriminator_HandshakeAck); + Ack.push_back(ServerPhase_WAITINGCACK); + m_Client->SendPluginMessage("FML|HS", Ack); break; } @@ -274,10 +274,10 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data { LOG("Client is pending completion; sending complete ack"); - AString ack; - ack.push_back(Discriminator_HandshakeAck); - ack.push_back(ServerPhase_COMPLETE); - m_Client->SendPluginMessage("FML|HS", ack); + AString Ack; + Ack.push_back(Discriminator_HandshakeAck); + Ack.push_back(ServerPhase_COMPLETE); + m_Client->SendPluginMessage("FML|HS", Ack); // Now finish logging in m_Client->FinishAuthenticate(*m_Name, *m_UUID, *m_Properties); @@ -288,7 +288,7 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data } default: - LOG("Unexpected Forge packet %d received", discriminator); + LOG("Unexpected Forge packet %d received", Discriminator); SetError(); return; } diff --git a/src/Protocol/ForgeMods.cpp b/src/Protocol/ForgeMods.cpp index d36bd1b727..40a7a013a7 100644 --- a/src/Protocol/ForgeMods.cpp +++ b/src/Protocol/ForgeMods.cpp @@ -28,9 +28,9 @@ cForgeMods::cForgeMods(AStringMap a):m_Mods(a) const cForgeMods & cForgeMods::Unmodded(void) { - static cForgeMods unmodded; + static cForgeMods Unmodded; - return unmodded; + return Unmodded; } From 789a54521f781996406ccfecd49b505f2de8c9c4 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 24 Jul 2017 20:03:15 -0700 Subject: [PATCH 066/166] Remove cForgeMods::GetModVersionAt(), use GetModVersion() instead --- Server/Plugins/APIDump/APIDesc.lua | 17 ----------------- src/Protocol/ForgeHandshake.cpp | 6 ++++-- src/Protocol/ForgeMods.cpp | 17 ++--------------- src/Protocol/ForgeMods.h | 5 +---- 4 files changed, 7 insertions(+), 38 deletions(-) diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua index fd35326660..0222379499 100644 --- a/Server/Plugins/APIDump/APIDesc.lua +++ b/Server/Plugins/APIDump/APIDesc.lua @@ -4881,23 +4881,6 @@ cFile:DeleteFile("/usr/bin/virus.exe"); Notes = "Returns the version of the mod name given.", }, - GetModVersionAt = - { - Params = - { - { - Name = "i", - Type = "number", - }, - }, - Returns = - { - { - Type = "string", - }, - }, - Notes = "Returns the version of the Forge mod at the given index.", - }, GetNumMods = { Returns = diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 439e197591..8bd3196232 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -211,8 +211,10 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data Buf.WriteVarInt32(static_cast(ModCount)); for (size_t i = 0; i < ModCount; ++i) { - Buf.WriteVarUTF8String(ServerMods.GetModNameAt(i)); - Buf.WriteVarUTF8String(ServerMods.GetModVersionAt(i)); + const AString & name = ServerMods.GetModNameAt(i); + const AString & version = ServerMods.GetModVersion(name); + Buf.WriteVarUTF8String(name); + Buf.WriteVarUTF8String(version); } AString ServerModList; Buf.ReadAll(ServerModList); diff --git a/src/Protocol/ForgeMods.cpp b/src/Protocol/ForgeMods.cpp index 40a7a013a7..2e74d42692 100644 --- a/src/Protocol/ForgeMods.cpp +++ b/src/Protocol/ForgeMods.cpp @@ -19,7 +19,6 @@ cForgeMods::cForgeMods(AStringMap a):m_Mods(a) for (const auto & item: a) { m_ModNames.push_back(item.first); - m_ModVersions.push_back(item.second); } } @@ -51,7 +50,7 @@ bool cForgeMods::HasMod(AString & name) const -const AString & cForgeMods::GetModVersion(AString & name) const +const AString & cForgeMods::GetModVersion(const AString & name) const { return m_Mods.find(name)->second; } @@ -68,18 +67,9 @@ const AString & cForgeMods::GetModNameAt(size_t i) const -const AString & cForgeMods::GetModVersionAt(size_t i) const -{ - return m_ModVersions[i]; -} - - - - void cForgeMods::Add(AString & a_Name, AString & a_Version) { m_ModNames.push_back(a_Name); - m_ModVersions.push_back(a_Version); m_Mods.insert(std::make_pair(a_Name, a_Version)); } @@ -92,10 +82,7 @@ void cForgeMods::Remove(AString & a_Name) auto it = std::find(m_ModNames.begin(), m_ModNames.end(), a_Name); if (it != m_ModNames.end()) { - auto index = std::distance(m_ModNames.begin(), it); - - m_ModNames.erase(m_ModNames.begin() + index); - m_ModVersions.erase(m_ModVersions.begin() + index); + m_ModNames.erase(it); } m_Mods.erase(a_Name); diff --git a/src/Protocol/ForgeMods.h b/src/Protocol/ForgeMods.h index 356ac45961..2e46dd54d4 100644 --- a/src/Protocol/ForgeMods.h +++ b/src/Protocol/ForgeMods.h @@ -20,13 +20,11 @@ class cForgeMods bool HasMod(AString & name) const; /** Returns the version of the mod name given. */ - const AString & GetModVersion(AString & name) const; + const AString & GetModVersion(const AString & name) const; /** Returns the name of the Forge mod at the given index. */ const AString & GetModNameAt(size_t i) const; - /** Returns the version of the Forge mod at the given index. */ - const AString & GetModVersionAt(size_t i) const; // tolua_end cForgeMods(); @@ -45,5 +43,4 @@ class cForgeMods private: AStringMap m_Mods; AStringVector m_ModNames; - AStringVector m_ModVersions; } ; // tolua_export From 12117fba519a212a4bc5a250e033e688cc3441c6 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 24 Jul 2017 20:09:00 -0700 Subject: [PATCH 067/166] Fix top-level 5 empty line whitespace in cForgeHandshake --- src/Protocol/ForgeHandshake.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 8bd3196232..dddadffcdf 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -96,6 +96,10 @@ void cForgeHandshake::SendServerHello() m_Client->SendPluginMessage("FML|HS", Message); } + + + + AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) { cByteBuffer Buf(a_Size); @@ -125,6 +129,10 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) return Mods; } + + + + void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data, size_t a_Size) { if (!m_IsForgeClient) From 02915d6cd769c02b650a97da48fb64813d6924fb Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 24 Jul 2017 20:58:44 -0700 Subject: [PATCH 068/166] Change to map data structure for m_ForgeModsByVersion instead of individual member variables per version --- src/Server.cpp | 67 +++++++++++++++++++++++++------------------------- src/Server.h | 15 +++-------- 2 files changed, 36 insertions(+), 46 deletions(-) diff --git a/src/Server.cpp b/src/Server.cpp index b72539ed94..616eff4243 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -220,6 +220,25 @@ bool cServer::InitServer(cSettingsRepositoryInterface & a_Settings, bool a_Shoul LOGWARNING("WARNING: BungeeCord is allowed and server set to online mode. This is unsafe and will not work properly. Disable either authentication or BungeeCord in settings.ini."); } + int Versions[] = + { + // TODO: better way to get all supported versions from cProtocolRecognizer? + cProtocolRecognizer::PROTO_VERSION_1_8_0, + cProtocolRecognizer::PROTO_VERSION_1_9_0, + cProtocolRecognizer::PROTO_VERSION_1_9_1, + cProtocolRecognizer::PROTO_VERSION_1_9_2, + cProtocolRecognizer::PROTO_VERSION_1_9_4, + cProtocolRecognizer::PROTO_VERSION_1_10_0, + cProtocolRecognizer::PROTO_VERSION_1_11_0, + cProtocolRecognizer::PROTO_VERSION_1_11_1, + cProtocolRecognizer::PROTO_VERSION_1_12, + }; + for (size_t i = 0; i < sizeof(Versions) / sizeof(Versions[0]); ++i) + { + cForgeMods Mods; + m_ForgeModsByVersion.insert(std::make_pair(Versions[i], Mods)); + } + m_ShouldAllowMultiWorldTabCompletion = a_Settings.GetValueSetB("Server", "AllowMultiWorldTabCompletion", true); m_ShouldLimitPlayerBlockChanges = a_Settings.GetValueSetB("AntiCheat", "LimitPlayerBlockChanges", true); m_ShouldLoadOfflinePlayerData = a_Settings.GetValueSetB("PlayerData", "LoadOfflinePlayerData", false); @@ -256,16 +275,10 @@ int cServer::GetNumPlayers(void) const void cServer::RegisterForgeMod(AString & a_Name, AString & a_Version) { - // TODO: refactor - m_ForgeMods_1_8_0.Add(a_Name, a_Version); - m_ForgeMods_1_9_0.Add(a_Name, a_Version); - m_ForgeMods_1_9_1.Add(a_Name, a_Version); - m_ForgeMods_1_9_2.Add(a_Name, a_Version); - m_ForgeMods_1_9_4.Add(a_Name, a_Version); - m_ForgeMods_1_10_0.Add(a_Name, a_Version); - m_ForgeMods_1_11_0.Add(a_Name, a_Version); - m_ForgeMods_1_11_1.Add(a_Name, a_Version); - m_ForgeMods_1_12.Add(a_Name, a_Version); + for (auto & it : m_ForgeModsByVersion) + { + it.second.Add(a_Name, a_Version); + } } @@ -284,16 +297,10 @@ void cServer::RegisterForgeModForProtocol(AString & a_ModName, AString & a_ModVe void cServer::UnregisterForgeMod(AString &a_Name) { - // TODO: refactor - m_ForgeMods_1_8_0.Remove(a_Name); - m_ForgeMods_1_9_0.Remove(a_Name); - m_ForgeMods_1_9_1.Remove(a_Name); - m_ForgeMods_1_9_2.Remove(a_Name); - m_ForgeMods_1_9_4.Remove(a_Name); - m_ForgeMods_1_10_0.Remove(a_Name); - m_ForgeMods_1_11_0.Remove(a_Name); - m_ForgeMods_1_11_1.Remove(a_Name); - m_ForgeMods_1_12.Remove(a_Name); + for (auto & it : m_ForgeModsByVersion) + { + it.second.Remove(a_Name); + } } @@ -308,21 +315,13 @@ void cServer::UnregisterForgeModForProtocol(AString &a_ModName, UInt32 a_Protoco -cForgeMods & cServer::GetRegisteredForgeMods(UInt32 a_Protocol) +cForgeMods & cServer::GetRegisteredForgeMods(const UInt32 a_Protocol) { - switch (a_Protocol) - { - case cProtocolRecognizer::PROTO_VERSION_1_8_0: return m_ForgeMods_1_8_0; - case cProtocolRecognizer::PROTO_VERSION_1_9_0: return m_ForgeMods_1_9_0; - case cProtocolRecognizer::PROTO_VERSION_1_9_1: return m_ForgeMods_1_9_1; - case cProtocolRecognizer::PROTO_VERSION_1_9_2: return m_ForgeMods_1_9_2; - case cProtocolRecognizer::PROTO_VERSION_1_9_4: return m_ForgeMods_1_9_4; - case cProtocolRecognizer::PROTO_VERSION_1_10_0: return m_ForgeMods_1_10_0; - case cProtocolRecognizer::PROTO_VERSION_1_11_0: return m_ForgeMods_1_11_0; - case cProtocolRecognizer::PROTO_VERSION_1_11_1: return m_ForgeMods_1_11_1; - default: - case cProtocolRecognizer::PROTO_VERSION_1_12: return m_ForgeMods_1_12; - } + auto it = m_ForgeModsByVersion.find(a_Protocol); + + ASSERT(it != m_ForgeModsByVersion.end()); + + return it->second; } diff --git a/src/Server.h b/src/Server.h index 83c65e929f..2066506cd0 100644 --- a/src/Server.h +++ b/src/Server.h @@ -161,7 +161,7 @@ class cServer from the settings. */ bool ShouldAllowMultiWorldTabCompletion(void) const { return m_ShouldAllowMultiWorldTabCompletion; } - cForgeMods & GetRegisteredForgeMods(UInt32 a_Protocol); + cForgeMods & GetRegisteredForgeMods(const UInt32 a_Protocol); private: @@ -229,17 +229,8 @@ class cServer int m_MaxPlayers; bool m_bIsHardcore; - // TODO: std::map data structure? - cForgeMods m_ForgeMods_1_8_0; - cForgeMods m_ForgeMods_1_9_0; - cForgeMods m_ForgeMods_1_9_1; - cForgeMods m_ForgeMods_1_9_2; - cForgeMods m_ForgeMods_1_9_4; - cForgeMods m_ForgeMods_1_10_0; - cForgeMods m_ForgeMods_1_10_1; - cForgeMods m_ForgeMods_1_11_0; - cForgeMods m_ForgeMods_1_11_1; - cForgeMods m_ForgeMods_1_12; + /** Map of protocol version to Forge mods for that version. */ + std::map m_ForgeModsByVersion; /** True - allow same username to login more than once False - only once */ bool m_bAllowMultiLogin; From 82e2fdd16aa349ee09c61f8f16f18b974f19bbb4 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 24 Jul 2017 21:37:08 -0700 Subject: [PATCH 069/166] Rename IsModded -> IsForgeClient --- Server/Plugins/APIDump/APIDesc.lua | 2 +- src/ClientHandle.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua index 0222379499..0907858e04 100644 --- a/Server/Plugins/APIDump/APIDesc.lua +++ b/Server/Plugins/APIDump/APIDesc.lua @@ -1476,7 +1476,7 @@ end }, Notes = "Returns true if the client has registered to receive messages on the specified plugin channel.", }, - IsModded = + IsForgeClient = { Returns = { diff --git a/src/ClientHandle.h b/src/ClientHandle.h index e18b7807cd..eebc4c804e 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -270,7 +270,7 @@ class cClientHandle // tolua_export const cForgeMods & GetForgeMods(void) const { return m_ForgeMods ? *m_ForgeMods : cForgeMods::Unmodded(); } /** Returns true if the client is modded with Forge. */ - bool IsModded(void) const { return m_ForgeHandshake.m_IsForgeClient; } + bool IsForgeClient(void) const { return m_ForgeHandshake.m_IsForgeClient; } // tolua_end From b58aae707cb3bebdfa8c43ba8b17e67336d921ed Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 24 Jul 2017 21:38:31 -0700 Subject: [PATCH 070/166] Alpha-sort the PluginManager hook list for HOOK_LOGIN_FORGE --- src/Bindings/PluginManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index 5ce6f5d6f5..04e7840b7d 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -101,6 +101,7 @@ class cPluginManager HOOK_KILLED, HOOK_KILLING, HOOK_LOGIN, + HOOK_LOGIN_FORGE, HOOK_PLAYER_BREAKING_BLOCK, HOOK_PLAYER_BROKEN_BLOCK, HOOK_PLAYER_DESTROYED, @@ -142,7 +143,6 @@ class cPluginManager HOOK_WEATHER_CHANGING, HOOK_WORLD_STARTED, HOOK_WORLD_TICK, - HOOK_LOGIN_FORGE, // tolua_end From 3749574c721fd72b914284af3bd9b42fb3c7c900 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 24 Jul 2017 21:40:30 -0700 Subject: [PATCH 071/166] Initialize m_ForgeMods pointer with nullptr instead of 0 integer --- src/ClientHandle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 19278b1342..018b4cfa0e 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -65,7 +65,7 @@ float cClientHandle::FASTBREAK_PERCENTAGE; cClientHandle::cClientHandle(const AString & a_IPString, int a_ViewDistance) : m_ForgeHandshake(this), - m_ForgeMods(0), + m_ForgeMods(nullptr), m_LastSentDimension(dimNotSet), m_CurrentViewDistance(a_ViewDistance), m_RequestedViewDistance(a_ViewDistance), From 0cb1ed59bd131a21db41d0537d25619be53678b3 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 24 Jul 2017 21:42:18 -0700 Subject: [PATCH 072/166] Alpha-sort src/Protocol/CMakeLists new Forge files --- src/Protocol/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt index 732801322c..c4ac0ba110 100644 --- a/src/Protocol/CMakeLists.txt +++ b/src/Protocol/CMakeLists.txt @@ -5,6 +5,8 @@ include_directories ("${PROJECT_SOURCE_DIR}/../") SET (SRCS Authenticator.cpp ChunkDataSerializer.cpp + ForgeHandshake.cpp + ForgeMods.cpp MojangAPI.cpp Packetizer.cpp Protocol_1_8.cpp @@ -13,13 +15,13 @@ SET (SRCS Protocol_1_11.cpp Protocol_1_12.cpp ProtocolRecognizer.cpp - ForgeHandshake.cpp - ForgeMods.cpp ) SET (HDRS Authenticator.h ChunkDataSerializer.h + ForgeHandshake.h + ForgeMods.h MojangAPI.h Packetizer.h Protocol.h @@ -29,8 +31,6 @@ SET (HDRS Protocol_1_11.h Protocol_1_12.h ProtocolRecognizer.h - ForgeHandshake.h - ForgeMods.h ) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") From 0a2c0e643bd76d0d57632a8a233353599d15181d Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 24 Jul 2017 21:43:50 -0700 Subject: [PATCH 073/166] cForgeHandshake constructor initialization list on separate lines --- src/Protocol/ForgeHandshake.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index dddadffcdf..d23f52e225 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -11,7 +11,10 @@ #include "../ClientHandle.h" #include "../Root.h" -cForgeHandshake::cForgeHandshake(cClientHandle *client) : m_IsForgeClient(false), m_Errored(false), m_Client(client) +cForgeHandshake::cForgeHandshake(cClientHandle *client) : + m_IsForgeClient(false), + m_Errored(false), + m_Client(client) { } From 6ca813a823de7336fb274e4e18ddeedd460ae00d Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 24 Jul 2017 21:47:55 -0700 Subject: [PATCH 074/166] Clean up ModList parsing, pass only payload and add length check --- src/Protocol/ForgeHandshake.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index d23f52e225..4cbe71e123 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -105,19 +105,20 @@ void cForgeHandshake::SendServerHello() AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) { - cByteBuffer Buf(a_Size); - Buf.Write(a_Data, a_Size); + AStringMap Mods; - Int8 Discriminator; - Buf.ReadBEInt8(Discriminator); + if (a_Size < 4) + { + LOG("ParseModList invalid packet, missing length (size=%zu)", a_Size); + return Mods; + } - ASSERT(Discriminator == 2); + cByteBuffer Buf(a_Size); + Buf.Write(a_Data, a_Size); UInt32 NumMods; Buf.ReadVarInt32(NumMods); - AStringMap Mods; - for (size_t i = 0; i < NumMods; ++i) { AString Name, Version; @@ -181,7 +182,7 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data { LOGD("Received ModList"); - AStringMap ClientMods = ParseModList(a_Data, a_Size); + AStringMap ClientMods = ParseModList(a_Data + 1, a_Size - 1); AString ClientModsString; for (auto & item: ClientMods) { From 6da327f0b9e6e255c3a6826dca47d6b25add8d00 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 24 Jul 2017 21:48:56 -0700 Subject: [PATCH 075/166] Add whitespace before ForgeHandshake class definition --- src/Protocol/ForgeHandshake.cpp | 2 ++ src/Protocol/ForgeHandshake.h | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 4cbe71e123..c5b9a475fa 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -302,9 +302,11 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data } default: + { LOG("Unexpected Forge packet %d received", Discriminator); SetError(); return; + } } } diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index 5cd513e709..ae6ab29d11 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -14,6 +14,10 @@ namespace Json } class cClientHandle; + + + + class cForgeHandshake { public: From 859acae4947df3049f70b79fbdae325141aa1bcb Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 24 Jul 2017 21:58:48 -0700 Subject: [PATCH 076/166] Move enums into ForgeHandshake implementation file, not part of interface --- src/Protocol/ForgeHandshake.cpp | 32 +++++++++++++++++++++++++ src/Protocol/ForgeHandshake.h | 41 ++++++++++++--------------------- 2 files changed, 47 insertions(+), 26 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index c5b9a475fa..48e74087cb 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -11,6 +11,38 @@ #include "../ClientHandle.h" #include "../Root.h" + +/** Discriminator byte values prefixing the FML|HS packets to determine their type. */ +enum +{ + Discriminator_ServerHello = 0, + Discriminator_ClientHello = 1, + Discriminator_ModList = 2, + Discriminator_RegistryData = 3, + Discriminator_HandshakeReset = -2, + Discriminator_HandshakeAck = -1, +}; + +/** Client handshake state phases. */ +enum +{ + ClientPhase_WAITINGSERVERDATA = 2, + ClientPhase_WAITINGSERVERCOMPLETE = 3, + ClientPhase_PENDINGCOMPLETE = 4, + ClientPhase_COMPLETE = 5, +}; + +/** Server handshake state phases. */ +enum +{ + ServerPhase_WAITINGCACK = 2, + ServerPhase_COMPLETE = 3, +}; + + + + + cForgeHandshake::cForgeHandshake(cClientHandle *client) : m_IsForgeClient(false), m_Errored(false), diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index ae6ab29d11..a95132fdb6 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -23,47 +23,36 @@ class cForgeHandshake public: cForgeHandshake(cClientHandle * client); + /** Add the registered Forge mods to the server ping list packet. */ void AugmentServerListPing(Json::Value & ResponseValue); + + /** Begin the Forge Modloader Handshake (FML|HS) sequence. */ void BeginForgeHandshake(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties); + /** Send the ServerHello packet in the Forge handshake. */ void SendServerHello(); - void DataReceived(cClientHandle * a_Client, const char * a_Data, size_t a_Size); - AStringMap ParseModList(const char * a_Data, size_t a_Size); + /** Process received data from the client advancing the Forge handshake. */ + void DataReceived(cClientHandle * a_Client, const char * a_Data, size_t a_Size); + /** True if the client advertised itself as a Forge client. */ bool m_IsForgeClient; private: + /** Parse the client ModList packet of installed Forge mods and versions. */ + AStringMap ParseModList(const char * a_Data, size_t a_Size); + + /** Set the Forge handshake to an errored state. */ void SetError(); + + /** True if the Forge handshake is in an errored state. */ bool m_Errored; + /** The client handle undergoing this Forge handshake. */ cClientHandle * m_Client; + /** Values saved from BeginForgeHandshake() for continuing the normal handshake after Forge completes. */ const AString * m_Name; const AString * m_UUID; const Json::Value * m_Properties; - - enum - { - Discriminator_ServerHello = 0, - Discriminator_ClientHello = 1, - Discriminator_ModList = 2, - Discriminator_RegistryData = 3, - Discriminator_HandshakeReset = -2, - Discriminator_HandshakeAck = -1, - }; - - enum - { - ClientPhase_WAITINGSERVERDATA = 2, - ClientPhase_WAITINGSERVERCOMPLETE = 3, - ClientPhase_PENDINGCOMPLETE = 4, - ClientPhase_COMPLETE = 5, - }; - - enum - { - ServerPhase_WAITINGCACK = 2, - ServerPhase_COMPLETE = 3, - }; }; From a3fa137a35c96a40b4989e3749c3e253496e9577 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 24 Jul 2017 21:59:15 -0700 Subject: [PATCH 077/166] Comment and whitespace on cProtocol::ForgeDataReceived --- src/Protocol/Protocol.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index 6f0a59ad8d..97594ef581 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -63,6 +63,8 @@ class cProtocol /** Called when client sends some data */ virtual void DataReceived(const char * a_Data, size_t a_Size) = 0; + + /** Called when client sends some data over the FML|HS plugin channel */ void ForgeDataReceived(const char * a_Data, size_t a_Size) { m_Client->m_ForgeHandshake.DataReceived(m_Client, a_Data, a_Size); From 688ba2dbb4477930d7b6f24313a2497635deaebe Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 24 Jul 2017 22:16:40 -0700 Subject: [PATCH 078/166] Add documentation for HOOK_LOGIN_FORGE --- Server/Plugins/APIDump/Classes/Plugins.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Server/Plugins/APIDump/Classes/Plugins.lua b/Server/Plugins/APIDump/Classes/Plugins.lua index c007354122..82f6f7ec29 100644 --- a/Server/Plugins/APIDump/Classes/Plugins.lua +++ b/Server/Plugins/APIDump/Classes/Plugins.lua @@ -796,6 +796,10 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage); { Notes = "Called when a Login packet is sent to the client, before the client is queued for authentication.", }, + HOOK_LOGIN_FORGE = + { + Notes = "Called when a Forge client has sent its ModList to the server, during the login handshake.", + }, HOOK_PLAYER_ANIMATION = { Notes = "Called when a client send the Animation packet.", From 2ce1ddcd4103d0e7675a3a5d5413a3cf5283cdab Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 25 Jul 2017 18:24:45 -0700 Subject: [PATCH 079/166] Change cClientHandle cForgeMods to std::unique_ptr --- src/ClientHandle.cpp | 2 +- src/ClientHandle.h | 2 +- src/Protocol/ForgeHandshake.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 018b4cfa0e..c37db5d4fe 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -142,7 +142,7 @@ cClientHandle::~cClientHandle() if (m_ForgeMods != nullptr) { - delete m_ForgeMods; + m_ForgeMods.reset(); } if (!m_HasSentDC) diff --git a/src/ClientHandle.h b/src/ClientHandle.h index eebc4c804e..ca59483e6b 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -387,7 +387,7 @@ class cClientHandle // tolua_export cForgeHandshake m_ForgeHandshake; - cForgeMods * m_ForgeMods; + std::unique_ptr m_ForgeMods; private: /** The dimension that was last sent to a player in a Respawn or Login packet. diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 48e74087cb..d3a7ff41ef 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -228,10 +228,10 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data if (m_Client->m_ForgeMods != nullptr) { - delete m_Client->m_ForgeMods; + m_Client->m_ForgeMods.reset(); } - m_Client->m_ForgeMods = new cForgeMods(ClientMods); + m_Client->m_ForgeMods = cpp14::make_unique(ClientMods); // Let the plugins know about this event, they may refuse the player: if (cRoot::Get()->GetPluginManager()->CallHookLoginForge(*a_Client)) From a3ee32484d714d1a690b19afc49f28e0bdf11522 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 25 Jul 2017 18:28:12 -0700 Subject: [PATCH 080/166] Change fixed handshake channels list from vector to std::array --- src/Protocol/ForgeHandshake.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index d3a7ff41ef..d7a7643370 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -98,12 +98,12 @@ void cForgeHandshake::BeginForgeHandshake(const AString & a_Name, const AString m_UUID = &a_UUID; m_Properties = &a_Properties; - AStringVector Channels = { "FML|HS", "FML", "FML|MP", "FML", "FORGE" }; + std::array Channels{{ "FML|HS", "FML", "FML|MP", "FML", "FORGE" }}; AString ChannelsString; - for (AStringVector::iterator itr = Channels.begin(); itr != Channels.end(); ++itr) + for (auto & Channel: Channels) { - ChannelsString.append(*itr); + ChannelsString.append(Channel); ChannelsString.push_back('\0'); } From f3a8b58df104227f3799f0f077da42fb46168730 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 25 Jul 2017 18:30:12 -0700 Subject: [PATCH 081/166] Change to use uniform initialization insert() on string maps --- src/Protocol/ForgeHandshake.cpp | 2 +- src/Protocol/ForgeMods.cpp | 2 +- src/Server.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index d7a7643370..d81c7bb168 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -157,7 +157,7 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) Buf.ReadVarUTF8String(Name); Buf.ReadVarUTF8String(Version); - Mods.insert(std::pair(Name, Version)); + Mods.insert({Name, Version}); LOGD("ParseModList name=%s, version=%s", Name.c_str(), Version.c_str()); } diff --git a/src/Protocol/ForgeMods.cpp b/src/Protocol/ForgeMods.cpp index 2e74d42692..e91c021c11 100644 --- a/src/Protocol/ForgeMods.cpp +++ b/src/Protocol/ForgeMods.cpp @@ -70,7 +70,7 @@ const AString & cForgeMods::GetModNameAt(size_t i) const void cForgeMods::Add(AString & a_Name, AString & a_Version) { m_ModNames.push_back(a_Name); - m_Mods.insert(std::make_pair(a_Name, a_Version)); + m_Mods.insert({a_Name, a_Version}); } diff --git a/src/Server.cpp b/src/Server.cpp index 616eff4243..513fcd32da 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -236,7 +236,7 @@ bool cServer::InitServer(cSettingsRepositoryInterface & a_Settings, bool a_Shoul for (size_t i = 0; i < sizeof(Versions) / sizeof(Versions[0]); ++i) { cForgeMods Mods; - m_ForgeModsByVersion.insert(std::make_pair(Versions[i], Mods)); + m_ForgeModsByVersion.insert({Versions[i], Mods}); } m_ShouldAllowMultiWorldTabCompletion = a_Settings.GetValueSetB("Server", "AllowMultiWorldTabCompletion", true); From 9e5cbe2cdb374ab829214445d7564ff9505f9e03 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 25 Jul 2017 18:32:16 -0700 Subject: [PATCH 082/166] Change cForgeMods AString params to const AString --- src/Protocol/ForgeMods.cpp | 6 +++--- src/Protocol/ForgeMods.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Protocol/ForgeMods.cpp b/src/Protocol/ForgeMods.cpp index e91c021c11..4ac31191e4 100644 --- a/src/Protocol/ForgeMods.cpp +++ b/src/Protocol/ForgeMods.cpp @@ -42,7 +42,7 @@ size_t cForgeMods::GetNumMods(void) const -bool cForgeMods::HasMod(AString & name) const +bool cForgeMods::HasMod(const AString & name) const { return m_Mods.find(name) != m_Mods.end(); } @@ -67,7 +67,7 @@ const AString & cForgeMods::GetModNameAt(size_t i) const -void cForgeMods::Add(AString & a_Name, AString & a_Version) +void cForgeMods::Add(const AString & a_Name, const AString & a_Version) { m_ModNames.push_back(a_Name); m_Mods.insert({a_Name, a_Version}); @@ -77,7 +77,7 @@ void cForgeMods::Add(AString & a_Name, AString & a_Version) -void cForgeMods::Remove(AString & a_Name) +void cForgeMods::Remove(const AString & a_Name) { auto it = std::find(m_ModNames.begin(), m_ModNames.end(), a_Name); if (it != m_ModNames.end()) diff --git a/src/Protocol/ForgeMods.h b/src/Protocol/ForgeMods.h index 2e46dd54d4..8af6d87fe7 100644 --- a/src/Protocol/ForgeMods.h +++ b/src/Protocol/ForgeMods.h @@ -17,7 +17,7 @@ class cForgeMods size_t GetNumMods(void) const; /** Returns true if the mod with the given name is installed. */ - bool HasMod(AString & name) const; + bool HasMod(const AString & name) const; /** Returns the version of the mod name given. */ const AString & GetModVersion(const AString & name) const; @@ -32,9 +32,9 @@ class cForgeMods static const cForgeMods & Unmodded(void); - void Add(AString & a_Name, AString & a_Version); + void Add(const AString & a_Name, const AString & a_Version); - void Remove(AString & a_Name); + void Remove(const AString & a_Name); AStringMap GetMods() { return m_Mods; } From fa7e152851e369e2a37d8715be74514d4ad14f17 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 25 Jul 2017 20:32:10 -0700 Subject: [PATCH 083/166] Check Buf.ReadVar return values in ForgeHandshake parsing --- src/Protocol/ForgeHandshake.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index d81c7bb168..dd8e52115d 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -149,13 +149,26 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) Buf.Write(a_Data, a_Size); UInt32 NumMods; - Buf.ReadVarInt32(NumMods); + if (!Buf.ReadVarInt32(NumMods)) + { + LOG("ParseModList failed to read mod count"); + return Mods; + } for (size_t i = 0; i < NumMods; ++i) { AString Name, Version; - Buf.ReadVarUTF8String(Name); - Buf.ReadVarUTF8String(Version); + if (!Buf.ReadVarUTF8String(Name)) + { + LOG("ParseModList failed to read mod name at i=%zu", i); + break; + } + + if (!Buf.ReadVarUTF8String(Version)) + { + LOG("ParseModList failed to read mod version at i=%zu", i); + break; + } Mods.insert({Name, Version}); From 66975f8fea64829686db692c9e54736cd8dde34e Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Wed, 26 Jul 2017 23:45:51 -0700 Subject: [PATCH 084/166] Fix double copy in cForgeMods constructor, pass by reference --- src/Protocol/ForgeMods.cpp | 2 +- src/Protocol/ForgeMods.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Protocol/ForgeMods.cpp b/src/Protocol/ForgeMods.cpp index 4ac31191e4..d5b38332f9 100644 --- a/src/Protocol/ForgeMods.cpp +++ b/src/Protocol/ForgeMods.cpp @@ -14,7 +14,7 @@ cForgeMods::cForgeMods() -cForgeMods::cForgeMods(AStringMap a):m_Mods(a) +cForgeMods::cForgeMods(const AStringMap & a):m_Mods(a) { for (const auto & item: a) { diff --git a/src/Protocol/ForgeMods.h b/src/Protocol/ForgeMods.h index 8af6d87fe7..68575bd147 100644 --- a/src/Protocol/ForgeMods.h +++ b/src/Protocol/ForgeMods.h @@ -28,7 +28,7 @@ class cForgeMods // tolua_end cForgeMods(); - cForgeMods(AStringMap a); + cForgeMods(const AStringMap & a); static const cForgeMods & Unmodded(void); From 276918dbeac477fc8b3278866b450d44d009aa21 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Thu, 27 Jul 2017 20:54:53 -0700 Subject: [PATCH 085/166] Forge mod registration checks success, prevent duplicate regresion --- src/Protocol/ForgeMods.cpp | 12 ++++++++++-- src/Protocol/ForgeMods.h | 2 +- src/Server.cpp | 9 +++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Protocol/ForgeMods.cpp b/src/Protocol/ForgeMods.cpp index d5b38332f9..e1d8e42b85 100644 --- a/src/Protocol/ForgeMods.cpp +++ b/src/Protocol/ForgeMods.cpp @@ -67,10 +67,18 @@ const AString & cForgeMods::GetModNameAt(size_t i) const -void cForgeMods::Add(const AString & a_Name, const AString & a_Version) +bool cForgeMods::Add(const AString & a_Name, const AString & a_Version) { + auto ret = m_Mods.insert({a_Name, a_Version}); + + if (!ret.second) + { + return false; + } + m_ModNames.push_back(a_Name); - m_Mods.insert({a_Name, a_Version}); + + return true; } diff --git a/src/Protocol/ForgeMods.h b/src/Protocol/ForgeMods.h index 68575bd147..e8866b71d8 100644 --- a/src/Protocol/ForgeMods.h +++ b/src/Protocol/ForgeMods.h @@ -32,7 +32,7 @@ class cForgeMods static const cForgeMods & Unmodded(void); - void Add(const AString & a_Name, const AString & a_Version); + bool Add(const AString & a_Name, const AString & a_Version); void Remove(const AString & a_Name); diff --git a/src/Server.cpp b/src/Server.cpp index 513fcd32da..f672e2e336 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -275,10 +275,13 @@ int cServer::GetNumPlayers(void) const void cServer::RegisterForgeMod(AString & a_Name, AString & a_Version) { + bool success = false; for (auto & it : m_ForgeModsByVersion) { - it.second.Add(a_Name, a_Version); + success |= it.second.Add(a_Name, a_Version); } + + (void) success; // TODO: raise Lua exception in manual binding } @@ -288,7 +291,9 @@ void cServer::RegisterForgeMod(AString & a_Name, AString & a_Version) void cServer::RegisterForgeModForProtocol(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber) { cForgeMods & mods = GetRegisteredForgeMods(a_ProtocolVersionNumber); - mods.Add(a_ModName, a_ModVersion); + bool success = mods.Add(a_ModName, a_ModVersion); + + (void) success; // TODO: raise Lua exception in manual binding } From 981486f29ebb16f90f698abf0e46a9b1ffa191a0 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Thu, 27 Jul 2017 21:16:31 -0700 Subject: [PATCH 086/166] Manually bind RegisterForgeMod to throw Lua exception on failure --- src/Bindings/ManualBindings.cpp | 71 ++++++++++++++++++++++++++++++++- src/Server.cpp | 8 ++-- src/Server.h | 6 ++- 3 files changed, 78 insertions(+), 7 deletions(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index e81a8ef05c..b6059f515a 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -32,6 +32,7 @@ #include "../Generating/ChunkDesc.h" #include "../LineBlockTracer.h" #include "../CompositeChat.h" +#include "../Server.h" #include "../StringCompression.h" #include "../CommandOutput.h" #include "../BuildInfo.h" @@ -3134,13 +3135,76 @@ static int tolua_cRoot_GetFurnaceRecipe(lua_State * tolua_S) +static int tolua_cServer_RegisterForgeModForProtocol(lua_State * a_LuaState) +{ + cLuaState L(a_LuaState); + if ( + !L.CheckParamUserType(1, "cServer") || + !L.CheckParamString(2, 3) || + !L.CheckParamNumber(4) || + !L.CheckParamEnd(5) + ) + { + return 0; + } + + cServer * Server = reinterpret_cast(tolua_tousertype(L, 1, nullptr)); + AString Name, Version; + UInt32 Protocol; + L.GetStackValue(2, Name); + L.GetStackValue(3, Version); + L.GetStackValue(4, Protocol); + + if (!Server->RegisterForgeModForProtocol(Name, Version, Protocol)) + { + tolua_error(L, "duplicate Forge mod name registration", nullptr); + return 0; + } + + return 1; +} + + + + + +static int tolua_cServer_RegisterForgeMod(lua_State * a_LuaState) +{ + cLuaState L(a_LuaState); + if ( + !L.CheckParamUserType(1, "cServer") || + !L.CheckParamString(2, 3) || + !L.CheckParamEnd(4) + ) + { + return 0; + } + + cServer * Server = reinterpret_cast(tolua_tousertype(L, 1, nullptr)); + AString Name, Version; + L.GetStackValue(2, Name); + L.GetStackValue(3, Version); + + if (!Server->RegisterForgeMod(Name, Version)) + { + tolua_error(L, "duplicate Forge mod name registration", nullptr); + return 0; + } + + return 1; +} + + + + + static int tolua_cScoreboard_GetTeamNames(lua_State * L) { cLuaState S(L); if ( !S.CheckParamUserType(1, "cScoreboard") || !S.CheckParamEnd(2) - ) + ) { return 0; } @@ -3885,6 +3949,11 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "GetTeamNames", tolua_cScoreboard_GetTeamNames); tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cServer"); + tolua_function(tolua_S, "RegisterForgeMod", tolua_cServer_RegisterForgeMod); + tolua_function(tolua_S, "RegisterForgeModForProtocol", tolua_cServer_RegisterForgeModForProtocol); + tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cStringCompression"); tolua_function(tolua_S, "CompressStringZLIB", tolua_CompressStringZLIB); tolua_function(tolua_S, "UncompressStringZLIB", tolua_UncompressStringZLIB); diff --git a/src/Server.cpp b/src/Server.cpp index f672e2e336..23a8850bad 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -273,7 +273,7 @@ int cServer::GetNumPlayers(void) const -void cServer::RegisterForgeMod(AString & a_Name, AString & a_Version) +bool cServer::RegisterForgeMod(AString & a_Name, AString & a_Version) { bool success = false; for (auto & it : m_ForgeModsByVersion) @@ -281,19 +281,19 @@ void cServer::RegisterForgeMod(AString & a_Name, AString & a_Version) success |= it.second.Add(a_Name, a_Version); } - (void) success; // TODO: raise Lua exception in manual binding + return success; } -void cServer::RegisterForgeModForProtocol(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber) +bool cServer::RegisterForgeModForProtocol(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber) { cForgeMods & mods = GetRegisteredForgeMods(a_ProtocolVersionNumber); bool success = mods.Add(a_ModName, a_ModVersion); - (void) success; // TODO: raise Lua exception in manual binding + return success; } diff --git a/src/Server.h b/src/Server.h index 2066506cd0..10016ae6a0 100644 --- a/src/Server.h +++ b/src/Server.h @@ -72,11 +72,13 @@ class cServer int GetNumPlayers(void) const; void SetMaxPlayers(int a_MaxPlayers) { m_MaxPlayers = a_MaxPlayers; } + // tolua_end /** Add a Forge mod to the server ping list. */ - void RegisterForgeMod(AString & a_ModName, AString & a_ModVersion); + bool RegisterForgeMod(AString & a_ModName, AString & a_ModVersion); /** Add a Forge mod to the server ping list for one protocol version. */ - void RegisterForgeModForProtocol(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber); + bool RegisterForgeModForProtocol(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber); + // tolua_begin /** Remove a Forge mod from the server ping list. */ void UnregisterForgeMod(AString & a_ModName); From d7e5e5858d391a0ca4cc2f554c1a4ce8c34124fa Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 28 Jul 2017 15:37:35 -0700 Subject: [PATCH 087/166] Remove all-protocol Forge mod registration, rename per-proto to RegisterForgeMod --- Server/Plugins/APIDump/APIDesc.lua | 30 ++----------------------- src/Bindings/ManualBindings.cpp | 35 ++---------------------------- src/Server.cpp | 28 ++---------------------- src/Server.h | 12 +++------- 4 files changed, 9 insertions(+), 96 deletions(-) diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua index ff0e26d7ac..ee16c964f8 100644 --- a/Server/Plugins/APIDump/APIDesc.lua +++ b/Server/Plugins/APIDump/APIDesc.lua @@ -11817,21 +11817,6 @@ end Notes = "Returns true if the specified player is queued to be transferred to a World.", }, RegisterForgeMod = - { - Params = - { - { - Name = "ModName", - Type = "string", - }, - { - Name = "ModVersion", - Type = "string", - }, - }, - Notes = "Add a Forge mod name/version to the server ping list.", - }, - RegisterForgeModForProtocol = { Params = { @@ -11848,7 +11833,7 @@ end Type = "number", }, }, - Notes = "Add a Forge mod name/version to the server ping list for all protocol versions.", + Notes = "Add a Forge mod name/version to the server ping list.", }, SetMaxPlayers = { @@ -11871,18 +11856,7 @@ end }, Notes = "Returns true iff the server is set to authenticate players (\"online mode\").", }, - UnregisterForgeMod = - { - Params = - { - { - Name = "ModName", - Type = "string", - }, - }, - Notes = "Remove a Forge mod name/version from the server ping list.", - }, - UnregisterForgeModForProtocol = + UnregisterForgeMod { Params = { diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index b6059f515a..09dfd0c6d0 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -3135,7 +3135,7 @@ static int tolua_cRoot_GetFurnaceRecipe(lua_State * tolua_S) -static int tolua_cServer_RegisterForgeModForProtocol(lua_State * a_LuaState) +static int tolua_cServer_RegisterForgeMod(lua_State * a_LuaState) { cLuaState L(a_LuaState); if ( @@ -3155,37 +3155,7 @@ static int tolua_cServer_RegisterForgeModForProtocol(lua_State * a_LuaState) L.GetStackValue(3, Version); L.GetStackValue(4, Protocol); - if (!Server->RegisterForgeModForProtocol(Name, Version, Protocol)) - { - tolua_error(L, "duplicate Forge mod name registration", nullptr); - return 0; - } - - return 1; -} - - - - - -static int tolua_cServer_RegisterForgeMod(lua_State * a_LuaState) -{ - cLuaState L(a_LuaState); - if ( - !L.CheckParamUserType(1, "cServer") || - !L.CheckParamString(2, 3) || - !L.CheckParamEnd(4) - ) - { - return 0; - } - - cServer * Server = reinterpret_cast(tolua_tousertype(L, 1, nullptr)); - AString Name, Version; - L.GetStackValue(2, Name); - L.GetStackValue(3, Version); - - if (!Server->RegisterForgeMod(Name, Version)) + if (!Server->RegisterForgeMod(Name, Version, Protocol)) { tolua_error(L, "duplicate Forge mod name registration", nullptr); return 0; @@ -3951,7 +3921,6 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_beginmodule(tolua_S, "cServer"); tolua_function(tolua_S, "RegisterForgeMod", tolua_cServer_RegisterForgeMod); - tolua_function(tolua_S, "RegisterForgeModForProtocol", tolua_cServer_RegisterForgeModForProtocol); tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cStringCompression"); diff --git a/src/Server.cpp b/src/Server.cpp index 23a8850bad..9aa9ea200e 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -273,22 +273,9 @@ int cServer::GetNumPlayers(void) const -bool cServer::RegisterForgeMod(AString & a_Name, AString & a_Version) -{ - bool success = false; - for (auto & it : m_ForgeModsByVersion) - { - success |= it.second.Add(a_Name, a_Version); - } - - return success; -} - - - -bool cServer::RegisterForgeModForProtocol(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber) +bool cServer::RegisterForgeMod(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber) { cForgeMods & mods = GetRegisteredForgeMods(a_ProtocolVersionNumber); bool success = mods.Add(a_ModName, a_ModVersion); @@ -300,18 +287,7 @@ bool cServer::RegisterForgeModForProtocol(AString & a_ModName, AString & a_ModVe -void cServer::UnregisterForgeMod(AString &a_Name) -{ - for (auto & it : m_ForgeModsByVersion) - { - it.second.Remove(a_Name); - } -} - - - - -void cServer::UnregisterForgeModForProtocol(AString &a_ModName, UInt32 a_ProtocolVersionNumber) +void cServer::UnregisterForgeMod(AString &a_ModName, UInt32 a_ProtocolVersionNumber) { cForgeMods & mods = GetRegisteredForgeMods(a_ProtocolVersionNumber); mods.Remove(a_ModName); diff --git a/src/Server.h b/src/Server.h index 10016ae6a0..3edbd47b49 100644 --- a/src/Server.h +++ b/src/Server.h @@ -74,17 +74,11 @@ class cServer // tolua_end /** Add a Forge mod to the server ping list. */ - bool RegisterForgeMod(AString & a_ModName, AString & a_ModVersion); - - /** Add a Forge mod to the server ping list for one protocol version. */ - bool RegisterForgeModForProtocol(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber); + bool RegisterForgeMod(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber); // tolua_begin - /** Remove a Forge mod from the server ping list. */ - void UnregisterForgeMod(AString & a_ModName); - - /** Remove a Forge mod to the server ping list for one protocol version. */ - void UnregisterForgeModForProtocol(AString & a_ModName, UInt32 a_ProtocolVersionNumber); + /** Remove a Forge mod to the server ping list. */ + void UnregisterForgeMod(AString & a_ModName, UInt32 a_ProtocolVersionNumber); /** Check if the player is queued to be transferred to a World. Returns true is Player is found in queue. */ From 3868658bc40d6e03522f61f77947c11996e9f791 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 28 Jul 2017 15:43:47 -0700 Subject: [PATCH 088/166] Simplify using GetStackValues() in manual binding for tolua_cServer_RegisterForgeMod --- src/Bindings/ManualBindings.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 09dfd0c6d0..a2269cd58c 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -3148,12 +3148,10 @@ static int tolua_cServer_RegisterForgeMod(lua_State * a_LuaState) return 0; } - cServer * Server = reinterpret_cast(tolua_tousertype(L, 1, nullptr)); + cServer * Server; AString Name, Version; UInt32 Protocol; - L.GetStackValue(2, Name); - L.GetStackValue(3, Version); - L.GetStackValue(4, Protocol); + L.GetStackValues(1, Server, Name, Version, Protocol); if (!Server->RegisterForgeMod(Name, Version, Protocol)) { From 343467bd72088a5eb335e91e9fd1749f16ec727e Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 28 Jul 2017 15:45:59 -0700 Subject: [PATCH 089/166] Revert accidental whitespace change in tolua_cScoreboard_GetTeamNames --- src/Bindings/ManualBindings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index a2269cd58c..fd49eab430 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -3172,7 +3172,7 @@ static int tolua_cScoreboard_GetTeamNames(lua_State * L) if ( !S.CheckParamUserType(1, "cScoreboard") || !S.CheckParamEnd(2) - ) + ) { return 0; } From 094a4e77666199ba4654c19d93f1e35f6bda3ced Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 28 Jul 2017 15:47:58 -0700 Subject: [PATCH 090/166] Remove unnecessary nullptr check before m_ForgeMods.reset() --- src/ClientHandle.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index c37db5d4fe..88ffa03a1d 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -140,10 +140,7 @@ cClientHandle::~cClientHandle() m_Player = nullptr; } - if (m_ForgeMods != nullptr) - { - m_ForgeMods.reset(); - } + m_ForgeMods.reset(); if (!m_HasSentDC) { From 2da145cdd1441a9ac1d43bedf125fc8d2458d086 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 28 Jul 2017 15:51:51 -0700 Subject: [PATCH 091/166] Remove cProtocol::ForgeDataReceived(), unnecessary indirection --- src/ClientHandle.cpp | 2 +- src/Protocol/Protocol.h | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 88ffa03a1d..7543dd2957 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -876,7 +876,7 @@ void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString } else if (a_Channel == "FML|HS") { - m_Protocol->ForgeDataReceived(a_Message.c_str(), a_Message.size()); + m_ForgeHandshake.DataReceived(this, a_Message.c_str(), a_Message.size()); } else if (!HasPluginChannel(a_Channel)) { diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index 97594ef581..cd27e1bdf4 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -64,12 +64,6 @@ class cProtocol /** Called when client sends some data */ virtual void DataReceived(const char * a_Data, size_t a_Size) = 0; - /** Called when client sends some data over the FML|HS plugin channel */ - void ForgeDataReceived(const char * a_Data, size_t a_Size) - { - m_Client->m_ForgeHandshake.DataReceived(m_Client, a_Data, a_Size); - } - // Sending stuff to clients (alphabetically sorted): virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity & a_Vehicle) = 0; virtual void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) = 0; From 8823e39e79a54e652c0919c0b6b92effe6cd33d0 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 28 Jul 2017 16:27:24 -0700 Subject: [PATCH 092/166] Privitize m_ForgeMods and m_ForgeHandshake --- src/ClientHandle.h | 16 +++++++++++++++- src/Protocol/Protocol_1_10.cpp | 2 +- src/Protocol/Protocol_1_11.cpp | 4 ++-- src/Protocol/Protocol_1_12.cpp | 2 +- src/Protocol/Protocol_1_8.cpp | 2 +- src/Protocol/Protocol_1_9.cpp | 10 +++++----- 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/ClientHandle.h b/src/ClientHandle.h index ca59483e6b..3171c9107a 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -274,6 +274,18 @@ class cClientHandle // tolua_export // tolua_end + /** Add the Forge mod list to the server ping response. */ + void ForgeAugmentServerListPing(Json::Value & a_Response) + { + m_ForgeHandshake.AugmentServerListPing(a_Response); + } + + /** Mark a client connection as using Forge. Set by the protocol. */ + void SetIsForgeClient() + { + m_ForgeHandshake.m_IsForgeClient = true; + } + /** Returns true if the client wants the chunk specified to be sent (in m_ChunksToSend) */ bool WantsSendChunk(int a_ChunkX, int a_ChunkZ); @@ -385,11 +397,13 @@ class cClientHandle // tolua_export bool IsPlayerChunkSent(); +private: + /** Forge handshake state machine. */ cForgeHandshake m_ForgeHandshake; + /** Forge mods and versions installed on this client, if any. */ std::unique_ptr m_ForgeMods; -private: /** The dimension that was last sent to a player in a Respawn or Login packet. Used to avoid Respawning into the same dimension, which confuses the client. */ eDimension m_LastSentDimension; diff --git a/src/Protocol/Protocol_1_10.cpp b/src/Protocol/Protocol_1_10.cpp index 2519a5b12f..2c2ef2e5a9 100644 --- a/src/Protocol/Protocol_1_10.cpp +++ b/src/Protocol/Protocol_1_10.cpp @@ -346,7 +346,7 @@ void cProtocol_1_10_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.AugmentServerListPing(ResponseValue); + m_Client->ForgeAugmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_11.cpp b/src/Protocol/Protocol_1_11.cpp index 73278e0078..02f085cb17 100644 --- a/src/Protocol/Protocol_1_11.cpp +++ b/src/Protocol/Protocol_1_11.cpp @@ -586,7 +586,7 @@ void cProtocol_1_11_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.AugmentServerListPing(ResponseValue); + m_Client->ForgeAugmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -1210,7 +1210,7 @@ void cProtocol_1_11_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.AugmentServerListPing(ResponseValue); + m_Client->ForgeAugmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp index 78c9151f7c..230860f3c4 100644 --- a/src/Protocol/Protocol_1_12.cpp +++ b/src/Protocol/Protocol_1_12.cpp @@ -399,7 +399,7 @@ void cProtocol_1_12::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.AugmentServerListPing(ResponseValue); + m_Client->ForgeAugmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp index a948dd0deb..ba6dfb3c56 100644 --- a/src/Protocol/Protocol_1_8.cpp +++ b/src/Protocol/Protocol_1_8.cpp @@ -2135,7 +2135,7 @@ void cProtocol_1_8_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.AugmentServerListPing(ResponseValue); + m_Client->ForgeAugmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index a29c97cb17..afc33a3320 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -132,7 +132,7 @@ cProtocol_1_9_0::cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_Ser if (Params[1] == "FML") { LOG("Forge client connected!"); - m_Client->m_ForgeHandshake.m_IsForgeClient = true; + m_Client->SetIsForgeClient(); } else if (Params.size() == 4) { @@ -2185,7 +2185,7 @@ void cProtocol_1_9_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.AugmentServerListPing(ResponseValue); + m_Client->ForgeAugmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4190,7 +4190,7 @@ void cProtocol_1_9_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.AugmentServerListPing(ResponseValue); + m_Client->ForgeAugmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4248,7 +4248,7 @@ void cProtocol_1_9_2::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.AugmentServerListPing(ResponseValue); + m_Client->ForgeAugmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -4306,7 +4306,7 @@ void cProtocol_1_9_4::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->m_ForgeHandshake.AugmentServerListPing(ResponseValue); + m_Client->ForgeAugmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); From 7be5d610813f2c2bf79b67b012851a4cb2493304 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 28 Jul 2017 16:30:11 -0700 Subject: [PATCH 093/166] Move member variables after typedef --- src/ClientHandle.cpp | 2 +- src/ClientHandle.h | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 7543dd2957..66804a5484 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -64,9 +64,9 @@ float cClientHandle::FASTBREAK_PERCENTAGE; // cClientHandle: cClientHandle::cClientHandle(const AString & a_IPString, int a_ViewDistance) : + m_LastSentDimension(dimNotSet), m_ForgeHandshake(this), m_ForgeMods(nullptr), - m_LastSentDimension(dimNotSet), m_CurrentViewDistance(a_ViewDistance), m_RequestedViewDistance(a_ViewDistance), m_IPString(a_IPString), diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 3171c9107a..93232a5be0 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -398,12 +398,6 @@ class cClientHandle // tolua_export bool IsPlayerChunkSent(); private: - /** Forge handshake state machine. */ - cForgeHandshake m_ForgeHandshake; - - /** Forge mods and versions installed on this client, if any. */ - std::unique_ptr m_ForgeMods; - /** The dimension that was last sent to a player in a Respawn or Login packet. Used to avoid Respawning into the same dimension, which confuses the client. */ eDimension m_LastSentDimension; @@ -415,6 +409,12 @@ class cClientHandle // tolua_export /** The type used for storing the names of registered plugin channels. */ typedef std::set cChannels; + /** Forge handshake state machine. */ + cForgeHandshake m_ForgeHandshake; + + /** Forge mods and versions installed on this client, if any. */ + std::unique_ptr m_ForgeMods; + /** The actual view distance used, the minimum of client's requested view distance and world's max view distance. */ int m_CurrentViewDistance; From 19026b96d6072ef4e25ece1fc83d5cfc522208cd Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 28 Jul 2017 16:35:44 -0700 Subject: [PATCH 094/166] enum Discriminator: signed char, Discriminator_ -> Discriminator:: --- src/Protocol/ForgeHandshake.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index dd8e52115d..c8e05c8bd5 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -13,14 +13,14 @@ /** Discriminator byte values prefixing the FML|HS packets to determine their type. */ -enum +enum Discriminator: signed char { - Discriminator_ServerHello = 0, - Discriminator_ClientHello = 1, - Discriminator_ModList = 2, - Discriminator_RegistryData = 3, - Discriminator_HandshakeReset = -2, - Discriminator_HandshakeAck = -1, + ServerHello = 0, + ClientHello = 1, + ModList = 2, + RegistryData = 3, + HandshakeReset = -2, + HandshakeAck = -1, }; /** Client handshake state phases. */ @@ -119,7 +119,7 @@ void cForgeHandshake::SendServerHello() { AString Message; // Discriminator | Byte | Always 0 for ServerHello - Message.push_back(Discriminator_ServerHello); + Message.push_back(Discriminator::ServerHello); // FML protocol Version | Byte | Determined from NetworkRegistery. Currently 2. Message.push_back('\2'); // Dimension TODO @@ -202,7 +202,7 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data switch (Discriminator) { - case Discriminator_ClientHello: + case Discriminator::ClientHello: { if (a_Size == 2) { @@ -223,7 +223,7 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data break; } - case Discriminator_ModList: + case Discriminator::ModList: { LOGD("Received ModList"); @@ -264,7 +264,7 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data size_t ModCount = ServerMods.GetNumMods(); - Buf.WriteBEInt8(Discriminator_ModList); + Buf.WriteBEInt8(Discriminator::ModList); Buf.WriteVarInt32(static_cast(ModCount)); for (size_t i = 0; i < ModCount; ++i) { @@ -280,7 +280,7 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data break; } - case Discriminator_HandshakeAck: + case Discriminator::HandshakeAck: { if (a_Size != 2) { @@ -297,7 +297,7 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data case ClientPhase_WAITINGSERVERDATA: { cByteBuffer Buf(1024); - Buf.WriteBEInt8(Discriminator_RegistryData); + Buf.WriteBEInt8(Discriminator::RegistryData); // TODO: send real registry data bool HasMore = false; @@ -323,7 +323,7 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data LOG("Client finished receiving registry data; acknowledging"); AString Ack; - Ack.push_back(Discriminator_HandshakeAck); + Ack.push_back(Discriminator::HandshakeAck); Ack.push_back(ServerPhase_WAITINGCACK); m_Client->SendPluginMessage("FML|HS", Ack); break; @@ -334,7 +334,7 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data LOG("Client is pending completion; sending complete ack"); AString Ack; - Ack.push_back(Discriminator_HandshakeAck); + Ack.push_back(Discriminator::HandshakeAck); Ack.push_back(ServerPhase_COMPLETE); m_Client->SendPluginMessage("FML|HS", Ack); From 4401a7554d594cca7834b9fe2b9c6a62b4b69a98 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 28 Jul 2017 16:36:18 -0700 Subject: [PATCH 095/166] a_ prefix on cForgeHandshake constructor --- src/Protocol/ForgeHandshake.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index c8e05c8bd5..140f3f5120 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -43,10 +43,10 @@ enum -cForgeHandshake::cForgeHandshake(cClientHandle *client) : +cForgeHandshake::cForgeHandshake(cClientHandle *a_Client) : m_IsForgeClient(false), m_Errored(false), - m_Client(client) + m_Client(a_Client) { } From ed6acb7f34292e4e22b0930372a14eb29c6c789a Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 28 Jul 2017 16:38:10 -0700 Subject: [PATCH 096/166] size_t format specifier: %zu -> SIZE_T_FMT --- src/Protocol/ForgeHandshake.cpp | 16 ++++++++-------- src/Protocol/Protocol_1_9.cpp | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 140f3f5120..78236663e6 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -141,7 +141,7 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) if (a_Size < 4) { - LOG("ParseModList invalid packet, missing length (size=%zu)", a_Size); + LOG("ParseModList invalid packet, missing length (size=" SIZE_T_FMT ")", a_Size); return Mods; } @@ -160,13 +160,13 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) AString Name, Version; if (!Buf.ReadVarUTF8String(Name)) { - LOG("ParseModList failed to read mod name at i=%zu", i); + LOG("ParseModList failed to read mod name at i=" SIZE_T_FMT, i); break; } if (!Buf.ReadVarUTF8String(Version)) { - LOG("ParseModList failed to read mod version at i=%zu", i); + LOG("ParseModList failed to read mod version at i=" SIZE_T_FMT, i); break; } @@ -186,15 +186,15 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data { if (!m_IsForgeClient) { - LOG("Received unexpected Forge data from non-Forge client (%zu bytes)", a_Size); + LOG("Received unexpected Forge data from non-Forge client (" SIZE_T_FMT " bytes)", a_Size); return; } - LOGD("Received Forge data: %zu bytes: %s", a_Size, a_Data); + LOGD("Received Forge data: " SIZE_T_FMT " bytes: %s", a_Size, a_Data); if (a_Size <= 1) { - LOG("Received unexpectedly short Forge data (%zu bytes)", a_Size); + LOG("Received unexpectedly short Forge data (" SIZE_T_FMT " bytes)", a_Size); return; } @@ -237,7 +237,7 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data ClientModsString.append(", "); } - LOG("Client connected with %zu mods: %s", ClientMods.size(), ClientModsString.c_str()); + LOG("Client connected with " SIZE_T_FMT " mods: %s", ClientMods.size(), ClientModsString.c_str()); if (m_Client->m_ForgeMods != nullptr) { @@ -284,7 +284,7 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data { if (a_Size != 2) { - LOG("Unexpected HandshakeAck packet length: %zu", a_Size); + LOG("Unexpected HandshakeAck packet length: " SIZE_T_FMT "", a_Size); SetError(); break; } diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index afc33a3320..ca188fd0a9 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -155,7 +155,7 @@ cProtocol_1_9_0::cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_Ser } else { - LOG("Unknown additional data sent in server address (BungeeCord/FML?): %zu parameters", Params.size()); + LOG("Unknown additional data sent in server address (BungeeCord/FML?): " SIZE_T_FMT " parameters", Params.size()); // TODO: support FML + BungeeCord? (what parameters does it send in that case?) https://github.com/SpigotMC/BungeeCord/issues/899 } } From 935bebcc9dff19008cb84eba0c9ab81224b6ba3f Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 28 Jul 2017 16:40:41 -0700 Subject: [PATCH 097/166] Tone down logging in ParseModList, debug log only errors --- src/Protocol/ForgeHandshake.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 78236663e6..2c25203a30 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -141,7 +141,7 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) if (a_Size < 4) { - LOG("ParseModList invalid packet, missing length (size=" SIZE_T_FMT ")", a_Size); + LOGD("ParseModList invalid packet, missing length (size=" SIZE_T_FMT ")", a_Size); return Mods; } @@ -151,7 +151,7 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) UInt32 NumMods; if (!Buf.ReadVarInt32(NumMods)) { - LOG("ParseModList failed to read mod count"); + LOGD("ParseModList failed to read mod count"); return Mods; } @@ -160,19 +160,17 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) AString Name, Version; if (!Buf.ReadVarUTF8String(Name)) { - LOG("ParseModList failed to read mod name at i=" SIZE_T_FMT, i); + LOGD("ParseModList failed to read mod name at i=" SIZE_T_FMT, i); break; } if (!Buf.ReadVarUTF8String(Version)) { - LOG("ParseModList failed to read mod version at i=" SIZE_T_FMT, i); + LOGD("ParseModList failed to read mod version at i=" SIZE_T_FMT, i); break; } Mods.insert({Name, Version}); - - LOGD("ParseModList name=%s, version=%s", Name.c_str(), Version.c_str()); } return Mods; From 5109370c1286686367b72ff26606d53d7fe4796c Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 28 Jul 2017 16:44:10 -0700 Subject: [PATCH 098/166] Remove empty lines in ForgeHandshake, more logical block grouping --- src/Protocol/ForgeHandshake.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 2c25203a30..a709929d43 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -66,12 +66,10 @@ void cForgeHandshake::AugmentServerListPing(Json::Value & a_ResponseValue) LOG("Received server ping from version: %d", ProtocolVersion); - // modinfo: Json::Value Modinfo; Modinfo["type"] = "FML"; Json::Value ModList(Json::arrayValue); - for (auto & item: Mods.GetMods()) { Json::Value Mod; @@ -79,10 +77,8 @@ void cForgeHandshake::AugmentServerListPing(Json::Value & a_ResponseValue) Mod["version"] = item.second; ModList.append(Mod); } - Modinfo["modList"] = ModList; - // Augment the response: a_ResponseValue["modinfo"] = Modinfo; } @@ -100,7 +96,6 @@ void cForgeHandshake::BeginForgeHandshake(const AString & a_Name, const AString std::array Channels{{ "FML|HS", "FML", "FML|MP", "FML", "FORGE" }}; AString ChannelsString; - for (auto & Channel: Channels) { ChannelsString.append(Channel); @@ -147,7 +142,6 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) cByteBuffer Buf(a_Size); Buf.Write(a_Data, a_Size); - UInt32 NumMods; if (!Buf.ReadVarInt32(NumMods)) { @@ -163,13 +157,11 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) LOGD("ParseModList failed to read mod name at i=" SIZE_T_FMT, i); break; } - if (!Buf.ReadVarUTF8String(Version)) { LOGD("ParseModList failed to read mod version at i=" SIZE_T_FMT, i); break; } - Mods.insert({Name, Version}); } @@ -187,7 +179,6 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data LOG("Received unexpected Forge data from non-Forge client (" SIZE_T_FMT " bytes)", a_Size); return; } - LOGD("Received Forge data: " SIZE_T_FMT " bytes: %s", a_Size, a_Data); if (a_Size <= 1) From bc3adb6d631b7b3069e56ee9c8a618e6f7766ad1 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 28 Jul 2017 16:52:00 -0700 Subject: [PATCH 099/166] Refactor cForgeHandshake::DataReceived into Handle* functions --- src/Protocol/ForgeHandshake.cpp | 287 +++++++++++++++++--------------- src/Protocol/ForgeHandshake.h | 4 + 2 files changed, 156 insertions(+), 135 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index a709929d43..7e6d1dde34 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -171,6 +171,155 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) +void cForgeHandshake::HandleClientHello(cClientHandle * a_Client, const char * a_Data, size_t a_Size) +{ + if (a_Size == 2) + { + int FmlProtocolVersion = a_Data[1]; + LOGD("Received ClientHello with FML protocol version %d", FmlProtocolVersion); + if (FmlProtocolVersion != 2) + { + LOG("Unsupported FML client protocol version received in ClientHello: %d", FmlProtocolVersion); + SetError(); + } + } + else + { + LOG("Unexpectedly short ClientHello received"); + SetError(); + } +} + + + + +void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Data, size_t a_Size) +{ + LOGD("Received ModList"); + + AStringMap ClientMods = ParseModList(a_Data + 1, a_Size - 1); + AString ClientModsString; + for (auto & item: ClientMods) + { + ClientModsString.append(item.first); + ClientModsString.append("@"); + ClientModsString.append(item.second); + ClientModsString.append(", "); + } + + LOG("Client connected with " SIZE_T_FMT " mods: %s", ClientMods.size(), ClientModsString.c_str()); + + if (m_Client->m_ForgeMods != nullptr) + { + m_Client->m_ForgeMods.reset(); + } + + m_Client->m_ForgeMods = cpp14::make_unique(ClientMods); + + // Let the plugins know about this event, they may refuse the player: + if (cRoot::Get()->GetPluginManager()->CallHookLoginForge(*a_Client)) + { + LOG("Modded client refused by plugin"); + SetError(); + return; + } + + // Send server ModList + + // TODO: max size? + cByteBuffer Buf(1024); + + // Send server-side Forge mods registered by plugins + auto &ServerMods = m_Client->GetForgeMods(); + + size_t ModCount = ServerMods.GetNumMods(); + + Buf.WriteBEInt8(Discriminator::ModList); + Buf.WriteVarInt32(static_cast(ModCount)); + for (size_t i = 0; i < ModCount; ++i) + { + const AString & name = ServerMods.GetModNameAt(i); + const AString & version = ServerMods.GetModVersion(name); + Buf.WriteVarUTF8String(name); + Buf.WriteVarUTF8String(version); + } + AString ServerModList; + Buf.ReadAll(ServerModList); + + m_Client->SendPluginMessage("FML|HS", ServerModList); +} + + + + +void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * a_Data, size_t a_Size) +{ + if (a_Size != 2) + { + LOG("Unexpected HandshakeAck packet length: " SIZE_T_FMT "", a_Size); + SetError(); + return; + } + + int Phase = a_Data[1]; + LOGD("Received client HandshakeAck with phase=%d", Phase); + + switch (Phase) + { + case ClientPhase_WAITINGSERVERDATA: + { + cByteBuffer Buf(1024); + Buf.WriteBEInt8(Discriminator::RegistryData); + + // TODO: send real registry data + bool HasMore = false; + AString RegistryName = "potions"; + UInt32 NumIDs = 0; + UInt32 NumSubstitutions = 0; + UInt32 NumDummies = 0; + + Buf.WriteBool(HasMore); + Buf.WriteVarUTF8String(RegistryName); + Buf.WriteVarInt32(NumIDs); + Buf.WriteVarInt32(NumSubstitutions); + Buf.WriteVarInt32(NumDummies); + + AString RegistryData; + Buf.ReadAll(RegistryData); + m_Client->SendPluginMessage("FML|HS", RegistryData); + break; + } + + case ClientPhase_WAITINGSERVERCOMPLETE: + { + LOG("Client finished receiving registry data; acknowledging"); + + AString Ack; + Ack.push_back(Discriminator::HandshakeAck); + Ack.push_back(ServerPhase_WAITINGCACK); + m_Client->SendPluginMessage("FML|HS", Ack); + break; + } + + case ClientPhase_PENDINGCOMPLETE: + { + LOG("Client is pending completion; sending complete ack"); + + AString Ack; + Ack.push_back(Discriminator::HandshakeAck); + Ack.push_back(ServerPhase_COMPLETE); + m_Client->SendPluginMessage("FML|HS", Ack); + + // Now finish logging in + m_Client->FinishAuthenticate(*m_Name, *m_UUID, *m_Properties); + break; + } + } +} + + + + void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data, size_t a_Size) { @@ -192,148 +341,16 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data switch (Discriminator) { case Discriminator::ClientHello: - { - if (a_Size == 2) - { - int FmlProtocolVersion = a_Data[1]; - LOGD("Received ClientHello with FML protocol version %d", FmlProtocolVersion); - if (FmlProtocolVersion != 2) - { - LOG("Unsupported FML client protocol version received in ClientHello: %d", FmlProtocolVersion); - SetError(); - } - } - else - { - LOG("Unexpectedly short ClientHello received"); - SetError(); - } - + HandleClientHello(a_Client, a_Data, a_Size); break; - } case Discriminator::ModList: - { - LOGD("Received ModList"); - - AStringMap ClientMods = ParseModList(a_Data + 1, a_Size - 1); - AString ClientModsString; - for (auto & item: ClientMods) - { - ClientModsString.append(item.first); - ClientModsString.append("@"); - ClientModsString.append(item.second); - ClientModsString.append(", "); - } - - LOG("Client connected with " SIZE_T_FMT " mods: %s", ClientMods.size(), ClientModsString.c_str()); - - if (m_Client->m_ForgeMods != nullptr) - { - m_Client->m_ForgeMods.reset(); - } - - m_Client->m_ForgeMods = cpp14::make_unique(ClientMods); - - // Let the plugins know about this event, they may refuse the player: - if (cRoot::Get()->GetPluginManager()->CallHookLoginForge(*a_Client)) - { - LOG("Modded client refused by plugin"); - SetError(); - return; - } - - // Send server ModList - - // TODO: max size? - cByteBuffer Buf(1024); - - // Send server-side Forge mods registered by plugins - auto &ServerMods = m_Client->GetForgeMods(); - - size_t ModCount = ServerMods.GetNumMods(); - - Buf.WriteBEInt8(Discriminator::ModList); - Buf.WriteVarInt32(static_cast(ModCount)); - for (size_t i = 0; i < ModCount; ++i) - { - const AString & name = ServerMods.GetModNameAt(i); - const AString & version = ServerMods.GetModVersion(name); - Buf.WriteVarUTF8String(name); - Buf.WriteVarUTF8String(version); - } - AString ServerModList; - Buf.ReadAll(ServerModList); - - m_Client->SendPluginMessage("FML|HS", ServerModList); + HandleModList(a_Client, a_Data, a_Size); break; - } case Discriminator::HandshakeAck: - { - if (a_Size != 2) - { - LOG("Unexpected HandshakeAck packet length: " SIZE_T_FMT "", a_Size); - SetError(); - break; - } - - int Phase = a_Data[1]; - LOGD("Received client HandshakeAck with phase=%d", Phase); - - switch (Phase) - { - case ClientPhase_WAITINGSERVERDATA: - { - cByteBuffer Buf(1024); - Buf.WriteBEInt8(Discriminator::RegistryData); - - // TODO: send real registry data - bool HasMore = false; - AString RegistryName = "potions"; - UInt32 NumIDs = 0; - UInt32 NumSubstitutions = 0; - UInt32 NumDummies = 0; - - Buf.WriteBool(HasMore); - Buf.WriteVarUTF8String(RegistryName); - Buf.WriteVarInt32(NumIDs); - Buf.WriteVarInt32(NumSubstitutions); - Buf.WriteVarInt32(NumDummies); - - AString RegistryData; - Buf.ReadAll(RegistryData); - m_Client->SendPluginMessage("FML|HS", RegistryData); - break; - } - - case ClientPhase_WAITINGSERVERCOMPLETE: - { - LOG("Client finished receiving registry data; acknowledging"); - - AString Ack; - Ack.push_back(Discriminator::HandshakeAck); - Ack.push_back(ServerPhase_WAITINGCACK); - m_Client->SendPluginMessage("FML|HS", Ack); - break; - } - - case ClientPhase_PENDINGCOMPLETE: - { - LOG("Client is pending completion; sending complete ack"); - - AString Ack; - Ack.push_back(Discriminator::HandshakeAck); - Ack.push_back(ServerPhase_COMPLETE); - m_Client->SendPluginMessage("FML|HS", Ack); - - // Now finish logging in - m_Client->FinishAuthenticate(*m_Name, *m_UUID, *m_Properties); - break; - } - } + HandleHandshakeAck(a_Client, a_Data, a_Size); break; - } default: { diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index a95132fdb6..13ed7893f4 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -39,6 +39,10 @@ class cForgeHandshake bool m_IsForgeClient; private: + void HandleClientHello(cClientHandle * a_Client, const char * a_Data, size_t a_Size); + void HandleModList(cClientHandle * a_Client, const char * a_Data, size_t a_Size); + void HandleHandshakeAck(cClientHandle * a_Client, const char * a_Data, size_t a_Size); + /** Parse the client ModList packet of installed Forge mods and versions. */ AStringMap ParseModList(const char * a_Data, size_t a_Size); From 9dfb124b6676810d74530efec54978252fceec6e Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 28 Jul 2017 23:07:48 -0700 Subject: [PATCH 100/166] Fix initialization error in file Plugins/APIDump/APIDesc.lua: 2 (Plugins/APIDump/APIDesc.lua:11930: attempt to call global 'UnregisterForgeMod' (a nil value)) --- Server/Plugins/APIDump/APIDesc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua index 6dcc3f8ea7..59897a9b2e 100644 --- a/Server/Plugins/APIDump/APIDesc.lua +++ b/Server/Plugins/APIDump/APIDesc.lua @@ -11926,7 +11926,7 @@ end }, Notes = "Returns true iff the server is set to authenticate players (\"online mode\").", }, - UnregisterForgeMod + UnregisterForgeMod = { Params = { From ab62461dce1cd2a6e7b439594af679f19ee803d4 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 29 Jul 2017 00:00:07 -0700 Subject: [PATCH 101/166] Revert enum Discriminator: signed char, Discriminator_ -> Discriminator:: (fails on gcc) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://travis-ci.org/cuberite/cuberite/jobs/258806610 /home/travis/build/cuberite/cuberite/src/Protocol/ForgeHandshake.cpp:343:8: error: ‘Discriminator’ is not a class, namespace, or enumeration case Discriminator::ClientHello: --- src/Protocol/ForgeHandshake.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 7e6d1dde34..d38c3bc0e7 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -15,12 +15,12 @@ /** Discriminator byte values prefixing the FML|HS packets to determine their type. */ enum Discriminator: signed char { - ServerHello = 0, - ClientHello = 1, - ModList = 2, - RegistryData = 3, - HandshakeReset = -2, - HandshakeAck = -1, + Discriminator_ServerHello = 0, + Discriminator_ClientHello = 1, + Discriminator_ModList = 2, + Discriminator_RegistryData = 3, + Discriminator_HandshakeReset = -2, + Discriminator_HandshakeAck = -1, }; /** Client handshake state phases. */ @@ -114,7 +114,7 @@ void cForgeHandshake::SendServerHello() { AString Message; // Discriminator | Byte | Always 0 for ServerHello - Message.push_back(Discriminator::ServerHello); + Message.push_back(Discriminator_ServerHello); // FML protocol Version | Byte | Determined from NetworkRegistery. Currently 2. Message.push_back('\2'); // Dimension TODO @@ -234,7 +234,7 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat size_t ModCount = ServerMods.GetNumMods(); - Buf.WriteBEInt8(Discriminator::ModList); + Buf.WriteBEInt8(Discriminator_ModList); Buf.WriteVarInt32(static_cast(ModCount)); for (size_t i = 0; i < ModCount; ++i) { @@ -269,7 +269,7 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * case ClientPhase_WAITINGSERVERDATA: { cByteBuffer Buf(1024); - Buf.WriteBEInt8(Discriminator::RegistryData); + Buf.WriteBEInt8(Discriminator_RegistryData); // TODO: send real registry data bool HasMore = false; @@ -295,7 +295,7 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * LOG("Client finished receiving registry data; acknowledging"); AString Ack; - Ack.push_back(Discriminator::HandshakeAck); + Ack.push_back(Discriminator_HandshakeAck); Ack.push_back(ServerPhase_WAITINGCACK); m_Client->SendPluginMessage("FML|HS", Ack); break; @@ -306,7 +306,7 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * LOG("Client is pending completion; sending complete ack"); AString Ack; - Ack.push_back(Discriminator::HandshakeAck); + Ack.push_back(Discriminator_HandshakeAck); Ack.push_back(ServerPhase_COMPLETE); m_Client->SendPluginMessage("FML|HS", Ack); @@ -340,15 +340,15 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data switch (Discriminator) { - case Discriminator::ClientHello: + case Discriminator_ClientHello: HandleClientHello(a_Client, a_Data, a_Size); break; - case Discriminator::ModList: + case Discriminator_ModList: HandleModList(a_Client, a_Data, a_Size); break; - case Discriminator::HandshakeAck: + case Discriminator_HandshakeAck: HandleHandshakeAck(a_Client, a_Data, a_Size); break; From 4c59531e68d8c4d6b15b69e07754edb529e335f2 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 29 Jul 2017 12:24:28 -0700 Subject: [PATCH 102/166] Try changing Discriminator to an 'enum class' --- src/Protocol/ForgeHandshake.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index d38c3bc0e7..3d0634afe5 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -13,14 +13,14 @@ /** Discriminator byte values prefixing the FML|HS packets to determine their type. */ -enum Discriminator: signed char +enum class Discriminator: Int8 { - Discriminator_ServerHello = 0, - Discriminator_ClientHello = 1, - Discriminator_ModList = 2, - Discriminator_RegistryData = 3, - Discriminator_HandshakeReset = -2, - Discriminator_HandshakeAck = -1, + ServerHello = 0, + ClientHello = 1, + ModList = 2, + RegistryData = 3, + HandshakeReset = -2, + HandshakeAck = -1, }; /** Client handshake state phases. */ @@ -114,7 +114,7 @@ void cForgeHandshake::SendServerHello() { AString Message; // Discriminator | Byte | Always 0 for ServerHello - Message.push_back(Discriminator_ServerHello); + Message.push_back(static_cast(Discriminator::ServerHello)); // FML protocol Version | Byte | Determined from NetworkRegistery. Currently 2. Message.push_back('\2'); // Dimension TODO @@ -234,7 +234,7 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat size_t ModCount = ServerMods.GetNumMods(); - Buf.WriteBEInt8(Discriminator_ModList); + Buf.WriteBEInt8(static_cast(Discriminator::ModList)); Buf.WriteVarInt32(static_cast(ModCount)); for (size_t i = 0; i < ModCount; ++i) { @@ -269,7 +269,7 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * case ClientPhase_WAITINGSERVERDATA: { cByteBuffer Buf(1024); - Buf.WriteBEInt8(Discriminator_RegistryData); + Buf.WriteBEInt8(static_cast(Discriminator::RegistryData)); // TODO: send real registry data bool HasMore = false; @@ -295,7 +295,7 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * LOG("Client finished receiving registry data; acknowledging"); AString Ack; - Ack.push_back(Discriminator_HandshakeAck); + Ack.push_back(static_cast(Discriminator::HandshakeAck)); Ack.push_back(ServerPhase_WAITINGCACK); m_Client->SendPluginMessage("FML|HS", Ack); break; @@ -306,7 +306,7 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * LOG("Client is pending completion; sending complete ack"); AString Ack; - Ack.push_back(Discriminator_HandshakeAck); + Ack.push_back(static_cast(Discriminator::HandshakeAck)); Ack.push_back(ServerPhase_COMPLETE); m_Client->SendPluginMessage("FML|HS", Ack); @@ -340,15 +340,15 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data switch (Discriminator) { - case Discriminator_ClientHello: + case static_cast(Discriminator::ClientHello): HandleClientHello(a_Client, a_Data, a_Size); break; - case Discriminator_ModList: + case static_cast(Discriminator::ModList): HandleModList(a_Client, a_Data, a_Size); break; - case Discriminator_HandshakeAck: + case static_cast(Discriminator::HandshakeAck): HandleHandshakeAck(a_Client, a_Data, a_Size); break; From e10e3ffd74e78e1e720fbe114332e1d5359dd33d Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 29 Jul 2017 12:28:48 -0700 Subject: [PATCH 103/166] Change client/server phase to enum classes enum class, unlike enum, has names local to the enum itself, so ServerPhase::COMPLETE is separate from ClientPhase::COMPLETE, see https://stackoverflow.com/questions/18335861/why-is-enum-class-preferred-over-plain-enum --- src/Protocol/ForgeHandshake.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 3d0634afe5..7471f31b2f 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -24,19 +24,19 @@ enum class Discriminator: Int8 }; /** Client handshake state phases. */ -enum +enum class ClientPhase: Int8 { - ClientPhase_WAITINGSERVERDATA = 2, - ClientPhase_WAITINGSERVERCOMPLETE = 3, - ClientPhase_PENDINGCOMPLETE = 4, - ClientPhase_COMPLETE = 5, + WAITINGSERVERDATA = 2, + WAITINGSERVERCOMPLETE = 3, + PENDINGCOMPLETE = 4, + COMPLETE = 5, }; /** Server handshake state phases. */ -enum +enum class ServerPhase: Int8 { - ServerPhase_WAITINGCACK = 2, - ServerPhase_COMPLETE = 3, + WAITINGCACK = 2, + COMPLETE = 3, }; @@ -266,7 +266,7 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * switch (Phase) { - case ClientPhase_WAITINGSERVERDATA: + case static_cast(ClientPhase::WAITINGSERVERDATA): { cByteBuffer Buf(1024); Buf.WriteBEInt8(static_cast(Discriminator::RegistryData)); @@ -290,24 +290,24 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * break; } - case ClientPhase_WAITINGSERVERCOMPLETE: + case static_cast(ClientPhase::WAITINGSERVERCOMPLETE): { LOG("Client finished receiving registry data; acknowledging"); AString Ack; Ack.push_back(static_cast(Discriminator::HandshakeAck)); - Ack.push_back(ServerPhase_WAITINGCACK); + Ack.push_back(static_cast(ServerPhase::WAITINGCACK)); m_Client->SendPluginMessage("FML|HS", Ack); break; } - case ClientPhase_PENDINGCOMPLETE: + case static_cast(ClientPhase::PENDINGCOMPLETE): { LOG("Client is pending completion; sending complete ack"); AString Ack; Ack.push_back(static_cast(Discriminator::HandshakeAck)); - Ack.push_back(ServerPhase_COMPLETE); + Ack.push_back(static_cast(ServerPhase::COMPLETE)); m_Client->SendPluginMessage("FML|HS", Ack); // Now finish logging in From db5956ddaa3a710e97e2ea292d1b76d2396f6c43 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 29 Jul 2017 12:40:01 -0700 Subject: [PATCH 104/166] Revert "Change client/server phase to enum classes" (gcc fail) This reverts commit e10e3ffd74e78e1e720fbe114332e1d5359dd33d. https://travis-ci.org/cuberite/cuberite/jobs/258935845 --- src/Protocol/ForgeHandshake.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 7471f31b2f..3d0634afe5 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -24,19 +24,19 @@ enum class Discriminator: Int8 }; /** Client handshake state phases. */ -enum class ClientPhase: Int8 +enum { - WAITINGSERVERDATA = 2, - WAITINGSERVERCOMPLETE = 3, - PENDINGCOMPLETE = 4, - COMPLETE = 5, + ClientPhase_WAITINGSERVERDATA = 2, + ClientPhase_WAITINGSERVERCOMPLETE = 3, + ClientPhase_PENDINGCOMPLETE = 4, + ClientPhase_COMPLETE = 5, }; /** Server handshake state phases. */ -enum class ServerPhase: Int8 +enum { - WAITINGCACK = 2, - COMPLETE = 3, + ServerPhase_WAITINGCACK = 2, + ServerPhase_COMPLETE = 3, }; @@ -266,7 +266,7 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * switch (Phase) { - case static_cast(ClientPhase::WAITINGSERVERDATA): + case ClientPhase_WAITINGSERVERDATA: { cByteBuffer Buf(1024); Buf.WriteBEInt8(static_cast(Discriminator::RegistryData)); @@ -290,24 +290,24 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * break; } - case static_cast(ClientPhase::WAITINGSERVERCOMPLETE): + case ClientPhase_WAITINGSERVERCOMPLETE: { LOG("Client finished receiving registry data; acknowledging"); AString Ack; Ack.push_back(static_cast(Discriminator::HandshakeAck)); - Ack.push_back(static_cast(ServerPhase::WAITINGCACK)); + Ack.push_back(ServerPhase_WAITINGCACK); m_Client->SendPluginMessage("FML|HS", Ack); break; } - case static_cast(ClientPhase::PENDINGCOMPLETE): + case ClientPhase_PENDINGCOMPLETE: { LOG("Client is pending completion; sending complete ack"); AString Ack; Ack.push_back(static_cast(Discriminator::HandshakeAck)); - Ack.push_back(static_cast(ServerPhase::COMPLETE)); + Ack.push_back(ServerPhase_COMPLETE); m_Client->SendPluginMessage("FML|HS", Ack); // Now finish logging in From 342056dada02bf985779513a4b8b66b6c76bef05 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 29 Jul 2017 12:40:18 -0700 Subject: [PATCH 105/166] Revert "Try changing Discriminator to an 'enum class'" (gcc fail) This reverts commit 4c59531e68d8c4d6b15b69e07754edb529e335f2. https://travis-ci.org/cuberite/cuberite/jobs/258935845 --- src/Protocol/ForgeHandshake.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 3d0634afe5..d38c3bc0e7 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -13,14 +13,14 @@ /** Discriminator byte values prefixing the FML|HS packets to determine their type. */ -enum class Discriminator: Int8 +enum Discriminator: signed char { - ServerHello = 0, - ClientHello = 1, - ModList = 2, - RegistryData = 3, - HandshakeReset = -2, - HandshakeAck = -1, + Discriminator_ServerHello = 0, + Discriminator_ClientHello = 1, + Discriminator_ModList = 2, + Discriminator_RegistryData = 3, + Discriminator_HandshakeReset = -2, + Discriminator_HandshakeAck = -1, }; /** Client handshake state phases. */ @@ -114,7 +114,7 @@ void cForgeHandshake::SendServerHello() { AString Message; // Discriminator | Byte | Always 0 for ServerHello - Message.push_back(static_cast(Discriminator::ServerHello)); + Message.push_back(Discriminator_ServerHello); // FML protocol Version | Byte | Determined from NetworkRegistery. Currently 2. Message.push_back('\2'); // Dimension TODO @@ -234,7 +234,7 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat size_t ModCount = ServerMods.GetNumMods(); - Buf.WriteBEInt8(static_cast(Discriminator::ModList)); + Buf.WriteBEInt8(Discriminator_ModList); Buf.WriteVarInt32(static_cast(ModCount)); for (size_t i = 0; i < ModCount; ++i) { @@ -269,7 +269,7 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * case ClientPhase_WAITINGSERVERDATA: { cByteBuffer Buf(1024); - Buf.WriteBEInt8(static_cast(Discriminator::RegistryData)); + Buf.WriteBEInt8(Discriminator_RegistryData); // TODO: send real registry data bool HasMore = false; @@ -295,7 +295,7 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * LOG("Client finished receiving registry data; acknowledging"); AString Ack; - Ack.push_back(static_cast(Discriminator::HandshakeAck)); + Ack.push_back(Discriminator_HandshakeAck); Ack.push_back(ServerPhase_WAITINGCACK); m_Client->SendPluginMessage("FML|HS", Ack); break; @@ -306,7 +306,7 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * LOG("Client is pending completion; sending complete ack"); AString Ack; - Ack.push_back(static_cast(Discriminator::HandshakeAck)); + Ack.push_back(Discriminator_HandshakeAck); Ack.push_back(ServerPhase_COMPLETE); m_Client->SendPluginMessage("FML|HS", Ack); @@ -340,15 +340,15 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data switch (Discriminator) { - case static_cast(Discriminator::ClientHello): + case Discriminator_ClientHello: HandleClientHello(a_Client, a_Data, a_Size); break; - case static_cast(Discriminator::ModList): + case Discriminator_ModList: HandleModList(a_Client, a_Data, a_Size); break; - case static_cast(Discriminator::HandshakeAck): + case Discriminator_HandshakeAck: HandleHandshakeAck(a_Client, a_Data, a_Size); break; From cd07cd1579a46ecc122e787bcd91a5baaa05325e Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 29 Jul 2017 12:56:09 -0700 Subject: [PATCH 106/166] Initialize m_ForgeModsByVersion on-demand when each version is requested --- src/Server.cpp | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/Server.cpp b/src/Server.cpp index 4870218ae8..a07c59db62 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -211,25 +211,6 @@ bool cServer::InitServer(cSettingsRepositoryInterface & a_Settings, bool a_Shoul LOGWARNING("WARNING: BungeeCord is allowed and server set to online mode. This is unsafe and will not work properly. Disable either authentication or BungeeCord in settings.ini."); } - int Versions[] = - { - // TODO: better way to get all supported versions from cProtocolRecognizer? - cProtocolRecognizer::PROTO_VERSION_1_8_0, - cProtocolRecognizer::PROTO_VERSION_1_9_0, - cProtocolRecognizer::PROTO_VERSION_1_9_1, - cProtocolRecognizer::PROTO_VERSION_1_9_2, - cProtocolRecognizer::PROTO_VERSION_1_9_4, - cProtocolRecognizer::PROTO_VERSION_1_10_0, - cProtocolRecognizer::PROTO_VERSION_1_11_0, - cProtocolRecognizer::PROTO_VERSION_1_11_1, - cProtocolRecognizer::PROTO_VERSION_1_12, - }; - for (size_t i = 0; i < sizeof(Versions) / sizeof(Versions[0]); ++i) - { - cForgeMods Mods; - m_ForgeModsByVersion.insert({Versions[i], Mods}); - } - m_ShouldAllowMultiWorldTabCompletion = a_Settings.GetValueSetB("Server", "AllowMultiWorldTabCompletion", true); m_ShouldLimitPlayerBlockChanges = a_Settings.GetValueSetB("AntiCheat", "LimitPlayerBlockChanges", true); m_ShouldLoadOfflinePlayerData = a_Settings.GetValueSetB("PlayerData", "LoadOfflinePlayerData", false); @@ -281,7 +262,12 @@ cForgeMods & cServer::GetRegisteredForgeMods(const UInt32 a_Protocol) { auto it = m_ForgeModsByVersion.find(a_Protocol); - ASSERT(it != m_ForgeModsByVersion.end()); + if (it == m_ForgeModsByVersion.end()) + { + cForgeMods mods; + m_ForgeModsByVersion.insert({a_Protocol, mods}); + return m_ForgeModsByVersion.find(a_Protocol)->second; + } return it->second; } From bfb4b7a08a2125a948640710852a30cafbcaf65c Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 29 Jul 2017 12:57:32 -0700 Subject: [PATCH 107/166] Add doxy comment for GetRegisteredForgeMods() --- src/Server.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Server.h b/src/Server.h index 2d0729cfdb..064c7b2d33 100644 --- a/src/Server.h +++ b/src/Server.h @@ -154,6 +154,7 @@ class cServer from the settings. */ bool ShouldAllowMultiWorldTabCompletion(void) const { return m_ShouldAllowMultiWorldTabCompletion; } + /** Get the Forge mods registered for a given protocol. */ cForgeMods & GetRegisteredForgeMods(const UInt32 a_Protocol); private: From 7a7992b68328e896b461905d658946af10f72ef6 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 29 Jul 2017 14:49:41 -0700 Subject: [PATCH 108/166] Remove cForgeMods in registration, use AStringMap --- src/Protocol/ForgeHandshake.cpp | 6 +++--- src/Server.cpp | 18 +++++++++++------- src/Server.h | 4 ++-- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index d38c3bc0e7..0e5d033c0c 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -57,9 +57,9 @@ cForgeHandshake::cForgeHandshake(cClientHandle *a_Client) : void cForgeHandshake::AugmentServerListPing(Json::Value & a_ResponseValue) { UInt32 ProtocolVersion = m_Client->GetProtocolVersion(); - cForgeMods & Mods = cRoot::Get()->GetServer()->GetRegisteredForgeMods(ProtocolVersion); + AStringMap & Mods = cRoot::Get()->GetServer()->GetRegisteredForgeMods(ProtocolVersion); - if (!Mods.HasMods()) + if (Mods.size() == 0) { return; } @@ -70,7 +70,7 @@ void cForgeHandshake::AugmentServerListPing(Json::Value & a_ResponseValue) Modinfo["type"] = "FML"; Json::Value ModList(Json::arrayValue); - for (auto & item: Mods.GetMods()) + for (auto & item: Mods) { Json::Value Mod; Mod["modid"] = item.first; diff --git a/src/Server.cpp b/src/Server.cpp index a07c59db62..a676fb7eae 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -239,10 +239,9 @@ bool cServer::InitServer(cSettingsRepositoryInterface & a_Settings, bool a_Shoul bool cServer::RegisterForgeMod(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber) { - cForgeMods & mods = GetRegisteredForgeMods(a_ProtocolVersionNumber); - bool success = mods.Add(a_ModName, a_ModVersion); + AStringMap & Mods = GetRegisteredForgeMods(a_ProtocolVersionNumber); - return success; + return Mods.insert({a_ModName, a_ModVersion}).second; } @@ -251,20 +250,25 @@ bool cServer::RegisterForgeMod(AString & a_ModName, AString & a_ModVersion, UInt void cServer::UnregisterForgeMod(AString &a_ModName, UInt32 a_ProtocolVersionNumber) { - cForgeMods & mods = GetRegisteredForgeMods(a_ProtocolVersionNumber); - mods.Remove(a_ModName); + AStringMap & Mods = GetRegisteredForgeMods(a_ProtocolVersionNumber); + + auto it = Mods.find(a_ModName); + if (it != Mods.end()) + { + Mods.erase(it); + } } -cForgeMods & cServer::GetRegisteredForgeMods(const UInt32 a_Protocol) +AStringMap & cServer::GetRegisteredForgeMods(const UInt32 a_Protocol) { auto it = m_ForgeModsByVersion.find(a_Protocol); if (it == m_ForgeModsByVersion.end()) { - cForgeMods mods; + AStringMap mods; m_ForgeModsByVersion.insert({a_Protocol, mods}); return m_ForgeModsByVersion.find(a_Protocol)->second; } diff --git a/src/Server.h b/src/Server.h index 064c7b2d33..c9212e50b9 100644 --- a/src/Server.h +++ b/src/Server.h @@ -155,7 +155,7 @@ class cServer bool ShouldAllowMultiWorldTabCompletion(void) const { return m_ShouldAllowMultiWorldTabCompletion; } /** Get the Forge mods registered for a given protocol. */ - cForgeMods & GetRegisteredForgeMods(const UInt32 a_Protocol); + AStringMap & GetRegisteredForgeMods(const UInt32 a_Protocol); private: @@ -215,7 +215,7 @@ class cServer bool m_bIsHardcore; /** Map of protocol version to Forge mods for that version. */ - std::map m_ForgeModsByVersion; + std::map m_ForgeModsByVersion; /** True - allow same username to login more than once False - only once */ bool m_bAllowMultiLogin; From 2d63362281459c66d840e7ee0a8ffb30b6e811e2 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 29 Jul 2017 15:01:41 -0700 Subject: [PATCH 109/166] Remove cForgeMods in ClientHandle, use AStringMap --- src/ClientHandle.h | 4 ++-- src/Protocol/ForgeHandshake.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 93232a5be0..5beac48b2b 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -267,7 +267,7 @@ class cClientHandle // tolua_export const AString & GetClientBrand(void) const { return m_ClientBrand; } /** Returns the Forge mods installed on the client. */ - const cForgeMods & GetForgeMods(void) const { return m_ForgeMods ? *m_ForgeMods : cForgeMods::Unmodded(); } + const AStringMap & GetForgeMods(void) const { return m_ForgeMods ? *m_ForgeMods : *new AStringMap(); } // TODO: fix memory leak /** Returns true if the client is modded with Forge. */ bool IsForgeClient(void) const { return m_ForgeHandshake.m_IsForgeClient; } @@ -413,7 +413,7 @@ class cClientHandle // tolua_export cForgeHandshake m_ForgeHandshake; /** Forge mods and versions installed on this client, if any. */ - std::unique_ptr m_ForgeMods; + std::unique_ptr m_ForgeMods; /** The actual view distance used, the minimum of client's requested view distance and world's max view distance. */ int m_CurrentViewDistance; diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 0e5d033c0c..ed665f78f7 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -214,7 +214,7 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat m_Client->m_ForgeMods.reset(); } - m_Client->m_ForgeMods = cpp14::make_unique(ClientMods); + m_Client->m_ForgeMods = cpp14::make_unique(ClientMods); // Let the plugins know about this event, they may refuse the player: if (cRoot::Get()->GetPluginManager()->CallHookLoginForge(*a_Client)) @@ -232,14 +232,14 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat // Send server-side Forge mods registered by plugins auto &ServerMods = m_Client->GetForgeMods(); - size_t ModCount = ServerMods.GetNumMods(); + size_t ModCount = ServerMods.size(); Buf.WriteBEInt8(Discriminator_ModList); Buf.WriteVarInt32(static_cast(ModCount)); - for (size_t i = 0; i < ModCount; ++i) + for (auto & item: ServerMods) { - const AString & name = ServerMods.GetModNameAt(i); - const AString & version = ServerMods.GetModVersion(name); + const AString & name = item.first; + const AString & version = item.second; Buf.WriteVarUTF8String(name); Buf.WriteVarUTF8String(version); } From f547136b086eda1689d350233e46a2d96f98f595 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 29 Jul 2017 15:15:30 -0700 Subject: [PATCH 110/166] Remove cForgeMods class in favor of AStringMap --- Server/Plugins/APIDump/APIDesc.lua | 73 +--------------------- src/Bindings/AllToLua.pkg | 1 - src/Bindings/CMakeLists.txt | 1 - src/ClientHandle.h | 1 - src/Protocol/CMakeLists.txt | 2 - src/Protocol/ForgeMods.cpp | 97 ------------------------------ src/Protocol/ForgeMods.h | 46 -------------- src/Server.h | 1 - 8 files changed, 1 insertion(+), 221 deletions(-) delete mode 100644 src/Protocol/ForgeMods.cpp delete mode 100644 src/Protocol/ForgeMods.h diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua index 59897a9b2e..38c002a340 100644 --- a/Server/Plugins/APIDump/APIDesc.lua +++ b/Server/Plugins/APIDump/APIDesc.lua @@ -1353,7 +1353,7 @@ end Returns = { { - Type = "cForgeMods", + Type = "AStringMap", }, }, Notes = "Returns the Forge mods installed on the client.", @@ -4902,77 +4902,6 @@ cFile:DeleteFile("/usr/bin/virus.exe"); }, Inherits = "cEntity", }, - cForgeMods = - { - Desc = [[ - Data structure listing the Forge mods name and versions. - ]], - Functions = - { - GetModNameAt = - { - Params = - { - { - Name = "i", - Type = "number", - }, - }, - Returns = - { - { - Type = "string", - }, - }, - Notes = "Returns the name of the Forge mod at the given index.", - }, - GetModVersion = - { - Params = - { - { - Name = "name", - Type = "string", - }, - }, - Returns = - { - { - Type = "string", - }, - }, - Notes = "Returns the version of the mod name given.", - - }, - GetNumMods = - { - Returns = - { - { - Type = "number", - }, - }, - Notes = "Returns the number of Forge mods.", - }, - HasMod = - { - Params = - { - { - Name = "name", - Type = "string", - }, - }, - Returns = - { - { - Type = "boolean", - }, - }, - Notes = "Returns true if the mod with the given name is installed.", - }, - }, - }, cHangingEntity = { Functions = diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 1b435fc022..a109913e25 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -69,7 +69,6 @@ $cfile "../MapManager.h" $cfile "../Scoreboard.h" $cfile "../Statistics.h" $cfile "../Protocol/MojangAPI.h" -$cfile "../Protocol/ForgeMods.h" // Entities: $cfile "../Entities/Entity.h" diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt index f40cd9e716..da7c8bbe87 100644 --- a/src/Bindings/CMakeLists.txt +++ b/src/Bindings/CMakeLists.txt @@ -131,7 +131,6 @@ set(BINDING_DEPENDENCIES ../Mobs/MonsterTypes.h ../OSSupport/File.h ../Protocol/MojangAPI.h - ../Protocol/ForgeMods.h ../Root.h ../Scoreboard.h ../Server.h diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 5beac48b2b..38979532e1 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -22,7 +22,6 @@ #include "ChunkSender.h" #include "EffectID.h" #include "Protocol/ForgeHandshake.h" -#include "Protocol/ForgeMods.h" #include diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt index c4ac0ba110..00ffeb2553 100644 --- a/src/Protocol/CMakeLists.txt +++ b/src/Protocol/CMakeLists.txt @@ -6,7 +6,6 @@ SET (SRCS Authenticator.cpp ChunkDataSerializer.cpp ForgeHandshake.cpp - ForgeMods.cpp MojangAPI.cpp Packetizer.cpp Protocol_1_8.cpp @@ -21,7 +20,6 @@ SET (HDRS Authenticator.h ChunkDataSerializer.h ForgeHandshake.h - ForgeMods.h MojangAPI.h Packetizer.h Protocol.h diff --git a/src/Protocol/ForgeMods.cpp b/src/Protocol/ForgeMods.cpp deleted file mode 100644 index e1d8e42b85..0000000000 --- a/src/Protocol/ForgeMods.cpp +++ /dev/null @@ -1,97 +0,0 @@ - -// ForgeMods.cpp - -// Data structure listing the Forge mods name and versions - -#include "Globals.h" -#include "ForgeMods.h" - -cForgeMods::cForgeMods() -{ -} - - - - - -cForgeMods::cForgeMods(const AStringMap & a):m_Mods(a) -{ - for (const auto & item: a) - { - m_ModNames.push_back(item.first); - } -} - - - - -const cForgeMods & cForgeMods::Unmodded(void) -{ - static cForgeMods Unmodded; - - return Unmodded; -} - - - - -size_t cForgeMods::GetNumMods(void) const -{ - return m_Mods.size(); -} - - - -bool cForgeMods::HasMod(const AString & name) const -{ - return m_Mods.find(name) != m_Mods.end(); -} - - - - -const AString & cForgeMods::GetModVersion(const AString & name) const -{ - return m_Mods.find(name)->second; -} - - - - -const AString & cForgeMods::GetModNameAt(size_t i) const -{ - return m_ModNames[i]; -} - - - - - -bool cForgeMods::Add(const AString & a_Name, const AString & a_Version) -{ - auto ret = m_Mods.insert({a_Name, a_Version}); - - if (!ret.second) - { - return false; - } - - m_ModNames.push_back(a_Name); - - return true; -} - - - - - -void cForgeMods::Remove(const AString & a_Name) -{ - auto it = std::find(m_ModNames.begin(), m_ModNames.end(), a_Name); - if (it != m_ModNames.end()) - { - m_ModNames.erase(it); - } - - m_Mods.erase(a_Name); -} diff --git a/src/Protocol/ForgeMods.h b/src/Protocol/ForgeMods.h deleted file mode 100644 index e8866b71d8..0000000000 --- a/src/Protocol/ForgeMods.h +++ /dev/null @@ -1,46 +0,0 @@ - -// ForgeMods.h - -// Data structure listing the Forge mods name and versions. - -#pragma once - -#include - -// tolua_begin -class cForgeMods -{ -public: - // TODO: can tolua++ bridge AStringMap (etc.) as a Lua table? or non-fixedsize arrays? - - /** Returns the number of Forge mods. */ - size_t GetNumMods(void) const; - - /** Returns true if the mod with the given name is installed. */ - bool HasMod(const AString & name) const; - - /** Returns the version of the mod name given. */ - const AString & GetModVersion(const AString & name) const; - - /** Returns the name of the Forge mod at the given index. */ - const AString & GetModNameAt(size_t i) const; - - // tolua_end - - cForgeMods(); - cForgeMods(const AStringMap & a); - - static const cForgeMods & Unmodded(void); - - bool Add(const AString & a_Name, const AString & a_Version); - - void Remove(const AString & a_Name); - - AStringMap GetMods() { return m_Mods; } - - bool HasMods() { return m_Mods.size() != 0; } - -private: - AStringMap m_Mods; - AStringVector m_ModNames; -} ; // tolua_export diff --git a/src/Server.h b/src/Server.h index c9212e50b9..3bb889c2b0 100644 --- a/src/Server.h +++ b/src/Server.h @@ -12,7 +12,6 @@ #include "RCONServer.h" #include "OSSupport/IsThread.h" #include "OSSupport/Network.h" -#include "Protocol/ForgeMods.h" #ifdef _MSC_VER #pragma warning(push) From abd295fd24a51671949f2d4a8d9fee41dc5c032d Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 29 Jul 2017 15:31:21 -0700 Subject: [PATCH 111/166] APIDesc: GetForgeMods() returns table (Lua), =C++ AStringMap? --- Server/Plugins/APIDump/APIDesc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua index 38c002a340..fc4203239a 100644 --- a/Server/Plugins/APIDump/APIDesc.lua +++ b/Server/Plugins/APIDump/APIDesc.lua @@ -1353,7 +1353,7 @@ end Returns = { { - Type = "AStringMap", + Type = "table", }, }, Notes = "Returns the Forge mods installed on the client.", From c01c9ff1b7cb14ac5fdce5f746f1aedeb099154c Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 29 Jul 2017 15:44:09 -0700 Subject: [PATCH 112/166] (Incomplete) Try to bridge GetForgeMods AStringMap -> Lua table --- src/Bindings/ManualBindings.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index fd49eab430..04fbe7c6fd 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2344,6 +2344,34 @@ static int tolua_cClientHandle_SendPluginMessage(lua_State * L) +static int tolua_cClientHandle_GetForgeMods(lua_State * L) +{ + cLuaState S(L); + if ( + !S.CheckParamUserType(1, "cClientHandle") || + !S.CheckParamEnd(2) + ) + { + return 0; + } + cClientHandle * Client = reinterpret_cast(tolua_tousertype(L, 1, nullptr)); + if (Client == nullptr) + { + LOGWARNING("ClientHandle is nil in cClientHandle:GetForgeMods()"); + S.LogStackTrace(); + return 0; + } + AStringMap Mods = Client->GetForgeMods(); + + S.Push(Client->GetForgeMods()); + return 0; +} + + + + + + static int tolua_cMojangAPI_AddPlayerNameToUUIDMapping(lua_State * L) { cLuaState S(L); @@ -3775,6 +3803,7 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_constant(tolua_S, "MAX_VIEW_DISTANCE", cClientHandle::MAX_VIEW_DISTANCE); tolua_constant(tolua_S, "MIN_VIEW_DISTANCE", cClientHandle::MIN_VIEW_DISTANCE); tolua_function(tolua_S, "SendPluginMessage", tolua_cClientHandle_SendPluginMessage); + tolua_function(tolua_S, "GetForgeMods", tolua_cClientHandle_GetForgeMods); tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cColor"); From 4aea032e1556c5dcb2534e1005464a9f7942e7c5 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 29 Jul 2017 21:02:52 -0700 Subject: [PATCH 113/166] Copy saved values by value for BeginForgeHandshake(), not ptr --- src/Protocol/ForgeHandshake.cpp | 6 +++--- src/Protocol/ForgeHandshake.h | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index ed665f78f7..d2f03a4d7c 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -90,8 +90,8 @@ void cForgeHandshake::BeginForgeHandshake(const AString & a_Name, const AString { ASSERT(m_IsForgeClient); - m_Name = &a_Name; - m_UUID = &a_UUID; + m_Name = a_Name; + m_UUID = a_UUID; m_Properties = &a_Properties; std::array Channels{{ "FML|HS", "FML", "FML|MP", "FML", "FORGE" }}; @@ -311,7 +311,7 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * m_Client->SendPluginMessage("FML|HS", Ack); // Now finish logging in - m_Client->FinishAuthenticate(*m_Name, *m_UUID, *m_Properties); + m_Client->FinishAuthenticate(m_Name, m_UUID, m_Properties); break; } } diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index 13ed7893f4..0a15f2aeea 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -6,6 +6,7 @@ #pragma once #include +#include "json/json.h" // fwd: namespace Json @@ -56,7 +57,7 @@ class cForgeHandshake cClientHandle * m_Client; /** Values saved from BeginForgeHandshake() for continuing the normal handshake after Forge completes. */ - const AString * m_Name; - const AString * m_UUID; - const Json::Value * m_Properties; + AString m_Name; + AString m_UUID; + Json::Value m_Properties; }; From d360dd3960285cd19a6ab268a4b3d579a65d3de9 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 29 Jul 2017 21:17:45 -0700 Subject: [PATCH 114/166] Fix m_Properties copy (curiously only clang on Travis caught this...) --- src/Protocol/ForgeHandshake.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index d2f03a4d7c..5cae206bc4 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -92,7 +92,7 @@ void cForgeHandshake::BeginForgeHandshake(const AString & a_Name, const AString m_Name = a_Name; m_UUID = a_UUID; - m_Properties = &a_Properties; + m_Properties = a_Properties; std::array Channels{{ "FML|HS", "FML", "FML|MP", "FML", "FORGE" }}; AString ChannelsString; From ee58733fd8466a6d533b344abeb47bc08ab52b15 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 29 Jul 2017 22:21:21 -0700 Subject: [PATCH 115/166] Restore cForgeMods until I can properly bridge AStringMap to Lua table --- Server/Plugins/APIDump/APIDesc.lua | 73 +++++++++++++++++++++- src/Bindings/AllToLua.pkg | 1 + src/Bindings/CMakeLists.txt | 1 + src/Bindings/ManualBindings.cpp | 29 --------- src/ClientHandle.h | 5 +- src/Protocol/CMakeLists.txt | 2 + src/Protocol/ForgeHandshake.cpp | 10 +-- src/Protocol/ForgeMods.cpp | 97 ++++++++++++++++++++++++++++++ src/Protocol/ForgeMods.h | 46 ++++++++++++++ src/Server.h | 1 + 10 files changed, 228 insertions(+), 37 deletions(-) create mode 100644 src/Protocol/ForgeMods.cpp create mode 100644 src/Protocol/ForgeMods.h diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua index fc4203239a..59897a9b2e 100644 --- a/Server/Plugins/APIDump/APIDesc.lua +++ b/Server/Plugins/APIDump/APIDesc.lua @@ -1353,7 +1353,7 @@ end Returns = { { - Type = "table", + Type = "cForgeMods", }, }, Notes = "Returns the Forge mods installed on the client.", @@ -4902,6 +4902,77 @@ cFile:DeleteFile("/usr/bin/virus.exe"); }, Inherits = "cEntity", }, + cForgeMods = + { + Desc = [[ + Data structure listing the Forge mods name and versions. + ]], + Functions = + { + GetModNameAt = + { + Params = + { + { + Name = "i", + Type = "number", + }, + }, + Returns = + { + { + Type = "string", + }, + }, + Notes = "Returns the name of the Forge mod at the given index.", + }, + GetModVersion = + { + Params = + { + { + Name = "name", + Type = "string", + }, + }, + Returns = + { + { + Type = "string", + }, + }, + Notes = "Returns the version of the mod name given.", + + }, + GetNumMods = + { + Returns = + { + { + Type = "number", + }, + }, + Notes = "Returns the number of Forge mods.", + }, + HasMod = + { + Params = + { + { + Name = "name", + Type = "string", + }, + }, + Returns = + { + { + Type = "boolean", + }, + }, + Notes = "Returns true if the mod with the given name is installed.", + }, + }, + }, cHangingEntity = { Functions = diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index a109913e25..1b435fc022 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -69,6 +69,7 @@ $cfile "../MapManager.h" $cfile "../Scoreboard.h" $cfile "../Statistics.h" $cfile "../Protocol/MojangAPI.h" +$cfile "../Protocol/ForgeMods.h" // Entities: $cfile "../Entities/Entity.h" diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt index da7c8bbe87..f40cd9e716 100644 --- a/src/Bindings/CMakeLists.txt +++ b/src/Bindings/CMakeLists.txt @@ -131,6 +131,7 @@ set(BINDING_DEPENDENCIES ../Mobs/MonsterTypes.h ../OSSupport/File.h ../Protocol/MojangAPI.h + ../Protocol/ForgeMods.h ../Root.h ../Scoreboard.h ../Server.h diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 04fbe7c6fd..fd49eab430 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2344,34 +2344,6 @@ static int tolua_cClientHandle_SendPluginMessage(lua_State * L) -static int tolua_cClientHandle_GetForgeMods(lua_State * L) -{ - cLuaState S(L); - if ( - !S.CheckParamUserType(1, "cClientHandle") || - !S.CheckParamEnd(2) - ) - { - return 0; - } - cClientHandle * Client = reinterpret_cast(tolua_tousertype(L, 1, nullptr)); - if (Client == nullptr) - { - LOGWARNING("ClientHandle is nil in cClientHandle:GetForgeMods()"); - S.LogStackTrace(); - return 0; - } - AStringMap Mods = Client->GetForgeMods(); - - S.Push(Client->GetForgeMods()); - return 0; -} - - - - - - static int tolua_cMojangAPI_AddPlayerNameToUUIDMapping(lua_State * L) { cLuaState S(L); @@ -3803,7 +3775,6 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_constant(tolua_S, "MAX_VIEW_DISTANCE", cClientHandle::MAX_VIEW_DISTANCE); tolua_constant(tolua_S, "MIN_VIEW_DISTANCE", cClientHandle::MIN_VIEW_DISTANCE); tolua_function(tolua_S, "SendPluginMessage", tolua_cClientHandle_SendPluginMessage); - tolua_function(tolua_S, "GetForgeMods", tolua_cClientHandle_GetForgeMods); tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cColor"); diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 38979532e1..93232a5be0 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -22,6 +22,7 @@ #include "ChunkSender.h" #include "EffectID.h" #include "Protocol/ForgeHandshake.h" +#include "Protocol/ForgeMods.h" #include @@ -266,7 +267,7 @@ class cClientHandle // tolua_export const AString & GetClientBrand(void) const { return m_ClientBrand; } /** Returns the Forge mods installed on the client. */ - const AStringMap & GetForgeMods(void) const { return m_ForgeMods ? *m_ForgeMods : *new AStringMap(); } // TODO: fix memory leak + const cForgeMods & GetForgeMods(void) const { return m_ForgeMods ? *m_ForgeMods : cForgeMods::Unmodded(); } /** Returns true if the client is modded with Forge. */ bool IsForgeClient(void) const { return m_ForgeHandshake.m_IsForgeClient; } @@ -412,7 +413,7 @@ class cClientHandle // tolua_export cForgeHandshake m_ForgeHandshake; /** Forge mods and versions installed on this client, if any. */ - std::unique_ptr m_ForgeMods; + std::unique_ptr m_ForgeMods; /** The actual view distance used, the minimum of client's requested view distance and world's max view distance. */ int m_CurrentViewDistance; diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt index 00ffeb2553..c4ac0ba110 100644 --- a/src/Protocol/CMakeLists.txt +++ b/src/Protocol/CMakeLists.txt @@ -6,6 +6,7 @@ SET (SRCS Authenticator.cpp ChunkDataSerializer.cpp ForgeHandshake.cpp + ForgeMods.cpp MojangAPI.cpp Packetizer.cpp Protocol_1_8.cpp @@ -20,6 +21,7 @@ SET (HDRS Authenticator.h ChunkDataSerializer.h ForgeHandshake.h + ForgeMods.h MojangAPI.h Packetizer.h Protocol.h diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 5cae206bc4..1f9b497bee 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -214,7 +214,7 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat m_Client->m_ForgeMods.reset(); } - m_Client->m_ForgeMods = cpp14::make_unique(ClientMods); + m_Client->m_ForgeMods = cpp14::make_unique(ClientMods); // Let the plugins know about this event, they may refuse the player: if (cRoot::Get()->GetPluginManager()->CallHookLoginForge(*a_Client)) @@ -232,14 +232,14 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat // Send server-side Forge mods registered by plugins auto &ServerMods = m_Client->GetForgeMods(); - size_t ModCount = ServerMods.size(); + size_t ModCount = ServerMods.GetNumMods(); Buf.WriteBEInt8(Discriminator_ModList); Buf.WriteVarInt32(static_cast(ModCount)); - for (auto & item: ServerMods) + for (size_t i = 0; i < ModCount; ++i) { - const AString & name = item.first; - const AString & version = item.second; + const AString & name = ServerMods.GetModNameAt(i); + const AString & version = ServerMods.GetModVersion(name); Buf.WriteVarUTF8String(name); Buf.WriteVarUTF8String(version); } diff --git a/src/Protocol/ForgeMods.cpp b/src/Protocol/ForgeMods.cpp new file mode 100644 index 0000000000..e1d8e42b85 --- /dev/null +++ b/src/Protocol/ForgeMods.cpp @@ -0,0 +1,97 @@ + +// ForgeMods.cpp + +// Data structure listing the Forge mods name and versions + +#include "Globals.h" +#include "ForgeMods.h" + +cForgeMods::cForgeMods() +{ +} + + + + + +cForgeMods::cForgeMods(const AStringMap & a):m_Mods(a) +{ + for (const auto & item: a) + { + m_ModNames.push_back(item.first); + } +} + + + + +const cForgeMods & cForgeMods::Unmodded(void) +{ + static cForgeMods Unmodded; + + return Unmodded; +} + + + + +size_t cForgeMods::GetNumMods(void) const +{ + return m_Mods.size(); +} + + + +bool cForgeMods::HasMod(const AString & name) const +{ + return m_Mods.find(name) != m_Mods.end(); +} + + + + +const AString & cForgeMods::GetModVersion(const AString & name) const +{ + return m_Mods.find(name)->second; +} + + + + +const AString & cForgeMods::GetModNameAt(size_t i) const +{ + return m_ModNames[i]; +} + + + + + +bool cForgeMods::Add(const AString & a_Name, const AString & a_Version) +{ + auto ret = m_Mods.insert({a_Name, a_Version}); + + if (!ret.second) + { + return false; + } + + m_ModNames.push_back(a_Name); + + return true; +} + + + + + +void cForgeMods::Remove(const AString & a_Name) +{ + auto it = std::find(m_ModNames.begin(), m_ModNames.end(), a_Name); + if (it != m_ModNames.end()) + { + m_ModNames.erase(it); + } + + m_Mods.erase(a_Name); +} diff --git a/src/Protocol/ForgeMods.h b/src/Protocol/ForgeMods.h new file mode 100644 index 0000000000..e8866b71d8 --- /dev/null +++ b/src/Protocol/ForgeMods.h @@ -0,0 +1,46 @@ + +// ForgeMods.h + +// Data structure listing the Forge mods name and versions. + +#pragma once + +#include + +// tolua_begin +class cForgeMods +{ +public: + // TODO: can tolua++ bridge AStringMap (etc.) as a Lua table? or non-fixedsize arrays? + + /** Returns the number of Forge mods. */ + size_t GetNumMods(void) const; + + /** Returns true if the mod with the given name is installed. */ + bool HasMod(const AString & name) const; + + /** Returns the version of the mod name given. */ + const AString & GetModVersion(const AString & name) const; + + /** Returns the name of the Forge mod at the given index. */ + const AString & GetModNameAt(size_t i) const; + + // tolua_end + + cForgeMods(); + cForgeMods(const AStringMap & a); + + static const cForgeMods & Unmodded(void); + + bool Add(const AString & a_Name, const AString & a_Version); + + void Remove(const AString & a_Name); + + AStringMap GetMods() { return m_Mods; } + + bool HasMods() { return m_Mods.size() != 0; } + +private: + AStringMap m_Mods; + AStringVector m_ModNames; +} ; // tolua_export diff --git a/src/Server.h b/src/Server.h index 3bb889c2b0..c9212e50b9 100644 --- a/src/Server.h +++ b/src/Server.h @@ -12,6 +12,7 @@ #include "RCONServer.h" #include "OSSupport/IsThread.h" #include "OSSupport/Network.h" +#include "Protocol/ForgeMods.h" #ifdef _MSC_VER #pragma warning(push) From ee630a2648c1daaab7ac64eee92aa62518a7032e Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 30 Jul 2017 11:07:22 -0700 Subject: [PATCH 116/166] Revert "Restore cForgeMods until I can properly bridge AStringMap to Lua table" This reverts commit ee58733fd8466a6d533b344abeb47bc08ab52b15. --- Server/Plugins/APIDump/APIDesc.lua | 73 +--------------------- src/Bindings/AllToLua.pkg | 1 - src/Bindings/CMakeLists.txt | 1 - src/Bindings/ManualBindings.cpp | 29 +++++++++ src/ClientHandle.h | 5 +- src/Protocol/CMakeLists.txt | 2 - src/Protocol/ForgeHandshake.cpp | 10 +-- src/Protocol/ForgeMods.cpp | 97 ------------------------------ src/Protocol/ForgeMods.h | 46 -------------- src/Server.h | 1 - 10 files changed, 37 insertions(+), 228 deletions(-) delete mode 100644 src/Protocol/ForgeMods.cpp delete mode 100644 src/Protocol/ForgeMods.h diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua index 59897a9b2e..fc4203239a 100644 --- a/Server/Plugins/APIDump/APIDesc.lua +++ b/Server/Plugins/APIDump/APIDesc.lua @@ -1353,7 +1353,7 @@ end Returns = { { - Type = "cForgeMods", + Type = "table", }, }, Notes = "Returns the Forge mods installed on the client.", @@ -4902,77 +4902,6 @@ cFile:DeleteFile("/usr/bin/virus.exe"); }, Inherits = "cEntity", }, - cForgeMods = - { - Desc = [[ - Data structure listing the Forge mods name and versions. - ]], - Functions = - { - GetModNameAt = - { - Params = - { - { - Name = "i", - Type = "number", - }, - }, - Returns = - { - { - Type = "string", - }, - }, - Notes = "Returns the name of the Forge mod at the given index.", - }, - GetModVersion = - { - Params = - { - { - Name = "name", - Type = "string", - }, - }, - Returns = - { - { - Type = "string", - }, - }, - Notes = "Returns the version of the mod name given.", - - }, - GetNumMods = - { - Returns = - { - { - Type = "number", - }, - }, - Notes = "Returns the number of Forge mods.", - }, - HasMod = - { - Params = - { - { - Name = "name", - Type = "string", - }, - }, - Returns = - { - { - Type = "boolean", - }, - }, - Notes = "Returns true if the mod with the given name is installed.", - }, - }, - }, cHangingEntity = { Functions = diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 1b435fc022..a109913e25 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -69,7 +69,6 @@ $cfile "../MapManager.h" $cfile "../Scoreboard.h" $cfile "../Statistics.h" $cfile "../Protocol/MojangAPI.h" -$cfile "../Protocol/ForgeMods.h" // Entities: $cfile "../Entities/Entity.h" diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt index f40cd9e716..da7c8bbe87 100644 --- a/src/Bindings/CMakeLists.txt +++ b/src/Bindings/CMakeLists.txt @@ -131,7 +131,6 @@ set(BINDING_DEPENDENCIES ../Mobs/MonsterTypes.h ../OSSupport/File.h ../Protocol/MojangAPI.h - ../Protocol/ForgeMods.h ../Root.h ../Scoreboard.h ../Server.h diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index fd49eab430..04fbe7c6fd 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2344,6 +2344,34 @@ static int tolua_cClientHandle_SendPluginMessage(lua_State * L) +static int tolua_cClientHandle_GetForgeMods(lua_State * L) +{ + cLuaState S(L); + if ( + !S.CheckParamUserType(1, "cClientHandle") || + !S.CheckParamEnd(2) + ) + { + return 0; + } + cClientHandle * Client = reinterpret_cast(tolua_tousertype(L, 1, nullptr)); + if (Client == nullptr) + { + LOGWARNING("ClientHandle is nil in cClientHandle:GetForgeMods()"); + S.LogStackTrace(); + return 0; + } + AStringMap Mods = Client->GetForgeMods(); + + S.Push(Client->GetForgeMods()); + return 0; +} + + + + + + static int tolua_cMojangAPI_AddPlayerNameToUUIDMapping(lua_State * L) { cLuaState S(L); @@ -3775,6 +3803,7 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_constant(tolua_S, "MAX_VIEW_DISTANCE", cClientHandle::MAX_VIEW_DISTANCE); tolua_constant(tolua_S, "MIN_VIEW_DISTANCE", cClientHandle::MIN_VIEW_DISTANCE); tolua_function(tolua_S, "SendPluginMessage", tolua_cClientHandle_SendPluginMessage); + tolua_function(tolua_S, "GetForgeMods", tolua_cClientHandle_GetForgeMods); tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cColor"); diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 93232a5be0..38979532e1 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -22,7 +22,6 @@ #include "ChunkSender.h" #include "EffectID.h" #include "Protocol/ForgeHandshake.h" -#include "Protocol/ForgeMods.h" #include @@ -267,7 +266,7 @@ class cClientHandle // tolua_export const AString & GetClientBrand(void) const { return m_ClientBrand; } /** Returns the Forge mods installed on the client. */ - const cForgeMods & GetForgeMods(void) const { return m_ForgeMods ? *m_ForgeMods : cForgeMods::Unmodded(); } + const AStringMap & GetForgeMods(void) const { return m_ForgeMods ? *m_ForgeMods : *new AStringMap(); } // TODO: fix memory leak /** Returns true if the client is modded with Forge. */ bool IsForgeClient(void) const { return m_ForgeHandshake.m_IsForgeClient; } @@ -413,7 +412,7 @@ class cClientHandle // tolua_export cForgeHandshake m_ForgeHandshake; /** Forge mods and versions installed on this client, if any. */ - std::unique_ptr m_ForgeMods; + std::unique_ptr m_ForgeMods; /** The actual view distance used, the minimum of client's requested view distance and world's max view distance. */ int m_CurrentViewDistance; diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt index c4ac0ba110..00ffeb2553 100644 --- a/src/Protocol/CMakeLists.txt +++ b/src/Protocol/CMakeLists.txt @@ -6,7 +6,6 @@ SET (SRCS Authenticator.cpp ChunkDataSerializer.cpp ForgeHandshake.cpp - ForgeMods.cpp MojangAPI.cpp Packetizer.cpp Protocol_1_8.cpp @@ -21,7 +20,6 @@ SET (HDRS Authenticator.h ChunkDataSerializer.h ForgeHandshake.h - ForgeMods.h MojangAPI.h Packetizer.h Protocol.h diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 1f9b497bee..5cae206bc4 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -214,7 +214,7 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat m_Client->m_ForgeMods.reset(); } - m_Client->m_ForgeMods = cpp14::make_unique(ClientMods); + m_Client->m_ForgeMods = cpp14::make_unique(ClientMods); // Let the plugins know about this event, they may refuse the player: if (cRoot::Get()->GetPluginManager()->CallHookLoginForge(*a_Client)) @@ -232,14 +232,14 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat // Send server-side Forge mods registered by plugins auto &ServerMods = m_Client->GetForgeMods(); - size_t ModCount = ServerMods.GetNumMods(); + size_t ModCount = ServerMods.size(); Buf.WriteBEInt8(Discriminator_ModList); Buf.WriteVarInt32(static_cast(ModCount)); - for (size_t i = 0; i < ModCount; ++i) + for (auto & item: ServerMods) { - const AString & name = ServerMods.GetModNameAt(i); - const AString & version = ServerMods.GetModVersion(name); + const AString & name = item.first; + const AString & version = item.second; Buf.WriteVarUTF8String(name); Buf.WriteVarUTF8String(version); } diff --git a/src/Protocol/ForgeMods.cpp b/src/Protocol/ForgeMods.cpp deleted file mode 100644 index e1d8e42b85..0000000000 --- a/src/Protocol/ForgeMods.cpp +++ /dev/null @@ -1,97 +0,0 @@ - -// ForgeMods.cpp - -// Data structure listing the Forge mods name and versions - -#include "Globals.h" -#include "ForgeMods.h" - -cForgeMods::cForgeMods() -{ -} - - - - - -cForgeMods::cForgeMods(const AStringMap & a):m_Mods(a) -{ - for (const auto & item: a) - { - m_ModNames.push_back(item.first); - } -} - - - - -const cForgeMods & cForgeMods::Unmodded(void) -{ - static cForgeMods Unmodded; - - return Unmodded; -} - - - - -size_t cForgeMods::GetNumMods(void) const -{ - return m_Mods.size(); -} - - - -bool cForgeMods::HasMod(const AString & name) const -{ - return m_Mods.find(name) != m_Mods.end(); -} - - - - -const AString & cForgeMods::GetModVersion(const AString & name) const -{ - return m_Mods.find(name)->second; -} - - - - -const AString & cForgeMods::GetModNameAt(size_t i) const -{ - return m_ModNames[i]; -} - - - - - -bool cForgeMods::Add(const AString & a_Name, const AString & a_Version) -{ - auto ret = m_Mods.insert({a_Name, a_Version}); - - if (!ret.second) - { - return false; - } - - m_ModNames.push_back(a_Name); - - return true; -} - - - - - -void cForgeMods::Remove(const AString & a_Name) -{ - auto it = std::find(m_ModNames.begin(), m_ModNames.end(), a_Name); - if (it != m_ModNames.end()) - { - m_ModNames.erase(it); - } - - m_Mods.erase(a_Name); -} diff --git a/src/Protocol/ForgeMods.h b/src/Protocol/ForgeMods.h deleted file mode 100644 index e8866b71d8..0000000000 --- a/src/Protocol/ForgeMods.h +++ /dev/null @@ -1,46 +0,0 @@ - -// ForgeMods.h - -// Data structure listing the Forge mods name and versions. - -#pragma once - -#include - -// tolua_begin -class cForgeMods -{ -public: - // TODO: can tolua++ bridge AStringMap (etc.) as a Lua table? or non-fixedsize arrays? - - /** Returns the number of Forge mods. */ - size_t GetNumMods(void) const; - - /** Returns true if the mod with the given name is installed. */ - bool HasMod(const AString & name) const; - - /** Returns the version of the mod name given. */ - const AString & GetModVersion(const AString & name) const; - - /** Returns the name of the Forge mod at the given index. */ - const AString & GetModNameAt(size_t i) const; - - // tolua_end - - cForgeMods(); - cForgeMods(const AStringMap & a); - - static const cForgeMods & Unmodded(void); - - bool Add(const AString & a_Name, const AString & a_Version); - - void Remove(const AString & a_Name); - - AStringMap GetMods() { return m_Mods; } - - bool HasMods() { return m_Mods.size() != 0; } - -private: - AStringMap m_Mods; - AStringVector m_ModNames; -} ; // tolua_export diff --git a/src/Server.h b/src/Server.h index c9212e50b9..3bb889c2b0 100644 --- a/src/Server.h +++ b/src/Server.h @@ -12,7 +12,6 @@ #include "RCONServer.h" #include "OSSupport/IsThread.h" #include "OSSupport/Network.h" -#include "Protocol/ForgeMods.h" #ifdef _MSC_VER #pragma warning(push) From cc8ca3204af753ce4b2461e6eb358398e849d35a Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 30 Jul 2017 11:11:20 -0700 Subject: [PATCH 117/166] Fix tolua_cClientHandle_GetForgeMods() return value 1 --- src/Bindings/ManualBindings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 04fbe7c6fd..63da2b48fe 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2364,7 +2364,7 @@ static int tolua_cClientHandle_GetForgeMods(lua_State * L) AStringMap Mods = Client->GetForgeMods(); S.Push(Client->GetForgeMods()); - return 0; + return 1; } From 8e8db6c0b5b9df63693fa11ec624546e38849dc7 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 30 Jul 2017 11:12:54 -0700 Subject: [PATCH 118/166] LOGD when Forge client connected --- src/Protocol/Protocol_1_9.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index 4c573d1da4..5a61ea5aa7 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -131,7 +131,7 @@ cProtocol_1_9_0::cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_Ser if (Params[1] == "FML") { - LOG("Forge client connected!"); + LOGD("Forge client connected!"); m_Client->SetIsForgeClient(); } else if (Params.size() == 4) From 8fffcb36ca8e7424228b5f763002859a0cc7bccc Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 30 Jul 2017 11:13:48 -0700 Subject: [PATCH 119/166] Fix tolua_cServer_RegisterForgeMod, it doesn't return a value --- src/Bindings/ManualBindings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 63da2b48fe..027602bd33 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -3187,7 +3187,7 @@ static int tolua_cServer_RegisterForgeMod(lua_State * a_LuaState) return 0; } - return 1; + return 0; } From 0bd28f37828a48c10cf7205f03b05907a37a8b60 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 30 Jul 2017 11:14:31 -0700 Subject: [PATCH 120/166] static const registration channels array --- src/Protocol/ForgeHandshake.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 5cae206bc4..69015ab596 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -94,7 +94,7 @@ void cForgeHandshake::BeginForgeHandshake(const AString & a_Name, const AString m_UUID = a_UUID; m_Properties = a_Properties; - std::array Channels{{ "FML|HS", "FML", "FML|MP", "FML", "FORGE" }}; + static const std::array Channels{{ "FML|HS", "FML", "FML|MP", "FML", "FORGE" }}; AString ChannelsString; for (auto & Channel: Channels) { From 60a5a477e89cd16ce9b28fc179af4b2c7368b562 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 30 Jul 2017 11:41:19 -0700 Subject: [PATCH 121/166] Fix comment, PostAuthenticate was renamed FinishAuthenticate --- src/ClientHandle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 38979532e1..aefcf769fb 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -403,7 +403,7 @@ class cClientHandle // tolua_export friend class cServer; // Needs access to SetSelf() - friend class cForgeHandshake; // Needs access to PostAuthenticate() + friend class cForgeHandshake; // Needs access to FinishAuthenticate() /** The type used for storing the names of registered plugin channels. */ typedef std::set cChannels; From 33bdcea2c6bc0079a44e805ceb768a89ea4c8479 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 30 Jul 2017 11:42:59 -0700 Subject: [PATCH 122/166] LOGD commonplace ForgeHandshake messages --- src/Protocol/ForgeHandshake.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 69015ab596..d4a1d97a82 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -64,7 +64,7 @@ void cForgeHandshake::AugmentServerListPing(Json::Value & a_ResponseValue) return; } - LOG("Received server ping from version: %d", ProtocolVersion); + LOGD("Received server ping from version: %d", ProtocolVersion); Json::Value Modinfo; Modinfo["type"] = "FML"; @@ -292,7 +292,7 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * case ClientPhase_WAITINGSERVERCOMPLETE: { - LOG("Client finished receiving registry data; acknowledging"); + LOGD("Client finished receiving registry data; acknowledging"); AString Ack; Ack.push_back(Discriminator_HandshakeAck); @@ -303,7 +303,7 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * case ClientPhase_PENDINGCOMPLETE: { - LOG("Client is pending completion; sending complete ack"); + LOGD("Client is pending completion; sending complete ack"); AString Ack; Ack.push_back(Discriminator_HandshakeAck); From bd5f1c90a648d4bb1b06d1cb6e9a6d20e3f8fa93 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 30 Jul 2017 15:25:05 -0700 Subject: [PATCH 123/166] Pass mods AStringMap param to Forge login hook --- src/Bindings/Plugin.h | 2 +- src/Bindings/PluginLua.cpp | 4 ++-- src/Bindings/PluginLua.h | 2 +- src/Bindings/PluginManager.cpp | 4 ++-- src/Bindings/PluginManager.h | 2 +- src/Protocol/ForgeHandshake.cpp | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index fe4616fe54..75acf4a1e4 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -69,7 +69,7 @@ class cPlugin virtual bool OnKilled (cEntity & a_Victim, TakeDamageInfo & a_TDI, AString & a_DeathMessage) = 0; virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer, TakeDamageInfo & a_TDI) = 0; virtual bool OnLogin (cClientHandle & a_Client, UInt32 a_ProtocolVersion, const AString & a_Username) = 0; - virtual bool OnLoginForge (cClientHandle & a_Client) = 0; + virtual bool OnLoginForge (cClientHandle & a_Client, const AStringMap & a_Mods) = 0; virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) = 0; virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 5951192b0e..c89f31f4cc 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -550,9 +550,9 @@ bool cPluginLua::OnLogin(cClientHandle & a_Client, UInt32 a_ProtocolVersion, con -bool cPluginLua::OnLoginForge(cClientHandle & a_Client) +bool cPluginLua::OnLoginForge(cClientHandle & a_Client, const AStringMap & a_Mods) { - return CallSimpleHooks(cPluginManager::HOOK_LOGIN_FORGE, &a_Client); + return CallSimpleHooks(cPluginManager::HOOK_LOGIN_FORGE, &a_Client, a_Mods); } diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index b1aa33dcfa..5cfeda6ead 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -96,7 +96,7 @@ class cPluginLua : virtual bool OnKilled (cEntity & a_Victim, TakeDamageInfo & a_TDI, AString & a_DeathMessage) override; virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer, TakeDamageInfo & a_TDI) override; virtual bool OnLogin (cClientHandle & a_Client, UInt32 a_ProtocolVersion, const AString & a_Username) override; - virtual bool OnLoginForge (cClientHandle & a_Client) override; + virtual bool OnLoginForge (cClientHandle & a_Client, const AStringMap & a_Mods) override; virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) override; virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index 37259ff4bc..c100587370 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -789,14 +789,14 @@ bool cPluginManager::CallHookLogin(cClientHandle & a_Client, UInt32 a_ProtocolVe -bool cPluginManager::CallHookLoginForge(cClientHandle & a_Client) +bool cPluginManager::CallHookLoginForge(cClientHandle & a_Client, AStringMap & a_Mods) { FIND_HOOK(HOOK_LOGIN_FORGE) VERIFY_HOOK; for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) { - if ((*itr)->OnLoginForge(a_Client)) + if ((*itr)->OnLoginForge(a_Client, a_Mods)) { return true; } diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index 04e7840b7d..3fe24f24b4 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -247,7 +247,7 @@ class cPluginManager bool CallHookKilled (cEntity & a_Victim, TakeDamageInfo & a_TDI, AString & a_DeathMessage); bool CallHookKilling (cEntity & a_Victim, cEntity * a_Killer, TakeDamageInfo & a_TDI); bool CallHookLogin (cClientHandle & a_Client, UInt32 a_ProtocolVersion, const AString & a_Username); - bool CallHookLoginForge (cClientHandle & a_Client); + bool CallHookLoginForge (cClientHandle & a_Client, AStringMap & a_Mods); bool CallHookPlayerAnimation (cPlayer & a_Player, int a_Animation); bool CallHookPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); bool CallHookPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index d4a1d97a82..75d0aaefd0 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -217,7 +217,7 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat m_Client->m_ForgeMods = cpp14::make_unique(ClientMods); // Let the plugins know about this event, they may refuse the player: - if (cRoot::Get()->GetPluginManager()->CallHookLoginForge(*a_Client)) + if (cRoot::Get()->GetPluginManager()->CallHookLoginForge(*a_Client, ClientMods)) { LOG("Modded client refused by plugin"); SetError(); From 67b25708f48c38dd03e539f32f570c7f59376d9a Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 30 Jul 2017 15:30:54 -0700 Subject: [PATCH 124/166] Use namespaces for discriminator and phase constants --- src/Protocol/ForgeHandshake.cpp | 62 ++++++++++++++++----------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 75d0aaefd0..396aee40e1 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -13,31 +13,31 @@ /** Discriminator byte values prefixing the FML|HS packets to determine their type. */ -enum Discriminator: signed char +namespace Discriminator { - Discriminator_ServerHello = 0, - Discriminator_ClientHello = 1, - Discriminator_ModList = 2, - Discriminator_RegistryData = 3, - Discriminator_HandshakeReset = -2, - Discriminator_HandshakeAck = -1, -}; + static const Int8 ServerHello = 0; + static const Int8 ClientHello = 1; + static const Int8 ModList = 2; + static const Int8 RegistryData = 3; + // static const Int8 HandshakeReset = -2; + static const Int8 HandshakeAck = -1; +} /** Client handshake state phases. */ -enum +namespace ClientPhase { - ClientPhase_WAITINGSERVERDATA = 2, - ClientPhase_WAITINGSERVERCOMPLETE = 3, - ClientPhase_PENDINGCOMPLETE = 4, - ClientPhase_COMPLETE = 5, -}; + static const Int8 WAITINGSERVERDATA = 2; + static const Int8 WAITINGSERVERCOMPLETE = 3; + static const Int8 PENDINGCOMPLETE = 4; + // static const Int8 COMPLETE = 5; +} /** Server handshake state phases. */ -enum +namespace ServerPhase { - ServerPhase_WAITINGCACK = 2, - ServerPhase_COMPLETE = 3, -}; + static const Int8 WAITINGCACK = 2; + static const Int8 COMPLETE = 3; +} @@ -114,7 +114,7 @@ void cForgeHandshake::SendServerHello() { AString Message; // Discriminator | Byte | Always 0 for ServerHello - Message.push_back(Discriminator_ServerHello); + Message.push_back(Discriminator::ServerHello); // FML protocol Version | Byte | Determined from NetworkRegistery. Currently 2. Message.push_back('\2'); // Dimension TODO @@ -234,7 +234,7 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat size_t ModCount = ServerMods.size(); - Buf.WriteBEInt8(Discriminator_ModList); + Buf.WriteBEInt8(Discriminator::ModList); Buf.WriteVarInt32(static_cast(ModCount)); for (auto & item: ServerMods) { @@ -266,10 +266,10 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * switch (Phase) { - case ClientPhase_WAITINGSERVERDATA: + case ClientPhase::WAITINGSERVERDATA: { cByteBuffer Buf(1024); - Buf.WriteBEInt8(Discriminator_RegistryData); + Buf.WriteBEInt8(Discriminator::RegistryData); // TODO: send real registry data bool HasMore = false; @@ -290,24 +290,24 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * break; } - case ClientPhase_WAITINGSERVERCOMPLETE: + case ClientPhase::WAITINGSERVERCOMPLETE: { LOGD("Client finished receiving registry data; acknowledging"); AString Ack; - Ack.push_back(Discriminator_HandshakeAck); - Ack.push_back(ServerPhase_WAITINGCACK); + Ack.push_back(Discriminator::HandshakeAck); + Ack.push_back(ServerPhase::WAITINGCACK); m_Client->SendPluginMessage("FML|HS", Ack); break; } - case ClientPhase_PENDINGCOMPLETE: + case ClientPhase::PENDINGCOMPLETE: { LOGD("Client is pending completion; sending complete ack"); AString Ack; - Ack.push_back(Discriminator_HandshakeAck); - Ack.push_back(ServerPhase_COMPLETE); + Ack.push_back(Discriminator::HandshakeAck); + Ack.push_back(ServerPhase::COMPLETE); m_Client->SendPluginMessage("FML|HS", Ack); // Now finish logging in @@ -340,15 +340,15 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data switch (Discriminator) { - case Discriminator_ClientHello: + case Discriminator::ClientHello: HandleClientHello(a_Client, a_Data, a_Size); break; - case Discriminator_ModList: + case Discriminator::ModList: HandleModList(a_Client, a_Data, a_Size); break; - case Discriminator_HandshakeAck: + case Discriminator::HandshakeAck: HandleHandshakeAck(a_Client, a_Data, a_Size); break; From 87435ce723c27ee79d8f508d5c04636d1ed1d034 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 30 Jul 2017 19:51:28 -0700 Subject: [PATCH 125/166] Change cClientHandle m_ForgeMods to value, remove pointer --- Server/Plugins/Core | 2 +- src/ClientHandle.cpp | 3 --- src/ClientHandle.h | 6 +++--- src/Protocol/ForgeHandshake.cpp | 7 +------ 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Server/Plugins/Core b/Server/Plugins/Core index 68430458a3..3e8b70dcb1 160000 --- a/Server/Plugins/Core +++ b/Server/Plugins/Core @@ -1 +1 @@ -Subproject commit 68430458a3ea695cac85bc82136941bc83253e1e +Subproject commit 3e8b70dcb11c7d5f8c6f68494b108b14c9fca141 diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 5be7ad0552..2e3a3ef98e 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -66,7 +66,6 @@ float cClientHandle::FASTBREAK_PERCENTAGE; cClientHandle::cClientHandle(const AString & a_IPString, int a_ViewDistance) : m_LastSentDimension(dimNotSet), m_ForgeHandshake(this), - m_ForgeMods(nullptr), m_CurrentViewDistance(a_ViewDistance), m_RequestedViewDistance(a_ViewDistance), m_IPString(a_IPString), @@ -140,8 +139,6 @@ cClientHandle::~cClientHandle() m_Player = nullptr; } - m_ForgeMods.reset(); - if (!m_HasSentDC) { SendDisconnect("Server shut down? Kthnxbai"); diff --git a/src/ClientHandle.h b/src/ClientHandle.h index aefcf769fb..a26d28a0a6 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -266,7 +266,7 @@ class cClientHandle // tolua_export const AString & GetClientBrand(void) const { return m_ClientBrand; } /** Returns the Forge mods installed on the client. */ - const AStringMap & GetForgeMods(void) const { return m_ForgeMods ? *m_ForgeMods : *new AStringMap(); } // TODO: fix memory leak + const AStringMap & GetForgeMods(void) const { return m_ForgeMods; } /** Returns true if the client is modded with Forge. */ bool IsForgeClient(void) const { return m_ForgeHandshake.m_IsForgeClient; } @@ -411,8 +411,8 @@ class cClientHandle // tolua_export /** Forge handshake state machine. */ cForgeHandshake m_ForgeHandshake; - /** Forge mods and versions installed on this client, if any. */ - std::unique_ptr m_ForgeMods; + /** Forge mods and versions installed on this client. */ + AStringMap m_ForgeMods; /** The actual view distance used, the minimum of client's requested view distance and world's max view distance. */ int m_CurrentViewDistance; diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 396aee40e1..b1e7a35cb9 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -209,12 +209,7 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat LOG("Client connected with " SIZE_T_FMT " mods: %s", ClientMods.size(), ClientModsString.c_str()); - if (m_Client->m_ForgeMods != nullptr) - { - m_Client->m_ForgeMods.reset(); - } - - m_Client->m_ForgeMods = cpp14::make_unique(ClientMods); + m_Client->m_ForgeMods = ClientMods; // Let the plugins know about this event, they may refuse the player: if (cRoot::Get()->GetPluginManager()->CallHookLoginForge(*a_Client, ClientMods)) From a51b6066806687a26085dd3b8563ba71e348ac15 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 31 Jul 2017 21:40:13 -0700 Subject: [PATCH 126/166] Update plugin Core from master branch --- Server/Plugins/Core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/Plugins/Core b/Server/Plugins/Core index 3e8b70dcb1..68430458a3 160000 --- a/Server/Plugins/Core +++ b/Server/Plugins/Core @@ -1 +1 @@ -Subproject commit 3e8b70dcb11c7d5f8c6f68494b108b14c9fca141 +Subproject commit 68430458a3ea695cac85bc82136941bc83253e1e From 4d25690dcad760440f8ed600b64b861461f83580 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 1 Aug 2017 09:13:17 -0700 Subject: [PATCH 127/166] Use CheckParamSelf() in manual bindings, remove now-unnecessary null check --- src/Bindings/ManualBindings.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 027602bd33..567cccb762 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2348,19 +2348,14 @@ static int tolua_cClientHandle_GetForgeMods(lua_State * L) { cLuaState S(L); if ( - !S.CheckParamUserType(1, "cClientHandle") || + !S.CheckParamSelf("cClientHandle") || !S.CheckParamEnd(2) ) { return 0; } cClientHandle * Client = reinterpret_cast(tolua_tousertype(L, 1, nullptr)); - if (Client == nullptr) - { - LOGWARNING("ClientHandle is nil in cClientHandle:GetForgeMods()"); - S.LogStackTrace(); - return 0; - } + AStringMap Mods = Client->GetForgeMods(); S.Push(Client->GetForgeMods()); @@ -3167,7 +3162,7 @@ static int tolua_cServer_RegisterForgeMod(lua_State * a_LuaState) { cLuaState L(a_LuaState); if ( - !L.CheckParamUserType(1, "cServer") || + !L.CheckParamSelf("cServer") || !L.CheckParamString(2, 3) || !L.CheckParamNumber(4) || !L.CheckParamEnd(5) From 9884d279b8ad05346fcc8d09d9291a1612332fa4 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 1 Aug 2017 09:14:35 -0700 Subject: [PATCH 128/166] Use GetStackValue() instead of reinterpret_cast(tolua_tousertype.. --- src/Bindings/ManualBindings.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 567cccb762..cc4de429ad 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2354,7 +2354,8 @@ static int tolua_cClientHandle_GetForgeMods(lua_State * L) { return 0; } - cClientHandle * Client = reinterpret_cast(tolua_tousertype(L, 1, nullptr)); + cClientHandle * Client; + S.GetStackValue(1, Client); AStringMap Mods = Client->GetForgeMods(); From ea7f42138cbdae51b76137791bc48debc9cb5d5e Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 1 Aug 2017 09:15:28 -0700 Subject: [PATCH 129/166] Alpha-sort manual bindings cClientHandle and add blank line to separate from constants --- src/Bindings/ManualBindings.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index cc4de429ad..db4e16946e 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -3798,8 +3798,9 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_beginmodule(tolua_S, "cClientHandle"); tolua_constant(tolua_S, "MAX_VIEW_DISTANCE", cClientHandle::MAX_VIEW_DISTANCE); tolua_constant(tolua_S, "MIN_VIEW_DISTANCE", cClientHandle::MIN_VIEW_DISTANCE); - tolua_function(tolua_S, "SendPluginMessage", tolua_cClientHandle_SendPluginMessage); + tolua_function(tolua_S, "GetForgeMods", tolua_cClientHandle_GetForgeMods); + tolua_function(tolua_S, "SendPluginMessage", tolua_cClientHandle_SendPluginMessage); tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cColor"); From 1bf7c3d14eef34173cf8983f423bc80c0a63f91f Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 1 Aug 2017 09:16:11 -0700 Subject: [PATCH 130/166] Spaces around i = in ModList parse debugging message --- src/Protocol/ForgeHandshake.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index b1e7a35cb9..03a8687ee6 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -154,12 +154,12 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) AString Name, Version; if (!Buf.ReadVarUTF8String(Name)) { - LOGD("ParseModList failed to read mod name at i=" SIZE_T_FMT, i); + LOGD("ParseModList failed to read mod name at i = " SIZE_T_FMT, i); break; } if (!Buf.ReadVarUTF8String(Version)) { - LOGD("ParseModList failed to read mod version at i=" SIZE_T_FMT, i); + LOGD("ParseModList failed to read mod version at i = " SIZE_T_FMT, i); break; } Mods.insert({Name, Version}); From c45d6a7f3376d44fc6547974e7c23f8ab14a0625 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 1 Aug 2017 09:17:46 -0700 Subject: [PATCH 131/166] Fix ClientHello error message, unexpected length not only short --- src/Protocol/ForgeHandshake.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 03a8687ee6..15b43022d3 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -185,7 +185,7 @@ void cForgeHandshake::HandleClientHello(cClientHandle * a_Client, const char * a } else { - LOG("Unexpectedly short ClientHello received"); + LOG("Received unexpected length of ClientHello: " SIZE_T_FMT, a_Size); SetError(); } } From d7ccda15b95020e5c7b4157ab948682b338d8e9b Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 1 Aug 2017 09:18:10 -0700 Subject: [PATCH 132/166] Space after & in auto & --- src/Protocol/ForgeHandshake.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 15b43022d3..dff8d6021f 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -225,7 +225,7 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat cByteBuffer Buf(1024); // Send server-side Forge mods registered by plugins - auto &ServerMods = m_Client->GetForgeMods(); + auto & ServerMods = m_Client->GetForgeMods(); size_t ModCount = ServerMods.size(); From d5390be5c0620009910a0b5d4a4aa9b3debc56e6 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 1 Aug 2017 09:21:17 -0700 Subject: [PATCH 133/166] Fix finishing login in ClientPhase::COMPLETE ack, and catch unknown phases --- src/Protocol/ForgeHandshake.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index dff8d6021f..3866578778 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -29,7 +29,7 @@ namespace ClientPhase static const Int8 WAITINGSERVERDATA = 2; static const Int8 WAITINGSERVERCOMPLETE = 3; static const Int8 PENDINGCOMPLETE = 4; - // static const Int8 COMPLETE = 5; + static const Int8 COMPLETE = 5; } /** Server handshake state phases. */ @@ -305,10 +305,22 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * Ack.push_back(ServerPhase::COMPLETE); m_Client->SendPluginMessage("FML|HS", Ack); + break; + } + + case ClientPhase::COMPLETE: + { // Now finish logging in m_Client->FinishAuthenticate(m_Name, m_UUID, m_Properties); break; } + + default: + { + LOG("Received unknown phase in Forge handshake acknowledgement: %d", Phase); + SetError(); + break; + } } } From 1c5a48a3a6b3ab4db19e660a961ae83dad7fcc51 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 1 Aug 2017 09:22:10 -0700 Subject: [PATCH 134/166] Single-line cases in Discriminator switch --- src/Protocol/ForgeHandshake.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 3866578778..0b2941f77a 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -347,17 +347,9 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data switch (Discriminator) { - case Discriminator::ClientHello: - HandleClientHello(a_Client, a_Data, a_Size); - break; - - case Discriminator::ModList: - HandleModList(a_Client, a_Data, a_Size); - break; - - case Discriminator::HandshakeAck: - HandleHandshakeAck(a_Client, a_Data, a_Size); - break; + case Discriminator::ClientHello: HandleClientHello(a_Client, a_Data, a_Size); break; + case Discriminator::ModList: HandleModList(a_Client, a_Data, a_Size); break; + case Discriminator::HandshakeAck: HandleHandshakeAck(a_Client, a_Data, a_Size); break; default: { From 1a7f58777d4ed05f7213280f3416fdaa2920abdb Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 1 Aug 2017 20:58:01 -0700 Subject: [PATCH 135/166] Change to use 'auto' everywhere possible --- src/Bindings/ManualBindings.cpp | 2 +- src/Protocol/ForgeHandshake.cpp | 12 ++++++------ src/Server.cpp | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index db4e16946e..fbf276e47e 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2357,7 +2357,7 @@ static int tolua_cClientHandle_GetForgeMods(lua_State * L) cClientHandle * Client; S.GetStackValue(1, Client); - AStringMap Mods = Client->GetForgeMods(); + auto Mods = Client->GetForgeMods(); S.Push(Client->GetForgeMods()); return 1; diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 0b2941f77a..4277b5d403 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -56,8 +56,8 @@ cForgeHandshake::cForgeHandshake(cClientHandle *a_Client) : void cForgeHandshake::AugmentServerListPing(Json::Value & a_ResponseValue) { - UInt32 ProtocolVersion = m_Client->GetProtocolVersion(); - AStringMap & Mods = cRoot::Get()->GetServer()->GetRegisteredForgeMods(ProtocolVersion); + auto ProtocolVersion = m_Client->GetProtocolVersion(); + auto & Mods = cRoot::Get()->GetServer()->GetRegisteredForgeMods(ProtocolVersion); if (Mods.size() == 0) { @@ -197,7 +197,7 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat { LOGD("Received ModList"); - AStringMap ClientMods = ParseModList(a_Data + 1, a_Size - 1); + auto ClientMods = ParseModList(a_Data + 1, a_Size - 1); AString ClientModsString; for (auto & item: ClientMods) { @@ -227,7 +227,7 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat // Send server-side Forge mods registered by plugins auto & ServerMods = m_Client->GetForgeMods(); - size_t ModCount = ServerMods.size(); + auto ModCount = ServerMods.size(); Buf.WriteBEInt8(Discriminator::ModList); Buf.WriteVarInt32(static_cast(ModCount)); @@ -256,7 +256,7 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * return; } - int Phase = a_Data[1]; + auto Phase = a_Data[1]; LOGD("Received client HandshakeAck with phase=%d", Phase); switch (Phase) @@ -343,7 +343,7 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data return; } - int Discriminator = a_Data[0]; + auto Discriminator = a_Data[0]; switch (Discriminator) { diff --git a/src/Server.cpp b/src/Server.cpp index a676fb7eae..14ab12c0fc 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -239,7 +239,7 @@ bool cServer::InitServer(cSettingsRepositoryInterface & a_Settings, bool a_Shoul bool cServer::RegisterForgeMod(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber) { - AStringMap & Mods = GetRegisteredForgeMods(a_ProtocolVersionNumber); + auto & Mods = GetRegisteredForgeMods(a_ProtocolVersionNumber); return Mods.insert({a_ModName, a_ModVersion}).second; } @@ -250,7 +250,7 @@ bool cServer::RegisterForgeMod(AString & a_ModName, AString & a_ModVersion, UInt void cServer::UnregisterForgeMod(AString &a_ModName, UInt32 a_ProtocolVersionNumber) { - AStringMap & Mods = GetRegisteredForgeMods(a_ProtocolVersionNumber); + auto & Mods = GetRegisteredForgeMods(a_ProtocolVersionNumber); auto it = Mods.find(a_ModName); if (it != Mods.end()) From ef94a24908575d1a10150552194445bcdcac0002 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Wed, 2 Aug 2017 21:24:38 -0700 Subject: [PATCH 136/166] Change SetError() to variadic macro SET_HANDSHAKE_ERROR() --- src/Protocol/ForgeHandshake.cpp | 48 +++++++++++++++------------------ src/Protocol/ForgeHandshake.h | 3 --- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 4277b5d403..811eef9e09 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -53,6 +53,15 @@ cForgeHandshake::cForgeHandshake(cClientHandle *a_Client) : +#define SET_HANDSHAKE_ERROR(...) { \ + LOGD("Forge handshake error:"); \ + LOGD(__VA_ARGS__); \ + m_Errored = true; \ +} + + + + void cForgeHandshake::AugmentServerListPing(Json::Value & a_ResponseValue) { @@ -136,7 +145,7 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) if (a_Size < 4) { - LOGD("ParseModList invalid packet, missing length (size=" SIZE_T_FMT ")", a_Size); + SET_HANDSHAKE_ERROR("ParseModList invalid packet, missing length (size=" SIZE_T_FMT ")", a_Size); return Mods; } @@ -145,7 +154,7 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) UInt32 NumMods; if (!Buf.ReadVarInt32(NumMods)) { - LOGD("ParseModList failed to read mod count"); + SET_HANDSHAKE_ERROR("ParseModList failed to read mod count"); return Mods; } @@ -154,12 +163,12 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) AString Name, Version; if (!Buf.ReadVarUTF8String(Name)) { - LOGD("ParseModList failed to read mod name at i = " SIZE_T_FMT, i); + SET_HANDSHAKE_ERROR("ParseModList failed to read mod name at i = " SIZE_T_FMT, i); break; } if (!Buf.ReadVarUTF8String(Version)) { - LOGD("ParseModList failed to read mod version at i = " SIZE_T_FMT, i); + SET_HANDSHAKE_ERROR("ParseModList failed to read mod version at i = " SIZE_T_FMT, i); break; } Mods.insert({Name, Version}); @@ -179,14 +188,12 @@ void cForgeHandshake::HandleClientHello(cClientHandle * a_Client, const char * a LOGD("Received ClientHello with FML protocol version %d", FmlProtocolVersion); if (FmlProtocolVersion != 2) { - LOG("Unsupported FML client protocol version received in ClientHello: %d", FmlProtocolVersion); - SetError(); + SET_HANDSHAKE_ERROR("Unsupported FML client protocol version received in ClientHello: %d", FmlProtocolVersion); } } else { - LOG("Received unexpected length of ClientHello: " SIZE_T_FMT, a_Size); - SetError(); + SET_HANDSHAKE_ERROR("Received unexpected length of ClientHello: " SIZE_T_FMT, a_Size); } } @@ -214,8 +221,7 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat // Let the plugins know about this event, they may refuse the player: if (cRoot::Get()->GetPluginManager()->CallHookLoginForge(*a_Client, ClientMods)) { - LOG("Modded client refused by plugin"); - SetError(); + SET_HANDSHAKE_ERROR("Modded client refused by plugin"); return; } @@ -251,8 +257,7 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * { if (a_Size != 2) { - LOG("Unexpected HandshakeAck packet length: " SIZE_T_FMT "", a_Size); - SetError(); + SET_HANDSHAKE_ERROR("Unexpected HandshakeAck packet length: " SIZE_T_FMT "", a_Size); return; } @@ -317,8 +322,7 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * default: { - LOG("Received unknown phase in Forge handshake acknowledgement: %d", Phase); - SetError(); + SET_HANDSHAKE_ERROR("Received unknown phase in Forge handshake acknowledgement: %d", Phase); break; } } @@ -332,14 +336,14 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data { if (!m_IsForgeClient) { - LOG("Received unexpected Forge data from non-Forge client (" SIZE_T_FMT " bytes)", a_Size); + SET_HANDSHAKE_ERROR("Received unexpected Forge data from non-Forge client (" SIZE_T_FMT " bytes)", a_Size); return; } LOGD("Received Forge data: " SIZE_T_FMT " bytes: %s", a_Size, a_Data); if (a_Size <= 1) { - LOG("Received unexpectedly short Forge data (" SIZE_T_FMT " bytes)", a_Size); + SET_HANDSHAKE_ERROR("Received unexpectedly short Forge data (" SIZE_T_FMT " bytes)", a_Size); return; } @@ -353,18 +357,8 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data default: { - LOG("Unexpected Forge packet %d received", Discriminator); - SetError(); + SET_HANDSHAKE_ERROR("Unexpected Forge packet %d received", Discriminator); return; } } } - - - - - -void cForgeHandshake::SetError() -{ - m_Errored = true; -} diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index 0a15f2aeea..340da3a276 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -47,9 +47,6 @@ class cForgeHandshake /** Parse the client ModList packet of installed Forge mods and versions. */ AStringMap ParseModList(const char * a_Data, size_t a_Size); - /** Set the Forge handshake to an errored state. */ - void SetError(); - /** True if the Forge handshake is in an errored state. */ bool m_Errored; From 254b33974dafb62296dfccc7769916493b25f3bc Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Thu, 3 Aug 2017 18:12:46 -0700 Subject: [PATCH 137/166] Change to SetError(Printf()) removing variadic macro --- src/Protocol/ForgeHandshake.cpp | 33 +++++++++++++++++---------------- src/Protocol/ForgeHandshake.h | 2 ++ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 811eef9e09..e81bdaceff 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -53,10 +53,11 @@ cForgeHandshake::cForgeHandshake(cClientHandle *a_Client) : -#define SET_HANDSHAKE_ERROR(...) { \ - LOGD("Forge handshake error:"); \ - LOGD(__VA_ARGS__); \ - m_Errored = true; \ + +void cForgeHandshake::SetError(const AString & message) +{ + LOGD("Forge handshake error: %s", message.c_str()); + m_Errored = true; } @@ -145,7 +146,7 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) if (a_Size < 4) { - SET_HANDSHAKE_ERROR("ParseModList invalid packet, missing length (size=" SIZE_T_FMT ")", a_Size); + SetError(Printf("ParseModList invalid packet, missing length (size=" SIZE_T_FMT ")", a_Size)); return Mods; } @@ -154,7 +155,7 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) UInt32 NumMods; if (!Buf.ReadVarInt32(NumMods)) { - SET_HANDSHAKE_ERROR("ParseModList failed to read mod count"); + SetError("ParseModList failed to read mod count"); return Mods; } @@ -163,12 +164,12 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) AString Name, Version; if (!Buf.ReadVarUTF8String(Name)) { - SET_HANDSHAKE_ERROR("ParseModList failed to read mod name at i = " SIZE_T_FMT, i); + SetError(Printf("ParseModList failed to read mod name at i = " SIZE_T_FMT, i)); break; } if (!Buf.ReadVarUTF8String(Version)) { - SET_HANDSHAKE_ERROR("ParseModList failed to read mod version at i = " SIZE_T_FMT, i); + SetError(Printf("ParseModList failed to read mod version at i = " SIZE_T_FMT, i)); break; } Mods.insert({Name, Version}); @@ -188,12 +189,12 @@ void cForgeHandshake::HandleClientHello(cClientHandle * a_Client, const char * a LOGD("Received ClientHello with FML protocol version %d", FmlProtocolVersion); if (FmlProtocolVersion != 2) { - SET_HANDSHAKE_ERROR("Unsupported FML client protocol version received in ClientHello: %d", FmlProtocolVersion); + SetError(Printf("Unsupported FML client protocol version received in ClientHello: %d", FmlProtocolVersion)); } } else { - SET_HANDSHAKE_ERROR("Received unexpected length of ClientHello: " SIZE_T_FMT, a_Size); + SetError(Printf("Received unexpected length of ClientHello: " SIZE_T_FMT, a_Size)); } } @@ -221,7 +222,7 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat // Let the plugins know about this event, they may refuse the player: if (cRoot::Get()->GetPluginManager()->CallHookLoginForge(*a_Client, ClientMods)) { - SET_HANDSHAKE_ERROR("Modded client refused by plugin"); + SetError("Modded client refused by plugin"); return; } @@ -257,7 +258,7 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * { if (a_Size != 2) { - SET_HANDSHAKE_ERROR("Unexpected HandshakeAck packet length: " SIZE_T_FMT "", a_Size); + SetError(Printf("Unexpected HandshakeAck packet length: " SIZE_T_FMT "", a_Size)); return; } @@ -322,7 +323,7 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * default: { - SET_HANDSHAKE_ERROR("Received unknown phase in Forge handshake acknowledgement: %d", Phase); + SetError(Printf("Received unknown phase in Forge handshake acknowledgement: %d", Phase)); break; } } @@ -336,14 +337,14 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data { if (!m_IsForgeClient) { - SET_HANDSHAKE_ERROR("Received unexpected Forge data from non-Forge client (" SIZE_T_FMT " bytes)", a_Size); + SetError(Printf("Received unexpected Forge data from non-Forge client (" SIZE_T_FMT " bytes)", a_Size)); return; } LOGD("Received Forge data: " SIZE_T_FMT " bytes: %s", a_Size, a_Data); if (a_Size <= 1) { - SET_HANDSHAKE_ERROR("Received unexpectedly short Forge data (" SIZE_T_FMT " bytes)", a_Size); + SetError(Printf("Received unexpectedly short Forge data (" SIZE_T_FMT " bytes)", a_Size)); return; } @@ -357,7 +358,7 @@ void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data default: { - SET_HANDSHAKE_ERROR("Unexpected Forge packet %d received", Discriminator); + SetError(Printf("Unexpected Forge packet %d received", Discriminator)); return; } } diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index 340da3a276..fe5a2987d7 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -44,6 +44,8 @@ class cForgeHandshake void HandleModList(cClientHandle * a_Client, const char * a_Data, size_t a_Size); void HandleHandshakeAck(cClientHandle * a_Client, const char * a_Data, size_t a_Size); + void SetError(const AString & message); + /** Parse the client ModList packet of installed Forge mods and versions. */ AStringMap ParseModList(const char * a_Data, size_t a_Size); From de1cf388d1e38acee94edcf543fcadb9f06b7db4 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 4 Aug 2017 21:19:28 -0700 Subject: [PATCH 138/166] Fix checking errored state and add SetError() documentation --- src/Protocol/ForgeHandshake.cpp | 7 ++++++- src/Protocol/ForgeHandshake.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index e81bdaceff..860a0c1ff8 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -335,12 +335,17 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data, size_t a_Size) { + LOGD("Received Forge data: " SIZE_T_FMT " bytes: %s", a_Size, a_Data); if (!m_IsForgeClient) { SetError(Printf("Received unexpected Forge data from non-Forge client (" SIZE_T_FMT " bytes)", a_Size)); return; } - LOGD("Received Forge data: " SIZE_T_FMT " bytes: %s", a_Size, a_Data); + if (m_Errored) + { + LOGD("Received unexpected Forge data when in errored state, ignored"); + return; + } if (a_Size <= 1) { diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index fe5a2987d7..67846250e7 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -44,6 +44,7 @@ class cForgeHandshake void HandleModList(cClientHandle * a_Client, const char * a_Data, size_t a_Size); void HandleHandshakeAck(cClientHandle * a_Client, const char * a_Data, size_t a_Size); + /** Set errored state to prevent further handshake message processing. */ void SetError(const AString & message); /** Parse the client ModList packet of installed Forge mods and versions. */ From 5cbdbd2eb92560bfaf275dab4f28fd209b95895f Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 6 Aug 2017 23:52:53 -0700 Subject: [PATCH 139/166] Fix cByteBuffer definition error from latest merge --- src/Protocol/ForgeHandshake.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 860a0c1ff8..c11648863c 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -7,6 +7,7 @@ #include "ForgeHandshake.h" #include "json/json.h" #include "../Server.h" +#include "../ByteBuffer.h" #include "../Bindings/PluginManager.h" #include "../ClientHandle.h" #include "../Root.h" From 44bf20e2292417ead78264c19322528419c5d633 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 7 Aug 2017 20:25:01 -0700 Subject: [PATCH 140/166] Style: remove indent for if condition in tolua_cClientHandle_GetForgeMods --- src/Bindings/ManualBindings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 1df474b271..a7ea7e4ae4 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2349,7 +2349,7 @@ static int tolua_cClientHandle_GetForgeMods(lua_State * L) if ( !S.CheckParamSelf("cClientHandle") || !S.CheckParamEnd(2) - ) + ) { return 0; } From 68b9a11641074b6b42a03b940c323553f36a1c51 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 7 Aug 2017 20:25:28 -0700 Subject: [PATCH 141/166] Remove unnecessary Mods variable in tolua_cClientHandle_GetForgeMods --- src/Bindings/ManualBindings.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index a7ea7e4ae4..09eeafebdc 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2356,8 +2356,6 @@ static int tolua_cClientHandle_GetForgeMods(lua_State * L) cClientHandle * Client; S.GetStackValue(1, Client); - auto Mods = Client->GetForgeMods(); - S.Push(Client->GetForgeMods()); return 1; } From e7f1ccdec570c64c88a35d264a7e14c02d169bce Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 7 Aug 2017 20:26:04 -0700 Subject: [PATCH 142/166] Change .size() == 0 to .empty() --- src/Protocol/ForgeHandshake.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index c11648863c..fe66064e16 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -70,7 +70,7 @@ void cForgeHandshake::AugmentServerListPing(Json::Value & a_ResponseValue) auto ProtocolVersion = m_Client->GetProtocolVersion(); auto & Mods = cRoot::Get()->GetServer()->GetRegisteredForgeMods(ProtocolVersion); - if (Mods.size() == 0) + if (Mods.empty()) { return; } From 620b68b0910cd998212398a5f8b7391fcf53cc92 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 7 Aug 2017 20:26:35 -0700 Subject: [PATCH 143/166] Spaces around '=' in ParseModList error message --- src/Protocol/ForgeHandshake.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index fe66064e16..c5fb2f5d79 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -147,7 +147,7 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) if (a_Size < 4) { - SetError(Printf("ParseModList invalid packet, missing length (size=" SIZE_T_FMT ")", a_Size)); + SetError(Printf("ParseModList invalid packet, missing length (size = " SIZE_T_FMT ")", a_Size)); return Mods; } From 8035bffa6220593caff19fbe66c409a5ab2f7555 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 7 Aug 2017 20:29:35 -0700 Subject: [PATCH 144/166] Loop induction variable UInt32 to match NumMods not size_t --- src/Protocol/ForgeHandshake.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index c5fb2f5d79..52cc1f62fc 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -160,17 +160,17 @@ AStringMap cForgeHandshake::ParseModList(const char * a_Data, size_t a_Size) return Mods; } - for (size_t i = 0; i < NumMods; ++i) + for (UInt32 i = 0; i < NumMods; ++i) { AString Name, Version; if (!Buf.ReadVarUTF8String(Name)) { - SetError(Printf("ParseModList failed to read mod name at i = " SIZE_T_FMT, i)); + SetError(Printf("ParseModList failed to read mod name at i = %d", i)); break; } if (!Buf.ReadVarUTF8String(Version)) { - SetError(Printf("ParseModList failed to read mod version at i = " SIZE_T_FMT, i)); + SetError(Printf("ParseModList failed to read mod version at i = %d", i)); break; } Mods.insert({Name, Version}); From ab7910be2f5946644c2131f1d36d7b1775bbc6be Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 7 Aug 2017 21:41:35 -0700 Subject: [PATCH 145/166] Scale max ModList buffer size to 256 bytes per mod --- src/Protocol/ForgeHandshake.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 52cc1f62fc..92204c2406 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -229,14 +229,13 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat // Send server ModList - // TODO: max size? - cByteBuffer Buf(1024); - // Send server-side Forge mods registered by plugins auto & ServerMods = m_Client->GetForgeMods(); auto ModCount = ServerMods.size(); + cByteBuffer Buf(256 * ModCount); + Buf.WriteBEInt8(Discriminator::ModList); Buf.WriteVarInt32(static_cast(ModCount)); for (auto & item: ServerMods) From c61d20970dcc6630f87fe9f1640437033389d660 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 7 Aug 2017 21:42:24 -0700 Subject: [PATCH 146/166] Consts in HandleModList --- src/Protocol/ForgeHandshake.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 92204c2406..5eca00daa7 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -230,15 +230,15 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat // Send server ModList // Send server-side Forge mods registered by plugins - auto & ServerMods = m_Client->GetForgeMods(); + const auto & ServerMods = m_Client->GetForgeMods(); - auto ModCount = ServerMods.size(); + const auto ModCount = ServerMods.size(); cByteBuffer Buf(256 * ModCount); Buf.WriteBEInt8(Discriminator::ModList); Buf.WriteVarInt32(static_cast(ModCount)); - for (auto & item: ServerMods) + for (const auto & item: ServerMods) { const AString & name = item.first; const AString & version = item.second; From 1dd19be74acc4f8f0bd9c2beaa5e0e31faf9b525 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 7 Aug 2017 21:43:00 -0700 Subject: [PATCH 147/166] Comment field names instead of variables --- src/Protocol/ForgeHandshake.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 5eca00daa7..64dd7d3eb7 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -240,10 +240,8 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat Buf.WriteVarInt32(static_cast(ModCount)); for (const auto & item: ServerMods) { - const AString & name = item.first; - const AString & version = item.second; - Buf.WriteVarUTF8String(name); - Buf.WriteVarUTF8String(version); + Buf.WriteVarUTF8String(item.first); // name + Buf.WriteVarUTF8String(item.second); // version } AString ServerModList; Buf.ReadAll(ServerModList); From b0cd9077f8980ecf93aa48ba1c2bb65c3a66519d Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 7 Aug 2017 21:43:23 -0700 Subject: [PATCH 148/166] Space around '=' with phase --- src/Protocol/ForgeHandshake.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 64dd7d3eb7..4d639dae2c 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -261,7 +261,7 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * } auto Phase = a_Data[1]; - LOGD("Received client HandshakeAck with phase=%d", Phase); + LOGD("Received client HandshakeAck with phase = %d", Phase); switch (Phase) { From d89917fabd975e3943cc21bee09c425f3a82e96c Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 7 Aug 2017 21:49:23 -0700 Subject: [PATCH 149/166] Remove logging binary data in cForgeHandshake::DataReceived --- src/Protocol/ForgeHandshake.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 4d639dae2c..616fac00f3 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -333,7 +333,6 @@ void cForgeHandshake::HandleHandshakeAck(cClientHandle * a_Client, const char * void cForgeHandshake::DataReceived(cClientHandle * a_Client, const char * a_Data, size_t a_Size) { - LOGD("Received Forge data: " SIZE_T_FMT " bytes: %s", a_Size, a_Data); if (!m_IsForgeClient) { SetError(Printf("Received unexpected Forge data from non-Forge client (" SIZE_T_FMT " bytes)", a_Size)); From ab61bcb15da8941edd7d68c10f77cfd18b72aa2a Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 7 Aug 2017 21:50:32 -0700 Subject: [PATCH 150/166] Remove unnecessary forward declaration of Json in ForgeHandshake --- src/Protocol/ForgeHandshake.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index 67846250e7..927c5125ad 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -9,10 +9,6 @@ #include "json/json.h" // fwd: -namespace Json -{ - class Value; -} class cClientHandle; From c5908ed1f2d452bb2fa1708cf2c2b1f2d941171d Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 7 Aug 2017 21:55:52 -0700 Subject: [PATCH 151/166] Move data members above functions in cForgeHandshake --- src/Protocol/ForgeHandshake.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index 927c5125ad..b2a3f846de 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -18,6 +18,9 @@ class cClientHandle; class cForgeHandshake { public: + /** True if the client advertised itself as a Forge client. */ + bool m_IsForgeClient; + cForgeHandshake(cClientHandle * client); /** Add the registered Forge mods to the server ping list packet. */ @@ -32,20 +35,7 @@ class cForgeHandshake /** Process received data from the client advancing the Forge handshake. */ void DataReceived(cClientHandle * a_Client, const char * a_Data, size_t a_Size); - /** True if the client advertised itself as a Forge client. */ - bool m_IsForgeClient; - private: - void HandleClientHello(cClientHandle * a_Client, const char * a_Data, size_t a_Size); - void HandleModList(cClientHandle * a_Client, const char * a_Data, size_t a_Size); - void HandleHandshakeAck(cClientHandle * a_Client, const char * a_Data, size_t a_Size); - - /** Set errored state to prevent further handshake message processing. */ - void SetError(const AString & message); - - /** Parse the client ModList packet of installed Forge mods and versions. */ - AStringMap ParseModList(const char * a_Data, size_t a_Size); - /** True if the Forge handshake is in an errored state. */ bool m_Errored; @@ -56,4 +46,14 @@ class cForgeHandshake AString m_Name; AString m_UUID; Json::Value m_Properties; + + void HandleClientHello(cClientHandle * a_Client, const char * a_Data, size_t a_Size); + void HandleModList(cClientHandle * a_Client, const char * a_Data, size_t a_Size); + void HandleHandshakeAck(cClientHandle * a_Client, const char * a_Data, size_t a_Size); + + /** Set errored state to prevent further handshake message processing. */ + void SetError(const AString & message); + + /** Parse the client ModList packet of installed Forge mods and versions. */ + AStringMap ParseModList(const char * a_Data, size_t a_Size); }; From d34632a8e64228270f0dd881a59bd840f9fa6fdb Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 7 Aug 2017 21:58:32 -0700 Subject: [PATCH 152/166] Move ClientHandle include to Protocol_1_10 where it is used --- src/Protocol/Protocol.h | 1 - src/Protocol/Protocol_1_10.cpp | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index 480b58bcd4..93f25310b7 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -15,7 +15,6 @@ #include "../Map.h" #include "../ByteBuffer.h" #include "../EffectID.h" -#include "../ClientHandle.h" diff --git a/src/Protocol/Protocol_1_10.cpp b/src/Protocol/Protocol_1_10.cpp index e4d7a1eea4..ff7322ecf3 100644 --- a/src/Protocol/Protocol_1_10.cpp +++ b/src/Protocol/Protocol_1_10.cpp @@ -15,6 +15,7 @@ Implements the 1.10 protocol classes: #include "../Root.h" #include "../Server.h" +#include "../ClientHandle.h" #include "../WorldStorage/FastNBT.h" From f6307c5152edd9295a943d40913d757b06630130 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 7 Aug 2017 22:00:10 -0700 Subject: [PATCH 153/166] Whitespace around tolua comments Server.h --- src/Server.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Server.h b/src/Server.h index bdb2b60a9f..9bbd7dc4c5 100644 --- a/src/Server.h +++ b/src/Server.h @@ -71,8 +71,10 @@ class cServer void SetMaxPlayers(size_t a_MaxPlayers) { m_MaxPlayers = a_MaxPlayers; } // tolua_end + /** Add a Forge mod to the server ping list. */ bool RegisterForgeMod(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber); + // tolua_begin /** Remove a Forge mod to the server ping list. */ From aa596db7fa34abb66852d4f3fe0e5b845113f2fc Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 8 Aug 2017 22:52:07 -0700 Subject: [PATCH 154/166] const GetRegisteredForgeMods() and add private non-const accessor --- src/Server.cpp | 14 +++++++++++--- src/Server.h | 5 ++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Server.cpp b/src/Server.cpp index 70741dec48..5747ada849 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -237,7 +237,7 @@ bool cServer::InitServer(cSettingsRepositoryInterface & a_Settings, bool a_Shoul bool cServer::RegisterForgeMod(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber) { - auto & Mods = GetRegisteredForgeMods(a_ProtocolVersionNumber); + auto & Mods = RegisteredForgeMods(a_ProtocolVersionNumber); return Mods.insert({a_ModName, a_ModVersion}).second; } @@ -248,7 +248,7 @@ bool cServer::RegisterForgeMod(AString & a_ModName, AString & a_ModVersion, UInt void cServer::UnregisterForgeMod(AString &a_ModName, UInt32 a_ProtocolVersionNumber) { - auto & Mods = GetRegisteredForgeMods(a_ProtocolVersionNumber); + auto & Mods = RegisteredForgeMods(a_ProtocolVersionNumber); auto it = Mods.find(a_ModName); if (it != Mods.end()) @@ -260,7 +260,7 @@ void cServer::UnregisterForgeMod(AString &a_ModName, UInt32 a_ProtocolVersionNum -AStringMap & cServer::GetRegisteredForgeMods(const UInt32 a_Protocol) +AStringMap & cServer::RegisteredForgeMods(const UInt32 a_Protocol) { auto it = m_ForgeModsByVersion.find(a_Protocol); @@ -277,6 +277,14 @@ AStringMap & cServer::GetRegisteredForgeMods(const UInt32 a_Protocol) +const AStringMap & cServer::GetRegisteredForgeMods(const UInt32 a_Protocol) +{ + return RegisteredForgeMods(a_Protocol); +} + + + + bool cServer::IsPlayerInQueue(AString a_Username) { cCSLock Lock(m_CSClients); diff --git a/src/Server.h b/src/Server.h index 9bbd7dc4c5..3c43bbea1d 100644 --- a/src/Server.h +++ b/src/Server.h @@ -155,7 +155,7 @@ class cServer bool ShouldAllowMultiWorldTabCompletion(void) const { return m_ShouldAllowMultiWorldTabCompletion; } /** Get the Forge mods registered for a given protocol. */ - AStringMap & GetRegisteredForgeMods(const UInt32 a_Protocol); + const AStringMap & GetRegisteredForgeMods(const UInt32 a_Protocol); private: @@ -256,6 +256,9 @@ class cServer cServer(void); + /** Get the Forge mods registered for a given protocol, for modification */ + AStringMap & RegisteredForgeMods(const UInt32 a_Protocol); + /** Loads, or generates, if missing, RSA keys for protocol encryption */ void PrepareKeys(void); From 68d078281dc13c6059a9c8e4df85d4c424146579 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 8 Aug 2017 22:53:13 -0700 Subject: [PATCH 155/166] Revert "const GetRegisteredForgeMods() and add private non-const accessor" This reverts commit aa596db7fa34abb66852d4f3fe0e5b845113f2fc. --- src/Server.cpp | 14 +++----------- src/Server.h | 5 +---- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/Server.cpp b/src/Server.cpp index 5747ada849..70741dec48 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -237,7 +237,7 @@ bool cServer::InitServer(cSettingsRepositoryInterface & a_Settings, bool a_Shoul bool cServer::RegisterForgeMod(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber) { - auto & Mods = RegisteredForgeMods(a_ProtocolVersionNumber); + auto & Mods = GetRegisteredForgeMods(a_ProtocolVersionNumber); return Mods.insert({a_ModName, a_ModVersion}).second; } @@ -248,7 +248,7 @@ bool cServer::RegisterForgeMod(AString & a_ModName, AString & a_ModVersion, UInt void cServer::UnregisterForgeMod(AString &a_ModName, UInt32 a_ProtocolVersionNumber) { - auto & Mods = RegisteredForgeMods(a_ProtocolVersionNumber); + auto & Mods = GetRegisteredForgeMods(a_ProtocolVersionNumber); auto it = Mods.find(a_ModName); if (it != Mods.end()) @@ -260,7 +260,7 @@ void cServer::UnregisterForgeMod(AString &a_ModName, UInt32 a_ProtocolVersionNum -AStringMap & cServer::RegisteredForgeMods(const UInt32 a_Protocol) +AStringMap & cServer::GetRegisteredForgeMods(const UInt32 a_Protocol) { auto it = m_ForgeModsByVersion.find(a_Protocol); @@ -277,14 +277,6 @@ AStringMap & cServer::RegisteredForgeMods(const UInt32 a_Protocol) -const AStringMap & cServer::GetRegisteredForgeMods(const UInt32 a_Protocol) -{ - return RegisteredForgeMods(a_Protocol); -} - - - - bool cServer::IsPlayerInQueue(AString a_Username) { cCSLock Lock(m_CSClients); diff --git a/src/Server.h b/src/Server.h index 3c43bbea1d..9bbd7dc4c5 100644 --- a/src/Server.h +++ b/src/Server.h @@ -155,7 +155,7 @@ class cServer bool ShouldAllowMultiWorldTabCompletion(void) const { return m_ShouldAllowMultiWorldTabCompletion; } /** Get the Forge mods registered for a given protocol. */ - const AStringMap & GetRegisteredForgeMods(const UInt32 a_Protocol); + AStringMap & GetRegisteredForgeMods(const UInt32 a_Protocol); private: @@ -256,9 +256,6 @@ class cServer cServer(void); - /** Get the Forge mods registered for a given protocol, for modification */ - AStringMap & RegisteredForgeMods(const UInt32 a_Protocol); - /** Loads, or generates, if missing, RSA keys for protocol encryption */ void PrepareKeys(void); From 9de99fef81ecbd0cdf498c733d98be99ec036542 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 8 Aug 2017 22:52:07 -0700 Subject: [PATCH 156/166] const GetRegisteredForgeMods() and add private non-const accessor --- src/Server.cpp | 14 +++++++++++--- src/Server.h | 5 ++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Server.cpp b/src/Server.cpp index 70741dec48..5747ada849 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -237,7 +237,7 @@ bool cServer::InitServer(cSettingsRepositoryInterface & a_Settings, bool a_Shoul bool cServer::RegisterForgeMod(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber) { - auto & Mods = GetRegisteredForgeMods(a_ProtocolVersionNumber); + auto & Mods = RegisteredForgeMods(a_ProtocolVersionNumber); return Mods.insert({a_ModName, a_ModVersion}).second; } @@ -248,7 +248,7 @@ bool cServer::RegisterForgeMod(AString & a_ModName, AString & a_ModVersion, UInt void cServer::UnregisterForgeMod(AString &a_ModName, UInt32 a_ProtocolVersionNumber) { - auto & Mods = GetRegisteredForgeMods(a_ProtocolVersionNumber); + auto & Mods = RegisteredForgeMods(a_ProtocolVersionNumber); auto it = Mods.find(a_ModName); if (it != Mods.end()) @@ -260,7 +260,7 @@ void cServer::UnregisterForgeMod(AString &a_ModName, UInt32 a_ProtocolVersionNum -AStringMap & cServer::GetRegisteredForgeMods(const UInt32 a_Protocol) +AStringMap & cServer::RegisteredForgeMods(const UInt32 a_Protocol) { auto it = m_ForgeModsByVersion.find(a_Protocol); @@ -277,6 +277,14 @@ AStringMap & cServer::GetRegisteredForgeMods(const UInt32 a_Protocol) +const AStringMap & cServer::GetRegisteredForgeMods(const UInt32 a_Protocol) +{ + return RegisteredForgeMods(a_Protocol); +} + + + + bool cServer::IsPlayerInQueue(AString a_Username) { cCSLock Lock(m_CSClients); diff --git a/src/Server.h b/src/Server.h index 9bbd7dc4c5..3c43bbea1d 100644 --- a/src/Server.h +++ b/src/Server.h @@ -155,7 +155,7 @@ class cServer bool ShouldAllowMultiWorldTabCompletion(void) const { return m_ShouldAllowMultiWorldTabCompletion; } /** Get the Forge mods registered for a given protocol. */ - AStringMap & GetRegisteredForgeMods(const UInt32 a_Protocol); + const AStringMap & GetRegisteredForgeMods(const UInt32 a_Protocol); private: @@ -256,6 +256,9 @@ class cServer cServer(void); + /** Get the Forge mods registered for a given protocol, for modification */ + AStringMap & RegisteredForgeMods(const UInt32 a_Protocol); + /** Loads, or generates, if missing, RSA keys for protocol encryption */ void PrepareKeys(void); From 0737594f5c140c41d4099676bab24df1000e4b5a Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Thu, 24 Aug 2017 19:55:26 -0700 Subject: [PATCH 157/166] Augment server ping for 1.12.1 protocol for Forge --- src/Protocol/Protocol_1_12.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp index 909e327456..99df680ea2 100644 --- a/src/Protocol/Protocol_1_12.cpp +++ b/src/Protocol/Protocol_1_12.cpp @@ -1668,6 +1668,7 @@ void cProtocol_1_12_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; + m_Client->ForgeAugmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); From a46617334ae0acdf8e49be94133c81dbf9b52837 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 25 Aug 2017 20:24:42 -0700 Subject: [PATCH 158/166] Fix duplicate CompositeChat.h inclusion in ManualBindings --- src/Bindings/ManualBindings.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index e2ea1e34f6..ac62b0f494 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -33,7 +33,6 @@ #include "../HTTP/UrlParser.h" #include "../Item.h" #include "../LineBlockTracer.h" -#include "../CompositeChat.h" #include "../Server.h" #include "../Root.h" #include "../StringCompression.h" From 63a0f408c9684856f2af221070fe85b43bf3e92f Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 25 Aug 2017 20:27:04 -0700 Subject: [PATCH 159/166] Fix ManualBindings merge --- src/Bindings/ManualBindings.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index ac62b0f494..ee9cb61e90 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2380,6 +2380,7 @@ static int tolua_cClientHandle_GetForgeMods(lua_State * L) S.GetStackValue(1, Client); S.Push(Client->GetForgeMods()); + return 1; } @@ -2437,8 +2438,6 @@ static int tolua_cClientHandle_GenerateOfflineUUID(lua_State * tolua_S) -<<<<<<< HEAD -======= static int tolua_cClientHandle_IsUUIDOnline(lua_State * tolua_S) { // Check the params: @@ -2519,7 +2518,6 @@ static int tolua_cMobHeadEntity_GetOwnerUUID(lua_State * tolua_S) ->>>>>>> master static int tolua_cMojangAPI_AddPlayerNameToUUIDMapping(lua_State * L) { @@ -4060,20 +4058,14 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cClientHandle"); -<<<<<<< HEAD - tolua_constant(tolua_S, "MAX_VIEW_DISTANCE", cClientHandle::MAX_VIEW_DISTANCE); - tolua_constant(tolua_S, "MIN_VIEW_DISTANCE", cClientHandle::MIN_VIEW_DISTANCE); - - tolua_function(tolua_S, "GetForgeMods", tolua_cClientHandle_GetForgeMods); - tolua_function(tolua_S, "SendPluginMessage", tolua_cClientHandle_SendPluginMessage); -======= tolua_constant(tolua_S, "MAX_VIEW_DISTANCE", cClientHandle::MAX_VIEW_DISTANCE); tolua_constant(tolua_S, "MIN_VIEW_DISTANCE", cClientHandle::MIN_VIEW_DISTANCE); + + tolua_function(tolua_S, "GetForgeMods", tolua_cClientHandle_GetForgeMods); tolua_function(tolua_S, "SendPluginMessage", tolua_cClientHandle_SendPluginMessage); tolua_function(tolua_S, "GetUUID", tolua_cClientHandle_GetUUID); tolua_function(tolua_S, "GenerateOfflineUUID", tolua_cClientHandle_GenerateOfflineUUID); tolua_function(tolua_S, "IsUUIDOnline", tolua_cClientHandle_IsUUIDOnline); ->>>>>>> master tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cColor"); From c169ec929775f6994685faee431badb8746968b5 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 25 Aug 2017 20:30:35 -0700 Subject: [PATCH 160/166] Fix UUID type, now cUUID not AString --- src/ClientHandle.cpp | 2 +- src/ClientHandle.h | 2 +- src/Protocol/ForgeHandshake.cpp | 2 +- src/Protocol/ForgeHandshake.h | 5 +++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index a7a1cf0d01..dbd6d4b4ef 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -366,7 +366,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const cUUID & a_UUID, c -void cClientHandle::FinishAuthenticate(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties) +void cClientHandle::FinishAuthenticate(const AString & a_Name, const cUUID & a_UUID, const Json::Value & a_Properties) { cWorld * World; { diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 2149a258ce..4a4898179b 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -553,7 +553,7 @@ class cClientHandle // tolua_export float m_BreakProgress; /** Finish logging the user in after authenticating. */ - void FinishAuthenticate(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties); + void FinishAuthenticate(const AString & a_Name, const cUUID & a_UUID, const Json::Value & a_Properties); /** Returns true if the rate block interactions is within a reasonable limit (bot protection) */ bool CheckBlockInteractionsRate(void); diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 616fac00f3..51583ae031 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -97,7 +97,7 @@ void cForgeHandshake::AugmentServerListPing(Json::Value & a_ResponseValue) -void cForgeHandshake::BeginForgeHandshake(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties) +void cForgeHandshake::BeginForgeHandshake(const AString & a_Name, const cUUID & a_UUID, const Json::Value & a_Properties) { ASSERT(m_IsForgeClient); diff --git a/src/Protocol/ForgeHandshake.h b/src/Protocol/ForgeHandshake.h index b2a3f846de..f7be9e958e 100644 --- a/src/Protocol/ForgeHandshake.h +++ b/src/Protocol/ForgeHandshake.h @@ -6,6 +6,7 @@ #pragma once #include +#include "UUID.h" #include "json/json.h" // fwd: @@ -27,7 +28,7 @@ class cForgeHandshake void AugmentServerListPing(Json::Value & ResponseValue); /** Begin the Forge Modloader Handshake (FML|HS) sequence. */ - void BeginForgeHandshake(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties); + void BeginForgeHandshake(const AString & a_Name, const cUUID & a_UUID, const Json::Value & a_Properties); /** Send the ServerHello packet in the Forge handshake. */ void SendServerHello(); @@ -44,7 +45,7 @@ class cForgeHandshake /** Values saved from BeginForgeHandshake() for continuing the normal handshake after Forge completes. */ AString m_Name; - AString m_UUID; + cUUID m_UUID; Json::Value m_Properties; void HandleClientHello(cClientHandle * a_Client, const char * a_Data, size_t a_Size); From b4056d55d01ca66f34cffdf08f385fd2b27b20ca Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 25 Aug 2017 21:25:44 -0700 Subject: [PATCH 161/166] Encode Forge ServerHello using cByteBuffer --- src/Protocol/ForgeHandshake.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index 51583ae031..d775d6381c 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -124,15 +124,14 @@ void cForgeHandshake::BeginForgeHandshake(const AString & a_Name, const cUUID & void cForgeHandshake::SendServerHello() { AString Message; + cByteBuffer Buf(6); // Discriminator | Byte | Always 0 for ServerHello - Message.push_back(Discriminator::ServerHello); + Buf.WriteBEInt8(Discriminator::ServerHello); // FML protocol Version | Byte | Determined from NetworkRegistery. Currently 2. - Message.push_back('\2'); + Buf.WriteBEInt8(2); // Dimension TODO - Message.push_back('\0'); - Message.push_back('\0'); - Message.push_back('\0'); - Message.push_back('\0'); + Buf.WriteBEInt32(0); + Buf.ReadAll(Message); m_Client->SendPluginMessage("FML|HS", Message); } From 6cd0545d369a64c75d78be50900994c076fc0beb Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 25 Aug 2017 21:28:27 -0700 Subject: [PATCH 162/166] Change mod list string to use AppendPrintf --- src/Protocol/ForgeHandshake.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Protocol/ForgeHandshake.cpp b/src/Protocol/ForgeHandshake.cpp index d775d6381c..48b89baf4c 100644 --- a/src/Protocol/ForgeHandshake.cpp +++ b/src/Protocol/ForgeHandshake.cpp @@ -209,10 +209,7 @@ void cForgeHandshake::HandleModList(cClientHandle * a_Client, const char * a_Dat AString ClientModsString; for (auto & item: ClientMods) { - ClientModsString.append(item.first); - ClientModsString.append("@"); - ClientModsString.append(item.second); - ClientModsString.append(", "); + AppendPrintf(ClientModsString, "%s@%s, ", item.first.c_str(), item.second.c_str()); } LOG("Client connected with " SIZE_T_FMT " mods: %s", ClientMods.size(), ClientModsString.c_str()); From 664228812468a38ea1fa3dd59b735db933a5c8c7 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Fri, 25 Aug 2017 21:33:41 -0700 Subject: [PATCH 163/166] Fix five lines spacing after CallHookLoginForge() --- src/Bindings/PluginManager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index 8ed0428040..7c4712f0f2 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -808,7 +808,6 @@ bool cPluginManager::CallHookLoginForge(cClientHandle & a_Client, AStringMap & a - bool cPluginManager::CallHookPlayerAnimation(cPlayer & a_Player, int a_Animation) { FIND_HOOK(HOOK_PLAYER_ANIMATION); From 9a9f61238f28673631d09d2dbe65baffbf108550 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 26 Aug 2017 12:00:23 -0700 Subject: [PATCH 164/166] Add const to AString references in (Un)registerForgeMod --- src/Server.cpp | 4 ++-- src/Server.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Server.cpp b/src/Server.cpp index 7702fac70e..6ddb14ae5d 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -235,7 +235,7 @@ bool cServer::InitServer(cSettingsRepositoryInterface & a_Settings, bool a_Shoul -bool cServer::RegisterForgeMod(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber) +bool cServer::RegisterForgeMod(const AString & a_ModName, const AString & a_ModVersion, UInt32 a_ProtocolVersionNumber) { auto & Mods = RegisteredForgeMods(a_ProtocolVersionNumber); @@ -246,7 +246,7 @@ bool cServer::RegisterForgeMod(AString & a_ModName, AString & a_ModVersion, UInt -void cServer::UnregisterForgeMod(AString &a_ModName, UInt32 a_ProtocolVersionNumber) +void cServer::UnregisterForgeMod(const AString & a_ModName, UInt32 a_ProtocolVersionNumber) { auto & Mods = RegisteredForgeMods(a_ProtocolVersionNumber); diff --git a/src/Server.h b/src/Server.h index e89a139ec3..d0c94f953e 100644 --- a/src/Server.h +++ b/src/Server.h @@ -74,12 +74,12 @@ class cServer // tolua_end /** Add a Forge mod to the server ping list. */ - bool RegisterForgeMod(AString & a_ModName, AString & a_ModVersion, UInt32 a_ProtocolVersionNumber); + bool RegisterForgeMod(const AString & a_ModName, const AString & a_ModVersion, UInt32 a_ProtocolVersionNumber); // tolua_begin /** Remove a Forge mod to the server ping list. */ - void UnregisterForgeMod(AString & a_ModName, UInt32 a_ProtocolVersionNumber); + void UnregisterForgeMod(const AString & a_ModName, UInt32 a_ProtocolVersionNumber); /** Check if the player is queued to be transferred to a World. Returns true is Player is found in queue. */ From b8e5b3fb264ecca090f7f07f73783e80f29f0ae5 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 26 Aug 2017 12:02:00 -0700 Subject: [PATCH 165/166] Enhance documentation string for m_ForgeModsByVersion --- src/Server.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Server.h b/src/Server.h index d0c94f953e..7e4389ecfb 100644 --- a/src/Server.h +++ b/src/Server.h @@ -215,7 +215,7 @@ class cServer size_t m_MaxPlayers; bool m_bIsHardcore; - /** Map of protocol version to Forge mods for that version. */ + /** Map of protocol version to Forge mods (map of ModName -> ModVersionString) */ std::map m_ForgeModsByVersion; /** True - allow same username to login more than once False - only once */ From b6570d805a24958af4fdb77aa25118ec142101be Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 26 Aug 2017 12:04:46 -0700 Subject: [PATCH 166/166] Enhance documentation string for GetRegisteredForgeMods, detail map --- src/Server.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Server.h b/src/Server.h index 7e4389ecfb..ffdee64d93 100644 --- a/src/Server.h +++ b/src/Server.h @@ -155,7 +155,7 @@ class cServer from the settings. */ bool ShouldAllowMultiWorldTabCompletion(void) const { return m_ShouldAllowMultiWorldTabCompletion; } - /** Get the Forge mods registered for a given protocol. */ + /** Get the Forge mods (map of ModName -> ModVersionString) registered for a given protocol. */ const AStringMap & GetRegisteredForgeMods(const UInt32 a_Protocol); private: