mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-10-15 03:48:07 +00:00
Merge remote-tracking branch 'refs/remotes/origin/main'
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
set(DWORLDSERVER_SOURCES
|
||||
"ObjectIDManager.cpp"
|
||||
"PerformanceManager.cpp"
|
||||
)
|
||||
|
||||
add_library(dWorldServer ${DWORLDSERVER_SOURCES})
|
||||
add_executable(WorldServer "WorldServer.cpp")
|
||||
add_compile_definitions(WorldServer PRIVATE PROJECT_VERSION="\"${PROJECT_VERSION}\"")
|
||||
|
||||
target_link_libraries(dWorldServer ${COMMON_LIBRARIES})
|
||||
target_link_libraries(WorldServer ${COMMON_LIBRARIES} dChatFilter dGame dZoneManager dPhysics Detour Recast tinyxml2 dWorldServer dNavigation)
|
||||
target_link_libraries(WorldServer ${COMMON_LIBRARIES} dChatFilter dGame dZoneManager dPhysics Detour Recast tinyxml2 dWorldServer dNavigation dServer)
|
||||
target_include_directories(WorldServer PRIVATE ${PROJECT_SOURCE_DIR}/dServer)
|
||||
|
||||
|
@@ -1,55 +0,0 @@
|
||||
#include "ObjectIDManager.h"
|
||||
|
||||
// Custom Classes
|
||||
#include "MasterPackets.h"
|
||||
#include "Database.h"
|
||||
#include "Logger.h"
|
||||
#include "Game.h"
|
||||
|
||||
// Static Variables
|
||||
ObjectIDManager* ObjectIDManager::m_Address = nullptr;
|
||||
static std::uniform_int_distribution<int> uni(10000000, INT32_MAX);
|
||||
|
||||
//! Initializes the manager
|
||||
void ObjectIDManager::Initialize(void) {
|
||||
//this->currentRequestID = 0;
|
||||
this->currentObjectID = uint32_t(1152921508165007067); //Initial value for this server's objectIDs
|
||||
}
|
||||
|
||||
//! Requests a persistent ID
|
||||
void ObjectIDManager::RequestPersistentID(std::function<void(uint32_t)> callback) {
|
||||
PersistentIDRequest* request = new PersistentIDRequest();
|
||||
request->requestID = ++this->currentRequestID;
|
||||
request->callback = callback;
|
||||
|
||||
this->requests.push_back(request);
|
||||
|
||||
MasterPackets::SendPersistentIDRequest(Game::server, request->requestID);
|
||||
}
|
||||
|
||||
//! Handles a persistent ID response
|
||||
void ObjectIDManager::HandleRequestPersistentIDResponse(uint64_t requestID, uint32_t persistentID) {
|
||||
for (uint32_t i = 0; i < this->requests.size(); ++i) {
|
||||
if (this->requests[i]->requestID == requestID) {
|
||||
|
||||
// Call the callback function
|
||||
this->requests[i]->callback(persistentID);
|
||||
|
||||
// Then delete the request
|
||||
delete this->requests[i];
|
||||
this->requests.erase(this->requests.begin() + i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! Handles cases where we have to get a unique object ID synchronously
|
||||
uint32_t ObjectIDManager::GenerateRandomObjectID() {
|
||||
return uni(Game::randomEngine);
|
||||
}
|
||||
|
||||
|
||||
//! Generates an object ID server-sided (used for regular entities like smashables)
|
||||
uint32_t ObjectIDManager::GenerateObjectID(void) {
|
||||
return ++this->currentObjectID;
|
||||
}
|
@@ -1,75 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// C++
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
|
||||
/*!
|
||||
\file ObjectIDManager.hpp
|
||||
\brief A manager for handling object ID generation
|
||||
*/
|
||||
|
||||
//! The persistent ID request
|
||||
struct PersistentIDRequest {
|
||||
uint64_t requestID;
|
||||
|
||||
std::function<void(uint32_t)> callback;
|
||||
};
|
||||
|
||||
//! The Object ID Manager
|
||||
class ObjectIDManager {
|
||||
private:
|
||||
static ObjectIDManager* m_Address; //!< The singleton instance
|
||||
|
||||
std::vector<PersistentIDRequest*> requests; //!< All outstanding persistent ID requests
|
||||
uint64_t currentRequestID; //!< The current request ID
|
||||
|
||||
uint32_t currentObjectID; //!< The current object ID
|
||||
|
||||
public:
|
||||
|
||||
//! The singleton instance
|
||||
static ObjectIDManager* Instance() {
|
||||
if (m_Address == 0) {
|
||||
m_Address = new ObjectIDManager;
|
||||
}
|
||||
|
||||
return m_Address;
|
||||
}
|
||||
|
||||
//! Initializes the manager
|
||||
void Initialize(void);
|
||||
|
||||
//! Requests a persistent ID
|
||||
/*!
|
||||
\param callback The callback function
|
||||
*/
|
||||
void RequestPersistentID(std::function<void(uint32_t)> callback);
|
||||
|
||||
|
||||
//! Handles a persistent ID response
|
||||
/*!
|
||||
\param requestID The request ID
|
||||
\param persistentID The persistent ID
|
||||
*/
|
||||
void HandleRequestPersistentIDResponse(uint64_t requestID, uint32_t persistentID);
|
||||
|
||||
//! Generates an object ID server-sided
|
||||
/*!
|
||||
\return A generated object ID
|
||||
*/
|
||||
uint32_t GenerateObjectID(void);
|
||||
|
||||
//! Generates a random object ID server-sided
|
||||
/*!
|
||||
\return A generated object ID
|
||||
*/
|
||||
static uint32_t GenerateRandomObjectID();
|
||||
|
||||
//! Generates a persistent object ID server-sided
|
||||
/*!
|
||||
\return A generated object ID
|
||||
*/
|
||||
uint32_t GeneratePersistentObjectID(void);
|
||||
};
|
@@ -18,6 +18,7 @@
|
||||
#include "PerformanceManager.h"
|
||||
#include "Diagnostics.h"
|
||||
#include "BinaryPathFinder.h"
|
||||
#include "dPlatforms.h"
|
||||
|
||||
//RakNet includes:
|
||||
#include "RakNetDefines.h"
|
||||
@@ -28,7 +29,6 @@
|
||||
#include <csignal>
|
||||
|
||||
#include "AuthPackets.h"
|
||||
#include "PacketUtils.h"
|
||||
#include "BitStreamUtils.h"
|
||||
#include "WorldPackets.h"
|
||||
#include "UserManager.h"
|
||||
@@ -74,6 +74,11 @@
|
||||
#include "ZCompression.h"
|
||||
#include "EntityManager.h"
|
||||
#include "CheatDetection.h"
|
||||
#include "eGameMasterLevel.h"
|
||||
#include "StringifiedEnum.h"
|
||||
#include "Server.h"
|
||||
#include "PositionUpdate.h"
|
||||
#include "PlayerManager.h"
|
||||
|
||||
#include "ServerPreconditions.h"
|
||||
#include "Scene.h"
|
||||
@@ -88,9 +93,10 @@ namespace Game {
|
||||
RakPeerInterface* chatServer = nullptr;
|
||||
std::mt19937 randomEngine;
|
||||
SystemAddress chatSysAddr;
|
||||
bool shouldShutdown = false;
|
||||
Game::signal_t lastSignal = 0;
|
||||
EntityManager* entityManager = nullptr;
|
||||
dZoneManager* zoneManager = nullptr;
|
||||
std::string projectVersion = PROJECT_VERSION;
|
||||
} // namespace Game
|
||||
|
||||
bool chatDisabled = false;
|
||||
@@ -101,8 +107,8 @@ void WorldShutdownProcess(uint32_t zoneId);
|
||||
void FinalizeShutdown();
|
||||
void SendShutdownMessageToMaster();
|
||||
|
||||
Logger* SetupLogger(uint32_t zoneID, uint32_t instanceID);
|
||||
void HandlePacketChat(Packet* packet);
|
||||
void HandleMasterPacket(Packet* packet);
|
||||
void HandlePacket(Packet* packet);
|
||||
|
||||
struct tempSessionInfo {
|
||||
@@ -123,8 +129,8 @@ int main(int argc, char** argv) {
|
||||
// Triggers the shutdown sequence at application exit
|
||||
std::atexit(WorldShutdownSequence);
|
||||
|
||||
signal(SIGINT, [](int) { WorldShutdownSequence(); });
|
||||
signal(SIGTERM, [](int) { WorldShutdownSequence(); });
|
||||
std::signal(SIGINT, Game::OnSignal);
|
||||
std::signal(SIGTERM, Game::OnSignal);
|
||||
|
||||
uint32_t zoneID = 1000;
|
||||
uint32_t cloneID = 0;
|
||||
@@ -142,17 +148,14 @@ int main(int argc, char** argv) {
|
||||
if (argument == "-port") ourPort = atoi(argv[i + 1]);
|
||||
}
|
||||
|
||||
Game::config = new dConfig("worldconfig.ini");
|
||||
|
||||
//Create all the objects we need to run our service:
|
||||
Game::logger = SetupLogger(zoneID, instanceID);
|
||||
Server::SetupLogger("WorldServer_" + std::to_string(zoneID) + "_" + std::to_string(instanceID));
|
||||
if (!Game::logger) return EXIT_FAILURE;
|
||||
|
||||
//Read our config:
|
||||
Game::config = new dConfig((BinaryPathFinder::GetBinaryDir() / "worldconfig.ini").string());
|
||||
Game::logger->SetLogToConsole(Game::config->GetValue("log_to_console") != "0");
|
||||
Game::logger->SetLogDebugStatements(Game::config->GetValue("log_debug_statements") == "1");
|
||||
|
||||
LOG("Starting World server...");
|
||||
LOG("Version: %i.%i", PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR);
|
||||
LOG("Version: %s", Game::projectVersion.c_str());
|
||||
LOG("Compiled on: %s", __TIMESTAMP__);
|
||||
|
||||
if (Game::config->GetValue("disable_chat") == "1") chatDisabled = true;
|
||||
@@ -181,13 +184,7 @@ int main(int argc, char** argv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
CDClientManager::Instance();
|
||||
|
||||
//Connect to the MySQL Database
|
||||
std::string mysql_host = Game::config->GetValue("mysql_host");
|
||||
std::string mysql_database = Game::config->GetValue("mysql_database");
|
||||
std::string mysql_username = Game::config->GetValue("mysql_username");
|
||||
std::string mysql_password = Game::config->GetValue("mysql_password");
|
||||
CDClientManager::Instance().LoadValuesFromDatabase();
|
||||
|
||||
Diagnostics::SetProduceMemoryDump(Game::config->GetValue("generate_dump") == "1");
|
||||
|
||||
@@ -195,8 +192,9 @@ int main(int argc, char** argv) {
|
||||
Diagnostics::SetOutDirectory(Game::config->GetValue("dump_folder"));
|
||||
}
|
||||
|
||||
//Connect to the MySQL Database:
|
||||
try {
|
||||
Database::Connect(mysql_host, mysql_database, mysql_username, mysql_password);
|
||||
Database::Connect();
|
||||
} catch (sql::SQLException& ex) {
|
||||
LOG("Got an error while connecting to the database: %s", ex.what());
|
||||
return EXIT_FAILURE;
|
||||
@@ -205,27 +203,26 @@ int main(int argc, char** argv) {
|
||||
//Find out the master's IP:
|
||||
std::string masterIP = "localhost";
|
||||
uint32_t masterPort = 1000;
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("SELECT ip, port FROM servers WHERE name='master';");
|
||||
auto res = stmt->executeQuery();
|
||||
while (res->next()) {
|
||||
masterIP = res->getString(1).c_str();
|
||||
masterPort = res->getInt(2);
|
||||
auto masterInfo = Database::Get()->GetMasterInfo();
|
||||
|
||||
if (masterInfo) {
|
||||
masterIP = masterInfo->ip;
|
||||
masterPort = masterInfo->port;
|
||||
}
|
||||
|
||||
delete res;
|
||||
delete stmt;
|
||||
|
||||
ObjectIDManager::Instance()->Initialize();
|
||||
UserManager::Instance()->Initialize();
|
||||
Game::chatFilter = new dChatFilter(Game::assetManager->GetResPath().string() + "/chatplus_en_us", bool(std::stoi(Game::config->GetValue("dont_generate_dcf"))));
|
||||
|
||||
Game::server = new dServer(masterIP, ourPort, instanceID, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::World, Game::config, &Game::shouldShutdown, zoneID);
|
||||
bool dontGenerateDCF = false;
|
||||
GeneralUtils::TryParse(Game::config->GetValue("dont_generate_dcf"), dontGenerateDCF);
|
||||
Game::chatFilter = new dChatFilter(Game::assetManager->GetResPath().string() + "/chatplus_en_us", dontGenerateDCF);
|
||||
|
||||
Game::server = new dServer(masterIP, ourPort, instanceID, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::World, Game::config, &Game::lastSignal, zoneID);
|
||||
|
||||
//Connect to the chat server:
|
||||
uint32_t chatPort = 1501;
|
||||
if (Game::config->GetValue("chat_server_port") != "") chatPort = std::atoi(Game::config->GetValue("chat_server_port").c_str());
|
||||
|
||||
auto chatSock = SocketDescriptor(uint16_t(ourPort + 2), 0);
|
||||
auto chatSock = SocketDescriptor(static_cast<uint16_t>(ourPort + 2), 0);
|
||||
Game::chatServer = RakNetworkFactory::GetRakPeerInterface();
|
||||
Game::chatServer->Startup(1, 30, &chatSock, 1);
|
||||
Game::chatServer->Connect(masterIP.c_str(), chatPort, "3.25 ND1", 8);
|
||||
@@ -330,6 +327,8 @@ int main(int argc, char** argv) {
|
||||
uint32_t saveTime = 10 * 60 * currentFramerate; // 10 minutes in frames
|
||||
uint32_t sqlPingTime = 10 * 60 * currentFramerate; // 10 minutes in frames
|
||||
uint32_t emptyShutdownTime = (cloneID == 0 ? 30 : 5) * 60 * currentFramerate; // 30 minutes for main worlds, 5 for all others.
|
||||
|
||||
Game::logger->Flush(); // once immediately before the main loop
|
||||
while (true) {
|
||||
Metrics::StartMeasurement(MetricVariable::Frame);
|
||||
Metrics::StartMeasurement(MetricVariable::GameLoop);
|
||||
@@ -380,9 +379,9 @@ int main(int argc, char** argv) {
|
||||
if (!Game::server->GetIsConnectedToMaster()) {
|
||||
framesSinceMasterDisconnect++;
|
||||
|
||||
if (framesSinceMasterDisconnect >= noMasterConnectionTimeout && !Game::shouldShutdown) {
|
||||
if (framesSinceMasterDisconnect >= noMasterConnectionTimeout && !Game::ShouldShutdown()) {
|
||||
LOG("Game loop running but no connection to master for %d frames, shutting down", noMasterConnectionTimeout);
|
||||
Game::shouldShutdown = true;
|
||||
Game::lastSignal = -1;
|
||||
}
|
||||
} else framesSinceMasterDisconnect = 0;
|
||||
|
||||
@@ -425,7 +424,7 @@ int main(int argc, char** argv) {
|
||||
//Check for packets here:
|
||||
packet = Game::server->ReceiveFromMaster();
|
||||
if (packet) { //We can get messages not handle-able by the dServer class, so handle them if we returned anything.
|
||||
HandlePacket(packet);
|
||||
HandleMasterPacket(packet);
|
||||
Game::server->DeallocateMasterPacket(packet);
|
||||
}
|
||||
|
||||
@@ -477,7 +476,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
//If we haven't had any players for a while, time out and shut down:
|
||||
if (framesSinceLastUser >= emptyShutdownTime) {
|
||||
Game::shouldShutdown = true;
|
||||
Game::lastSignal = -1;
|
||||
}
|
||||
} else {
|
||||
framesSinceLastUser = 0;
|
||||
@@ -498,16 +497,12 @@ int main(int argc, char** argv) {
|
||||
//Find out the master's IP for absolutely no reason:
|
||||
std::string masterIP;
|
||||
uint32_t masterPort;
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("SELECT ip, port FROM servers WHERE name='master';");
|
||||
auto res = stmt->executeQuery();
|
||||
while (res->next()) {
|
||||
masterIP = res->getString(1).c_str();
|
||||
masterPort = res->getInt(2);
|
||||
auto masterInfo = Database::Get()->GetMasterInfo();
|
||||
if (masterInfo) {
|
||||
masterIP = masterInfo->ip;
|
||||
masterPort = masterInfo->port;
|
||||
}
|
||||
|
||||
delete res;
|
||||
delete stmt;
|
||||
|
||||
framesSinceLastSQLPing = 0;
|
||||
} else framesSinceLastSQLPing++;
|
||||
|
||||
@@ -534,7 +529,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
|
||||
if (Game::shouldShutdown && !worldShutdownSequenceComplete) {
|
||||
if (Game::ShouldShutdown() && !worldShutdownSequenceComplete) {
|
||||
WorldShutdownProcess(zoneID);
|
||||
break;
|
||||
}
|
||||
@@ -546,18 +541,6 @@ int main(int argc, char** argv) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Logger* SetupLogger(uint32_t zoneID, uint32_t instanceID) {
|
||||
std::string logPath = (BinaryPathFinder::GetBinaryDir() / ("logs/WorldServer_" + std::to_string(zoneID) + "_" + std::to_string(instanceID) + "_" + std::to_string(time(nullptr)) + ".log")).string();
|
||||
bool logToConsole = false;
|
||||
bool logDebugStatements = false;
|
||||
#ifdef _DEBUG
|
||||
logToConsole = true;
|
||||
logDebugStatements = true;
|
||||
#endif
|
||||
|
||||
return new Logger(logPath, logToConsole, logDebugStatements);
|
||||
}
|
||||
|
||||
void HandlePacketChat(Packet* packet) {
|
||||
if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) {
|
||||
LOG("Lost our connection to chat, zone(%i), instance(%i)", Game::server->GetZoneID(), Game::server->GetInstanceID());
|
||||
@@ -689,6 +672,132 @@ void HandlePacketChat(Packet* packet) {
|
||||
}
|
||||
}
|
||||
|
||||
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: {
|
||||
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:
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
uint32_t sessionKey = 0;
|
||||
inStream.Read(sessionKey);
|
||||
LUWString username;
|
||||
inStream.Read(username);
|
||||
|
||||
//Find them:
|
||||
auto it = m_PendingUsers.find(username.GetAsString());
|
||||
if (it == m_PendingUsers.end()) return;
|
||||
|
||||
//Convert our key:
|
||||
std::string userHash = std::to_string(sessionKey);
|
||||
userHash = md5(userHash);
|
||||
|
||||
//Verify it:
|
||||
if (userHash != it->second.hash) {
|
||||
LOG("SOMEONE IS TRYING TO HACK? SESSION KEY MISMATCH: ours: %s != master: %s", userHash.c_str(), it->second.hash.c_str());
|
||||
Game::server->Disconnect(it->second.sysAddr, eServerDisconnectIdentifiers::INVALID_SESSION_KEY);
|
||||
return;
|
||||
} else {
|
||||
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.GetAsString(), userHash);
|
||||
|
||||
auto zone = Game::zoneManager->GetZone();
|
||||
if (zone) {
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
float z = 0.0f;
|
||||
|
||||
if (zone->GetZoneID().GetMapID() == 1100) {
|
||||
auto pos = zone->GetSpawnPos();
|
||||
x = pos.x;
|
||||
y = pos.y;
|
||||
z = pos.z;
|
||||
}
|
||||
|
||||
WorldPackets::SendLoadStaticZone(it->second.sysAddr, x, y, z, zone->GetChecksum(), Game::zoneManager->GetZoneID());
|
||||
}
|
||||
|
||||
if (Game::server->GetZoneID() == 0) {
|
||||
//Since doing this reroute breaks the client's request, we have to call this manually.
|
||||
UserManager::Instance()->RequestCharacterList(it->second.sysAddr);
|
||||
}
|
||||
|
||||
m_PendingUsers.erase(username.GetAsString());
|
||||
|
||||
//Notify master:
|
||||
{
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::PLAYER_ADDED);
|
||||
bitStream.Write((LWOMAPID)Game::server->GetZoneID());
|
||||
bitStream.Write((LWOINSTANCEID)instanceID);
|
||||
Game::server->SendToMaster(&bitStream);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case eMasterMessageType::AFFIRM_TRANSFER_REQUEST: {
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
uint64_t requestID;
|
||||
inStream.Read(requestID);
|
||||
LOG("Got affirmation request of transfer %llu", requestID);
|
||||
|
||||
CBITSTREAM;
|
||||
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::AFFIRM_TRANSFER_RESPONSE);
|
||||
bitStream.Write(requestID);
|
||||
Game::server->SendToMaster(&bitStream);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case eMasterMessageType::SHUTDOWN: {
|
||||
Game::lastSignal = -1;
|
||||
LOG("Got shutdown request from master, zone (%i), instance (%i)", Game::server->GetZoneID(), Game::server->GetInstanceID());
|
||||
break;
|
||||
}
|
||||
|
||||
case eMasterMessageType::NEW_SESSION_ALERT: {
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
uint32_t sessionKey = inStream.Read(sessionKey);
|
||||
|
||||
LUString username;
|
||||
inStream.Read(username);
|
||||
LOG("Got new session alert for user %s", username.string.c_str());
|
||||
//Find them:
|
||||
User* user = UserManager::Instance()->GetUser(username.string.c_str());
|
||||
if (!user) {
|
||||
LOG("But they're not logged in?");
|
||||
return;
|
||||
}
|
||||
|
||||
//Check the key:
|
||||
if (sessionKey != std::atoi(user->GetSessionKey().c_str())) {
|
||||
LOG("But the session key is invalid!", username.string.c_str());
|
||||
Game::server->Disconnect(user->GetSystemAddress(), eServerDisconnectIdentifiers::INVALID_SESSION_KEY);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG("Unknown packet ID from master %i", int(packet->data[3]));
|
||||
}
|
||||
}
|
||||
|
||||
void HandlePacket(Packet* packet) {
|
||||
if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) {
|
||||
auto user = UserManager::Instance()->GetUser(packet->systemAddress);
|
||||
@@ -703,7 +812,7 @@ void HandlePacket(Packet* packet) {
|
||||
auto* entity = Game::entityManager->GetEntity(c->GetObjectID());
|
||||
|
||||
if (!entity) {
|
||||
entity = Player::GetPlayer(packet->systemAddress);
|
||||
entity = PlayerManager::GetPlayer(packet->systemAddress);
|
||||
}
|
||||
|
||||
if (entity) {
|
||||
@@ -747,172 +856,31 @@ void HandlePacket(Packet* packet) {
|
||||
}
|
||||
}
|
||||
|
||||
if (static_cast<eConnectionType>(packet->data[1]) == eConnectionType::MASTER) {
|
||||
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);
|
||||
ObjectIDManager::Instance()->HandleRequestPersistentIDResponse(requestID, objectID);
|
||||
break;
|
||||
}
|
||||
|
||||
case eMasterMessageType::REQUEST_ZONE_TRANSFER_RESPONSE: {
|
||||
uint64_t requestID = PacketUtils::ReadU64(8, packet);
|
||||
ZoneInstanceManager::Instance()->HandleRequestZoneTransferResponse(requestID, packet);
|
||||
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);
|
||||
uint32_t sessionKey = 0;
|
||||
std::string username;
|
||||
|
||||
inStream.Read(sessionKey);
|
||||
username = PacketUtils::ReadString(12, packet, false);
|
||||
|
||||
//Find them:
|
||||
auto it = m_PendingUsers.find(username);
|
||||
if (it == m_PendingUsers.end()) return;
|
||||
|
||||
//Convert our key:
|
||||
std::string userHash = std::to_string(sessionKey);
|
||||
userHash = md5(userHash);
|
||||
|
||||
//Verify it:
|
||||
if (userHash != it->second.hash) {
|
||||
LOG("SOMEONE IS TRYING TO HACK? SESSION KEY MISMATCH: ours: %s != master: %s", userHash.c_str(), it->second.hash.c_str());
|
||||
Game::server->Disconnect(it->second.sysAddr, eServerDisconnectIdentifiers::INVALID_SESSION_KEY);
|
||||
return;
|
||||
} else {
|
||||
LOG("User %s authenticated with correct key.", username.c_str());
|
||||
|
||||
UserManager::Instance()->DeleteUser(packet->systemAddress);
|
||||
|
||||
//Create our user and send them in:
|
||||
UserManager::Instance()->CreateUser(it->second.sysAddr, username, userHash);
|
||||
|
||||
auto zone = Game::zoneManager->GetZone();
|
||||
if (zone) {
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
float z = 0.0f;
|
||||
|
||||
if (zone->GetZoneID().GetMapID() == 1100) {
|
||||
auto pos = zone->GetSpawnPos();
|
||||
x = pos.x;
|
||||
y = pos.y;
|
||||
z = pos.z;
|
||||
}
|
||||
|
||||
WorldPackets::SendLoadStaticZone(it->second.sysAddr, x, y, z, zone->GetChecksum());
|
||||
}
|
||||
|
||||
if (Game::server->GetZoneID() == 0) {
|
||||
//Since doing this reroute breaks the client's request, we have to call this manually.
|
||||
UserManager::Instance()->RequestCharacterList(it->second.sysAddr);
|
||||
}
|
||||
|
||||
m_PendingUsers.erase(username);
|
||||
|
||||
//Notify master:
|
||||
{
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::PLAYER_ADDED);
|
||||
bitStream.Write((LWOMAPID)Game::server->GetZoneID());
|
||||
bitStream.Write((LWOINSTANCEID)instanceID);
|
||||
Game::server->SendToMaster(&bitStream);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case eMasterMessageType::AFFIRM_TRANSFER_REQUEST: {
|
||||
const uint64_t requestID = PacketUtils::ReadU64(8, packet);
|
||||
|
||||
LOG("Got affirmation request of transfer %llu", requestID);
|
||||
|
||||
CBITSTREAM;
|
||||
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::AFFIRM_TRANSFER_RESPONSE);
|
||||
bitStream.Write(requestID);
|
||||
Game::server->SendToMaster(&bitStream);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case eMasterMessageType::SHUTDOWN: {
|
||||
Game::shouldShutdown = true;
|
||||
LOG("Got shutdown request from master, zone (%i), instance (%i)", Game::server->GetZoneID(), Game::server->GetInstanceID());
|
||||
break;
|
||||
}
|
||||
|
||||
case eMasterMessageType::NEW_SESSION_ALERT: {
|
||||
RakNet::BitStream inStream(packet->data, packet->length, false);
|
||||
uint64_t header = inStream.Read(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;
|
||||
}
|
||||
|
||||
//Find them:
|
||||
User* user = UserManager::Instance()->GetUser(username.c_str());
|
||||
if (!user) {
|
||||
LOG("Got new session alert for user %s, but they're not logged in.", username.c_str());
|
||||
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());
|
||||
Game::server->Disconnect(user->GetSystemAddress(), eServerDisconnectIdentifiers::INVALID_SESSION_KEY);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
LOG("Unknown packet ID from master %i", int(packet->data[3]));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (static_cast<eConnectionType>(packet->data[1]) != eConnectionType::WORLD) return;
|
||||
|
||||
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;
|
||||
inStream.Read(username);
|
||||
|
||||
LUWString sessionKey;
|
||||
// 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()) {
|
||||
uint32_t gmLevel = 0;
|
||||
auto* stmt = Database::CreatePreppedStmt("SELECT gm_level FROM accounts WHERE name=? LIMIT 1;");
|
||||
stmt->setString(1, username.c_str());
|
||||
|
||||
auto* res = stmt->executeQuery();
|
||||
while (res->next()) {
|
||||
gmLevel = res->getInt(1);
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
delete stmt;
|
||||
delete res;
|
||||
|
||||
// Developers may skip this check
|
||||
if (gmLevel < 8 && 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;
|
||||
@@ -922,14 +890,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;
|
||||
}
|
||||
@@ -976,7 +944,7 @@ void HandlePacket(Packet* packet) {
|
||||
CheckType::Entity,
|
||||
"Sending GM with a sending player that does not match their own. GM ID: %i",
|
||||
static_cast<int32_t>(messageID)
|
||||
);
|
||||
);
|
||||
|
||||
if (isSender) GameMessageHandler::HandleMessage(&dataStream, packet->systemAddress, objectID, messageID);
|
||||
break;
|
||||
@@ -1000,7 +968,7 @@ void HandlePacket(Packet* packet) {
|
||||
CheckType::User,
|
||||
"Sending login request with a sending player that does not match their own. Player ID: %llu",
|
||||
playerID
|
||||
);
|
||||
);
|
||||
|
||||
if (!valid) return;
|
||||
|
||||
@@ -1048,7 +1016,10 @@ void HandlePacket(Packet* packet) {
|
||||
info.lot = 1;
|
||||
Entity* player = Game::entityManager->CreateEntity(info, UserManager::Instance()->GetUser(packet->systemAddress));
|
||||
|
||||
WorldPackets::SendCreateCharacter(packet->systemAddress, player, c->GetXMLData(), username, c->GetGMLevel());
|
||||
auto* characterComponent = player->GetComponent<CharacterComponent>();
|
||||
if (!characterComponent) return;
|
||||
|
||||
WorldPackets::SendCreateCharacter(packet->systemAddress, player->GetComponent<CharacterComponent>()->GetReputation(), player->GetObjectID(), c->GetXMLData(), username, c->GetGMLevel());
|
||||
WorldPackets::SendServerState(packet->systemAddress);
|
||||
|
||||
const auto respawnPoint = player->GetCharacter()->GetRespawnPoint(Game::zoneManager->GetZone()->GetWorldID());
|
||||
@@ -1061,33 +1032,30 @@ void HandlePacket(Packet* packet) {
|
||||
|
||||
Game::entityManager->ConstructAllEntities(packet->systemAddress);
|
||||
|
||||
auto* characterComponent = player->GetComponent<CharacterComponent>();
|
||||
if (characterComponent) {
|
||||
player->GetComponent<CharacterComponent>()->RocketUnEquip(player);
|
||||
}
|
||||
characterComponent->RocketUnEquip(player);
|
||||
|
||||
// Do charxml fixes here
|
||||
auto* levelComponent = player->GetComponent<LevelProgressionComponent>();
|
||||
if (!levelComponent) return;
|
||||
|
||||
auto version = levelComponent->GetCharacterVersion();
|
||||
switch(version) {
|
||||
case eCharacterVersion::RELEASE:
|
||||
// TODO: Implement, super low priority
|
||||
case eCharacterVersion::LIVE:
|
||||
LOG("Updating Character Flags");
|
||||
c->SetRetroactiveFlags();
|
||||
levelComponent->SetCharacterVersion(eCharacterVersion::PLAYER_FACTION_FLAGS);
|
||||
case eCharacterVersion::PLAYER_FACTION_FLAGS:
|
||||
LOG("Updating Vault Size");
|
||||
player->RetroactiveVaultSize();
|
||||
levelComponent->SetCharacterVersion(eCharacterVersion::VAULT_SIZE);
|
||||
case eCharacterVersion::VAULT_SIZE:
|
||||
LOG("Updaing Speedbase");
|
||||
levelComponent->SetRetroactiveBaseSpeed();
|
||||
levelComponent->SetCharacterVersion(eCharacterVersion::UP_TO_DATE);
|
||||
case eCharacterVersion::UP_TO_DATE:
|
||||
break;
|
||||
switch (version) {
|
||||
case eCharacterVersion::RELEASE:
|
||||
// TODO: Implement, super low priority
|
||||
case eCharacterVersion::LIVE:
|
||||
LOG("Updating Character Flags");
|
||||
c->SetRetroactiveFlags();
|
||||
levelComponent->SetCharacterVersion(eCharacterVersion::PLAYER_FACTION_FLAGS);
|
||||
case eCharacterVersion::PLAYER_FACTION_FLAGS:
|
||||
LOG("Updating Vault Size");
|
||||
player->RetroactiveVaultSize();
|
||||
levelComponent->SetCharacterVersion(eCharacterVersion::VAULT_SIZE);
|
||||
case eCharacterVersion::VAULT_SIZE:
|
||||
LOG("Updaing Speedbase");
|
||||
levelComponent->SetRetroactiveBaseSpeed();
|
||||
levelComponent->SetCharacterVersion(eCharacterVersion::UP_TO_DATE);
|
||||
case eCharacterVersion::UP_TO_DATE:
|
||||
break;
|
||||
}
|
||||
|
||||
player->GetCharacter()->SetTargetScene("");
|
||||
@@ -1103,89 +1071,44 @@ void HandlePacket(Packet* packet) {
|
||||
if (g_CloneID != 0) {
|
||||
const auto& worldId = Game::zoneManager->GetZone()->GetZoneID();
|
||||
|
||||
const auto zoneId = Game::server->GetZoneID();
|
||||
const auto zoneId = worldId.GetMapID();
|
||||
const auto cloneId = g_CloneID;
|
||||
|
||||
auto query = CDClientDatabase::CreatePreppedStmt(
|
||||
"SELECT id FROM PropertyTemplate WHERE mapID = ?;");
|
||||
query.bind(1, (int)zoneId);
|
||||
//Check for BBB models:
|
||||
auto propertyInfo = Database::Get()->GetPropertyInfo(zoneId, cloneId);
|
||||
|
||||
auto result = query.execQuery();
|
||||
|
||||
if (result.eof() || result.fieldIsNull(0)) {
|
||||
LOG("No property templates found for zone %d, not sending BBB", zoneId);
|
||||
LWOOBJID propertyId = LWOOBJID_EMPTY;
|
||||
if (propertyInfo) propertyId = propertyInfo->id;
|
||||
else {
|
||||
LOG("Couldn't find property ID for zone %i, clone %i", zoneId, cloneId);
|
||||
goto noBBB;
|
||||
}
|
||||
for (auto& bbbModel : Database::Get()->GetUgcModels(propertyId)) {
|
||||
LOG("Getting lxfml ugcID: %llu", bbbModel.id);
|
||||
|
||||
//Check for BBB models:
|
||||
auto stmt = Database::CreatePreppedStmt("SELECT ugc_id FROM properties_contents WHERE lot=14 AND property_id=?");
|
||||
bbbModel.lxfmlData.seekg(0, std::ios::end);
|
||||
size_t lxfmlSize = bbbModel.lxfmlData.tellg();
|
||||
bbbModel.lxfmlData.seekg(0);
|
||||
|
||||
int32_t templateId = result.getIntField(0);
|
||||
//Send message:
|
||||
LWOOBJID blueprintID = bbbModel.id;
|
||||
GeneralUtils::SetBit(blueprintID, eObjectBits::CHARACTER);
|
||||
GeneralUtils::SetBit(blueprintID, eObjectBits::PERSISTENT);
|
||||
|
||||
result.finalize();
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::BLUEPRINT_SAVE_RESPONSE);
|
||||
bitStream.Write<LWOOBJID>(LWOOBJID_EMPTY); //always zero so that a check on the client passes
|
||||
bitStream.Write(eBlueprintSaveResponseType::EverythingWorked);
|
||||
bitStream.Write<uint32_t>(1);
|
||||
bitStream.Write(blueprintID);
|
||||
|
||||
auto* propertyLookup = Database::CreatePreppedStmt("SELECT * FROM properties WHERE template_id = ? AND clone_id = ?;");
|
||||
bitStream.Write<uint32_t>(lxfmlSize);
|
||||
|
||||
propertyLookup->setInt(1, templateId);
|
||||
propertyLookup->setInt64(2, g_CloneID);
|
||||
bitStream.WriteAlignedBytes(reinterpret_cast<const unsigned char*>(bbbModel.lxfmlData.str().c_str()), lxfmlSize);
|
||||
|
||||
auto* propertyEntry = propertyLookup->executeQuery();
|
||||
uint64_t propertyId = 0;
|
||||
|
||||
if (propertyEntry->next()) {
|
||||
propertyId = propertyEntry->getUInt64(1);
|
||||
SystemAddress sysAddr = packet->systemAddress;
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
delete propertyLookup;
|
||||
|
||||
stmt->setUInt64(1, propertyId);
|
||||
auto res = stmt->executeQuery();
|
||||
while (res->next()) {
|
||||
LOG("Getting lxfml ugcID: %u", res->getUInt(1));
|
||||
|
||||
//Get lxfml:
|
||||
auto stmtL = Database::CreatePreppedStmt("SELECT lxfml from ugc where id=?");
|
||||
stmtL->setUInt(1, res->getUInt(1));
|
||||
|
||||
auto lxres = stmtL->executeQuery();
|
||||
|
||||
while (lxres->next()) {
|
||||
auto lxfml = lxres->getBlob(1);
|
||||
|
||||
lxfml->seekg(0, std::ios::end);
|
||||
size_t lxfmlSize = lxfml->tellg();
|
||||
lxfml->seekg(0);
|
||||
|
||||
//Send message:
|
||||
{
|
||||
LWOOBJID blueprintID = res->getUInt(1);
|
||||
GeneralUtils::SetBit(blueprintID, eObjectBits::CHARACTER);
|
||||
GeneralUtils::SetBit(blueprintID, eObjectBits::PERSISTENT);
|
||||
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::BLUEPRINT_SAVE_RESPONSE);
|
||||
bitStream.Write<LWOOBJID>(LWOOBJID_EMPTY); //always zero so that a check on the client passes
|
||||
bitStream.Write(eBlueprintSaveResponseType::EverythingWorked);
|
||||
bitStream.Write<uint32_t>(1);
|
||||
bitStream.Write(blueprintID);
|
||||
|
||||
bitStream.Write<uint32_t>(lxfmlSize);
|
||||
|
||||
for (size_t i = 0; i < lxfmlSize; ++i)
|
||||
bitStream.Write<uint8_t>(lxfml->get());
|
||||
|
||||
SystemAddress sysAddr = packet->systemAddress;
|
||||
SEND_PACKET;
|
||||
PacketUtils::SavePacket("lxfml packet " + std::to_string(res->getUInt(1)) + ".bin", (char*)bitStream.GetData(), bitStream.GetNumberOfBytesUsed());
|
||||
}
|
||||
}
|
||||
|
||||
delete stmtL;
|
||||
delete lxres;
|
||||
}
|
||||
|
||||
delete stmt;
|
||||
delete res;
|
||||
}
|
||||
|
||||
noBBB:
|
||||
@@ -1216,6 +1139,7 @@ void HandlePacket(Packet* packet) {
|
||||
bitStream.Write(zone.GetInstanceID());
|
||||
bitStream.Write(zone.GetCloneID());
|
||||
bitStream.Write(player->GetParentUser()->GetMuteExpire());
|
||||
bitStream.Write(player->GetGMLevel());
|
||||
|
||||
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false);
|
||||
}
|
||||
@@ -1230,7 +1154,16 @@ void HandlePacket(Packet* packet) {
|
||||
}
|
||||
|
||||
case eWorldMessageType::POSITION_UPDATE: {
|
||||
ClientPackets::HandleClientPositionUpdate(packet->systemAddress, packet);
|
||||
auto positionUpdate = ClientPackets::HandleClientPositionUpdate(packet);
|
||||
|
||||
User* user = UserManager::Instance()->GetUser(packet->systemAddress);
|
||||
if (!user) {
|
||||
LOG("Unable to get user to parse position update");
|
||||
return;
|
||||
}
|
||||
|
||||
Entity* entity = Game::entityManager->GetEntity(user->GetLastUsedChar()->GetObjectID());
|
||||
if (entity) entity->ProcessPositionUpdate(positionUpdate);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1278,7 +1211,74 @@ void HandlePacket(Packet* packet) {
|
||||
}
|
||||
|
||||
case eWorldMessageType::STRING_CHECK: {
|
||||
ClientPackets::HandleChatModerationRequest(packet->systemAddress, packet);
|
||||
auto request = ClientPackets::HandleChatModerationRequest(packet);
|
||||
|
||||
// TODO: Find a good home for the logic in this case.
|
||||
User* user = UserManager::Instance()->GetUser(packet->systemAddress);
|
||||
if (!user) {
|
||||
LOG("Unable to get user to parse chat moderation request");
|
||||
return;
|
||||
}
|
||||
|
||||
auto* entity = PlayerManager::GetPlayer(packet->systemAddress);
|
||||
|
||||
if (entity == nullptr) {
|
||||
LOG("Unable to get player to parse chat moderation request");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the player has restricted chat access
|
||||
auto* character = entity->GetCharacter();
|
||||
|
||||
if (character->HasPermission(ePermissionMap::RestrictedChatAccess)) {
|
||||
// Send a message to the player
|
||||
ChatPackets::SendSystemMessage(
|
||||
packet->systemAddress,
|
||||
u"This character has restricted chat access."
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool isBestFriend = false;
|
||||
|
||||
if (request.chatLevel == 1) {
|
||||
// Private chat
|
||||
LWOOBJID idOfReceiver = LWOOBJID_EMPTY;
|
||||
|
||||
{
|
||||
auto characterIdFetch = Database::Get()->GetCharacterInfo(request.receiver);
|
||||
|
||||
if (characterIdFetch) {
|
||||
idOfReceiver = characterIdFetch->id;
|
||||
}
|
||||
}
|
||||
const auto& bffMap = user->GetIsBestFriendMap();
|
||||
if (bffMap.find(request.receiver) == bffMap.end() && idOfReceiver != LWOOBJID_EMPTY) {
|
||||
auto bffInfo = Database::Get()->GetBestFriendStatus(entity->GetObjectID(), idOfReceiver);
|
||||
|
||||
if (bffInfo) {
|
||||
isBestFriend = bffInfo->bestFriendStatus == 3;
|
||||
}
|
||||
|
||||
if (isBestFriend) {
|
||||
user->UpdateBestFriendValue(request.receiver, true);
|
||||
}
|
||||
} else if (bffMap.find(request.receiver) != bffMap.end()) {
|
||||
isBestFriend = true;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::pair<uint8_t, uint8_t>> segments = Game::chatFilter->IsSentenceOkay(request.message, entity->GetGMLevel(), !(isBestFriend && request.chatLevel == 1));
|
||||
|
||||
bool bAllClean = segments.empty();
|
||||
|
||||
if (user->GetIsMuted()) {
|
||||
bAllClean = false;
|
||||
}
|
||||
|
||||
user->SetLastChatMessageApproved(bAllClean);
|
||||
WorldPackets::SendChatModerationResponse(packet->systemAddress, bAllClean, request.requestID, request.receiver, segments);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1286,7 +1286,29 @@ void HandlePacket(Packet* packet) {
|
||||
if (chatDisabled) {
|
||||
ChatPackets::SendMessageFail(packet->systemAddress);
|
||||
} else {
|
||||
ClientPackets::HandleChatMessage(packet->systemAddress, packet);
|
||||
auto chatMessage = ClientPackets::HandleChatMessage(packet);
|
||||
|
||||
// TODO: Find a good home for the logic in this case.
|
||||
User* user = UserManager::Instance()->GetUser(packet->systemAddress);
|
||||
if (!user) {
|
||||
LOG("Unable to get user to parse chat message");
|
||||
return;
|
||||
}
|
||||
|
||||
if (user->GetIsMuted()) {
|
||||
user->GetLastUsedChar()->SendMuteNotice();
|
||||
return;
|
||||
}
|
||||
std::string playerName = user->GetLastUsedChar()->GetName();
|
||||
bool isMythran = user->GetLastUsedChar()->GetGMLevel() > eGameMasterLevel::CIVILIAN;
|
||||
bool isOk = Game::chatFilter->IsSentenceOkay(GeneralUtils::UTF16ToWTF8(chatMessage.message), user->GetLastUsedChar()->GetGMLevel()).empty();
|
||||
LOG_DEBUG("Msg: %s was approved previously? %i", GeneralUtils::UTF16ToWTF8(chatMessage.message).c_str(), user->GetLastChatMessageApproved());
|
||||
if (!isOk) return;
|
||||
if (!isOk && !isMythran) return;
|
||||
|
||||
std::string sMessage = GeneralUtils::UTF16ToWTF8(chatMessage.message);
|
||||
LOG("%s: %s", playerName.c_str(), sMessage.c_str());
|
||||
ChatPackets::SendChatMessage(packet->systemAddress, chatMessage.chatChannel, playerName, user->GetLoggedInChar(), isMythran, chatMessage.message);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -1310,8 +1332,46 @@ void HandlePacket(Packet* packet) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case eWorldMessageType::UI_HELP_TOP_5: {
|
||||
auto language = ClientPackets::SendTop5HelpIssues(packet);
|
||||
// TODO: Handle different languages in a nice way
|
||||
// 0: en_US
|
||||
// 1: pl_US
|
||||
// 2: de_DE
|
||||
// 3: en_GB
|
||||
|
||||
// TODO: Find a good home for the logic in this case.
|
||||
auto* user = UserManager::Instance()->GetUser(packet->systemAddress);
|
||||
if (!user) return;
|
||||
auto* character = user->GetLastUsedChar();
|
||||
if (!character) return;
|
||||
auto* entity = character->GetEntity();
|
||||
if (!entity) return;
|
||||
|
||||
AMFArrayValue data;
|
||||
// Summaries
|
||||
data.Insert("Summary0", Game::config->GetValue("help_0_summary"));
|
||||
data.Insert("Summary1", Game::config->GetValue("help_1_summary"));
|
||||
data.Insert("Summary2", Game::config->GetValue("help_2_summary"));
|
||||
data.Insert("Summary3", Game::config->GetValue("help_3_summary"));
|
||||
data.Insert("Summary4", Game::config->GetValue("help_4_summary"));
|
||||
|
||||
// Descriptions
|
||||
data.Insert("Description0", Game::config->GetValue("help_0_description"));
|
||||
data.Insert("Description1", Game::config->GetValue("help_1_description"));
|
||||
data.Insert("Description2", Game::config->GetValue("help_2_description"));
|
||||
data.Insert("Description3", Game::config->GetValue("help_3_description"));
|
||||
data.Insert("Description4", Game::config->GetValue("help_4_description"));
|
||||
|
||||
GameMessages::SendUIMessageServerToSingleClient(entity, packet->systemAddress, "UIHelpTop5", data);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
LOG("Unknown world packet received: %i", int(packet->data[3]));
|
||||
const auto messageId = *reinterpret_cast<eWorldMessageType*>(&packet->data[3]);
|
||||
const std::string_view messageIdString = StringifiedEnum::ToString(messageId);
|
||||
LOG("Unknown world packet received: %4i, %s", messageId, messageIdString.data());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1320,7 +1380,7 @@ void WorldShutdownProcess(uint32_t zoneId) {
|
||||
for (auto i = 0; i < Game::server->GetReplicaManager()->GetParticipantCount(); ++i) {
|
||||
const auto& player = Game::server->GetReplicaManager()->GetParticipantAtIndex(i);
|
||||
|
||||
auto* entity = Player::GetPlayer(player);
|
||||
auto* entity = PlayerManager::GetPlayer(player);
|
||||
LOG("Saving data!");
|
||||
if (entity != nullptr && entity->GetCharacter() != nullptr) {
|
||||
auto* skillComponent = entity->GetComponent<SkillComponent>();
|
||||
@@ -1337,6 +1397,7 @@ void WorldShutdownProcess(uint32_t zoneId) {
|
||||
if (PropertyManagementComponent::Instance() != nullptr) {
|
||||
LOG("Saving ALL property data for zone %i clone %i!", zoneId, PropertyManagementComponent::Instance()->GetCloneId());
|
||||
PropertyManagementComponent::Instance()->Save();
|
||||
Database::Get()->RemoveUnreferencedUgcModels();
|
||||
LOG("ALL property data saved for zone %i clone %i!", zoneId, PropertyManagementComponent::Instance()->GetCloneId());
|
||||
}
|
||||
|
||||
@@ -1351,11 +1412,16 @@ void WorldShutdownProcess(uint32_t zoneId) {
|
||||
}
|
||||
|
||||
void WorldShutdownSequence() {
|
||||
if (Game::shouldShutdown || worldShutdownSequenceComplete) {
|
||||
bool shouldShutdown = Game::ShouldShutdown() || worldShutdownSequenceComplete;
|
||||
Game::lastSignal = -1;
|
||||
#ifndef DARKFLAME_PLATFORM_WIN32
|
||||
if (shouldShutdown)
|
||||
#endif
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Game::shouldShutdown = true;
|
||||
if (!Game::logger) return;
|
||||
|
||||
LOG("Zone (%i) instance (%i) shutting down outside of main loop!", Game::server->GetZoneID(), instanceID);
|
||||
WorldShutdownProcess(Game::server->GetZoneID());
|
||||
@@ -1369,11 +1435,17 @@ void FinalizeShutdown() {
|
||||
Metrics::Clear();
|
||||
Database::Destroy("WorldServer");
|
||||
if (Game::chatFilter) delete Game::chatFilter;
|
||||
Game::chatFilter = nullptr;
|
||||
if (Game::zoneManager) delete Game::zoneManager;
|
||||
Game::zoneManager = nullptr;
|
||||
if (Game::server) delete Game::server;
|
||||
Game::server = nullptr;
|
||||
if (Game::config) delete Game::config;
|
||||
Game::config = nullptr;
|
||||
if (Game::entityManager) delete Game::entityManager;
|
||||
Game::entityManager = nullptr;
|
||||
if (Game::logger) delete Game::logger;
|
||||
Game::logger = nullptr;
|
||||
|
||||
worldShutdownSequenceComplete = true;
|
||||
|
||||
|
Reference in New Issue
Block a user