eqemu-server/world/zonelist.cpp
Mitch Freeman 91f5932c6d
[Feature] Add RoF2 Guild features (#3699)
* [Feature] Add additional Guild Features

This adds the following guild features and design pattern
- the existing guild system was used
- guild features are based on RoF2 within source with translaters used to converted between client differences
- backward compatible with Ti and UF, and allows for mixed client servers
- Guild Back for Ti and UF is based on RoF2 Permissions for banking if Guild Leader does not use Ti/UF
- Guild Ranks and Permissions are enabled.
- Guild Tributes are enabled.
- Event logging via rules for donating tribute items and plat
- Rules to limit Guild Tributes based on max level of server
- Rewrote guild communications to client using specific opcodes
-- Server no longer sends a guild member list on each zone
-- Guild window is updated when a member levels, rank changes, zone changes, banker/alt status using individual opcodes
-- When a member is removed or added to a guild, a single opcode is sent to each guild member
-- This reduces network traffic considerably

Known issues:
- Visual bug only. Guild Tributes window will display a 0 for level if tribute is above max level rule setting.
- Visual bug only. Guild Mgmt Window will not display an online member if the player has 'show offline' unchecked and a guild member zones within the Notes/Tribute tab.  This is resolved by selecting and de-selecting the 'Show Offline' checkbox.

* Updated RoF2 Guild Comms

Updated RoF2 Guild Comms
Update RoF2 Opcodes
Rewrote RoF2 Guild Communications using specific opcodes.
Added database changes - they are irreversible

* Formatting

* Update base_guild_members_repository.h

* Format GuildInfo

* Format GuildAction enum

* Formatting in clientlist

* quantity vs quantity

* desc vs description

* Format structs

* Inline struct values

* Formatting

* Formatting

* Formatting fixes

* Formatting items

* Formatting

* Formatting

* struct formatting updates

* Updated formatting

* Updated
- std:string items
- naming conventions
- magic numbers

* Repo refactors
Other formatting updates

* Remove test guild commands

* Updated #guild info command

* Add new repo methods for Neckolla ReplaceOne and ReplaceMany

* Fix guild_tributes repo

* Update database_update_manifest.cpp

* Phase 1 of final testing with RoF2 -> RoF2.
Next phase will be inter compatibility review

* Remove #guild testing commands

* Fix uf translator error
Rewrite LoadGuilds

* Use extended repository

* FIx guild window on member add

* LoadGuild Changes

* Update guild_base.cpp

* Few small fixes for display issue with UF

* Update guild_base.cpp

* Update guild_members_repository.h

* Update zoneserver.cpp

* Update guild.cpp

* Update entity.h

* Switch formatting

* Formatting

* Update worldserver.cpp

* Switch formatting

* Formatting switch statement

* Update guild.cpp

* Formatting in guild_base

* We don't need to validate m_db everywhere

* More formatting / spacing issues

* Switch format

* Update guild_base.cpp

* Fix an UF issue displaying incorrect guildtag as <>

* Updated several constants, fixed a few issues with Ti/UF and guild tributes not being removed or sent when a member is removed/disbands from a guild.

* Formatting and logging updates

* Fix for Loadguilds and permissions after repo updates.

* Cleanup unnecessary m_db checks

* Updated logging to use player_event_logs

* Updated to use the single opcodes for guild traffic for Ti/UF/RoF2.  Several enhancements for guild functionality for more reusable code and readability.

* Update to fix Demote Self and guild invites declining when option set to not accept guild invites

* Potential fix for guild notes/tribute display issues when client has 'Show Offline' unchecked.

* Updates to fox recent master changes

Updates to fix recent master changes

* Updates in response to comments

* Further Updates in response to comments

* Comment updates and refactor for SendAppearance functions

* Comment updates

* Update client spawn process for show guild name

Add show guild tag to default spawn process

* Update to use zone spawn packets for RoF2
Removed several unused functions as a result
Updated MemberRankUpdate to properly update guild_show on rank change.
Updated OP_GuildURLAndChannel opcode for UF/RoF2

* Cleanup of world changes
Created function for repetitive zonelist sendpackets to only booted zones
Re-Inserted accidental delete of scanclosemobs

* Fixes

* Further world cleanup

* Fix a few test guild bank cases for backward compat
Removed a duplicate db call
Fixed a fallthrough issue

* Update guild_mgr.cpp

* Cleanup

---------

Co-authored-by: Akkadius <akkadius1@gmail.com>
2024-02-10 03:27:58 -06:00

872 lines
21 KiB
C++

/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2005 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 "zonelist.h"
#include "zoneserver.h"
#include "worlddb.h"
#include "world_config.h"
#include "../common/misc_functions.h"
#include "../common/servertalk.h"
#include "../common/strings.h"
#include "../common/random.h"
#include "../common/json/json.h"
#include "../common/event_sub.h"
#include "web_interface.h"
#include "../common/zone_store.h"
extern uint32 numzones;
extern EQ::Random emu_random;
extern WebInterfaceList web_interface;
volatile bool UCSServerAvailable_ = false;
void CatchSignal(int sig_num);
ZSList::ZSList()
{
NextID = 1;
CurGroupID = 1;
memset(pLockedZones, 0, sizeof(pLockedZones));
m_tick = std::make_unique<EQ::Timer>(5000, true, std::bind(&ZSList::OnTick, this, std::placeholders::_1));
m_keepalive = std::make_unique<EQ::Timer>(1000, true, std::bind(&ZSList::OnKeepAlive, this, std::placeholders::_1));
}
ZSList::~ZSList() {
}
void ZSList::ShowUpTime(WorldTCPConnection* con, const char* adminname) {
uint32 ms = Timer::GetCurrentTime();
std::string time_string = Strings::MillisecondsToTime(ms);
con->SendEmoteMessage(
adminname,
0,
AccountStatus::Player,
Chat::White,
fmt::format(
"Worldserver Uptime | {}",
time_string
).c_str()
);
}
void ZSList::Add(ZoneServer* zoneserver) {
zone_server_list.emplace_back(std::unique_ptr<ZoneServer>(zoneserver));
zoneserver->SendGroupIDs();
}
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) {
auto port = (*iter)->GetCPort();
zone_server_list.erase(iter);
if (port != 0) {
m_ports_free.push_back(port);
}
return;
}
iter++;
}
}
void ZSList::KillAll() {
auto iterator = zone_server_list.begin();
while (iterator != zone_server_list.end()) {
(*iterator)->Disconnect();
iterator = zone_server_list.erase(iterator);
}
}
void ZSList::Process() {
if (shutdowntimer && shutdowntimer->Check()) {
LogInfo("Shutdown timer has expired. Telling all zones to shut down and exiting. (fake sigint)");
auto pack2 = new ServerPacket;
pack2->opcode = ServerOP_ShutdownAll;
pack2->size = 0;
SendPacket(pack2);
safe_delete(pack2);
Process();
CatchSignal(2);
}
if (reminder && reminder->Check() && shutdowntimer) {
SendEmoteMessage(
0,
0,
AccountStatus::Player,
Chat::System,
fmt::format(
"[SYSTEM] World will be shutting down in {} minutes.",
((shutdowntimer->GetRemainingTime() / 1000) / 60)
).c_str()
);
}
}
bool ZSList::SendPacket(ServerPacket* pack) {
auto iterator = zone_server_list.begin();
while (iterator != zone_server_list.end()) {
(*iterator)->SendPacket(pack);
iterator++;
}
return true;
}
bool ZSList::SendPacket(uint32 ZoneID, ServerPacket* pack) {
auto iterator = zone_server_list.begin();
while (iterator != zone_server_list.end()) {
if ((*iterator)->GetZoneID() == ZoneID) {
ZoneServer* tmp = (*iterator).get();
tmp->SendPacket(pack);
return true;
}
iterator++;
}
return(false);
}
bool ZSList::SendPacket(uint32 ZoneID, uint16 instanceID, ServerPacket* pack) {
if (instanceID != 0)
{
auto iterator = zone_server_list.begin();
while (iterator != zone_server_list.end()) {
if ((*iterator)->GetInstanceID() == instanceID) {
ZoneServer* tmp = (*iterator).get();
tmp->SendPacket(pack);
return true;
}
iterator++;
}
}
else
{
auto iterator = zone_server_list.begin();
while (iterator != zone_server_list.end()) {
if ((*iterator)->GetZoneID() == ZoneID
&& (*iterator)->GetInstanceID() == 0) {
ZoneServer* tmp = (*iterator).get();
tmp->SendPacket(pack);
return true;
}
iterator++;
}
}
return(false);
}
ZoneServer* ZSList::FindByName(const char* zonename) {
auto iterator = zone_server_list.begin();
while (iterator != zone_server_list.end()) {
if (strcasecmp((*iterator)->GetZoneName(), zonename) == 0) {
ZoneServer* tmp = (*iterator).get();
return tmp;
}
iterator++;
}
return 0;
}
ZoneServer* ZSList::FindByID(uint32 ZoneID) {
auto iterator = zone_server_list.begin();
while (iterator != zone_server_list.end()) {
if ((*iterator)->GetID() == ZoneID) {
ZoneServer* tmp = (*iterator).get();
return tmp;
}
iterator++;
}
return 0;
}
ZoneServer* ZSList::FindByZoneID(uint32 ZoneID) {
auto iterator = zone_server_list.begin();
while (iterator != zone_server_list.end()) {
ZoneServer* tmp = (*iterator).get();
if (tmp->GetZoneID() == ZoneID && tmp->GetInstanceID() == 0) {
return tmp;
}
iterator++;
}
return 0;
}
ZoneServer* ZSList::FindByPort(uint16 port) {
auto iterator = zone_server_list.begin();
while (iterator != zone_server_list.end()) {
if ((*iterator)->GetCPort() == port) {
ZoneServer* tmp = (*iterator).get();
return tmp;
}
iterator++;
}
return 0;
}
ZoneServer* ZSList::FindByInstanceID(uint32 InstanceID)
{
auto iterator = zone_server_list.begin();
while (iterator != zone_server_list.end()) {
if ((*iterator)->GetInstanceID() == InstanceID) {
ZoneServer* tmp = (*iterator).get();
return tmp;
}
iterator++;
}
return 0;
}
bool ZSList::SetLockedZone(uint16 iZoneID, bool iLock) {
for (auto &zone : pLockedZones) {
if (iLock) {
if (zone == 0) {
zone = iZoneID;
return true;
}
}
else {
if (zone == iZoneID) {
zone = 0;
return true;
}
}
}
return false;
}
void ZSList::Init()
{
const WorldConfig* Config = WorldConfig::get();
for (uint16 i = Config->ZonePortLow; i <= Config->ZonePortHigh; ++i) {
m_ports_free.push_back(i);
}
}
bool ZSList::IsZoneLocked(uint16 iZoneID) {
for (auto &zone : pLockedZones) {
if (zone == iZoneID)
return true;
}
return false;
}
void ZSList::ListLockedZones(const char* to, WorldTCPConnection* connection) {
int zone_count = 0;
for (const auto& zone_id : pLockedZones) {
if (zone_id) {
int zone_number = (zone_count + 1);
connection->SendEmoteMessageRaw(
to,
0,
AccountStatus::Player,
Chat::White,
fmt::format(
"Zone {} | Name: {} ({}) ID: {}",
zone_number,
ZoneLongName(zone_id),
ZoneName(zone_id),
zone_id
).c_str()
);
zone_count++;
}
}
std::string zone_message = (
zone_count ?
fmt::format("{} Zones are locked.", zone_count) :
"There are no zones locked."
);
connection->SendEmoteMessage(
to,
0,
AccountStatus::Player,
Chat::White,
zone_message.c_str()
);
}
void ZSList::SendZoneStatus(const char* to, int16 admin, WorldTCPConnection* connection) {
char locked[4];
if (WorldConfig::get()->Locked == true) {
strcpy(locked, "Yes");
}
else {
strcpy(locked, "No");
}
auto out = fmt::memory_buffer();
if (connection->IsConsole()) {
fmt::format_to(std::back_inserter(out), "World Locked: {}\r\n", locked);
}
else {
fmt::format_to(std::back_inserter(out), "World Locked: {}^", locked);
}
if (connection->IsConsole()) {
fmt::format_to(std::back_inserter(out), "Zoneservers online:\r\n");
}
else {
fmt::format_to(std::back_inserter(out), "Zoneservers online:^");
}
int v = 0, w = 0, x = 0, y = 0, z = 0;
char is_static_string[2] = { 0, 0 }, zone_data_string[64];
memset(zone_data_string, 0, sizeof(zone_data_string));
ZoneServer* zone_server_data = 0;
auto iterator = zone_server_list.begin();
while (iterator != zone_server_list.end()) {
zone_server_data = (*iterator).get();
auto addr = zone_server_data->GetIP();
if (zone_server_data->IsStaticZone()) {
z++;
}
else if (zone_server_data->GetZoneID() != 0) {
w++;
}
else if (zone_server_data->GetZoneID() == 0 && !zone_server_data->IsBootingUp()) {
v++;
}
if (zone_server_data->IsStaticZone())
is_static_string[0] = 'S';
else
is_static_string[0] = 'D';
if (admin >= AccountStatus::GMLeadAdmin) {
if (zone_server_data->GetZoneID()) {
snprintf(zone_data_string, sizeof(zone_data_string), "%s (%i)", zone_server_data->GetZoneName(), zone_server_data->GetZoneID());
}
else if (zone_server_data->IsBootingUp()) {
strcpy(zone_data_string, "...");
}
else {
zone_data_string[0] = 0;
}
fmt::format_to(std::back_inserter(out),
"#{:<3} :: {} :: {}:{:<5} :: {:2} :: {}:{} :: {} :: ({})",
zone_server_data->GetID(),
is_static_string,
addr.c_str(),
zone_server_data->GetPort(),
zone_server_data->NumPlayers(),
zone_server_data->GetCAddress(),
zone_server_data->GetCPort(),
zone_data_string,
zone_server_data->GetZoneOSProcessID()
);
if (out.size() >= 3584) {
connection->SendEmoteMessageRaw(
to,
0,
AccountStatus::Player,
Chat::NPCQuestSay,
out.data()
);
out.clear();
}
else {
if (connection->IsConsole())
fmt::format_to(std::back_inserter(out), "\r\n");
else
fmt::format_to(std::back_inserter(out), "^");
}
x++;
}
else if (zone_server_data->GetZoneID() != 0) {
if (zone_server_data->GetZoneID())
strcpy(zone_data_string, zone_server_data->GetZoneName());
else
zone_data_string[0] = 0;
fmt::format_to(std::back_inserter(out), " #{} {} {}", zone_server_data->GetID(), is_static_string, zone_data_string);
if (out.size() >= 3584) {
connection->SendEmoteMessageRaw(
to,
0,
AccountStatus::Player,
Chat::NPCQuestSay,
out.data()
);
out.clear();
}
else {
if (connection->IsConsole()) {
fmt::format_to(std::back_inserter(out), "\r\n");
}
else {
fmt::format_to(std::back_inserter(out), "^");
}
}
x++;
}
y++;
iterator++;
}
if (connection->IsConsole()) {
fmt::format_to(std::back_inserter(out), "{} servers listed. {} servers online.\r\n", x, y);
}
else {
fmt::format_to(std::back_inserter(out), "{} servers listed. {} servers online.^", x, y);
}
fmt::format_to(std::back_inserter(out), "{} zones are static zones, {} zones are booted zones, {} zones available.", z, w, v);
connection->SendEmoteMessageRaw(
to,
0,
AccountStatus::Player,
Chat::NPCQuestSay,
out.data()
);
}
void ZSList::SendChannelMessage(const char* from, const char* to, uint8 chan_num, uint8 language, const char* message, ...) {
if (!message)
return;
va_list argptr;
char buffer[1024];
va_start(argptr, message);
vsnprintf(buffer, sizeof(buffer), message, argptr);
va_end(argptr);
SendChannelMessageRaw(from, to, chan_num, language, buffer);
}
void ZSList::SendChannelMessageRaw(const char* from, const char* to, uint8 chan_num, uint8 language, const char* message) {
if (!message)
return;
auto pack = new ServerPacket;
pack->opcode = ServerOP_ChannelMessage;
pack->size = sizeof(ServerChannelMessage_Struct) + strlen(message) + 1;
pack->pBuffer = new uchar[pack->size];
memset(pack->pBuffer, 0, pack->size);
ServerChannelMessage_Struct* scm = (ServerChannelMessage_Struct*)pack->pBuffer;
if (from == 0) {
strcpy(scm->from, "WServer");
scm->noreply = true;
}
else if (from[0] == 0) {
strcpy(scm->from, "WServer");
scm->noreply = true;
}
else
strcpy(scm->from, from);
if (to != 0) {
strcpy((char *)scm->to, to);
strcpy((char *)scm->deliverto, to);
}
else {
scm->to[0] = 0;
scm->deliverto[0] = 0;
}
scm->language = language;
scm->lang_skill = 100;
scm->chan_num = chan_num;
strcpy(&scm->message[0], message);
SendPacket(pack);
delete pack;
}
void ZSList::SendEmoteMessage(const char* to, uint32 to_guilddbid, int16 to_minstatus, uint32 type, const char* message, ...) {
if (!message)
return;
va_list argptr;
char buffer[1024];
va_start(argptr, message);
vsnprintf(buffer, sizeof(buffer), message, argptr);
va_end(argptr);
SendEmoteMessageRaw(to, to_guilddbid, to_minstatus, type, buffer);
}
void ZSList::SendEmoteMessageRaw(const char* to, uint32 to_guilddbid, int16 to_minstatus, uint32 type, const char* message) {
if (!message)
return;
auto pack = new ServerPacket;
pack->opcode = ServerOP_EmoteMessage;
pack->size = sizeof(ServerEmoteMessage_Struct) + strlen(message) + 1;
pack->pBuffer = new uchar[pack->size];
memset(pack->pBuffer, 0, pack->size);
ServerEmoteMessage_Struct* sem = (ServerEmoteMessage_Struct*)pack->pBuffer;
if (to) {
strcpy((char *)sem->to, to);
}
else {
sem->to[0] = 0;
}
sem->guilddbid = to_guilddbid;
sem->minstatus = to_minstatus;
sem->type = type;
strcpy(&sem->message[0], message);
char tempto[64] = { 0 };
if (to)
strn0cpy(tempto, to, 64);
if (tempto[0] == 0) {
SendPacket(pack);
}
else {
ZoneServer* zs = FindByName(to);
if (zs != 0)
zs->SendPacket(pack);
else
SendPacket(pack);
}
delete pack;
}
void ZSList::SendTimeSync() {
auto pack = new ServerPacket(ServerOP_SyncWorldTime, sizeof(eqTimeOfDay));
eqTimeOfDay* tod = (eqTimeOfDay*)pack->pBuffer;
tod->start_eqtime = worldclock.getStartEQTime();
tod->start_realtime = worldclock.getStartRealTime();
SendPacket(pack);
delete pack;
}
void ZSList::NextGroupIDs(uint32 &start, uint32 &end) {
start = CurGroupID;
CurGroupID += 1000; //hand them out 1000 at a time...
if (CurGroupID < start) { //handle overflow
start = 1;
CurGroupID = 1001;
}
end = CurGroupID - 1;
}
void ZSList::SOPZoneBootup(const char* adminname, uint32 ZoneServerID, const char* zonename, bool iMakeStatic) {
ZoneServer* zs = 0;
ZoneServer* zs2 = 0;
uint32 zoneid;
if (!(zoneid = ZoneID(zonename))) {
SendEmoteMessage(
adminname,
0,
AccountStatus::Player,
Chat::White,
fmt::format(
"Error: SOP_ZoneBootup: Zone '{}' not found in 'zone' table.",
zonename
).c_str()
);
} else {
if (ZoneServerID != 0) {
zs = FindByID(ZoneServerID);
} else {
SendEmoteMessage(
adminname,
0,
AccountStatus::Player,
Chat::White,
"Error: SOP_ZoneBootup: Server ID must be specified."
);
}
if (!zs) {
SendEmoteMessage(
adminname,
0,
AccountStatus::Player,
Chat::White,
"Error: SOP_ZoneBootup: Zoneserver not found."
);
} else {
zs2 = FindByName(zonename);
if (zs2 != 0)
SendEmoteMessage(
adminname,
0,
AccountStatus::Player,
Chat::White,
fmt::format(
"Error: SOP_ZoneBootup: Zone '{}' already being hosted by Zoneserver ID {}.",
zonename,
zs2->GetID()
).c_str()
);
else {
zs->TriggerBootup(zoneid, 0, adminname, iMakeStatic);
}
}
}
}
void ZSList::RebootZone(const char* ip1, uint16 port, const char* ip2, uint32 skipid, uint32 zoneid) {
// get random zone
uint32 x = 0;
auto iterator = zone_server_list.begin();
while (iterator != zone_server_list.end()) {
x++;
iterator++;
}
if (x == 0)
return;
auto tmp = new ZoneServer *[x];
uint32 y = 0;
iterator = zone_server_list.begin();
while (iterator != zone_server_list.end()) {
if (!strcmp((*iterator)->GetCAddress(), ip2) && !(*iterator)->IsBootingUp() && (*iterator)->GetID() != skipid) {
tmp[y++] = (*iterator).get();
}
iterator++;
}
if (y == 0) {
safe_delete_array(tmp);
return;
}
uint32 z = emu_random.Int(0, y - 1);
auto pack = new ServerPacket(ServerOP_ZoneReboot, sizeof(ServerZoneReboot_Struct));
ServerZoneReboot_Struct* s = (ServerZoneReboot_Struct*)pack->pBuffer;
// strcpy(s->ip1,ip1);
strcpy(s->ip2, ip2);
s->port = port;
s->zoneid = zoneid;
if (zoneid != 0)
LogInfo("Rebooting static zone with the ID of: [{}]", zoneid);
tmp[z]->SendPacket(pack);
delete pack;
safe_delete_array(tmp);
}
uint16 ZSList::GetAvailableZonePort()
{
if (m_ports_free.empty()) {
return 0;
}
auto first = m_ports_free.front();
m_ports_free.pop_front();
return first;
}
uint32 ZSList::TriggerBootup(uint32 iZoneID, uint32 iInstanceID) {
if (iInstanceID > 0)
{
auto iterator = zone_server_list.begin();
while (iterator != zone_server_list.end()) {
if ((*iterator)->GetInstanceID() == iInstanceID)
{
return (*iterator)->GetID();
}
iterator++;
}
iterator = zone_server_list.begin();
while (iterator != zone_server_list.end()) {
if ((*iterator)->GetZoneID() == 0 && !(*iterator)->IsBootingUp()) {
ZoneServer* zone = (*iterator).get();
zone->TriggerBootup(iZoneID, iInstanceID);
return zone->GetID();
}
iterator++;
}
return 0;
}
else
{
auto iterator = zone_server_list.begin();
while (iterator != zone_server_list.end()) {
if ((*iterator)->GetZoneID() == iZoneID && (*iterator)->GetInstanceID() == 0)
{
return (*iterator)->GetID();
}
iterator++;
}
iterator = zone_server_list.begin();
while (iterator != zone_server_list.end()) {
if ((*iterator)->GetZoneID() == 0 && !(*iterator)->IsBootingUp()) {
ZoneServer* zone = (*iterator).get();
zone->TriggerBootup(iZoneID);
return zone->GetID();
}
iterator++;
}
return 0;
}
}
void ZSList::SendLSZones() {
auto iterator = zone_server_list.begin();
while (iterator != zone_server_list.end()) {
ZoneServer* zs = (*iterator).get();
zs->LSBootUpdate(zs->GetZoneID(), true);
iterator++;
}
}
int ZSList::GetZoneCount() {
return(zone_server_list.size());
}
void ZSList::GetZoneIDList(std::vector<uint32> &zones) {
auto iterator = zone_server_list.begin();
while (iterator != zone_server_list.end()) {
ZoneServer* zs = (*iterator).get();
zones.push_back(zs->GetID());
iterator++;
}
}
void ZSList::UpdateUCSServerAvailable(bool ucss_available) {
UCSServerAvailable_ = ucss_available;
auto outapp = new ServerPacket(ServerOP_UCSServerStatusReply, sizeof(UCSServerStatus_Struct));
auto ucsss = (UCSServerStatus_Struct*)outapp->pBuffer;
ucsss->available = (ucss_available ? 1 : 0);
ucsss->timestamp = Timer::GetCurrentTime();
SendPacket(outapp);
safe_delete(outapp);
}
void ZSList::WorldShutDown(uint32 time, uint32 interval)
{
if (time > 0) {
SendEmoteMessage(
0,
0,
AccountStatus::Player,
Chat::System,
fmt::format(
"[SYSTEM] World will be shutting down in {} minutes.",
(time / 60)
).c_str()
);
time *= 1000;
interval *= 1000;
if (interval < 5000) { interval = 5000; }
shutdowntimer->SetTimer(time);
reminder->SetTimer(interval - 1000);
reminder->SetAtTrigger(interval);
shutdowntimer->Start();
reminder->Start();
}
else {
SendEmoteMessage(
0,
0,
AccountStatus::Player,
Chat::Yellow,
"[SYSTEM] World is shutting down."
);
auto pack = new ServerPacket;
pack->opcode = ServerOP_ShutdownAll;
pack->size = 0;
SendPacket(pack);
safe_delete(pack);
Process();
CatchSignal(2);
}
}
void ZSList::DropClient(uint32 lsid, ZoneServer *ignore_zoneserver) {
ServerPacket packet(ServerOP_DropClient, sizeof(ServerZoneDropClient_Struct));
auto drop = (ServerZoneDropClient_Struct*)packet.pBuffer;
drop->lsid = lsid;
for (auto &zs : zone_server_list) {
if (zs.get() != ignore_zoneserver) {
zs->SendPacket(&packet);
}
}
}
void ZSList::OnTick(EQ::Timer *t)
{
if (!EventSubscriptionWatcher::Get()->IsSubscribed("EQW::ZoneUpdate")) {
return;
}
Json::Value out;
out["event"] = "EQW::ZoneUpdate";
out["data"] = Json::Value();
for (auto &zone : zone_server_list)
{
Json::Value outzone;
outzone["CAddress"] = zone->GetCAddress();
outzone["CLocalAddress"] = zone->GetCLocalAddress();
outzone["CompileTime"] = zone->GetCompileTime();
outzone["CPort"] = zone->GetCPort();
outzone["ID"] = zone->GetID();
outzone["InstanceID"] = zone->GetInstanceID();
outzone["IP"] = zone->GetIP();
outzone["LaunchedName"] = zone->GetLaunchedName();
outzone["LaunchName"] = zone->GetLaunchName();
outzone["Port"] = zone->GetPort();
outzone["PrevZoneID"] = zone->GetPrevZoneID();
outzone["UUID"] = zone->GetUUID();
outzone["ZoneID"] = zone->GetZoneID();
outzone["ZoneLongName"] = zone->GetZoneLongName();
outzone["ZoneName"] = zone->GetZoneName();
outzone["ZoneOSProcessID"] = zone->GetZoneOSProcessID();
outzone["NumPlayers"] = zone->NumPlayers();
outzone["BootingUp"] = zone->IsBootingUp();
outzone["StaticZone"] = zone->IsStaticZone();
out["data"].append(outzone);
}
web_interface.SendEvent(out);
}
void ZSList::OnKeepAlive(EQ::Timer *t)
{
for (auto &zone : zone_server_list) {
zone->SendKeepAlive();
}
}
const std::list<std::unique_ptr<ZoneServer>> &ZSList::getZoneServerList() const
{
return zone_server_list;
}
bool ZSList::SendPacketToBootedZones(ServerPacket* pack)
{
for (auto const& z : zone_server_list) {
auto r = z.get();
if (r && r->GetZoneID() > 0) {
r->SendPacket(pack);
}
}
return true;
}