[Player Event Logs] Migrate and Deprecate QS Legacy Logging (#4542)

* First pass of player_event_loot_items

* Second pass of player_event_loot_items

* Third pass of player_event_loot_items

* Example without RecordDetailEvent template

* Cleanup the removal of the template

* Fourth Pass

Add retention for etl tables
Rename tables/fields to etl nomenclature
Combine database work to one atomic load

* Reposition to reduce db tasks

* Refactor etl processing for easier additions

* Add merchant purchase event
testing passed though appears that the event itself has a few bugs.  Will fix them in another commit

* Fix PlayerEventMerchantPurchase in client_packet.cpp

* WIP - Handin

* Handin Event added

* Cleanup

* All a rentention period of 0 days which deletes all current records.

* Updates

Cleanup and refactor a few items.

* Cleanup and Formatting

Cleanup and Formatting

* Add etl for
Playerevent::Trade
PlayerEvent::Speech (new event to mirror functionality of qs_speech

* Add etl for
Playerevent::KilledNPC, KilledNamedNPC and KilledRaidNPC

* Add etl for Playerevent::AA_purchase

Add etl for Playerevent::AA_purchase

* Cleanup before PR

* Review comment updates.

* Add world cli etl:settings to output a json on all player event details.

* Add reserve for all etl_queues
Correct a failed test case for improper next id for etl tables when table is first created.

* Potential solution for a dedicated database connection for player events.

* Simple thread for player_events.  Likely there is a better way to do this.

* Add zone to qs communications for recordplayerevents

First pass of enabling zone to qs direct transport to allow for PlayerEvents to bypass world.

* Cleanup a linux compile issue

* Add augments to LOOT ITEM and DESTROY ITEM

* Add augments to ITEMCREATION, FORAGESUCCESS, FISHSUCCESS, DESTROYITEM, LOOTITEM, DROPPEDITEM, TRADERPURCHASE, TRADERSELL, GUILDTRIBUTEDONATE and cleaned up the naming convention of augments

* Formatting fixes

* Swap out GetNextTableId

* Statically load counter

* Add counter.clear() since the counter is static

* Upload optional QS conversion scripts

* Remove all qs_tables and code referencing them

* Update database.cpp

* Simplify ProcessBatchQueue

* Simplify PorcessBatchQueue

* Simplify event truncation

* Build event truncation to bulk query by retention groups

* Post rebase

* Update player_events.h

* Fix build

* Update npc.cpp

* First pass of direct zone to qs sending for player events

* Remove keepalive logic

* Fix event ordering

* Cleanup

* Update player_event_logs.cpp

* Wipe event data after ETL processed

* Split up database connections, hot reload logs for QS

* Load rules from database vs qs_database

* Update player_event_logs.cpp

* Hot toggle queryserv connect

---------

Co-authored-by: Akkadius <akkadius1@gmail.com>
This commit is contained in:
Mitch Freeman
2025-02-05 04:02:16 -04:00
committed by GitHub
parent 21d27a1122
commit 8f4f8368df
99 changed files with 8156 additions and 2451 deletions
+4
View File
@@ -6,6 +6,8 @@ SET(qserv_sources
queryserv.cpp
queryservconfig.cpp
worldserver.cpp
zonelist.cpp
zoneserver.cpp
)
SET(qserv_headers
@@ -13,6 +15,8 @@ SET(qserv_headers
lfguild.h
queryservconfig.h
worldserver.h
zonelist.h
zoneserver.h
)
ADD_EXECUTABLE(queryserv ${qserv_sources} ${qserv_headers})
+1 -378
View File
@@ -1,386 +1,9 @@
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2008 EQEMu Development Team (http://eqemulator.net)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "../common/global_define.h"
#include "../common/eqemu_logsys.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mysqld_error.h>
#include <limits.h>
#include <ctype.h>
#include <assert.h>
#include <map>
#include <vector>
// Disgrace: for windows compile
#ifdef _WINDOWS
#include <windows.h>
#define snprintf _snprintf
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#else
#include "../common/unix.h"
#include <netinet/in.h>
#endif
#include "database.h"
#include "../common/eq_packet_structs.h"
#include "../common/strings.h"
#include "../common/servertalk.h"
void QSDatabase::AddSpeech(
const char *from,
const char *to,
const char *message,
uint16 minstatus,
uint32 guilddbid,
uint8 type
)
{
auto escapedFrom = new char[strlen(from) * 2 + 1];
auto escapedTo = new char[strlen(to) * 2 + 1];
auto escapedMessage = new char[strlen(message) * 2 + 1];
DoEscapeString(escapedFrom, from, strlen(from));
DoEscapeString(escapedTo, to, strlen(to));
DoEscapeString(escapedMessage, message, strlen(message));
std::string query = StringFormat(
"INSERT INTO `qs_player_speech` "
"SET `from` = '%s', `to` = '%s', `message`='%s', "
"`minstatus`='%i', `guilddbid`='%i', `type`='%i'",
escapedFrom, escapedTo, escapedMessage, minstatus, guilddbid, type
);
safe_delete_array(escapedFrom);
safe_delete_array(escapedTo);
safe_delete_array(escapedMessage);
auto results = QueryDatabase(query);
if (!results.Success()) {
LogInfo("Failed Speech Entry Insert: [{}]", results.ErrorMessage().c_str());
LogInfo("[{}]", query.c_str());
}
}
void QSDatabase::LogPlayerDropItem(QSPlayerDropItem_Struct *QS)
{
std::string query = StringFormat(
"INSERT INTO `qs_player_drop_record` SET `time` = NOW(), "
"`char_id` = '%i', `pickup` = '%i', "
"`zone_id` = '%i', `x` = '%i', `y` = '%i', `z` = '%i' ",
QS->char_id, QS->pickup, QS->zone_id, QS->x, QS->y, QS->z
);
auto results = QueryDatabase(query);
if (!results.Success()) {
LogInfo("Failed Drop Record Insert: [{}]", results.ErrorMessage().c_str());
LogInfo("[{}]", query.c_str());
}
if (QS->_detail_count == 0) {
return;
}
int lastIndex = results.LastInsertedID();
for (int i = 0; i < QS->_detail_count; i++) {
query = StringFormat(
"INSERT INTO `qs_player_drop_record_entries` SET `event_id` = '%i', "
"`item_id` = '%i', `charges` = '%i', `aug_1` = '%i', `aug_2` = '%i', "
"`aug_3` = '%i', `aug_4` = '%i', `aug_5` = '%i'",
lastIndex, QS->items[i].item_id,
QS->items[i].charges, QS->items[i].aug_1, QS->items[i].aug_2,
QS->items[i].aug_3, QS->items[i].aug_4, QS->items[i].aug_5
);
results = QueryDatabase(query);
if (!results.Success()) {
LogInfo("Failed Drop Record Entry Insert: [{}]", results.ErrorMessage().c_str());
LogInfo("[{}]", query.c_str());
}
}
}
void QSDatabase::LogPlayerTrade(PlayerLogTrade_Struct *QS, uint32 detailCount)
{
std::string query = StringFormat(
"INSERT INTO `qs_player_trade_record` SET `time` = NOW(), "
"`char1_id` = '%i', `char1_pp` = '%i', `char1_gp` = '%i', "
"`char1_sp` = '%i', `char1_cp` = '%i', `char1_items` = '%i', "
"`char2_id` = '%i', `char2_pp` = '%i', `char2_gp` = '%i', "
"`char2_sp` = '%i', `char2_cp` = '%i', `char2_items` = '%i'",
QS->character_1_id, QS->character_1_money.platinum, QS->character_1_money.gold,
QS->character_1_money.silver, QS->character_1_money.copper, QS->character_1_item_count,
QS->character_2_id, QS->character_2_money.platinum, QS->character_2_money.gold,
QS->character_2_money.silver, QS->character_2_money.copper, QS->character_2_item_count
);
auto results = QueryDatabase(query);
if (!results.Success()) {
LogInfo("Failed Trade Log Record Insert: [{}]", results.ErrorMessage().c_str());
LogInfo("[{}]", query.c_str());
}
if (detailCount == 0) {
return;
}
int lastIndex = results.LastInsertedID();
for (int i = 0; i < detailCount; i++) {
query = StringFormat(
"INSERT INTO `qs_player_trade_record_entries` SET `event_id` = '%i', "
"`from_id` = '%i', `from_slot` = '%i', `to_id` = '%i', `to_slot` = '%i', "
"`item_id` = '%i', `charges` = '%i', `aug_1` = '%i', `aug_2` = '%i', "
"`aug_3` = '%i', `aug_4` = '%i', `aug_5` = '%i'",
lastIndex, QS->item_entries[i].from_character_id, QS->item_entries[i].from_slot,
QS->item_entries[i].to_character_id, QS->item_entries[i].to_slot, QS->item_entries[i].item_id,
QS->item_entries[i].charges, QS->item_entries[i].aug_1, QS->item_entries[i].aug_2,
QS->item_entries[i].aug_3, QS->item_entries[i].aug_4, QS->item_entries[i].aug_5
);
results = QueryDatabase(query);
if (!results.Success()) {
LogInfo("Failed Trade Log Record Entry Insert: [{}]", results.ErrorMessage().c_str());
LogInfo("[{}]", query.c_str());
}
}
}
void QSDatabase::LogPlayerHandin(QSPlayerLogHandin_Struct *QS, uint32 detailCount)
{
std::string query = StringFormat(
"INSERT INTO `qs_player_handin_record` SET `time` = NOW(), "
"`quest_id` = '%i', `char_id` = '%i', `char_pp` = '%i', "
"`char_gp` = '%i', `char_sp` = '%i', `char_cp` = '%i', "
"`char_items` = '%i', `npc_id` = '%i', `npc_pp` = '%i', "
"`npc_gp` = '%i', `npc_sp` = '%i', `npc_cp` = '%i', "
"`npc_items`='%i'",
QS->quest_id, QS->char_id, QS->char_money.platinum,
QS->char_money.gold, QS->char_money.silver, QS->char_money.copper,
QS->char_count, QS->npc_id, QS->npc_money.platinum,
QS->npc_money.gold, QS->npc_money.silver, QS->npc_money.copper,
QS->npc_count
);
auto results = QueryDatabase(query);
if (!results.Success()) {
LogInfo("Failed Handin Log Record Insert: [{}]", results.ErrorMessage().c_str());
LogInfo("[{}]", query.c_str());
}
if (detailCount == 0) {
return;
}
int lastIndex = results.LastInsertedID();
for (int i = 0; i < detailCount; i++) {
query = StringFormat(
"INSERT INTO `qs_player_handin_record_entries` SET `event_id` = '%i', "
"`action_type` = '%s', `char_slot` = '%i', `item_id` = '%i', "
"`charges` = '%i', `aug_1` = '%i', `aug_2` = '%i', `aug_3` = '%i', "
"`aug_4` = '%i', `aug_5` = '%i'",
lastIndex, QS->items[i].action_type, QS->items[i].char_slot,
QS->items[i].item_id, QS->items[i].charges, QS->items[i].aug_1,
QS->items[i].aug_2, QS->items[i].aug_3, QS->items[i].aug_4,
QS->items[i].aug_5
);
auto results = QueryDatabase(query);
if (!results.Success()) {
LogInfo("Failed Handin Log Record Entry Insert: [{}]", results.ErrorMessage().c_str());
LogInfo("[{}]", query.c_str());
}
}
}
void QSDatabase::LogPlayerNPCKill(QSPlayerLogNPCKill_Struct *QS, uint32 members)
{
std::string query = StringFormat(
"INSERT INTO `qs_player_npc_kill_record` "
"SET `npc_id` = '%i', `type` = '%i', "
"`zone_id` = '%i', `time` = NOW()",
QS->s1.NPCID, QS->s1.Type, QS->s1.ZoneID
);
auto results = QueryDatabase(query);
if (!results.Success()) {
LogInfo("Failed NPC Kill Log Record Insert: [{}]", results.ErrorMessage().c_str());
LogInfo("[{}]", query.c_str());
}
if (members == 0) {
return;
}
int lastIndex = results.LastInsertedID();
for (int i = 0; i < members; i++) {
query = StringFormat(
"INSERT INTO `qs_player_npc_kill_record_entries` "
"SET `event_id` = '%i', `char_id` = '%i'",
lastIndex, QS->Chars[i].char_id
);
auto results = QueryDatabase(query);
if (!results.Success()) {
LogInfo("Failed NPC Kill Log Entry Insert: [{}]", results.ErrorMessage().c_str());
LogInfo("[{}]", query.c_str());
}
}
}
void QSDatabase::LogPlayerDelete(QSPlayerLogDelete_Struct *QS, uint32 items)
{
std::string query = StringFormat(
"INSERT INTO `qs_player_delete_record` SET `time` = NOW(), "
"`char_id` = '%i', `stack_size` = '%i', `char_items` = '%i'",
QS->char_id, QS->stack_size, QS->char_count, QS->char_count
);
auto results = QueryDatabase(query);
if (!results.Success()) {
LogInfo("Failed Delete Log Record Insert: [{}]", results.ErrorMessage().c_str());
LogInfo("[{}]", query.c_str());
}
if (items == 0) {
return;
}
int lastIndex = results.LastInsertedID();
for (int i = 0; i < items; i++) {
query = StringFormat(
"INSERT INTO `qs_player_delete_record_entries` SET `event_id` = '%i', "
"`char_slot` = '%i', `item_id` = '%i', `charges` = '%i', `aug_1` = '%i', "
"`aug_2` = '%i', `aug_3` = '%i', `aug_4` = '%i', `aug_5` = '%i'",
lastIndex, QS->items[i].char_slot, QS->items[i].item_id, QS->items[i].charges,
QS->items[i].aug_1, QS->items[i].aug_2, QS->items[i].aug_3, QS->items[i].aug_4,
QS->items[i].aug_5
);
results = QueryDatabase(query);
if (!results.Success()) {
LogInfo("Failed Delete Log Record Entry Insert: [{}]", results.ErrorMessage().c_str());
LogInfo("[{}]", query.c_str());
}
}
}
void QSDatabase::LogPlayerMove(QSPlayerLogMove_Struct *QS, uint32 items)
{
/* These are item moves */
std::string query = StringFormat(
"INSERT INTO `qs_player_move_record` SET `time` = NOW(), "
"`char_id` = '%i', `from_slot` = '%i', `to_slot` = '%i', "
"`stack_size` = '%i', `char_items` = '%i', `postaction` = '%i'",
QS->char_id, QS->from_slot, QS->to_slot, QS->stack_size,
QS->char_count, QS->postaction
);
auto results = QueryDatabase(query);
if (!results.Success()) {
LogInfo("Failed Move Log Record Insert: [{}]", results.ErrorMessage().c_str());
LogInfo("[{}]", query.c_str());
}
if (items == 0) {
return;
}
int lastIndex = results.LastInsertedID();
for (int i = 0; i < items; i++) {
query = StringFormat(
"INSERT INTO `qs_player_move_record_entries` SET `event_id` = '%i', "
"`from_slot` = '%i', `to_slot` = '%i', `item_id` = '%i', `charges` = '%i', "
"`aug_1` = '%i', `aug_2` = '%i', `aug_3` = '%i', `aug_4` = '%i', `aug_5` = '%i'",
lastIndex, QS->items[i].from_slot, QS->items[i].to_slot, QS->items[i].item_id,
QS->items[i].charges, QS->items[i].aug_1, QS->items[i].aug_2,
QS->items[i].aug_3, QS->items[i].aug_4, QS->items[i].aug_5
);
results = QueryDatabase(query);
if (!results.Success()) {
LogInfo("Failed Move Log Record Entry Insert: [{}]", results.ErrorMessage().c_str());
LogInfo("[{}]", query.c_str());
}
}
}
void QSDatabase::LogMerchantTransaction(QSMerchantLogTransaction_Struct *QS, uint32 items)
{
/* Merchant transactions are from the perspective of the merchant, not the player */
std::string query = StringFormat(
"INSERT INTO `qs_merchant_transaction_record` SET `time` = NOW(), "
"`zone_id` = '%i', `merchant_id` = '%i', `merchant_pp` = '%i', "
"`merchant_gp` = '%i', `merchant_sp` = '%i', `merchant_cp` = '%i', "
"`merchant_items` = '%i', `char_id` = '%i', `char_pp` = '%i', "
"`char_gp` = '%i', `char_sp` = '%i', `char_cp` = '%i', "
"`char_items` = '%i'",
QS->zone_id, QS->merchant_id, QS->merchant_money.platinum,
QS->merchant_money.gold, QS->merchant_money.silver,
QS->merchant_money.copper, QS->merchant_count, QS->char_id,
QS->char_money.platinum, QS->char_money.gold, QS->char_money.silver,
QS->char_money.copper, QS->char_count
);
auto results = QueryDatabase(query);
if (!results.Success()) {
LogInfo("Failed Transaction Log Record Insert: [{}]", results.ErrorMessage().c_str());
LogInfo("[{}]", query.c_str());
}
if (items == 0) {
return;
}
int lastIndex = results.LastInsertedID();
for (int i = 0; i < items; i++) {
query = StringFormat(
"INSERT INTO `qs_merchant_transaction_record_entries` SET `event_id` = '%i', "
"`char_slot` = '%i', `item_id` = '%i', `charges` = '%i', `aug_1` = '%i', "
"`aug_2` = '%i', `aug_3` = '%i', `aug_4` = '%i', `aug_5` = '%i'",
lastIndex, QS->items[i].char_slot, QS->items[i].item_id, QS->items[i].charges,
QS->items[i].aug_1, QS->items[i].aug_2, QS->items[i].aug_3, QS->items[i].aug_4,
QS->items[i].aug_5
);
results = QueryDatabase(query);
if (!results.Success()) {
LogInfo("Failed Transaction Log Record Entry Insert: [{}]", results.ErrorMessage().c_str());
LogInfo("[{}]", query.c_str());
}
}
}
// this function does not delete the ServerPacket, so it must be handled at call site
void QSDatabase::GeneralQueryReceive(ServerPacket *pack)
@@ -388,7 +11,7 @@ void QSDatabase::GeneralQueryReceive(ServerPacket *pack)
/*
These are general queries passed from anywhere in zone instead of packing structures and breaking them down again and again
*/
auto queryBuffer = new char[pack->ReadUInt32() + 1];
auto queryBuffer = new char[pack->ReadUInt32() + 1];
pack->ReadString(queryBuffer);
std::string query(queryBuffer);
-28
View File
@@ -1,22 +1,3 @@
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2008 EQEMu Development Team (http://eqemulator.net)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CHATSERVER_DATABASE_H
#define CHATSERVER_DATABASE_H
@@ -33,17 +14,8 @@
#include <vector>
#include <map>
class QSDatabase : public Database {
public:
void AddSpeech(const char* from, const char* to, const char* message, uint16 minstatus, uint32 guilddbid, uint8 type);
void LogPlayerTrade(PlayerLogTrade_Struct* QS, uint32 DetailCount);
void LogPlayerDropItem(QSPlayerDropItem_Struct* QS);
void LogPlayerHandin(QSPlayerLogHandin_Struct* QS, uint32 DetailCount);
void LogPlayerNPCKill(QSPlayerLogNPCKill_Struct* QS, uint32 Members);
void LogPlayerDelete(QSPlayerLogDelete_Struct* QS, uint32 Items);
void LogPlayerMove(QSPlayerLogMove_Struct* QS, uint32 Items);
void LogMerchantTransaction(QSMerchantLogTransaction_Struct* QS, uint32 Items);
void GeneralQueryReceive(ServerPacket *pack);
};
+8 -11
View File
@@ -1,14 +1,11 @@
#include <stdlib.h>
#include "lfguild.h"
#include "database.h"
#include "worldserver.h"
#include "../common/eqemu_logsys.h"
#include "../common/strings.h"
#include "../common/packet_dump.h"
#include "../common/rulesys.h"
extern WorldServer *worldserver;
extern QSDatabase database;
extern QSDatabase qs_database;
PlayerLookingForGuild::PlayerLookingForGuild(char *name, char *comments, uint32 level, uint32 classes, uint32 aa_count, uint32 time_zone, uint32 time_posted)
{
@@ -38,7 +35,7 @@ bool LFGuildManager::LoadDatabase()
std::string query = "SELECT `type`,`name`,`comment`, "
"`fromlevel`, `tolevel`, `classes`, "
"`aacount`, `timezone`, `timeposted` FROM `lfguild`";
auto results = database.QueryDatabase(query);
auto results = qs_database.QueryDatabase(query);
if (!results.Success()) {
return false;
}
@@ -239,7 +236,7 @@ void LFGuildManager::TogglePlayer(uint32 FromZoneID, uint32 FromInstanceID, char
}
std::string query = StringFormat("DELETE FROM `lfguild` WHERE `type` = 0 AND `name` = '%s'", From);
auto results = database.QueryDatabase(query);
auto results = qs_database.QueryDatabase(query);
uint32 Now = time(nullptr);
@@ -252,7 +249,7 @@ void LFGuildManager::TogglePlayer(uint32 FromZoneID, uint32 FromInstanceID, char
"`classes`, `aacount`, `timezone`, `timeposted`) "
"VALUES (0, '%s', '%s', %u, 0, %u, %u, %u, %u)",
From, Comments, Level, Class, AAPoints, TimeZone, Now);
auto results = database.QueryDatabase(query);
auto results = qs_database.QueryDatabase(query);
}
auto pack = new ServerPacket(ServerOP_QueryServGeneric, strlen(From) + strlen(Comments) + 30);
@@ -281,7 +278,7 @@ void LFGuildManager::ToggleGuild(uint32 FromZoneID, uint32 FromInstanceID, char
}
std::string query = StringFormat("DELETE FROM `lfguild` WHERE `type` = 1 AND `name` = '%s'", GuildName);
auto results = database.QueryDatabase(query);
auto results = qs_database.QueryDatabase(query);
uint32 Now = time(nullptr);
@@ -296,7 +293,7 @@ void LFGuildManager::ToggleGuild(uint32 FromZoneID, uint32 FromInstanceID, char
"VALUES (1, '%s', '%s', %u, %u, %u, %u, %u, %u)",
GuildName, Comments, FromLevel, ToLevel,
Classes, AACount, TimeZone, Now);
auto results = database.QueryDatabase(query);
auto results = qs_database.QueryDatabase(query);
}
@@ -324,7 +321,7 @@ void LFGuildManager::ExpireEntries()
continue;
std::string query = StringFormat("DELETE from `lfguild` WHERE `type` = 0 AND `name` = '%s'", (*it).Name.c_str());
auto results = database.QueryDatabase(query);
auto results = qs_database.QueryDatabase(query);
if(!results.Success())
it = Players.erase(it);
@@ -336,7 +333,7 @@ void LFGuildManager::ExpireEntries()
continue;
std::string query = StringFormat("DELETE from `lfguild` WHERE `type` = 1 AND `name` = '%s'", (*it2).Name.c_str());
auto results = database.QueryDatabase(query);
auto results = qs_database.QueryDatabase(query);
if(!results.Success())
it2 = Guilds.erase(it2);
+80 -26
View File
@@ -1,27 +1,7 @@
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2008 EQEMu Development Team (http://eqemulator.net)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "../common/global_define.h"
#include "../common/eqemu_logsys.h"
#include "../common/opcodemgr.h"
#include "../common/rulesys.h"
#include "../common/servertalk.h"
#include "../common/platform.h"
#include "../common/crash.h"
#include "../common/strings.h"
@@ -31,16 +11,21 @@
#include "queryservconfig.h"
#include "lfguild.h"
#include "worldserver.h"
#include "../common/path_manager.h"
#include "../common/zone_store.h"
#include "../common/events/player_event_logs.h"
#include <list>
#include <signal.h>
#include <thread>
#include "../common/net/servertalk_server.h"
#include "../common/net/console_server.h"
#include "../queryserv/zonelist.h"
#include "../queryserv/zoneserver.h"
#include "../common/discord/discord_manager.h"
volatile bool RunLoops = true;
QSDatabase database;
QSDatabase qs_database;
Database database;
LFGuildManager lfguildmanager;
std::string WorldShortName;
const queryservconfig *Config;
@@ -49,6 +34,9 @@ EQEmuLogSys LogSys;
PathManager path;
ZoneStore zone_store;
PlayerEventLogs player_event_logs;
ZSList zs_list;
uint32 numzones = 0;
DiscordManager discord_manager;
void CatchSignal(int sig_num)
{
@@ -76,12 +64,22 @@ int main()
LogInfo("Connecting to MySQL");
/* MySQL Connection */
if (!database.Connect(
if (!qs_database.Connect(
Config->QSDatabaseHost.c_str(),
Config->QSDatabaseUsername.c_str(),
Config->QSDatabasePassword.c_str(),
Config->QSDatabaseDB.c_str(),
Config->QSDatabasePort
)) {
LogInfo("Cannot continue without a qs database connection");
return 1;
}
if (!database.Connect(
Config->DatabaseHost.c_str(),
Config->DatabaseUsername.c_str(),
Config->DatabasePassword.c_str(),
Config->DatabaseDB.c_str(),
Config->DatabasePort
)) {
LogInfo("Cannot continue without a database connection");
return 1;
@@ -101,6 +99,61 @@ int main()
return 1;
}
//rules:
{
std::string tmp;
if (database.GetVariable("RuleSet", tmp)) {
LogInfo("Loading rule set [{}]", tmp.c_str());
if (!RuleManager::Instance()->LoadRules(&database, tmp.c_str(), false)) {
LogError("Failed to load ruleset [{}], falling back to defaults", tmp.c_str());
}
}
else {
if (!RuleManager::Instance()->LoadRules(&database, "default", false)) {
LogInfo("No rule set configured, using default rules");
}
}
EQ::InitializeDynamicLookups();
}
std::unique_ptr<EQ::Net::ConsoleServer> console;
EQ::Net::ServertalkServerOptions server_opts;
auto server_connection = std::make_unique<EQ::Net::ServertalkServer>();
server_opts.port = Config->QSPort;
server_opts.ipv6 = false;
server_opts.credentials = Config->SharedKey;
server_connection->Listen(server_opts);
LogInfo("Server (TCP) listener started on port [{}]", Config->QSPort);
server_connection->OnConnectionIdentified(
"Zone", [&console](std::shared_ptr<EQ::Net::ServertalkServerConnection> connection) {
numzones++;
zs_list.Add(new ZoneServer(connection, console.get()));
LogInfo(
"New Zone Server connection from [{}] at [{}:{}] zone_count [{}]",
connection->Handle()->RemoteIP(),
connection->Handle()->RemotePort(),
connection->GetUUID(),
numzones
);
}
);
server_connection->OnConnectionRemoved(
"Zone", [](std::shared_ptr<EQ::Net::ServertalkServerConnection> connection) {
numzones--;
zs_list.Remove(connection->GetUUID());
LogInfo(
"Removed Zone Server connection from [{}] total zone_count [{}]",
connection->GetUUID(),
numzones
);
}
);
/* Initial Connection to Worldserver */
worldserver = new WorldServer;
worldserver->Connect();
@@ -109,9 +162,9 @@ int main()
lfguildmanager.LoadDatabase();
Timer player_event_process_timer(1000);
player_event_logs.SetDatabase(&database)->Init();
player_event_logs.SetDatabase(&qs_database)->Init();
auto loop_fn = [&](EQ::Timer* t) {
auto loop_fn = [&](EQ::Timer *t) {
Timer::SetCurrentTime();
if (!RunLoops) {
@@ -124,7 +177,7 @@ int main()
}
if (player_event_process_timer.Check()) {
player_event_logs.Process();
std::jthread player_event_thread(&PlayerEventLogs::Process, &player_event_logs);
}
};
@@ -133,6 +186,7 @@ int main()
EQ::EventLoop::Get().Run();
safe_delete(worldserver);
LogSys.CloseFileLogs();
}
+8 -80
View File
@@ -1,22 +1,3 @@
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "../common/global_define.h"
#include "../common/eqemu_logsys.h"
#include "../common/md5.h"
@@ -41,7 +22,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
extern WorldServer worldserver;
extern const queryservconfig *Config;
extern QSDatabase database;
extern QSDatabase qs_database;
extern LFGuildManager lfguildmanager;
WorldServer::WorldServer()
@@ -91,65 +72,9 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p)
case 0: {
break;
}
case ServerOP_PlayerEvent: {
auto n = PlayerEvent::PlayerEventContainer{};
auto s = (ServerSendPlayerEvent_Struct *) p.Data();
EQ::Util::MemoryStreamReader ss(s->cereal_data, s->cereal_size);
cereal::BinaryInputArchive archive(ss);
archive(n);
player_event_logs.AddToQueue(n.player_event_log);
break;
}
case ServerOP_KeepAlive: {
break;
}
case ServerOP_Speech: {
Server_Speech_Struct *SSS = (Server_Speech_Struct *) p.Data();
std::string tmp1 = SSS->from;
std::string tmp2 = SSS->to;
database.AddSpeech(tmp1.c_str(), tmp2.c_str(), SSS->message, SSS->minstatus, SSS->guilddbid, SSS->type);
break;
}
case ServerOP_QSPlayerLogTrades: {
PlayerLogTrade_Struct *QS = (PlayerLogTrade_Struct *) p.Data();
database.LogPlayerTrade(QS, QS->_detail_count);
break;
}
case ServerOP_QSPlayerDropItem: {
QSPlayerDropItem_Struct *QS = (QSPlayerDropItem_Struct *) p.Data();
database.LogPlayerDropItem(QS);
break;
}
case ServerOP_QSPlayerLogHandins: {
QSPlayerLogHandin_Struct *QS = (QSPlayerLogHandin_Struct *) p.Data();
database.LogPlayerHandin(QS, QS->_detail_count);
break;
}
case ServerOP_QSPlayerLogNPCKills: {
QSPlayerLogNPCKill_Struct *QS = (QSPlayerLogNPCKill_Struct *) p.Data();
uint32 Members = (uint32) (p.Length() - sizeof(QSPlayerLogNPCKill_Struct));
if (Members > 0) { Members = Members / sizeof(QSPlayerLogNPCKillsPlayers_Struct); }
database.LogPlayerNPCKill(QS, Members);
break;
}
case ServerOP_QSPlayerLogDeletes: {
QSPlayerLogDelete_Struct *QS = (QSPlayerLogDelete_Struct *) p.Data();
uint32 Items = QS->char_count;
database.LogPlayerDelete(QS, Items);
break;
}
case ServerOP_QSPlayerLogMoves: {
QSPlayerLogMove_Struct *QS = (QSPlayerLogMove_Struct *) p.Data();
uint32 Items = QS->char_count;
database.LogPlayerMove(QS, Items);
break;
}
case ServerOP_QSPlayerLogMerchantTransactions: {
QSMerchantLogTransaction_Struct *QS = (QSMerchantLogTransaction_Struct *) p.Data();
uint32 Items = QS->char_count + QS->merchant_count;
database.LogMerchantTransaction(QS, Items);
case ServerOP_ReloadLogs: {
LogSys.LoadLogDatabaseSettings();
player_event_logs.ReloadSettings();
break;
}
case ServerOP_QueryServGeneric: {
@@ -199,9 +124,12 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p)
pack.opcode = opcode;
pack.size = (uint32) p.Length();
database.GeneralQueryReceive(&pack);
qs_database.GeneralQueryReceive(&pack);
pack.pBuffer = nullptr;
break;
}
default:
LogInfo("Unhandled opcode: {}", opcode);
break;
}
}
+20
View File
@@ -0,0 +1,20 @@
#include "zonelist.h"
#include "zoneserver.h"
#include "../common/strings.h"
void ZSList::Add(ZoneServer* zoneserver) {
zone_server_list.emplace_back(std::unique_ptr<ZoneServer>(zoneserver));
zoneserver->SetIsZoneConnected(true);
}
void ZSList::Remove(const std::string &uuid)
{
auto iter = zone_server_list.begin();
while (iter != zone_server_list.end()) {
if ((*iter)->GetUUID().compare(uuid) == 0) {
zone_server_list.erase(iter);
return;
}
iter++;
}
}
+23
View File
@@ -0,0 +1,23 @@
#ifndef ZONELIST_H_
#define ZONELIST_H_
#include "../common/types.h"
#include <string>
#include <vector>
#include <memory>
#include <list>
class WorldTCPConnection;
class ZoneServer;
class ZSList {
public:
std::list<std::unique_ptr<ZoneServer>> &GetZsList() { return zone_server_list; }
void Add(ZoneServer *zoneserver);
void Remove(const std::string &uuid);
private:
std::list<std::unique_ptr<ZoneServer>> zone_server_list;
};
#endif /*ZONELIST_H_*/
+48
View File
@@ -0,0 +1,48 @@
#include "zoneserver.h"
#include "../common/global_define.h"
#include "../common/eqemu_logsys.h"
#include "../common/repositories/player_event_logs_repository.h"
#include "../common/events/player_event_logs.h"
#include "../common/discord/discord_manager.h"
extern DiscordManager discord_manager;
ZoneServer::ZoneServer(
std::shared_ptr<EQ::Net::ServertalkServerConnection> in_connection,
EQ::Net::ConsoleServer *in_console
)
: m_connection(in_connection)
{
m_connection->OnMessage(std::bind(&ZoneServer::HandleMessage, this, std::placeholders::_1, std::placeholders::_2));
m_console = in_console;
}
ZoneServer::~ZoneServer()
{
}
void ZoneServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p)
{
ServerPacket tpack(opcode, p);
auto pack = &tpack;
switch (opcode) {
case ServerOP_PlayerEvent: {
auto n = PlayerEvent::PlayerEventContainer{};
auto s = reinterpret_cast<ServerSendPlayerEvent_Struct *>(pack->pBuffer);
EQ::Util::MemoryStreamReader ss(s->cereal_data, s->cereal_size);
cereal::BinaryInputArchive archive(ss);
archive(n);
player_event_logs.AddToQueue(n.player_event_log);
discord_manager.QueuePlayerEventMessage(n);
break;
}
default: {
LogInfo("Unknown ServerOP Received [{}]", opcode);
break;
}
}
}
+32
View File
@@ -0,0 +1,32 @@
#ifndef ZONESERVER_H
#define ZONESERVER_H
#include "../world/world_tcp_connection.h"
#include "../common/net/servertalk_server.h"
#include "../common/event/timer.h"
#include "../common/timer.h"
#include "../common/emu_constants.h"
#include "../world/console.h"
#include <string>
class Client;
class ServerPacket;
class ZoneServer : public WorldTCPConnection {
public:
ZoneServer(std::shared_ptr<EQ::Net::ServertalkServerConnection> in_connection, EQ::Net::ConsoleServer *in_console);
~ZoneServer();
void SendPacket(ServerPacket *pack) { m_connection->SendPacket(pack); }
void SetIsZoneConnected(bool in) { m_is_zone_connected = in; }
bool GetIsZoneConnected() { return m_is_zone_connected; }
void HandleMessage(uint16 opcode, const EQ::Net::Packet &p);
std::string GetUUID() const { return m_connection->GetUUID(); }
private:
std::shared_ptr<EQ::Net::ServertalkServerConnection> m_connection{};
bool m_is_zone_connected = false;
EQ::Net::ConsoleServer *m_console;
};
#endif