implement server and client player join/leave notifications
This commit is contained in:
9
include/blitz/common/Types.h
Normal file
9
include/blitz/common/Types.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace blitz {
|
||||
|
||||
using EntityID = std::uint32_t;
|
||||
|
||||
} // namespace blitz
|
||||
13
include/blitz/components/PlayerInfo.h
Normal file
13
include/blitz/components/PlayerInfo.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <blitz/common/Types.h>
|
||||
#include <string>
|
||||
|
||||
namespace blitz {
|
||||
|
||||
struct PlayerInfoComponent {
|
||||
EntityID m_PlayerId;
|
||||
std::string m_Pseudo;
|
||||
};
|
||||
|
||||
} // namespace blitz
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <blitz/components/PlayerInfo.h>
|
||||
#include <vector>
|
||||
|
||||
namespace blitz {
|
||||
namespace protocol {
|
||||
@@ -14,17 +15,25 @@ struct UpdateHealth {
|
||||
float m_NewHealth;
|
||||
};
|
||||
|
||||
struct LoggingSuccess {};
|
||||
struct LoggingSuccess {
|
||||
EntityID m_PlayerId;
|
||||
};
|
||||
|
||||
struct PlayerDeath {};
|
||||
|
||||
struct PlayerJoin {};
|
||||
struct PlayerJoin {
|
||||
PlayerInfoComponent m_Player;
|
||||
};
|
||||
|
||||
struct PlayerLeave {};
|
||||
struct PlayerLeave {
|
||||
EntityID m_PlayerId;
|
||||
};
|
||||
|
||||
struct PlayerStats {};
|
||||
|
||||
struct PlayerList {};
|
||||
struct PlayerList {
|
||||
std::vector<PlayerInfoComponent> m_Players;
|
||||
};
|
||||
|
||||
struct ServerConfig {};
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace client {
|
||||
|
||||
class Client : private NonCopyable {
|
||||
public:
|
||||
Client();
|
||||
Client(std::shared_ptr<Nz::EnttWorld> a_World);
|
||||
~Client();
|
||||
|
||||
void Connect(const Nz::IpAddress& a_Ip);
|
||||
@@ -25,6 +25,7 @@ class Client : private NonCopyable {
|
||||
|
||||
void BindHandlers();
|
||||
void UnbindHandlers();
|
||||
void Login();
|
||||
};
|
||||
|
||||
} // namespace client
|
||||
|
||||
13
include/client/components/LocalPlayer.h
Normal file
13
include/client/components/LocalPlayer.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <blitz/common/Types.h>
|
||||
|
||||
namespace blitz {
|
||||
namespace client {
|
||||
|
||||
struct LocalPlayerComponent {
|
||||
EntityID m_LocalPlayerId;
|
||||
};
|
||||
|
||||
} // namespace client
|
||||
} // namespace blitz
|
||||
@@ -9,6 +9,9 @@ class KeepAliveHandler : public protocol::PacketHandler {
|
||||
~KeepAliveHandler();
|
||||
|
||||
NazaraSlot(network::EnetConnection, OnKeepAlive, m_Slot);
|
||||
|
||||
private:
|
||||
void Handle(const protocol::data::KeepAlive&);
|
||||
};
|
||||
|
||||
} // namespace client
|
||||
|
||||
18
include/client/handlers/LoggingSuccessHandler.h
Normal file
18
include/client/handlers/LoggingSuccessHandler.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <blitz/protocol/PacketHandler.h>
|
||||
|
||||
namespace blitz {
|
||||
namespace client {
|
||||
|
||||
class LoggingSuccessHandler : public protocol::PacketHandler {
|
||||
public:
|
||||
LoggingSuccessHandler(network::EnetConnection& a_Connection, EnttWorld& a_World);
|
||||
~LoggingSuccessHandler();
|
||||
|
||||
NazaraSlot(network::EnetConnection, OnLoggingSuccess, m_Slot);
|
||||
|
||||
private:
|
||||
void Handle(const protocol::data::LoggingSuccess&);
|
||||
};
|
||||
|
||||
} // namespace client
|
||||
} // namespace blitz
|
||||
18
include/client/handlers/PlayerJoinHandler.h
Normal file
18
include/client/handlers/PlayerJoinHandler.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <blitz/protocol/PacketHandler.h>
|
||||
|
||||
namespace blitz {
|
||||
namespace client {
|
||||
|
||||
class PlayerJoinHandler : public protocol::PacketHandler {
|
||||
public:
|
||||
PlayerJoinHandler(network::EnetConnection& a_Connection, EnttWorld& a_World);
|
||||
~PlayerJoinHandler();
|
||||
|
||||
NazaraSlot(network::EnetConnection, OnPlayerJoin, m_Slot);
|
||||
|
||||
private:
|
||||
void Handle(const protocol::data::PlayerJoin&);
|
||||
};
|
||||
|
||||
} // namespace client
|
||||
} // namespace blitz
|
||||
18
include/client/handlers/PlayerLeaveHandler.h
Normal file
18
include/client/handlers/PlayerLeaveHandler.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <blitz/protocol/PacketHandler.h>
|
||||
|
||||
namespace blitz {
|
||||
namespace client {
|
||||
|
||||
class PlayerLeaveHandler : public protocol::PacketHandler {
|
||||
public:
|
||||
PlayerLeaveHandler(network::EnetConnection& a_Connection, EnttWorld& a_World);
|
||||
~PlayerLeaveHandler();
|
||||
|
||||
NazaraSlot(network::EnetConnection, OnPlayerLeave, m_Slot);
|
||||
|
||||
private:
|
||||
void Handle(const protocol::data::PlayerLeave&);
|
||||
};
|
||||
|
||||
} // namespace client
|
||||
} // namespace blitz
|
||||
18
include/client/handlers/PlayerListHandler.h
Normal file
18
include/client/handlers/PlayerListHandler.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <blitz/protocol/PacketHandler.h>
|
||||
|
||||
namespace blitz {
|
||||
namespace client {
|
||||
|
||||
class PlayerListHandler : public protocol::PacketHandler {
|
||||
public:
|
||||
PlayerListHandler(network::EnetConnection& a_Connection, EnttWorld& a_World);
|
||||
~PlayerListHandler();
|
||||
|
||||
NazaraSlot(network::EnetConnection, OnPlayerList, m_Slot);
|
||||
|
||||
private:
|
||||
void Handle(const protocol::data::PlayerList&);
|
||||
};
|
||||
|
||||
} // namespace client
|
||||
} // namespace blitz
|
||||
@@ -8,6 +8,10 @@ namespace server {
|
||||
|
||||
class Server {
|
||||
public:
|
||||
/**
|
||||
* \brief Construct a server
|
||||
* \pre Two instances of Server should not share the same world
|
||||
*/
|
||||
Server(std::uint16_t a_Port, std::shared_ptr<Nz::EnttWorld> a_World);
|
||||
~Server();
|
||||
|
||||
|
||||
13
include/server/components/ServerIdCounter.h
Normal file
13
include/server/components/ServerIdCounter.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <blitz/common/Types.h>
|
||||
|
||||
namespace blitz {
|
||||
namespace server {
|
||||
|
||||
struct ServerIdCounterComponent {
|
||||
EntityID m_NextEntityId;
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
} // namespace blitz
|
||||
20
include/server/handlers/PlayerLoginHandler.h
Normal file
20
include/server/handlers/PlayerLoginHandler.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <blitz/protocol/PacketHandler.h>
|
||||
|
||||
namespace blitz {
|
||||
namespace server {
|
||||
|
||||
class PlayerLoginHandler : public protocol::PacketHandler {
|
||||
public:
|
||||
PlayerLoginHandler(network::EnetConnection& a_Connection, EnttWorld& a_World);
|
||||
~PlayerLoginHandler();
|
||||
|
||||
NazaraSlot(network::EnetConnection, OnPlayerLogin, m_Slot);
|
||||
|
||||
private:
|
||||
void Handle(std::uint16_t, const protocol::data::PlayerLogin&);
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
} // namespace blitz
|
||||
Reference in New Issue
Block a user