fully implement KeepAlive behavior
This commit is contained in:
37
include/server/Server.h
Normal file
37
include/server/Server.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <blitz/network/EnetServer.h>
|
||||
#include <blitz/protocol/PacketHandler.h>
|
||||
|
||||
namespace blitz {
|
||||
namespace server {
|
||||
|
||||
class Server {
|
||||
public:
|
||||
Server(std::uint16_t a_Port, std::shared_ptr<Nz::EnttWorld> a_World);
|
||||
~Server();
|
||||
|
||||
network::EnetConnection* GetConnection(std::uint16_t a_PeerId);
|
||||
|
||||
void CloseConnection(std::uint16_t a_PeerId);
|
||||
|
||||
private:
|
||||
void HandleConnect(network::EnetConnection&);
|
||||
void HandleDisconnect(network::EnetConnection&);
|
||||
|
||||
struct Session {
|
||||
network::EnetConnection* m_Connection;
|
||||
std::vector<std::unique_ptr<protocol::PacketHandler>> m_Handlers;
|
||||
};
|
||||
|
||||
EnttWorld m_World;
|
||||
std::map<std::uint16_t, Session> m_Sessions;
|
||||
network::EnetServer m_NetworkServer;
|
||||
|
||||
void RegisterHandlers(Session& session);
|
||||
void RegisterSystems();
|
||||
void CreateEntity(network::EnetConnection&);
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
} // namespace blitz
|
||||
13
include/server/components/Disconnect.h
Normal file
13
include/server/components/Disconnect.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
namespace blitz {
|
||||
namespace server {
|
||||
|
||||
enum Reason { Timeout };
|
||||
|
||||
struct DisconnectComponent {
|
||||
Reason m_Reason;
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
} // namespace blitz
|
||||
13
include/server/components/EnetConnection.h
Normal file
13
include/server/components/EnetConnection.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <blitz/network/EnetConnection.h>
|
||||
|
||||
namespace blitz {
|
||||
namespace server {
|
||||
|
||||
struct EnetConnectionComponent {
|
||||
network::EnetConnection* m_Connection;
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
} // namespace blitz
|
||||
17
include/server/components/KeepAliveSession.h
Normal file
17
include/server/components/KeepAliveSession.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
#include <cstdint>
|
||||
|
||||
namespace blitz {
|
||||
namespace server {
|
||||
|
||||
struct KeepAliveSessionComponent {
|
||||
std::uint16_t m_PeerId;
|
||||
std::uint64_t m_LastKeepAliveId;
|
||||
Nz::Time m_LastTime;
|
||||
bool m_RecievedResponse = false;
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
} // namespace blitz
|
||||
20
include/server/handlers/KeepAliveHandler.h
Normal file
20
include/server/handlers/KeepAliveHandler.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <blitz/protocol/PacketHandler.h>
|
||||
|
||||
namespace blitz {
|
||||
namespace server {
|
||||
|
||||
class KeepAliveHandler : public protocol::PacketHandler {
|
||||
public:
|
||||
KeepAliveHandler(network::EnetConnection& a_Connection, EnttWorld& a_World);
|
||||
~KeepAliveHandler();
|
||||
|
||||
NazaraSlot(network::EnetConnection, OnKeepAlive, m_Slot);
|
||||
|
||||
private:
|
||||
void Handle(std::uint16_t, const protocol::data::KeepAlive&);
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
} // namespace blitz
|
||||
23
include/server/systems/DisconnectSystem.h
Normal file
23
include/server/systems/DisconnectSystem.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
#include <entt/entity/registry.hpp>
|
||||
|
||||
namespace blitz {
|
||||
namespace server {
|
||||
|
||||
class Server;
|
||||
|
||||
class DisconectSystem {
|
||||
public:
|
||||
DisconectSystem(entt::registry& a_Registry, Server& a_Server);
|
||||
|
||||
void Update(Nz::Time elapsedTime);
|
||||
|
||||
private:
|
||||
entt::registry& m_Registry;
|
||||
Server& m_Server;
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
} // namespace blitz
|
||||
20
include/server/systems/KeepAliveSystem.h
Normal file
20
include/server/systems/KeepAliveSystem.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
#include <entt/entity/registry.hpp>
|
||||
|
||||
namespace blitz {
|
||||
namespace server {
|
||||
|
||||
class KeepAliveSystem {
|
||||
public:
|
||||
KeepAliveSystem(entt::registry& a_Registry);
|
||||
|
||||
void Update(Nz::Time elapsedTime);
|
||||
|
||||
private:
|
||||
entt::registry& m_Registry;
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
} // namespace blitz
|
||||
Reference in New Issue
Block a user