DarkflameServer/dNet/dServer.h

113 lines
2.9 KiB
C
Raw Normal View History

#pragma once
#include <string>
#include "RakPeerInterface.h"
#include "ReplicaManager.h"
#include "NetworkIDManager.h"
class dLogger;
2022-12-06 00:08:47 +00:00
class dConfig;
enum class eServerDisconnectIdentifiers : uint32_t;
enum class ServerType : uint32_t {
Master,
Auth,
Chat,
World
};
enum class ServiceId : uint32_t{
General = 0,
Auth = 1,
Chat = 2,
World = 4,
Client = 5,
};
class dServer {
public:
// 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,
dLogger* logger,
const std::string masterIP,
int masterPort,
ServerType serverType,
dConfig* config,
bool* shouldShutdown,
2022-12-15 12:02:38 +00:00
unsigned int zoneID = 0);
~dServer();
Packet* ReceiveFromMaster();
Packet* Receive();
void DeallocatePacket(Packet* packet);
void DeallocateMasterPacket(Packet* packet);
virtual void Send(RakNet::BitStream* bitStream, const SystemAddress& sysAddr, bool broadcast);
void SendToMaster(RakNet::BitStream* bitStream);
void Disconnect(const SystemAddress& sysAddr, eServerDisconnectIdentifiers disconNotifyID);
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; }
dLogger* GetLogger() const { return mLogger; }
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();
void UpdateMaximumMtuSize();
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:
dLogger* mLogger = nullptr;
2022-12-06 00:08:47 +00:00
dConfig* mConfig = nullptr;
RakPeerInterface* mPeer = nullptr;
ReplicaManager* mReplicaManager = nullptr;
NetworkIDManager* mNetIDManager = nullptr;
2022-12-15 12:02:38 +00:00
/**
* Whether or not to shut down the server. Pointer to Game::shouldShutdown.
*/
bool* mShouldShutdown = nullptr;
SocketDescriptor mSocketDescriptor;
std::string mIP;
2022-07-28 13:39:57 +00:00
int mPort;
int mMaxConnections;
unsigned int mZoneID;
int mInstanceID;
bool mUseEncryption;
bool mIsInternal;
bool mIsOkay;
bool mMasterConnectionActive;
ServerType mServerType;
RakPeerInterface* mMasterPeer = nullptr;
SocketDescriptor mMasterSocketDescriptor;
SystemAddress mMasterSystemAddress;
std::string mMasterIP;
int mMasterPort;
2022-07-28 13:39:57 +00:00
};