2021-12-05 17:54:36 +00:00
|
|
|
#pragma once
|
|
|
|
#include <string>
|
2024-01-02 03:50:00 +00:00
|
|
|
#include <csignal>
|
2024-10-13 20:42:59 +00:00
|
|
|
#include <memory>
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-10-13 20:42:59 +00:00
|
|
|
#include "TransportLayer.h"
|
2024-01-06 08:16:10 +00:00
|
|
|
|
2024-10-13 20:42:59 +00:00
|
|
|
enum class TransportType : uint32_t {
|
|
|
|
RakNet,
|
|
|
|
Tcp
|
|
|
|
};
|
2024-01-02 03:50:00 +00:00
|
|
|
|
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,
|
2024-10-13 20:42:59 +00:00
|
|
|
unsigned int zoneID = 0
|
|
|
|
);
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
~dServer();
|
|
|
|
|
|
|
|
Packet* ReceiveFromMaster();
|
2024-10-13 20:42:59 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
Packet* Receive();
|
2024-10-13 20:42:59 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
void DeallocatePacket(Packet* packet);
|
2024-10-13 20:42:59 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
void DeallocateMasterPacket(Packet* packet);
|
2024-10-13 20:42:59 +00:00
|
|
|
|
2024-02-27 05:43:33 +00:00
|
|
|
virtual void Send(RakNet::BitStream& bitStream, const SystemAddress& sysAddr, bool broadcast);
|
2024-10-13 20:42:59 +00:00
|
|
|
|
2024-02-27 05:43:33 +00:00
|
|
|
void SendToMaster(RakNet::BitStream& bitStream);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
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);
|
2024-10-13 20:42:59 +00:00
|
|
|
|
|
|
|
const std::string& GetIP() const;
|
|
|
|
|
|
|
|
const int GetPort() const;
|
|
|
|
|
|
|
|
const int GetMaxConnections() const;
|
|
|
|
|
|
|
|
const bool GetIsEncrypted() const;
|
|
|
|
|
|
|
|
const bool GetIsInternal() const;
|
|
|
|
|
|
|
|
const bool GetIsOkay() const;
|
|
|
|
|
|
|
|
Logger* GetLogger() const;
|
|
|
|
|
|
|
|
const bool GetIsConnectedToMaster() const;
|
|
|
|
|
|
|
|
const unsigned int GetZoneID() const;
|
|
|
|
|
|
|
|
const int GetInstanceID() const;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
int GetPing(const SystemAddress& sysAddr) const;
|
2024-10-13 20:42:59 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
int GetLatestPing(const SystemAddress& sysAddr) const;
|
|
|
|
|
2024-10-13 20:42:59 +00:00
|
|
|
const ServerType GetServerType() const;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-10-13 20:42:59 +00:00
|
|
|
/**
|
|
|
|
* @brief Gets the transport layer.
|
|
|
|
*
|
|
|
|
* @return The TransportLayer instance.
|
|
|
|
*/
|
|
|
|
const std::unique_ptr<TransportLayer>& GetTransportLayer() const;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-10-13 20:42:59 +00:00
|
|
|
/**
|
|
|
|
* @brief Gets the transport type.
|
|
|
|
*
|
|
|
|
* @return The transport type.
|
|
|
|
*/
|
|
|
|
const TransportType GetTransportType() const;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-10-13 20:42:59 +00:00
|
|
|
/**
|
|
|
|
* Implicit conversion to TransportLayer*.
|
|
|
|
*/
|
|
|
|
operator TransportLayer*() const {
|
|
|
|
return m_TransportLayer.get();
|
|
|
|
}
|
2022-12-15 12:02:38 +00:00
|
|
|
|
|
|
|
/**
|
2024-10-13 20:42:59 +00:00
|
|
|
* @brief Get pointer to the TransportLayer.
|
|
|
|
*
|
|
|
|
* @return Pointer to the TransportLayer.
|
2022-12-15 12:02:38 +00:00
|
|
|
*/
|
2024-10-13 20:42:59 +00:00
|
|
|
TransportLayer* GetTransportLayerPtr() const {
|
|
|
|
return m_TransportLayer.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
TransportType m_TransportType;
|
|
|
|
|
|
|
|
std::unique_ptr<TransportLayer> m_TransportLayer;
|
2021-12-05 17:54:36 +00:00
|
|
|
};
|