diff --git a/source/game/StarNetPackets.cpp b/source/game/StarNetPackets.cpp index 26203d6..140845a 100644 --- a/source/game/StarNetPackets.cpp +++ b/source/game/StarNetPackets.cpp @@ -167,17 +167,20 @@ PacketPtr createPacket(PacketType type) { } } -PacketPtr createPacket(PacketType type, JsonArray const& args) { +PacketPtr createPacket(PacketType type, Maybe const& args) { + if (!args) + return createPacket(type); + switch (type) { - case PacketType::Pause: return make_shared(args[0].toBool()); - case PacketType::ServerInfo: return make_shared(args[0].toUInt(), args[1].toUInt()); - case PacketType::GiveItem: return make_shared(ItemDescriptor(args[0])); - case PacketType::UpdateTileProtection: return make_shared(args[0].toUInt(), args[1].toBool()); - case PacketType::SetDungeonGravity: return make_shared(args[0].toUInt(), args[0].toFloat()); - case PacketType::SetDungeonBreathable: return make_shared(args[0].toUInt(), args[0].toBool()); - case PacketType::SetPlayerStart: return make_shared(Vec2F{args[0].toArray()[0].toFloat(), args[0].toArray()[0].toFloat()}, args[1].toBool()); - case PacketType::EntityMessage: return make_shared(EntityId(args[0].toUInt()), args[1].toString(), args[2].toArray(), Uuid(args[3].toString())); - case PacketType::UpdateWorldProperties: return make_shared(args[0].toObject()); + case PacketType::Pause: return make_shared(args->getBool("pause"), args->getFloat("timescale", 1.0f)); + case PacketType::ServerInfo: return make_shared(args->getUInt("players"), args->getUInt("maxPlayers")); + case PacketType::GiveItem: return make_shared(ItemDescriptor(args->getObject("ItemDescriptor"))); + case PacketType::UpdateTileProtection: return make_shared(args->getUInt("dungeonId"), args->getBool("protected")); + case PacketType::SetDungeonGravity: return make_shared(args->getUInt("dungeonId"), args->getFloat("gravity")); + case PacketType::SetDungeonBreathable: return make_shared(args->getUInt("dungeonId"), args->getBool("breathable")); + case PacketType::SetPlayerStart: return make_shared(Vec2F{args->getArray("position")[0].toFloat(), args->getArray("position")[1].toFloat()}, args->getBool("respawnInWorld")); + case PacketType::EntityMessage: return make_shared(EntityId(args->getInt("entityId")), args->getString("message"), args->get("JsonArray").toArray(), Uuid(args->getString("Uuid"))); + case PacketType::UpdateWorldProperties: return make_shared(args->getObject("updatedProperties")); default: throw StarPacketException(strf("Unrecognized packet type {}", (unsigned int)type)); } diff --git a/source/game/StarNetPackets.hpp b/source/game/StarNetPackets.hpp index e6f5b43..7c76037 100644 --- a/source/game/StarNetPackets.hpp +++ b/source/game/StarNetPackets.hpp @@ -139,7 +139,7 @@ struct Packet { }; PacketPtr createPacket(PacketType type); -PacketPtr createPacket(PacketType type, JsonArray const& args); +PacketPtr createPacket(PacketType type, Maybe const& args); template struct PacketBase : public Packet {