62 lines
1.4 KiB
C++
62 lines
1.4 KiB
C++
#pragma once
|
|
|
|
/**
|
|
* \file EnetConnection.h
|
|
* \brief File containing the blitz::network::EnetConnection class
|
|
*/
|
|
|
|
#include <Nazara/Core/ByteArray.hpp>
|
|
#include <NazaraUtils/Signal.hpp>
|
|
#include <blitz/common/NonCopyable.h>
|
|
#include <blitz/protocol/PacketData.h>
|
|
#include <blitz/protocol/PacketDeclare.h>
|
|
|
|
namespace Nz {
|
|
|
|
class ENetPeer;
|
|
|
|
} // namespace Nz
|
|
|
|
namespace blitz {
|
|
namespace network {
|
|
|
|
class EnetClient;
|
|
class EnetServer;
|
|
|
|
|
|
|
|
#define DeclarePacket(PacketName, ...) \
|
|
/** Sends a PacketName over the network */ \
|
|
void Send##PacketName(const blitz::protocol::data::PacketName& a_##PacketName) const; \
|
|
/** Use On##PacketName.Connect() to process a PacketName incoming from network */ \
|
|
NazaraSignal(On##PacketName, const blitz::protocol::data::PacketName&);
|
|
|
|
|
|
|
|
|
|
|
|
class EnetConnection : private NonCopyable {
|
|
public:
|
|
EnetConnection(Nz::ENetPeer* a_Peer = nullptr);
|
|
|
|
bool IsConnected() const;
|
|
|
|
std::uint16_t GetPeerId() const;
|
|
|
|
DeclareAllPacket();
|
|
|
|
private:
|
|
Nz::ENetPeer* m_Peer;
|
|
|
|
void Recieve(Nz::ByteArray&);
|
|
void SetPeer(Nz::ENetPeer* a_Peer);
|
|
|
|
friend class EnetClient;
|
|
friend class EnetServer;
|
|
};
|
|
|
|
#undef DeclarePacket
|
|
|
|
} // namespace network
|
|
} // namespace blitz
|