mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-24 14:37:25 +00:00
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
This commit is contained in:
parent
b683413a60
commit
dbe4a0ced3
@ -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"
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include "CDClientManager.h"
|
||||
#include "Game.h"
|
||||
#include "Logger.h"
|
||||
#include "PacketUtils.h"
|
||||
#include <functional>
|
||||
#include "CDDestructibleComponentTable.h"
|
||||
#include "CDClientDatabase.h"
|
||||
|
@ -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) {
|
||||
|
@ -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<uint32_t>(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<uint32_t>(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;
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include "eGameActivity.h"
|
||||
|
||||
#include "dServer.h"
|
||||
#include "PacketUtils.h"
|
||||
#include "Spawner.h"
|
||||
#include "MovingPlatformComponent.h"
|
||||
#include "Preconditions.h"
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include <iomanip>
|
||||
|
||||
#include "Entity.h"
|
||||
#include "PacketUtils.h"
|
||||
|
||||
#include "CDClientManager.h"
|
||||
#include "GameMessages.h"
|
||||
|
@ -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<uint32_t>(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<char*>(bitStream.GetData()), bitStream.GetNumberOfBytesUsed());
|
||||
}
|
||||
|
||||
// Property
|
||||
|
@ -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) {
|
||||
|
@ -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<uint32_t>(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;
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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"
|
||||
|
@ -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<uint16_t>(serverPort);
|
||||
bitStream.Write(LUString(serverIP, static_cast<uint32_t>(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);
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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<bool>(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);
|
||||
|
@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// C++
|
||||
#define _VARIADIC_MAX 10
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@ -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);
|
||||
|
||||
|
@ -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<eConnectionType>(packet->data[1]) == eConnectionType::MASTER) {
|
||||
switch (static_cast<eMasterMessageType>(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:
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include <csignal>
|
||||
|
||||
#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<eConnectionType>(packet->data[1]) != eConnectionType::MASTER || packet->length < 4) return;
|
||||
switch (static_cast<eMasterMessageType>(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<char>(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<eWorldMessageType>(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());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user