Compare commits
6 Commits
7abb31c2e1
...
d412871de5
| Author | SHA1 | Date | |
|---|---|---|---|
| d412871de5 | |||
| 072c13ca89 | |||
| 998dc7ea2e | |||
| 3eb3eadd4b | |||
| 159867e747 | |||
| f9f5f60049 |
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "doxygen/doxygen-awesome-css"]
|
||||||
|
path = doxygen/doxygen-awesome-css
|
||||||
|
url = https://github.com/jothepro/doxygen-awesome-css.git
|
||||||
21
doxygen/footer.html
Normal file
21
doxygen/footer.html
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<!-- HTML footer for doxygen 1.9.1-->
|
||||||
|
<!-- start footer part -->
|
||||||
|
<!--BEGIN GENERATE_TREEVIEW-->
|
||||||
|
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
||||||
|
<ul>
|
||||||
|
$navpath
|
||||||
|
<li class="footer">$generatedby <a href="https://www.doxygen.org/index.html"><img class="footer"
|
||||||
|
src="$relpath^doxygen.svg" width="104" height="31" alt="doxygen" /></a> $doxygenversion </li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<!--END GENERATE_TREEVIEW-->
|
||||||
|
<!--BEGIN !GENERATE_TREEVIEW-->
|
||||||
|
<hr class="footer" />
|
||||||
|
<address class="footer"><small>
|
||||||
|
$generatedby <a href="https://www.doxygen.org/index.html"><img class="footer" src="$relpath^doxygen.svg"
|
||||||
|
width="104" height="31" alt="doxygen" /></a> $doxygenversion
|
||||||
|
</small></address>
|
||||||
|
<!--END !GENERATE_TREEVIEW-->
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
66
doxygen/header.html
Normal file
66
doxygen/header.html
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<!-- HTML header for doxygen 1.9.1-->
|
||||||
|
<!DOCTYPE html
|
||||||
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8" />
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=9" />
|
||||||
|
<meta name="generator" content="Doxygen $doxygenversion" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<!--BEGIN PROJECT_NAME-->
|
||||||
|
<title>$projectname: $title</title><!--END PROJECT_NAME-->
|
||||||
|
<!--BEGIN !PROJECT_NAME-->
|
||||||
|
<title>$title</title><!--END !PROJECT_NAME-->
|
||||||
|
<link href="$relpath^tabs.css" rel="stylesheet" type="text/css" />
|
||||||
|
<script type="text/javascript" src="$relpath^jquery.js"></script>
|
||||||
|
<script type="text/javascript" src="$relpath^dynsections.js"></script>
|
||||||
|
$treeview
|
||||||
|
$search
|
||||||
|
$mathjax
|
||||||
|
<link href="$relpath^$stylesheet" rel="stylesheet" type="text/css" />
|
||||||
|
$extrastylesheet
|
||||||
|
<script type="text/javascript" src="$relpath^doxygen-awesome-darkmode-toggle.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
DoxygenAwesomeDarkModeToggle.init()
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
||||||
|
|
||||||
|
<!--BEGIN TITLEAREA-->
|
||||||
|
<div id="titlearea">
|
||||||
|
<table cellspacing="0" cellpadding="0">
|
||||||
|
<tbody>
|
||||||
|
<tr style="height: 56px;">
|
||||||
|
<!--BEGIN PROJECT_LOGO-->
|
||||||
|
<td id="projectlogo"><img alt="Logo" src="$relpath^$projectlogo" /></td>
|
||||||
|
<!--END PROJECT_LOGO-->
|
||||||
|
<!--BEGIN PROJECT_NAME-->
|
||||||
|
<td id="projectalign" style="padding-left: 0.5em;">
|
||||||
|
<div id="projectname">$projectname
|
||||||
|
<!--BEGIN PROJECT_NUMBER--> <span id="projectnumber">$projectnumber</span><!--END PROJECT_NUMBER-->
|
||||||
|
</div>
|
||||||
|
<!--BEGIN PROJECT_BRIEF-->
|
||||||
|
<div id="projectbrief">$projectbrief</div><!--END PROJECT_BRIEF-->
|
||||||
|
</td>
|
||||||
|
<!--END PROJECT_NAME-->
|
||||||
|
<!--BEGIN !PROJECT_NAME-->
|
||||||
|
<!--BEGIN PROJECT_BRIEF-->
|
||||||
|
<td style="padding-left: 0.5em;">
|
||||||
|
<div id="projectbrief">$projectbrief</div>
|
||||||
|
</td>
|
||||||
|
<!--END PROJECT_BRIEF-->
|
||||||
|
<!--END !PROJECT_NAME-->
|
||||||
|
<!--BEGIN DISABLE_INDEX-->
|
||||||
|
<!--BEGIN SEARCHENGINE-->
|
||||||
|
<td>$searchbox</td>
|
||||||
|
<!--END SEARCHENGINE-->
|
||||||
|
<!--END DISABLE_INDEX-->
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<!--END TITLEAREA-->
|
||||||
|
<!-- end header part -->
|
||||||
5
doxygen/stylesheet.css
Normal file
5
doxygen/stylesheet.css
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
/* The standard CSS for doxygen 1.9.1 */
|
||||||
|
|
||||||
|
body, table, div, p, dl {
|
||||||
|
font: 400 14px/22px Roboto,sans-serif;
|
||||||
|
}
|
||||||
@@ -1,8 +1,20 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Nazara/Network/ENetPeer.hpp>
|
/**
|
||||||
#include <blitz/protocol/PacketSerializer.h>
|
* \file EnetConnexion.h
|
||||||
#include <blitz/protocol/Packets.h>
|
* \brief File containing the blitz::network::EnetConnexion class
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Nazara/Core/ByteArray.hpp>
|
||||||
|
#include <NazaraUtils/Signal.hpp>
|
||||||
|
#include <blitz/protocol/PacketData.h>
|
||||||
|
#include <blitz/protocol/PacketDeclare.h>
|
||||||
|
|
||||||
|
namespace Nz {
|
||||||
|
|
||||||
|
class ENetPeer;
|
||||||
|
|
||||||
|
} // namespace Nz
|
||||||
|
|
||||||
namespace blitz {
|
namespace blitz {
|
||||||
namespace network {
|
namespace network {
|
||||||
@@ -12,11 +24,11 @@ class EnetServer;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define DeclarePacket(Name, NFlag) \
|
#define DeclarePacket(PacketName, ...) \
|
||||||
void Send##Name(const blitz::protocol::data::Name& a_##Name) const { \
|
/** Sends a PacketName over the network */ \
|
||||||
m_Peer->Send(0, NFlag, protocol::PacketSerializer::Serialize(protocol::packets::Name(a_##Name))); \
|
void Send##PacketName(const blitz::protocol::data::PacketName& a_##PacketName) const; \
|
||||||
} \
|
/** Use On##PacketName.Connect() to process a PacketName incoming from network */ \
|
||||||
NazaraSignal(On##Name, const blitz::protocol::data::Name&)
|
NazaraSignal(On##PacketName, const blitz::protocol::data::PacketName&);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -26,22 +38,18 @@ class EnetConnexion {
|
|||||||
public:
|
public:
|
||||||
EnetConnexion(Nz::ENetPeer* a_Peer = nullptr);
|
EnetConnexion(Nz::ENetPeer* a_Peer = nullptr);
|
||||||
|
|
||||||
bool IsConnected() const {
|
bool IsConnected() const;
|
||||||
if (!m_Peer)
|
|
||||||
return false;
|
|
||||||
return m_Peer->IsConnected();
|
|
||||||
}
|
|
||||||
|
|
||||||
DeclareAllPacket()
|
DeclareAllPacket();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Nz::ENetPeer* m_Peer;
|
Nz::ENetPeer* m_Peer;
|
||||||
|
|
||||||
void Recieve(Nz::ByteArray&);
|
void Recieve(Nz::ByteArray&);
|
||||||
void SetPeer(Nz::ENetPeer* a_Peer);
|
void SetPeer(Nz::ENetPeer* a_Peer);
|
||||||
|
|
||||||
friend class EnetClient;
|
friend class EnetClient;
|
||||||
friend class EnetServer;
|
friend class EnetServer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#undef DeclarePacket
|
#undef DeclarePacket
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include <Nazara/Network/ENetHost.hpp>
|
#include <Nazara/Network/ENetHost.hpp>
|
||||||
#include <blitz/common/NonCopyable.h>
|
#include <blitz/common/NonCopyable.h>
|
||||||
#include <blitz/network/EnetConnexion.h>
|
#include <blitz/network/EnetConnexion.h>
|
||||||
#include <blitz/protocol/Packets.h>
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@@ -19,7 +18,7 @@ class EnetServer : private NonCopyable {
|
|||||||
|
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
void BroadcastPacket(const protocol::Packet& a_Packet, Nz::ENetPacketFlags a_Flags);
|
// void BroadcastPacket(const protocol::Packet& a_Packet, Nz::ENetPacketFlags a_Flags);
|
||||||
|
|
||||||
EnetConnexion* GetConnexion(std::uint16_t a_PeerId);
|
EnetConnexion* GetConnexion(std::uint16_t a_PeerId);
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,49 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file PacketDeclare.h
|
||||||
|
* \brief Holds the definitions of the packets (but not their content)
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace blitz {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \enum PacketSender
|
||||||
|
* \brief Indicate who should send a packet
|
||||||
|
*/
|
||||||
|
enum class PacketSender {
|
||||||
|
/** Sent by clients and server */
|
||||||
|
Both,
|
||||||
|
/** Sent by clients to the server */
|
||||||
|
Client,
|
||||||
|
/** Sent by server to the clients */
|
||||||
|
Server,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \def DeclareAllPacket
|
||||||
|
* \brief Avoids repetitive operations on packets
|
||||||
|
*/
|
||||||
#define DeclareAllPacket() \
|
#define DeclareAllPacket() \
|
||||||
DeclarePacket(PlayerLogin, Nz::ENetPacketFlag::Reliable); \
|
DeclarePacket(ChatMessage, Reliable, Both) \
|
||||||
DeclarePacket(UpdateHealth, Nz::ENetPacketFlag::Reliable); \
|
DeclarePacket(Disconnect, Reliable, Both) \
|
||||||
DeclarePacket(LoggingSuccess, Nz::ENetPacketFlag::Reliable); \
|
DeclarePacket(KeepAlive, Reliable, Both) \
|
||||||
DeclarePacket(PlayerDeath, Nz::ENetPacketFlag::Reliable); \
|
DeclarePacket(LoggingSuccess, Reliable, Server) \
|
||||||
DeclarePacket(PlayerJoin, Nz::ENetPacketFlag::Reliable); \
|
DeclarePacket(PlayerDeath, Reliable, Server) \
|
||||||
DeclarePacket(PlayerLeave, Nz::ENetPacketFlag::Reliable); \
|
DeclarePacket(PlayerJoin, Reliable, Server) \
|
||||||
DeclarePacket(PlayerStats, Nz::ENetPacketFlag::Reliable); \
|
DeclarePacket(PlayerLeave, Reliable, Server) \
|
||||||
DeclarePacket(PlayerList, Nz::ENetPacketFlag::Reliable); \
|
DeclarePacket(PlayerList, Reliable, Server) \
|
||||||
DeclarePacket(ServerConfig, Nz::ENetPacketFlag::Reliable); \
|
DeclarePacket(PlayerLogin, Reliable, Client) \
|
||||||
DeclarePacket(ServerTps, Nz::ENetPacketFlag::Reliable); \
|
DeclarePacket(PlayerPositionAndRotation, Reliable, Both) \
|
||||||
DeclarePacket(UpdateGameState, Nz::ENetPacketFlag::Reliable); \
|
DeclarePacket(PlayerShoot, Reliable, Both) \
|
||||||
DeclarePacket(KeepAlive, Nz::ENetPacketFlag::Reliable); \
|
DeclarePacket(PlayerStats, Reliable, Server) \
|
||||||
DeclarePacket(Disconnect, Nz::ENetPacketFlag::Reliable); \
|
DeclarePacket(ServerConfig, Reliable, Server) \
|
||||||
DeclarePacket(ChatMessage, Nz::ENetPacketFlag::Reliable); \
|
DeclarePacket(ServerTps, Reliable, Server) \
|
||||||
DeclarePacket(PlayerPositionAndRotation, Nz::ENetPacketFlag::Reliable); \
|
DeclarePacket(UpdateGameState, Reliable, Server) \
|
||||||
DeclarePacket(PlayerShoot, Nz::ENetPacketFlag::Reliable);
|
DeclarePacket(UpdateHealth, Reliable, Client)
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace blitz
|
||||||
@@ -1,20 +1,33 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file PacketVisitor.h
|
||||||
|
* \brief File containing the blitz::protocol::PacketVisitor class
|
||||||
|
*/
|
||||||
|
|
||||||
#include <blitz/protocol/Packets.h>
|
#include <blitz/protocol/Packets.h>
|
||||||
#include <blitz/protocol/PacketDeclare.h>
|
|
||||||
|
|
||||||
namespace blitz {
|
namespace blitz {
|
||||||
namespace protocol {
|
namespace protocol {
|
||||||
|
|
||||||
#define DeclarePacket(PacketName, ...) \
|
#define DeclarePacket(PacketName, ...) \
|
||||||
|
/** This function is called when the packet processed by PacketVisitor::Check is a PacketName */ \
|
||||||
virtual void Visit(const packets::PacketName&) {}
|
virtual void Visit(const packets::PacketName&) {}
|
||||||
|
|
||||||
class PacketVisitor {
|
/**
|
||||||
|
* \class PacketVisitor
|
||||||
|
* \brief This class uses double-dispatch in order to find the real type of a packet
|
||||||
|
*/
|
||||||
|
class PacketVisitor : private NonCopyable {
|
||||||
protected:
|
protected:
|
||||||
PacketVisitor() {}
|
PacketVisitor() {}
|
||||||
virtual ~PacketVisitor() {}
|
virtual ~PacketVisitor() {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* \brief Calls the right PacketVisitor::Visit method corresponding to the real type of the packet
|
||||||
|
* \param packet the Packet to visit
|
||||||
|
*/
|
||||||
void Check(const Packet& packet);
|
void Check(const Packet& packet);
|
||||||
|
|
||||||
DeclareAllPacket()
|
DeclareAllPacket()
|
||||||
|
|||||||
@@ -1,54 +1,52 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file Packets.h
|
||||||
|
* \brief File containing the definitions of the packets
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <blitz/common/NonCopyable.h>
|
||||||
#include <blitz/protocol/PacketData.h>
|
#include <blitz/protocol/PacketData.h>
|
||||||
#include <blitz/protocol/PacketDeclare.h>
|
#include <blitz/protocol/PacketDeclare.h>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace blitz {
|
namespace blitz {
|
||||||
namespace protocol {
|
namespace protocol {
|
||||||
|
|
||||||
class PacketVisitor;
|
class PacketVisitor;
|
||||||
|
|
||||||
|
/** A Packet id is 8 bits wide */
|
||||||
using PacketID = std::uint8_t;
|
using PacketID = std::uint8_t;
|
||||||
|
|
||||||
|
#define DeclarePacket(PacketName, ...) /** PacketName */ PacketName,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \enum PacketType
|
||||||
|
* \brief Map a Packet to an id
|
||||||
|
*/
|
||||||
enum class PacketType : PacketID {
|
enum class PacketType : PacketID {
|
||||||
// client --> server
|
|
||||||
|
|
||||||
PlayerLogin = 0,
|
DeclareAllPacket()
|
||||||
UpdateHealth,
|
|
||||||
|
|
||||||
// client <-- server
|
|
||||||
|
|
||||||
LoggingSuccess,
|
|
||||||
PlayerDeath,
|
|
||||||
PlayerJoin,
|
|
||||||
PlayerLeave,
|
|
||||||
PlayerList,
|
|
||||||
PlayerStats,
|
|
||||||
ServerConfig,
|
|
||||||
ServerTps,
|
|
||||||
UpdateGameState,
|
|
||||||
|
|
||||||
// client <--> server
|
|
||||||
|
|
||||||
KeepAlive,
|
|
||||||
Disconnect,
|
|
||||||
ChatMessage,
|
|
||||||
PlayerPositionAndRotation,
|
|
||||||
PlayerShoot,
|
|
||||||
|
|
||||||
|
/** The number of packets */
|
||||||
PACKET_COUNT
|
PACKET_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#undef DeclarePacket
|
||||||
|
|
||||||
|
|
||||||
|
class Packet : private NonCopyable {
|
||||||
class Packet {
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* \return The real type of the packet
|
||||||
|
*/
|
||||||
virtual PacketType GetType() const = 0;
|
virtual PacketType GetType() const = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
/** Use a PacketVisitor to make double-dispatch possible */
|
||||||
virtual void Accept(PacketVisitor& a_Visitor) const = 0;
|
virtual void Accept(PacketVisitor& a_Visitor) const = 0;
|
||||||
|
|
||||||
|
friend class PacketVisitor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -58,16 +56,21 @@ class Packet {
|
|||||||
namespace packets {
|
namespace packets {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* \class ConcretePacket
|
||||||
|
* \brief A Packet associated with an id and holding data
|
||||||
* \tparam PT The packet type
|
* \tparam PT The packet type
|
||||||
* \tparam Data The structure holding the data of the packet
|
* \tparam Data The structure holding the data of the packet (in blitz::protocol::data namespace)
|
||||||
*/
|
*/
|
||||||
template <PacketType PT, typename Data>
|
template <PacketType PT, typename Data>
|
||||||
class ConcretePacket : public Packet {
|
class ConcretePacket : public Packet {
|
||||||
public:
|
public:
|
||||||
|
/** The type of the struct holding the data */
|
||||||
using PacketDataType = Data;
|
using PacketDataType = Data;
|
||||||
|
|
||||||
|
/** The structure holding the actual data */
|
||||||
PacketDataType m_Data;
|
PacketDataType m_Data;
|
||||||
|
|
||||||
|
/** Construct the packet with data of type PacketDataType */
|
||||||
ConcretePacket(const PacketDataType& a_Data = {});
|
ConcretePacket(const PacketDataType& a_Data = {});
|
||||||
|
|
||||||
constexpr PacketType GetType() const override {
|
constexpr PacketType GetType() const override {
|
||||||
@@ -76,8 +79,6 @@ class ConcretePacket : public Packet {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void Accept(PacketVisitor& a_Visitor) const override;
|
void Accept(PacketVisitor& a_Visitor) const override;
|
||||||
|
|
||||||
friend class PacketVisitor;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -90,9 +91,10 @@ class ConcretePacket : public Packet {
|
|||||||
#ifdef BLITZ_INSTANCIATE_PACKETS
|
#ifdef BLITZ_INSTANCIATE_PACKETS
|
||||||
#define DeclarePacket(PacketName, ...) \
|
#define DeclarePacket(PacketName, ...) \
|
||||||
using PacketName = ConcretePacket<PacketType::PacketName, data::PacketName>; \
|
using PacketName = ConcretePacket<PacketType::PacketName, data::PacketName>; \
|
||||||
template class ConcretePacket<PacketType::PacketName, data::PacketName>
|
template class ConcretePacket<PacketType::PacketName, data::PacketName>;
|
||||||
#else
|
#else
|
||||||
#define DeclarePacket(PacketName, ...) using PacketName = ConcretePacket<PacketType::PacketName, data::PacketName>
|
#define DeclarePacket(PacketName, ...) /** Defines the PacketName packet */ \
|
||||||
|
using PacketName = ConcretePacket<PacketType::PacketName, data::PacketName>;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DeclareAllPacket()
|
DeclareAllPacket()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include <blitz/network/EnetConnexion.h>
|
#include <blitz/network/EnetConnexion.h>
|
||||||
|
|
||||||
|
#include <Nazara/Network/ENetPeer.hpp>
|
||||||
#include <blitz/protocol/PacketSerializer.h>
|
#include <blitz/protocol/PacketSerializer.h>
|
||||||
#include <blitz/protocol/PacketVisitor.h>
|
#include <blitz/protocol/PacketVisitor.h>
|
||||||
|
|
||||||
@@ -20,12 +21,14 @@ class PacketDispatcher : public protocol::PacketVisitor {
|
|||||||
public:
|
public:
|
||||||
PacketDispatcher(EnetConnexion& a_Connexion) : m_Connexion(a_Connexion) {}
|
PacketDispatcher(EnetConnexion& a_Connexion) : m_Connexion(a_Connexion) {}
|
||||||
|
|
||||||
DeclareAllPacket();
|
DeclareAllPacket()
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EnetConnexion& m_Connexion;
|
EnetConnexion& m_Connexion;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#undef DeclarePacket
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -36,6 +39,12 @@ void EnetConnexion::SetPeer(Nz::ENetPeer* a_Peer) {
|
|||||||
m_Peer = a_Peer;
|
m_Peer = a_Peer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool EnetConnexion::IsConnected() const {
|
||||||
|
if (!m_Peer)
|
||||||
|
return false;
|
||||||
|
return m_Peer->IsConnected();
|
||||||
|
}
|
||||||
|
|
||||||
void EnetConnexion::Recieve(Nz::ByteArray& a_Data) {
|
void EnetConnexion::Recieve(Nz::ByteArray& a_Data) {
|
||||||
auto packet = protocol::PacketSerializer::Deserialize(a_Data);
|
auto packet = protocol::PacketSerializer::Deserialize(a_Data);
|
||||||
if (!packet)
|
if (!packet)
|
||||||
@@ -44,5 +53,12 @@ void EnetConnexion::Recieve(Nz::ByteArray& a_Data) {
|
|||||||
dispatcher.Check(*packet.get());
|
dispatcher.Check(*packet.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define DeclarePacket(Name, NFlag, ...) \
|
||||||
|
void EnetConnexion::Send##Name(const blitz::protocol::data::Name& a_##Name) const { \
|
||||||
|
m_Peer->Send(0, Nz::ENetPacketFlag::NFlag, protocol::PacketSerializer::Serialize(protocol::packets::Name(a_##Name))); \
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclareAllPacket()
|
||||||
|
|
||||||
} // namespace network
|
} // namespace network
|
||||||
} // namespace blitz
|
} // namespace blitz
|
||||||
|
|||||||
@@ -76,9 +76,9 @@ EnetConnexion* EnetServer::GetConnexion(std::uint16_t a_PeerId) {
|
|||||||
return &it->second;
|
return &it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnetServer::BroadcastPacket(const protocol::Packet& a_Packet, Nz::ENetPacketFlags a_Flags) {
|
/*void EnetServer::BroadcastPacket(const protocol::Packet& a_Packet, Nz::ENetPacketFlags a_Flags) {
|
||||||
// m_Host.Broadcast(0, a_Flags, std::move(a_Data));
|
m_Host.Broadcast(0, a_Flags, std::move(a_Data));
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void EnetServer::RemoveConnexion(std::uint16_t a_PeerId) {
|
void EnetServer::RemoveConnexion(std::uint16_t a_PeerId) {
|
||||||
m_Connexion.erase(a_PeerId);
|
m_Connexion.erase(a_PeerId);
|
||||||
|
|||||||
@@ -9,29 +9,18 @@ namespace PacketFactory {
|
|||||||
|
|
||||||
using PacketCreator = std::function<std::unique_ptr<Packet>()>;
|
using PacketCreator = std::function<std::unique_ptr<Packet>()>;
|
||||||
|
|
||||||
|
#define DeclarePacket(PacketName, ...) std::make_unique<packets::PacketName>(),
|
||||||
|
|
||||||
static const std::array<std::unique_ptr<Packet>, static_cast<std::size_t>(PacketType::PACKET_COUNT)> Packets = {
|
static const std::array<std::unique_ptr<Packet>, static_cast<std::size_t>(PacketType::PACKET_COUNT)> Packets = {
|
||||||
std::make_unique<packets::PlayerLogin>(),
|
|
||||||
std::make_unique<packets::UpdateHealth>(),
|
DeclareAllPacket()
|
||||||
std::make_unique<packets::LoggingSuccess>(),
|
|
||||||
std::make_unique<packets::PlayerDeath>(),
|
|
||||||
std::make_unique<packets::PlayerJoin>(),
|
|
||||||
std::make_unique<packets::PlayerLeave>(),
|
|
||||||
std::make_unique<packets::PlayerList>(),
|
|
||||||
std::make_unique<packets::PlayerStats>(),
|
|
||||||
std::make_unique<packets::ServerConfig>(),
|
|
||||||
std::make_unique<packets::ServerTps>(),
|
|
||||||
std::make_unique<packets::UpdateGameState>(),
|
|
||||||
std::make_unique<packets::KeepAlive>(),
|
|
||||||
std::make_unique<packets::Disconnect>(),
|
|
||||||
std::make_unique<packets::ChatMessage>(),
|
|
||||||
std::make_unique<packets::PlayerPositionAndRotation>(),
|
|
||||||
std::make_unique<packets::PlayerShoot>(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::unique_ptr<Packet>& CreateReadOnlyPacket(PacketType a_Type) {
|
const std::unique_ptr<Packet>& CreateReadOnlyPacket(PacketType a_Type) {
|
||||||
return Packets[static_cast<std::size_t>(a_Type)];
|
return Packets[static_cast<std::size_t>(a_Type)];
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace PacketFactory
|
} // namespace PacketFactory
|
||||||
} // namespace protocol
|
} // namespace protocol
|
||||||
} // namespace blitz
|
} // namespace blitz
|
||||||
|
|||||||
@@ -11,29 +11,16 @@ namespace protocol {
|
|||||||
|
|
||||||
namespace PacketSerializer {
|
namespace PacketSerializer {
|
||||||
|
|
||||||
#define VisitSerialize(ClassName) \
|
#define DeclarePacket(PacketName, ...) \
|
||||||
void Visit(const ClassName& a_Packet) override { \
|
void Visit(const packets::PacketName& a_Packet) override { \
|
||||||
const auto& packetData = a_Packet.m_Data; \
|
const auto& packetData = a_Packet.m_Data; \
|
||||||
SerializePacketData(packetData); \
|
SerializePacketData(packetData); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
void SerializePacketData(const ClassName::PacketDataType& a_Packet)
|
void SerializePacketData(const packets::PacketName::PacketDataType& a_Packet);
|
||||||
|
|
||||||
#define VisitDeserialize(ClassName) \
|
|
||||||
void Visit(const ClassName& a_Packet) override { \
|
|
||||||
auto packetPtr = PacketFactory::CreatePacket<ClassName>(); \
|
|
||||||
auto& packetData = packetPtr->m_Data; \
|
|
||||||
\
|
|
||||||
DeserializePacketData(packetData); \
|
|
||||||
\
|
|
||||||
m_Packet = std::move(packetPtr); \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
void DeserializePacketData(ClassName::PacketDataType& a_Packet)
|
|
||||||
|
|
||||||
|
|
||||||
#define DeclarePacket(PacketName, ...) \
|
|
||||||
VisitSerialize(packets::PacketName)
|
|
||||||
|
|
||||||
class Serializer : public PacketVisitor {
|
class Serializer : public PacketVisitor {
|
||||||
private:
|
private:
|
||||||
@@ -51,8 +38,24 @@ class Serializer : public PacketVisitor {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#undef DeclarePacket
|
#undef DeclarePacket
|
||||||
#define DeclarePacket(PacketName, ...) \
|
|
||||||
VisitDeserialize(packets::PacketName)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define DeclarePacket(PacketName, ...) \
|
||||||
|
void Visit(const packets::PacketName& a_Packet) override { \
|
||||||
|
auto packetPtr = PacketFactory::CreatePacket<packets::PacketName>(); \
|
||||||
|
auto& packetData = packetPtr->m_Data; \
|
||||||
|
\
|
||||||
|
DeserializePacketData(packetData); \
|
||||||
|
\
|
||||||
|
m_Packet = std::move(packetPtr); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
void DeserializePacketData(packets::PacketName::PacketDataType& a_Packet);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Deserializer : public PacketVisitor {
|
class Deserializer : public PacketVisitor {
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user