2021-12-05 17:54:36 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <ctime>
|
|
|
|
#include <chrono>
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
#include "MD5.h"
|
|
|
|
|
|
|
|
//DLU Includes:
|
|
|
|
#include "dCommonVars.h"
|
|
|
|
#include "dServer.h"
|
2023-10-21 23:31:55 +00:00
|
|
|
#include "Logger.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "Database.h"
|
|
|
|
#include "dConfig.h"
|
|
|
|
#include "dpWorld.h"
|
|
|
|
#include "dZoneManager.h"
|
|
|
|
#include "Metrics.hpp"
|
|
|
|
#include "PerformanceManager.h"
|
|
|
|
#include "Diagnostics.h"
|
2022-11-27 11:59:59 +00:00
|
|
|
#include "BinaryPathFinder.h"
|
2023-12-16 18:27:06 +00:00
|
|
|
#include "dPlatforms.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
//RakNet includes:
|
|
|
|
#include "RakNetDefines.h"
|
|
|
|
#include "RakNetworkFactory.h"
|
|
|
|
#include "RakString.h"
|
|
|
|
|
|
|
|
//World includes:
|
|
|
|
#include <csignal>
|
|
|
|
|
|
|
|
#include "AuthPackets.h"
|
2023-09-21 01:06:28 +00:00
|
|
|
#include "BitStreamUtils.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "WorldPackets.h"
|
|
|
|
#include "UserManager.h"
|
|
|
|
#include "CDClientManager.h"
|
|
|
|
#include "CDClientDatabase.h"
|
|
|
|
#include "GeneralUtils.h"
|
|
|
|
#include "ObjectIDManager.h"
|
|
|
|
#include "ZoneInstanceManager.h"
|
|
|
|
#include "dChatFilter.h"
|
|
|
|
#include "ClientPackets.h"
|
|
|
|
#include "CharacterComponent.h"
|
|
|
|
|
|
|
|
#include "EntityManager.h"
|
2023-01-07 05:17:05 +00:00
|
|
|
#include "EntityInfo.h"
|
|
|
|
#include "User.h"
|
|
|
|
#include "Loot.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "Entity.h"
|
|
|
|
#include "Character.h"
|
|
|
|
#include "ChatPackets.h"
|
|
|
|
#include "GameMessageHandler.h"
|
|
|
|
#include "GameMessages.h"
|
|
|
|
#include "Mail.h"
|
|
|
|
#include "TeamManager.h"
|
|
|
|
#include "SkillComponent.h"
|
|
|
|
#include "DestroyableComponent.h"
|
|
|
|
#include "Game.h"
|
|
|
|
#include "MasterPackets.h"
|
|
|
|
#include "PropertyManagementComponent.h"
|
2022-11-01 18:21:26 +00:00
|
|
|
#include "AssetManager.h"
|
2022-12-19 19:45:50 +00:00
|
|
|
#include "LevelProgressionComponent.h"
|
2022-11-28 00:48:46 +00:00
|
|
|
#include "eBlueprintSaveResponseType.h"
|
2023-05-13 22:22:00 +00:00
|
|
|
#include "Amf3.h"
|
2023-01-07 05:17:05 +00:00
|
|
|
#include "NiPoint3.h"
|
2023-02-19 12:29:14 +00:00
|
|
|
#include "eServerDisconnectIdentifiers.h"
|
2023-04-25 18:17:40 +00:00
|
|
|
#include "eObjectBits.h"
|
2023-05-03 21:38:32 +00:00
|
|
|
#include "eConnectionType.h"
|
2024-11-18 00:39:44 +00:00
|
|
|
#include "MessageType/Server.h"
|
|
|
|
#include "MessageType/Chat.h"
|
|
|
|
#include "MessageType/World.h"
|
|
|
|
#include "MessageType/Master.h"
|
|
|
|
#include "MessageType/Game.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "ZCompression.h"
|
2023-07-15 20:56:33 +00:00
|
|
|
#include "EntityManager.h"
|
2023-09-28 17:16:11 +00:00
|
|
|
#include "CheatDetection.h"
|
2023-11-18 00:47:18 +00:00
|
|
|
#include "eGameMasterLevel.h"
|
2023-12-23 16:51:59 +00:00
|
|
|
#include "StringifiedEnum.h"
|
2024-01-06 05:32:09 +00:00
|
|
|
#include "Server.h"
|
2024-01-07 07:05:57 +00:00
|
|
|
#include "PositionUpdate.h"
|
2024-01-13 09:40:56 +00:00
|
|
|
#include "PlayerManager.h"
|
2024-01-18 08:10:52 +00:00
|
|
|
#include "eLoginResponse.h"
|
2024-11-18 00:08:36 +00:00
|
|
|
#include "MissionComponent.h"
|
2024-04-08 20:11:59 +00:00
|
|
|
#include "SlashCommandHandler.h"
|
2024-11-18 00:08:36 +00:00
|
|
|
#include "InventoryComponent.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
namespace Game {
|
2023-10-21 23:31:55 +00:00
|
|
|
Logger* logger = nullptr;
|
2022-12-15 14:13:49 +00:00
|
|
|
dServer* server = nullptr;
|
|
|
|
dChatFilter* chatFilter = nullptr;
|
|
|
|
dConfig* config = nullptr;
|
|
|
|
AssetManager* assetManager = nullptr;
|
|
|
|
RakPeerInterface* chatServer = nullptr;
|
2021-12-05 17:54:36 +00:00
|
|
|
std::mt19937 randomEngine;
|
|
|
|
SystemAddress chatSysAddr;
|
2024-01-02 03:50:00 +00:00
|
|
|
Game::signal_t lastSignal = 0;
|
2023-07-15 20:56:33 +00:00
|
|
|
EntityManager* entityManager = nullptr;
|
2023-07-17 22:55:33 +00:00
|
|
|
dZoneManager* zoneManager = nullptr;
|
2023-12-31 06:26:49 +00:00
|
|
|
std::string projectVersion = PROJECT_VERSION;
|
2022-12-15 12:02:38 +00:00
|
|
|
} // namespace Game
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
bool chatDisabled = false;
|
2021-12-20 12:50:53 +00:00
|
|
|
bool chatConnected = false;
|
2021-12-05 17:54:36 +00:00
|
|
|
bool worldShutdownSequenceComplete = false;
|
|
|
|
void WorldShutdownSequence();
|
2022-04-11 00:00:03 +00:00
|
|
|
void WorldShutdownProcess(uint32_t zoneId);
|
2022-04-10 01:35:41 +00:00
|
|
|
void FinalizeShutdown();
|
|
|
|
void SendShutdownMessageToMaster();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
void HandlePacketChat(Packet* packet);
|
2024-01-06 05:32:09 +00:00
|
|
|
void HandleMasterPacket(Packet* packet);
|
2021-12-05 17:54:36 +00:00
|
|
|
void HandlePacket(Packet* packet);
|
|
|
|
|
|
|
|
struct tempSessionInfo {
|
|
|
|
SystemAddress sysAddr;
|
|
|
|
std::string hash;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::map<std::string, tempSessionInfo> m_PendingUsers;
|
2022-12-16 10:24:02 +00:00
|
|
|
uint32_t instanceID = 0;
|
|
|
|
uint32_t g_CloneID = 0;
|
2021-12-16 22:11:51 +00:00
|
|
|
std::string databaseChecksum = "";
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
Diagnostics::SetProcessName("World");
|
|
|
|
Diagnostics::SetProcessFileName(argv[0]);
|
|
|
|
Diagnostics::Initialize();
|
|
|
|
|
|
|
|
// Triggers the shutdown sequence at application exit
|
|
|
|
std::atexit(WorldShutdownSequence);
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2024-01-02 03:50:00 +00:00
|
|
|
std::signal(SIGINT, Game::OnSignal);
|
|
|
|
std::signal(SIGTERM, Game::OnSignal);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-12-16 10:24:02 +00:00
|
|
|
uint32_t zoneID = 1000;
|
|
|
|
uint32_t cloneID = 0;
|
|
|
|
uint32_t maxClients = 8;
|
|
|
|
uint32_t ourPort = 2007;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
//Check our arguments:
|
2022-12-16 10:24:02 +00:00
|
|
|
for (int32_t i = 0; i < argc; ++i) {
|
2021-12-05 17:54:36 +00:00
|
|
|
std::string argument(argv[i]);
|
|
|
|
|
|
|
|
if (argument == "-zone") zoneID = atoi(argv[i + 1]);
|
|
|
|
if (argument == "-instance") instanceID = atoi(argv[i + 1]);
|
|
|
|
if (argument == "-clone") cloneID = atoi(argv[i + 1]);
|
|
|
|
if (argument == "-maxclients") maxClients = atoi(argv[i + 1]);
|
|
|
|
if (argument == "-port") ourPort = atoi(argv[i + 1]);
|
|
|
|
}
|
|
|
|
|
2024-01-06 05:32:09 +00:00
|
|
|
Game::config = new dConfig("worldconfig.ini");
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//Create all the objects we need to run our service:
|
2024-01-06 05:32:09 +00:00
|
|
|
Server::SetupLogger("WorldServer_" + std::to_string(zoneID) + "_" + std::to_string(instanceID));
|
2022-12-15 14:13:49 +00:00
|
|
|
if (!Game::logger) return EXIT_FAILURE;
|
|
|
|
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Starting World server...");
|
2023-12-31 06:26:49 +00:00
|
|
|
LOG("Version: %s", Game::projectVersion.c_str());
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Compiled on: %s", __TIMESTAMP__);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-12-15 14:13:49 +00:00
|
|
|
if (Game::config->GetValue("disable_chat") == "1") chatDisabled = true;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-11-01 18:21:26 +00:00
|
|
|
try {
|
2022-12-15 14:13:49 +00:00
|
|
|
std::string clientPathStr = Game::config->GetValue("client_location");
|
2022-11-27 11:59:59 +00:00
|
|
|
if (clientPathStr.empty()) clientPathStr = "./res";
|
|
|
|
std::filesystem::path clientPath = std::filesystem::path(clientPathStr);
|
|
|
|
if (clientPath.is_relative()) {
|
|
|
|
clientPath = BinaryPathFinder::GetBinaryDir() / clientPath;
|
|
|
|
}
|
|
|
|
Game::assetManager = new AssetManager(clientPath);
|
2022-11-01 18:21:26 +00:00
|
|
|
} catch (std::runtime_error& ex) {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Got an error while setting up assets: %s", ex.what());
|
2022-11-01 18:21:26 +00:00
|
|
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
// Connect to CDClient
|
|
|
|
try {
|
2022-12-22 06:34:11 +00:00
|
|
|
CDClientDatabase::Connect((BinaryPathFinder::GetBinaryDir() / "resServer" / "CDServer.sqlite").string());
|
2021-12-05 17:54:36 +00:00
|
|
|
} catch (CppSQLite3Exception& e) {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Unable to connect to CDServer SQLite Database");
|
|
|
|
LOG("Error: %s", e.errorMessage());
|
|
|
|
LOG("Error Code: %i", e.errorCode());
|
2022-12-15 14:13:49 +00:00
|
|
|
return EXIT_FAILURE;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2024-02-09 05:40:43 +00:00
|
|
|
CDClientManager::LoadValuesFromDatabase();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-12-15 14:13:49 +00:00
|
|
|
Diagnostics::SetProduceMemoryDump(Game::config->GetValue("generate_dump") == "1");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-12-15 14:13:49 +00:00
|
|
|
if (!Game::config->GetValue("dump_folder").empty()) {
|
|
|
|
Diagnostics::SetOutDirectory(Game::config->GetValue("dump_folder"));
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-11-18 00:47:18 +00:00
|
|
|
//Connect to the MySQL Database:
|
2021-12-05 17:54:36 +00:00
|
|
|
try {
|
2023-11-18 00:47:18 +00:00
|
|
|
Database::Connect();
|
2021-12-05 17:54:36 +00:00
|
|
|
} catch (sql::SQLException& ex) {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Got an error while connecting to the database: %s", ex.what());
|
2022-12-15 14:13:49 +00:00
|
|
|
return EXIT_FAILURE;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Find out the master's IP:
|
|
|
|
std::string masterIP = "localhost";
|
2022-12-16 10:24:02 +00:00
|
|
|
uint32_t masterPort = 1000;
|
2023-11-18 00:47:18 +00:00
|
|
|
auto masterInfo = Database::Get()->GetMasterInfo();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-11-18 00:47:18 +00:00
|
|
|
if (masterInfo) {
|
|
|
|
masterIP = masterInfo->ip;
|
|
|
|
masterPort = masterInfo->port;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
UserManager::Instance()->Initialize();
|
2024-01-05 00:21:03 +00:00
|
|
|
|
2024-02-10 11:05:25 +00:00
|
|
|
const bool dontGenerateDCF = GeneralUtils::TryParse<bool>(Game::config->GetValue("dont_generate_dcf")).value_or(false);
|
2024-01-05 00:21:03 +00:00
|
|
|
Game::chatFilter = new dChatFilter(Game::assetManager->GetResPath().string() + "/chatplus_en_us", dontGenerateDCF);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-02 03:50:00 +00:00
|
|
|
Game::server = new dServer(masterIP, ourPort, instanceID, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::World, Game::config, &Game::lastSignal, zoneID);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
//Connect to the chat server:
|
2022-12-16 10:24:02 +00:00
|
|
|
uint32_t chatPort = 1501;
|
2022-12-15 14:13:49 +00:00
|
|
|
if (Game::config->GetValue("chat_server_port") != "") chatPort = std::atoi(Game::config->GetValue("chat_server_port").c_str());
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2023-12-24 00:11:00 +00:00
|
|
|
auto chatSock = SocketDescriptor(static_cast<uint16_t>(ourPort + 2), 0);
|
2021-12-05 17:54:36 +00:00
|
|
|
Game::chatServer = RakNetworkFactory::GetRakPeerInterface();
|
|
|
|
Game::chatServer->Startup(1, 30, &chatSock, 1);
|
|
|
|
Game::chatServer->Connect(masterIP.c_str(), chatPort, "3.25 ND1", 8);
|
|
|
|
|
|
|
|
//Set up other things:
|
|
|
|
Game::randomEngine = std::mt19937(time(0));
|
|
|
|
|
|
|
|
//Run it until server gets a kill message from Master:
|
|
|
|
auto lastTime = std::chrono::high_resolution_clock::now();
|
|
|
|
auto t = std::chrono::high_resolution_clock::now();
|
|
|
|
|
|
|
|
Packet* packet = nullptr;
|
2022-12-16 10:24:02 +00:00
|
|
|
uint32_t framesSinceLastFlush = 0;
|
|
|
|
uint32_t framesSinceMasterDisconnect = 0;
|
|
|
|
uint32_t framesSinceChatDisconnect = 0;
|
|
|
|
uint32_t framesSinceLastUsersSave = 0;
|
|
|
|
uint32_t framesSinceLastSQLPing = 0;
|
|
|
|
uint32_t framesSinceLastUser = 0;
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
const float maxPacketProcessingTime = 1.5f; //0.015f;
|
2022-12-16 10:24:02 +00:00
|
|
|
const uint32_t maxPacketsToProcess = 1024;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
bool ready = false;
|
2022-12-16 10:24:02 +00:00
|
|
|
uint32_t framesSinceMasterStatus = 0;
|
|
|
|
uint32_t framesSinceShutdownSequence = 0;
|
2022-12-16 11:46:38 +00:00
|
|
|
uint32_t currentFramerate = highFramerate;
|
2022-02-09 09:38:09 +00:00
|
|
|
|
2022-12-16 10:24:02 +00:00
|
|
|
uint32_t ghostingStepCount = 0;
|
2021-12-05 17:54:36 +00:00
|
|
|
auto ghostingLastTime = std::chrono::high_resolution_clock::now();
|
|
|
|
|
|
|
|
PerformanceManager::SelectProfile(zoneID);
|
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager = new EntityManager();
|
2023-07-17 22:55:33 +00:00
|
|
|
Game::zoneManager = new dZoneManager();
|
2021-12-05 17:54:36 +00:00
|
|
|
//Load our level:
|
|
|
|
if (zoneID != 0) {
|
2024-01-19 21:12:05 +00:00
|
|
|
dpWorld::Initialize(zoneID);
|
2023-07-17 22:55:33 +00:00
|
|
|
Game::zoneManager->Initialize(LWOZONEID(zoneID, instanceID, cloneID));
|
2021-12-05 17:54:36 +00:00
|
|
|
g_CloneID = cloneID;
|
2021-12-12 15:14:04 +00:00
|
|
|
|
2023-08-04 22:48:45 +00:00
|
|
|
} else {
|
|
|
|
Game::entityManager->Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
// pre calculate the FDB checksum
|
|
|
|
if (Game::config->GetValue("check_fdb") == "1") {
|
|
|
|
std::ifstream fileStream;
|
|
|
|
|
|
|
|
static const std::vector<std::string> aliases = {
|
|
|
|
"CDServers.fdb",
|
|
|
|
"cdserver.fdb",
|
|
|
|
"CDClient.fdb",
|
|
|
|
"cdclient.fdb",
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto& file : aliases) {
|
|
|
|
fileStream.open(Game::assetManager->GetResPath() / file, std::ios::binary | std::ios::in);
|
|
|
|
if (fileStream.is_open()) {
|
|
|
|
break;
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2023-08-04 22:48:45 +00:00
|
|
|
}
|
2021-12-16 22:11:51 +00:00
|
|
|
|
2023-08-04 22:48:45 +00:00
|
|
|
const int32_t bufferSize = 1024;
|
2024-05-02 11:35:44 +00:00
|
|
|
MD5 md5;
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2023-08-04 22:48:45 +00:00
|
|
|
char fileStreamBuffer[1024] = {};
|
2021-12-12 15:53:19 +00:00
|
|
|
|
2023-08-04 22:48:45 +00:00
|
|
|
while (!fileStream.eof()) {
|
|
|
|
memset(fileStreamBuffer, 0, bufferSize);
|
|
|
|
fileStream.read(fileStreamBuffer, bufferSize);
|
2024-05-02 11:35:44 +00:00
|
|
|
md5.update(fileStreamBuffer, fileStream.gcount());
|
2023-08-04 22:48:45 +00:00
|
|
|
}
|
2021-12-12 15:14:04 +00:00
|
|
|
|
2023-08-04 22:48:45 +00:00
|
|
|
fileStream.close();
|
2021-12-12 15:53:19 +00:00
|
|
|
|
2023-08-04 22:48:45 +00:00
|
|
|
const char* nullTerminateBuffer = "\0";
|
2024-05-02 11:35:44 +00:00
|
|
|
md5.update(nullTerminateBuffer, 1); // null terminate the data
|
|
|
|
md5.finalize();
|
|
|
|
databaseChecksum = md5.hexdigest();
|
2021-12-12 15:14:04 +00:00
|
|
|
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("FDB Checksum calculated as: %s", databaseChecksum.c_str());
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-12-16 12:02:54 +00:00
|
|
|
uint32_t currentFrameDelta = highFrameDelta;
|
2022-12-16 11:46:38 +00:00
|
|
|
// These values are adjust them selves to the current framerate should it update.
|
|
|
|
uint32_t logFlushTime = 15 * currentFramerate; // 15 seconds in frames
|
|
|
|
uint32_t shutdownTimeout = 10 * 60 * currentFramerate; // 10 minutes in frames
|
|
|
|
uint32_t noMasterConnectionTimeout = 5 * currentFramerate; // 5 seconds in frames
|
|
|
|
uint32_t chatReconnectionTime = 30 * currentFramerate; // 30 seconds in frames
|
|
|
|
uint32_t saveTime = 10 * 60 * currentFramerate; // 10 minutes in frames
|
|
|
|
uint32_t sqlPingTime = 10 * 60 * currentFramerate; // 10 minutes in frames
|
2022-12-22 13:16:35 +00:00
|
|
|
uint32_t emptyShutdownTime = (cloneID == 0 ? 30 : 5) * 60 * currentFramerate; // 30 minutes for main worlds, 5 for all others.
|
2024-01-02 03:50:00 +00:00
|
|
|
|
2024-04-10 01:15:51 +00:00
|
|
|
// Register slash commands if not in zone 0
|
|
|
|
if (zoneID != 0) SlashCommandHandler::Startup();
|
2024-04-08 20:11:59 +00:00
|
|
|
|
2024-01-02 03:50:00 +00:00
|
|
|
Game::logger->Flush(); // once immediately before the main loop
|
2021-12-05 17:54:36 +00:00
|
|
|
while (true) {
|
|
|
|
Metrics::StartMeasurement(MetricVariable::Frame);
|
|
|
|
Metrics::StartMeasurement(MetricVariable::GameLoop);
|
|
|
|
|
|
|
|
std::clock_t metricCPUTimeStart = std::clock();
|
|
|
|
|
|
|
|
const auto currentTime = std::chrono::high_resolution_clock::now();
|
|
|
|
float deltaTime = std::chrono::duration<float>(currentTime - lastTime).count();
|
|
|
|
lastTime = currentTime;
|
|
|
|
|
|
|
|
const auto occupied = UserManager::Instance()->GetUserCount() != 0;
|
|
|
|
|
2022-12-16 11:46:38 +00:00
|
|
|
uint32_t newFrameDelta = currentFrameDelta;
|
2021-12-05 17:54:36 +00:00
|
|
|
if (!ready) {
|
2022-12-16 11:46:38 +00:00
|
|
|
newFrameDelta = highFrameDelta;
|
2021-12-05 17:54:36 +00:00
|
|
|
} else {
|
2022-12-16 11:46:38 +00:00
|
|
|
newFrameDelta = PerformanceManager::GetServerFrameDelta();
|
|
|
|
}
|
|
|
|
|
2022-12-16 12:02:54 +00:00
|
|
|
// Update to the new framerate and scale all timings to said new framerate
|
2022-12-16 11:46:38 +00:00
|
|
|
if (newFrameDelta != currentFrameDelta) {
|
2024-03-18 01:48:09 +00:00
|
|
|
float_t ratioBeforeToAfter = static_cast<float>(currentFrameDelta) / static_cast<float>(newFrameDelta);
|
2022-12-16 11:46:38 +00:00
|
|
|
currentFrameDelta = newFrameDelta;
|
|
|
|
currentFramerate = MS_TO_FRAMES(newFrameDelta);
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG_DEBUG("Framerate for zone/instance/clone %i/%i/%i is now %i", zoneID, instanceID, cloneID, currentFramerate);
|
2022-12-16 11:46:38 +00:00
|
|
|
logFlushTime = 15 * currentFramerate; // 15 seconds in frames
|
2022-12-16 12:02:54 +00:00
|
|
|
framesSinceLastFlush *= ratioBeforeToAfter;
|
2022-12-16 11:46:38 +00:00
|
|
|
shutdownTimeout = 10 * 60 * currentFramerate; // 10 minutes in frames
|
2022-12-16 12:02:54 +00:00
|
|
|
framesSinceLastUser *= ratioBeforeToAfter;
|
2022-12-16 11:46:38 +00:00
|
|
|
noMasterConnectionTimeout = 5 * currentFramerate; // 5 seconds in frames
|
2022-12-16 12:02:54 +00:00
|
|
|
framesSinceMasterDisconnect *= ratioBeforeToAfter;
|
2022-12-16 11:46:38 +00:00
|
|
|
chatReconnectionTime = 30 * currentFramerate; // 30 seconds in frames
|
2022-12-16 12:02:54 +00:00
|
|
|
framesSinceChatDisconnect *= ratioBeforeToAfter;
|
2022-12-16 11:46:38 +00:00
|
|
|
saveTime = 10 * 60 * currentFramerate; // 10 minutes in frames
|
2022-12-16 12:02:54 +00:00
|
|
|
framesSinceLastUsersSave *= ratioBeforeToAfter;
|
2022-12-16 11:46:38 +00:00
|
|
|
sqlPingTime = 10 * 60 * currentFramerate; // 10 minutes in frames
|
2022-12-16 12:02:54 +00:00
|
|
|
framesSinceLastSQLPing *= ratioBeforeToAfter;
|
2022-12-22 13:16:35 +00:00
|
|
|
emptyShutdownTime = (cloneID == 0 ? 30 : 5) * 60 * currentFramerate; // 30 minutes for main worlds, 5 for all others.
|
|
|
|
framesSinceLastUser *= ratioBeforeToAfter;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Warning if we ran slow
|
2022-12-16 11:46:38 +00:00
|
|
|
if (deltaTime > currentFrameDelta) {
|
2024-09-13 16:45:55 +00:00
|
|
|
LOG("We're running behind, dT: %f > %i (framerate %i)", deltaTime, currentFrameDelta, currentFramerate);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Check if we're still connected to master:
|
|
|
|
if (!Game::server->GetIsConnectedToMaster()) {
|
|
|
|
framesSinceMasterDisconnect++;
|
|
|
|
|
2024-01-02 03:50:00 +00:00
|
|
|
if (framesSinceMasterDisconnect >= noMasterConnectionTimeout && !Game::ShouldShutdown()) {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Game loop running but no connection to master for %d frames, shutting down", noMasterConnectionTimeout);
|
2024-01-02 03:50:00 +00:00
|
|
|
Game::lastSignal = -1;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
} else framesSinceMasterDisconnect = 0;
|
|
|
|
|
2021-12-20 12:50:53 +00:00
|
|
|
// Check if we're still connected to chat:
|
|
|
|
if (!chatConnected) {
|
|
|
|
framesSinceChatDisconnect++;
|
|
|
|
|
2022-12-16 11:46:38 +00:00
|
|
|
if (framesSinceChatDisconnect >= chatReconnectionTime) {
|
2021-12-20 12:50:53 +00:00
|
|
|
framesSinceChatDisconnect = 0;
|
|
|
|
|
|
|
|
Game::chatServer->Connect(masterIP.c_str(), chatPort, "3.25 ND1", 8);
|
|
|
|
}
|
|
|
|
} else framesSinceChatDisconnect = 0;
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//In world we'd update our other systems here.
|
|
|
|
|
|
|
|
if (zoneID != 0 && deltaTime > 0.0f) {
|
|
|
|
Metrics::StartMeasurement(MetricVariable::UpdateEntities);
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->UpdateEntities(deltaTime);
|
2021-12-05 17:54:36 +00:00
|
|
|
Metrics::EndMeasurement(MetricVariable::UpdateEntities);
|
|
|
|
|
2024-05-01 06:09:35 +00:00
|
|
|
Metrics::StartMeasurement(MetricVariable::Physics);
|
|
|
|
dpWorld::StepWorld(deltaTime);
|
|
|
|
Metrics::EndMeasurement(MetricVariable::Physics);
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
Metrics::StartMeasurement(MetricVariable::Ghosting);
|
|
|
|
if (std::chrono::duration<float>(currentTime - ghostingLastTime).count() >= 1.0f) {
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->UpdateGhosting();
|
2021-12-05 17:54:36 +00:00
|
|
|
ghostingLastTime = currentTime;
|
|
|
|
}
|
|
|
|
Metrics::EndMeasurement(MetricVariable::Ghosting);
|
|
|
|
|
|
|
|
Metrics::StartMeasurement(MetricVariable::UpdateSpawners);
|
2023-07-17 22:55:33 +00:00
|
|
|
Game::zoneManager->Update(deltaTime);
|
2021-12-05 17:54:36 +00:00
|
|
|
Metrics::EndMeasurement(MetricVariable::UpdateSpawners);
|
|
|
|
}
|
|
|
|
|
|
|
|
Metrics::StartMeasurement(MetricVariable::PacketHandling);
|
|
|
|
|
|
|
|
//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.
|
2024-01-06 05:32:09 +00:00
|
|
|
HandleMasterPacket(packet);
|
2021-12-05 17:54:36 +00:00
|
|
|
Game::server->DeallocateMasterPacket(packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Handle our chat packets:
|
|
|
|
packet = Game::chatServer->Receive();
|
|
|
|
if (packet) {
|
|
|
|
HandlePacketChat(packet);
|
|
|
|
Game::chatServer->DeallocatePacket(packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Handle world-specific packets:
|
|
|
|
float timeSpent = 0.0f;
|
|
|
|
|
|
|
|
UserManager::Instance()->DeletePendingRemovals();
|
|
|
|
|
|
|
|
auto t1 = std::chrono::high_resolution_clock::now();
|
2022-12-16 10:24:02 +00:00
|
|
|
for (uint32_t curPacket = 0; curPacket < maxPacketsToProcess && timeSpent < maxPacketProcessingTime; curPacket++) {
|
2021-12-05 17:54:36 +00:00
|
|
|
packet = Game::server->Receive();
|
|
|
|
if (packet) {
|
|
|
|
auto t1 = std::chrono::high_resolution_clock::now();
|
|
|
|
HandlePacket(packet);
|
|
|
|
auto t2 = std::chrono::high_resolution_clock::now();
|
|
|
|
|
2022-12-29 14:34:53 +00:00
|
|
|
timeSpent += std::chrono::duration_cast<std::chrono::duration<float>>(t2 - t1).count();
|
2021-12-05 17:54:36 +00:00
|
|
|
Game::server->DeallocatePacket(packet);
|
|
|
|
packet = nullptr;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Metrics::EndMeasurement(MetricVariable::PacketHandling);
|
|
|
|
|
|
|
|
Metrics::StartMeasurement(MetricVariable::UpdateReplica);
|
|
|
|
|
|
|
|
//Update our replica objects:
|
|
|
|
Game::server->UpdateReplica();
|
|
|
|
|
|
|
|
Metrics::EndMeasurement(MetricVariable::UpdateReplica);
|
|
|
|
|
|
|
|
//Push our log every 15s:
|
2022-12-16 11:46:38 +00:00
|
|
|
if (framesSinceLastFlush >= logFlushTime) {
|
2021-12-05 17:54:36 +00:00
|
|
|
Game::logger->Flush();
|
|
|
|
framesSinceLastFlush = 0;
|
|
|
|
} else framesSinceLastFlush++;
|
|
|
|
|
|
|
|
if (zoneID != 0 && !occupied) {
|
|
|
|
framesSinceLastUser++;
|
|
|
|
|
|
|
|
//If we haven't had any players for a while, time out and shut down:
|
2022-12-22 13:16:35 +00:00
|
|
|
if (framesSinceLastUser >= emptyShutdownTime) {
|
2024-01-02 03:50:00 +00:00
|
|
|
Game::lastSignal = -1;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
framesSinceLastUser = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Save all connected users every 10 minutes:
|
2022-12-16 11:46:38 +00:00
|
|
|
if (framesSinceLastUsersSave >= saveTime && zoneID != 0) {
|
2021-12-05 17:54:36 +00:00
|
|
|
UserManager::Instance()->SaveAllActiveCharacters();
|
|
|
|
framesSinceLastUsersSave = 0;
|
|
|
|
|
|
|
|
if (PropertyManagementComponent::Instance() != nullptr) {
|
|
|
|
PropertyManagementComponent::Instance()->Save();
|
|
|
|
}
|
|
|
|
} else framesSinceLastUsersSave++;
|
|
|
|
|
|
|
|
//Every 10 min we ping our sql server to keep it alive hopefully:
|
2022-12-16 11:46:38 +00:00
|
|
|
if (framesSinceLastSQLPing >= sqlPingTime) {
|
2021-12-05 17:54:36 +00:00
|
|
|
//Find out the master's IP for absolutely no reason:
|
|
|
|
std::string masterIP;
|
2022-12-16 10:24:02 +00:00
|
|
|
uint32_t masterPort;
|
2023-11-18 00:47:18 +00:00
|
|
|
auto masterInfo = Database::Get()->GetMasterInfo();
|
|
|
|
if (masterInfo) {
|
|
|
|
masterIP = masterInfo->ip;
|
|
|
|
masterPort = masterInfo->port;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
framesSinceLastSQLPing = 0;
|
|
|
|
} else framesSinceLastSQLPing++;
|
|
|
|
|
|
|
|
Metrics::EndMeasurement(MetricVariable::GameLoop);
|
|
|
|
|
|
|
|
Metrics::StartMeasurement(MetricVariable::Sleep);
|
|
|
|
|
2022-12-16 11:46:38 +00:00
|
|
|
t += std::chrono::milliseconds(currentFrameDelta);
|
2021-12-05 17:54:36 +00:00
|
|
|
std::this_thread::sleep_until(t);
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
Metrics::EndMeasurement(MetricVariable::Sleep);
|
|
|
|
|
|
|
|
if (!ready && Game::server->GetIsConnectedToMaster()) {
|
|
|
|
// Some delay is required here or else we crash the client?
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
framesSinceMasterStatus++;
|
|
|
|
|
|
|
|
if (framesSinceMasterStatus >= 200) {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Finished loading world with zone (%i), ready up!", Game::server->GetZoneID());
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
MasterPackets::SendWorldReady(Game::server, Game::server->GetZoneID(), Game::server->GetInstanceID());
|
|
|
|
|
|
|
|
ready = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-02 03:50:00 +00:00
|
|
|
if (Game::ShouldShutdown() && !worldShutdownSequenceComplete) {
|
2022-04-10 01:35:41 +00:00
|
|
|
WorldShutdownProcess(zoneID);
|
2022-04-09 23:02:27 +00:00
|
|
|
break;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Metrics::AddMeasurement(MetricVariable::CPUTime, (1e6 * (1000.0 * (std::clock() - metricCPUTimeStart))) / CLOCKS_PER_SEC);
|
|
|
|
Metrics::EndMeasurement(MetricVariable::Frame);
|
|
|
|
}
|
2022-04-10 01:35:41 +00:00
|
|
|
FinalizeShutdown();
|
2022-04-09 23:02:27 +00:00
|
|
|
return EXIT_SUCCESS;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HandlePacketChat(Packet* packet) {
|
2024-05-31 04:53:03 +00:00
|
|
|
if (packet->length < 1) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Lost our connection to chat, zone(%i), instance(%i)", Game::server->GetZoneID(), Game::server->GetInstanceID());
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2021-12-20 12:50:53 +00:00
|
|
|
chatConnected = false;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (packet->data[0] == ID_CONNECTION_REQUEST_ACCEPTED) {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Established connection to chat, zone(%i), instance (%i)", Game::server->GetZoneID(), Game::server->GetInstanceID());
|
2021-12-05 17:54:36 +00:00
|
|
|
Game::chatSysAddr = packet->systemAddress;
|
2021-12-20 12:50:53 +00:00
|
|
|
|
|
|
|
chatConnected = true;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-05-31 04:53:03 +00:00
|
|
|
if (packet->data[0] == ID_USER_PACKET_ENUM && packet->length >= 4) {
|
2024-04-01 03:27:50 +00:00
|
|
|
if (static_cast<eConnectionType>(packet->data[1]) == eConnectionType::CHAT) {
|
2024-11-18 00:39:44 +00:00
|
|
|
switch (static_cast<MessageType::Chat>(packet->data[3])) {
|
|
|
|
case MessageType::Chat::WORLD_ROUTE_PACKET: {
|
2024-04-01 03:27:50 +00:00
|
|
|
CINSTREAM_SKIP_HEADER;
|
|
|
|
LWOOBJID playerID;
|
|
|
|
inStream.Read(playerID);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
auto player = Game::entityManager->GetEntity(playerID);
|
|
|
|
if (!player) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
auto sysAddr = player->GetSystemAddress();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
//Write our stream outwards:
|
|
|
|
CBITSTREAM;
|
2024-05-31 04:53:03 +00:00
|
|
|
unsigned char data;
|
|
|
|
while (inStream.Read(data)) {
|
|
|
|
bitStream.Write(data);
|
2024-04-01 03:27:50 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
SEND_PACKET; //send routed packet to player
|
|
|
|
break;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::Chat::GM_ANNOUNCE: {
|
2024-04-01 03:27:50 +00:00
|
|
|
CINSTREAM_SKIP_HEADER;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
std::string title;
|
|
|
|
std::string msg;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
uint32_t len;
|
|
|
|
inStream.Read<uint32_t>(len);
|
|
|
|
for (uint32_t i = 0; len > i; i++) {
|
|
|
|
char character;
|
|
|
|
inStream.Read<char>(character);
|
|
|
|
title += character;
|
|
|
|
}
|
2022-07-17 03:40:46 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
len = 0;
|
|
|
|
inStream.Read<uint32_t>(len);
|
|
|
|
for (uint32_t i = 0; len > i; i++) {
|
|
|
|
char character;
|
|
|
|
inStream.Read<char>(character);
|
|
|
|
msg += character;
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
//Send to our clients:
|
|
|
|
AMFArrayValue args;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
args.Insert("title", title);
|
|
|
|
args.Insert("message", msg);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
GameMessages::SendUIMessageServerToAllClients("ToggleAnnounce", args);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::Chat::GM_MUTE: {
|
2024-04-01 03:27:50 +00:00
|
|
|
CINSTREAM_SKIP_HEADER;
|
|
|
|
LWOOBJID playerId;
|
|
|
|
time_t expire = 0;
|
|
|
|
inStream.Read(playerId);
|
|
|
|
inStream.Read(expire);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
auto* entity = Game::entityManager->GetEntity(playerId);
|
|
|
|
auto* character = entity != nullptr ? entity->GetCharacter() : nullptr;
|
|
|
|
auto* user = character != nullptr ? character->GetParentUser() : nullptr;
|
|
|
|
if (user) {
|
|
|
|
user->SetMuteExpire(expire);
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
entity->GetCharacter()->SendMuteNotice();
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
break;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::Chat::TEAM_GET_STATUS: {
|
2024-04-01 03:27:50 +00:00
|
|
|
CINSTREAM_SKIP_HEADER;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
LWOOBJID teamID = 0;
|
|
|
|
char lootOption = 0;
|
|
|
|
char memberCount = 0;
|
|
|
|
std::vector<LWOOBJID> members;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
inStream.Read(teamID);
|
|
|
|
bool deleteTeam = inStream.ReadBit();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
if (deleteTeam) {
|
|
|
|
TeamManager::Instance()->DeleteTeam(teamID);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
LOG("Deleting team (%llu)", teamID);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
inStream.Read(lootOption);
|
|
|
|
inStream.Read(memberCount);
|
|
|
|
LOG("Updating team (%llu), (%i), (%i)", teamID, lootOption, memberCount);
|
|
|
|
for (char i = 0; i < memberCount; i++) {
|
|
|
|
LWOOBJID member = LWOOBJID_EMPTY;
|
|
|
|
inStream.Read(member);
|
|
|
|
members.push_back(member);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
LOG("Updating team member (%llu)", member);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
TeamManager::Instance()->UpdateTeam(teamID, lootOption, members);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-01 03:27:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
LOG("Received an unknown chat: %i", int(packet->data[3]));
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-06 05:32:09 +00:00
|
|
|
void HandleMasterPacket(Packet* packet) {
|
2024-05-31 04:53:03 +00:00
|
|
|
if (packet->length < 2) return;
|
2024-01-06 05:32:09 +00:00
|
|
|
if (static_cast<eConnectionType>(packet->data[1]) != eConnectionType::MASTER || packet->length < 4) return;
|
2024-11-18 00:39:44 +00:00
|
|
|
switch (static_cast<MessageType::Master>(packet->data[3])) {
|
|
|
|
case MessageType::Master::REQUEST_PERSISTENT_ID_RESPONSE: {
|
2024-01-07 08:02:27 +00:00
|
|
|
CINSTREAM_SKIP_HEADER;
|
|
|
|
uint64_t requestID;
|
|
|
|
inStream.Read(requestID);
|
|
|
|
uint32_t objectID;
|
|
|
|
inStream.Read(objectID);
|
2024-01-06 05:32:09 +00:00
|
|
|
ObjectIDManager::HandleRequestPersistentIDResponse(requestID, objectID);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::Master::SESSION_KEY_RESPONSE: {
|
2024-01-06 05:32:09 +00:00
|
|
|
//Read our session key and to which user it belongs:
|
2024-01-07 08:02:27 +00:00
|
|
|
CINSTREAM_SKIP_HEADER;
|
2024-01-06 05:32:09 +00:00
|
|
|
uint32_t sessionKey = 0;
|
|
|
|
inStream.Read(sessionKey);
|
2024-01-12 20:23:44 +00:00
|
|
|
LUWString username;
|
2024-01-07 08:02:27 +00:00
|
|
|
inStream.Read(username);
|
2024-01-06 05:32:09 +00:00
|
|
|
|
|
|
|
//Find them:
|
2024-01-07 08:02:27 +00:00
|
|
|
auto it = m_PendingUsers.find(username.GetAsString());
|
2024-01-06 05:32:09 +00:00
|
|
|
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 {
|
2024-01-07 08:02:27 +00:00
|
|
|
LOG("User %s authenticated with correct key.", username.GetAsString().c_str());
|
2024-01-06 05:32:09 +00:00
|
|
|
|
|
|
|
UserManager::Instance()->DeleteUser(packet->systemAddress);
|
|
|
|
|
|
|
|
//Create our user and send them in:
|
2024-01-07 08:02:27 +00:00
|
|
|
UserManager::Instance()->CreateUser(it->second.sysAddr, username.GetAsString(), userHash);
|
2024-01-06 05:32:09 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-01-07 07:05:57 +00:00
|
|
|
WorldPackets::SendLoadStaticZone(it->second.sysAddr, x, y, z, zone->GetChecksum(), Game::zoneManager->GetZoneID());
|
2024-01-06 05:32:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-01-07 08:02:27 +00:00
|
|
|
m_PendingUsers.erase(username.GetAsString());
|
2024-01-06 05:32:09 +00:00
|
|
|
|
|
|
|
//Notify master:
|
|
|
|
{
|
|
|
|
CBITSTREAM;
|
2024-11-18 00:39:44 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::PLAYER_ADDED);
|
2024-03-18 01:48:09 +00:00
|
|
|
bitStream.Write<LWOMAPID>(Game::server->GetZoneID());
|
|
|
|
bitStream.Write<LWOINSTANCEID>(instanceID);
|
2024-02-27 05:43:33 +00:00
|
|
|
Game::server->SendToMaster(bitStream);
|
2024-01-06 05:32:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::Master::AFFIRM_TRANSFER_REQUEST: {
|
2024-01-07 08:02:27 +00:00
|
|
|
CINSTREAM_SKIP_HEADER;
|
|
|
|
uint64_t requestID;
|
|
|
|
inStream.Read(requestID);
|
2024-01-06 05:32:09 +00:00
|
|
|
LOG("Got affirmation request of transfer %llu", requestID);
|
|
|
|
|
|
|
|
CBITSTREAM;
|
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::AFFIRM_TRANSFER_RESPONSE);
|
2024-01-06 05:32:09 +00:00
|
|
|
bitStream.Write(requestID);
|
2024-02-27 05:43:33 +00:00
|
|
|
Game::server->SendToMaster(bitStream);
|
2024-01-06 05:32:09 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::Master::SHUTDOWN: {
|
2024-01-06 05:32:09 +00:00
|
|
|
Game::lastSignal = -1;
|
|
|
|
LOG("Got shutdown request from master, zone (%i), instance (%i)", Game::server->GetZoneID(), Game::server->GetInstanceID());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::Master::NEW_SESSION_ALERT: {
|
2024-01-07 08:02:27 +00:00
|
|
|
CINSTREAM_SKIP_HEADER;
|
2024-01-06 05:32:09 +00:00
|
|
|
uint32_t sessionKey = inStream.Read(sessionKey);
|
|
|
|
|
2024-01-12 20:23:44 +00:00
|
|
|
LUString username;
|
2024-01-07 08:02:27 +00:00
|
|
|
inStream.Read(username);
|
|
|
|
LOG("Got new session alert for user %s", username.string.c_str());
|
2024-01-06 05:32:09 +00:00
|
|
|
//Find them:
|
2024-01-07 08:02:27 +00:00
|
|
|
User* user = UserManager::Instance()->GetUser(username.string.c_str());
|
2024-01-06 05:32:09 +00:00
|
|
|
if (!user) {
|
2024-01-07 08:02:27 +00:00
|
|
|
LOG("But they're not logged in?");
|
2024-01-06 05:32:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Check the key:
|
|
|
|
if (sessionKey != std::atoi(user->GetSessionKey().c_str())) {
|
2024-01-07 08:02:27 +00:00
|
|
|
LOG("But the session key is invalid!", username.string.c_str());
|
2024-01-06 05:32:09 +00:00
|
|
|
Game::server->Disconnect(user->GetSystemAddress(), eServerDisconnectIdentifiers::INVALID_SESSION_KEY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
LOG("Unknown packet ID from master %i", int(packet->data[3]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
void HandlePacket(Packet* packet) {
|
2024-05-31 04:53:03 +00:00
|
|
|
if (packet->length < 1) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) {
|
|
|
|
auto user = UserManager::Instance()->GetUser(packet->systemAddress);
|
|
|
|
if (!user) return;
|
|
|
|
|
|
|
|
auto c = user->GetLastUsedChar();
|
|
|
|
if (!c) {
|
|
|
|
UserManager::Instance()->DeleteUser(packet->systemAddress);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* entity = Game::entityManager->GetEntity(c->GetObjectID());
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (!entity) {
|
2024-01-13 09:40:56 +00:00
|
|
|
entity = PlayerManager::GetPlayer(packet->systemAddress);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (entity) {
|
|
|
|
auto* skillComponent = entity->GetComponent<SkillComponent>();
|
|
|
|
|
|
|
|
if (skillComponent != nullptr) {
|
|
|
|
skillComponent->Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
entity->GetCharacter()->SaveXMLToDatabase();
|
|
|
|
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Deleting player %llu", entity->GetObjectID());
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->DestroyEntity(entity);
|
2022-07-13 03:36:06 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-13 03:36:06 +00:00
|
|
|
{
|
2021-12-05 17:54:36 +00:00
|
|
|
CBITSTREAM;
|
2024-11-18 00:39:44 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::UNEXPECTED_DISCONNECT);
|
2022-07-13 03:36:06 +00:00
|
|
|
bitStream.Write(user->GetLoggedInChar());
|
2021-12-05 17:54:36 +00:00
|
|
|
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
UserManager::Instance()->DeleteUser(packet->systemAddress);
|
|
|
|
|
|
|
|
if (PropertyManagementComponent::Instance() != nullptr) {
|
|
|
|
PropertyManagementComponent::Instance()->Save();
|
|
|
|
}
|
|
|
|
|
|
|
|
CBITSTREAM;
|
2024-11-18 00:39:44 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::PLAYER_REMOVED);
|
2024-03-18 01:48:09 +00:00
|
|
|
bitStream.Write<LWOMAPID>(Game::server->GetZoneID());
|
|
|
|
bitStream.Write<LWOINSTANCEID>(instanceID);
|
2024-02-27 05:43:33 +00:00
|
|
|
Game::server->SendToMaster(bitStream);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-05-06 18:32:53 +00:00
|
|
|
if (packet->data[0] != ID_USER_PACKET_ENUM || packet->length < 4) return;
|
2023-05-03 21:38:32 +00:00
|
|
|
if (static_cast<eConnectionType>(packet->data[1]) == eConnectionType::SERVER) {
|
2024-11-18 00:39:44 +00:00
|
|
|
if (static_cast<MessageType::Server>(packet->data[3]) == MessageType::Server::VERSION_CONFIRM) {
|
2021-12-05 17:54:36 +00:00
|
|
|
AuthPackets::HandleHandshake(Game::server, packet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-03 21:38:32 +00:00
|
|
|
if (static_cast<eConnectionType>(packet->data[1]) != eConnectionType::WORLD) return;
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
switch (static_cast<MessageType::World>(packet->data[3])) {
|
|
|
|
case MessageType::World::VALIDATION: {
|
2024-01-07 08:02:27 +00:00
|
|
|
CINSTREAM_SKIP_HEADER;
|
2024-01-12 20:23:44 +00:00
|
|
|
LUWString username;
|
2024-01-07 08:02:27 +00:00
|
|
|
inStream.Read(username);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-12 20:23:44 +00:00
|
|
|
LUWString sessionKey;
|
2021-12-14 19:25:30 +00:00
|
|
|
// sometimes client puts a null terminator at the end of the checksum and sometimes doesn't, weird
|
2024-01-07 08:02:27 +00:00
|
|
|
inStream.Read(sessionKey);
|
|
|
|
LUString clientDatabaseChecksum(32);
|
|
|
|
inStream.Read(clientDatabaseChecksum);
|
2021-12-14 19:25:30 +00:00
|
|
|
|
2021-12-16 22:11:51 +00:00
|
|
|
// If the check is turned on, validate the client's database checksum.
|
|
|
|
if (Game::config->GetValue("check_fdb") == "1" && !databaseChecksum.empty()) {
|
2024-01-07 08:02:27 +00:00
|
|
|
auto accountInfo = Database::Get()->GetAccountInfo(username.GetAsString());
|
2023-11-18 00:47:18 +00:00
|
|
|
if (!accountInfo) {
|
|
|
|
LOG("Client's account does not exist in the database, aborting connection.");
|
|
|
|
Game::server->Disconnect(packet->systemAddress, eServerDisconnectIdentifiers::CHARACTER_NOT_FOUND);
|
|
|
|
return;
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-16 22:11:51 +00:00
|
|
|
// Developers may skip this check
|
2024-01-18 08:10:52 +00:00
|
|
|
if (clientDatabaseChecksum.string != databaseChecksum) {
|
|
|
|
|
|
|
|
if (accountInfo->maxGmLevel < eGameMasterLevel::DEVELOPER) {
|
|
|
|
LOG("Client's database checksum does not match the server's, aborting connection.");
|
|
|
|
std::vector<Stamp> stamps;
|
|
|
|
|
|
|
|
// Using the LoginResponse here since the UI is still in the login screen state
|
|
|
|
// and we have a way to send a message about the client mismatch.
|
|
|
|
AuthPackets::SendLoginResponse(
|
|
|
|
Game::server, packet->systemAddress, eLoginResponse::PERMISSIONS_NOT_HIGH_ENOUGH,
|
|
|
|
Game::config->GetValue("cdclient_mismatch_message"), "", 0, "", stamps);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
AMFArrayValue args;
|
|
|
|
|
|
|
|
args.Insert("title", Game::config->GetValue("cdclient_mismatch_title"));
|
|
|
|
args.Insert("message", Game::config->GetValue("cdclient_mismatch_message"));
|
|
|
|
|
|
|
|
GameMessages::SendUIMessageServerToSingleClient("ToggleAnnounce", args, packet->systemAddress);
|
|
|
|
LOG("Account (%s) with GmLevel (%s) does not have a matching FDB, but is a developer and will skip this check."
|
|
|
|
, username.GetAsString().c_str(), StringifiedEnum::ToString(accountInfo->maxGmLevel).data());
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Request the session info from Master:
|
|
|
|
CBITSTREAM;
|
2024-11-18 00:39:44 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::REQUEST_SESSION_KEY);
|
2024-01-07 08:02:27 +00:00
|
|
|
bitStream.Write(username);
|
2024-02-27 05:43:33 +00:00
|
|
|
Game::server->SendToMaster(bitStream);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
//Insert info into our pending list
|
|
|
|
tempSessionInfo info;
|
|
|
|
info.sysAddr = SystemAddress(packet->systemAddress);
|
2024-01-07 08:02:27 +00:00
|
|
|
info.hash = sessionKey.GetAsString();
|
|
|
|
m_PendingUsers.insert(std::make_pair(username.GetAsString(), info));
|
2022-07-28 13:39:57 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::World::CHARACTER_LIST_REQUEST: {
|
2021-12-05 17:54:36 +00:00
|
|
|
//We need to delete the entity first, otherwise the char list could delete it while it exists in the world!
|
|
|
|
if (Game::server->GetZoneID() != 0) {
|
2022-07-13 03:36:06 +00:00
|
|
|
auto user = UserManager::Instance()->GetUser(packet->systemAddress);
|
2023-11-05 09:00:19 +00:00
|
|
|
if (!user || !user->GetLastUsedChar()) return;
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->DestroyEntity(user->GetLastUsedChar()->GetEntity());
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//This loops prevents users who aren't authenticated to double-request the char list, which
|
2022-05-09 22:33:43 +00:00
|
|
|
//would make the login screen freeze sometimes.
|
2021-12-05 17:54:36 +00:00
|
|
|
if (m_PendingUsers.size() > 0) {
|
|
|
|
for (auto it : m_PendingUsers) {
|
|
|
|
if (it.second.sysAddr == packet->systemAddress) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UserManager::Instance()->RequestCharacterList(packet->systemAddress);
|
|
|
|
break;
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::World::GAME_MSG: {
|
2021-12-05 17:54:36 +00:00
|
|
|
RakNet::BitStream bitStream(packet->data, packet->length, false);
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
uint64_t header;
|
|
|
|
LWOOBJID objectID;
|
2024-11-18 00:39:44 +00:00
|
|
|
MessageType::Game messageID;
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
bitStream.Read(header);
|
|
|
|
bitStream.Read(objectID);
|
|
|
|
bitStream.Read(messageID);
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
RakNet::BitStream dataStream;
|
|
|
|
bitStream.Read(dataStream, bitStream.GetNumberOfUnreadBits());
|
|
|
|
|
2023-09-28 17:16:11 +00:00
|
|
|
auto isSender = CheatDetection::VerifyLwoobjidIsSender(
|
|
|
|
objectID,
|
|
|
|
packet->systemAddress,
|
|
|
|
CheckType::Entity,
|
|
|
|
"Sending GM with a sending player that does not match their own. GM ID: %i",
|
|
|
|
static_cast<int32_t>(messageID)
|
2023-11-18 00:47:18 +00:00
|
|
|
);
|
2023-09-28 17:16:11 +00:00
|
|
|
|
2024-02-26 14:17:22 +00:00
|
|
|
if (isSender) GameMessageHandler::HandleMessage(dataStream, packet->systemAddress, objectID, messageID);
|
2021-12-05 17:54:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::World::CHARACTER_CREATE_REQUEST: {
|
2021-12-05 17:54:36 +00:00
|
|
|
UserManager::Instance()->CreateCharacter(packet->systemAddress, packet);
|
|
|
|
break;
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::World::LOGIN_REQUEST: {
|
2021-12-05 17:54:36 +00:00
|
|
|
RakNet::BitStream inStream(packet->data, packet->length, false);
|
|
|
|
uint64_t header = inStream.Read(header);
|
|
|
|
|
|
|
|
LWOOBJID playerID = 0;
|
2022-07-13 03:36:06 +00:00
|
|
|
inStream.Read(playerID);
|
2023-09-28 17:16:11 +00:00
|
|
|
|
|
|
|
bool valid = CheatDetection::VerifyLwoobjidIsSender(
|
|
|
|
playerID,
|
|
|
|
packet->systemAddress,
|
|
|
|
CheckType::User,
|
|
|
|
"Sending login request with a sending player that does not match their own. Player ID: %llu",
|
|
|
|
playerID
|
2023-11-18 00:47:18 +00:00
|
|
|
);
|
2023-09-28 17:16:11 +00:00
|
|
|
|
|
|
|
if (!valid) return;
|
|
|
|
|
2023-04-25 18:17:40 +00:00
|
|
|
GeneralUtils::ClearBit(playerID, eObjectBits::CHARACTER);
|
|
|
|
GeneralUtils::ClearBit(playerID, eObjectBits::PERSISTENT);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2022-07-13 03:36:06 +00:00
|
|
|
auto user = UserManager::Instance()->GetUser(packet->systemAddress);
|
|
|
|
|
|
|
|
if (user) {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto lastCharacter = user->GetLoggedInChar();
|
|
|
|
// This means we swapped characters and we need to remove the previous player from the container.
|
|
|
|
if (static_cast<uint32_t>(lastCharacter) != playerID) {
|
2022-07-13 03:36:06 +00:00
|
|
|
CBITSTREAM;
|
2024-11-18 00:39:44 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::UNEXPECTED_DISCONNECT);
|
2021-12-05 17:54:36 +00:00
|
|
|
bitStream.Write(lastCharacter);
|
|
|
|
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false);
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UserManager::Instance()->LoginCharacter(packet->systemAddress, static_cast<uint32_t>(playerID));
|
|
|
|
break;
|
|
|
|
}
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::World::CHARACTER_DELETE_REQUEST: {
|
2021-12-05 17:54:36 +00:00
|
|
|
UserManager::Instance()->DeleteCharacter(packet->systemAddress, packet);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::World::CHARACTER_RENAME_REQUEST: {
|
2021-12-05 17:54:36 +00:00
|
|
|
UserManager::Instance()->RenameCharacter(packet->systemAddress, packet);
|
|
|
|
break;
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::World::LEVEL_LOAD_COMPLETE: {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Received level load complete from user.");
|
2021-12-05 17:54:36 +00:00
|
|
|
User* user = UserManager::Instance()->GetUser(packet->systemAddress);
|
2022-07-13 03:36:06 +00:00
|
|
|
if (user) {
|
2021-12-05 17:54:36 +00:00
|
|
|
Character* c = user->GetLastUsedChar();
|
2022-05-09 22:33:43 +00:00
|
|
|
if (c != nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
std::u16string username = GeneralUtils::ASCIIToUTF16(c->GetName());
|
|
|
|
Game::server->GetReplicaManager()->AddParticipant(packet->systemAddress);
|
|
|
|
|
|
|
|
EntityInfo info{};
|
|
|
|
info.lot = 1;
|
2023-07-15 20:56:33 +00:00
|
|
|
Entity* player = Game::entityManager->CreateEntity(info, UserManager::Instance()->GetUser(packet->systemAddress));
|
2022-04-01 01:17:43 +00:00
|
|
|
|
2024-01-07 07:05:57 +00:00
|
|
|
auto* characterComponent = player->GetComponent<CharacterComponent>();
|
|
|
|
if (!characterComponent) return;
|
|
|
|
|
|
|
|
WorldPackets::SendCreateCharacter(packet->systemAddress, player->GetComponent<CharacterComponent>()->GetReputation(), player->GetObjectID(), c->GetXMLData(), username, c->GetGMLevel());
|
2021-12-05 17:54:36 +00:00
|
|
|
WorldPackets::SendServerState(packet->systemAddress);
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2023-07-17 22:55:33 +00:00
|
|
|
const auto respawnPoint = player->GetCharacter()->GetRespawnPoint(Game::zoneManager->GetZone()->GetWorldID());
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->ConstructEntity(player, UNASSIGNED_SYSTEM_ADDRESS, true);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-29 07:53:12 +00:00
|
|
|
if (respawnPoint != NiPoint3Constant::ZERO) {
|
|
|
|
GameMessages::SendPlayerReachedRespawnCheckpoint(player, respawnPoint, NiQuaternionConstant::IDENTITY);
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2022-05-09 00:57:36 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->ConstructAllEntities(packet->systemAddress);
|
2022-05-09 00:57:36 +00:00
|
|
|
|
2023-11-22 02:05:15 +00:00
|
|
|
characterComponent->RocketUnEquip(player);
|
2022-01-19 01:51:12 +00:00
|
|
|
|
2022-12-19 19:45:50 +00:00
|
|
|
// Do charxml fixes here
|
|
|
|
auto* levelComponent = player->GetComponent<LevelProgressionComponent>();
|
2024-11-18 00:08:36 +00:00
|
|
|
auto* const inventoryComponent = player->GetComponent<InventoryComponent>();
|
|
|
|
const auto* const missionComponent = player->GetComponent<MissionComponent>();
|
|
|
|
if (!levelComponent || !missionComponent || !inventoryComponent) return;
|
2022-12-19 19:45:50 +00:00
|
|
|
|
|
|
|
auto version = levelComponent->GetCharacterVersion();
|
2023-11-18 00:47:18 +00:00
|
|
|
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();
|
2024-11-18 00:08:36 +00:00
|
|
|
levelComponent->SetCharacterVersion(eCharacterVersion::SPEED_BASE);
|
|
|
|
case eCharacterVersion::SPEED_BASE: {
|
|
|
|
LOG("Removing lots from NJ Jay missions bugged at foss");
|
|
|
|
// https://explorer.lu/missions/1789
|
|
|
|
const auto* mission = missionComponent->GetMission(1789);
|
|
|
|
if (mission && mission->IsComplete()) {
|
|
|
|
inventoryComponent->RemoveItem(14474, 1, eInventoryType::ITEMS);
|
|
|
|
inventoryComponent->RemoveItem(14474, 1, eInventoryType::VAULT_ITEMS);
|
|
|
|
}
|
|
|
|
// https://explorer.lu/missions/1927
|
|
|
|
mission = missionComponent->GetMission(1927);
|
|
|
|
if (mission && mission->IsComplete()) {
|
|
|
|
inventoryComponent->RemoveItem(14493, 1, eInventoryType::ITEMS);
|
|
|
|
inventoryComponent->RemoveItem(14493, 1, eInventoryType::VAULT_ITEMS);
|
|
|
|
}
|
2023-11-18 00:47:18 +00:00
|
|
|
levelComponent->SetCharacterVersion(eCharacterVersion::UP_TO_DATE);
|
2024-11-18 00:08:36 +00:00
|
|
|
}
|
2023-11-18 00:47:18 +00:00
|
|
|
case eCharacterVersion::UP_TO_DATE:
|
|
|
|
break;
|
2022-12-19 19:45:50 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
player->GetCharacter()->SetTargetScene("");
|
|
|
|
|
|
|
|
// Fix the destroyable component
|
|
|
|
auto* destroyableComponent = player->GetComponent<DestroyableComponent>();
|
|
|
|
|
|
|
|
if (destroyableComponent != nullptr) {
|
|
|
|
destroyableComponent->FixStats();
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
//Tell the player to generate BBB models, if any:
|
|
|
|
if (g_CloneID != 0) {
|
2023-07-17 22:55:33 +00:00
|
|
|
const auto& worldId = Game::zoneManager->GetZone()->GetZoneID();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-11-18 00:47:18 +00:00
|
|
|
const auto zoneId = worldId.GetMapID();
|
2022-01-13 03:48:27 +00:00
|
|
|
const auto cloneId = g_CloneID;
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//Check for BBB models:
|
2023-11-18 00:47:18 +00:00
|
|
|
auto propertyInfo = Database::Get()->GetPropertyInfo(zoneId, cloneId);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-11-18 00:47:18 +00:00
|
|
|
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;
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2023-11-18 00:47:18 +00:00
|
|
|
for (auto& bbbModel : Database::Get()->GetUgcModels(propertyId)) {
|
|
|
|
LOG("Getting lxfml ugcID: %llu", bbbModel.id);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-11-18 00:47:18 +00:00
|
|
|
bbbModel.lxfmlData.seekg(0, std::ios::end);
|
|
|
|
size_t lxfmlSize = bbbModel.lxfmlData.tellg();
|
|
|
|
bbbModel.lxfmlData.seekg(0);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-11-18 00:47:18 +00:00
|
|
|
//Send message:
|
|
|
|
LWOOBJID blueprintID = bbbModel.id;
|
|
|
|
GeneralUtils::SetBit(blueprintID, eObjectBits::CHARACTER);
|
|
|
|
GeneralUtils::SetBit(blueprintID, eObjectBits::PERSISTENT);
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2023-11-18 00:47:18 +00:00
|
|
|
CBITSTREAM;
|
2024-11-18 00:39:44 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::BLUEPRINT_SAVE_RESPONSE);
|
2023-11-18 00:47:18 +00:00
|
|
|
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);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-11-18 00:47:18 +00:00
|
|
|
bitStream.Write<uint32_t>(lxfmlSize);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-11-18 00:47:18 +00:00
|
|
|
bitStream.WriteAlignedBytes(reinterpret_cast<const unsigned char*>(bbbModel.lxfmlData.str().c_str()), lxfmlSize);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-11-18 00:47:18 +00:00
|
|
|
SystemAddress sysAddr = packet->systemAddress;
|
|
|
|
SEND_PACKET;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
noBBB:
|
|
|
|
|
|
|
|
// Tell the client it's done loading:
|
|
|
|
GameMessages::SendInvalidZoneTransferList(player, packet->systemAddress, GeneralUtils::ASCIIToUTF16(Game::config->GetValue("source")), u"", false, false);
|
|
|
|
GameMessages::SendServerDoneLoadingAllObjects(player, packet->systemAddress);
|
|
|
|
|
|
|
|
//Send the player it's mail count:
|
|
|
|
//update: this might not be needed so im going to try disabling this here.
|
|
|
|
//Mail::HandleNotificationRequest(packet->systemAddress, player->GetObjectID());
|
2022-05-09 22:33:43 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//Notify chat that a player has loaded:
|
2024-02-04 14:29:05 +00:00
|
|
|
auto* character = player->GetCharacter();
|
|
|
|
auto* user = character != nullptr ? character->GetParentUser() : nullptr;
|
|
|
|
if (user) {
|
|
|
|
const auto& playerName = character->GetName();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
CBITSTREAM;
|
2024-11-18 00:39:44 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::LOGIN_SESSION_NOTIFY);
|
2021-12-05 17:54:36 +00:00
|
|
|
bitStream.Write(player->GetObjectID());
|
|
|
|
bitStream.Write<uint32_t>(playerName.size());
|
|
|
|
for (size_t i = 0; i < playerName.size(); i++) {
|
|
|
|
bitStream.Write(playerName[i]);
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-17 22:55:33 +00:00
|
|
|
auto zone = Game::zoneManager->GetZone()->GetZoneID();
|
2021-12-05 17:54:36 +00:00
|
|
|
bitStream.Write(zone.GetMapID());
|
2022-07-25 02:26:51 +00:00
|
|
|
bitStream.Write(zone.GetInstanceID());
|
|
|
|
bitStream.Write(zone.GetCloneID());
|
2024-02-04 14:29:05 +00:00
|
|
|
bitStream.Write(user->GetMuteExpire());
|
2024-01-14 07:03:01 +00:00
|
|
|
bitStream.Write(player->GetGMLevel());
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false);
|
|
|
|
}
|
|
|
|
} else {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Couldn't find character to log in with for user %s (%i)!", user->GetUsername().c_str(), user->GetAccountID());
|
2023-02-19 12:29:14 +00:00
|
|
|
Game::server->Disconnect(packet->systemAddress, eServerDisconnectIdentifiers::CHARACTER_NOT_FOUND);
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
|
|
|
} else {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Couldn't get user for level load complete!");
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::World::POSITION_UPDATE: {
|
2024-01-07 07:05:57 +00:00
|
|
|
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);
|
2021-12-05 17:54:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::World::MAIL: {
|
2021-12-05 17:54:36 +00:00
|
|
|
RakNet::BitStream bitStream(packet->data, packet->length, false);
|
2023-09-28 17:16:11 +00:00
|
|
|
// FIXME: Change this to the macro to skip the header...
|
2021-12-05 17:54:36 +00:00
|
|
|
LWOOBJID space;
|
|
|
|
bitStream.Read(space);
|
2024-02-27 04:01:18 +00:00
|
|
|
Mail::HandleMailStuff(bitStream, packet->systemAddress, UserManager::Instance()->GetUser(packet->systemAddress)->GetLastUsedChar()->GetEntity());
|
2022-07-28 13:39:57 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::World::ROUTE_PACKET: {
|
2022-07-25 02:26:51 +00:00
|
|
|
//Yeet to chat
|
2023-05-08 11:31:10 +00:00
|
|
|
CINSTREAM_SKIP_HEADER;
|
2022-07-25 02:26:51 +00:00
|
|
|
uint32_t size = 0;
|
|
|
|
inStream.Read(size);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (size > 20000) {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Tried to route a packet with a read size > 20000, so likely a false packet.");
|
2022-07-28 13:39:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
CBITSTREAM;
|
|
|
|
|
2023-09-21 01:06:28 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, packet->data[14]);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
//We need to insert the player's objectID so the chat server can find who originated this request:
|
|
|
|
LWOOBJID objectID = 0;
|
|
|
|
auto user = UserManager::Instance()->GetUser(packet->systemAddress);
|
|
|
|
if (user) {
|
|
|
|
objectID = user->GetLastUsedChar()->GetObjectID();
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
bitStream.Write(objectID);
|
|
|
|
|
|
|
|
//Now write the rest of the data:
|
|
|
|
auto data = inStream.GetData();
|
2024-05-31 04:53:03 +00:00
|
|
|
for (uint32_t i = 23; i - 23 < size && i < packet->length; ++i) {
|
|
|
|
bitStream.Write(data[i]);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE_ORDERED, 0, Game::chatSysAddr, false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::World::STRING_CHECK: {
|
2024-01-07 07:05:57 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-01-13 09:40:56 +00:00
|
|
|
auto* entity = PlayerManager::GetPlayer(packet->systemAddress);
|
2024-01-07 07:05:57 +00:00
|
|
|
|
|
|
|
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);
|
2022-07-28 13:39:57 +00:00
|
|
|
break;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::World::GENERAL_CHAT_MESSAGE: {
|
2021-12-05 17:54:36 +00:00
|
|
|
if (chatDisabled) {
|
|
|
|
ChatPackets::SendMessageFail(packet->systemAddress);
|
2022-07-28 13:39:57 +00:00
|
|
|
} else {
|
2024-01-07 07:05:57 +00:00
|
|
|
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);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::World::HANDLE_FUNNESS: {
|
2021-12-05 17:54:36 +00:00
|
|
|
//This means the client is running slower or faster than it should.
|
|
|
|
//Could be insane lag, but I'mma just YEET them as it's usually speedhacking.
|
|
|
|
//This is updated to now count the amount of times we've been caught "speedhacking" to kick with a delay
|
|
|
|
//This is hopefully going to fix the random disconnects people face sometimes.
|
|
|
|
if (Game::config->GetValue("disable_anti_speedhack") == "1") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
User* user = UserManager::Instance()->GetUser(packet->systemAddress);
|
|
|
|
if (user) {
|
|
|
|
user->UserOutOfSync();
|
2022-07-28 13:39:57 +00:00
|
|
|
} else {
|
2023-02-19 12:29:14 +00:00
|
|
|
Game::server->Disconnect(packet->systemAddress, eServerDisconnectIdentifiers::KICK);
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-11-16 01:30:46 +00:00
|
|
|
|
2024-11-18 00:39:44 +00:00
|
|
|
case MessageType::World::UI_HELP_TOP_5: {
|
2024-01-07 07:05:57 +00:00
|
|
|
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);
|
2023-11-16 01:30:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
default:
|
2024-11-18 00:39:44 +00:00
|
|
|
const auto messageId = *reinterpret_cast<MessageType::World*>(&packet->data[3]);
|
2023-12-24 00:11:00 +00:00
|
|
|
const std::string_view messageIdString = StringifiedEnum::ToString(messageId);
|
2023-12-23 16:51:59 +00:00
|
|
|
LOG("Unknown world packet received: %4i, %s", messageId, messageIdString.data());
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-10 01:35:41 +00:00
|
|
|
void WorldShutdownProcess(uint32_t zoneId) {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Saving map %i instance %i", zoneId, instanceID);
|
2022-04-10 01:35:41 +00:00
|
|
|
for (auto i = 0; i < Game::server->GetReplicaManager()->GetParticipantCount(); ++i) {
|
|
|
|
const auto& player = Game::server->GetReplicaManager()->GetParticipantAtIndex(i);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-01-13 09:40:56 +00:00
|
|
|
auto* entity = PlayerManager::GetPlayer(player);
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Saving data!");
|
2022-04-10 01:35:41 +00:00
|
|
|
if (entity != nullptr && entity->GetCharacter() != nullptr) {
|
|
|
|
auto* skillComponent = entity->GetComponent<SkillComponent>();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2022-04-10 01:35:41 +00:00
|
|
|
if (skillComponent != nullptr) {
|
|
|
|
skillComponent->Reset();
|
|
|
|
}
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Saving character %s...", entity->GetCharacter()->GetName().c_str());
|
2022-04-10 01:35:41 +00:00
|
|
|
entity->GetCharacter()->SaveXMLToDatabase();
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Character data for %s was saved!", entity->GetCharacter()->GetName().c_str());
|
2022-04-10 01:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2022-04-10 01:35:41 +00:00
|
|
|
if (PropertyManagementComponent::Instance() != nullptr) {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Saving ALL property data for zone %i clone %i!", zoneId, PropertyManagementComponent::Instance()->GetCloneId());
|
2022-04-10 01:35:41 +00:00
|
|
|
PropertyManagementComponent::Instance()->Save();
|
2023-11-18 00:47:18 +00:00
|
|
|
Database::Get()->RemoveUnreferencedUgcModels();
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("ALL property data saved for zone %i clone %i!", zoneId, PropertyManagementComponent::Instance()->GetCloneId());
|
2022-04-10 01:35:41 +00:00
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("ALL DATA HAS BEEN SAVED FOR ZONE %i INSTANCE %i!", zoneId, instanceID);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2022-04-10 01:35:41 +00:00
|
|
|
while (Game::server->GetReplicaManager()->GetParticipantCount() > 0) {
|
|
|
|
const auto& player = Game::server->GetReplicaManager()->GetParticipantAtIndex(0);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-02-19 12:29:14 +00:00
|
|
|
Game::server->Disconnect(player, eServerDisconnectIdentifiers::SERVER_SHUTDOWN);
|
2022-04-10 01:35:41 +00:00
|
|
|
}
|
|
|
|
SendShutdownMessageToMaster();
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-04-10 01:35:41 +00:00
|
|
|
void WorldShutdownSequence() {
|
2024-01-03 00:28:17 +00:00
|
|
|
bool shouldShutdown = Game::ShouldShutdown() || worldShutdownSequenceComplete;
|
2024-01-02 03:50:00 +00:00
|
|
|
Game::lastSignal = -1;
|
2023-12-16 18:27:06 +00:00
|
|
|
#ifndef DARKFLAME_PLATFORM_WIN32
|
2024-01-03 00:28:17 +00:00
|
|
|
if (shouldShutdown)
|
2023-12-16 18:27:06 +00:00
|
|
|
#endif
|
|
|
|
{
|
2022-04-10 01:35:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-03 00:28:17 +00:00
|
|
|
if (!Game::logger) return;
|
|
|
|
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Zone (%i) instance (%i) shutting down outside of main loop!", Game::server->GetZoneID(), instanceID);
|
2022-04-10 01:35:41 +00:00
|
|
|
WorldShutdownProcess(Game::server->GetZoneID());
|
|
|
|
FinalizeShutdown();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-04-10 01:35:41 +00:00
|
|
|
|
|
|
|
void FinalizeShutdown() {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Shutdown complete, zone (%i), instance (%i)", Game::server->GetZoneID(), instanceID);
|
2022-04-10 01:35:41 +00:00
|
|
|
|
2022-12-15 14:13:49 +00:00
|
|
|
//Delete our objects here:
|
2022-04-10 01:35:41 +00:00
|
|
|
Metrics::Clear();
|
2024-01-19 21:12:05 +00:00
|
|
|
dpWorld::Shutdown();
|
2022-04-10 01:35:41 +00:00
|
|
|
Database::Destroy("WorldServer");
|
2022-12-15 14:13:49 +00:00
|
|
|
if (Game::chatFilter) delete Game::chatFilter;
|
2023-12-16 18:27:06 +00:00
|
|
|
Game::chatFilter = nullptr;
|
2023-07-17 22:55:33 +00:00
|
|
|
if (Game::zoneManager) delete Game::zoneManager;
|
2023-12-16 18:27:06 +00:00
|
|
|
Game::zoneManager = nullptr;
|
2022-12-15 14:13:49 +00:00
|
|
|
if (Game::server) delete Game::server;
|
2023-12-16 18:27:06 +00:00
|
|
|
Game::server = nullptr;
|
2022-12-15 14:13:49 +00:00
|
|
|
if (Game::config) delete Game::config;
|
2023-12-16 18:27:06 +00:00
|
|
|
Game::config = nullptr;
|
2023-07-15 20:56:33 +00:00
|
|
|
if (Game::entityManager) delete Game::entityManager;
|
2023-12-16 18:27:06 +00:00
|
|
|
Game::entityManager = nullptr;
|
2023-07-17 22:55:33 +00:00
|
|
|
if (Game::logger) delete Game::logger;
|
2023-12-16 18:27:06 +00:00
|
|
|
Game::logger = nullptr;
|
2022-04-10 01:35:41 +00:00
|
|
|
|
|
|
|
worldShutdownSequenceComplete = true;
|
|
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendShutdownMessageToMaster() {
|
|
|
|
CBITSTREAM;
|
2024-11-18 00:39:44 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::SHUTDOWN_RESPONSE);
|
2024-02-27 05:43:33 +00:00
|
|
|
Game::server->SendToMaster(bitStream);
|
2022-07-27 06:52:53 +00:00
|
|
|
}
|