2021-12-05 17:54:36 +00:00
|
|
|
#pragma once
|
|
|
|
#include <string>
|
2024-01-02 03:50:00 +00:00
|
|
|
#include <csignal>
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "RakPeerInterface.h"
|
|
|
|
#include "ReplicaManager.h"
|
|
|
|
#include "NetworkIDManager.h"
|
|
|
|
|
2023-10-21 23:31:55 +00:00
|
|
|
class Logger;
|
2022-12-06 00:08:47 +00:00
|
|
|
class dConfig;
|
2023-02-19 12:29:14 +00:00
|
|
|
enum class eServerDisconnectIdentifiers : uint32_t;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
enum class ServerType : uint32_t {
|
|
|
|
Master,
|
|
|
|
Auth,
|
|
|
|
Chat,
|
|
|
|
World
|
|
|
|
};
|
|
|
|
|
2024-01-02 03:50:00 +00:00
|
|
|
namespace Game {
|
|
|
|
using signal_t = volatile std::sig_atomic_t;
|
|
|
|
}
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
class dServer {
|
|
|
|
public:
|
2022-11-07 08:12:35 +00:00
|
|
|
// Default constructor should only used for testing!
|
|
|
|
dServer() {};
|
2022-12-15 12:02:38 +00:00
|
|
|
dServer(
|
|
|
|
const std::string& ip,
|
|
|
|
int port,
|
|
|
|
int instanceID,
|
|
|
|
int maxConnections,
|
|
|
|
bool isInternal,
|
|
|
|
bool useEncryption,
|
2023-10-21 23:31:55 +00:00
|
|
|
Logger* logger,
|
2022-12-15 12:02:38 +00:00
|
|
|
const std::string masterIP,
|
|
|
|
int masterPort,
|
|
|
|
ServerType serverType,
|
|
|
|
dConfig* config,
|
2024-01-02 03:50:00 +00:00
|
|
|
Game::signal_t* shouldShutdown,
|
2022-12-15 12:02:38 +00:00
|
|
|
unsigned int zoneID = 0);
|
2021-12-05 17:54:36 +00:00
|
|
|
~dServer();
|
|
|
|
|
|
|
|
Packet* ReceiveFromMaster();
|
|
|
|
Packet* Receive();
|
|
|
|
void DeallocatePacket(Packet* packet);
|
|
|
|
void DeallocateMasterPacket(Packet* packet);
|
2022-11-07 08:12:35 +00:00
|
|
|
virtual void Send(RakNet::BitStream* bitStream, const SystemAddress& sysAddr, bool broadcast);
|
2021-12-05 17:54:36 +00:00
|
|
|
void SendToMaster(RakNet::BitStream* bitStream);
|
|
|
|
|
2023-02-19 12:29:14 +00:00
|
|
|
void Disconnect(const SystemAddress& sysAddr, eServerDisconnectIdentifiers disconNotifyID);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
bool IsConnected(const SystemAddress& sysAddr);
|
|
|
|
const std::string& GetIP() const { return mIP; }
|
|
|
|
const int GetPort() const { return mPort; }
|
|
|
|
const int GetMaxConnections() const { return mMaxConnections; }
|
|
|
|
const bool GetIsEncrypted() const { return mUseEncryption; }
|
|
|
|
const bool GetIsInternal() const { return mIsInternal; }
|
|
|
|
const bool GetIsOkay() const { return mIsOkay; }
|
2023-10-21 23:31:55 +00:00
|
|
|
Logger* GetLogger() const { return mLogger; }
|
2021-12-05 17:54:36 +00:00
|
|
|
const bool GetIsConnectedToMaster() const { return mMasterConnectionActive; }
|
|
|
|
const unsigned int GetZoneID() const { return mZoneID; }
|
|
|
|
const int GetInstanceID() const { return mInstanceID; }
|
|
|
|
ReplicaManager* GetReplicaManager() { return mReplicaManager; }
|
|
|
|
void UpdateReplica();
|
2022-12-06 00:08:47 +00:00
|
|
|
void UpdateBandwidthLimit();
|
2022-12-21 16:51:27 +00:00
|
|
|
void UpdateMaximumMtuSize();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
int GetPing(const SystemAddress& sysAddr) const;
|
|
|
|
int GetLatestPing(const SystemAddress& sysAddr) const;
|
|
|
|
|
|
|
|
NetworkIDManager* GetNetworkIDManager() { return mNetIDManager; }
|
|
|
|
|
|
|
|
const ServerType GetServerType() const { return mServerType; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool Startup();
|
|
|
|
void Shutdown();
|
|
|
|
void SetupForMasterConnection();
|
|
|
|
bool ConnectToMaster();
|
|
|
|
|
|
|
|
private:
|
2023-10-21 23:31:55 +00:00
|
|
|
Logger* mLogger = nullptr;
|
2022-12-06 00:08:47 +00:00
|
|
|
dConfig* mConfig = nullptr;
|
2022-11-07 08:12:35 +00:00
|
|
|
RakPeerInterface* mPeer = nullptr;
|
|
|
|
ReplicaManager* mReplicaManager = nullptr;
|
|
|
|
NetworkIDManager* mNetIDManager = nullptr;
|
2022-12-15 12:02:38 +00:00
|
|
|
|
|
|
|
/**
|
2024-01-02 03:50:00 +00:00
|
|
|
* Whether or not to shut down the server. Pointer to Game::lastSignal.
|
2022-12-15 12:02:38 +00:00
|
|
|
*/
|
2024-01-02 03:50:00 +00:00
|
|
|
Game::signal_t* mShouldShutdown = nullptr;
|
2021-12-05 17:54:36 +00:00
|
|
|
SocketDescriptor mSocketDescriptor;
|
|
|
|
std::string mIP;
|
2022-07-28 13:39:57 +00:00
|
|
|
int mPort;
|
2021-12-05 17:54:36 +00:00
|
|
|
int mMaxConnections;
|
|
|
|
unsigned int mZoneID;
|
|
|
|
int mInstanceID;
|
|
|
|
bool mUseEncryption;
|
|
|
|
bool mIsInternal;
|
|
|
|
bool mIsOkay;
|
|
|
|
bool mMasterConnectionActive;
|
|
|
|
ServerType mServerType;
|
|
|
|
|
2022-11-07 08:12:35 +00:00
|
|
|
RakPeerInterface* mMasterPeer = nullptr;
|
2021-12-05 17:54:36 +00:00
|
|
|
SocketDescriptor mMasterSocketDescriptor;
|
|
|
|
SystemAddress mMasterSystemAddress;
|
|
|
|
std::string mMasterIP;
|
|
|
|
int mMasterPort;
|
2022-07-28 13:39:57 +00:00
|
|
|
};
|