mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-12-16 20:24:39 -06:00
Compare commits
45 Commits
aggregate-
...
spooder-fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d45e7bbda9 | ||
|
|
23d71340c9 | ||
|
|
5942182486 | ||
|
|
131239538b | ||
|
|
4c507e34a5 | ||
|
|
50921cce2d | ||
|
|
3806891db0 | ||
|
|
ba91058736 | ||
|
|
73e70badb7 | ||
|
|
e4cae35edb | ||
|
|
2746683235 | ||
|
|
c6087ce77a | ||
|
|
e96fd56fbd | ||
|
|
500ae4d6e5 | ||
|
|
094797881b | ||
|
|
3dd2791066 | ||
| 570c597148 | |||
|
|
ad003634f4 | ||
| d8ac148cee | |||
|
|
471d65707c | ||
|
|
94f8a99fba | ||
|
|
288991ef49 | ||
|
|
74cc4176e1 | ||
| b33e9935f5 | |||
|
|
258ee5c1ee | ||
|
|
a8820c14f2 | ||
| 1ec8da8bf7 | |||
|
|
b24775f472 | ||
|
|
bd65fc6e33 | ||
|
|
44f466ac72 | ||
|
|
51540568fb | ||
| 08020cd86d | |||
| ca78a166d9 | |||
| 2e386d29df | |||
| d893ecddeb | |||
|
|
f4f13e081a | ||
|
|
c26086aff5 | ||
|
|
0337449aa7 | ||
|
|
598f4e1663 | ||
|
|
5eca25e42a | ||
|
|
d233c7e2aa | ||
| beaceb947b | |||
|
|
2cc13c6499 | ||
|
|
ad81e341da | ||
|
|
fe6be21008 |
@@ -1,5 +1,5 @@
|
||||
PROJECT_VERSION_MAJOR=1
|
||||
PROJECT_VERSION_MINOR=0
|
||||
PROJECT_VERSION_MINOR=1
|
||||
PROJECT_VERSION_PATCH=1
|
||||
# LICENSE
|
||||
LICENSE=AGPL-3.0
|
||||
@@ -18,3 +18,5 @@ __maria_db_connector_compile_jobs__=1
|
||||
__enable_testing__=1
|
||||
# The path to OpenSSL. Change this if your OpenSSL install path is different than the default.
|
||||
OPENSSL_ROOT_DIR=/usr/local/opt/openssl@3/
|
||||
# Uncomment the below line to cache the entire CDClient into memory
|
||||
# CDCLIENT_CACHE_ALL=1
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
//DLU Includes:
|
||||
#include "dCommonVars.h"
|
||||
#include "dServer.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
#include "Database.h"
|
||||
#include "dConfig.h"
|
||||
#include "Diagnostics.h"
|
||||
@@ -25,14 +25,14 @@
|
||||
|
||||
#include "Game.h"
|
||||
namespace Game {
|
||||
dLogger* logger = nullptr;
|
||||
Logger* logger = nullptr;
|
||||
dServer* server = nullptr;
|
||||
dConfig* config = nullptr;
|
||||
bool shouldShutdown = false;
|
||||
std::mt19937 randomEngine;
|
||||
}
|
||||
|
||||
dLogger* SetupLogger();
|
||||
Logger* SetupLogger();
|
||||
void HandlePacket(Packet* packet);
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
@@ -51,9 +51,9 @@ int main(int argc, char** argv) {
|
||||
Game::logger->SetLogToConsole(Game::config->GetValue("log_to_console") != "0");
|
||||
Game::logger->SetLogDebugStatements(Game::config->GetValue("log_debug_statements") == "1");
|
||||
|
||||
Game::logger->Log("AuthServer", "Starting Auth server...");
|
||||
Game::logger->Log("AuthServer", "Version: %i.%i", PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR);
|
||||
Game::logger->Log("AuthServer", "Compiled on: %s", __TIMESTAMP__);
|
||||
LOG("Starting Auth server...");
|
||||
LOG("Version: %i.%i", PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR);
|
||||
LOG("Compiled on: %s", __TIMESTAMP__);
|
||||
|
||||
//Connect to the MySQL Database
|
||||
std::string mysql_host = Game::config->GetValue("mysql_host");
|
||||
@@ -64,7 +64,7 @@ int main(int argc, char** argv) {
|
||||
try {
|
||||
Database::Connect(mysql_host, mysql_database, mysql_username, mysql_password);
|
||||
} catch (sql::SQLException& ex) {
|
||||
Game::logger->Log("AuthServer", "Got an error while connecting to the database: %s", ex.what());
|
||||
LOG("Got an error while connecting to the database: %s", ex.what());
|
||||
Database::Destroy("AuthServer");
|
||||
delete Game::server;
|
||||
delete Game::logger;
|
||||
@@ -161,7 +161,7 @@ int main(int argc, char** argv) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
dLogger* SetupLogger() {
|
||||
Logger* SetupLogger() {
|
||||
std::string logPath = (BinaryPathFinder::GetBinaryDir() / ("logs/AuthServer_" + std::to_string(time(nullptr)) + ".log")).string();
|
||||
bool logToConsole = false;
|
||||
bool logDebugStatements = false;
|
||||
@@ -170,7 +170,7 @@ dLogger* SetupLogger() {
|
||||
logDebugStatements = true;
|
||||
#endif
|
||||
|
||||
return new dLogger(logPath, logToConsole, logDebugStatements);
|
||||
return new Logger(logPath, logToConsole, logDebugStatements);
|
||||
}
|
||||
|
||||
void HandlePacket(Packet* packet) {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <regex>
|
||||
|
||||
#include "dCommonVars.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
#include "dConfig.h"
|
||||
#include "Database.h"
|
||||
#include "Game.h"
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
#include "Database.h"
|
||||
#include <vector>
|
||||
#include "PacketUtils.h"
|
||||
#include "BitStreamUtils.h"
|
||||
#include "Game.h"
|
||||
#include "dServer.h"
|
||||
#include "GeneralUtils.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
#include "eAddFriendResponseCode.h"
|
||||
#include "eAddFriendResponseType.h"
|
||||
#include "RakString.h"
|
||||
@@ -75,11 +76,11 @@ void ChatPacketHandler::HandleFriendlistRequest(Packet* packet) {
|
||||
|
||||
//Now, we need to send the friendlist to the server they came from:
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::GET_FRIENDS_LIST_RESPONSE);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::GET_FRIENDS_LIST_RESPONSE);
|
||||
bitStream.Write<uint8_t>(0);
|
||||
bitStream.Write<uint16_t>(1); //Length of packet -- just writing one as it doesn't matter, client skips it.
|
||||
bitStream.Write((uint16_t)friends.size());
|
||||
@@ -396,7 +397,7 @@ void ChatPacketHandler::HandleChatMessage(Packet* packet) {
|
||||
|
||||
std::string message = PacketUtils::ReadString(0x66, packet, true, 512);
|
||||
|
||||
Game::logger->Log("ChatPacketHandler", "Got a message from (%s) [%d]: %s", senderName.c_str(), channel, message.c_str());
|
||||
LOG("Got a message from (%s) [%d]: %s", senderName.c_str(), channel, message.c_str());
|
||||
|
||||
if (channel != 8) return;
|
||||
|
||||
@@ -412,21 +413,21 @@ void ChatPacketHandler::HandleChatMessage(Packet* packet) {
|
||||
const auto otherName = std::string(otherMember->playerName.c_str());
|
||||
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(otherMember->playerID);
|
||||
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::PRIVATE_CHAT_MESSAGE);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::PRIVATE_CHAT_MESSAGE);
|
||||
bitStream.Write(otherMember->playerID);
|
||||
bitStream.Write<uint8_t>(8);
|
||||
bitStream.Write<unsigned int>(69);
|
||||
PacketUtils::WritePacketWString(senderName, 33, &bitStream);
|
||||
bitStream.Write(LUWString(senderName));
|
||||
bitStream.Write(sender->playerID);
|
||||
bitStream.Write<uint16_t>(0);
|
||||
bitStream.Write<uint8_t>(0); //not mythran nametag
|
||||
PacketUtils::WritePacketWString(otherName, 33, &bitStream);
|
||||
bitStream.Write(LUWString(otherName));
|
||||
bitStream.Write<uint8_t>(0); //not mythran for receiver
|
||||
bitStream.Write<uint8_t>(0); //teams?
|
||||
PacketUtils::WritePacketWString(message, 512, &bitStream);
|
||||
bitStream.Write(LUWString(message, 512));
|
||||
|
||||
SystemAddress sysAddr = otherMember->sysAddr;
|
||||
SEND_PACKET;
|
||||
@@ -434,7 +435,7 @@ void ChatPacketHandler::HandleChatMessage(Packet* packet) {
|
||||
}
|
||||
|
||||
void ChatPacketHandler::HandlePrivateChatMessage(Packet* packet) {
|
||||
LWOOBJID senderID = PacketUtils::ReadPacketS64(0x08, packet);
|
||||
LWOOBJID senderID = PacketUtils::ReadS64(0x08, packet);
|
||||
std::string receiverName = PacketUtils::ReadString(0x66, packet, true);
|
||||
std::string message = PacketUtils::ReadString(0xAA, packet, true, 512);
|
||||
|
||||
@@ -451,21 +452,21 @@ void ChatPacketHandler::HandlePrivateChatMessage(Packet* packet) {
|
||||
//To the sender:
|
||||
{
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(goonA->playerID);
|
||||
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::PRIVATE_CHAT_MESSAGE);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::PRIVATE_CHAT_MESSAGE);
|
||||
bitStream.Write(goonA->playerID);
|
||||
bitStream.Write<uint8_t>(7);
|
||||
bitStream.Write<unsigned int>(69);
|
||||
PacketUtils::WritePacketWString(goonAName, 33, &bitStream);
|
||||
bitStream.Write(LUWString(goonAName));
|
||||
bitStream.Write(goonA->playerID);
|
||||
bitStream.Write<uint16_t>(0);
|
||||
bitStream.Write<uint8_t>(0); //not mythran nametag
|
||||
PacketUtils::WritePacketWString(goonBName, 33, &bitStream);
|
||||
bitStream.Write(LUWString(goonBName));
|
||||
bitStream.Write<uint8_t>(0); //not mythran for receiver
|
||||
bitStream.Write<uint8_t>(0); //success
|
||||
PacketUtils::WritePacketWString(message, 512, &bitStream);
|
||||
bitStream.Write(LUWString(message, 512));
|
||||
|
||||
SystemAddress sysAddr = goonA->sysAddr;
|
||||
SEND_PACKET;
|
||||
@@ -474,21 +475,21 @@ void ChatPacketHandler::HandlePrivateChatMessage(Packet* packet) {
|
||||
//To the receiver:
|
||||
{
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(goonB->playerID);
|
||||
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::PRIVATE_CHAT_MESSAGE);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::PRIVATE_CHAT_MESSAGE);
|
||||
bitStream.Write(goonA->playerID);
|
||||
bitStream.Write<uint8_t>(7);
|
||||
bitStream.Write<unsigned int>(69);
|
||||
PacketUtils::WritePacketWString(goonAName, 33, &bitStream);
|
||||
bitStream.Write(LUWString(goonAName));
|
||||
bitStream.Write(goonA->playerID);
|
||||
bitStream.Write<uint16_t>(0);
|
||||
bitStream.Write<uint8_t>(0); //not mythran nametag
|
||||
PacketUtils::WritePacketWString(goonBName, 33, &bitStream);
|
||||
bitStream.Write(LUWString(goonBName));
|
||||
bitStream.Write<uint8_t>(0); //not mythran for receiver
|
||||
bitStream.Write<uint8_t>(3); //new whisper
|
||||
PacketUtils::WritePacketWString(message, 512, &bitStream);
|
||||
bitStream.Write(LUWString(message, 512));
|
||||
|
||||
SystemAddress sysAddr = goonB->sysAddr;
|
||||
SEND_PACKET;
|
||||
@@ -526,13 +527,13 @@ void ChatPacketHandler::HandleTeamInvite(Packet* packet) {
|
||||
if (team->memberIDs.size() > 3) {
|
||||
// no more teams greater than 4
|
||||
|
||||
Game::logger->Log("ChatPacketHandler", "Someone tried to invite a 5th player to a team");
|
||||
LOG("Someone tried to invite a 5th player to a team");
|
||||
return;
|
||||
}
|
||||
|
||||
SendTeamInvite(other, player);
|
||||
|
||||
Game::logger->Log("ChatPacketHandler", "Got team invite: %llu -> %s", playerID, invitedPlayer.c_str());
|
||||
LOG("Got team invite: %llu -> %s", playerID, invitedPlayer.c_str());
|
||||
}
|
||||
|
||||
void ChatPacketHandler::HandleTeamInviteResponse(Packet* packet) {
|
||||
@@ -546,7 +547,7 @@ void ChatPacketHandler::HandleTeamInviteResponse(Packet* packet) {
|
||||
LWOOBJID leaderID = LWOOBJID_EMPTY;
|
||||
inStream.Read(leaderID);
|
||||
|
||||
Game::logger->Log("ChatPacketHandler", "Accepted invite: %llu -> %llu (%d)", playerID, leaderID, declined);
|
||||
LOG("Accepted invite: %llu -> %llu (%d)", playerID, leaderID, declined);
|
||||
|
||||
if (declined) {
|
||||
return;
|
||||
@@ -555,13 +556,13 @@ void ChatPacketHandler::HandleTeamInviteResponse(Packet* packet) {
|
||||
auto* team = playerContainer.GetTeam(leaderID);
|
||||
|
||||
if (team == nullptr) {
|
||||
Game::logger->Log("ChatPacketHandler", "Failed to find team for leader (%llu)", leaderID);
|
||||
LOG("Failed to find team for leader (%llu)", leaderID);
|
||||
|
||||
team = playerContainer.GetTeam(playerID);
|
||||
}
|
||||
|
||||
if (team == nullptr) {
|
||||
Game::logger->Log("ChatPacketHandler", "Failed to find team for player (%llu)", playerID);
|
||||
LOG("Failed to find team for player (%llu)", playerID);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -577,7 +578,7 @@ void ChatPacketHandler::HandleTeamLeave(Packet* packet) {
|
||||
|
||||
auto* team = playerContainer.GetTeam(playerID);
|
||||
|
||||
Game::logger->Log("ChatPacketHandler", "(%llu) leaving team", playerID);
|
||||
LOG("(%llu) leaving team", playerID);
|
||||
|
||||
if (team != nullptr) {
|
||||
playerContainer.RemoveMember(team, playerID, false, false, true);
|
||||
@@ -591,7 +592,7 @@ void ChatPacketHandler::HandleTeamKick(Packet* packet) {
|
||||
|
||||
std::string kickedPlayer = PacketUtils::ReadString(0x14, packet, true);
|
||||
|
||||
Game::logger->Log("ChatPacketHandler", "(%llu) kicking (%s) from team", playerID, kickedPlayer.c_str());
|
||||
LOG("(%llu) kicking (%s) from team", playerID, kickedPlayer.c_str());
|
||||
|
||||
auto* kicked = playerContainer.GetPlayerData(kickedPlayer);
|
||||
|
||||
@@ -621,7 +622,7 @@ void ChatPacketHandler::HandleTeamPromote(Packet* packet) {
|
||||
|
||||
std::string promotedPlayer = PacketUtils::ReadString(0x14, packet, true);
|
||||
|
||||
Game::logger->Log("ChatPacketHandler", "(%llu) promoting (%s) to team leader", playerID, promotedPlayer.c_str());
|
||||
LOG("(%llu) promoting (%s) to team leader", playerID, promotedPlayer.c_str());
|
||||
|
||||
auto* promoted = playerContainer.GetPlayerData(promotedPlayer);
|
||||
|
||||
@@ -709,13 +710,13 @@ void ChatPacketHandler::HandleTeamStatusRequest(Packet* packet) {
|
||||
|
||||
void ChatPacketHandler::SendTeamInvite(PlayerData* receiver, PlayerData* sender) {
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(receiver->playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::TEAM_INVITE);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::TEAM_INVITE);
|
||||
|
||||
PacketUtils::WritePacketWString(sender->playerName.c_str(), 33, &bitStream);
|
||||
bitStream.Write(LUWString(sender->playerName.c_str()));
|
||||
bitStream.Write(sender->playerID);
|
||||
|
||||
SystemAddress sysAddr = receiver->sysAddr;
|
||||
@@ -724,7 +725,7 @@ void ChatPacketHandler::SendTeamInvite(PlayerData* receiver, PlayerData* sender)
|
||||
|
||||
void ChatPacketHandler::SendTeamInviteConfirm(PlayerData* receiver, bool bLeaderIsFreeTrial, LWOOBJID i64LeaderID, LWOZONEID i64LeaderZoneID, uint8_t ucLootFlag, uint8_t ucNumOfOtherPlayers, uint8_t ucResponseCode, std::u16string wsLeaderName) {
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(receiver->playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
@@ -751,7 +752,7 @@ void ChatPacketHandler::SendTeamInviteConfirm(PlayerData* receiver, bool bLeader
|
||||
|
||||
void ChatPacketHandler::SendTeamStatus(PlayerData* receiver, LWOOBJID i64LeaderID, LWOZONEID i64LeaderZoneID, uint8_t ucLootFlag, uint8_t ucNumOfOtherPlayers, std::u16string wsLeaderName) {
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(receiver->playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
@@ -776,7 +777,7 @@ void ChatPacketHandler::SendTeamStatus(PlayerData* receiver, LWOOBJID i64LeaderI
|
||||
|
||||
void ChatPacketHandler::SendTeamSetLeader(PlayerData* receiver, LWOOBJID i64PlayerID) {
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(receiver->playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
@@ -793,7 +794,7 @@ void ChatPacketHandler::SendTeamSetLeader(PlayerData* receiver, LWOOBJID i64Play
|
||||
|
||||
void ChatPacketHandler::SendTeamAddPlayer(PlayerData* receiver, bool bIsFreeTrial, bool bLocal, bool bNoLootOnDeath, LWOOBJID i64PlayerID, std::u16string wsPlayerName, LWOZONEID zoneID) {
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(receiver->playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
@@ -822,7 +823,7 @@ void ChatPacketHandler::SendTeamAddPlayer(PlayerData* receiver, bool bIsFreeTria
|
||||
|
||||
void ChatPacketHandler::SendTeamRemovePlayer(PlayerData* receiver, bool bDisband, bool bIsKicked, bool bIsLeaving, bool bLocal, LWOOBJID i64LeaderID, LWOOBJID i64PlayerID, std::u16string wsPlayerName) {
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(receiver->playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
@@ -848,7 +849,7 @@ void ChatPacketHandler::SendTeamRemovePlayer(PlayerData* receiver, bool bDisband
|
||||
|
||||
void ChatPacketHandler::SendTeamSetOffWorldFlag(PlayerData* receiver, LWOOBJID i64PlayerID, LWOZONEID zoneID) {
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(receiver->playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
@@ -882,16 +883,16 @@ void ChatPacketHandler::SendFriendUpdate(PlayerData* friendData, PlayerData* pla
|
||||
[bool] - is FTP*/
|
||||
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(friendData->playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::UPDATE_FRIEND_NOTIFY);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::UPDATE_FRIEND_NOTIFY);
|
||||
bitStream.Write<uint8_t>(notifyType);
|
||||
|
||||
std::string playerName = playerData->playerName.c_str();
|
||||
|
||||
PacketUtils::WritePacketWString(playerName, 33, &bitStream);
|
||||
bitStream.Write(LUWString(playerName));
|
||||
|
||||
bitStream.Write(playerData->zoneID.GetMapID());
|
||||
bitStream.Write(playerData->zoneID.GetInstanceID());
|
||||
@@ -921,12 +922,12 @@ void ChatPacketHandler::SendFriendRequest(PlayerData* receiver, PlayerData* send
|
||||
}
|
||||
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(receiver->playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::ADD_FRIEND_REQUEST);
|
||||
PacketUtils::WritePacketWString(sender->playerName.c_str(), 33, &bitStream);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::ADD_FRIEND_REQUEST);
|
||||
bitStream.Write(LUWString(sender->playerName.c_str()));
|
||||
bitStream.Write<uint8_t>(0); // This is a BFF flag however this is unused in live and does not have an implementation client side.
|
||||
|
||||
SystemAddress sysAddr = receiver->sysAddr;
|
||||
@@ -937,16 +938,16 @@ void ChatPacketHandler::SendFriendResponse(PlayerData* receiver, PlayerData* sen
|
||||
if (!receiver || !sender) return;
|
||||
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(receiver->playerID);
|
||||
|
||||
// Portion that will get routed:
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::ADD_FRIEND_RESPONSE);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::ADD_FRIEND_RESPONSE);
|
||||
bitStream.Write(responseCode);
|
||||
// For all requests besides accepted, write a flag that says whether or not we are already best friends with the receiver.
|
||||
bitStream.Write<uint8_t>(responseCode != eAddFriendResponseType::ACCEPTED ? isBestFriendsAlready : sender->sysAddr != UNASSIGNED_SYSTEM_ADDRESS);
|
||||
// Then write the player name
|
||||
PacketUtils::WritePacketWString(sender->playerName.c_str(), 33, &bitStream);
|
||||
bitStream.Write(LUWString(sender->playerName.c_str()));
|
||||
// Then if this is an acceptance code, write the following extra info.
|
||||
if (responseCode == eAddFriendResponseType::ACCEPTED) {
|
||||
bitStream.Write(sender->playerID);
|
||||
@@ -962,13 +963,13 @@ void ChatPacketHandler::SendRemoveFriend(PlayerData* receiver, std::string& pers
|
||||
if (!receiver) return;
|
||||
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(receiver->playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::REMOVE_FRIEND_RESPONSE);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::REMOVE_FRIEND_RESPONSE);
|
||||
bitStream.Write<uint8_t>(isSuccessful); //isOnline
|
||||
PacketUtils::WritePacketWString(personToRemove, 33, &bitStream);
|
||||
bitStream.Write(LUWString(personToRemove));
|
||||
|
||||
SystemAddress sysAddr = receiver->sysAddr;
|
||||
SEND_PACKET;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
//DLU Includes:
|
||||
#include "dCommonVars.h"
|
||||
#include "dServer.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
#include "Database.h"
|
||||
#include "dConfig.h"
|
||||
#include "dChatFilter.h"
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <MessageIdentifiers.h>
|
||||
|
||||
namespace Game {
|
||||
dLogger* logger = nullptr;
|
||||
Logger* logger = nullptr;
|
||||
dServer* server = nullptr;
|
||||
dConfig* config = nullptr;
|
||||
dChatFilter* chatFilter = nullptr;
|
||||
@@ -37,7 +37,7 @@ namespace Game {
|
||||
}
|
||||
|
||||
|
||||
dLogger* SetupLogger();
|
||||
Logger* SetupLogger();
|
||||
void HandlePacket(Packet* packet);
|
||||
|
||||
PlayerContainer playerContainer;
|
||||
@@ -58,9 +58,9 @@ int main(int argc, char** argv) {
|
||||
Game::logger->SetLogToConsole(Game::config->GetValue("log_to_console") != "0");
|
||||
Game::logger->SetLogDebugStatements(Game::config->GetValue("log_debug_statements") == "1");
|
||||
|
||||
Game::logger->Log("ChatServer", "Starting Chat server...");
|
||||
Game::logger->Log("ChatServer", "Version: %i.%i", PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR);
|
||||
Game::logger->Log("ChatServer", "Compiled on: %s", __TIMESTAMP__);
|
||||
LOG("Starting Chat server...");
|
||||
LOG("Version: %i.%i", PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR);
|
||||
LOG("Compiled on: %s", __TIMESTAMP__);
|
||||
|
||||
try {
|
||||
std::string clientPathStr = Game::config->GetValue("client_location");
|
||||
@@ -72,7 +72,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
Game::assetManager = new AssetManager(clientPath);
|
||||
} catch (std::runtime_error& ex) {
|
||||
Game::logger->Log("ChatServer", "Got an error while setting up assets: %s", ex.what());
|
||||
LOG("Got an error while setting up assets: %s", ex.what());
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ int main(int argc, char** argv) {
|
||||
try {
|
||||
Database::Connect(mysql_host, mysql_database, mysql_username, mysql_password);
|
||||
} catch (sql::SQLException& ex) {
|
||||
Game::logger->Log("ChatServer", "Got an error while connecting to the database: %s", ex.what());
|
||||
LOG("Got an error while connecting to the database: %s", ex.what());
|
||||
Database::Destroy("ChatServer");
|
||||
delete Game::server;
|
||||
delete Game::logger;
|
||||
@@ -185,7 +185,7 @@ int main(int argc, char** argv) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
dLogger* SetupLogger() {
|
||||
Logger* SetupLogger() {
|
||||
std::string logPath = (BinaryPathFinder::GetBinaryDir() / ("logs/ChatServer_" + std::to_string(time(nullptr)) + ".log")).string();
|
||||
bool logToConsole = false;
|
||||
bool logDebugStatements = false;
|
||||
@@ -194,16 +194,16 @@ dLogger* SetupLogger() {
|
||||
logDebugStatements = true;
|
||||
#endif
|
||||
|
||||
return new dLogger(logPath, logToConsole, logDebugStatements);
|
||||
return new Logger(logPath, logToConsole, logDebugStatements);
|
||||
}
|
||||
|
||||
void HandlePacket(Packet* packet) {
|
||||
if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) {
|
||||
Game::logger->Log("ChatServer", "A server has disconnected, erasing their connected players from the list.");
|
||||
LOG("A server has disconnected, erasing their connected players from the list.");
|
||||
}
|
||||
|
||||
if (packet->data[0] == ID_NEW_INCOMING_CONNECTION) {
|
||||
Game::logger->Log("ChatServer", "A server is connecting, awaiting user list.");
|
||||
LOG("A server is connecting, awaiting user list.");
|
||||
}
|
||||
|
||||
if (packet->length < 4) return; // Nothing left to process. Need 4 bytes to continue.
|
||||
@@ -234,7 +234,7 @@ void HandlePacket(Packet* packet) {
|
||||
}
|
||||
|
||||
default:
|
||||
Game::logger->Log("ChatServer", "Unknown CHAT_INTERNAL id: %i", int(packet->data[3]));
|
||||
LOG("Unknown CHAT_INTERNAL id: %i", int(packet->data[3]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ void HandlePacket(Packet* packet) {
|
||||
break;
|
||||
|
||||
case eChatMessageType::GET_IGNORE_LIST:
|
||||
Game::logger->Log("ChatServer", "Asked for ignore list, but is unimplemented right now.");
|
||||
LOG("Asked for ignore list, but is unimplemented right now.");
|
||||
break;
|
||||
|
||||
case eChatMessageType::TEAM_GET_STATUS:
|
||||
@@ -303,19 +303,19 @@ void HandlePacket(Packet* packet) {
|
||||
break;
|
||||
|
||||
default:
|
||||
Game::logger->Log("ChatServer", "Unknown CHAT id: %i", int(packet->data[3]));
|
||||
LOG("Unknown CHAT id: %i", int(packet->data[3]));
|
||||
}
|
||||
}
|
||||
|
||||
if (static_cast<eConnectionType>(packet->data[1]) == eConnectionType::WORLD) {
|
||||
switch (static_cast<eWorldMessageType>(packet->data[3])) {
|
||||
case eWorldMessageType::ROUTE_PACKET: {
|
||||
Game::logger->Log("ChatServer", "Routing packet from world");
|
||||
LOG("Routing packet from world");
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
Game::logger->Log("ChatServer", "Unknown World id: %i", int(packet->data[3]));
|
||||
LOG("Unknown World id: %i", int(packet->data[3]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,15 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
#include "ChatPacketHandler.h"
|
||||
#include "GeneralUtils.h"
|
||||
#include "PacketUtils.h"
|
||||
#include "BitStreamUtils.h"
|
||||
#include "Database.h"
|
||||
#include "eConnectionType.h"
|
||||
#include "eChatInternalMessageType.h"
|
||||
#include "ChatPackets.h"
|
||||
#include "dConfig.h"
|
||||
|
||||
PlayerContainer::PlayerContainer() {
|
||||
}
|
||||
@@ -18,6 +20,10 @@ PlayerContainer::~PlayerContainer() {
|
||||
mPlayers.clear();
|
||||
}
|
||||
|
||||
TeamData::TeamData() {
|
||||
lootFlag = Game::config->GetValue("default_team_loot") == "0" ? 0 : 1;
|
||||
}
|
||||
|
||||
void PlayerContainer::InsertPlayer(Packet* packet) {
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
PlayerData* data = new PlayerData();
|
||||
@@ -38,7 +44,7 @@ void PlayerContainer::InsertPlayer(Packet* packet) {
|
||||
mNames[data->playerID] = GeneralUtils::UTF8ToUTF16(data->playerName);
|
||||
|
||||
mPlayers.insert(std::make_pair(data->playerID, data));
|
||||
Game::logger->Log("PlayerContainer", "Added user: %s (%llu), zone: %i", data->playerName.c_str(), data->playerID, data->zoneID.GetMapID());
|
||||
LOG("Added user: %s (%llu), zone: %i", data->playerName.c_str(), data->playerID, data->zoneID.GetMapID());
|
||||
|
||||
auto* insertLog = Database::CreatePreppedStmt("INSERT INTO activity_log (character_id, activity, time, map_id) VALUES (?, ?, ?, ?);");
|
||||
|
||||
@@ -81,7 +87,7 @@ void PlayerContainer::RemovePlayer(Packet* packet) {
|
||||
}
|
||||
}
|
||||
|
||||
Game::logger->Log("PlayerContainer", "Removed user: %llu", playerID);
|
||||
LOG("Removed user: %llu", playerID);
|
||||
mPlayers.erase(playerID);
|
||||
|
||||
auto* insertLog = Database::CreatePreppedStmt("INSERT INTO activity_log (character_id, activity, time, map_id) VALUES (?, ?, ?, ?);");
|
||||
@@ -104,7 +110,7 @@ void PlayerContainer::MuteUpdate(Packet* packet) {
|
||||
auto* player = this->GetPlayerData(playerID);
|
||||
|
||||
if (player == nullptr) {
|
||||
Game::logger->Log("PlayerContainer", "Failed to find user: %llu", playerID);
|
||||
LOG("Failed to find user: %llu", playerID);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -146,7 +152,7 @@ void PlayerContainer::CreateTeamServer(Packet* packet) {
|
||||
|
||||
void PlayerContainer::BroadcastMuteUpdate(LWOOBJID player, time_t time) {
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::MUTE_UPDATE);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::MUTE_UPDATE);
|
||||
|
||||
bitStream.Write(player);
|
||||
bitStream.Write(time);
|
||||
@@ -207,6 +213,14 @@ TeamData* PlayerContainer::GetTeam(LWOOBJID playerID) {
|
||||
}
|
||||
|
||||
void PlayerContainer::AddMember(TeamData* team, LWOOBJID playerID) {
|
||||
if (team->memberIDs.size() >= 4){
|
||||
LOG("Tried to add player to team that already had 4 players");
|
||||
auto* player = GetPlayerData(playerID);
|
||||
if (!player) return;
|
||||
ChatPackets::SendSystemMessage(player->sysAddr, u"The teams is full! You have not been added to a team!");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto index = std::find(team->memberIDs.begin(), team->memberIDs.end(), playerID);
|
||||
|
||||
if (index != team->memberIDs.end()) return;
|
||||
@@ -345,7 +359,7 @@ void PlayerContainer::TeamStatusUpdate(TeamData* team) {
|
||||
|
||||
void PlayerContainer::UpdateTeamsOnWorld(TeamData* team, bool deleteTeam) {
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::TEAM_UPDATE);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::TEAM_UPDATE);
|
||||
|
||||
bitStream.Write(team->teamID);
|
||||
bitStream.Write(deleteTeam);
|
||||
|
||||
@@ -18,6 +18,7 @@ struct PlayerData {
|
||||
};
|
||||
|
||||
struct TeamData {
|
||||
TeamData();
|
||||
LWOOBJID teamID = LWOOBJID_EMPTY; // Internal use
|
||||
LWOOBJID leaderID = LWOOBJID_EMPTY;
|
||||
std::vector<LWOOBJID> memberIDs{};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define __AMF3__H__
|
||||
|
||||
#include "dCommonVars.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
#include "Game.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "AmfSerialize.h"
|
||||
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
|
||||
// Writes an AMFValue pointer to a RakNet::BitStream
|
||||
template<>
|
||||
@@ -29,7 +29,7 @@ void RakNet::BitStream::Write<AMFBaseValue&>(AMFBaseValue& value) {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
Game::logger->Log("AmfSerialize", "Encountered unwritable AMFType %i!", type);
|
||||
LOG("Encountered unwritable AMFType %i!", type);
|
||||
}
|
||||
case eAmf::Undefined:
|
||||
case eAmf::Null:
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "Database.h"
|
||||
#include "Game.h"
|
||||
#include "ZCompression.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
|
||||
//! Forward declarations
|
||||
|
||||
@@ -59,14 +59,14 @@ uint32_t BrickByBrickFix::TruncateBrokenBrickByBrickXml() {
|
||||
completeUncompressedModel.append((char*)uncompressedChunk.get());
|
||||
completeUncompressedModel.resize(previousSize + actualUncompressedSize);
|
||||
} else {
|
||||
Game::logger->Log("BrickByBrickFix", "Failed to inflate chunk %i for model %llu. Error: %i", chunkCount, modelId, err);
|
||||
LOG("Failed to inflate chunk %i for model %llu. Error: %i", chunkCount, modelId, err);
|
||||
break;
|
||||
}
|
||||
chunkCount++;
|
||||
}
|
||||
std::unique_ptr<tinyxml2::XMLDocument> document = std::make_unique<tinyxml2::XMLDocument>();
|
||||
if (!document) {
|
||||
Game::logger->Log("BrickByBrickFix", "Failed to initialize tinyxml document. Aborting.");
|
||||
LOG("Failed to initialize tinyxml document. Aborting.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -75,8 +75,7 @@ uint32_t BrickByBrickFix::TruncateBrokenBrickByBrickXml() {
|
||||
"</LXFML>",
|
||||
completeUncompressedModel.length() >= 15 ? completeUncompressedModel.length() - 15 : 0) == std::string::npos
|
||||
) {
|
||||
Game::logger->Log("BrickByBrickFix",
|
||||
"Brick-by-brick model %llu will be deleted!", modelId);
|
||||
LOG("Brick-by-brick model %llu will be deleted!", modelId);
|
||||
ugcModelToDelete->setInt64(1, modelsToTruncate->getInt64(1));
|
||||
pcModelToDelete->setInt64(1, modelsToTruncate->getInt64(1));
|
||||
ugcModelToDelete->execute();
|
||||
@@ -85,8 +84,7 @@ uint32_t BrickByBrickFix::TruncateBrokenBrickByBrickXml() {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Game::logger->Log("BrickByBrickFix",
|
||||
"Brick-by-brick model %llu will be deleted!", modelId);
|
||||
LOG("Brick-by-brick model %llu will be deleted!", modelId);
|
||||
ugcModelToDelete->setInt64(1, modelsToTruncate->getInt64(1));
|
||||
pcModelToDelete->setInt64(1, modelsToTruncate->getInt64(1));
|
||||
ugcModelToDelete->execute();
|
||||
@@ -140,12 +138,10 @@ uint32_t BrickByBrickFix::UpdateBrickByBrickModelsToSd0() {
|
||||
insertionStatement->setInt64(2, modelId);
|
||||
try {
|
||||
insertionStatement->executeUpdate();
|
||||
Game::logger->Log("BrickByBrickFix", "Updated model %i to sd0", modelId);
|
||||
LOG("Updated model %i to sd0", modelId);
|
||||
updatedModels++;
|
||||
} catch (sql::SQLException exception) {
|
||||
Game::logger->Log(
|
||||
"BrickByBrickFix",
|
||||
"Failed to update model %i. This model should be inspected manually to see why."
|
||||
LOG("Failed to update model %i. This model should be inspected manually to see why."
|
||||
"The database error is %s", modelId, exception.what());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ set(DCOMMON_SOURCES
|
||||
"BinaryIO.cpp"
|
||||
"dConfig.cpp"
|
||||
"Diagnostics.cpp"
|
||||
"dLogger.cpp"
|
||||
"Logger.cpp"
|
||||
"GeneralUtils.cpp"
|
||||
"LDFFormat.cpp"
|
||||
"MD5.cpp"
|
||||
@@ -12,7 +12,7 @@ set(DCOMMON_SOURCES
|
||||
"NiPoint3.cpp"
|
||||
"NiQuaternion.cpp"
|
||||
"SHA512.cpp"
|
||||
"Type.cpp"
|
||||
"Demangler.cpp"
|
||||
"ZCompression.cpp"
|
||||
"BrickByBrickFix.cpp"
|
||||
"BinaryPathFinder.cpp"
|
||||
|
||||
29
dCommon/Demangler.cpp
Normal file
29
dCommon/Demangler.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "Demangler.h"
|
||||
#ifdef __GNUG__
|
||||
#include <cstdlib>
|
||||
#include <cxxabi.h>
|
||||
#include <memory>
|
||||
#include <typeinfo>
|
||||
|
||||
std::string Demangler::Demangle(const char* name) {
|
||||
// some arbitrary value to eliminate the compiler warning
|
||||
// -4 is not a valid return value for __cxa_demangle so we'll use that.
|
||||
int status = -4;
|
||||
|
||||
// __cxa_demangle requires that we free the returned char*
|
||||
std::unique_ptr<char, void (*)(void*)> res{
|
||||
abi::__cxa_demangle(name, NULL, NULL, &status),
|
||||
std::free
|
||||
};
|
||||
|
||||
return (status == 0) ? res.get() : "";
|
||||
}
|
||||
|
||||
#else // __GNUG__
|
||||
|
||||
// does nothing if not g++
|
||||
std::string Demangler::Demangle(const char* name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
#endif // __GNUG__
|
||||
9
dCommon/Demangler.h
Normal file
9
dCommon/Demangler.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Demangler {
|
||||
// Given a char* containing a mangled name, return a std::string containing the demangled name.
|
||||
// If the function fails for any reason, it returns an empty string.
|
||||
std::string Demangle(const char* name);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "Diagnostics.h"
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
|
||||
// If we're on Win32, we'll include our minidump writer
|
||||
#ifdef _WIN32
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <Dbghelp.h>
|
||||
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
|
||||
void make_minidump(EXCEPTION_POINTERS* e) {
|
||||
auto hDbgHelp = LoadLibraryA("dbghelp");
|
||||
@@ -28,7 +28,7 @@ void make_minidump(EXCEPTION_POINTERS* e) {
|
||||
"_%4d%02d%02d_%02d%02d%02d.dmp",
|
||||
t.wYear, t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond);
|
||||
}
|
||||
Game::logger->Log("Diagnostics", "Creating crash dump %s", name);
|
||||
LOG("Creating crash dump %s", name);
|
||||
auto hFile = CreateFileA(name, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
if (hFile == INVALID_HANDLE_VALUE)
|
||||
return;
|
||||
@@ -83,7 +83,7 @@ struct bt_ctx {
|
||||
|
||||
static inline void Bt(struct backtrace_state* state) {
|
||||
std::string fileName = Diagnostics::GetOutDirectory() + "crash_" + Diagnostics::GetProcessName() + "_" + std::to_string(getpid()) + ".log";
|
||||
Game::logger->Log("Diagnostics", "backtrace is enabled, crash dump located at %s", fileName.c_str());
|
||||
LOG("backtrace is enabled, crash dump located at %s", fileName.c_str());
|
||||
FILE* file = fopen(fileName.c_str(), "w+");
|
||||
if (file != nullptr) {
|
||||
backtrace_print(state, 2, file);
|
||||
@@ -107,7 +107,7 @@ static void ErrorCallback(void* data, const char* msg, int errnum) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "Type.h"
|
||||
#include "Demangler.h"
|
||||
|
||||
void GenerateDump() {
|
||||
std::string cmd = "sudo gcore " + std::to_string(getpid());
|
||||
@@ -118,45 +118,47 @@ void CatchUnhandled(int sig) {
|
||||
#ifndef __include_backtrace__
|
||||
|
||||
std::string fileName = Diagnostics::GetOutDirectory() + "crash_" + Diagnostics::GetProcessName() + "_" + std::to_string(getpid()) + ".log";
|
||||
Game::logger->Log("Diagnostics", "Encountered signal %i, creating crash dump %s", sig, fileName.c_str());
|
||||
LOG("Encountered signal %i, creating crash dump %s", sig, fileName.c_str());
|
||||
if (Diagnostics::GetProduceMemoryDump()) {
|
||||
GenerateDump();
|
||||
}
|
||||
|
||||
void* array[10];
|
||||
constexpr uint8_t MaxStackTrace = 32;
|
||||
void* array[MaxStackTrace];
|
||||
size_t size;
|
||||
|
||||
// get void*'s for all entries on the stack
|
||||
size = backtrace(array, 10);
|
||||
size = backtrace(array, MaxStackTrace);
|
||||
|
||||
#if defined(__GNUG__) and defined(__dynamic)
|
||||
# if defined(__GNUG__)
|
||||
|
||||
// Loop through the returned addresses, and get the symbols to be demangled
|
||||
char** strings = backtrace_symbols(array, size);
|
||||
|
||||
// Print the stack trace
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
// Take a string like './WorldServer(_ZN19SlashCommandHandler17HandleChatCommandERKSbIDsSt11char_traitsIDsESaIDsEEP6EntityRK13SystemAddress+0x6187) [0x55869c44ecf7]' and extract the function name
|
||||
// Take a string like './WorldServer(_ZN19SlashCommandHandler17HandleChatCommandERKSbIDsSt11char_traitsIDsESaIDsEEP6EntityRK13SystemAddress+0x6187) [0x55869c44ecf7]'
|
||||
// and extract '_ZN19SlashCommandHandler17HandleChatCommandERKSbIDsSt11char_traitsIDsESaIDsEEP6EntityRK13SystemAddress' from it to be demangled into a proper name
|
||||
std::string functionName = strings[i];
|
||||
std::string::size_type start = functionName.find('(');
|
||||
std::string::size_type end = functionName.find('+');
|
||||
if (start != std::string::npos && end != std::string::npos) {
|
||||
std::string demangled = functionName.substr(start + 1, end - start - 1);
|
||||
|
||||
demangled = demangle(functionName.c_str());
|
||||
demangled = Demangler::Demangle(demangled.c_str());
|
||||
|
||||
if (demangled.empty()) {
|
||||
Game::logger->Log("Diagnostics", "[%02zu] %s", i, demangled.c_str());
|
||||
} else {
|
||||
Game::logger->Log("Diagnostics", "[%02zu] %s", i, functionName.c_str());
|
||||
// If the demangled string is not empty, then we can replace the mangled string with the demangled one
|
||||
if (!demangled.empty()) {
|
||||
demangled.push_back('(');
|
||||
demangled += functionName.substr(end);
|
||||
functionName = demangled;
|
||||
}
|
||||
} else {
|
||||
Game::logger->Log("Diagnostics", "[%02zu] %s", i, functionName.c_str());
|
||||
}
|
||||
|
||||
LOG("[%02zu] %s", i, functionName.c_str());
|
||||
}
|
||||
#else
|
||||
# else // defined(__GNUG__)
|
||||
backtrace_symbols_fd(array, size, STDOUT_FILENO);
|
||||
#endif
|
||||
# endif // defined(__GNUG__)
|
||||
|
||||
FILE* file = fopen(fileName.c_str(), "w+");
|
||||
if (file != NULL) {
|
||||
@@ -166,7 +168,7 @@ void CatchUnhandled(int sig) {
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
#else
|
||||
#else // __include_backtrace__
|
||||
|
||||
struct backtrace_state* state = backtrace_create_state(
|
||||
Diagnostics::GetProcessFileName().c_str(),
|
||||
@@ -177,7 +179,7 @@ void CatchUnhandled(int sig) {
|
||||
struct bt_ctx ctx = { state, 0 };
|
||||
Bt(state);
|
||||
|
||||
#endif
|
||||
#endif // __include_backtrace__
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "CDClientDatabase.h"
|
||||
#include "GeneralUtils.h"
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
#include "AssetManager.h"
|
||||
|
||||
#include "eSqliteDataType.h"
|
||||
@@ -44,7 +44,7 @@ bool FdbToSqlite::Convert::ConvertDatabase(AssetMemoryBuffer& buffer) {
|
||||
|
||||
CDClientDatabase::ExecuteQuery("COMMIT;");
|
||||
} catch (CppSQLite3Exception& e) {
|
||||
Game::logger->Log("FdbToSqlite", "Encountered error %s converting FDB to SQLite", e.errorMessage());
|
||||
LOG("Encountered error %s converting FDB to SQLite", e.errorMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <random>
|
||||
|
||||
class dServer;
|
||||
class dLogger;
|
||||
class Logger;
|
||||
class InstanceManager;
|
||||
class dChatFilter;
|
||||
class dConfig;
|
||||
@@ -14,7 +14,7 @@ class EntityManager;
|
||||
class dZoneManager;
|
||||
|
||||
namespace Game {
|
||||
extern dLogger* logger;
|
||||
extern Logger* logger;
|
||||
extern dServer* server;
|
||||
extern InstanceManager* im;
|
||||
extern dChatFilter* chatFilter;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "NiPoint3.h"
|
||||
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
|
||||
enum eInventoryType : uint32_t;
|
||||
enum class eObjectBits : size_t;
|
||||
@@ -126,6 +126,11 @@ namespace GeneralUtils {
|
||||
template <typename T>
|
||||
T Parse(const char* value);
|
||||
|
||||
template <>
|
||||
inline bool Parse(const char* value) {
|
||||
return std::stoi(value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline int32_t Parse(const char* value) {
|
||||
return std::stoi(value);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "GeneralUtils.h"
|
||||
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
|
||||
// C++
|
||||
#include <string_view>
|
||||
@@ -48,7 +48,7 @@ LDFBaseData* LDFBaseData::DataFromString(const std::string_view& format) {
|
||||
try {
|
||||
type = static_cast<eLDFType>(strtol(ldfTypeAndValue.first.data(), &storage, 10));
|
||||
} catch (std::exception) {
|
||||
Game::logger->Log("LDFFormat", "Attempted to process invalid ldf type (%s) from string (%s)", ldfTypeAndValue.first.data(), format.data());
|
||||
LOG("Attempted to process invalid ldf type (%s) from string (%s)", ldfTypeAndValue.first.data(), format.data());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -61,35 +61,33 @@ LDFBaseData* LDFBaseData::DataFromString(const std::string_view& format) {
|
||||
}
|
||||
|
||||
case LDF_TYPE_S32: {
|
||||
try {
|
||||
int32_t data = static_cast<int32_t>(strtoul(ldfTypeAndValue.second.data(), &storage, 10));
|
||||
returnValue = new LDFData<int32_t>(key, data);
|
||||
} catch (std::exception) {
|
||||
Game::logger->Log("LDFFormat", "Warning: Attempted to process invalid int32 value (%s) from string (%s)", ldfTypeAndValue.second.data(), format.data());
|
||||
int32_t data;
|
||||
if (!GeneralUtils::TryParse(ldfTypeAndValue.second.data(), data)) {
|
||||
LOG("Warning: Attempted to process invalid int32 value (%s) from string (%s)", ldfTypeAndValue.second.data(), format.data());
|
||||
return nullptr;
|
||||
}
|
||||
returnValue = new LDFData<int32_t>(key, data);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case LDF_TYPE_FLOAT: {
|
||||
try {
|
||||
float data = strtof(ldfTypeAndValue.second.data(), &storage);
|
||||
returnValue = new LDFData<float>(key, data);
|
||||
} catch (std::exception) {
|
||||
Game::logger->Log("LDFFormat", "Warning: Attempted to process invalid float value (%s) from string (%s)", ldfTypeAndValue.second.data(), format.data());
|
||||
float data;
|
||||
if (!GeneralUtils::TryParse(ldfTypeAndValue.second.data(), data)) {
|
||||
LOG("Warning: Attempted to process invalid float value (%s) from string (%s)", ldfTypeAndValue.second.data(), format.data());
|
||||
return nullptr;
|
||||
}
|
||||
returnValue = new LDFData<float>(key, data);
|
||||
break;
|
||||
}
|
||||
|
||||
case LDF_TYPE_DOUBLE: {
|
||||
try {
|
||||
double data = strtod(ldfTypeAndValue.second.data(), &storage);
|
||||
returnValue = new LDFData<double>(key, data);
|
||||
} catch (std::exception) {
|
||||
Game::logger->Log("LDFFormat", "Warning: Attempted to process invalid double value (%s) from string (%s)", ldfTypeAndValue.second.data(), format.data());
|
||||
double data;
|
||||
if (!GeneralUtils::TryParse(ldfTypeAndValue.second.data(), data)) {
|
||||
LOG("Warning: Attempted to process invalid double value (%s) from string (%s)", ldfTypeAndValue.second.data(), format.data());
|
||||
return nullptr;
|
||||
}
|
||||
returnValue = new LDFData<double>(key, data);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -102,10 +100,8 @@ LDFBaseData* LDFBaseData::DataFromString(const std::string_view& format) {
|
||||
} else if (ldfTypeAndValue.second == "false") {
|
||||
data = 0;
|
||||
} else {
|
||||
try {
|
||||
data = static_cast<uint32_t>(strtoul(ldfTypeAndValue.second.data(), &storage, 10));
|
||||
} catch (std::exception) {
|
||||
Game::logger->Log("LDFFormat", "Warning: Attempted to process invalid uint32 value (%s) from string (%s)", ldfTypeAndValue.second.data(), format.data());
|
||||
if (!GeneralUtils::TryParse(ldfTypeAndValue.second.data(), data)) {
|
||||
LOG("Warning: Attempted to process invalid uint32 value (%s) from string (%s)", ldfTypeAndValue.second.data(), format.data());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@@ -122,10 +118,8 @@ LDFBaseData* LDFBaseData::DataFromString(const std::string_view& format) {
|
||||
} else if (ldfTypeAndValue.second == "false") {
|
||||
data = false;
|
||||
} else {
|
||||
try {
|
||||
data = static_cast<bool>(strtol(ldfTypeAndValue.second.data(), &storage, 10));
|
||||
} catch (std::exception) {
|
||||
Game::logger->Log("LDFFormat", "Warning: Attempted to process invalid bool value (%s) from string (%s)", ldfTypeAndValue.second.data(), format.data());
|
||||
if (!GeneralUtils::TryParse(ldfTypeAndValue.second.data(), data)) {
|
||||
LOG("Warning: Attempted to process invalid bool value (%s) from string (%s)", ldfTypeAndValue.second.data(), format.data());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@@ -135,24 +129,22 @@ LDFBaseData* LDFBaseData::DataFromString(const std::string_view& format) {
|
||||
}
|
||||
|
||||
case LDF_TYPE_U64: {
|
||||
try {
|
||||
uint64_t data = static_cast<uint64_t>(strtoull(ldfTypeAndValue.second.data(), &storage, 10));
|
||||
returnValue = new LDFData<uint64_t>(key, data);
|
||||
} catch (std::exception) {
|
||||
Game::logger->Log("LDFFormat", "Warning: Attempted to process invalid uint64 value (%s) from string (%s)", ldfTypeAndValue.second.data(), format.data());
|
||||
uint64_t data;
|
||||
if (!GeneralUtils::TryParse(ldfTypeAndValue.second.data(), data)) {
|
||||
LOG("Warning: Attempted to process invalid uint64 value (%s) from string (%s)", ldfTypeAndValue.second.data(), format.data());
|
||||
return nullptr;
|
||||
}
|
||||
returnValue = new LDFData<uint64_t>(key, data);
|
||||
break;
|
||||
}
|
||||
|
||||
case LDF_TYPE_OBJID: {
|
||||
try {
|
||||
LWOOBJID data = static_cast<LWOOBJID>(strtoll(ldfTypeAndValue.second.data(), &storage, 10));
|
||||
returnValue = new LDFData<LWOOBJID>(key, data);
|
||||
} catch (std::exception) {
|
||||
Game::logger->Log("LDFFormat", "Warning: Attempted to process invalid LWOOBJID value (%s) from string (%s)", ldfTypeAndValue.second.data(), format.data());
|
||||
LWOOBJID data;
|
||||
if (!GeneralUtils::TryParse(ldfTypeAndValue.second.data(), data)) {
|
||||
LOG("Warning: Attempted to process invalid LWOOBJID value (%s) from string (%s)", ldfTypeAndValue.second.data(), format.data());
|
||||
return nullptr;
|
||||
}
|
||||
returnValue = new LDFData<LWOOBJID>(key, data);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -163,12 +155,12 @@ LDFBaseData* LDFBaseData::DataFromString(const std::string_view& format) {
|
||||
}
|
||||
|
||||
case LDF_TYPE_UNKNOWN: {
|
||||
Game::logger->Log("LDFFormat", "Warning: Attempted to process invalid unknown value (%s) from string (%s)", ldfTypeAndValue.second.data(), format.data());
|
||||
LOG("Warning: Attempted to process invalid unknown value (%s) from string (%s)", ldfTypeAndValue.second.data(), format.data());
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
Game::logger->Log("LDFFormat", "Warning: Attempted to process invalid LDF type (%d) from string (%s)", type, format.data());
|
||||
LOG("Warning: Attempted to process invalid LDF type (%d) from string (%s)", type, format.data());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
96
dCommon/Logger.cpp
Normal file
96
dCommon/Logger.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
#include "Logger.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <ctime>
|
||||
#include <filesystem>
|
||||
#include <stdarg.h>
|
||||
|
||||
Writer::~Writer() {
|
||||
// Dont try to close stdcout...
|
||||
if (!m_Outfile || m_IsConsoleWriter) return;
|
||||
|
||||
fclose(m_Outfile);
|
||||
m_Outfile = NULL;
|
||||
}
|
||||
|
||||
void Writer::Log(const char* time, const char* message) {
|
||||
if (!m_Outfile) return;
|
||||
|
||||
fputs(time, m_Outfile);
|
||||
fputs(message, m_Outfile);
|
||||
}
|
||||
|
||||
void Writer::Flush() {
|
||||
if (!m_Outfile) return;
|
||||
fflush(m_Outfile);
|
||||
}
|
||||
|
||||
FileWriter::FileWriter(const char* outpath) {
|
||||
m_Outfile = fopen(outpath, "wt");
|
||||
if (!m_Outfile) printf("Couldn't open %s for writing!\n", outpath);
|
||||
m_Outpath = outpath;
|
||||
m_IsConsoleWriter = false;
|
||||
}
|
||||
|
||||
ConsoleWriter::ConsoleWriter(bool enabled) {
|
||||
m_Enabled = enabled;
|
||||
m_Outfile = stdout;
|
||||
m_IsConsoleWriter = true;
|
||||
}
|
||||
|
||||
Logger::Logger(const std::string& outpath, bool logToConsole, bool logDebugStatements) {
|
||||
m_logDebugStatements = logDebugStatements;
|
||||
std::filesystem::path outpathPath(outpath);
|
||||
if (!std::filesystem::exists(outpathPath.parent_path())) std::filesystem::create_directories(outpathPath.parent_path());
|
||||
m_Writers.push_back(std::make_unique<FileWriter>(outpath));
|
||||
m_Writers.push_back(std::make_unique<ConsoleWriter>(logToConsole));
|
||||
}
|
||||
|
||||
void Logger::vLog(const char* format, va_list args) {
|
||||
time_t t = time(NULL);
|
||||
struct tm* time = localtime(&t);
|
||||
char timeStr[70];
|
||||
strftime(timeStr, sizeof(timeStr), "[%d-%m-%y %H:%M:%S ", time);
|
||||
char message[2048];
|
||||
vsnprintf(message, 2048, format, args);
|
||||
for (const auto& writer : m_Writers) {
|
||||
writer->Log(timeStr, message);
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::Log(const char* className, const char* format, ...) {
|
||||
va_list args;
|
||||
std::string log = std::string(className) + "] " + std::string(format) + "\n";
|
||||
va_start(args, format);
|
||||
vLog(log.c_str(), args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void Logger::LogDebug(const char* className, const char* format, ...) {
|
||||
if (!m_logDebugStatements) return;
|
||||
va_list args;
|
||||
std::string log = std::string(className) + "] " + std::string(format) + "\n";
|
||||
va_start(args, format);
|
||||
vLog(log.c_str(), args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void Logger::Flush() {
|
||||
for (const auto& writer : m_Writers) {
|
||||
writer->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::SetLogToConsole(bool logToConsole) {
|
||||
for (const auto& writer : m_Writers) {
|
||||
if (writer->IsConsoleWriter()) writer->SetEnabled(logToConsole);
|
||||
}
|
||||
}
|
||||
|
||||
bool Logger::GetLogToConsole() const {
|
||||
bool toReturn = false;
|
||||
for (const auto& writer : m_Writers) {
|
||||
if (writer->IsConsoleWriter()) toReturn |= writer->GetEnabled();
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
89
dCommon/Logger.h
Normal file
89
dCommon/Logger.h
Normal file
@@ -0,0 +1,89 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define STRINGIFY_IMPL(x) #x
|
||||
|
||||
#define STRINGIFY(x) STRINGIFY_IMPL(x)
|
||||
|
||||
#define GET_FILE_NAME(x, y) GetFileNameFromAbsolutePath(__FILE__ x y)
|
||||
|
||||
#define FILENAME_AND_LINE GET_FILE_NAME(":", STRINGIFY(__LINE__))
|
||||
|
||||
// Calculate the filename at compile time from the path.
|
||||
// We just do this by scanning the path for the last '/' or '\' character and returning the string after it.
|
||||
constexpr const char* GetFileNameFromAbsolutePath(const char* path) {
|
||||
const char* file = path;
|
||||
while (*path) {
|
||||
char nextChar = *path++;
|
||||
if (nextChar == '/' || nextChar == '\\') {
|
||||
file = path;
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
// These have to have a constexpr variable to store the filename_and_line result in a local variable otherwise
|
||||
// they will not be valid constexpr and will be evaluated at runtime instead of compile time!
|
||||
// The full string is still stored in the binary, however the offset of the filename in the absolute paths
|
||||
// is used in the instruction instead of the start of the absolute path.
|
||||
#define LOG(message, ...) do { auto str = FILENAME_AND_LINE; Game::logger->Log(str, message, ##__VA_ARGS__); } while(0)
|
||||
#define LOG_DEBUG(message, ...) do { auto str = FILENAME_AND_LINE; Game::logger->LogDebug(str, message, ##__VA_ARGS__); } while(0)
|
||||
|
||||
// Writer class for writing data to files.
|
||||
class Writer {
|
||||
public:
|
||||
Writer(bool enabled = true) : m_Enabled(enabled) {};
|
||||
virtual ~Writer();
|
||||
|
||||
virtual void Log(const char* time, const char* message);
|
||||
virtual void Flush();
|
||||
|
||||
void SetEnabled(bool disabled) { m_Enabled = disabled; }
|
||||
bool GetEnabled() const { return m_Enabled; }
|
||||
|
||||
bool IsConsoleWriter() { return m_IsConsoleWriter; }
|
||||
public:
|
||||
bool m_Enabled = true;
|
||||
bool m_IsConsoleWriter = false;
|
||||
FILE* m_Outfile;
|
||||
};
|
||||
|
||||
// FileWriter class for writing data to a file on a disk.
|
||||
class FileWriter : public Writer {
|
||||
public:
|
||||
FileWriter(const char* outpath);
|
||||
FileWriter(const std::string& outpath) : FileWriter(outpath.c_str()) {};
|
||||
private:
|
||||
std::string m_Outpath;
|
||||
};
|
||||
|
||||
// ConsoleWriter class for writing data to the console.
|
||||
class ConsoleWriter : public Writer {
|
||||
public:
|
||||
ConsoleWriter(bool enabled);
|
||||
};
|
||||
|
||||
class Logger {
|
||||
public:
|
||||
Logger() = delete;
|
||||
Logger(const std::string& outpath, bool logToConsole, bool logDebugStatements);
|
||||
|
||||
void Log(const char* filenameAndLine, const char* format, ...);
|
||||
void LogDebug(const char* filenameAndLine, const char* format, ...);
|
||||
|
||||
void Flush();
|
||||
|
||||
bool GetLogToConsole() const;
|
||||
void SetLogToConsole(bool logToConsole);
|
||||
|
||||
void SetLogDebugStatements(bool logDebugStatements) { m_logDebugStatements = logDebugStatements; }
|
||||
|
||||
private:
|
||||
void vLog(const char* format, va_list args);
|
||||
|
||||
bool m_logDebugStatements;
|
||||
std::vector<std::unique_ptr<Writer>> m_Writers;
|
||||
};
|
||||
@@ -136,6 +136,13 @@ NiPoint3& NiPoint3::operator+=(const NiPoint3& point) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
NiPoint3& NiPoint3::operator*=(const float scalar) {
|
||||
this->x *= scalar;
|
||||
this->y *= scalar;
|
||||
this->z *= scalar;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Operator for subtraction of vectors
|
||||
NiPoint3 NiPoint3::operator-(const NiPoint3& point) const {
|
||||
return NiPoint3(this->x - point.x, this->y - point.y, this->z - point.z);
|
||||
|
||||
@@ -138,6 +138,8 @@ public:
|
||||
//! Operator for addition of vectors
|
||||
NiPoint3& operator+=(const NiPoint3& point);
|
||||
|
||||
NiPoint3& operator*=(const float scalar);
|
||||
|
||||
//! Operator for subtraction of vectors
|
||||
NiPoint3 operator-(const NiPoint3& point) const;
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
#include "Type.h"
|
||||
#ifdef __GNUG__
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <cxxabi.h>
|
||||
|
||||
std::string demangle(const char* name) {
|
||||
|
||||
int status = -4; // some arbitrary value to eliminate the compiler warning
|
||||
|
||||
// enable c++11 by passing the flag -std=c++11 to g++
|
||||
std::unique_ptr<char, void(*)(void*)> res{
|
||||
abi::__cxa_demangle(name, NULL, NULL, &status),
|
||||
std::free
|
||||
};
|
||||
|
||||
return (status == 0) ? res.get() : name;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// does nothing if not g++
|
||||
std::string demangle(const char* name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <typeinfo>
|
||||
|
||||
std::string demangle(const char* name);
|
||||
|
||||
template <class T>
|
||||
std::string type(const T& t) {
|
||||
|
||||
return demangle(typeid(t).name());
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "AssetManager.h"
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ struct AssetMemoryBuffer : std::streambuf {
|
||||
}
|
||||
|
||||
void close() {
|
||||
delete m_Base;
|
||||
free(m_Base);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct PackRecord {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "PackIndex.h"
|
||||
#include "BinaryIO.h"
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
|
||||
PackIndex::PackIndex(const std::filesystem::path& filePath) {
|
||||
m_FileStream = std::ifstream(filePath / "versions" / "primary.pki", std::ios::in | std::ios::binary);
|
||||
@@ -34,7 +34,7 @@ PackIndex::PackIndex(const std::filesystem::path& filePath) {
|
||||
m_PackFileIndices.push_back(packFileIndex);
|
||||
}
|
||||
|
||||
Game::logger->Log("PackIndex", "Loaded pack catalog with %i pack files and %i files", m_PackPaths.size(), m_PackFileIndices.size());
|
||||
LOG("Loaded pack catalog with %i pack files and %i files", m_PackPaths.size(), m_PackFileIndices.size());
|
||||
|
||||
for (auto& item : m_PackPaths) {
|
||||
std::replace(item.begin(), item.end(), '\\', '/');
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "BitStream.h"
|
||||
#include "eConnectionType.h"
|
||||
#include "eClientMessageType.h"
|
||||
#include "BitStreamUtils.h"
|
||||
|
||||
#pragma warning (disable:4251) //Disables SQL warnings
|
||||
|
||||
@@ -32,7 +33,7 @@ constexpr uint32_t lowFrameDelta = FRAMES_TO_MS(lowFramerate);
|
||||
#define CBITSTREAM RakNet::BitStream bitStream;
|
||||
#define CINSTREAM RakNet::BitStream inStream(packet->data, packet->length, false);
|
||||
#define CINSTREAM_SKIP_HEADER CINSTREAM if (inStream.GetNumberOfUnreadBits() >= BYTES_TO_BITS(HEADER_SIZE)) inStream.IgnoreBytes(HEADER_SIZE); else inStream.IgnoreBits(inStream.GetNumberOfUnreadBits());
|
||||
#define CMSGHEADER PacketUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::GAME_MSG);
|
||||
#define CMSGHEADER BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::GAME_MSG);
|
||||
#define SEND_PACKET Game::server->Send(&bitStream, sysAddr, false);
|
||||
#define SEND_PACKET_BROADCAST Game::server->Send(&bitStream, UNASSIGNED_SYSTEM_ADDRESS, true);
|
||||
|
||||
|
||||
@@ -1152,7 +1152,7 @@ enum class eGameMessageType : uint16_t {
|
||||
COLLISION_POINT_REMOVED = 1269,
|
||||
SET_ATTACHED = 1270,
|
||||
SET_DESTROYABLE_MODEL_BRICKS = 1271,
|
||||
VEHICLE_SET_POWERSLIDE_LOCK_WHEELS = 1273,
|
||||
VEHICLE_SET_POWERSLIDE_LOCK_WHEELS = 1272,
|
||||
VEHICLE_SET_WHEEL_LOCK_STATE = 1273,
|
||||
SHOW_HEALTH_BAR = 1274,
|
||||
GET_SHOWS_HEALTH_BAR = 1275,
|
||||
|
||||
@@ -101,7 +101,7 @@ enum class eReplicaComponentType : uint32_t {
|
||||
TRADE,
|
||||
USER_CONTROL,
|
||||
IGNORE_LIST,
|
||||
ROCKET_LAUNCH_LUP,
|
||||
MULTI_ZONE_ENTRANCE,
|
||||
BUFF_REAL, // the real buff component, should just be name BUFF
|
||||
INTERACTION_MANAGER,
|
||||
DONATION_VENDOR,
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
#include "dLogger.h"
|
||||
|
||||
dLogger::dLogger(const std::string& outpath, bool logToConsole, bool logDebugStatements) {
|
||||
m_logToConsole = logToConsole;
|
||||
m_logDebugStatements = logDebugStatements;
|
||||
m_outpath = outpath;
|
||||
|
||||
#ifdef _WIN32
|
||||
mFile = std::ofstream(m_outpath);
|
||||
if (!mFile) { printf("Couldn't open %s for writing!\n", outpath.c_str()); }
|
||||
#else
|
||||
fp = fopen(outpath.c_str(), "wt");
|
||||
if (fp == NULL) { printf("Couldn't open %s for writing!\n", outpath.c_str()); }
|
||||
#endif
|
||||
}
|
||||
|
||||
dLogger::~dLogger() {
|
||||
#ifdef _WIN32
|
||||
mFile.close();
|
||||
#else
|
||||
if (fp != nullptr) {
|
||||
fclose(fp);
|
||||
fp = nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void dLogger::vLog(const char* format, va_list args) {
|
||||
#ifdef _WIN32
|
||||
time_t t = time(NULL);
|
||||
struct tm time;
|
||||
localtime_s(&time, &t);
|
||||
char timeStr[70];
|
||||
strftime(timeStr, sizeof(timeStr), "%d-%m-%y %H:%M:%S", &time);
|
||||
char message[2048];
|
||||
vsnprintf(message, 2048, format, args);
|
||||
|
||||
if (m_logToConsole) std::cout << "[" << timeStr << "] " << message;
|
||||
mFile << "[" << timeStr << "] " << message;
|
||||
#else
|
||||
time_t t = time(NULL);
|
||||
struct tm* time = localtime(&t);
|
||||
char timeStr[70];
|
||||
strftime(timeStr, sizeof(timeStr), "%d-%m-%y %H:%M:%S", time);
|
||||
char message[2048];
|
||||
vsnprintf(message, 2048, format, args);
|
||||
|
||||
if (m_logToConsole) {
|
||||
fputs("[", stdout);
|
||||
fputs(timeStr, stdout);
|
||||
fputs("] ", stdout);
|
||||
fputs(message, stdout);
|
||||
}
|
||||
|
||||
if (fp != nullptr) {
|
||||
fputs("[", fp);
|
||||
fputs(timeStr, fp);
|
||||
fputs("] ", fp);
|
||||
fputs(message, fp);
|
||||
} else {
|
||||
printf("Logger not initialized!\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void dLogger::LogBasic(const char* format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vLog(format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void dLogger::LogBasic(const std::string& message) {
|
||||
LogBasic(message.c_str());
|
||||
}
|
||||
|
||||
void dLogger::Log(const char* className, const char* format, ...) {
|
||||
va_list args;
|
||||
std::string log = "[" + std::string(className) + "] " + std::string(format) + "\n";
|
||||
va_start(args, format);
|
||||
vLog(log.c_str(), args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void dLogger::Log(const std::string& className, const std::string& message) {
|
||||
Log(className.c_str(), message.c_str());
|
||||
}
|
||||
|
||||
void dLogger::LogDebug(const char* className, const char* format, ...) {
|
||||
if (!m_logDebugStatements) return;
|
||||
va_list args;
|
||||
std::string log = "[" + std::string(className) + "] " + std::string(format) + "\n";
|
||||
va_start(args, format);
|
||||
vLog(log.c_str(), args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void dLogger::LogDebug(const std::string& className, const std::string& message) {
|
||||
LogDebug(className.c_str(), message.c_str());
|
||||
}
|
||||
|
||||
void dLogger::Flush() {
|
||||
#ifdef _WIN32
|
||||
mFile.flush();
|
||||
#else
|
||||
if (fp != nullptr) {
|
||||
std::fflush(fp);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
#pragma once
|
||||
#include <ctime>
|
||||
#include <cstdarg>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
class dLogger {
|
||||
public:
|
||||
dLogger(const std::string& outpath, bool logToConsole, bool logDebugStatements);
|
||||
~dLogger();
|
||||
|
||||
void SetLogToConsole(bool logToConsole) { m_logToConsole = logToConsole; }
|
||||
void SetLogDebugStatements(bool logDebugStatements) { m_logDebugStatements = logDebugStatements; }
|
||||
void vLog(const char* format, va_list args);
|
||||
|
||||
void LogBasic(const std::string& message);
|
||||
void LogBasic(const char* format, ...);
|
||||
void Log(const char* className, const char* format, ...);
|
||||
void Log(const std::string& className, const std::string& message);
|
||||
void LogDebug(const std::string& className, const std::string& message);
|
||||
void LogDebug(const char* className, const char* format, ...);
|
||||
|
||||
void Flush();
|
||||
|
||||
const bool GetIsLoggingToConsole() const { return m_logToConsole; }
|
||||
|
||||
private:
|
||||
bool m_logDebugStatements;
|
||||
bool m_logToConsole;
|
||||
std::string m_outpath;
|
||||
std::ofstream mFile;
|
||||
|
||||
#ifndef _WIN32
|
||||
//Glorious linux can run with SPEED:
|
||||
FILE* fp = nullptr;
|
||||
#endif
|
||||
};
|
||||
@@ -13,15 +13,7 @@
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
// Enable this to cache all entries in each table for fast access, comes with more memory cost
|
||||
//#define CDCLIENT_CACHE_ALL
|
||||
|
||||
/*!
|
||||
\file CDClientDatabase.hpp
|
||||
\brief An interface between the CDClient.sqlite file and the server
|
||||
*/
|
||||
|
||||
//! The CDClient Database namespace
|
||||
//! The CDClient Database namespace
|
||||
namespace CDClientDatabase {
|
||||
|
||||
//! Opens a connection with the CDClient
|
||||
|
||||
@@ -38,43 +38,53 @@
|
||||
#include "CDFeatureGatingTable.h"
|
||||
#include "CDRailActivatorComponent.h"
|
||||
|
||||
// Uncomment this to cache the full cdclient database into memory. This will make the server load faster, but will use more memory.
|
||||
// A vanilla CDClient takes about 46MB of memory + the regular world data.
|
||||
// #define CDCLIENT_CACHE_ALL
|
||||
|
||||
#ifdef CDCLIENT_CACHE_ALL
|
||||
#define CDCLIENT_DONT_CACHE_TABLE(x) x
|
||||
#else
|
||||
#define CDCLIENT_DONT_CACHE_TABLE(x)
|
||||
#endif
|
||||
|
||||
CDClientManager::CDClientManager() {
|
||||
CDActivityRewardsTable::Instance();
|
||||
CDAnimationsTable::Instance();
|
||||
CDBehaviorParameterTable::Instance();
|
||||
CDBehaviorTemplateTable::Instance();
|
||||
CDComponentsRegistryTable::Instance();
|
||||
CDCurrencyTableTable::Instance();
|
||||
CDDestructibleComponentTable::Instance();
|
||||
CDEmoteTableTable::Instance();
|
||||
CDInventoryComponentTable::Instance();
|
||||
CDItemComponentTable::Instance();
|
||||
CDItemSetsTable::Instance();
|
||||
CDItemSetSkillsTable::Instance();
|
||||
CDLevelProgressionLookupTable::Instance();
|
||||
CDLootMatrixTable::Instance();
|
||||
CDLootTableTable::Instance();
|
||||
CDMissionNPCComponentTable::Instance();
|
||||
CDMissionTasksTable::Instance();
|
||||
CDMissionsTable::Instance();
|
||||
CDObjectSkillsTable::Instance();
|
||||
CDObjectsTable::Instance();
|
||||
CDPhysicsComponentTable::Instance();
|
||||
CDRebuildComponentTable::Instance();
|
||||
CDScriptComponentTable::Instance();
|
||||
CDSkillBehaviorTable::Instance();
|
||||
CDZoneTableTable::Instance();
|
||||
CDVendorComponentTable::Instance();
|
||||
CDActivitiesTable::Instance();
|
||||
CDPackageComponentTable::Instance();
|
||||
CDProximityMonitorComponentTable::Instance();
|
||||
CDMovementAIComponentTable::Instance();
|
||||
CDBrickIDTableTable::Instance();
|
||||
CDRarityTableTable::Instance();
|
||||
CDMissionEmailTable::Instance();
|
||||
CDRewardsTable::Instance();
|
||||
CDPropertyEntranceComponentTable::Instance();
|
||||
CDPropertyTemplateTable::Instance();
|
||||
CDFeatureGatingTable::Instance();
|
||||
CDRailActivatorComponentTable::Instance();
|
||||
CDActivityRewardsTable::Instance().LoadValuesFromDatabase();
|
||||
CDActivitiesTable::Instance().LoadValuesFromDatabase();
|
||||
CDCLIENT_DONT_CACHE_TABLE(CDAnimationsTable::Instance().LoadValuesFromDatabase());
|
||||
CDBehaviorParameterTable::Instance().LoadValuesFromDatabase();
|
||||
CDBehaviorTemplateTable::Instance().LoadValuesFromDatabase();
|
||||
CDBrickIDTableTable::Instance().LoadValuesFromDatabase();
|
||||
CDCLIENT_DONT_CACHE_TABLE(CDComponentsRegistryTable::Instance().LoadValuesFromDatabase());
|
||||
CDCurrencyTableTable::Instance().LoadValuesFromDatabase();
|
||||
CDDestructibleComponentTable::Instance().LoadValuesFromDatabase();
|
||||
CDEmoteTableTable::Instance().LoadValuesFromDatabase();
|
||||
CDFeatureGatingTable::Instance().LoadValuesFromDatabase();
|
||||
CDInventoryComponentTable::Instance().LoadValuesFromDatabase();
|
||||
CDCLIENT_DONT_CACHE_TABLE(CDItemComponentTable::Instance().LoadValuesFromDatabase());
|
||||
CDItemSetSkillsTable::Instance().LoadValuesFromDatabase();
|
||||
CDItemSetsTable::Instance().LoadValuesFromDatabase();
|
||||
CDLevelProgressionLookupTable::Instance().LoadValuesFromDatabase();
|
||||
CDCLIENT_DONT_CACHE_TABLE(CDLootMatrixTable::Instance().LoadValuesFromDatabase());
|
||||
CDCLIENT_DONT_CACHE_TABLE(CDLootTableTable::Instance().LoadValuesFromDatabase());
|
||||
CDMissionEmailTable::Instance().LoadValuesFromDatabase();
|
||||
CDMissionNPCComponentTable::Instance().LoadValuesFromDatabase();
|
||||
CDMissionTasksTable::Instance().LoadValuesFromDatabase();
|
||||
CDMissionsTable::Instance().LoadValuesFromDatabase();
|
||||
CDMovementAIComponentTable::Instance().LoadValuesFromDatabase();
|
||||
CDObjectSkillsTable::Instance().LoadValuesFromDatabase();
|
||||
CDCLIENT_DONT_CACHE_TABLE(CDObjectsTable::Instance().LoadValuesFromDatabase());
|
||||
CDPhysicsComponentTable::Instance().LoadValuesFromDatabase();
|
||||
CDPackageComponentTable::Instance().LoadValuesFromDatabase();
|
||||
CDProximityMonitorComponentTable::Instance().LoadValuesFromDatabase();
|
||||
CDPropertyEntranceComponentTable::Instance().LoadValuesFromDatabase();
|
||||
CDPropertyTemplateTable::Instance().LoadValuesFromDatabase();
|
||||
CDRailActivatorComponentTable::Instance().LoadValuesFromDatabase();
|
||||
CDRarityTableTable::Instance().LoadValuesFromDatabase();
|
||||
CDRebuildComponentTable::Instance().LoadValuesFromDatabase();
|
||||
CDRewardsTable::Instance().LoadValuesFromDatabase();
|
||||
CDScriptComponentTable::Instance().LoadValuesFromDatabase();
|
||||
CDSkillBehaviorTable::Instance().LoadValuesFromDatabase();
|
||||
CDVendorComponentTable::Instance().LoadValuesFromDatabase();
|
||||
CDZoneTableTable::Instance().LoadValuesFromDatabase();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "Database.h"
|
||||
#include "Game.h"
|
||||
#include "dConfig.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
using namespace std;
|
||||
|
||||
#pragma warning (disable:4251) //Disables SQL warnings
|
||||
@@ -64,8 +64,8 @@ void Database::Destroy(std::string source, bool log) {
|
||||
if (!con) return;
|
||||
|
||||
if (log) {
|
||||
if (source != "") Game::logger->Log("Database", "Destroying MySQL connection from %s!", source.c_str());
|
||||
else Game::logger->Log("Database", "Destroying MySQL connection!");
|
||||
if (source != "") LOG("Destroying MySQL connection from %s!", source.c_str());
|
||||
else LOG("Destroying MySQL connection!");
|
||||
}
|
||||
|
||||
con->close();
|
||||
@@ -84,7 +84,7 @@ sql::PreparedStatement* Database::CreatePreppedStmt(const std::string& query) {
|
||||
|
||||
if (!con) {
|
||||
Connect();
|
||||
Game::logger->Log("Database", "Trying to reconnect to MySQL");
|
||||
LOG("Trying to reconnect to MySQL");
|
||||
}
|
||||
|
||||
if (!con->isValid() || con->isClosed()) {
|
||||
@@ -93,7 +93,7 @@ sql::PreparedStatement* Database::CreatePreppedStmt(const std::string& query) {
|
||||
con = nullptr;
|
||||
|
||||
Connect();
|
||||
Game::logger->Log("Database", "Trying to reconnect to MySQL from invalid or closed connection");
|
||||
LOG("Trying to reconnect to MySQL from invalid or closed connection");
|
||||
}
|
||||
|
||||
auto* stmt = con->prepareStatement(str);
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
#include "Database.h"
|
||||
#include "Game.h"
|
||||
#include "GeneralUtils.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
#include "BinaryPathFinder.h"
|
||||
|
||||
#include <istream>
|
||||
#include <fstream>
|
||||
|
||||
Migration LoadMigration(std::string path) {
|
||||
Migration migration{};
|
||||
@@ -53,7 +53,7 @@ void MigrationRunner::RunMigrations() {
|
||||
delete stmt;
|
||||
if (doExit) continue;
|
||||
|
||||
Game::logger->Log("MigrationRunner", "Running migration: %s", migration.name.c_str());
|
||||
LOG("Running migration: %s", migration.name.c_str());
|
||||
if (migration.name == "dlu/5_brick_model_sd0.sql") {
|
||||
runSd0Migrations = true;
|
||||
} else {
|
||||
@@ -67,7 +67,7 @@ void MigrationRunner::RunMigrations() {
|
||||
}
|
||||
|
||||
if (finalSQL.empty() && !runSd0Migrations) {
|
||||
Game::logger->Log("MigrationRunner", "Server database is up to date.");
|
||||
LOG("Server database is up to date.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ void MigrationRunner::RunMigrations() {
|
||||
if (query.empty()) continue;
|
||||
simpleStatement->execute(query.c_str());
|
||||
} catch (sql::SQLException& e) {
|
||||
Game::logger->Log("MigrationRunner", "Encountered error running migration: %s", e.what());
|
||||
LOG("Encountered error running migration: %s", e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,9 +87,9 @@ void MigrationRunner::RunMigrations() {
|
||||
// Do this last on the off chance none of the other migrations have been run yet.
|
||||
if (runSd0Migrations) {
|
||||
uint32_t numberOfUpdatedModels = BrickByBrickFix::UpdateBrickByBrickModelsToSd0();
|
||||
Game::logger->Log("MasterServer", "%i models were updated from zlib to sd0.", numberOfUpdatedModels);
|
||||
LOG("%i models were updated from zlib to sd0.", numberOfUpdatedModels);
|
||||
uint32_t numberOfTruncatedModels = BrickByBrickFix::TruncateBrokenBrickByBrickXml();
|
||||
Game::logger->Log("MasterServer", "%i models were truncated from the database.", numberOfTruncatedModels);
|
||||
LOG("%i models were truncated from the database.", numberOfTruncatedModels);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,14 +135,14 @@ void MigrationRunner::RunSQLiteMigrations() {
|
||||
|
||||
// Doing these 1 migration at a time since one takes a long time and some may think it is crashing.
|
||||
// This will at the least guarentee that the full migration needs to be run in order to be counted as "migrated".
|
||||
Game::logger->Log("MigrationRunner", "Executing migration: %s. This may take a while. Do not shut down server.", migration.name.c_str());
|
||||
LOG("Executing migration: %s. This may take a while. Do not shut down server.", migration.name.c_str());
|
||||
CDClientDatabase::ExecuteQuery("BEGIN TRANSACTION;");
|
||||
for (const auto& dml : GeneralUtils::SplitString(migration.data, ';')) {
|
||||
if (dml.empty()) continue;
|
||||
try {
|
||||
CDClientDatabase::ExecuteDML(dml.c_str());
|
||||
} catch (CppSQLite3Exception& e) {
|
||||
Game::logger->Log("MigrationRunner", "Encountered error running DML command: (%i) : %s", e.errorCode(), e.errorMessage());
|
||||
LOG("Encountered error running DML command: (%i) : %s", e.errorCode(), e.errorMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,5 +154,5 @@ void MigrationRunner::RunSQLiteMigrations() {
|
||||
CDClientDatabase::ExecuteQuery("COMMIT;");
|
||||
}
|
||||
|
||||
Game::logger->Log("MigrationRunner", "CDServer database is up to date.");
|
||||
LOG("CDServer database is up to date.");
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "CDActivitiesTable.h"
|
||||
|
||||
CDActivitiesTable::CDActivitiesTable(void) {
|
||||
|
||||
void CDActivitiesTable::LoadValuesFromDatabase() {
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM Activities");
|
||||
@@ -55,8 +54,3 @@ std::vector<CDActivities> CDActivitiesTable::Query(std::function<bool(CDActiviti
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
std::vector<CDActivities> CDActivitiesTable::GetEntries(void) const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,9 +30,10 @@ private:
|
||||
std::vector<CDActivities> entries;
|
||||
|
||||
public:
|
||||
CDActivitiesTable();
|
||||
void LoadValuesFromDatabase();
|
||||
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDActivities> Query(std::function<bool(CDActivities)> predicate);
|
||||
|
||||
std::vector<CDActivities> GetEntries(void) const;
|
||||
const std::vector<CDActivities>& GetEntries() const { return this->entries; }
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "CDActivityRewardsTable.h"
|
||||
|
||||
CDActivityRewardsTable::CDActivityRewardsTable(void) {
|
||||
void CDActivityRewardsTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
@@ -43,8 +43,3 @@ std::vector<CDActivityRewards> CDActivityRewardsTable::Query(std::function<bool(
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
std::vector<CDActivityRewards> CDActivityRewardsTable::GetEntries(void) const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,10 +18,10 @@ private:
|
||||
std::vector<CDActivityRewards> entries;
|
||||
|
||||
public:
|
||||
CDActivityRewardsTable();
|
||||
void LoadValuesFromDatabase();
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDActivityRewards> Query(std::function<bool(CDActivityRewards)> predicate);
|
||||
|
||||
std::vector<CDActivityRewards> GetEntries(void) const;
|
||||
std::vector<CDActivityRewards> GetEntries() const;
|
||||
|
||||
};
|
||||
|
||||
@@ -2,6 +2,35 @@
|
||||
#include "GeneralUtils.h"
|
||||
#include "Game.h"
|
||||
|
||||
|
||||
void CDAnimationsTable::LoadValuesFromDatabase() {
|
||||
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM Animations");
|
||||
while (!tableData.eof()) {
|
||||
std::string animation_type = tableData.getStringField("animation_type", "");
|
||||
DluAssert(!animation_type.empty());
|
||||
AnimationGroupID animationGroupID = tableData.getIntField("animationGroupID", -1);
|
||||
DluAssert(animationGroupID != -1);
|
||||
|
||||
CDAnimation entry;
|
||||
entry.animation_name = tableData.getStringField("animation_name", "");
|
||||
entry.chance_to_play = tableData.getFloatField("chance_to_play", 1.0f);
|
||||
UNUSED_COLUMN(entry.min_loops = tableData.getIntField("min_loops", 0);)
|
||||
UNUSED_COLUMN(entry.max_loops = tableData.getIntField("max_loops", 0);)
|
||||
entry.animation_length = tableData.getFloatField("animation_length", 0.0f);
|
||||
UNUSED_COLUMN(entry.hideEquip = tableData.getIntField("hideEquip", 0) == 1;)
|
||||
UNUSED_COLUMN(entry.ignoreUpperBody = tableData.getIntField("ignoreUpperBody", 0) == 1;)
|
||||
UNUSED_COLUMN(entry.restartable = tableData.getIntField("restartable", 0) == 1;)
|
||||
UNUSED_COLUMN(entry.face_animation_name = tableData.getStringField("face_animation_name", "");)
|
||||
UNUSED_COLUMN(entry.priority = tableData.getFloatField("priority", 0.0f);)
|
||||
UNUSED_COLUMN(entry.blendTime = tableData.getFloatField("blendTime", 0.0f);)
|
||||
|
||||
this->animations[CDAnimationKey(animation_type, animationGroupID)].push_back(entry);
|
||||
tableData.nextRow();
|
||||
}
|
||||
|
||||
tableData.finalize();
|
||||
}
|
||||
|
||||
bool CDAnimationsTable::CacheData(CppSQLite3Statement& queryToCache) {
|
||||
auto tableData = queryToCache.execQuery();
|
||||
// If we received a bad lookup, cache it anyways so we do not run the query again.
|
||||
|
||||
@@ -27,6 +27,7 @@ class CDAnimationsTable : public CDTable<CDAnimationsTable> {
|
||||
typedef std::string AnimationID;
|
||||
typedef std::pair<std::string, AnimationGroupID> CDAnimationKey;
|
||||
public:
|
||||
void LoadValuesFromDatabase();
|
||||
/**
|
||||
* Given an animationType and the previousAnimationName played, return the next animationType to play.
|
||||
* If there are more than 1 animationTypes that can be played, one is selected at random but also does not allow
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#include "CDBehaviorParameterTable.h"
|
||||
#include "GeneralUtils.h"
|
||||
|
||||
uint64_t GetHash(const uint32_t behaviorID, const uint32_t parameterID) {
|
||||
uint64_t hash = behaviorID;
|
||||
hash <<= 31U;
|
||||
hash |= parameterID;
|
||||
uint64_t GetKey(const uint32_t behaviorID, const uint32_t parameterID) {
|
||||
uint64_t key = behaviorID;
|
||||
key <<= 31U;
|
||||
key |= parameterID;
|
||||
|
||||
return hash;
|
||||
return key;
|
||||
}
|
||||
|
||||
CDBehaviorParameterTable::CDBehaviorParameterTable() {
|
||||
void CDBehaviorParameterTable::LoadValuesFromDatabase() {
|
||||
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM BehaviorParameter");
|
||||
while (!tableData.eof()) {
|
||||
uint32_t behaviorID = tableData.getIntField("behaviorID", -1);
|
||||
@@ -21,7 +21,7 @@ CDBehaviorParameterTable::CDBehaviorParameterTable() {
|
||||
} else {
|
||||
parameterId = m_ParametersList.insert(std::make_pair(candidateStringToAdd, m_ParametersList.size())).first->second;
|
||||
}
|
||||
uint64_t hash = GetHash(behaviorID, parameterId);
|
||||
uint64_t hash = GetKey(behaviorID, parameterId);
|
||||
float value = tableData.getFloatField("value", -1.0f);
|
||||
|
||||
m_Entries.insert(std::make_pair(hash, value));
|
||||
@@ -34,7 +34,7 @@ CDBehaviorParameterTable::CDBehaviorParameterTable() {
|
||||
float CDBehaviorParameterTable::GetValue(const uint32_t behaviorID, const std::string& name, const float defaultValue) {
|
||||
auto parameterID = this->m_ParametersList.find(name);
|
||||
if (parameterID == this->m_ParametersList.end()) return defaultValue;
|
||||
auto hash = GetHash(behaviorID, parameterID->second);
|
||||
auto hash = GetKey(behaviorID, parameterID->second);
|
||||
|
||||
// Search for specific parameter
|
||||
auto it = m_Entries.find(hash);
|
||||
@@ -45,7 +45,7 @@ std::map<std::string, float> CDBehaviorParameterTable::GetParametersByBehaviorID
|
||||
uint64_t hashBase = behaviorID;
|
||||
std::map<std::string, float> returnInfo;
|
||||
for (auto& [parameterString, parameterId] : m_ParametersList) {
|
||||
uint64_t hash = GetHash(hashBase, parameterId);
|
||||
uint64_t hash = GetKey(hashBase, parameterId);
|
||||
auto infoCandidate = m_Entries.find(hash);
|
||||
if (infoCandidate != m_Entries.end()) {
|
||||
returnInfo.insert(std::make_pair(parameterString, infoCandidate->second));
|
||||
|
||||
@@ -12,7 +12,7 @@ private:
|
||||
std::unordered_map<BehaviorParameterHash, BehaviorParameterValue> m_Entries;
|
||||
std::unordered_map<std::string, uint32_t> m_ParametersList;
|
||||
public:
|
||||
CDBehaviorParameterTable();
|
||||
void LoadValuesFromDatabase();
|
||||
|
||||
float GetValue(const uint32_t behaviorID, const std::string& name, const float defaultValue = 0);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "CDBehaviorTemplateTable.h"
|
||||
|
||||
CDBehaviorTemplateTable::CDBehaviorTemplateTable(void) {
|
||||
void CDBehaviorTemplateTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
@@ -48,7 +48,7 @@ std::vector<CDBehaviorTemplate> CDBehaviorTemplateTable::Query(std::function<boo
|
||||
return data;
|
||||
}
|
||||
|
||||
std::vector<CDBehaviorTemplate> CDBehaviorTemplateTable::GetEntries(void) const {
|
||||
const std::vector<CDBehaviorTemplate>& CDBehaviorTemplateTable::GetEntries() const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
@@ -64,4 +64,3 @@ const CDBehaviorTemplate CDBehaviorTemplateTable::GetByBehaviorID(uint32_t behav
|
||||
return entry->second;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,12 @@ private:
|
||||
std::unordered_map<uint32_t, CDBehaviorTemplate> entriesMappedByBehaviorID;
|
||||
std::unordered_set<std::string> m_EffectHandles;
|
||||
public:
|
||||
CDBehaviorTemplateTable();
|
||||
void LoadValuesFromDatabase();
|
||||
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDBehaviorTemplate> Query(std::function<bool(CDBehaviorTemplate)> predicate);
|
||||
|
||||
std::vector<CDBehaviorTemplate> GetEntries(void) const;
|
||||
const std::vector<CDBehaviorTemplate>& GetEntries(void) const;
|
||||
|
||||
const CDBehaviorTemplate GetByBehaviorID(uint32_t behaviorID);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "CDBrickIDTableTable.h"
|
||||
|
||||
CDBrickIDTableTable::CDBrickIDTableTable(void) {
|
||||
void CDBrickIDTableTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
@@ -39,7 +39,7 @@ std::vector<CDBrickIDTable> CDBrickIDTableTable::Query(std::function<bool(CDBric
|
||||
return data;
|
||||
}
|
||||
|
||||
std::vector<CDBrickIDTable> CDBrickIDTableTable::GetEntries(void) const {
|
||||
const std::vector<CDBrickIDTable>& CDBrickIDTableTable::GetEntries() const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,9 @@ private:
|
||||
std::vector<CDBrickIDTable> entries;
|
||||
|
||||
public:
|
||||
CDBrickIDTableTable();
|
||||
void LoadValuesFromDatabase();
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDBrickIDTable> Query(std::function<bool(CDBrickIDTable)> predicate);
|
||||
|
||||
std::vector<CDBrickIDTable> GetEntries(void) const;
|
||||
const std::vector<CDBrickIDTable>& GetEntries() const;
|
||||
};
|
||||
|
||||
@@ -1,27 +1,37 @@
|
||||
#include "CDComponentsRegistryTable.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
#define CDCLIENT_CACHE_ALL
|
||||
|
||||
CDComponentsRegistryTable::CDComponentsRegistryTable(void) {
|
||||
|
||||
#ifdef CDCLIENT_CACHE_ALL
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM ComponentsRegistry");
|
||||
while (!tableSize.eof()) {
|
||||
size = tableSize.getIntField(0, 0);
|
||||
|
||||
tableSize.nextRow();
|
||||
}
|
||||
|
||||
tableSize.finalize();
|
||||
|
||||
// Reserve the size
|
||||
//this->entries.reserve(size);
|
||||
|
||||
void CDComponentsRegistryTable::LoadValuesFromDatabase() {
|
||||
// Now get the data
|
||||
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM ComponentsRegistry");
|
||||
while (!tableData.eof()) {
|
||||
CDComponentsRegistry entry;
|
||||
entry.id = tableData.getIntField("id", -1);
|
||||
entry.component_type = static_cast<eReplicaComponentType>(tableData.getIntField("component_type", 0));
|
||||
entry.component_id = tableData.getIntField("component_id", -1);
|
||||
|
||||
this->mappedEntries.insert_or_assign(((uint64_t)entry.component_type) << 32 | ((uint64_t)entry.id), entry.component_id);
|
||||
this->mappedEntries.insert_or_assign(entry.id, 0);
|
||||
|
||||
tableData.nextRow();
|
||||
}
|
||||
|
||||
tableData.finalize();
|
||||
}
|
||||
|
||||
int32_t CDComponentsRegistryTable::GetByIDAndType(uint32_t id, eReplicaComponentType componentType, int32_t defaultValue) {
|
||||
auto exists = mappedEntries.find(id);
|
||||
if (exists != mappedEntries.end()) {
|
||||
auto iter = mappedEntries.find(((uint64_t)componentType) << 32 | ((uint64_t)id));
|
||||
return iter == mappedEntries.end() ? defaultValue : iter->second;
|
||||
}
|
||||
|
||||
// Now get the data. Get all components of this entity so we dont do a query for each component
|
||||
auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM ComponentsRegistry WHERE id = ?;");
|
||||
query.bind(1, static_cast<int32_t>(id));
|
||||
|
||||
auto tableData = query.execQuery();
|
||||
|
||||
while (!tableData.eof()) {
|
||||
CDComponentsRegistry entry;
|
||||
entry.id = tableData.getIntField("id", -1);
|
||||
@@ -33,61 +43,10 @@ CDComponentsRegistryTable::CDComponentsRegistryTable(void) {
|
||||
tableData.nextRow();
|
||||
}
|
||||
|
||||
tableData.finalize();
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t CDComponentsRegistryTable::GetByIDAndType(uint32_t id, eReplicaComponentType componentType, int32_t defaultValue) {
|
||||
const auto& iter = this->mappedEntries.find(((uint64_t)componentType) << 32 | ((uint64_t)id));
|
||||
|
||||
if (iter == this->mappedEntries.end()) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return iter->second;
|
||||
|
||||
#ifndef CDCLIENT_CACHE_ALL
|
||||
// Now get the data
|
||||
std::stringstream query;
|
||||
|
||||
query << "SELECT * FROM ComponentsRegistry WHERE id = " << std::to_string(id);
|
||||
|
||||
auto tableData = CDClientDatabase::ExecuteQuery(query.str());
|
||||
while (!tableData.eof()) {
|
||||
CDComponentsRegistry entry;
|
||||
entry.id = tableData.getIntField("id", -1);
|
||||
entry.component_type = tableData.getIntField("component_type", -1);
|
||||
entry.component_id = tableData.getIntField("component_id", -1);
|
||||
|
||||
//this->entries.push_back(entry);
|
||||
|
||||
//Darwin's stuff:
|
||||
const auto& it = this->mappedEntries.find(entry.id);
|
||||
if (it != mappedEntries.end()) {
|
||||
const auto& iter = it->second.find(entry.component_type);
|
||||
if (iter == it->second.end()) {
|
||||
it->second.insert(std::make_pair(entry.component_type, entry.component_id));
|
||||
}
|
||||
} else {
|
||||
std::map<unsigned int, unsigned int> map;
|
||||
map.insert(std::make_pair(entry.component_type, entry.component_id));
|
||||
this->mappedEntries.insert(std::make_pair(entry.id, map));
|
||||
}
|
||||
|
||||
tableData.nextRow();
|
||||
}
|
||||
|
||||
tableData.finalize();
|
||||
|
||||
const auto& it2 = this->mappedEntries.find(id);
|
||||
if (it2 != mappedEntries.end()) {
|
||||
const auto& iter = it2->second.find(componentType);
|
||||
if (iter != it2->second.end()) {
|
||||
return iter->second;
|
||||
}
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
#endif
|
||||
mappedEntries.insert_or_assign(id, 0);
|
||||
|
||||
auto iter = this->mappedEntries.find(((uint64_t)componentType) << 32 | ((uint64_t)id));
|
||||
|
||||
return iter == this->mappedEntries.end() ? defaultValue : iter->second;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ struct CDComponentsRegistry {
|
||||
|
||||
class CDComponentsRegistryTable : public CDTable<CDComponentsRegistryTable> {
|
||||
private:
|
||||
std::map<uint64_t, uint32_t> mappedEntries; //id, component_type, component_id
|
||||
std::unordered_map<uint64_t, uint32_t> mappedEntries; //id, component_type, component_id
|
||||
|
||||
public:
|
||||
CDComponentsRegistryTable();
|
||||
void LoadValuesFromDatabase();
|
||||
int32_t GetByIDAndType(uint32_t id, eReplicaComponentType componentType, int32_t defaultValue = 0);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "CDCurrencyTableTable.h"
|
||||
|
||||
//! Constructor
|
||||
CDCurrencyTableTable::CDCurrencyTableTable(void) {
|
||||
void CDCurrencyTableTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
@@ -43,7 +43,7 @@ std::vector<CDCurrencyTable> CDCurrencyTableTable::Query(std::function<bool(CDCu
|
||||
return data;
|
||||
}
|
||||
|
||||
std::vector<CDCurrencyTable> CDCurrencyTableTable::GetEntries(void) const {
|
||||
const std::vector<CDCurrencyTable>& CDCurrencyTableTable::GetEntries() const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ private:
|
||||
std::vector<CDCurrencyTable> entries;
|
||||
|
||||
public:
|
||||
CDCurrencyTableTable();
|
||||
void LoadValuesFromDatabase();
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDCurrencyTable> Query(std::function<bool(CDCurrencyTable)> predicate);
|
||||
|
||||
std::vector<CDCurrencyTable> GetEntries(void) const;
|
||||
const std::vector<CDCurrencyTable>& GetEntries() const;
|
||||
};
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#include "CDDestructibleComponentTable.h"
|
||||
|
||||
//! Constructor
|
||||
CDDestructibleComponentTable::CDDestructibleComponentTable(void) {
|
||||
|
||||
void CDDestructibleComponentTable::LoadValuesFromDatabase() {
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM DestructibleComponent");
|
||||
@@ -52,7 +50,7 @@ std::vector<CDDestructibleComponent> CDDestructibleComponentTable::Query(std::fu
|
||||
return data;
|
||||
}
|
||||
|
||||
std::vector<CDDestructibleComponent> CDDestructibleComponentTable::GetEntries(void) const {
|
||||
const std::vector<CDDestructibleComponent>& CDDestructibleComponentTable::GetEntries() const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,9 +25,9 @@ private:
|
||||
std::vector<CDDestructibleComponent> entries;
|
||||
|
||||
public:
|
||||
CDDestructibleComponentTable();
|
||||
void LoadValuesFromDatabase();
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDDestructibleComponent> Query(std::function<bool(CDDestructibleComponent)> predicate);
|
||||
|
||||
std::vector<CDDestructibleComponent> GetEntries(void) const;
|
||||
const std::vector<CDDestructibleComponent>& GetEntries(void) const;
|
||||
};
|
||||
|
||||
@@ -1,40 +1,26 @@
|
||||
#include "CDEmoteTable.h"
|
||||
|
||||
//! Constructor
|
||||
CDEmoteTableTable::CDEmoteTableTable(void) {
|
||||
void CDEmoteTableTable::LoadValuesFromDatabase() {
|
||||
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM Emotes");
|
||||
while (!tableData.eof()) {
|
||||
CDEmoteTable* entry = new CDEmoteTable();
|
||||
entry->ID = tableData.getIntField("id", -1);
|
||||
entry->animationName = tableData.getStringField("animationName", "");
|
||||
entry->iconFilename = tableData.getStringField("iconFilename", "");
|
||||
entry->channel = tableData.getIntField("channel", -1);
|
||||
entry->locked = tableData.getIntField("locked", -1) != 0;
|
||||
entry->localize = tableData.getIntField("localize", -1) != 0;
|
||||
entry->locState = tableData.getIntField("locStatus", -1);
|
||||
entry->gateVersion = tableData.getStringField("gate_version", "");
|
||||
CDEmoteTable entry;
|
||||
entry.ID = tableData.getIntField("id", -1);
|
||||
entry.animationName = tableData.getStringField("animationName", "");
|
||||
entry.iconFilename = tableData.getStringField("iconFilename", "");
|
||||
entry.channel = tableData.getIntField("channel", -1);
|
||||
entry.locked = tableData.getIntField("locked", -1) != 0;
|
||||
entry.localize = tableData.getIntField("localize", -1) != 0;
|
||||
entry.locState = tableData.getIntField("locStatus", -1);
|
||||
entry.gateVersion = tableData.getStringField("gate_version", "");
|
||||
|
||||
entries.insert(std::make_pair(entry->ID, entry));
|
||||
entries.insert(std::make_pair(entry.ID, entry));
|
||||
tableData.nextRow();
|
||||
}
|
||||
|
||||
tableData.finalize();
|
||||
}
|
||||
|
||||
//! Destructor
|
||||
CDEmoteTableTable::~CDEmoteTableTable(void) {
|
||||
for (auto e : entries) {
|
||||
if (e.second) delete e.second;
|
||||
}
|
||||
|
||||
entries.clear();
|
||||
}
|
||||
|
||||
CDEmoteTable* CDEmoteTableTable::GetEmote(int id) {
|
||||
for (auto e : entries) {
|
||||
if (e.first == id) return e.second;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
auto itr = entries.find(id);
|
||||
return itr != entries.end() ? &itr->second : nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,11 +28,10 @@ struct CDEmoteTable {
|
||||
|
||||
class CDEmoteTableTable : public CDTable<CDEmoteTableTable> {
|
||||
private:
|
||||
std::map<int, CDEmoteTable*> entries;
|
||||
std::map<int, CDEmoteTable> entries;
|
||||
|
||||
public:
|
||||
CDEmoteTableTable();
|
||||
~CDEmoteTableTable();
|
||||
void LoadValuesFromDatabase();
|
||||
// Returns an emote by ID
|
||||
CDEmoteTable* GetEmote(int id);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "CDFeatureGatingTable.h"
|
||||
|
||||
//! Constructor
|
||||
CDFeatureGatingTable::CDFeatureGatingTable(void) {
|
||||
void CDFeatureGatingTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
@@ -53,7 +52,7 @@ bool CDFeatureGatingTable::FeatureUnlocked(const std::string& feature) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<CDFeatureGating> CDFeatureGatingTable::GetEntries(void) const {
|
||||
const std::vector<CDFeatureGating>& CDFeatureGatingTable::GetEntries() const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,12 @@ private:
|
||||
std::vector<CDFeatureGating> entries;
|
||||
|
||||
public:
|
||||
CDFeatureGatingTable();
|
||||
void LoadValuesFromDatabase();
|
||||
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDFeatureGating> Query(std::function<bool(CDFeatureGating)> predicate);
|
||||
|
||||
bool FeatureUnlocked(const std::string& feature) const;
|
||||
|
||||
std::vector<CDFeatureGating> GetEntries(void) const;
|
||||
const std::vector<CDFeatureGating>& GetEntries(void) const;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "CDInventoryComponentTable.h"
|
||||
|
||||
//! Constructor
|
||||
CDInventoryComponentTable::CDInventoryComponentTable(void) {
|
||||
void CDInventoryComponentTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
@@ -42,7 +41,7 @@ std::vector<CDInventoryComponent> CDInventoryComponentTable::Query(std::function
|
||||
return data;
|
||||
}
|
||||
|
||||
std::vector<CDInventoryComponent> CDInventoryComponentTable::GetEntries(void) const {
|
||||
const std::vector<CDInventoryComponent>& CDInventoryComponentTable::GetEntries() const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ private:
|
||||
std::vector<CDInventoryComponent> entries;
|
||||
|
||||
public:
|
||||
CDInventoryComponentTable();
|
||||
void LoadValuesFromDatabase();
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDInventoryComponent> Query(std::function<bool(CDInventoryComponent)> predicate);
|
||||
|
||||
std::vector<CDInventoryComponent> GetEntries(void) const;
|
||||
const std::vector<CDInventoryComponent>& GetEntries() const;
|
||||
};
|
||||
|
||||
@@ -3,11 +3,7 @@
|
||||
|
||||
CDItemComponent CDItemComponentTable::Default = {};
|
||||
|
||||
//! Constructor
|
||||
CDItemComponentTable::CDItemComponentTable(void) {
|
||||
Default = CDItemComponent();
|
||||
|
||||
#ifdef CDCLIENT_CACHE_ALL
|
||||
void CDItemComponentTable::LoadValuesFromDatabase() {
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM ItemComponent");
|
||||
@@ -55,13 +51,13 @@ CDItemComponentTable::CDItemComponentTable(void) {
|
||||
entry.currencyLOT = tableData.getIntField("currencyLOT", -1);
|
||||
entry.altCurrencyCost = tableData.getIntField("altCurrencyCost", -1);
|
||||
entry.subItems = tableData.getStringField("subItems", "");
|
||||
entry.audioEventUse = tableData.getStringField("audioEventUse", "");
|
||||
UNUSED_COLUMN(entry.audioEventUse = tableData.getStringField("audioEventUse", ""));
|
||||
entry.noEquipAnimation = tableData.getIntField("noEquipAnimation", -1) == 1 ? true : false;
|
||||
entry.commendationLOT = tableData.getIntField("commendationLOT", -1);
|
||||
entry.commendationCost = tableData.getIntField("commendationCost", -1);
|
||||
entry.audioEquipMetaEventSet = tableData.getStringField("audioEquipMetaEventSet", "");
|
||||
UNUSED_COLUMN(entry.audioEquipMetaEventSet = tableData.getStringField("audioEquipMetaEventSet", ""));
|
||||
entry.currencyCosts = tableData.getStringField("currencyCosts", "");
|
||||
entry.ingredientInfo = tableData.getStringField("ingredientInfo", "");
|
||||
UNUSED_COLUMN(entry.ingredientInfo = tableData.getStringField("ingredientInfo", ""));
|
||||
entry.locStatus = tableData.getIntField("locStatus", -1);
|
||||
entry.forgeType = tableData.getIntField("forgeType", -1);
|
||||
entry.SellMultiplier = tableData.getFloatField("SellMultiplier", -1.0f);
|
||||
@@ -71,7 +67,6 @@ CDItemComponentTable::CDItemComponentTable(void) {
|
||||
}
|
||||
|
||||
tableData.finalize();
|
||||
#endif
|
||||
}
|
||||
|
||||
const CDItemComponent& CDItemComponentTable::GetItemComponentByID(unsigned int skillID) {
|
||||
@@ -80,12 +75,10 @@ const CDItemComponent& CDItemComponentTable::GetItemComponentByID(unsigned int s
|
||||
return it->second;
|
||||
}
|
||||
|
||||
#ifndef CDCLIENT_CACHE_ALL
|
||||
std::stringstream query;
|
||||
auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM ItemComponent WHERE id = ?;");
|
||||
query.bind(1, static_cast<int32_t>(skillID));
|
||||
|
||||
query << "SELECT * FROM ItemComponent WHERE id = " << std::to_string(skillID);
|
||||
|
||||
auto tableData = CDClientDatabase::ExecuteQuery(query.str());
|
||||
auto tableData = query.execQuery();
|
||||
if (tableData.eof()) {
|
||||
entries.insert(std::make_pair(skillID, Default));
|
||||
return Default;
|
||||
@@ -144,7 +137,6 @@ const CDItemComponent& CDItemComponentTable::GetItemComponentByID(unsigned int s
|
||||
if (it2 != this->entries.end()) {
|
||||
return it2->second;
|
||||
}
|
||||
#endif
|
||||
|
||||
return Default;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ private:
|
||||
std::map<unsigned int, CDItemComponent> entries;
|
||||
|
||||
public:
|
||||
CDItemComponentTable();
|
||||
void LoadValuesFromDatabase();
|
||||
static std::map<LOT, uint32_t> ParseCraftingCurrencies(const CDItemComponent& itemComponent);
|
||||
|
||||
// Gets an entry by ID
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "CDItemSetSkillsTable.h"
|
||||
|
||||
//! Constructor
|
||||
CDItemSetSkillsTable::CDItemSetSkillsTable(void) {
|
||||
void CDItemSetSkillsTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
@@ -41,7 +40,7 @@ std::vector<CDItemSetSkills> CDItemSetSkillsTable::Query(std::function<bool(CDIt
|
||||
return data;
|
||||
}
|
||||
|
||||
std::vector<CDItemSetSkills> CDItemSetSkillsTable::GetEntries(void) const {
|
||||
const std::vector<CDItemSetSkills>& CDItemSetSkillsTable::GetEntries() const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,11 @@ private:
|
||||
std::vector<CDItemSetSkills> entries;
|
||||
|
||||
public:
|
||||
CDItemSetSkillsTable();
|
||||
void LoadValuesFromDatabase();
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDItemSetSkills> Query(std::function<bool(CDItemSetSkills)> predicate);
|
||||
|
||||
std::vector<CDItemSetSkills> GetEntries(void) const;
|
||||
const std::vector<CDItemSetSkills>& GetEntries() const;
|
||||
|
||||
std::vector<CDItemSetSkills> GetBySkillID(unsigned int SkillSetID);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "CDItemSetsTable.h"
|
||||
|
||||
//! Constructor
|
||||
CDItemSetsTable::CDItemSetsTable(void) {
|
||||
void CDItemSetsTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
@@ -53,7 +52,7 @@ std::vector<CDItemSets> CDItemSetsTable::Query(std::function<bool(CDItemSets)> p
|
||||
return data;
|
||||
}
|
||||
|
||||
std::vector<CDItemSets> CDItemSetsTable::GetEntries(void) const {
|
||||
const std::vector<CDItemSets>& CDItemSetsTable::GetEntries() const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,10 +26,10 @@ private:
|
||||
std::vector<CDItemSets> entries;
|
||||
|
||||
public:
|
||||
CDItemSetsTable();
|
||||
void LoadValuesFromDatabase();
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDItemSets> Query(std::function<bool(CDItemSets)> predicate);
|
||||
|
||||
std::vector<CDItemSets> GetEntries(void) const;
|
||||
const std::vector<CDItemSets>& GetEntries(void) const;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "CDLevelProgressionLookupTable.h"
|
||||
|
||||
//! Constructor
|
||||
CDLevelProgressionLookupTable::CDLevelProgressionLookupTable(void) {
|
||||
void CDLevelProgressionLookupTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
@@ -32,7 +31,6 @@ CDLevelProgressionLookupTable::CDLevelProgressionLookupTable(void) {
|
||||
tableData.finalize();
|
||||
}
|
||||
|
||||
//! Queries the table with a custom "where" clause
|
||||
std::vector<CDLevelProgressionLookup> CDLevelProgressionLookupTable::Query(std::function<bool(CDLevelProgressionLookup)> predicate) {
|
||||
|
||||
std::vector<CDLevelProgressionLookup> data = cpplinq::from(this->entries)
|
||||
@@ -42,8 +40,7 @@ std::vector<CDLevelProgressionLookup> CDLevelProgressionLookupTable::Query(std::
|
||||
return data;
|
||||
}
|
||||
|
||||
//! Gets all the entries in the table
|
||||
std::vector<CDLevelProgressionLookup> CDLevelProgressionLookupTable::GetEntries(void) const {
|
||||
const std::vector<CDLevelProgressionLookup>& CDLevelProgressionLookupTable::GetEntries() const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,10 +14,10 @@ private:
|
||||
std::vector<CDLevelProgressionLookup> entries;
|
||||
|
||||
public:
|
||||
CDLevelProgressionLookupTable();
|
||||
void LoadValuesFromDatabase();
|
||||
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDLevelProgressionLookup> Query(std::function<bool(CDLevelProgressionLookup)> predicate);
|
||||
|
||||
// Gets all the entries in the table
|
||||
std::vector<CDLevelProgressionLookup> GetEntries(void) const;
|
||||
const std::vector<CDLevelProgressionLookup>& GetEntries() const;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,19 @@
|
||||
#include "CDLootMatrixTable.h"
|
||||
|
||||
//! Constructor
|
||||
CDLootMatrixTable::CDLootMatrixTable(void) {
|
||||
CDLootMatrix CDLootMatrixTable::ReadRow(CppSQLite3Query& tableData) const {
|
||||
CDLootMatrix entry{};
|
||||
if (tableData.eof()) return entry;
|
||||
entry.LootTableIndex = tableData.getIntField("LootTableIndex", -1);
|
||||
entry.RarityTableIndex = tableData.getIntField("RarityTableIndex", -1);
|
||||
entry.percent = tableData.getFloatField("percent", -1.0f);
|
||||
entry.minToDrop = tableData.getIntField("minToDrop", -1);
|
||||
entry.maxToDrop = tableData.getIntField("maxToDrop", -1);
|
||||
entry.flagID = tableData.getIntField("flagID", -1);
|
||||
UNUSED(entry.gate_version = tableData.getStringField("gate_version", ""));
|
||||
return entry;
|
||||
}
|
||||
|
||||
void CDLootMatrixTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
@@ -12,8 +24,6 @@ CDLootMatrixTable::CDLootMatrixTable(void) {
|
||||
tableSize.nextRow();
|
||||
}
|
||||
|
||||
tableSize.finalize();
|
||||
|
||||
// Reserve the size
|
||||
this->entries.reserve(size);
|
||||
|
||||
@@ -21,33 +31,28 @@ CDLootMatrixTable::CDLootMatrixTable(void) {
|
||||
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM LootMatrix");
|
||||
while (!tableData.eof()) {
|
||||
CDLootMatrix entry;
|
||||
entry.LootMatrixIndex = tableData.getIntField("LootMatrixIndex", -1);
|
||||
entry.LootTableIndex = tableData.getIntField("LootTableIndex", -1);
|
||||
entry.RarityTableIndex = tableData.getIntField("RarityTableIndex", -1);
|
||||
entry.percent = tableData.getFloatField("percent", -1.0f);
|
||||
entry.minToDrop = tableData.getIntField("minToDrop", -1);
|
||||
entry.maxToDrop = tableData.getIntField("maxToDrop", -1);
|
||||
entry.id = tableData.getIntField("id", -1);
|
||||
entry.flagID = tableData.getIntField("flagID", -1);
|
||||
UNUSED(entry.gate_version = tableData.getStringField("gate_version", ""));
|
||||
uint32_t lootMatrixIndex = tableData.getIntField("LootMatrixIndex", -1);
|
||||
|
||||
this->entries.push_back(entry);
|
||||
this->entries[lootMatrixIndex].push_back(ReadRow(tableData));
|
||||
tableData.nextRow();
|
||||
}
|
||||
}
|
||||
|
||||
const LootMatrixEntries& CDLootMatrixTable::GetMatrix(uint32_t matrixId) {
|
||||
auto itr = this->entries.find(matrixId);
|
||||
if (itr != this->entries.end()) {
|
||||
return itr->second;
|
||||
}
|
||||
|
||||
auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM LootMatrix where LootMatrixIndex = ?;");
|
||||
query.bind(1, static_cast<int32_t>(matrixId));
|
||||
|
||||
auto tableData = query.execQuery();
|
||||
while (!tableData.eof()) {
|
||||
this->entries[matrixId].push_back(ReadRow(tableData));
|
||||
tableData.nextRow();
|
||||
}
|
||||
|
||||
tableData.finalize();
|
||||
}
|
||||
|
||||
std::vector<CDLootMatrix> CDLootMatrixTable::Query(std::function<bool(CDLootMatrix)> predicate) {
|
||||
|
||||
std::vector<CDLootMatrix> data = cpplinq::from(this->entries)
|
||||
>> cpplinq::where(predicate)
|
||||
>> cpplinq::to_vector();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
const std::vector<CDLootMatrix>& CDLootMatrixTable::GetEntries(void) const {
|
||||
return this->entries;
|
||||
return this->entries[matrixId];
|
||||
}
|
||||
|
||||
|
||||
@@ -4,26 +4,26 @@
|
||||
#include "CDTable.h"
|
||||
|
||||
struct CDLootMatrix {
|
||||
unsigned int LootMatrixIndex; //!< The Loot Matrix Index
|
||||
unsigned int LootTableIndex; //!< The Loot Table Index
|
||||
unsigned int RarityTableIndex; //!< The Rarity Table Index
|
||||
float percent; //!< The percent that this matrix is used?
|
||||
unsigned int minToDrop; //!< The minimum amount of loot from this matrix to drop
|
||||
unsigned int maxToDrop; //!< The maximum amount of loot from this matrix to drop
|
||||
unsigned int id; //!< The ID of the Loot Matrix
|
||||
unsigned int flagID; //!< ???
|
||||
UNUSED(std::string gate_version); //!< The Gate Version
|
||||
};
|
||||
|
||||
typedef uint32_t LootMatrixIndex;
|
||||
typedef std::vector<CDLootMatrix> LootMatrixEntries;
|
||||
|
||||
class CDLootMatrixTable : public CDTable<CDLootMatrixTable> {
|
||||
private:
|
||||
std::vector<CDLootMatrix> entries;
|
||||
|
||||
public:
|
||||
CDLootMatrixTable();
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDLootMatrix> Query(std::function<bool(CDLootMatrix)> predicate);
|
||||
void LoadValuesFromDatabase();
|
||||
|
||||
const std::vector<CDLootMatrix>& GetEntries(void) const;
|
||||
// Gets a matrix by ID or inserts a blank one if none existed.
|
||||
const LootMatrixEntries& GetMatrix(uint32_t matrixId);
|
||||
private:
|
||||
CDLootMatrix ReadRow(CppSQLite3Query& tableData) const;
|
||||
std::unordered_map<LootMatrixIndex, LootMatrixEntries> entries;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,44 @@
|
||||
#include "CDLootTableTable.h"
|
||||
#include "CDClientManager.h"
|
||||
#include "CDComponentsRegistryTable.h"
|
||||
#include "CDItemComponentTable.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
//! Constructor
|
||||
CDLootTableTable::CDLootTableTable(void) {
|
||||
// Sort the tables by their rarity so the highest rarity items are first.
|
||||
void SortTable(LootTableEntries& table) {
|
||||
auto* componentsRegistryTable = CDClientManager::Instance().GetTable<CDComponentsRegistryTable>();
|
||||
auto* itemComponentTable = CDClientManager::Instance().GetTable<CDItemComponentTable>();
|
||||
// We modify the table in place so the outer loop keeps track of what is sorted
|
||||
// and the inner loop finds the highest rarity item and swaps it with the current position
|
||||
// of the outer loop.
|
||||
for (auto oldItrOuter = table.begin(); oldItrOuter != table.end(); oldItrOuter++) {
|
||||
auto lootToInsert = oldItrOuter;
|
||||
// Its fine if this starts at 0, even if this doesnt match lootToInsert as the actual highest will
|
||||
// either be found and overwrite these values, or the original is somehow zero and is still the highest rarity.
|
||||
uint32_t highestLootRarity = 0;
|
||||
for (auto oldItrInner = oldItrOuter; oldItrInner != table.end(); oldItrInner++) {
|
||||
uint32_t itemComponentId = componentsRegistryTable->GetByIDAndType(oldItrInner->itemid, eReplicaComponentType::ITEM);
|
||||
uint32_t rarity = itemComponentTable->GetItemComponentByID(itemComponentId).rarity;
|
||||
if (rarity > highestLootRarity) {
|
||||
highestLootRarity = rarity;
|
||||
lootToInsert = oldItrInner;
|
||||
}
|
||||
}
|
||||
Game::logger->LogDebug("CDLootTableTable", "highest rarity %i item id %i", highestLootRarity, lootToInsert->itemid);
|
||||
std::swap(*oldItrOuter, *lootToInsert);
|
||||
}
|
||||
}
|
||||
|
||||
CDLootTable CDLootTableTable::ReadRow(CppSQLite3Query& tableData) const {
|
||||
CDLootTable entry{};
|
||||
if (tableData.eof()) return entry;
|
||||
entry.itemid = tableData.getIntField("itemid", -1);
|
||||
entry.MissionDrop = tableData.getIntField("MissionDrop", -1) == 1 ? true : false;
|
||||
entry.sortPriority = tableData.getIntField("sortPriority", -1);
|
||||
return entry;
|
||||
}
|
||||
|
||||
void CDLootTableTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
@@ -12,8 +49,6 @@ CDLootTableTable::CDLootTableTable(void) {
|
||||
tableSize.nextRow();
|
||||
}
|
||||
|
||||
tableSize.finalize();
|
||||
|
||||
// Reserve the size
|
||||
this->entries.reserve(size);
|
||||
|
||||
@@ -21,32 +56,32 @@ CDLootTableTable::CDLootTableTable(void) {
|
||||
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM LootTable");
|
||||
while (!tableData.eof()) {
|
||||
CDLootTable entry;
|
||||
entry.id = tableData.getIntField("id", -1);
|
||||
entry.itemid = tableData.getIntField("itemid", -1);
|
||||
entry.LootTableIndex = tableData.getIntField("LootTableIndex", -1);
|
||||
entry.id = tableData.getIntField("id", -1);
|
||||
entry.MissionDrop = tableData.getIntField("MissionDrop", -1) == 1 ? true : false;
|
||||
entry.sortPriority = tableData.getIntField("sortPriority", -1);
|
||||
uint32_t lootTableIndex = tableData.getIntField("LootTableIndex", -1);
|
||||
|
||||
this->entries.push_back(entry);
|
||||
this->entries[lootTableIndex].push_back(ReadRow(tableData));
|
||||
tableData.nextRow();
|
||||
}
|
||||
|
||||
tableData.finalize();
|
||||
for (auto& [id, table] : this->entries) {
|
||||
SortTable(table);
|
||||
}
|
||||
}
|
||||
|
||||
//! Queries the table with a custom "where" clause
|
||||
std::vector<CDLootTable> CDLootTableTable::Query(std::function<bool(CDLootTable)> predicate) {
|
||||
const LootTableEntries& CDLootTableTable::GetTable(uint32_t tableId) {
|
||||
auto itr = this->entries.find(tableId);
|
||||
if (itr != this->entries.end()) {
|
||||
return itr->second;
|
||||
}
|
||||
|
||||
std::vector<CDLootTable> data = cpplinq::from(this->entries)
|
||||
>> cpplinq::where(predicate)
|
||||
>> cpplinq::to_vector();
|
||||
auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM LootTable WHERE LootTableIndex = ?;");
|
||||
query.bind(1, static_cast<int32_t>(tableId));
|
||||
auto tableData = query.execQuery();
|
||||
|
||||
return data;
|
||||
while (!tableData.eof()) {
|
||||
CDLootTable entry;
|
||||
this->entries[tableId].push_back(ReadRow(tableData));
|
||||
tableData.nextRow();
|
||||
}
|
||||
SortTable(this->entries[tableId]);
|
||||
|
||||
return this->entries[tableId];
|
||||
}
|
||||
|
||||
//! Gets all the entries in the table
|
||||
const std::vector<CDLootTable>& CDLootTableTable::GetEntries(void) const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,20 +6,21 @@
|
||||
struct CDLootTable {
|
||||
unsigned int itemid; //!< The LOT of the item
|
||||
unsigned int LootTableIndex; //!< The Loot Table Index
|
||||
unsigned int id; //!< The ID
|
||||
bool MissionDrop; //!< Whether or not this loot table is a mission drop
|
||||
unsigned int sortPriority; //!< The sorting priority
|
||||
};
|
||||
|
||||
typedef uint32_t LootTableIndex;
|
||||
typedef std::vector<CDLootTable> LootTableEntries;
|
||||
|
||||
class CDLootTableTable : public CDTable<CDLootTableTable> {
|
||||
private:
|
||||
std::vector<CDLootTable> entries;
|
||||
CDLootTable ReadRow(CppSQLite3Query& tableData) const;
|
||||
std::unordered_map<LootTableIndex, LootTableEntries> entries;
|
||||
|
||||
public:
|
||||
CDLootTableTable();
|
||||
void LoadValuesFromDatabase();
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDLootTable> Query(std::function<bool(CDLootTable)> predicate);
|
||||
|
||||
const std::vector<CDLootTable>& GetEntries(void) const;
|
||||
const LootTableEntries& GetTable(uint32_t tableId);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "CDMissionEmailTable.h"
|
||||
|
||||
//! Constructor
|
||||
CDMissionEmailTable::CDMissionEmailTable(void) {
|
||||
void CDMissionEmailTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
@@ -48,7 +47,7 @@ std::vector<CDMissionEmail> CDMissionEmailTable::Query(std::function<bool(CDMiss
|
||||
}
|
||||
|
||||
//! Gets all the entries in the table
|
||||
std::vector<CDMissionEmail> CDMissionEmailTable::GetEntries(void) const {
|
||||
const std::vector<CDMissionEmail>& CDMissionEmailTable::GetEntries() const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@ private:
|
||||
std::vector<CDMissionEmail> entries;
|
||||
|
||||
public:
|
||||
CDMissionEmailTable();
|
||||
void LoadValuesFromDatabase();
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDMissionEmail> Query(std::function<bool(CDMissionEmail)> predicate);
|
||||
|
||||
std::vector<CDMissionEmail> GetEntries(void) const;
|
||||
const std::vector<CDMissionEmail>& GetEntries() const;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "CDMissionNPCComponentTable.h"
|
||||
|
||||
//! Constructor
|
||||
CDMissionNPCComponentTable::CDMissionNPCComponentTable(void) {
|
||||
void CDMissionNPCComponentTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
@@ -45,7 +44,7 @@ std::vector<CDMissionNPCComponent> CDMissionNPCComponentTable::Query(std::functi
|
||||
}
|
||||
|
||||
//! Gets all the entries in the table
|
||||
std::vector<CDMissionNPCComponent> CDMissionNPCComponentTable::GetEntries(void) const {
|
||||
const std::vector<CDMissionNPCComponent>& CDMissionNPCComponentTable::GetEntries() const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,12 +16,12 @@ private:
|
||||
std::vector<CDMissionNPCComponent> entries;
|
||||
|
||||
public:
|
||||
CDMissionNPCComponentTable();
|
||||
void LoadValuesFromDatabase();
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDMissionNPCComponent> Query(std::function<bool(CDMissionNPCComponent)> predicate);
|
||||
|
||||
// Gets all the entries in the table
|
||||
std::vector<CDMissionNPCComponent> GetEntries(void) const;
|
||||
const std::vector<CDMissionNPCComponent>& GetEntries() const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "CDMissionTasksTable.h"
|
||||
|
||||
//! Constructor
|
||||
CDMissionTasksTable::CDMissionTasksTable(void) {
|
||||
void CDMissionTasksTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
@@ -56,16 +55,14 @@ std::vector<CDMissionTasks*> CDMissionTasksTable::GetByMissionID(uint32_t missio
|
||||
|
||||
for (auto& entry : this->entries) {
|
||||
if (entry.id == missionID) {
|
||||
CDMissionTasks* task = const_cast<CDMissionTasks*>(&entry);
|
||||
|
||||
tasks.push_back(task);
|
||||
tasks.push_back(&entry);
|
||||
}
|
||||
}
|
||||
|
||||
return tasks;
|
||||
}
|
||||
|
||||
const std::vector<CDMissionTasks>& CDMissionTasksTable::GetEntries(void) const {
|
||||
const std::vector<CDMissionTasks>& CDMissionTasksTable::GetEntries() const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,12 +24,12 @@ private:
|
||||
std::vector<CDMissionTasks> entries;
|
||||
|
||||
public:
|
||||
CDMissionTasksTable();
|
||||
void LoadValuesFromDatabase();
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDMissionTasks> Query(std::function<bool(CDMissionTasks)> predicate);
|
||||
|
||||
std::vector<CDMissionTasks*> GetByMissionID(uint32_t missionID);
|
||||
|
||||
const std::vector<CDMissionTasks>& GetEntries(void) const;
|
||||
const std::vector<CDMissionTasks>& GetEntries() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
CDMissions CDMissionsTable::Default = {};
|
||||
|
||||
//! Constructor
|
||||
CDMissionsTable::CDMissionsTable(void) {
|
||||
void CDMissionsTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
|
||||
@@ -65,12 +65,12 @@ private:
|
||||
std::vector<CDMissions> entries;
|
||||
|
||||
public:
|
||||
CDMissionsTable();
|
||||
void LoadValuesFromDatabase();
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDMissions> Query(std::function<bool(CDMissions)> predicate);
|
||||
|
||||
// Gets all the entries in the table
|
||||
const std::vector<CDMissions>& GetEntries(void) const;
|
||||
const std::vector<CDMissions>& GetEntries() const;
|
||||
|
||||
const CDMissions* GetPtrByMissionID(uint32_t missionID) const;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "CDMovementAIComponentTable.h"
|
||||
|
||||
//! Constructor
|
||||
CDMovementAIComponentTable::CDMovementAIComponentTable(void) {
|
||||
void CDMovementAIComponentTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
@@ -37,7 +36,6 @@ CDMovementAIComponentTable::CDMovementAIComponentTable(void) {
|
||||
tableData.finalize();
|
||||
}
|
||||
|
||||
//! Queries the table with a custom "where" clause
|
||||
std::vector<CDMovementAIComponent> CDMovementAIComponentTable::Query(std::function<bool(CDMovementAIComponent)> predicate) {
|
||||
|
||||
std::vector<CDMovementAIComponent> data = cpplinq::from(this->entries)
|
||||
@@ -47,8 +45,7 @@ std::vector<CDMovementAIComponent> CDMovementAIComponentTable::Query(std::functi
|
||||
return data;
|
||||
}
|
||||
|
||||
//! Gets all the entries in the table
|
||||
std::vector<CDMovementAIComponent> CDMovementAIComponentTable::GetEntries(void) const {
|
||||
const std::vector<CDMovementAIComponent>& CDMovementAIComponentTable::GetEntries(void) const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ private:
|
||||
std::vector<CDMovementAIComponent> entries;
|
||||
|
||||
public:
|
||||
CDMovementAIComponentTable();
|
||||
void LoadValuesFromDatabase();
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDMovementAIComponent> Query(std::function<bool(CDMovementAIComponent)> predicate);
|
||||
|
||||
// Gets all the entries in the table
|
||||
std::vector<CDMovementAIComponent> GetEntries(void) const;
|
||||
const std::vector<CDMovementAIComponent>& GetEntries() const;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "CDObjectSkillsTable.h"
|
||||
|
||||
//! Constructor
|
||||
CDObjectSkillsTable::CDObjectSkillsTable(void) {
|
||||
void CDObjectSkillsTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
@@ -33,7 +32,6 @@ CDObjectSkillsTable::CDObjectSkillsTable(void) {
|
||||
tableData.finalize();
|
||||
}
|
||||
|
||||
//! Queries the table with a custom "where" clause
|
||||
std::vector<CDObjectSkills> CDObjectSkillsTable::Query(std::function<bool(CDObjectSkills)> predicate) {
|
||||
|
||||
std::vector<CDObjectSkills> data = cpplinq::from(this->entries)
|
||||
@@ -43,7 +41,6 @@ std::vector<CDObjectSkills> CDObjectSkillsTable::Query(std::function<bool(CDObje
|
||||
return data;
|
||||
}
|
||||
|
||||
//! Gets all the entries in the table
|
||||
std::vector<CDObjectSkills> CDObjectSkillsTable::GetEntries(void) const {
|
||||
const std::vector<CDObjectSkills>& CDObjectSkillsTable::GetEntries() const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
@@ -15,12 +15,12 @@ private:
|
||||
std::vector<CDObjectSkills> entries;
|
||||
|
||||
public:
|
||||
CDObjectSkillsTable();
|
||||
void LoadValuesFromDatabase();
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDObjectSkills> Query(std::function<bool(CDObjectSkills)> predicate);
|
||||
|
||||
// Gets all the entries in the table
|
||||
std::vector<CDObjectSkills> GetEntries(void) const;
|
||||
const std::vector<CDObjectSkills>& GetEntries() const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#include "CDObjectsTable.h"
|
||||
|
||||
//! Constructor
|
||||
CDObjectsTable::CDObjectsTable(void) {
|
||||
#ifdef CDCLIENT_CACHE_ALL
|
||||
void CDObjectsTable::LoadValuesFromDatabase() {
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM Objects");
|
||||
@@ -20,25 +18,24 @@ CDObjectsTable::CDObjectsTable(void) {
|
||||
CDObjects entry;
|
||||
entry.id = tableData.getIntField("id", -1);
|
||||
entry.name = tableData.getStringField("name", "");
|
||||
entry.placeable = tableData.getIntField("placeable", -1);
|
||||
UNUSED_COLUMN(entry.placeable = tableData.getIntField("placeable", -1);)
|
||||
entry.type = tableData.getStringField("type", "");
|
||||
entry.description = tableData.getStringField("description", "");
|
||||
entry.localize = tableData.getIntField("localize", -1);
|
||||
entry.npcTemplateID = tableData.getIntField("npcTemplateID", -1);
|
||||
entry.displayName = tableData.getStringField("displayName", "");
|
||||
UNUSED_COLUMN(entry.description = tableData.getStringField("description", "");)
|
||||
UNUSED_COLUMN(entry.localize = tableData.getIntField("localize", -1);)
|
||||
UNUSED_COLUMN(entry.npcTemplateID = tableData.getIntField("npcTemplateID", -1);)
|
||||
UNUSED_COLUMN(entry.displayName = tableData.getStringField("displayName", "");)
|
||||
entry.interactionDistance = tableData.getFloatField("interactionDistance", -1.0f);
|
||||
entry.nametag = tableData.getIntField("nametag", -1);
|
||||
entry._internalNotes = tableData.getStringField("_internalNotes", "");
|
||||
entry.locStatus = tableData.getIntField("locStatus", -1);
|
||||
entry.gate_version = tableData.getStringField("gate_version", "");
|
||||
entry.HQ_valid = tableData.getIntField("HQ_valid", -1);
|
||||
UNUSED_COLUMN(entry.nametag = tableData.getIntField("nametag", -1);)
|
||||
UNUSED_COLUMN(entry._internalNotes = tableData.getStringField("_internalNotes", "");)
|
||||
UNUSED_COLUMN(entry.locStatus = tableData.getIntField("locStatus", -1);)
|
||||
UNUSED_COLUMN(entry.gate_version = tableData.getStringField("gate_version", "");)
|
||||
UNUSED_COLUMN(entry.HQ_valid = tableData.getIntField("HQ_valid", -1);)
|
||||
|
||||
this->entries.insert(std::make_pair(entry.id, entry));
|
||||
tableData.nextRow();
|
||||
}
|
||||
|
||||
tableData.finalize();
|
||||
#endif
|
||||
|
||||
m_default.id = 0;
|
||||
}
|
||||
@@ -49,12 +46,10 @@ const CDObjects& CDObjectsTable::GetByID(unsigned int LOT) {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
#ifndef CDCLIENT_CACHE_ALL
|
||||
std::stringstream query;
|
||||
auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM Objects WHERE id = ?;");
|
||||
query.bind(1, static_cast<int32_t>(LOT));
|
||||
|
||||
query << "SELECT * FROM Objects WHERE id = " << std::to_string(LOT);
|
||||
|
||||
auto tableData = CDClientDatabase::ExecuteQuery(query.str());
|
||||
auto tableData = query.execQuery();
|
||||
if (tableData.eof()) {
|
||||
this->entries.insert(std::make_pair(LOT, m_default));
|
||||
return m_default;
|
||||
@@ -88,7 +83,6 @@ const CDObjects& CDObjectsTable::GetByID(unsigned int LOT) {
|
||||
if (it2 != entries.end()) {
|
||||
return it2->second;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_default;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ private:
|
||||
CDObjects m_default;
|
||||
|
||||
public:
|
||||
CDObjectsTable();
|
||||
void LoadValuesFromDatabase();
|
||||
// Gets an entry by ID
|
||||
const CDObjects& GetByID(unsigned int LOT);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "CDPackageComponentTable.h"
|
||||
|
||||
//! Constructor
|
||||
CDPackageComponentTable::CDPackageComponentTable(void) {
|
||||
void CDPackageComponentTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
@@ -43,7 +42,7 @@ std::vector<CDPackageComponent> CDPackageComponentTable::Query(std::function<boo
|
||||
}
|
||||
|
||||
//! Gets all the entries in the table
|
||||
std::vector<CDPackageComponent> CDPackageComponentTable::GetEntries(void) const {
|
||||
const std::vector<CDPackageComponent>& CDPackageComponentTable::GetEntries() const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ private:
|
||||
std::vector<CDPackageComponent> entries;
|
||||
|
||||
public:
|
||||
CDPackageComponentTable(void);
|
||||
void LoadValuesFromDatabase();
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDPackageComponent> Query(std::function<bool(CDPackageComponent)> predicate);
|
||||
|
||||
std::vector<CDPackageComponent> GetEntries(void) const;
|
||||
const std::vector<CDPackageComponent>& GetEntries() const;
|
||||
};
|
||||
|
||||
@@ -1,46 +1,35 @@
|
||||
#include "CDPhysicsComponentTable.h"
|
||||
|
||||
CDPhysicsComponentTable::CDPhysicsComponentTable(void) {
|
||||
void CDPhysicsComponentTable::LoadValuesFromDatabase() {
|
||||
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM PhysicsComponent");
|
||||
while (!tableData.eof()) {
|
||||
CDPhysicsComponent* entry = new CDPhysicsComponent();
|
||||
entry->id = tableData.getIntField("id", -1);
|
||||
entry->bStatic = tableData.getIntField("static", -1) != 0;
|
||||
entry->physicsAsset = tableData.getStringField("physics_asset", "");
|
||||
CDPhysicsComponent entry;
|
||||
entry.id = tableData.getIntField("id", -1);
|
||||
entry.bStatic = tableData.getIntField("static", -1) != 0;
|
||||
entry.physicsAsset = tableData.getStringField("physics_asset", "");
|
||||
UNUSED(entry->jump = tableData.getIntField("jump", -1) != 0);
|
||||
UNUSED(entry->doublejump = tableData.getIntField("doublejump", -1) != 0);
|
||||
entry->speed = tableData.getFloatField("speed", -1);
|
||||
entry.speed = tableData.getFloatField("speed", -1);
|
||||
UNUSED(entry->rotSpeed = tableData.getFloatField("rotSpeed", -1));
|
||||
entry->playerHeight = tableData.getFloatField("playerHeight");
|
||||
entry->playerRadius = tableData.getFloatField("playerRadius");
|
||||
entry->pcShapeType = tableData.getIntField("pcShapeType");
|
||||
entry->collisionGroup = tableData.getIntField("collisionGroup");
|
||||
entry.playerHeight = tableData.getFloatField("playerHeight");
|
||||
entry.playerRadius = tableData.getFloatField("playerRadius");
|
||||
entry.pcShapeType = tableData.getIntField("pcShapeType");
|
||||
entry.collisionGroup = tableData.getIntField("collisionGroup");
|
||||
UNUSED(entry->airSpeed = tableData.getFloatField("airSpeed"));
|
||||
UNUSED(entry->boundaryAsset = tableData.getStringField("boundaryAsset"));
|
||||
UNUSED(entry->jumpAirSpeed = tableData.getFloatField("jumpAirSpeed"));
|
||||
UNUSED(entry->friction = tableData.getFloatField("friction"));
|
||||
UNUSED(entry->gravityVolumeAsset = tableData.getStringField("gravityVolumeAsset"));
|
||||
|
||||
m_entries.insert(std::make_pair(entry->id, entry));
|
||||
m_entries.insert(std::make_pair(entry.id, entry));
|
||||
tableData.nextRow();
|
||||
}
|
||||
|
||||
tableData.finalize();
|
||||
}
|
||||
|
||||
CDPhysicsComponentTable::~CDPhysicsComponentTable() {
|
||||
for (auto e : m_entries) {
|
||||
if (e.second) delete e.second;
|
||||
}
|
||||
|
||||
m_entries.clear();
|
||||
}
|
||||
|
||||
CDPhysicsComponent* CDPhysicsComponentTable::GetByID(unsigned int componentID) {
|
||||
for (auto e : m_entries) {
|
||||
if (e.first == componentID) return e.second;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
auto itr = m_entries.find(componentID);
|
||||
return itr != m_entries.end() ? &itr->second : nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,12 +23,11 @@ struct CDPhysicsComponent {
|
||||
|
||||
class CDPhysicsComponentTable : public CDTable<CDPhysicsComponentTable> {
|
||||
public:
|
||||
CDPhysicsComponentTable();
|
||||
~CDPhysicsComponentTable();
|
||||
void LoadValuesFromDatabase();
|
||||
|
||||
static const std::string GetTableName() { return "PhysicsComponent"; };
|
||||
CDPhysicsComponent* GetByID(unsigned int componentID);
|
||||
|
||||
private:
|
||||
std::map<unsigned int, CDPhysicsComponent*> m_entries;
|
||||
std::map<unsigned int, CDPhysicsComponent> m_entries;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
|
||||
#include "CDPropertyEntranceComponentTable.h"
|
||||
|
||||
CDPropertyEntranceComponentTable::CDPropertyEntranceComponentTable() {
|
||||
void CDPropertyEntranceComponentTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
size_t size = 0;
|
||||
|
||||
@@ -11,12 +11,12 @@ struct CDPropertyEntranceComponent {
|
||||
|
||||
class CDPropertyEntranceComponentTable : public CDTable<CDPropertyEntranceComponentTable> {
|
||||
public:
|
||||
CDPropertyEntranceComponentTable();
|
||||
void LoadValuesFromDatabase();
|
||||
// Queries the table with a custom "where" clause
|
||||
CDPropertyEntranceComponent GetByID(uint32_t id);
|
||||
|
||||
// Gets all the entries in the table
|
||||
[[nodiscard]] std::vector<CDPropertyEntranceComponent> GetEntries() const { return entries; }
|
||||
[[nodiscard]] const std::vector<CDPropertyEntranceComponent>& GetEntries() const { return entries; }
|
||||
private:
|
||||
std::vector<CDPropertyEntranceComponent> entries{};
|
||||
CDPropertyEntranceComponent defaultEntry{};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "CDPropertyTemplateTable.h"
|
||||
|
||||
CDPropertyTemplateTable::CDPropertyTemplateTable() {
|
||||
void CDPropertyTemplateTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
size_t size = 0;
|
||||
|
||||
@@ -10,7 +10,7 @@ struct CDPropertyTemplate {
|
||||
|
||||
class CDPropertyTemplateTable : public CDTable<CDPropertyTemplateTable> {
|
||||
public:
|
||||
CDPropertyTemplateTable();
|
||||
void LoadValuesFromDatabase();
|
||||
|
||||
static const std::string GetTableName() { return "PropertyTemplate"; };
|
||||
CDPropertyTemplate GetByMapID(uint32_t mapID);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "CDProximityMonitorComponentTable.h"
|
||||
|
||||
//! Constructor
|
||||
CDProximityMonitorComponentTable::CDProximityMonitorComponentTable(void) {
|
||||
void CDProximityMonitorComponentTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
@@ -33,7 +32,6 @@ CDProximityMonitorComponentTable::CDProximityMonitorComponentTable(void) {
|
||||
tableData.finalize();
|
||||
}
|
||||
|
||||
//! Queries the table with a custom "where" clause
|
||||
std::vector<CDProximityMonitorComponent> CDProximityMonitorComponentTable::Query(std::function<bool(CDProximityMonitorComponent)> predicate) {
|
||||
|
||||
std::vector<CDProximityMonitorComponent> data = cpplinq::from(this->entries)
|
||||
@@ -43,8 +41,7 @@ std::vector<CDProximityMonitorComponent> CDProximityMonitorComponentTable::Query
|
||||
return data;
|
||||
}
|
||||
|
||||
//! Gets all the entries in the table
|
||||
std::vector<CDProximityMonitorComponent> CDProximityMonitorComponentTable::GetEntries(void) const {
|
||||
const std::vector<CDProximityMonitorComponent>& CDProximityMonitorComponentTable::GetEntries() const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ private:
|
||||
std::vector<CDProximityMonitorComponent> entries;
|
||||
|
||||
public:
|
||||
CDProximityMonitorComponentTable(void);
|
||||
void LoadValuesFromDatabase();
|
||||
//! Queries the table with a custom "where" clause
|
||||
std::vector<CDProximityMonitorComponent> Query(std::function<bool(CDProximityMonitorComponent)> predicate);
|
||||
|
||||
std::vector<CDProximityMonitorComponent> GetEntries(void) const;
|
||||
const std::vector<CDProximityMonitorComponent>& GetEntries() const;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "CDRailActivatorComponent.h"
|
||||
#include "GeneralUtils.h"
|
||||
|
||||
CDRailActivatorComponentTable::CDRailActivatorComponentTable() {
|
||||
void CDRailActivatorComponentTable::LoadValuesFromDatabase() {
|
||||
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM RailActivatorComponent;");
|
||||
while (!tableData.eof()) {
|
||||
CDRailActivatorComponent entry;
|
||||
@@ -52,7 +52,7 @@ CDRailActivatorComponent CDRailActivatorComponentTable::GetEntryByID(int32_t id)
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<CDRailActivatorComponent> CDRailActivatorComponentTable::GetEntries() const {
|
||||
const std::vector<CDRailActivatorComponent>& CDRailActivatorComponentTable::GetEntries() const {
|
||||
return m_Entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,10 +22,10 @@ struct CDRailActivatorComponent {
|
||||
|
||||
class CDRailActivatorComponentTable : public CDTable<CDRailActivatorComponentTable> {
|
||||
public:
|
||||
CDRailActivatorComponentTable();
|
||||
void LoadValuesFromDatabase();
|
||||
static const std::string GetTableName() { return "RailActivatorComponent"; };
|
||||
[[nodiscard]] CDRailActivatorComponent GetEntryByID(int32_t id) const;
|
||||
[[nodiscard]] std::vector<CDRailActivatorComponent> GetEntries() const;
|
||||
[[nodiscard]] const std::vector<CDRailActivatorComponent>& GetEntries() const;
|
||||
private:
|
||||
static std::pair<uint32_t, std::u16string> EffectPairFromString(std::string& str);
|
||||
std::vector<CDRailActivatorComponent> m_Entries{};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "CDRarityTableTable.h"
|
||||
|
||||
//! Constructor
|
||||
CDRarityTableTable::CDRarityTableTable(void) {
|
||||
void CDRarityTableTable::LoadValuesFromDatabase() {
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
@@ -18,33 +17,18 @@ CDRarityTableTable::CDRarityTableTable(void) {
|
||||
this->entries.reserve(size);
|
||||
|
||||
// Now get the data
|
||||
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM RarityTable");
|
||||
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM RarityTable order by randmax desc;");
|
||||
while (!tableData.eof()) {
|
||||
uint32_t rarityTableIndex = tableData.getIntField("RarityTableIndex", -1);
|
||||
|
||||
CDRarityTable entry;
|
||||
entry.id = tableData.getIntField("id", -1);
|
||||
entry.randmax = tableData.getFloatField("randmax", -1);
|
||||
entry.rarity = tableData.getIntField("rarity", -1);
|
||||
entry.RarityTableIndex = tableData.getIntField("RarityTableIndex", -1);
|
||||
|
||||
this->entries.push_back(entry);
|
||||
entries[rarityTableIndex].push_back(entry);
|
||||
tableData.nextRow();
|
||||
}
|
||||
|
||||
tableData.finalize();
|
||||
}
|
||||
|
||||
//! Queries the table with a custom "where" clause
|
||||
std::vector<CDRarityTable> CDRarityTableTable::Query(std::function<bool(CDRarityTable)> predicate) {
|
||||
|
||||
std::vector<CDRarityTable> data = cpplinq::from(this->entries)
|
||||
>> cpplinq::where(predicate)
|
||||
>> cpplinq::to_vector();
|
||||
|
||||
return data;
|
||||
const std::vector<CDRarityTable>& CDRarityTableTable::GetRarityTable(uint32_t id) {
|
||||
return entries[id];
|
||||
}
|
||||
|
||||
//! Gets all the entries in the table
|
||||
const std::vector<CDRarityTable>& CDRarityTableTable::GetEntries(void) const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user