1
0
EQ2Emu/source/WorldServer/Web/HTTPSClientPool.h
Emagi 315ab1d0e7 Project Nebulark Part 1, So much to list, this is a rough summary
- Raid support and cross peer support for Isle of Refuge, DoF, KoS and AoM clients.
- Zone Persistence added to non-instanced zones.
- Commands: /whogroup, /whoraid, /raidinvite, /raid_looter, /kickfromgroup, /kickfromraid, /leaveraid, /split, /raidsay (rsay) added.
- Cross peer zone and instance support
- Cross tell support (along with ignore)
- Cross ooc support
- Cross group support (can chat, leave group, disband cross peers, update group options)
- Cross who all support
- houses/instances fixed no more cross objects/spawns/etc from other houses
- houses now display characters name with the house zone description
- 1000's of house items now properly work with wall/ceiling
- debug messages removed from housing placement
- Encounters locked to raid instead of group
- group options restricted to raid leader
- reload rules for following are peer wide:
COMMAND_RELOADSTRUCTS
COMMAND_RELOAD_QUESTS
COMMAND_RELOAD_SPELLS
COMMAND_RELOAD_ZONESCRIPTS
COMMAND_RELOAD_FACTIONS
COMMAND_RELOAD_MAIL
COMMAND_RELOAD_GUILDS
COMMAND_RELOAD_RULES
COMMAND_RELOAD_STARTABILITIES
COMMAND_RELOAD_VOICEOVERS
COMMAND_RELOADSPAWNSCRIPTS
COMMAND_RELOADREGIONSCRIPTS
COMMAND_RELOADLUASYSTEM
- special/static zones (always_loaded) are now defined by a peer_priority unsigned short (smallint(5)) in zones table.  peer_priority = server_config world.peerpriority will spawn on that exe instance, if it is not available it is distributed to all peers.  Using the value of 0 (assuming no peer has priority of 0) or 65535 will result in peer distribution of zones.
server_config.json "WorldServer" block updated with the following (web peer port information), priority must be unique for EACH peer:
        "peeraddress": "10.1.1.2",
        "peerport": "9102",
        "peerpriority": "1",

New Command Line Run Arguments for World Exe to override server_config.json values
Allowed options:
  --worldaddress arg         World address
  --internalworldaddress arg Internal world address
  --worldport arg (=0)       Web world port
  --webworldaddress arg      Web world address
  --webworldport arg (=0)    Web world port
  --peerpriority arg (=0)    Peer priority

- fixed Isle of Refuge client group struct (raids added also)
- new log category Peering
- new LUA Functions AddRespawn(Zone, LocationID, RespawnTime) and CreatePersistedRespawn(LocationID, SpawnType, RespawnTime, ZoneID)
2024-11-18 11:13:04 -05:00

93 lines
3.6 KiB
C++

/*
EQ2Emu: Everquest II Server Emulator
Copyright (C) 2007-2025 EQ2Emu Development Team (https://www.eq2emu.com)
This file is part of EQ2Emu.
EQ2Emu 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, either version 3 of the License, or
(at your option) any later version.
EQ2Emu is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; 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 EQ2Emu. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef HTTPSCLIENTPOOL_H
#define HTTPSCLIENTPOOL_H
#include "HTTPSClient.h"
#include <unordered_map>
#include <string>
#include <memory>
#include <thread>
#include <chrono>
#include <atomic>
#include <queue>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <vector>
#include <boost/property_tree/ptree.hpp> // Include Boost property tree
struct pair_hash {
template <class T1, class T2>
std::size_t operator()(const std::pair<T1, T2>& pair) const {
return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
}
};
class HTTPSClientPool {
public:
HTTPSClientPool();
~HTTPSClientPool();
// init cert and key file
void init(const std::string& cert, const std::string& key);
// Pre-authenticate and add a client to the pool
void addPeerClient(const std::string& peerId, const std::string& server, const std::string& port, const std::string& authEndpoint);
std::shared_ptr<HTTPSClient> getOrCreateClient(const std::string& id, const std::string& server, const std::string& port);
// Send a request to a peer by ID and parse response as a ptree
boost::property_tree::ptree sendRequestToPeer(const std::string& peerId, const std::string& target);
boost::property_tree::ptree sendPostRequestToPeer(const std::string& peerId, const std::string& target, const std::string& jsonPayload);
void pollPeerHealthData(auto client, const std::string& id, const std::string& server, const std::string& port);
void startPolling(); // Starts asynchronous polling of peers
void stopPolling(); // Stops the polling process
// Sends a POST request asynchronously by adding it to the task queue
void sendPostRequestToPeerAsync(const std::string& peerId, const std::string& server, const std::string& port, const std::string& target, const std::string& payload);
// Worker thread function
void workerFunction();
bool isPolling() { return running; }
private:
std::shared_ptr<HTTPSClient> getClient(const std::string& peerId);
std::unordered_map<std::pair<std::string, std::string>, std::shared_ptr<HTTPSClient>, pair_hash> clients;
std::unordered_map<std::string, std::shared_ptr<HTTPSClient>> clientsById; // New map for ID-based lookup
std::string certFile;
std::string keyFile;
int pollingInterval; // Polling interval in milliseconds
std::queue<std::function<void()>> taskQueue; // Queue of tasks to execute
std::mutex queueMutex; // Mutex to protect access to the task queue
std::condition_variable condition; // Condition variable to signal worker threads
std::vector<std::thread> workers; // Worker threads
bool stop = false; // Flag to stop workers
std::atomic<bool> running; // Flag to control polling loop
void pollPeerHealth(const std::string& server, const std::string& port); // Polls individual peer
};
#endif // HTTPSCLIENTPOOL_H