From dbe4a0ced3132eda6472d8086d5c894577e8f452 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Sun, 7 Jan 2024 02:02:27 -0600 Subject: [PATCH] chore: continue work on removing raw packet reading (#1404) * chore: continue work on removing raw packet reading tested that logging in, deleted a char, renaming a char, and transfeering to a zone all work still * Address Feedback --- dChatServer/ChatIgnoreList.cpp | 1 - dGame/Entity.cpp | 1 - dGame/EntityManager.cpp | 5 -- dGame/UserManager.cpp | 61 ++++++++++++------- dGame/dComponents/QuickBuildComponent.cpp | 1 - dGame/dComponents/RenderComponent.cpp | 1 - dGame/dGameMessages/GameMessages.cpp | 4 -- dGame/dUtilities/Mail.cpp | 2 - dMasterServer/MasterServer.cpp | 40 ++++++------- dNet/AuthPackets.cpp | 4 +- dNet/ChatPackets.cpp | 1 - dNet/MasterPackets.cpp | 9 ++- dNet/WorldPackets.cpp | 1 - dNet/ZoneInstanceManager.cpp | 29 +++++---- dNet/ZoneInstanceManager.h | 4 +- dNet/dServer.cpp | 4 +- dWorldServer/WorldServer.cpp | 73 +++++++++++------------ 17 files changed, 118 insertions(+), 123 deletions(-) diff --git a/dChatServer/ChatIgnoreList.cpp b/dChatServer/ChatIgnoreList.cpp index 3b5103f0..f6e91ba0 100644 --- a/dChatServer/ChatIgnoreList.cpp +++ b/dChatServer/ChatIgnoreList.cpp @@ -2,7 +2,6 @@ #include "PlayerContainer.h" #include "eChatInternalMessageType.h" #include "BitStreamUtils.h" -#include "PacketUtils.h" #include "Game.h" #include "Logger.h" #include "eObjectBits.h" diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 8300de41..c693358d 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -3,7 +3,6 @@ #include "CDClientManager.h" #include "Game.h" #include "Logger.h" -#include "PacketUtils.h" #include #include "CDDestructibleComponentTable.h" #include "CDClientDatabase.h" diff --git a/dGame/EntityManager.cpp b/dGame/EntityManager.cpp index a098dbcf..7361574b 100644 --- a/dGame/EntityManager.cpp +++ b/dGame/EntityManager.cpp @@ -11,7 +11,6 @@ #include "SkillComponent.h" #include "SwitchComponent.h" #include "UserManager.h" -#include "PacketUtils.h" #include "Metrics.hpp" #include "dZoneManager.h" #include "MissionComponent.h" @@ -389,8 +388,6 @@ void EntityManager::ConstructEntity(Entity* entity, const SystemAddress& sysAddr Game::server->Send(&stream, sysAddr, false); } - // PacketUtils::SavePacket("[24]_"+std::to_string(entity->GetObjectID()) + "_" + std::to_string(m_SerializationCounter) + ".bin", (char*)stream.GetData(), stream.GetNumberOfBytesUsed()); - if (entity->IsPlayer()) { if (entity->GetGMLevel() > eGameMasterLevel::CIVILIAN) { GameMessages::SendToggleGMInvis(entity->GetObjectID(), true, sysAddr); @@ -434,8 +431,6 @@ void EntityManager::SerializeEntity(Entity* entity) { if (std::find(m_EntitiesToSerialize.begin(), m_EntitiesToSerialize.end(), entity->GetObjectID()) == m_EntitiesToSerialize.end()) { m_EntitiesToSerialize.push_back(entity->GetObjectID()); } - - //PacketUtils::SavePacket(std::to_string(m_SerializationCounter) + "_[27]_"+std::to_string(entity->GetObjectID()) + ".bin", (char*)stream.GetData(), stream.GetNumberOfBytesUsed()); } void EntityManager::DestructAllEntities(const SystemAddress& sysAddr) { diff --git a/dGame/UserManager.cpp b/dGame/UserManager.cpp index 2060de89..958369fc 100644 --- a/dGame/UserManager.cpp +++ b/dGame/UserManager.cpp @@ -11,7 +11,6 @@ #include "WorldPackets.h" #include "Character.h" #include "BitStream.h" -#include "PacketUtils.h" #include "ObjectIDManager.h" #include "Logger.h" #include "GeneralUtils.h" @@ -267,25 +266,41 @@ void UserManager::RequestCharacterList(const SystemAddress& sysAddr) { void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet) { User* u = GetUser(sysAddr); if (!u) return; + + LUWString LUWStringName(33); + uint32_t firstNameIndex; + uint32_t middleNameIndex; + uint32_t lastNameIndex; + uint32_t shirtColor; + uint32_t shirtStyle; + uint32_t pantsColor; + uint32_t hairStyle; + uint32_t hairColor; + uint32_t lh; + uint32_t rh; + uint32_t eyebrows; + uint32_t eyes; + uint32_t mouth; - std::string name = PacketUtils::ReadString(8, packet, true); + CINSTREAM_SKIP_HEADER; + inStream.Read(LUWStringName); + inStream.Read(firstNameIndex); + inStream.Read(middleNameIndex); + inStream.Read(lastNameIndex); + inStream.IgnoreBytes(9); + inStream.Read(shirtColor); + inStream.Read(shirtStyle); + inStream.Read(pantsColor); + inStream.Read(hairStyle); + inStream.Read(hairColor); + inStream.Read(lh); + inStream.Read(rh); + inStream.Read(eyebrows); + inStream.Read(eyes); + inStream.Read(mouth); - uint32_t firstNameIndex = PacketUtils::ReadU32(74, packet); - uint32_t middleNameIndex = PacketUtils::ReadU32(78, packet); - uint32_t lastNameIndex = PacketUtils::ReadU32(82, packet); + const auto name = LUWStringName.GetAsString(); std::string predefinedName = GetPredefinedName(firstNameIndex, middleNameIndex, lastNameIndex); - - uint32_t shirtColor = PacketUtils::ReadU32(95, packet); - uint32_t shirtStyle = PacketUtils::ReadU32(99, packet); - uint32_t pantsColor = PacketUtils::ReadU32(103, packet); - uint32_t hairStyle = PacketUtils::ReadU32(107, packet); - uint32_t hairColor = PacketUtils::ReadU32(111, packet); - uint32_t lh = PacketUtils::ReadU32(115, packet); - uint32_t rh = PacketUtils::ReadU32(119, packet); - uint32_t eyebrows = PacketUtils::ReadU32(123, packet); - uint32_t eyes = PacketUtils::ReadU32(127, packet); - uint32_t mouth = PacketUtils::ReadU32(131, packet); - LOT shirtLOT = FindCharShirtID(shirtColor, shirtStyle); LOT pantsLOT = FindCharPantsID(pantsColor); @@ -377,7 +392,9 @@ void UserManager::DeleteCharacter(const SystemAddress& sysAddr, Packet* packet) return; } - LWOOBJID objectID = PacketUtils::ReadS64(8, packet); + CINSTREAM_SKIP_HEADER; + LWOOBJID objectID; + inStream.Read(objectID); uint32_t charID = static_cast(objectID); LOG("Received char delete req for ID: %llu (%u)", objectID, charID); @@ -411,14 +428,18 @@ void UserManager::RenameCharacter(const SystemAddress& sysAddr, Packet* packet) return; } - LWOOBJID objectID = PacketUtils::ReadS64(8, packet); + CINSTREAM_SKIP_HEADER; + LWOOBJID objectID; + inStream.Read(objectID); GeneralUtils::ClearBit(objectID, eObjectBits::CHARACTER); GeneralUtils::ClearBit(objectID, eObjectBits::PERSISTENT); uint32_t charID = static_cast(objectID); LOG("Received char rename request for ID: %llu (%u)", objectID, charID); - std::string newName = PacketUtils::ReadString(16, packet, true); + LUWString LUWStringName(33); + inStream.Read(LUWStringName); + const auto newName = LUWStringName.GetAsString(); Character* character = nullptr; diff --git a/dGame/dComponents/QuickBuildComponent.cpp b/dGame/dComponents/QuickBuildComponent.cpp index 16263d81..b8aec2bd 100644 --- a/dGame/dComponents/QuickBuildComponent.cpp +++ b/dGame/dComponents/QuickBuildComponent.cpp @@ -14,7 +14,6 @@ #include "eGameActivity.h" #include "dServer.h" -#include "PacketUtils.h" #include "Spawner.h" #include "MovingPlatformComponent.h" #include "Preconditions.h" diff --git a/dGame/dComponents/RenderComponent.cpp b/dGame/dComponents/RenderComponent.cpp index f1b8ea0c..4d8ff667 100644 --- a/dGame/dComponents/RenderComponent.cpp +++ b/dGame/dComponents/RenderComponent.cpp @@ -5,7 +5,6 @@ #include #include "Entity.h" -#include "PacketUtils.h" #include "CDClientManager.h" #include "GameMessages.h" diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index eb6f11bb..4041fded 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -1,7 +1,6 @@ #include "GameMessages.h" #include "User.h" #include "Entity.h" -#include "PacketUtils.h" #include "BitStreamUtils.h" #include "BitStream.h" #include "Game.h" @@ -1726,8 +1725,6 @@ void GameMessages::SendStartCelebrationEffect(Entity* entity, const SystemAddres bitStream.Write(0); //subtext SEND_PACKET; - - //PacketUtils::SavePacket("StartCelebrationEffect.bin", (char*)bitStream.GetData(), bitStream.GetNumberOfBytesUsed()); } @@ -1950,7 +1947,6 @@ void GameMessages::SendBBBSaveResponse(const LWOOBJID& objectId, const LWOOBJID& bitStream.Write(buffer[i]); SEND_PACKET; - //PacketUtils::SavePacket("eGameMessageType::BBB_SAVE_RESPONSE.bin", reinterpret_cast(bitStream.GetData()), bitStream.GetNumberOfBytesUsed()); } // Property diff --git a/dGame/dUtilities/Mail.cpp b/dGame/dUtilities/Mail.cpp index 2677c9cc..fc0c833e 100644 --- a/dGame/dUtilities/Mail.cpp +++ b/dGame/dUtilities/Mail.cpp @@ -12,7 +12,6 @@ #include "dServer.h" #include "Entity.h" #include "Character.h" -#include "PacketUtils.h" #include "BitStreamUtils.h" #include "Logger.h" #include "EntityManager.h" @@ -305,7 +304,6 @@ void Mail::HandleDataRequest(RakNet::BitStream* packet, const SystemAddress& sys } Game::server->Send(&bitStream, sysAddr, false); - // PacketUtils::SavePacket("Max_Mail_Data.bin", (const char*)bitStream.GetData(), bitStream.GetNumberOfBytesUsed()); } void Mail::HandleAttachmentCollect(RakNet::BitStream* packet, const SystemAddress& sysAddr, Entity* player) { diff --git a/dMasterServer/MasterServer.cpp b/dMasterServer/MasterServer.cpp index a5691e49..cdfbdf0a 100644 --- a/dMasterServer/MasterServer.cpp +++ b/dMasterServer/MasterServer.cpp @@ -36,7 +36,6 @@ #include "InstanceManager.h" #include "MasterPackets.h" #include "PersistentIDManager.h" -#include "PacketUtils.h" #include "FdbToSqlite.h" #include "BitStreamUtils.h" #include "Start.h" @@ -504,17 +503,17 @@ void HandlePacket(Packet* packet) { uint32_t theirZoneID = 0; uint32_t theirInstanceID = 0; ServerType theirServerType; - std::string theirIP = ""; + LUString theirIP(33); inStream.Read(theirPort); inStream.Read(theirZoneID); inStream.Read(theirInstanceID); inStream.Read(theirServerType); - theirIP = PacketUtils::ReadString(24, packet, false); //24 is the current offset + inStream.Read(theirIP); if (theirServerType == ServerType::World) { if (!Game::im->IsPortInUse(theirPort)) { - Instance* in = new Instance(theirIP, theirPort, theirZoneID, theirInstanceID, 0, 12, 12); + Instance* in = new Instance(theirIP.string, theirPort, theirZoneID, theirInstanceID, 0, 12, 12); SystemAddress copy; copy.binaryAddress = packet->systemAddress.binaryAddress; @@ -553,47 +552,42 @@ void HandlePacket(Packet* packet) { } case eMasterMessageType::SET_SESSION_KEY: { - RakNet::BitStream inStream(packet->data, packet->length, false); - uint64_t header = inStream.Read(header); + CINSTREAM_SKIP_HEADER; uint32_t sessionKey = 0; - std::string username; - inStream.Read(sessionKey); - username = PacketUtils::ReadString(12, packet, false); - + LUString username(33); + inStream.Read(username); + for (auto it : activeSessions) { - if (it.second == username) { + if (it.second == username.string) { activeSessions.erase(it.first); CBITSTREAM; BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::NEW_SESSION_ALERT); bitStream.Write(sessionKey); - bitStream.Write(username.size()); - for (auto character : username) { - bitStream.Write(character); - } + bitStream.Write(username); SEND_PACKET_BROADCAST; break; } } - activeSessions.insert(std::make_pair(sessionKey, username)); - LOG("Got sessionKey %i for user %s", sessionKey, username.c_str()); + activeSessions.insert(std::make_pair(sessionKey, username.string)); + LOG("Got sessionKey %i for user %s", sessionKey, username.string.c_str()); break; } case eMasterMessageType::REQUEST_SESSION_KEY: { - RakNet::BitStream inStream(packet->data, packet->length, false); - uint64_t header = inStream.Read(header); - std::string username = PacketUtils::ReadString(8, packet, false); - + CINSTREAM_SKIP_HEADER; + LUWString username(33); + inStream.Read(username); + LOG("Requesting session key for %s", username.GetAsString().c_str()); for (auto key : activeSessions) { - if (key.second == username) { + if (key.second == username.GetAsString()) { CBITSTREAM; BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::SESSION_KEY_RESPONSE); bitStream.Write(key.first); - bitStream.Write(LUString(key.second, 64)); + bitStream.Write(username); Game::server->Send(&bitStream, packet->systemAddress, false); break; } diff --git a/dNet/AuthPackets.cpp b/dNet/AuthPackets.cpp index de8f5704..a878644c 100644 --- a/dNet/AuthPackets.cpp +++ b/dNet/AuthPackets.cpp @@ -1,5 +1,4 @@ #include "AuthPackets.h" -#include "PacketUtils.h" #include "BitStreamUtils.h" #include "dNetCommon.h" @@ -297,13 +296,12 @@ void AuthPackets::SendLoginResponse(dServer* server, const SystemAddress& sysAdd for (auto& stamp : stamps) stamp.Serialize(&loginResponse); server->Send(&loginResponse, sysAddr, false); - //Inform the master server that we've created a session for this user: if (responseCode == eLoginResponse::SUCCESS) { CBITSTREAM; BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::SET_SESSION_KEY); bitStream.Write(sessionKey); - bitStream.Write(LUString(username, 66)); + bitStream.Write(LUString(username)); server->SendToMaster(&bitStream); LOG("Set sessionKey: %i for user %s", sessionKey, username.c_str()); diff --git a/dNet/ChatPackets.cpp b/dNet/ChatPackets.cpp index 63eff5ef..d0354659 100644 --- a/dNet/ChatPackets.cpp +++ b/dNet/ChatPackets.cpp @@ -7,7 +7,6 @@ #include "RakNetTypes.h" #include "BitStream.h" #include "Game.h" -#include "PacketUtils.h" #include "BitStreamUtils.h" #include "dServer.h" #include "eConnectionType.h" diff --git a/dNet/MasterPackets.cpp b/dNet/MasterPackets.cpp index 624b92ad..6953026e 100644 --- a/dNet/MasterPackets.cpp +++ b/dNet/MasterPackets.cpp @@ -1,6 +1,5 @@ #include "MasterPackets.h" #include "BitStream.h" -#include "PacketUtils.h" #include "dCommonVars.h" #include "dServer.h" #include "eConnectionType.h" @@ -88,7 +87,7 @@ void MasterPackets::SendZoneTransferResponse(dServer* server, const SystemAddres bitStream.Write(zoneInstance); bitStream.Write(zoneClone); bitStream.Write(serverPort); - bitStream.Write(LUString(serverIP, static_cast(serverIP.size() + 1))); + bitStream.Write(LUString(serverIP, 255)); server->Send(&bitStream, sysAddr, false); } @@ -100,12 +99,12 @@ void MasterPackets::HandleServerInfo(Packet* packet) { uint32_t theirPort = 0; uint32_t theirZoneID = 0; uint32_t theirInstanceID = 0; - std::string theirIP = ""; + LUString theirIP(33); inStream.Read(theirPort); inStream.Read(theirZoneID); inStream.Read(theirInstanceID); - theirIP = PacketUtils::ReadString(inStream.GetReadOffset(), packet, false); //20 is the current offset + inStream.Read(theirIP); //TODO: Actually mark this server as an available server in the manager } @@ -118,7 +117,7 @@ void MasterPackets::SendServerInfo(dServer* server, Packet* packet) { bitStream.Write(server->GetZoneID()); bitStream.Write(server->GetInstanceID()); bitStream.Write(server->GetServerType()); - bitStream.Write(LUString(server->GetIP(), server->GetIP().size())); + bitStream.Write(LUString(server->GetIP())); server->SendToMaster(&bitStream); } diff --git a/dNet/WorldPackets.cpp b/dNet/WorldPackets.cpp index 6ea0b350..f92a971f 100644 --- a/dNet/WorldPackets.cpp +++ b/dNet/WorldPackets.cpp @@ -1,7 +1,6 @@ #include "WorldPackets.h" #include "dCommonVars.h" #include "BitStream.h" -#include "PacketUtils.h" #include "GeneralUtils.h" #include "Logger.h" #include "Game.h" diff --git a/dNet/ZoneInstanceManager.cpp b/dNet/ZoneInstanceManager.cpp index f9285579..354d3634 100644 --- a/dNet/ZoneInstanceManager.cpp +++ b/dNet/ZoneInstanceManager.cpp @@ -3,7 +3,6 @@ // Custom Classes #include "MasterPackets.h" -#include "PacketUtils.h" #include "dServer.h" // C++ @@ -25,20 +24,30 @@ void ZoneInstanceManager::RequestZoneTransfer(dServer* server, uint32_t zoneID, } //! Handles a zone transfer response -void ZoneInstanceManager::HandleRequestZoneTransferResponse(uint64_t requestID, Packet* packet) { - - bool mythranShift = static_cast(packet->data[16]); - uint32_t zoneID = PacketUtils::ReadU32(17, packet); - uint32_t zoneInstance = PacketUtils::ReadU32(21, packet); - uint32_t zoneClone = PacketUtils::ReadU32(25, packet); - uint16_t serverPort = PacketUtils::ReadU16(29, packet); - std::string serverIP = PacketUtils::ReadString(31, packet, false); +void ZoneInstanceManager::HandleRequestZoneTransferResponse(Packet* packet) { + CINSTREAM_SKIP_HEADER; + uint64_t requestID; + inStream.Read(requestID); + bool mythranShift; + uint8_t tmp; + inStream.Read(tmp); + mythranShift = tmp > 0; + uint32_t zoneID; + inStream.Read(zoneID); + uint32_t zoneInstance; + inStream.Read(zoneInstance); + uint32_t zoneClone; + inStream.Read(zoneClone); + uint16_t serverPort; + inStream.Read(serverPort); + LUString serverIP(255); + inStream.Read(serverIP); for (uint32_t i = 0; i < this->requests.size(); ++i) { if (this->requests[i]->requestID == requestID) { // Call the request callback - this->requests[i]->callback(mythranShift, zoneID, zoneInstance, zoneClone, serverIP, serverPort); + this->requests[i]->callback(mythranShift, zoneID, zoneInstance, zoneClone, serverIP.string, serverPort); delete this->requests[i]; this->requests.erase(this->requests.begin() + i); diff --git a/dNet/ZoneInstanceManager.h b/dNet/ZoneInstanceManager.h index 3f8da1ae..47080cde 100644 --- a/dNet/ZoneInstanceManager.h +++ b/dNet/ZoneInstanceManager.h @@ -1,7 +1,5 @@ #pragma once -// C++ -#define _VARIADIC_MAX 10 #include #include #include @@ -56,7 +54,7 @@ public: \param requestID The request ID \param packet The packet */ - void HandleRequestZoneTransferResponse(uint64_t requestID, Packet* packet); + void HandleRequestZoneTransferResponse(Packet* packet); void CreatePrivateZone(dServer* server, uint32_t zoneID, uint32_t zoneClone, const std::string& password); diff --git a/dNet/dServer.cpp b/dNet/dServer.cpp index e60e04f9..ed66b42c 100644 --- a/dNet/dServer.cpp +++ b/dNet/dServer.cpp @@ -10,7 +10,6 @@ #include "eServerMessageType.h" #include "eMasterMessageType.h" -#include "PacketUtils.h" #include "BitStreamUtils.h" #include "MasterPackets.h" #include "ZoneInstanceManager.h" @@ -127,8 +126,7 @@ Packet* dServer::ReceiveFromMaster() { if (static_cast(packet->data[1]) == eConnectionType::MASTER) { switch (static_cast(packet->data[3])) { case eMasterMessageType::REQUEST_ZONE_TRANSFER_RESPONSE: { - uint64_t requestID = PacketUtils::ReadU64(8, packet); - ZoneInstanceManager::Instance()->HandleRequestZoneTransferResponse(requestID, packet); + ZoneInstanceManager::Instance()->HandleRequestZoneTransferResponse(packet); break; } case eMasterMessageType::SHUTDOWN: diff --git a/dWorldServer/WorldServer.cpp b/dWorldServer/WorldServer.cpp index e6a0973f..046908ff 100644 --- a/dWorldServer/WorldServer.cpp +++ b/dWorldServer/WorldServer.cpp @@ -29,7 +29,6 @@ #include #include "AuthPackets.h" -#include "PacketUtils.h" #include "BitStreamUtils.h" #include "WorldPackets.h" #include "UserManager.h" @@ -664,24 +663,25 @@ void HandleMasterPacket(Packet* packet) { if (static_cast(packet->data[1]) != eConnectionType::MASTER || packet->length < 4) return; switch (static_cast(packet->data[3])) { case eMasterMessageType::REQUEST_PERSISTENT_ID_RESPONSE: { - uint64_t requestID = PacketUtils::ReadU64(8, packet); - uint32_t objectID = PacketUtils::ReadU32(16, packet); + CINSTREAM_SKIP_HEADER; + uint64_t requestID; + inStream.Read(requestID); + uint32_t objectID; + inStream.Read(objectID); ObjectIDManager::HandleRequestPersistentIDResponse(requestID, objectID); break; } case eMasterMessageType::SESSION_KEY_RESPONSE: { //Read our session key and to which user it belongs: - RakNet::BitStream inStream(packet->data, packet->length, false); - uint64_t header = inStream.Read(header); + CINSTREAM_SKIP_HEADER; uint32_t sessionKey = 0; - std::string username; - inStream.Read(sessionKey); - username = PacketUtils::ReadString(12, packet, false); + LUWString username(33); + inStream.Read(username); //Find them: - auto it = m_PendingUsers.find(username); + auto it = m_PendingUsers.find(username.GetAsString()); if (it == m_PendingUsers.end()) return; //Convert our key: @@ -694,12 +694,12 @@ void HandleMasterPacket(Packet* packet) { Game::server->Disconnect(it->second.sysAddr, eServerDisconnectIdentifiers::INVALID_SESSION_KEY); return; } else { - LOG("User %s authenticated with correct key.", username.c_str()); + LOG("User %s authenticated with correct key.", username.GetAsString().c_str()); UserManager::Instance()->DeleteUser(packet->systemAddress); //Create our user and send them in: - UserManager::Instance()->CreateUser(it->second.sysAddr, username, userHash); + UserManager::Instance()->CreateUser(it->second.sysAddr, username.GetAsString(), userHash); auto zone = Game::zoneManager->GetZone(); if (zone) { @@ -722,7 +722,7 @@ void HandleMasterPacket(Packet* packet) { UserManager::Instance()->RequestCharacterList(it->second.sysAddr); } - m_PendingUsers.erase(username); + m_PendingUsers.erase(username.GetAsString()); //Notify master: { @@ -737,8 +737,9 @@ void HandleMasterPacket(Packet* packet) { break; } case eMasterMessageType::AFFIRM_TRANSFER_REQUEST: { - const uint64_t requestID = PacketUtils::ReadU64(8, packet); - + CINSTREAM_SKIP_HEADER; + uint64_t requestID; + inStream.Read(requestID); LOG("Got affirmation request of transfer %llu", requestID); CBITSTREAM; @@ -757,30 +758,22 @@ void HandleMasterPacket(Packet* packet) { } case eMasterMessageType::NEW_SESSION_ALERT: { - RakNet::BitStream inStream(packet->data, packet->length, false); - uint64_t header = inStream.Read(header); + CINSTREAM_SKIP_HEADER; uint32_t sessionKey = inStream.Read(sessionKey); - std::string username; - - uint32_t len; - inStream.Read(len); - - for (uint32_t i = 0; i < len; i++) { - char character; inStream.Read(character); - username += character; - } - + LUString username(33); + inStream.Read(username); + LOG("Got new session alert for user %s", username.string.c_str()); //Find them: - User* user = UserManager::Instance()->GetUser(username.c_str()); + User* user = UserManager::Instance()->GetUser(username.string.c_str()); if (!user) { - LOG("Got new session alert for user %s, but they're not logged in.", username.c_str()); + LOG("But they're not logged in?"); return; } //Check the key: if (sessionKey != std::atoi(user->GetSessionKey().c_str())) { - LOG("Got new session alert for user %s, but the session key is invalid.", username.c_str()); + LOG("But the session key is invalid!", username.string.c_str()); Game::server->Disconnect(user->GetSystemAddress(), eServerDisconnectIdentifiers::INVALID_SESSION_KEY); return; } @@ -853,16 +846,19 @@ void HandlePacket(Packet* packet) { switch (static_cast(packet->data[3])) { case eWorldMessageType::VALIDATION: { - std::string username = PacketUtils::ReadString(0x08, packet, true); - std::string sessionKey = PacketUtils::ReadString(74, packet, true); - std::string clientDatabaseChecksum = PacketUtils::ReadString(packet->length - 33, packet, false); + CINSTREAM_SKIP_HEADER; + LUWString username(33); + inStream.Read(username); + LUWString sessionKey(33); // sometimes client puts a null terminator at the end of the checksum and sometimes doesn't, weird - clientDatabaseChecksum = clientDatabaseChecksum.substr(0, 32); + inStream.Read(sessionKey); + LUString clientDatabaseChecksum(32); + inStream.Read(clientDatabaseChecksum); // If the check is turned on, validate the client's database checksum. if (Game::config->GetValue("check_fdb") == "1" && !databaseChecksum.empty()) { - auto accountInfo = Database::Get()->GetAccountInfo(username); + auto accountInfo = Database::Get()->GetAccountInfo(username.GetAsString()); if (!accountInfo) { LOG("Client's account does not exist in the database, aborting connection."); Game::server->Disconnect(packet->systemAddress, eServerDisconnectIdentifiers::CHARACTER_NOT_FOUND); @@ -870,7 +866,7 @@ void HandlePacket(Packet* packet) { } // Developers may skip this check - if (accountInfo->maxGmLevel < eGameMasterLevel::DEVELOPER && clientDatabaseChecksum != databaseChecksum) { + if (accountInfo->maxGmLevel < eGameMasterLevel::DEVELOPER && clientDatabaseChecksum.string != databaseChecksum) { LOG("Client's database checksum does not match the server's, aborting connection."); Game::server->Disconnect(packet->systemAddress, eServerDisconnectIdentifiers::WRONG_GAME_VERSION); return; @@ -880,14 +876,14 @@ void HandlePacket(Packet* packet) { //Request the session info from Master: CBITSTREAM; BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::REQUEST_SESSION_KEY); - bitStream.Write(LUString(username, 64)); + bitStream.Write(username); Game::server->SendToMaster(&bitStream); //Insert info into our pending list tempSessionInfo info; info.sysAddr = SystemAddress(packet->systemAddress); - info.hash = sessionKey; - m_PendingUsers.insert(std::make_pair(username, info)); + info.hash = sessionKey.GetAsString(); + m_PendingUsers.insert(std::make_pair(username.GetAsString(), info)); break; } @@ -1098,7 +1094,6 @@ void HandlePacket(Packet* packet) { SystemAddress sysAddr = packet->systemAddress; SEND_PACKET; - // PacketUtils::SavePacket("lxfml packet " + std::to_string(bbbModel.id) + ".bin", (char*)bitStream.GetData(), bitStream.GetNumberOfBytesUsed()); } }