Update
This commit is contained in:
@ -1,27 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "HLAPI/NetworkMessage.hpp"
|
||||
|
||||
namespace std::net
|
||||
{
|
||||
class DataReceivedEvent
|
||||
{
|
||||
public:
|
||||
inline DataReceivedEvent(const NetworkMessage &msg)
|
||||
{
|
||||
SenderID = msg.GetSenderID();
|
||||
DistributionMode = msg.GetDistributionMode();
|
||||
DestinationID = msg.GetDestinationID();
|
||||
Tag = msg.GetTag();
|
||||
Data = msg.GetData<void>();
|
||||
}
|
||||
|
||||
public:
|
||||
uint32_t SenderID;
|
||||
DistributionMode DistributionMode;
|
||||
uint32_t DestinationID;
|
||||
uint32_t Tag;
|
||||
|
||||
void *Data;
|
||||
};
|
||||
}
|
||||
@ -1,36 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace std::net
|
||||
{
|
||||
class DisconnectedEvent // can be processed by client and server
|
||||
{
|
||||
private:
|
||||
DisconnectedEvent();
|
||||
|
||||
public:
|
||||
inline DisconnectedEvent(uint32_t id, char *reason, int32_t reason_id)
|
||||
: m_reason(reason)
|
||||
, m_clientID(id)
|
||||
, m_reasonID(reason_id)
|
||||
{
|
||||
}
|
||||
|
||||
inline DisconnectedEvent(uint32_t id, const std::string &reason, int32_t reason_id)
|
||||
: m_reason(reason)
|
||||
, m_clientID(id)
|
||||
, m_reasonID(reason_id)
|
||||
{
|
||||
}
|
||||
|
||||
inline const std::string &GetReason() const { return m_reason; }
|
||||
inline int32_t GetReasonID() const { return m_reasonID; }
|
||||
inline uint32_t GetID() const { return m_clientID; }
|
||||
|
||||
private:
|
||||
std::string m_reason;
|
||||
int32_t m_reasonID;
|
||||
uint32_t m_clientID;
|
||||
};
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace std::net
|
||||
{
|
||||
class NewConnectionEvent
|
||||
{
|
||||
public:
|
||||
inline NewConnectionEvent(uint32_t id, void *data)
|
||||
: m_id(id)
|
||||
, m_data(data)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t m_id;
|
||||
void *m_data;
|
||||
};
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <VoidNet/Net.hpp>
|
||||
#include "HLAPI/ServerConfig.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@ -19,6 +20,9 @@ namespace std::net
|
||||
|
||||
void AddPlugin(Plugin* plugin);
|
||||
|
||||
public:
|
||||
ServerConfig Config;
|
||||
|
||||
private:
|
||||
std::shared_ptr<std::net::TcpServer> m_tcpServer;
|
||||
};
|
||||
|
||||
10
include/HLAPI/ServerConfig.hpp
Normal file
10
include/HLAPI/ServerConfig.hpp
Normal file
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
namespace std::net
|
||||
{
|
||||
class ServerConfig
|
||||
{
|
||||
public:
|
||||
bool BroadcastConnectionEvents;
|
||||
};
|
||||
}
|
||||
@ -13,23 +13,27 @@ namespace std::net
|
||||
public:
|
||||
friend class TcpConnectionHandler;
|
||||
|
||||
TcpConnection();
|
||||
TcpConnection(TcpClient *client);
|
||||
|
||||
std::shared_ptr<TcpClient> GetClient();
|
||||
uint32_t GetID();
|
||||
void SetID(uint32_t id);
|
||||
|
||||
bool Connect(IPAddress addr);
|
||||
|
||||
template<typename T>
|
||||
void SendMessage(DistributionMode mode, uint32_t destinationId, uint32_t tag, void *data)
|
||||
{
|
||||
NetworkMessage msg(m_id, mode, destinationId, tag, data, sizeof(T));
|
||||
sendMessage(msg);
|
||||
}
|
||||
|
||||
void ReceiveData();
|
||||
|
||||
std::function<void(uint32_t, DistributionMode, uint32_t, uint32_t, void*)> DataReceivedEvent;
|
||||
std::function<void(uint32_t, std::string, int32_t)> DisconnectedEvent;
|
||||
std::function<void(std::string)> DisconnectedEvent;
|
||||
std::function<void(uint32_t, void*)> NewConnectionEvent;
|
||||
std::function<void()> OnConnectionEvent;
|
||||
|
||||
private:
|
||||
bool sendMessage(const NetworkMessage &msg);
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include <VoidNet/TcpListener.hpp>
|
||||
#include <HLAPI/TcpConnection.hpp>
|
||||
#include <HLAPI/Plugin/PluginManager.hpp>
|
||||
#include <HLAPI/ServerConfig.hpp>
|
||||
|
||||
namespace std::net
|
||||
{
|
||||
@ -58,6 +59,8 @@ namespace std::net
|
||||
|
||||
std::shared_ptr<PluginManager> m_pluginManager;
|
||||
|
||||
std::vector<pollfd> poll_fds;
|
||||
std::vector<pollfd> m_pollFds;
|
||||
|
||||
ServerConfig m_config;
|
||||
};
|
||||
}
|
||||
@ -6,7 +6,9 @@
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#undef SendMessage
|
||||
#undef GetMessage
|
||||
#undef SetPort
|
||||
#undef GetPort
|
||||
#undef max
|
||||
#undef min
|
||||
|
||||
|
||||
Reference in New Issue
Block a user