improve packet interface
This commit is contained in:
50
include/blitz/network/EnetConnexion.h
Normal file
50
include/blitz/network/EnetConnexion.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include <Nazara/Network/ENetPeer.hpp>
|
||||
#include <blitz/protocol/PacketSerializer.h>
|
||||
#include <blitz/protocol/Packets.h>
|
||||
|
||||
namespace blitz {
|
||||
namespace network {
|
||||
|
||||
class EnetClient;
|
||||
class EnetServer;
|
||||
|
||||
|
||||
|
||||
#define DeclarePacket(Name, NFlag) \
|
||||
void Send##Name(const blitz::protocol::data::Name& a_##Name) const { \
|
||||
m_Peer->Send(0, NFlag, protocol::PacketSerializer::Serialize(protocol::packets::Name(a_##Name))); \
|
||||
} \
|
||||
NazaraSignal(On##Name, const blitz::protocol::data::Name&)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class EnetConnexion {
|
||||
public:
|
||||
EnetConnexion(Nz::ENetPeer* a_Peer = nullptr);
|
||||
|
||||
bool IsConnected() const {
|
||||
if (!m_Peer)
|
||||
return false;
|
||||
return m_Peer->IsConnected();
|
||||
}
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user