generated from Persson-dev/Godot-Xmake
Compare commits
2 Commits
a092f6fbc1
...
03b6e577ea
| Author | SHA1 | Date | |
|---|---|---|---|
| 03b6e577ea | |||
| f557d0dd2d |
@@ -27,6 +27,8 @@ class NetworkInterface : public godot::Node, public protocol::PacketDispatcher {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void RecievePacketDataReliable(godot::PackedByteArray a_PacketData);
|
void RecievePacketDataReliable(godot::PackedByteArray a_PacketData);
|
||||||
|
void RecievePacketDataUnreliable(godot::PackedByteArray a_PacketData);
|
||||||
|
void RecievePacketDataUnreliableOrdered(godot::PackedByteArray a_PacketData);
|
||||||
|
|
||||||
void OnPlayerConnected(PeerID a_PeerId);
|
void OnPlayerConnected(PeerID a_PeerId);
|
||||||
void OnPlayerDisconnected(PeerID a_PeerId);
|
void OnPlayerDisconnected(PeerID a_PeerId);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <godot_cpp/variant/packed_byte_array.hpp>
|
#include <godot_cpp/variant/packed_byte_array.hpp>
|
||||||
#include <godot_cpp/variant/string.hpp>
|
#include <godot_cpp/variant/string.hpp>
|
||||||
|
#include <stdexcept>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace blitz {
|
namespace blitz {
|
||||||
@@ -9,25 +10,17 @@ namespace protocol {
|
|||||||
|
|
||||||
class PlayerInfo;
|
class PlayerInfo;
|
||||||
|
|
||||||
#define Operators(Type, GodotType) \
|
|
||||||
ByteBuffer& operator>>(Type& a_Data) { \
|
|
||||||
a_Data = m_Buffer.decode_##GodotType(m_ReadOffset); \
|
|
||||||
m_ReadOffset += sizeof(a_Data); \
|
|
||||||
return *this; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
ByteBuffer& operator<<(Type a_Data) { \
|
|
||||||
m_Buffer.resize(m_Buffer.size() + sizeof(a_Data)); \
|
|
||||||
m_Buffer.encode_##GodotType(m_Buffer.size() - sizeof(a_Data), a_Data); \
|
|
||||||
return *this; \
|
|
||||||
}
|
|
||||||
|
|
||||||
class ByteBuffer {
|
class ByteBuffer {
|
||||||
private:
|
private:
|
||||||
godot::PackedByteArray m_Buffer;
|
godot::PackedByteArray m_Buffer;
|
||||||
std::size_t m_ReadOffset;
|
std::size_t m_ReadOffset;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
class ReadError : public std::runtime_error {
|
||||||
|
public:
|
||||||
|
ReadError(const std::string& msg) : std::runtime_error(msg) {}
|
||||||
|
};
|
||||||
|
|
||||||
ByteBuffer(godot::PackedByteArray&& a_Buffer) : m_Buffer(std::move(a_Buffer)), m_ReadOffset(0) {}
|
ByteBuffer(godot::PackedByteArray&& a_Buffer) : m_Buffer(std::move(a_Buffer)), m_ReadOffset(0) {}
|
||||||
ByteBuffer() : m_ReadOffset(0) {
|
ByteBuffer() : m_ReadOffset(0) {
|
||||||
m_Buffer.resize(0);
|
m_Buffer.resize(0);
|
||||||
@@ -42,18 +35,30 @@ class ByteBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Integers
|
// Integers
|
||||||
Operators(int8_t, s8);
|
ByteBuffer& operator<<(int8_t a_Data);
|
||||||
Operators(uint8_t, u8);
|
ByteBuffer& operator>>(int8_t& a_Data);
|
||||||
Operators(int16_t, s16);
|
ByteBuffer& operator<<(uint8_t a_Data);
|
||||||
Operators(uint16_t, u16);
|
ByteBuffer& operator>>(uint8_t& a_Data);
|
||||||
Operators(int32_t, s32);
|
|
||||||
Operators(uint32_t, u32);
|
|
||||||
Operators(int64_t, s64);
|
|
||||||
Operators(uint64_t, u64);
|
|
||||||
|
|
||||||
// Reals
|
ByteBuffer& operator<<(int16_t a_Data);
|
||||||
Operators(float, float);
|
ByteBuffer& operator>>(int16_t& a_Data);
|
||||||
Operators(double, double);
|
ByteBuffer& operator<<(uint16_t a_Data);
|
||||||
|
ByteBuffer& operator>>(uint16_t& a_Data);
|
||||||
|
|
||||||
|
ByteBuffer& operator<<(int32_t a_Data);
|
||||||
|
ByteBuffer& operator>>(int32_t& a_Data);
|
||||||
|
ByteBuffer& operator<<(uint32_t a_Data);
|
||||||
|
ByteBuffer& operator>>(uint32_t& a_Data);
|
||||||
|
|
||||||
|
ByteBuffer& operator<<(int64_t a_Data);
|
||||||
|
ByteBuffer& operator>>(int64_t& a_Data);
|
||||||
|
ByteBuffer& operator<<(uint64_t a_Data);
|
||||||
|
ByteBuffer& operator>>(uint64_t& a_Data);
|
||||||
|
|
||||||
|
ByteBuffer& operator<<(float a_Data);
|
||||||
|
ByteBuffer& operator>>(float& a_Data);
|
||||||
|
ByteBuffer& operator<<(double a_Data);
|
||||||
|
ByteBuffer& operator>>(double& a_Data);
|
||||||
|
|
||||||
ByteBuffer& operator<<(const godot::String& a_Data);
|
ByteBuffer& operator<<(const godot::String& a_Data);
|
||||||
ByteBuffer& operator>>(godot::String& a_Data);
|
ByteBuffer& operator>>(godot::String& a_Data);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace protocol {
|
|||||||
* \enum PacketSender
|
* \enum PacketSender
|
||||||
* \brief Indicate who should send a packet
|
* \brief Indicate who should send a packet
|
||||||
*/
|
*/
|
||||||
enum class PacketSender {
|
enum class PacketSenderType {
|
||||||
/** Sent by clients and server */
|
/** Sent by clients and server */
|
||||||
Both,
|
Both,
|
||||||
/** Sent by clients to the server */
|
/** Sent by clients to the server */
|
||||||
@@ -36,7 +36,7 @@ enum class PacketSender {
|
|||||||
DeclarePacket(PlayerLeave, Reliable, Server) \
|
DeclarePacket(PlayerLeave, Reliable, Server) \
|
||||||
DeclarePacket(PlayerList, Reliable, Server) \
|
DeclarePacket(PlayerList, Reliable, Server) \
|
||||||
DeclarePacket(PlayerLogin, Reliable, Client) \
|
DeclarePacket(PlayerLogin, Reliable, Client) \
|
||||||
DeclarePacket(PlayerPositionAndRotation, Reliable, Both) \
|
DeclarePacket(PlayerPositionAndRotation, Unreliable, Both) \
|
||||||
DeclarePacket(PlayerShoot, Reliable, Both) \
|
DeclarePacket(PlayerShoot, Reliable, Both) \
|
||||||
DeclarePacket(PlayerStats, Reliable, Server) \
|
DeclarePacket(PlayerStats, Reliable, Server) \
|
||||||
DeclarePacket(ServerConfig, Reliable, Server) \
|
DeclarePacket(ServerConfig, Reliable, Server) \
|
||||||
|
|||||||
57
include/blitz/protocol/PacketSender.h
Normal file
57
include/blitz/protocol/PacketSender.h
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <blitz/protocol/PacketVisitor.h>
|
||||||
|
|
||||||
|
namespace blitz {
|
||||||
|
|
||||||
|
class NetworkInterface;
|
||||||
|
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
/* PacketBroadcaster */
|
||||||
|
///////////////////////
|
||||||
|
|
||||||
|
#define DeclarePacket(PacketName, Reliability, ...) void Visit(const protocol::packets::PacketName& a_Packet) override;
|
||||||
|
|
||||||
|
class PacketBroadcaster : public protocol::PacketVisitor {
|
||||||
|
private:
|
||||||
|
NetworkInterface& m_NetworkInterface;
|
||||||
|
|
||||||
|
public:
|
||||||
|
PacketBroadcaster(NetworkInterface& a_NetworkInterface) : m_NetworkInterface(a_NetworkInterface) {}
|
||||||
|
|
||||||
|
void BroadcastPacket(const protocol::Packet& a_Packet) {
|
||||||
|
Check(a_Packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclareAllPacket()
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////
|
||||||
|
/* PacketSender */
|
||||||
|
//////////////////
|
||||||
|
class PacketSender : public protocol::PacketVisitor {
|
||||||
|
private:
|
||||||
|
NetworkInterface& m_NetworkInterface;
|
||||||
|
PeerID m_PeerId;
|
||||||
|
|
||||||
|
public:
|
||||||
|
PacketSender(PeerID a_PeerId, NetworkInterface& a_NetworkInterface) : m_PeerId(a_PeerId), m_NetworkInterface(a_NetworkInterface) {}
|
||||||
|
|
||||||
|
void SendPacket(const protocol::Packet& a_Packet) {
|
||||||
|
Check(a_Packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclareAllPacket()
|
||||||
|
};
|
||||||
|
|
||||||
|
#undef DeclarePacket
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace blitz
|
||||||
@@ -1,21 +1,37 @@
|
|||||||
#include <blitz/godot/NetworkInterface.h>
|
#include <blitz/godot/NetworkInterface.h>
|
||||||
|
|
||||||
#include <blitz/protocol/PacketFactory.h>
|
#include <blitz/protocol/PacketFactory.h>
|
||||||
|
#include <blitz/protocol/PacketSender.h>
|
||||||
#include <blitz/protocol/PacketSerializer.h>
|
#include <blitz/protocol/PacketSerializer.h>
|
||||||
|
#include <blitz/protocol/PacketVisitor.h>
|
||||||
#include <godot_cpp/classes/e_net_multiplayer_peer.hpp>
|
#include <godot_cpp/classes/e_net_multiplayer_peer.hpp>
|
||||||
#include <godot_cpp/classes/multiplayer_api.hpp>
|
#include <godot_cpp/classes/multiplayer_api.hpp>
|
||||||
#include <godot_cpp/classes/packed_scene.hpp>
|
#include <godot_cpp/classes/packed_scene.hpp>
|
||||||
#include <godot_cpp/classes/resource_loader.hpp>
|
#include <godot_cpp/classes/resource_loader.hpp>
|
||||||
#include <godot_cpp/variant/utility_functions.hpp>
|
#include <godot_cpp/variant/utility_functions.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace blitz {
|
namespace blitz {
|
||||||
|
|
||||||
|
#define RPC_CONFIG(functionName, rpc_mode, transfer_mode, call_local, channel) \
|
||||||
|
{ \
|
||||||
|
Dictionary config; \
|
||||||
|
config["rpc_mode"] = rpc_mode; \
|
||||||
|
config["transfer_mode"] = transfer_mode; \
|
||||||
|
config["call_local"] = call_local; \
|
||||||
|
config["channel"] = channel; \
|
||||||
|
rpc_config(functionName, config); \
|
||||||
|
}
|
||||||
|
|
||||||
static const char ServerScenePath[] = "res://Scenes/Network/server.tscn";
|
static const char ServerScenePath[] = "res://Scenes/Network/server.tscn";
|
||||||
|
|
||||||
using namespace godot;
|
using namespace godot;
|
||||||
|
|
||||||
void NetworkInterface::_bind_methods() {
|
void NetworkInterface::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("RecievePacketDataReliable", "a_PacketData"), &NetworkInterface::RecievePacketDataReliable);
|
ClassDB::bind_method(D_METHOD("RecievePacketDataReliable", "a_PacketData"), &NetworkInterface::RecievePacketDataReliable);
|
||||||
|
ClassDB::bind_method(D_METHOD("RecievePacketDataUnreliable", "a_PacketData"), &NetworkInterface::RecievePacketDataUnreliable);
|
||||||
|
ClassDB::bind_method(
|
||||||
|
D_METHOD("RecievePacketDataUnreliableOrdered", "a_PacketData"), &NetworkInterface::RecievePacketDataUnreliableOrdered);
|
||||||
|
|
||||||
// server
|
// server
|
||||||
ADD_SIGNAL(MethodInfo("player_connected", PropertyInfo(Variant::INT, "peer_id")));
|
ADD_SIGNAL(MethodInfo("player_connected", PropertyInfo(Variant::INT, "peer_id")));
|
||||||
@@ -33,13 +49,10 @@ NetworkInterface::NetworkInterface() {}
|
|||||||
NetworkInterface::~NetworkInterface() {}
|
NetworkInterface::~NetworkInterface() {}
|
||||||
|
|
||||||
void NetworkInterface::_ready() {
|
void NetworkInterface::_ready() {
|
||||||
// TODO: unreliable
|
RPC_CONFIG("RecievePacketDataReliable", MultiplayerAPI::RPC_MODE_ANY_PEER, MultiplayerPeer::TRANSFER_MODE_RELIABLE, true, 0);
|
||||||
Dictionary config;
|
RPC_CONFIG("RecievePacketDataUnreliable", MultiplayerAPI::RPC_MODE_ANY_PEER, MultiplayerPeer::TRANSFER_MODE_UNRELIABLE, true, 1);
|
||||||
config["rpc_mode"] = MultiplayerAPI::RPC_MODE_ANY_PEER;
|
RPC_CONFIG("RecievePacketDataUnreliableOrdered", MultiplayerAPI::RPC_MODE_ANY_PEER,
|
||||||
config["transfer_mode"] = MultiplayerPeer::TRANSFER_MODE_RELIABLE;
|
MultiplayerPeer::TRANSFER_MODE_UNRELIABLE_ORDERED, true, 2);
|
||||||
config["call_local"] = true;
|
|
||||||
config["channel"] = 0;
|
|
||||||
rpc_config("RecievePacketDataReliable", config);
|
|
||||||
|
|
||||||
get_multiplayer()->connect("peer_connected", callable_mp(this, &NetworkInterface::OnPlayerConnected));
|
get_multiplayer()->connect("peer_connected", callable_mp(this, &NetworkInterface::OnPlayerConnected));
|
||||||
get_multiplayer()->connect("peer_disconnected", callable_mp(this, &NetworkInterface::OnPlayerDisconnected));
|
get_multiplayer()->connect("peer_disconnected", callable_mp(this, &NetworkInterface::OnPlayerDisconnected));
|
||||||
@@ -49,13 +62,13 @@ void NetworkInterface::_ready() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void NetworkInterface::BroadcastPacket(const protocol::Packet& a_Packet) {
|
void NetworkInterface::BroadcastPacket(const protocol::Packet& a_Packet) {
|
||||||
PackedByteArray byteArray = protocol::PacketSerializer::Serialize(a_Packet);
|
protocol::PacketBroadcaster packetBroadcaster(*this);
|
||||||
rpc("RecievePacketDataReliable", byteArray);
|
packetBroadcaster.BroadcastPacket(a_Packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkInterface::SendPacket(PeerID a_Peer, const protocol::Packet& a_Packet) {
|
void NetworkInterface::SendPacket(PeerID a_Peer, const protocol::Packet& a_Packet) {
|
||||||
PackedByteArray byteArray = protocol::PacketSerializer::Serialize(a_Packet);
|
protocol::PacketSender packetSender(a_Peer, *this);
|
||||||
rpc_id(a_Peer, "RecievePacketDataReliable", byteArray);
|
packetSender.SendPacket(a_Packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkInterface::RecievePacketDataReliable(godot::PackedByteArray a_PacketData) {
|
void NetworkInterface::RecievePacketDataReliable(godot::PackedByteArray a_PacketData) {
|
||||||
@@ -66,9 +79,27 @@ void NetworkInterface::RecievePacketDataReliable(godot::PackedByteArray a_Packet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NetworkInterface::RecievePacketDataUnreliable(godot::PackedByteArray a_PacketData) {
|
||||||
|
// we have to copy the function body in order to preserve the remote sender id
|
||||||
|
auto packet = protocol::PacketSerializer::Deserialize(a_PacketData);
|
||||||
|
if (packet) {
|
||||||
|
packet->m_Sender = get_multiplayer()->get_remote_sender_id();
|
||||||
|
Dispatch(*packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkInterface::RecievePacketDataUnreliableOrdered(godot::PackedByteArray a_PacketData) {
|
||||||
|
// we have to copy the function body in order to preserve the remote sender id
|
||||||
|
auto packet = protocol::PacketSerializer::Deserialize(a_PacketData);
|
||||||
|
if (packet) {
|
||||||
|
packet->m_Sender = get_multiplayer()->get_remote_sender_id();
|
||||||
|
Dispatch(*packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Error NetworkInterface::JoinGame(const String& a_Address, uint16_t a_Port) {
|
Error NetworkInterface::JoinGame(const String& a_Address, uint16_t a_Port) {
|
||||||
auto* peer = memnew(ENetMultiplayerPeer);
|
auto* peer = memnew(ENetMultiplayerPeer);
|
||||||
Error error = peer->create_client(a_Address, a_Port);
|
Error error = peer->create_client(a_Address, a_Port, 3);
|
||||||
if (error) {
|
if (error) {
|
||||||
OnConnectFail();
|
OnConnectFail();
|
||||||
return error;
|
return error;
|
||||||
@@ -80,7 +111,7 @@ Error NetworkInterface::JoinGame(const String& a_Address, uint16_t a_Port) {
|
|||||||
|
|
||||||
Error NetworkInterface::CreateGame(uint16_t a_Port, bool a_Dedicated) {
|
Error NetworkInterface::CreateGame(uint16_t a_Port, bool a_Dedicated) {
|
||||||
auto* peer = memnew(ENetMultiplayerPeer);
|
auto* peer = memnew(ENetMultiplayerPeer);
|
||||||
Error error = peer->create_server(a_Port);
|
Error error = peer->create_server(a_Port, 50, 3);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,36 @@
|
|||||||
namespace blitz {
|
namespace blitz {
|
||||||
namespace protocol {
|
namespace protocol {
|
||||||
|
|
||||||
|
#define Operators(Type, GodotType) \
|
||||||
|
ByteBuffer& ByteBuffer::operator>>(Type& a_Data) { \
|
||||||
|
if (sizeof(a_Data) + m_ReadOffset > m_Buffer.size()) { \
|
||||||
|
throw ReadError("Buffer is too small ! Can't read " #Type); \
|
||||||
|
} \
|
||||||
|
a_Data = m_Buffer.decode_##GodotType(m_ReadOffset); \
|
||||||
|
m_ReadOffset += sizeof(a_Data); \
|
||||||
|
return *this; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
ByteBuffer& ByteBuffer::operator<<(Type a_Data) { \
|
||||||
|
m_Buffer.resize(m_Buffer.size() + sizeof(a_Data)); \
|
||||||
|
m_Buffer.encode_##GodotType(m_Buffer.size() - sizeof(a_Data), a_Data); \
|
||||||
|
return *this; \
|
||||||
|
}
|
||||||
|
|
||||||
|
// Integers
|
||||||
|
Operators(int8_t, s8);
|
||||||
|
Operators(uint8_t, u8);
|
||||||
|
Operators(int16_t, s16);
|
||||||
|
Operators(uint16_t, u16);
|
||||||
|
Operators(int32_t, s32);
|
||||||
|
Operators(uint32_t, u32);
|
||||||
|
Operators(int64_t, s64);
|
||||||
|
Operators(uint64_t, u64);
|
||||||
|
|
||||||
|
// Reals
|
||||||
|
Operators(float, float);
|
||||||
|
Operators(double, double);
|
||||||
|
|
||||||
ByteBuffer& ByteBuffer::operator>>(PlayerInfo& a_Data) {
|
ByteBuffer& ByteBuffer::operator>>(PlayerInfo& a_Data) {
|
||||||
*this >> a_Data.m_PlayerId >> a_Data.m_PlayerName;
|
*this >> a_Data.m_PlayerId >> a_Data.m_PlayerName;
|
||||||
return *this;
|
return *this;
|
||||||
@@ -27,9 +57,9 @@ ByteBuffer& ByteBuffer::operator>>(godot::Vector3& a_Data) {
|
|||||||
|
|
||||||
ByteBuffer& ByteBuffer::operator>>(godot::String& a_Data) {
|
ByteBuffer& ByteBuffer::operator>>(godot::String& a_Data) {
|
||||||
int nullPos = m_Buffer.find(0, m_ReadOffset);
|
int nullPos = m_Buffer.find(0, m_ReadOffset);
|
||||||
// TODO: error handling
|
|
||||||
if (nullPos < 0)
|
if (nullPos < 0)
|
||||||
return *this;
|
throw ReadError("String does not have an and in buffer !");
|
||||||
|
|
||||||
|
|
||||||
godot::PackedByteArray stringBuffer = m_Buffer.slice(m_ReadOffset, nullPos);
|
godot::PackedByteArray stringBuffer = m_Buffer.slice(m_ReadOffset, nullPos);
|
||||||
a_Data = stringBuffer.get_string_from_utf8();
|
a_Data = stringBuffer.get_string_from_utf8();
|
||||||
|
|||||||
39
src/blitz/protocol/PacketSender.cpp
Normal file
39
src/blitz/protocol/PacketSender.cpp
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#include <blitz/protocol/PacketSender.h>
|
||||||
|
|
||||||
|
#include <blitz/godot/NetworkInterface.h>
|
||||||
|
#include <blitz/protocol/PacketSerializer.h>
|
||||||
|
|
||||||
|
namespace blitz {
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
/* PacketBroadcaster */
|
||||||
|
///////////////////////
|
||||||
|
|
||||||
|
#define DeclarePacket(PacketName, Reliability, ...) \
|
||||||
|
void PacketBroadcaster::Visit(const protocol::packets::PacketName& a_Packet) { \
|
||||||
|
m_NetworkInterface.rpc("RecievePacketData" #Reliability, protocol::PacketSerializer::Serialize(a_Packet)); \
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclareAllPacket()
|
||||||
|
|
||||||
|
#undef DeclarePacket
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////
|
||||||
|
/* PacketSender */
|
||||||
|
//////////////////
|
||||||
|
#define DeclarePacket(PacketName, Reliability, ...) \
|
||||||
|
void PacketSender::Visit(const protocol::packets::PacketName& a_Packet) { \
|
||||||
|
m_NetworkInterface.rpc_id(m_PeerId, "RecievePacketData" #Reliability, protocol::PacketSerializer::Serialize(a_Packet)); \
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclareAllPacket()
|
||||||
|
|
||||||
|
#undef DeclarePacket
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
} // namespace blitz
|
||||||
@@ -68,7 +68,8 @@ class Deserializer : public PacketVisitor {
|
|||||||
bool Deserialize(const PacketPtr& a_Packet) {
|
bool Deserialize(const PacketPtr& a_Packet) {
|
||||||
try {
|
try {
|
||||||
Check(*a_Packet.get());
|
Check(*a_Packet.get());
|
||||||
} catch (std::exception& e) {
|
} catch (ByteBuffer::ReadError& e) {
|
||||||
|
godot::UtilityFunctions::printerr("[PacketSerializer::Deserializer] ", e.what());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -109,6 +110,7 @@ std::unique_ptr<Packet> Deserialize(godot::PackedByteArray& a_Data) {
|
|||||||
const PacketPtr& emptyPacket = PacketFactory::CreateReadOnlyPacket(packetType);
|
const PacketPtr& emptyPacket = PacketFactory::CreateReadOnlyPacket(packetType);
|
||||||
|
|
||||||
Deserializer deserializer(std::move(stream));
|
Deserializer deserializer(std::move(stream));
|
||||||
|
|
||||||
if (deserializer.Deserialize(emptyPacket)) {
|
if (deserializer.Deserialize(emptyPacket)) {
|
||||||
PacketPtr packet = std::move(deserializer.GetPacket());
|
PacketPtr packet = std::move(deserializer.GetPacket());
|
||||||
return packet;
|
return packet;
|
||||||
|
|||||||
Reference in New Issue
Block a user