Set url from world config instead of hardcoding

This commit is contained in:
Aaron Kimbre 2022-05-09 17:33:43 -05:00
parent d7eb8783a8
commit 875827d688

View File

@ -102,7 +102,7 @@ int main(int argc, char** argv) {
// Triggers the shutdown sequence at application exit // Triggers the shutdown sequence at application exit
std::atexit(WorldShutdownSequence); std::atexit(WorldShutdownSequence);
signal(SIGINT, [](int){ WorldShutdownSequence(); }); signal(SIGINT, [](int){ WorldShutdownSequence(); });
signal(SIGTERM, [](int){ WorldShutdownSequence(); }); signal(SIGTERM, [](int){ WorldShutdownSequence(); });
@ -125,7 +125,7 @@ int main(int argc, char** argv) {
//Create all the objects we need to run our service: //Create all the objects we need to run our service:
Game::logger = SetupLogger(zoneID, instanceID); Game::logger = SetupLogger(zoneID, instanceID);
if (!Game::logger) return 0; if (!Game::logger) return 0;
Game::logger->SetLogToConsole(true); //We want this info to always be logged. Game::logger->SetLogToConsole(true); //We want this info to always be logged.
Game::logger->Log("WorldServer", "Starting World server...\n"); Game::logger->Log("WorldServer", "Starting World server...\n");
Game::logger->Log("WorldServer", "Version: %i.%i\n", PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR); Game::logger->Log("WorldServer", "Version: %i.%i\n", PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR);
@ -151,7 +151,7 @@ int main(int argc, char** argv) {
Game::logger->Log("WorldServer", "Error Code: %i\n", e.errorCode()); Game::logger->Log("WorldServer", "Error Code: %i\n", e.errorCode());
return -1; return -1;
} }
CDClientManager::Instance()->Initialize(); CDClientManager::Instance()->Initialize();
//Connect to the MySQL Database //Connect to the MySQL Database
@ -197,7 +197,7 @@ int main(int argc, char** argv) {
//Connect to the chat server: //Connect to the chat server:
int chatPort = 1501; int chatPort = 1501;
if (config.GetValue("chat_server_port") != "") chatPort = std::atoi(config.GetValue("chat_server_port").c_str()); if (config.GetValue("chat_server_port") != "") chatPort = std::atoi(config.GetValue("chat_server_port").c_str());
auto chatSock = SocketDescriptor(uint16_t(ourPort + 2), 0); auto chatSock = SocketDescriptor(uint16_t(ourPort + 2), 0);
Game::chatServer = RakNetworkFactory::GetRakPeerInterface(); Game::chatServer = RakNetworkFactory::GetRakPeerInterface();
Game::chatServer->Startup(1, 30, &chatSock, 1); Game::chatServer->Startup(1, 30, &chatSock, 1);
@ -218,7 +218,7 @@ int main(int argc, char** argv) {
int framesSinceLastUsersSave = 0; int framesSinceLastUsersSave = 0;
int framesSinceLastSQLPing = 0; int framesSinceLastSQLPing = 0;
int framesSinceLastUser = 0; int framesSinceLastUser = 0;
const float maxPacketProcessingTime = 1.5f; //0.015f; const float maxPacketProcessingTime = 1.5f; //0.015f;
const int maxPacketsToProcess = 1024; const int maxPacketsToProcess = 1024;
@ -249,7 +249,7 @@ int main(int argc, char** argv) {
"res/CDClient.fdb", "res/CDClient.fdb",
"res/cdclient.fdb", "res/cdclient.fdb",
}; };
for (const auto& file : aliases) { for (const auto& file : aliases) {
fileStream.open(file, std::ios::binary | std::ios::in); fileStream.open(file, std::ios::binary | std::ios::in);
if (fileStream.is_open()) { if (fileStream.is_open()) {
@ -259,7 +259,7 @@ int main(int argc, char** argv) {
const int bufferSize = 1024; const int bufferSize = 1024;
MD5* md5 = new MD5(); MD5* md5 = new MD5();
char fileStreamBuffer[1024] = {}; char fileStreamBuffer[1024] = {};
while (!fileStream.eof()) { while (!fileStream.eof()) {
@ -274,7 +274,7 @@ int main(int argc, char** argv) {
md5->update(nullTerminateBuffer, 1); // null terminate the data md5->update(nullTerminateBuffer, 1); // null terminate the data
md5->finalize(); md5->finalize();
databaseChecksum = md5->hexdigest(); databaseChecksum = md5->hexdigest();
delete md5; delete md5;
Game::logger->Log("WorldServer", "FDB Checksum calculated as: %s\n", databaseChecksum.c_str()); Game::logger->Log("WorldServer", "FDB Checksum calculated as: %s\n", databaseChecksum.c_str());
@ -360,7 +360,7 @@ int main(int argc, char** argv) {
//Check for packets here: //Check for packets here:
packet = Game::server->ReceiveFromMaster(); packet = Game::server->ReceiveFromMaster();
if (packet) { //We can get messages not handle-able by the dServer class, so handle them if we returned anything. if (packet) { //We can get messages not handle-able by the dServer class, so handle them if we returned anything.
HandlePacket(packet); HandlePacket(packet);
Game::server->DeallocateMasterPacket(packet); Game::server->DeallocateMasterPacket(packet);
} }
@ -459,13 +459,13 @@ int main(int argc, char** argv) {
t += std::chrono::milliseconds(currentFramerate); t += std::chrono::milliseconds(currentFramerate);
std::this_thread::sleep_until(t); std::this_thread::sleep_until(t);
Metrics::EndMeasurement(MetricVariable::Sleep); Metrics::EndMeasurement(MetricVariable::Sleep);
if (!ready && Game::server->GetIsConnectedToMaster()) if (!ready && Game::server->GetIsConnectedToMaster())
{ {
// Some delay is required here or else we crash the client? // Some delay is required here or else we crash the client?
framesSinceMasterStatus++; framesSinceMasterStatus++;
if (framesSinceMasterStatus >= 200) if (framesSinceMasterStatus >= 200)
@ -505,7 +505,7 @@ dLogger * SetupLogger(int zoneID, int instanceID) {
void HandlePacketChat(Packet* packet) { void HandlePacketChat(Packet* packet) {
if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) { if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) {
Game::logger->Log("WorldServer", "Lost our connection to chat, zone(%i), instance(%i)\n", Game::server->GetZoneID(), Game::server->GetInstanceID()); Game::logger->Log("WorldServer", "Lost our connection to chat, zone(%i), instance(%i)\n", Game::server->GetZoneID(), Game::server->GetInstanceID());
chatConnected = false; chatConnected = false;
} }
@ -579,7 +579,7 @@ void HandlePacketChat(Packet* packet) {
inStream.Read(playerId); inStream.Read(playerId);
inStream.Read(playerId); inStream.Read(playerId);
inStream.Read(expire); inStream.Read(expire);
auto* entity = EntityManager::Instance()->GetEntity(playerId); auto* entity = EntityManager::Instance()->GetEntity(playerId);
if (entity != nullptr) if (entity != nullptr)
@ -829,7 +829,7 @@ void HandlePacket(Packet* packet) {
} }
if (packet->data[1] != WORLD) return; if (packet->data[1] != WORLD) return;
switch (packet->data[3]) { switch (packet->data[3]) {
case MSG_WORLD_CLIENT_VALIDATION: { case MSG_WORLD_CLIENT_VALIDATION: {
std::string username = PacketUtils::ReadString(0x08, packet, true); std::string username = PacketUtils::ReadString(0x08, packet, true);
@ -844,7 +844,7 @@ void HandlePacket(Packet* packet) {
uint32_t gmLevel = 0; uint32_t gmLevel = 0;
auto* stmt = Database::CreatePreppedStmt("SELECT gm_level FROM accounts WHERE name=? LIMIT 1;"); auto* stmt = Database::CreatePreppedStmt("SELECT gm_level FROM accounts WHERE name=? LIMIT 1;");
stmt->setString(1, username.c_str()); stmt->setString(1, username.c_str());
auto* res = stmt->executeQuery(); auto* res = stmt->executeQuery();
while (res->next()) { while (res->next()) {
gmLevel = res->getInt(1); gmLevel = res->getInt(1);
@ -860,7 +860,7 @@ void HandlePacket(Packet* packet) {
return; return;
} }
} }
//Request the session info from Master: //Request the session info from Master:
CBITSTREAM; CBITSTREAM;
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_REQUEST_SESSION_KEY); PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_REQUEST_SESSION_KEY);
@ -872,7 +872,7 @@ void HandlePacket(Packet* packet) {
info.sysAddr = SystemAddress(packet->systemAddress); info.sysAddr = SystemAddress(packet->systemAddress);
info.hash = sessionKey; info.hash = sessionKey;
m_PendingUsers.insert(std::make_pair(username, info)); m_PendingUsers.insert(std::make_pair(username, info));
break; break;
} }
@ -885,7 +885,7 @@ void HandlePacket(Packet* packet) {
} }
//This loops prevents users who aren't authenticated to double-request the char list, which //This loops prevents users who aren't authenticated to double-request the char list, which
//would make the login screen freeze sometimes. //would make the login screen freeze sometimes.
if (m_PendingUsers.size() > 0) { if (m_PendingUsers.size() > 0) {
for (auto it : m_PendingUsers) { for (auto it : m_PendingUsers) {
if (it.second.sysAddr == packet->systemAddress) { if (it.second.sysAddr == packet->systemAddress) {
@ -900,18 +900,18 @@ void HandlePacket(Packet* packet) {
case MSG_WORLD_CLIENT_GAME_MSG: { case MSG_WORLD_CLIENT_GAME_MSG: {
RakNet::BitStream bitStream(packet->data, packet->length, false); RakNet::BitStream bitStream(packet->data, packet->length, false);
uint64_t header; uint64_t header;
LWOOBJID objectID; LWOOBJID objectID;
uint16_t messageID; uint16_t messageID;
bitStream.Read(header); bitStream.Read(header);
bitStream.Read(objectID); bitStream.Read(objectID);
bitStream.Read(messageID); bitStream.Read(messageID);
RakNet::BitStream dataStream; RakNet::BitStream dataStream;
bitStream.Read(dataStream, bitStream.GetNumberOfUnreadBits()); bitStream.Read(dataStream, bitStream.GetNumberOfUnreadBits());
GameMessageHandler::HandleMessage(&dataStream, packet->systemAddress, objectID, GAME_MSG(messageID)); GameMessageHandler::HandleMessage(&dataStream, packet->systemAddress, objectID, GAME_MSG(messageID));
break; break;
} }
@ -924,7 +924,7 @@ void HandlePacket(Packet* packet) {
case MSG_WORLD_CLIENT_LOGIN_REQUEST: { case MSG_WORLD_CLIENT_LOGIN_REQUEST: {
RakNet::BitStream inStream(packet->data, packet->length, false); RakNet::BitStream inStream(packet->data, packet->length, false);
uint64_t header = inStream.Read(header); uint64_t header = inStream.Read(header);
LWOOBJID playerID = 0; LWOOBJID playerID = 0;
inStream.Read(playerID); inStream.Read(playerID);
playerID = GeneralUtils::ClearBit(playerID, OBJECT_BIT_CHARACTER); playerID = GeneralUtils::ClearBit(playerID, OBJECT_BIT_CHARACTER);
@ -939,7 +939,7 @@ void HandlePacket(Packet* packet) {
UserManager::Instance()->RequestCharacterList(packet->systemAddress); UserManager::Instance()->RequestCharacterList(packet->systemAddress);
break; break;
} }
case MSG_WORLD_CLIENT_CHARACTER_RENAME_REQUEST: { case MSG_WORLD_CLIENT_CHARACTER_RENAME_REQUEST: {
UserManager::Instance()->RenameCharacter(packet->systemAddress, packet); UserManager::Instance()->RenameCharacter(packet->systemAddress, packet);
break; break;
@ -950,10 +950,10 @@ void HandlePacket(Packet* packet) {
User* user = UserManager::Instance()->GetUser(packet->systemAddress); User* user = UserManager::Instance()->GetUser(packet->systemAddress);
if (user) { if (user) {
Character* c = user->GetLastUsedChar(); Character* c = user->GetLastUsedChar();
if (c != nullptr) { if (c != nullptr) {
std::u16string username = GeneralUtils::ASCIIToUTF16(c->GetName()); std::u16string username = GeneralUtils::ASCIIToUTF16(c->GetName());
Game::server->GetReplicaManager()->AddParticipant(packet->systemAddress); Game::server->GetReplicaManager()->AddParticipant(packet->systemAddress);
EntityInfo info {}; EntityInfo info {};
info.lot = 1; info.lot = 1;
Entity* player = EntityManager::Instance()->CreateEntity(info, UserManager::Instance()->GetUser(packet->systemAddress)); Entity* player = EntityManager::Instance()->CreateEntity(info, UserManager::Instance()->GetUser(packet->systemAddress));
@ -962,20 +962,20 @@ void HandlePacket(Packet* packet) {
WorldPackets::SendServerState(packet->systemAddress); WorldPackets::SendServerState(packet->systemAddress);
const auto respawnPoint = player->GetCharacter()->GetRespawnPoint(dZoneManager::Instance()->GetZone()->GetWorldID()); const auto respawnPoint = player->GetCharacter()->GetRespawnPoint(dZoneManager::Instance()->GetZone()->GetWorldID());
EntityManager::Instance()->ConstructEntity(player, UNASSIGNED_SYSTEM_ADDRESS, true); EntityManager::Instance()->ConstructEntity(player, UNASSIGNED_SYSTEM_ADDRESS, true);
if (respawnPoint != NiPoint3::ZERO) if (respawnPoint != NiPoint3::ZERO)
{ {
GameMessages::SendPlayerReachedRespawnCheckpoint(player, respawnPoint, NiQuaternion::IDENTITY); GameMessages::SendPlayerReachedRespawnCheckpoint(player, respawnPoint, NiQuaternion::IDENTITY);
} }
EntityManager::Instance()->ConstructAllEntities(packet->systemAddress); EntityManager::Instance()->ConstructAllEntities(packet->systemAddress);
player->GetComponent<CharacterComponent>()->SetLastRocketConfig(u""); player->GetComponent<CharacterComponent>()->SetLastRocketConfig(u"");
c->SetRetroactiveFlags(); c->SetRetroactiveFlags();
player->RetroactiveVaultSize(); player->RetroactiveVaultSize();
player->GetCharacter()->SetTargetScene(""); player->GetCharacter()->SetTargetScene("");
@ -1012,7 +1012,7 @@ void HandlePacket(Packet* packet) {
int templateId = result.getIntField(0); int templateId = result.getIntField(0);
result.finalize(); result.finalize();
auto* propertyLookup = Database::CreatePreppedStmt("SELECT * FROM properties WHERE template_id = ? AND clone_id = ?;"); auto* propertyLookup = Database::CreatePreppedStmt("SELECT * FROM properties WHERE template_id = ? AND clone_id = ?;");
propertyLookup->setInt(1, templateId); propertyLookup->setInt(1, templateId);
@ -1037,7 +1037,7 @@ void HandlePacket(Packet* packet) {
stmtL->setUInt(1, res->getUInt(1)); stmtL->setUInt(1, res->getUInt(1));
auto lxres = stmtL->executeQuery(); auto lxres = stmtL->executeQuery();
while (lxres->next()) { while (lxres->next()) {
auto lxfml = lxres->getBlob(1); auto lxfml = lxres->getBlob(1);
@ -1089,7 +1089,7 @@ void HandlePacket(Packet* packet) {
noBBB: noBBB:
// Tell the client it's done loading: // Tell the client it's done loading:
GameMessages::SendInvalidZoneTransferList(player, packet->systemAddress, u"https://github.com/DarkflameUniverse/DarkflameServer", u"", false, false); GameMessages::SendInvalidZoneTransferList(player, packet->systemAddress, GeneralUtils::ASCIIToUTF16(Game::config->GetValue("source")), u"", false, false);
GameMessages::SendServerDoneLoadingAllObjects(player, packet->systemAddress); GameMessages::SendServerDoneLoadingAllObjects(player, packet->systemAddress);
//Send the player it's mail count: //Send the player it's mail count:
@ -1109,9 +1109,9 @@ void HandlePacket(Packet* packet) {
{ {
bitStream.Write(playerName[i]); bitStream.Write(playerName[i]);
} }
//bitStream.Write(playerName); //bitStream.Write(playerName);
auto zone = dZoneManager::Instance()->GetZone()->GetZoneID(); auto zone = dZoneManager::Instance()->GetZone()->GetZoneID();
bitStream.Write(zone.GetMapID()); bitStream.Write(zone.GetMapID());
bitStream.Write(zone.GetInstanceID()); bitStream.Write(zone.GetInstanceID());