From 0bc12141c3e2ef678a8c40481942a26ef9d24358 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Fri, 12 Jan 2024 14:23:44 -0600 Subject: [PATCH] chore: default size to 33 on LU(W)Strings since that's the most common lenght (#1410) Was doing this on other places, but not the main one --- dChatServer/ChatIgnoreList.cpp | 4 ++-- dGame/UserManager.cpp | 4 ++-- dMasterServer/MasterServer.cpp | 6 +++--- dNet/AuthPackets.cpp | 2 +- dNet/BitStreamUtils.h | 4 ++-- dNet/MasterPackets.cpp | 2 +- dWorldServer/WorldServer.cpp | 8 ++++---- tests/dCommonTests/TestLUString.cpp | 4 ++-- tests/dCommonTests/TestLUWString.cpp | 4 ++-- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/dChatServer/ChatIgnoreList.cpp b/dChatServer/ChatIgnoreList.cpp index f6e91ba0..d77eeeed 100644 --- a/dChatServer/ChatIgnoreList.cpp +++ b/dChatServer/ChatIgnoreList.cpp @@ -81,7 +81,7 @@ void ChatIgnoreList::AddIgnore(Packet* packet) { inStream.IgnoreBytes(4); // ignore some garbage zeros idk - LUWString toIgnoreName(33); + LUWString toIgnoreName; inStream.Read(toIgnoreName); std::string toIgnoreStr = toIgnoreName.GetAsString(); @@ -147,7 +147,7 @@ void ChatIgnoreList::RemoveIgnore(Packet* packet) { inStream.IgnoreBytes(4); // ignore some garbage zeros idk - LUWString removedIgnoreName(33); + LUWString removedIgnoreName; inStream.Read(removedIgnoreName); std::string removedIgnoreStr = removedIgnoreName.GetAsString(); diff --git a/dGame/UserManager.cpp b/dGame/UserManager.cpp index 958369fc..fc582108 100644 --- a/dGame/UserManager.cpp +++ b/dGame/UserManager.cpp @@ -267,7 +267,7 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet) User* u = GetUser(sysAddr); if (!u) return; - LUWString LUWStringName(33); + LUWString LUWStringName; uint32_t firstNameIndex; uint32_t middleNameIndex; uint32_t lastNameIndex; @@ -437,7 +437,7 @@ void UserManager::RenameCharacter(const SystemAddress& sysAddr, Packet* packet) uint32_t charID = static_cast(objectID); LOG("Received char rename request for ID: %llu (%u)", objectID, charID); - LUWString LUWStringName(33); + LUWString LUWStringName; inStream.Read(LUWStringName); const auto newName = LUWStringName.GetAsString(); diff --git a/dMasterServer/MasterServer.cpp b/dMasterServer/MasterServer.cpp index cdfbdf0a..f15bb9a9 100644 --- a/dMasterServer/MasterServer.cpp +++ b/dMasterServer/MasterServer.cpp @@ -503,7 +503,7 @@ void HandlePacket(Packet* packet) { uint32_t theirZoneID = 0; uint32_t theirInstanceID = 0; ServerType theirServerType; - LUString theirIP(33); + LUString theirIP; inStream.Read(theirPort); inStream.Read(theirZoneID); @@ -555,7 +555,7 @@ void HandlePacket(Packet* packet) { CINSTREAM_SKIP_HEADER; uint32_t sessionKey = 0; inStream.Read(sessionKey); - LUString username(33); + LUString username; inStream.Read(username); for (auto it : activeSessions) { @@ -579,7 +579,7 @@ void HandlePacket(Packet* packet) { case eMasterMessageType::REQUEST_SESSION_KEY: { CINSTREAM_SKIP_HEADER; - LUWString username(33); + LUWString username; inStream.Read(username); LOG("Requesting session key for %s", username.GetAsString().c_str()); for (auto key : activeSessions) { diff --git a/dNet/AuthPackets.cpp b/dNet/AuthPackets.cpp index a878644c..2597c576 100644 --- a/dNet/AuthPackets.cpp +++ b/dNet/AuthPackets.cpp @@ -95,7 +95,7 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) { std::vector stamps; stamps.emplace_back(eStamps::PASSPORT_AUTH_START, 0); - LUWString usernameLUString(33); + LUWString usernameLUString; inStream.Read(usernameLUString); const auto username = usernameLUString.GetAsString(); diff --git a/dNet/BitStreamUtils.h b/dNet/BitStreamUtils.h index 7403d0e1..1322ec95 100644 --- a/dNet/BitStreamUtils.h +++ b/dNet/BitStreamUtils.h @@ -12,7 +12,7 @@ struct LUString { std::string string; uint32_t size; - LUString(uint32_t size) { + LUString(uint32_t size = 33) { this->size = size; }; LUString(std::string string, uint32_t size = 33) { @@ -28,7 +28,7 @@ struct LUWString { std::u16string string; uint32_t size; - LUWString(uint32_t size) { + LUWString(uint32_t size = 33) { this->size = size; }; LUWString(std::u16string string, uint32_t size = 33) { diff --git a/dNet/MasterPackets.cpp b/dNet/MasterPackets.cpp index 6953026e..6d70fedb 100644 --- a/dNet/MasterPackets.cpp +++ b/dNet/MasterPackets.cpp @@ -99,7 +99,7 @@ void MasterPackets::HandleServerInfo(Packet* packet) { uint32_t theirPort = 0; uint32_t theirZoneID = 0; uint32_t theirInstanceID = 0; - LUString theirIP(33); + LUString theirIP; inStream.Read(theirPort); inStream.Read(theirZoneID); diff --git a/dWorldServer/WorldServer.cpp b/dWorldServer/WorldServer.cpp index fc5baf85..82c66db2 100644 --- a/dWorldServer/WorldServer.cpp +++ b/dWorldServer/WorldServer.cpp @@ -677,7 +677,7 @@ void HandleMasterPacket(Packet* packet) { CINSTREAM_SKIP_HEADER; uint32_t sessionKey = 0; inStream.Read(sessionKey); - LUWString username(33); + LUWString username; inStream.Read(username); //Find them: @@ -761,7 +761,7 @@ void HandleMasterPacket(Packet* packet) { CINSTREAM_SKIP_HEADER; uint32_t sessionKey = inStream.Read(sessionKey); - LUString username(33); + LUString username; inStream.Read(username); LOG("Got new session alert for user %s", username.string.c_str()); //Find them: @@ -847,10 +847,10 @@ void HandlePacket(Packet* packet) { switch (static_cast(packet->data[3])) { case eWorldMessageType::VALIDATION: { CINSTREAM_SKIP_HEADER; - LUWString username(33); + LUWString username; inStream.Read(username); - LUWString sessionKey(33); + LUWString sessionKey; // sometimes client puts a null terminator at the end of the checksum and sometimes doesn't, weird inStream.Read(sessionKey); LUString clientDatabaseChecksum(32); diff --git a/tests/dCommonTests/TestLUString.cpp b/tests/dCommonTests/TestLUString.cpp index 3abec985..30cc0f73 100644 --- a/tests/dCommonTests/TestLUString.cpp +++ b/tests/dCommonTests/TestLUString.cpp @@ -101,7 +101,7 @@ TEST(LUString33Test, SerializeReadTestNew) { std::string testString; for (int i = 0; i < 33; i++) testString += "a"; bitStream.Write(LUString(testString, 33)); - LUString result(33); + LUString result; ASSERT_EQ(result.size, 33); ASSERT_TRUE(bitStream.Read(result)); ASSERT_EQ(bitStream.GetNumberOfUnreadBits(), 0); @@ -113,7 +113,7 @@ TEST(LUString33Test, SerializeReadTestNewPartial) { std::string testString; for (int i = 0; i < 15; i++) testString += "a"; bitStream.Write(LUString(testString, 33)); - LUString result(33); + LUString result; ASSERT_EQ(result.size, 33); ASSERT_TRUE(bitStream.Read(result)); ASSERT_EQ(bitStream.GetNumberOfUnreadBits(), 0); diff --git a/tests/dCommonTests/TestLUWString.cpp b/tests/dCommonTests/TestLUWString.cpp index a16dd911..e812ae0c 100644 --- a/tests/dCommonTests/TestLUWString.cpp +++ b/tests/dCommonTests/TestLUWString.cpp @@ -101,7 +101,7 @@ TEST(LUWString33Test, SerializeReadTestNew) { std::u16string testString; for (int i = 0; i < 33; i++) testString += u'ü'; bitStream.Write(LUWString(testString, 33)); - LUWString result(33); + LUWString result; ASSERT_EQ(result.size, 33); ASSERT_TRUE(bitStream.Read(result)); ASSERT_EQ(bitStream.GetNumberOfUnreadBits(), 0); @@ -113,7 +113,7 @@ TEST(LUWString33Test, SerializeReadTestNewPartial) { std::u16string testString; for (int i = 0; i < 15; i++) testString += u'ü'; bitStream.Write(LUWString(testString, 33)); - LUWString result(33); + LUWString result; ASSERT_EQ(result.size, 33); ASSERT_TRUE(bitStream.Read(result)); ASSERT_EQ(bitStream.GetNumberOfUnreadBits(), 0);