2023-06-20 04:33:09 +00:00
|
|
|
#include "StarNetPackets.hpp"
|
|
|
|
#include "StarDataStreamExtra.hpp"
|
2024-03-22 09:59:02 +00:00
|
|
|
#include "StarJsonExtra.hpp"
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
namespace Star {
|
|
|
|
|
|
|
|
VersionNumber const StarProtocolVersion = 747;
|
|
|
|
|
|
|
|
EnumMap<PacketType> const PacketTypeNames{
|
|
|
|
{PacketType::ProtocolRequest, "ProtocolRequest"},
|
|
|
|
{PacketType::ProtocolResponse, "ProtocolResponse"},
|
|
|
|
{PacketType::ServerDisconnect, "ServerDisconnect"},
|
|
|
|
{PacketType::ConnectSuccess, "ConnectSuccess"},
|
|
|
|
{PacketType::ConnectFailure, "ConnectFailure"},
|
|
|
|
{PacketType::HandshakeChallenge, "HandshakeChallenge"},
|
|
|
|
{PacketType::ChatReceive, "ChatReceive"},
|
|
|
|
{PacketType::UniverseTimeUpdate, "UniverseTimeUpdate"},
|
|
|
|
{PacketType::CelestialResponse, "CelestialResponse"},
|
|
|
|
{PacketType::PlayerWarpResult, "PlayerWarpResult"},
|
|
|
|
{PacketType::PlanetTypeUpdate, "PlanetTypeUpdate"},
|
|
|
|
{PacketType::Pause, "Pause"},
|
|
|
|
{PacketType::ServerInfo, "ServerInfo"},
|
|
|
|
{PacketType::ClientConnect, "ClientConnect"},
|
|
|
|
{PacketType::ClientDisconnectRequest, "ClientDisconnectRequest"},
|
|
|
|
{PacketType::HandshakeResponse, "HandshakeResponse"},
|
|
|
|
{PacketType::PlayerWarp, "PlayerWarp"},
|
|
|
|
{PacketType::FlyShip, "FlyShip"},
|
|
|
|
{PacketType::ChatSend, "ChatSend"},
|
|
|
|
{PacketType::CelestialRequest, "CelestialRequest"},
|
|
|
|
{PacketType::ClientContextUpdate, "ClientContextUpdate"},
|
|
|
|
{PacketType::WorldStart, "WorldStart"},
|
|
|
|
{PacketType::WorldStop, "WorldStop"},
|
|
|
|
{PacketType::WorldLayoutUpdate, "WorldLayoutUpdate"},
|
|
|
|
{PacketType::WorldParametersUpdate, "WorldParametersUpdate"},
|
|
|
|
{PacketType::CentralStructureUpdate, "CentralStructureUpdate"},
|
|
|
|
{PacketType::TileArrayUpdate, "TileArrayUpdate"},
|
|
|
|
{PacketType::TileUpdate, "TileUpdate"},
|
|
|
|
{PacketType::TileLiquidUpdate, "TileLiquidUpdate"},
|
|
|
|
{PacketType::TileDamageUpdate, "TileDamageUpdate"},
|
|
|
|
{PacketType::TileModificationFailure, "TileModificationFailure"},
|
|
|
|
{PacketType::GiveItem, "GiveItem"},
|
|
|
|
{PacketType::EnvironmentUpdate, "EnvironmentUpdate"},
|
|
|
|
{PacketType::UpdateTileProtection, "UpdateTileProtection"},
|
|
|
|
{PacketType::SetDungeonGravity, "SetDungeonGravity"},
|
|
|
|
{PacketType::SetDungeonBreathable, "SetDungeonBreathable"},
|
|
|
|
{PacketType::SetPlayerStart, "SetPlayerStart"},
|
|
|
|
{PacketType::FindUniqueEntityResponse, "FindUniqueEntityResponse"},
|
|
|
|
{PacketType::Pong, "Pong"},
|
|
|
|
{PacketType::ModifyTileList, "ModifyTileList"},
|
|
|
|
{PacketType::DamageTileGroup, "DamageTileGroup"},
|
|
|
|
{PacketType::CollectLiquid, "CollectLiquid"},
|
|
|
|
{PacketType::RequestDrop, "RequestDrop"},
|
|
|
|
{PacketType::SpawnEntity, "SpawnEntity"},
|
|
|
|
{PacketType::ConnectWire, "ConnectWire"},
|
|
|
|
{PacketType::DisconnectAllWires, "DisconnectAllWires"},
|
|
|
|
{PacketType::WorldClientStateUpdate, "WorldClientStateUpdate"},
|
|
|
|
{PacketType::FindUniqueEntity, "FindUniqueEntity"},
|
|
|
|
{PacketType::WorldStartAcknowledge, "WorldStartAcknowledge"},
|
|
|
|
{PacketType::Ping, "Ping"},
|
|
|
|
{PacketType::EntityCreate, "EntityCreate"},
|
|
|
|
{PacketType::EntityUpdateSet, "EntityUpdate"},
|
|
|
|
{PacketType::EntityDestroy, "EntityDestroy"},
|
|
|
|
{PacketType::EntityInteract, "EntityInteract"},
|
|
|
|
{PacketType::EntityInteractResult, "EntityInteractResult"},
|
|
|
|
{PacketType::HitRequest, "HitRequest"},
|
|
|
|
{PacketType::DamageRequest, "DamageRequest"},
|
|
|
|
{PacketType::DamageNotification, "DamageNotification"},
|
|
|
|
{PacketType::EntityMessage, "EntityMessage"},
|
|
|
|
{PacketType::EntityMessageResponse, "EntityMessageResponse"},
|
|
|
|
{PacketType::UpdateWorldProperties, "UpdateWorldProperties"},
|
|
|
|
{PacketType::StepUpdate, "StepUpdate"},
|
|
|
|
{PacketType::SystemWorldStart, "SystemWorldStart"},
|
|
|
|
{PacketType::SystemWorldUpdate, "SystemWorldUpdate"},
|
|
|
|
{PacketType::SystemObjectCreate, "SystemObjectCreate"},
|
|
|
|
{PacketType::SystemObjectDestroy, "SystemObjectDestroy"},
|
|
|
|
{PacketType::SystemShipCreate, "SystemShipCreate"},
|
|
|
|
{PacketType::SystemShipDestroy, "SystemShipDestroy"},
|
|
|
|
{PacketType::SystemObjectSpawn, "SystemObjectSpawn"}
|
|
|
|
};
|
|
|
|
|
2024-07-27 04:09:12 +00:00
|
|
|
EnumMap<NetCompressionMode> const NetCompressionModeNames {
|
|
|
|
{NetCompressionMode::None, "None"},
|
|
|
|
{NetCompressionMode::Zstd, "Zstd"}
|
|
|
|
};
|
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
Packet::~Packet() {}
|
|
|
|
|
2024-03-22 09:59:02 +00:00
|
|
|
void Packet::readLegacy(DataStream& ds) { read(ds); }
|
|
|
|
void Packet::writeLegacy(DataStream& ds) const { write(ds); }
|
|
|
|
void Packet::readJson(Json const& json) {}
|
|
|
|
Json Packet::writeJson() const { return JsonObject{}; }
|
2023-07-31 10:22:09 +00:00
|
|
|
|
2024-03-22 09:59:02 +00:00
|
|
|
PacketCompressionMode Packet::compressionMode() const { return m_compressionMode; }
|
|
|
|
void Packet::setCompressionMode(PacketCompressionMode compressionMode) { m_compressionMode = compressionMode; }
|
2023-07-31 10:22:09 +00:00
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
PacketPtr createPacket(PacketType type) {
|
2023-06-26 18:48:27 +00:00
|
|
|
switch (type) {
|
|
|
|
case PacketType::ProtocolRequest: return make_shared<ProtocolRequestPacket>();
|
|
|
|
case PacketType::ProtocolResponse: return make_shared<ProtocolResponsePacket>();
|
|
|
|
case PacketType::ServerDisconnect: return make_shared<ServerDisconnectPacket>();
|
|
|
|
case PacketType::ConnectSuccess: return make_shared<ConnectSuccessPacket>();
|
|
|
|
case PacketType::ConnectFailure: return make_shared<ConnectFailurePacket>();
|
|
|
|
case PacketType::HandshakeChallenge: return make_shared<HandshakeChallengePacket>();
|
|
|
|
case PacketType::ChatReceive: return make_shared<ChatReceivePacket>();
|
|
|
|
case PacketType::UniverseTimeUpdate: return make_shared<UniverseTimeUpdatePacket>();
|
|
|
|
case PacketType::CelestialResponse: return make_shared<CelestialResponsePacket>();
|
|
|
|
case PacketType::PlayerWarpResult: return make_shared<PlayerWarpResultPacket>();
|
|
|
|
case PacketType::PlanetTypeUpdate: return make_shared<PlanetTypeUpdatePacket>();
|
|
|
|
case PacketType::Pause: return make_shared<PausePacket>();
|
|
|
|
case PacketType::ServerInfo: return make_shared<ServerInfoPacket>();
|
|
|
|
case PacketType::ClientConnect: return make_shared<ClientConnectPacket>();
|
|
|
|
case PacketType::ClientDisconnectRequest: return make_shared<ClientDisconnectRequestPacket>();
|
|
|
|
case PacketType::HandshakeResponse: return make_shared<HandshakeResponsePacket>();
|
|
|
|
case PacketType::PlayerWarp: return make_shared<PlayerWarpPacket>();
|
|
|
|
case PacketType::FlyShip: return make_shared<FlyShipPacket>();
|
|
|
|
case PacketType::ChatSend: return make_shared<ChatSendPacket>();
|
|
|
|
case PacketType::CelestialRequest: return make_shared<CelestialRequestPacket>();
|
|
|
|
case PacketType::ClientContextUpdate: return make_shared<ClientContextUpdatePacket>();
|
|
|
|
case PacketType::WorldStart: return make_shared<WorldStartPacket>();
|
|
|
|
case PacketType::WorldStop: return make_shared<WorldStopPacket>();
|
|
|
|
case PacketType::WorldLayoutUpdate: return make_shared<WorldLayoutUpdatePacket>();
|
|
|
|
case PacketType::WorldParametersUpdate: return make_shared<WorldParametersUpdatePacket>();
|
|
|
|
case PacketType::CentralStructureUpdate: return make_shared<CentralStructureUpdatePacket>();
|
|
|
|
case PacketType::TileArrayUpdate: return make_shared<TileArrayUpdatePacket>();
|
|
|
|
case PacketType::TileUpdate: return make_shared<TileUpdatePacket>();
|
|
|
|
case PacketType::TileLiquidUpdate: return make_shared<TileLiquidUpdatePacket>();
|
|
|
|
case PacketType::TileDamageUpdate: return make_shared<TileDamageUpdatePacket>();
|
|
|
|
case PacketType::TileModificationFailure: return make_shared<TileModificationFailurePacket>();
|
|
|
|
case PacketType::GiveItem: return make_shared<GiveItemPacket>();
|
|
|
|
case PacketType::EnvironmentUpdate: return make_shared<EnvironmentUpdatePacket>();
|
|
|
|
case PacketType::UpdateTileProtection: return make_shared<UpdateTileProtectionPacket>();
|
|
|
|
case PacketType::SetDungeonGravity: return make_shared<SetDungeonGravityPacket>();
|
|
|
|
case PacketType::SetDungeonBreathable: return make_shared<SetDungeonBreathablePacket>();
|
|
|
|
case PacketType::SetPlayerStart: return make_shared<SetPlayerStartPacket>();
|
|
|
|
case PacketType::FindUniqueEntityResponse: return make_shared<FindUniqueEntityResponsePacket>();
|
|
|
|
case PacketType::Pong: return make_shared<PongPacket>();
|
|
|
|
case PacketType::ModifyTileList: return make_shared<ModifyTileListPacket>();
|
|
|
|
case PacketType::DamageTileGroup: return make_shared<DamageTileGroupPacket>();
|
|
|
|
case PacketType::CollectLiquid: return make_shared<CollectLiquidPacket>();
|
|
|
|
case PacketType::RequestDrop: return make_shared<RequestDropPacket>();
|
|
|
|
case PacketType::SpawnEntity: return make_shared<SpawnEntityPacket>();
|
|
|
|
case PacketType::ConnectWire: return make_shared<ConnectWirePacket>();
|
|
|
|
case PacketType::DisconnectAllWires: return make_shared<DisconnectAllWiresPacket>();
|
|
|
|
case PacketType::WorldClientStateUpdate: return make_shared<WorldClientStateUpdatePacket>();
|
|
|
|
case PacketType::FindUniqueEntity: return make_shared<FindUniqueEntityPacket>();
|
|
|
|
case PacketType::WorldStartAcknowledge: return make_shared<WorldStartAcknowledgePacket>();
|
|
|
|
case PacketType::Ping: return make_shared<PingPacket>();
|
|
|
|
case PacketType::EntityCreate: return make_shared<EntityCreatePacket>();
|
|
|
|
case PacketType::EntityUpdateSet: return make_shared<EntityUpdateSetPacket>();
|
|
|
|
case PacketType::EntityDestroy: return make_shared<EntityDestroyPacket>();
|
|
|
|
case PacketType::EntityInteract: return make_shared<EntityInteractPacket>();
|
|
|
|
case PacketType::EntityInteractResult: return make_shared<EntityInteractResultPacket>();
|
|
|
|
case PacketType::HitRequest: return make_shared<HitRequestPacket>();
|
|
|
|
case PacketType::DamageRequest: return make_shared<DamageRequestPacket>();
|
|
|
|
case PacketType::DamageNotification: return make_shared<DamageNotificationPacket>();
|
|
|
|
case PacketType::EntityMessage: return make_shared<EntityMessagePacket>();
|
|
|
|
case PacketType::EntityMessageResponse: return make_shared<EntityMessageResponsePacket>();
|
|
|
|
case PacketType::UpdateWorldProperties: return make_shared<UpdateWorldPropertiesPacket>();
|
|
|
|
case PacketType::StepUpdate: return make_shared<StepUpdatePacket>();
|
|
|
|
case PacketType::SystemWorldStart: return make_shared<SystemWorldStartPacket>();
|
|
|
|
case PacketType::SystemWorldUpdate: return make_shared<SystemWorldUpdatePacket>();
|
|
|
|
case PacketType::SystemObjectCreate: return make_shared<SystemObjectCreatePacket>();
|
|
|
|
case PacketType::SystemObjectDestroy: return make_shared<SystemObjectDestroyPacket>();
|
|
|
|
case PacketType::SystemShipCreate: return make_shared<SystemShipCreatePacket>();
|
|
|
|
case PacketType::SystemShipDestroy: return make_shared<SystemShipDestroyPacket>();
|
|
|
|
case PacketType::SystemObjectSpawn: return make_shared<SystemObjectSpawnPacket>();
|
|
|
|
default:
|
2023-06-27 10:23:44 +00:00
|
|
|
throw StarPacketException(strf("Unrecognized packet type {}", (unsigned int)type));
|
2023-06-26 18:48:27 +00:00
|
|
|
}
|
2023-06-20 04:33:09 +00:00
|
|
|
}
|
|
|
|
|
2024-03-19 08:42:06 +00:00
|
|
|
PacketPtr createPacket(PacketType type, Maybe<Json> const& args) {
|
2024-03-22 09:59:02 +00:00
|
|
|
auto packet = createPacket(type);
|
2024-03-19 08:42:06 +00:00
|
|
|
|
2024-03-22 09:59:02 +00:00
|
|
|
if (args && !args->isNull())
|
|
|
|
packet->readJson(*args);
|
|
|
|
|
|
|
|
return packet;
|
2024-03-19 04:46:50 +00:00
|
|
|
}
|
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
ProtocolRequestPacket::ProtocolRequestPacket()
|
|
|
|
: requestProtocolVersion(0) {}
|
|
|
|
|
|
|
|
ProtocolRequestPacket::ProtocolRequestPacket(VersionNumber requestProtocolVersion)
|
|
|
|
: requestProtocolVersion(requestProtocolVersion) {}
|
|
|
|
|
|
|
|
void ProtocolRequestPacket::read(DataStream& ds) {
|
|
|
|
ds.read(requestProtocolVersion);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolRequestPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(requestProtocolVersion);
|
|
|
|
}
|
|
|
|
|
2024-07-27 04:09:12 +00:00
|
|
|
ProtocolResponsePacket::ProtocolResponsePacket(bool allowed, Json info)
|
|
|
|
: allowed(allowed), info(info) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void ProtocolResponsePacket::read(DataStream& ds) {
|
|
|
|
ds.read(allowed);
|
2024-07-27 04:09:12 +00:00
|
|
|
if (compressionMode() == PacketCompressionMode::Enabled) {
|
|
|
|
// gross hack for backwards compatibility with older OpenSB servers
|
|
|
|
// can be removed later
|
|
|
|
auto externalBuffer = as<DataStreamExternalBuffer>(&ds);
|
|
|
|
if (!externalBuffer || !externalBuffer->atEnd())
|
|
|
|
ds.read(info);
|
|
|
|
}
|
2023-06-20 04:33:09 +00:00
|
|
|
}
|
|
|
|
|
2024-07-27 04:09:12 +00:00
|
|
|
void ProtocolResponsePacket::writeLegacy(DataStream& ds) const {
|
2023-06-20 04:33:09 +00:00
|
|
|
ds.write(allowed);
|
|
|
|
}
|
|
|
|
|
2024-07-27 04:09:12 +00:00
|
|
|
void ProtocolResponsePacket::write(DataStream& ds) const {
|
|
|
|
writeLegacy(ds);
|
|
|
|
ds.write(info);
|
|
|
|
}
|
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
ConnectSuccessPacket::ConnectSuccessPacket() {}
|
|
|
|
|
|
|
|
ConnectSuccessPacket::ConnectSuccessPacket(
|
|
|
|
ConnectionId clientId, Uuid serverUuid, CelestialBaseInformation celestialInformation)
|
2024-02-19 15:55:19 +00:00
|
|
|
: clientId(clientId), serverUuid(std::move(serverUuid)), celestialInformation(std::move(celestialInformation)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void ConnectSuccessPacket::read(DataStream& ds) {
|
|
|
|
ds.vuread(clientId);
|
|
|
|
ds.read(serverUuid);
|
|
|
|
ds.read(celestialInformation);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectSuccessPacket::write(DataStream& ds) const {
|
|
|
|
ds.vuwrite(clientId);
|
|
|
|
ds.write(serverUuid);
|
|
|
|
ds.write(celestialInformation);
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectFailurePacket::ConnectFailurePacket() {}
|
|
|
|
|
2024-02-19 15:55:19 +00:00
|
|
|
ConnectFailurePacket::ConnectFailurePacket(String reason) : reason(std::move(reason)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void ConnectFailurePacket::read(DataStream& ds) {
|
|
|
|
ds.read(reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectFailurePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
HandshakeChallengePacket::HandshakeChallengePacket() {}
|
|
|
|
|
|
|
|
HandshakeChallengePacket::HandshakeChallengePacket(ByteArray const& passwordSalt) : passwordSalt(passwordSalt) {}
|
|
|
|
|
|
|
|
void HandshakeChallengePacket::read(DataStream& ds) {
|
|
|
|
ds.read(passwordSalt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HandshakeChallengePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(passwordSalt);
|
|
|
|
}
|
|
|
|
|
|
|
|
ChatReceivePacket::ChatReceivePacket() {}
|
|
|
|
|
|
|
|
ChatReceivePacket::ChatReceivePacket(ChatReceivedMessage receivedMessage) : receivedMessage(receivedMessage) {}
|
|
|
|
|
|
|
|
void ChatReceivePacket::read(DataStream& ds) {
|
|
|
|
ds.read(receivedMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatReceivePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(receivedMessage);
|
|
|
|
}
|
|
|
|
|
2024-03-22 09:59:02 +00:00
|
|
|
void ChatReceivePacket::readJson(Json const& json) {
|
|
|
|
receivedMessage = ChatReceivedMessage(json.get("receivedMessage"));
|
|
|
|
}
|
|
|
|
|
|
|
|
Json ChatReceivePacket::writeJson() const {
|
|
|
|
return JsonObject{
|
|
|
|
{"receivedMessage", receivedMessage.toJson()}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
UniverseTimeUpdatePacket::UniverseTimeUpdatePacket() {
|
|
|
|
universeTime = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
UniverseTimeUpdatePacket::UniverseTimeUpdatePacket(double universeTime) : universeTime(universeTime) {}
|
|
|
|
|
|
|
|
void UniverseTimeUpdatePacket::read(DataStream& ds) {
|
|
|
|
ds.vfread(universeTime, 0.05);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UniverseTimeUpdatePacket::write(DataStream& ds) const {
|
|
|
|
ds.vfwrite(universeTime, 0.05);
|
|
|
|
}
|
|
|
|
|
|
|
|
CelestialResponsePacket::CelestialResponsePacket() {}
|
|
|
|
|
2024-02-19 15:55:19 +00:00
|
|
|
CelestialResponsePacket::CelestialResponsePacket(List<CelestialResponse> responses) : responses(std::move(responses)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void CelestialResponsePacket::read(DataStream& ds) {
|
|
|
|
ds.read(responses);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CelestialResponsePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(responses);
|
|
|
|
}
|
|
|
|
|
|
|
|
PlayerWarpResultPacket::PlayerWarpResultPacket() : warpActionInvalid(false) {}
|
|
|
|
|
|
|
|
PlayerWarpResultPacket::PlayerWarpResultPacket(bool success, WarpAction warpAction, bool warpActionInvalid)
|
2024-02-19 15:55:19 +00:00
|
|
|
: success(success), warpAction(std::move(warpAction)), warpActionInvalid(warpActionInvalid) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void PlayerWarpResultPacket::read(DataStream& ds) {
|
|
|
|
ds.read(success);
|
|
|
|
ds.read(warpAction);
|
|
|
|
ds.read(warpActionInvalid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerWarpResultPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(success);
|
|
|
|
ds.write(warpAction);
|
|
|
|
ds.write(warpActionInvalid);
|
|
|
|
}
|
|
|
|
|
|
|
|
PlanetTypeUpdatePacket::PlanetTypeUpdatePacket() {}
|
|
|
|
|
|
|
|
PlanetTypeUpdatePacket::PlanetTypeUpdatePacket(CelestialCoordinate coordinate)
|
|
|
|
: coordinate(coordinate) {}
|
|
|
|
|
|
|
|
void PlanetTypeUpdatePacket::read(DataStream& ds) {
|
|
|
|
ds.read(coordinate);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlanetTypeUpdatePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(coordinate);
|
|
|
|
}
|
|
|
|
|
|
|
|
PausePacket::PausePacket() {}
|
|
|
|
|
2024-03-19 02:35:55 +00:00
|
|
|
PausePacket::PausePacket(bool pause, float timescale) : pause(pause), timescale(timescale) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
2024-03-19 02:35:55 +00:00
|
|
|
void PausePacket::readLegacy(DataStream& ds) {
|
2023-06-20 04:33:09 +00:00
|
|
|
ds.read(pause);
|
2024-03-19 02:35:55 +00:00
|
|
|
timescale = 1.0f;
|
2023-06-20 04:33:09 +00:00
|
|
|
}
|
|
|
|
|
2024-03-19 02:35:55 +00:00
|
|
|
void PausePacket::read(DataStream& ds) {
|
|
|
|
readLegacy(ds);
|
|
|
|
ds.read(timescale);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PausePacket::writeLegacy(DataStream& ds) const {
|
2023-06-20 04:33:09 +00:00
|
|
|
ds.write(pause);
|
|
|
|
}
|
|
|
|
|
2024-03-19 02:35:55 +00:00
|
|
|
void PausePacket::write(DataStream& ds) const {
|
|
|
|
writeLegacy(ds);
|
|
|
|
ds.write(timescale);
|
|
|
|
}
|
|
|
|
|
2024-03-22 09:59:02 +00:00
|
|
|
void PausePacket::readJson(Json const& json) {
|
|
|
|
pause = json.getBool("pause");
|
|
|
|
timescale = json.getFloat("timescale", 1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
Json PausePacket::writeJson() const {
|
|
|
|
return JsonObject{
|
|
|
|
{"pause", pause},
|
|
|
|
{"timescale", timescale}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
ServerInfoPacket::ServerInfoPacket() {}
|
|
|
|
|
|
|
|
ServerInfoPacket::ServerInfoPacket(uint16_t players, uint16_t maxPlayers) :
|
|
|
|
players(players),
|
|
|
|
maxPlayers(maxPlayers) {}
|
|
|
|
|
|
|
|
void ServerInfoPacket::read(DataStream& ds)
|
|
|
|
{
|
|
|
|
ds.read(players);
|
|
|
|
ds.read(maxPlayers);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ServerInfoPacket::write(DataStream& ds) const
|
|
|
|
{
|
|
|
|
ds.write(players);
|
|
|
|
ds.write(maxPlayers);
|
|
|
|
}
|
|
|
|
|
2024-03-22 09:59:02 +00:00
|
|
|
void ServerInfoPacket::readJson(Json const& json) {
|
|
|
|
players = json.getUInt("players");
|
|
|
|
maxPlayers = json.getUInt("maxPlayers");
|
|
|
|
}
|
|
|
|
|
|
|
|
Json ServerInfoPacket::writeJson() const {
|
|
|
|
return JsonObject{
|
|
|
|
{"players", players},
|
|
|
|
{"maxPlayers", maxPlayers}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
ClientConnectPacket::ClientConnectPacket() {}
|
|
|
|
|
|
|
|
ClientConnectPacket::ClientConnectPacket(ByteArray assetsDigest, bool allowAssetsMismatch, Uuid playerUuid,
|
|
|
|
String playerName, String playerSpecies, WorldChunks shipChunks, ShipUpgrades shipUpgrades,
|
2024-08-13 06:23:01 +00:00
|
|
|
bool introComplete, String account, Json info)
|
2024-02-19 15:55:19 +00:00
|
|
|
: assetsDigest(std::move(assetsDigest)), allowAssetsMismatch(allowAssetsMismatch), playerUuid(std::move(playerUuid)),
|
|
|
|
playerName(std::move(playerName)), playerSpecies(std::move(playerSpecies)), shipChunks(std::move(shipChunks)),
|
2024-08-13 06:23:01 +00:00
|
|
|
shipUpgrades(std::move(shipUpgrades)), introComplete(std::move(introComplete)), account(std::move(account)), info(std::move(info)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
2024-03-14 10:41:53 +00:00
|
|
|
void ClientConnectPacket::readLegacy(DataStream& ds) {
|
2023-06-20 04:33:09 +00:00
|
|
|
ds.read(assetsDigest);
|
|
|
|
ds.read(allowAssetsMismatch);
|
|
|
|
ds.read(playerUuid);
|
|
|
|
ds.read(playerName);
|
|
|
|
ds.read(playerSpecies);
|
|
|
|
ds.read(shipChunks);
|
|
|
|
ds.read(shipUpgrades);
|
|
|
|
ds.read(introComplete);
|
|
|
|
ds.read(account);
|
2024-08-13 06:23:01 +00:00
|
|
|
info = Json();
|
2023-06-20 04:33:09 +00:00
|
|
|
}
|
|
|
|
|
2024-03-14 10:41:53 +00:00
|
|
|
void ClientConnectPacket::read(DataStream& ds) {
|
|
|
|
readLegacy(ds);
|
|
|
|
ds.read(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientConnectPacket::writeLegacy(DataStream& ds) const {
|
2023-06-20 04:33:09 +00:00
|
|
|
ds.write(assetsDigest);
|
|
|
|
ds.write(allowAssetsMismatch);
|
|
|
|
ds.write(playerUuid);
|
|
|
|
ds.write(playerName);
|
|
|
|
ds.write(playerSpecies);
|
|
|
|
ds.write(shipChunks);
|
|
|
|
ds.write(shipUpgrades);
|
|
|
|
ds.write(introComplete);
|
|
|
|
ds.write(account);
|
|
|
|
}
|
|
|
|
|
2024-03-14 10:41:53 +00:00
|
|
|
void ClientConnectPacket::write(DataStream& ds) const {
|
|
|
|
writeLegacy(ds);
|
|
|
|
ds.write(info);
|
|
|
|
}
|
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
ClientDisconnectRequestPacket::ClientDisconnectRequestPacket() {}
|
|
|
|
|
|
|
|
void ClientDisconnectRequestPacket::read(DataStream& ds) {
|
|
|
|
// Packets cannot be empty due to the way packet serialization is handled.
|
|
|
|
ds.read<uint8_t>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientDisconnectRequestPacket::write(DataStream& ds) const {
|
|
|
|
// Packets cannot be empty due to the way packet serialization is handled.
|
|
|
|
ds.write<uint8_t>(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
HandshakeResponsePacket::HandshakeResponsePacket() {}
|
|
|
|
|
|
|
|
HandshakeResponsePacket::HandshakeResponsePacket(ByteArray const& passHash) : passHash(passHash) {}
|
|
|
|
|
|
|
|
void HandshakeResponsePacket::read(DataStream& ds) {
|
|
|
|
ds.read(passHash);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HandshakeResponsePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(passHash);
|
|
|
|
}
|
|
|
|
|
|
|
|
PlayerWarpPacket::PlayerWarpPacket() {}
|
|
|
|
|
2024-02-19 15:55:19 +00:00
|
|
|
PlayerWarpPacket::PlayerWarpPacket(WarpAction action, bool deploy) : action(std::move(action)), deploy(std::move(deploy)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void PlayerWarpPacket::read(DataStream& ds) {
|
|
|
|
ds.read(action);
|
|
|
|
ds.read(deploy);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerWarpPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(action);
|
|
|
|
ds.write(deploy);
|
|
|
|
}
|
|
|
|
|
|
|
|
FlyShipPacket::FlyShipPacket() {}
|
|
|
|
|
2024-02-19 15:55:19 +00:00
|
|
|
FlyShipPacket::FlyShipPacket(Vec3I system, SystemLocation location) : system(std::move(system)), location(std::move(location)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void FlyShipPacket::read(DataStream& ds) {
|
|
|
|
ds.read(system);
|
|
|
|
ds.read(location);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlyShipPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(system);
|
|
|
|
ds.write(location);
|
|
|
|
}
|
|
|
|
|
|
|
|
ChatSendPacket::ChatSendPacket() : sendMode(ChatSendMode::Broadcast) {}
|
|
|
|
|
2024-02-19 15:55:19 +00:00
|
|
|
ChatSendPacket::ChatSendPacket(String text, ChatSendMode sendMode) : text(std::move(text)), sendMode(sendMode) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void ChatSendPacket::read(DataStream& ds) {
|
|
|
|
ds.read(text);
|
|
|
|
ds.read(sendMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatSendPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(text);
|
|
|
|
ds.write(sendMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
CelestialRequestPacket::CelestialRequestPacket() {}
|
|
|
|
|
2024-02-19 15:55:19 +00:00
|
|
|
CelestialRequestPacket::CelestialRequestPacket(List<CelestialRequest> requests) : requests(std::move(requests)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void CelestialRequestPacket::read(DataStream& ds) {
|
|
|
|
ds.read(requests);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CelestialRequestPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(requests);
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientContextUpdatePacket::ClientContextUpdatePacket() {}
|
|
|
|
|
2024-02-19 15:55:19 +00:00
|
|
|
ClientContextUpdatePacket::ClientContextUpdatePacket(ByteArray updateData) : updateData(std::move(updateData)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void ClientContextUpdatePacket::read(DataStream& ds) {
|
|
|
|
ds.read(updateData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientContextUpdatePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(updateData);
|
|
|
|
}
|
|
|
|
|
|
|
|
WorldStartPacket::WorldStartPacket() : clientId(), localInterpolationMode() {}
|
|
|
|
|
|
|
|
void WorldStartPacket::read(DataStream& ds) {
|
|
|
|
ds.read(templateData);
|
|
|
|
ds.read(skyData);
|
|
|
|
ds.read(weatherData);
|
|
|
|
ds.read(playerStart);
|
|
|
|
ds.read(playerRespawn);
|
|
|
|
ds.read(respawnInWorld);
|
|
|
|
ds.read(worldProperties);
|
|
|
|
ds.read(dungeonIdGravity);
|
|
|
|
ds.read(dungeonIdBreathable);
|
|
|
|
ds.read(protectedDungeonIds);
|
|
|
|
ds.read(clientId);
|
|
|
|
ds.read(localInterpolationMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorldStartPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(templateData);
|
|
|
|
ds.write(skyData);
|
|
|
|
ds.write(weatherData);
|
|
|
|
ds.write(playerStart);
|
|
|
|
ds.write(playerRespawn);
|
|
|
|
ds.write(respawnInWorld);
|
|
|
|
ds.write(worldProperties);
|
|
|
|
ds.write(dungeonIdGravity);
|
|
|
|
ds.write(dungeonIdBreathable);
|
|
|
|
ds.write(protectedDungeonIds);
|
|
|
|
ds.write(clientId);
|
|
|
|
ds.write(localInterpolationMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
WorldStopPacket::WorldStopPacket() {}
|
|
|
|
|
|
|
|
WorldStopPacket::WorldStopPacket(String const& reason) : reason(reason) {}
|
|
|
|
|
|
|
|
void WorldStopPacket::read(DataStream& ds) {
|
|
|
|
ds.read(reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorldStopPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
WorldLayoutUpdatePacket::WorldLayoutUpdatePacket() {}
|
|
|
|
|
|
|
|
WorldLayoutUpdatePacket::WorldLayoutUpdatePacket(Json const& layoutData) : layoutData(layoutData) {}
|
|
|
|
|
|
|
|
void WorldLayoutUpdatePacket::read(DataStream& ds) {
|
|
|
|
ds.read(layoutData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorldLayoutUpdatePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(layoutData);
|
|
|
|
}
|
|
|
|
|
|
|
|
WorldParametersUpdatePacket::WorldParametersUpdatePacket() {}
|
|
|
|
|
|
|
|
WorldParametersUpdatePacket::WorldParametersUpdatePacket(ByteArray const& parametersData) : parametersData(parametersData) {}
|
|
|
|
|
|
|
|
void WorldParametersUpdatePacket::read(DataStream& ds) {
|
|
|
|
ds.read(parametersData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorldParametersUpdatePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(parametersData);
|
|
|
|
}
|
|
|
|
|
|
|
|
CentralStructureUpdatePacket::CentralStructureUpdatePacket() {}
|
|
|
|
|
2024-02-19 15:55:19 +00:00
|
|
|
CentralStructureUpdatePacket::CentralStructureUpdatePacket(Json structureData) : structureData(std::move(structureData)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void CentralStructureUpdatePacket::read(DataStream& ds) {
|
|
|
|
ds.read(structureData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CentralStructureUpdatePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(structureData);
|
|
|
|
}
|
|
|
|
|
|
|
|
TileArrayUpdatePacket::TileArrayUpdatePacket() {}
|
|
|
|
|
|
|
|
void TileArrayUpdatePacket::read(DataStream& ds) {
|
|
|
|
ds.viread(min[0]);
|
|
|
|
ds.viread(min[1]);
|
|
|
|
|
|
|
|
size_t width, height;
|
|
|
|
ds.vuread(width);
|
|
|
|
ds.vuread(height);
|
|
|
|
array.resize(width, height);
|
|
|
|
for (size_t y = 0; y < height; ++y) {
|
|
|
|
for (size_t x = 0; x < width; ++x)
|
|
|
|
ds.read(array(x, y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileArrayUpdatePacket::write(DataStream& ds) const {
|
|
|
|
ds.viwrite(min[0]);
|
|
|
|
ds.viwrite(min[1]);
|
|
|
|
ds.vuwrite(array.size(0));
|
|
|
|
ds.vuwrite(array.size(1));
|
|
|
|
for (size_t y = 0; y < array.size(1); ++y) {
|
|
|
|
for (size_t x = 0; x < array.size(0); ++x)
|
|
|
|
ds.write(array(x, y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileUpdatePacket::read(DataStream& ds) {
|
|
|
|
ds.viread(position[0]);
|
|
|
|
ds.viread(position[1]);
|
|
|
|
ds.read(tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileUpdatePacket::write(DataStream& ds) const {
|
|
|
|
ds.viwrite(position[0]);
|
|
|
|
ds.viwrite(position[1]);
|
|
|
|
ds.write(tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
TileLiquidUpdatePacket::TileLiquidUpdatePacket() {}
|
|
|
|
|
|
|
|
TileLiquidUpdatePacket::TileLiquidUpdatePacket(Vec2I const& position, LiquidNetUpdate liquidUpdate)
|
|
|
|
: position(position), liquidUpdate(liquidUpdate) {}
|
|
|
|
|
|
|
|
void TileLiquidUpdatePacket::read(DataStream& ds) {
|
|
|
|
ds.viread(position[0]);
|
|
|
|
ds.viread(position[1]);
|
|
|
|
ds.read(liquidUpdate.liquid);
|
|
|
|
ds.read(liquidUpdate.level);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileLiquidUpdatePacket::write(DataStream& ds) const {
|
|
|
|
ds.viwrite(position[0]);
|
|
|
|
ds.viwrite(position[1]);
|
|
|
|
ds.write(liquidUpdate.liquid);
|
|
|
|
ds.write(liquidUpdate.level);
|
|
|
|
}
|
|
|
|
|
|
|
|
TileDamageUpdatePacket::TileDamageUpdatePacket() : layer(TileLayer::Foreground) {}
|
|
|
|
|
|
|
|
TileDamageUpdatePacket::TileDamageUpdatePacket(
|
|
|
|
Vec2I const& position, TileLayer layer, TileDamageStatus const& tileDamage)
|
|
|
|
: position(position), layer(layer), tileDamage(tileDamage) {}
|
|
|
|
|
|
|
|
void TileDamageUpdatePacket::read(DataStream& ds) {
|
|
|
|
ds.read(position);
|
|
|
|
ds.read(layer);
|
|
|
|
ds.read(tileDamage);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileDamageUpdatePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(position);
|
|
|
|
ds.write(layer);
|
|
|
|
ds.write(tileDamage);
|
|
|
|
}
|
|
|
|
|
|
|
|
TileModificationFailurePacket::TileModificationFailurePacket() {}
|
|
|
|
|
|
|
|
TileModificationFailurePacket::TileModificationFailurePacket(TileModificationList modifications)
|
|
|
|
: modifications(modifications) {}
|
|
|
|
|
|
|
|
void TileModificationFailurePacket::read(DataStream& ds) {
|
|
|
|
ds.readContainer(modifications);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileModificationFailurePacket::write(DataStream& ds) const {
|
|
|
|
ds.writeContainer(modifications);
|
|
|
|
}
|
|
|
|
|
|
|
|
GiveItemPacket::GiveItemPacket() {}
|
|
|
|
|
|
|
|
GiveItemPacket::GiveItemPacket(ItemDescriptor const& item) : item(item) {}
|
|
|
|
|
|
|
|
void GiveItemPacket::read(DataStream& ds) {
|
|
|
|
ds.read(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GiveItemPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(item);
|
|
|
|
}
|
|
|
|
|
2024-03-22 09:59:02 +00:00
|
|
|
void GiveItemPacket::readJson(Json const& json) {
|
|
|
|
item = ItemDescriptor(json.get("item"));
|
|
|
|
}
|
|
|
|
|
|
|
|
Json GiveItemPacket::writeJson() const {
|
|
|
|
return JsonObject{
|
|
|
|
{"item", item.toJson()}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
EnvironmentUpdatePacket::EnvironmentUpdatePacket() {}
|
|
|
|
|
|
|
|
EnvironmentUpdatePacket::EnvironmentUpdatePacket(ByteArray skyDelta, ByteArray weatherDelta)
|
2024-02-19 15:55:19 +00:00
|
|
|
: skyDelta(std::move(skyDelta)), weatherDelta(std::move(weatherDelta)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void EnvironmentUpdatePacket::read(DataStream& ds) {
|
|
|
|
ds.read(skyDelta);
|
|
|
|
ds.read(weatherDelta);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnvironmentUpdatePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(skyDelta);
|
|
|
|
ds.write(weatherDelta);
|
|
|
|
}
|
|
|
|
|
|
|
|
ModifyTileListPacket::ModifyTileListPacket() : allowEntityOverlap() {}
|
|
|
|
|
|
|
|
ModifyTileListPacket::ModifyTileListPacket(TileModificationList modifications, bool allowEntityOverlap)
|
|
|
|
: modifications(modifications), allowEntityOverlap(allowEntityOverlap) {}
|
|
|
|
|
|
|
|
void ModifyTileListPacket::read(DataStream& ds) {
|
|
|
|
ds.readContainer(modifications);
|
|
|
|
ds.read(allowEntityOverlap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModifyTileListPacket::write(DataStream& ds) const {
|
|
|
|
ds.writeContainer(modifications);
|
|
|
|
ds.write(allowEntityOverlap);
|
|
|
|
}
|
|
|
|
|
|
|
|
DamageTileGroupPacket::DamageTileGroupPacket() : layer(TileLayer::Foreground) {}
|
|
|
|
|
|
|
|
DamageTileGroupPacket::DamageTileGroupPacket(
|
|
|
|
List<Vec2I> tilePositions, TileLayer layer, Vec2F sourcePosition, TileDamage tileDamage, Maybe<EntityId> sourceEntity)
|
2024-02-19 15:55:19 +00:00
|
|
|
: tilePositions(std::move(tilePositions)), layer(layer), sourcePosition(sourcePosition), tileDamage(std::move(tileDamage)), sourceEntity(std::move(sourceEntity)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void DamageTileGroupPacket::read(DataStream& ds) {
|
|
|
|
ds.readContainer(tilePositions);
|
|
|
|
ds.read(layer);
|
|
|
|
ds.read(sourcePosition);
|
|
|
|
ds.read(tileDamage);
|
|
|
|
ds.read(sourceEntity);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DamageTileGroupPacket::write(DataStream& ds) const {
|
|
|
|
ds.writeContainer(tilePositions);
|
|
|
|
ds.write(layer);
|
|
|
|
ds.write(sourcePosition);
|
|
|
|
ds.write(tileDamage);
|
|
|
|
ds.write(sourceEntity);
|
|
|
|
}
|
|
|
|
|
|
|
|
CollectLiquidPacket::CollectLiquidPacket() {}
|
|
|
|
|
|
|
|
CollectLiquidPacket::CollectLiquidPacket(List<Vec2I> tilePositions, LiquidId liquidId)
|
2024-02-19 15:55:19 +00:00
|
|
|
: tilePositions(std::move(tilePositions)), liquidId(liquidId) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void CollectLiquidPacket::read(DataStream& ds) {
|
|
|
|
ds.readContainer(tilePositions);
|
|
|
|
ds.read(liquidId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectLiquidPacket::write(DataStream& ds) const {
|
|
|
|
ds.writeContainer(tilePositions);
|
|
|
|
ds.write(liquidId);
|
|
|
|
}
|
|
|
|
|
|
|
|
RequestDropPacket::RequestDropPacket() {
|
|
|
|
dropEntityId = NullEntityId;
|
|
|
|
}
|
|
|
|
|
|
|
|
RequestDropPacket::RequestDropPacket(EntityId dropEntityId) : dropEntityId(dropEntityId) {}
|
|
|
|
|
|
|
|
void RequestDropPacket::read(DataStream& ds) {
|
|
|
|
ds.viread(dropEntityId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestDropPacket::write(DataStream& ds) const {
|
|
|
|
ds.viwrite(dropEntityId);
|
|
|
|
}
|
|
|
|
|
|
|
|
SpawnEntityPacket::SpawnEntityPacket() {}
|
|
|
|
|
|
|
|
SpawnEntityPacket::SpawnEntityPacket(EntityType entityType, ByteArray storeData, ByteArray firstNetState)
|
2024-02-19 15:55:19 +00:00
|
|
|
: entityType(entityType), storeData(std::move(storeData)), firstNetState(std::move(firstNetState)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void SpawnEntityPacket::read(DataStream& ds) {
|
|
|
|
ds.read(entityType);
|
|
|
|
ds.read(storeData);
|
|
|
|
ds.read(firstNetState);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpawnEntityPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(entityType);
|
|
|
|
ds.write(storeData);
|
|
|
|
ds.write(firstNetState);
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityInteractPacket::EntityInteractPacket() {}
|
|
|
|
|
|
|
|
EntityInteractPacket::EntityInteractPacket(InteractRequest interactRequest, Uuid requestId)
|
|
|
|
: interactRequest(interactRequest), requestId(requestId) {}
|
|
|
|
|
|
|
|
void EntityInteractPacket::read(DataStream& ds) {
|
|
|
|
ds.read(interactRequest);
|
|
|
|
ds.read(requestId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EntityInteractPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(interactRequest);
|
|
|
|
ds.write(requestId);
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityInteractResultPacket::EntityInteractResultPacket() {}
|
|
|
|
|
|
|
|
EntityInteractResultPacket::EntityInteractResultPacket(InteractAction action, Uuid requestId, EntityId sourceEntityId)
|
|
|
|
: action(action), requestId(requestId), sourceEntityId(sourceEntityId) {}
|
|
|
|
|
|
|
|
void EntityInteractResultPacket::read(DataStream& ds) {
|
|
|
|
ds.read(action);
|
|
|
|
ds.read(requestId);
|
|
|
|
ds.read(sourceEntityId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EntityInteractResultPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(action);
|
|
|
|
ds.write(requestId);
|
|
|
|
ds.write(sourceEntityId);
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityCreatePacket::EntityCreatePacket() {
|
|
|
|
entityId = NullEntityId;
|
|
|
|
}
|
|
|
|
|
|
|
|
ServerDisconnectPacket::ServerDisconnectPacket() {}
|
|
|
|
|
2024-02-19 15:55:19 +00:00
|
|
|
ServerDisconnectPacket::ServerDisconnectPacket(String reason) : reason(std::move(reason)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void ServerDisconnectPacket::read(DataStream& ds) {
|
|
|
|
ds.read(reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ServerDisconnectPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectWirePacket::ConnectWirePacket() {}
|
|
|
|
|
|
|
|
ConnectWirePacket::ConnectWirePacket(WireConnection outputConnection, WireConnection inputConnection)
|
|
|
|
: outputConnection(outputConnection), inputConnection(inputConnection) {}
|
|
|
|
|
|
|
|
void ConnectWirePacket::read(DataStream& ds) {
|
|
|
|
ds.read(outputConnection);
|
|
|
|
ds.read(inputConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectWirePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(outputConnection);
|
|
|
|
ds.write(inputConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
DisconnectAllWiresPacket::DisconnectAllWiresPacket() {}
|
|
|
|
|
|
|
|
DisconnectAllWiresPacket::DisconnectAllWiresPacket(Vec2I entityPosition, WireNode wireNode)
|
|
|
|
: entityPosition(entityPosition), wireNode(wireNode) {}
|
|
|
|
|
|
|
|
void DisconnectAllWiresPacket::read(DataStream& ds) {
|
|
|
|
ds.viread(entityPosition[0]);
|
|
|
|
ds.viread(entityPosition[1]);
|
|
|
|
ds.read(wireNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisconnectAllWiresPacket::write(DataStream& ds) const {
|
|
|
|
ds.viwrite(entityPosition[0]);
|
|
|
|
ds.viwrite(entityPosition[1]);
|
|
|
|
ds.write(wireNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
WorldClientStateUpdatePacket::WorldClientStateUpdatePacket() {}
|
|
|
|
|
|
|
|
WorldClientStateUpdatePacket::WorldClientStateUpdatePacket(ByteArray const& worldClientStateDelta)
|
|
|
|
: worldClientStateDelta(worldClientStateDelta) {}
|
|
|
|
|
|
|
|
void WorldClientStateUpdatePacket::read(DataStream& ds) {
|
|
|
|
ds.read(worldClientStateDelta);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorldClientStateUpdatePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(worldClientStateDelta);
|
|
|
|
}
|
|
|
|
|
|
|
|
FindUniqueEntityPacket::FindUniqueEntityPacket() {}
|
|
|
|
|
|
|
|
FindUniqueEntityPacket::FindUniqueEntityPacket(String uniqueEntityId)
|
2024-02-19 15:55:19 +00:00
|
|
|
: uniqueEntityId(std::move(uniqueEntityId)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void FindUniqueEntityPacket::read(DataStream& ds) {
|
|
|
|
ds.read(uniqueEntityId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FindUniqueEntityPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(uniqueEntityId);
|
|
|
|
}
|
|
|
|
|
|
|
|
WorldStartAcknowledgePacket::WorldStartAcknowledgePacket() {}
|
|
|
|
|
|
|
|
void WorldStartAcknowledgePacket::read(DataStream& ds) {
|
|
|
|
// Packets can't be empty, read the trash data
|
|
|
|
ds.read<bool>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorldStartAcknowledgePacket::write(DataStream& ds) const {
|
|
|
|
// Packets can't be empty, write some trash data
|
|
|
|
ds.write<bool>(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
PingPacket::PingPacket() {}
|
2024-04-04 03:35:36 +00:00
|
|
|
PingPacket::PingPacket(int64_t time) : time(time) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
2024-04-04 03:35:36 +00:00
|
|
|
void PingPacket::readLegacy(DataStream& ds) {
|
2023-06-20 04:33:09 +00:00
|
|
|
// Packets can't be empty, read the trash data
|
|
|
|
ds.read<bool>();
|
2024-04-04 03:35:36 +00:00
|
|
|
time = 0;
|
2023-06-20 04:33:09 +00:00
|
|
|
}
|
|
|
|
|
2024-04-04 03:35:36 +00:00
|
|
|
void PingPacket::read(DataStream& ds) {
|
|
|
|
ds.readVlqI(time);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PingPacket::writeLegacy(DataStream& ds) const {
|
2023-06-20 04:33:09 +00:00
|
|
|
// Packets can't be empty, write some trash data
|
2024-04-04 03:35:36 +00:00
|
|
|
ds.write<bool>(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PingPacket::write(DataStream& ds) const {
|
|
|
|
ds.writeVlqI(time);
|
2023-06-20 04:33:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EntityCreatePacket::EntityCreatePacket(EntityType entityType, ByteArray storeData, ByteArray firstNetState, EntityId entityId)
|
2024-02-19 15:55:19 +00:00
|
|
|
: entityType(entityType), storeData(std::move(storeData)), firstNetState(std::move(firstNetState)), entityId(entityId) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void EntityCreatePacket::read(DataStream& ds) {
|
|
|
|
ds.read(entityType);
|
|
|
|
ds.read(storeData);
|
|
|
|
ds.read(firstNetState);
|
|
|
|
ds.viread(entityId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EntityCreatePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(entityType);
|
|
|
|
ds.write(storeData);
|
|
|
|
ds.write(firstNetState);
|
|
|
|
ds.viwrite(entityId);
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityUpdateSetPacket::EntityUpdateSetPacket(ConnectionId forConnection) : forConnection(forConnection) {}
|
|
|
|
|
|
|
|
void EntityUpdateSetPacket::read(DataStream& ds) {
|
|
|
|
ds.vuread(forConnection);
|
|
|
|
ds.readMapContainer(deltas,
|
|
|
|
[](DataStream& ds, EntityId& entityId, ByteArray& delta) {
|
|
|
|
ds.viread(entityId);
|
|
|
|
ds.read(delta);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void EntityUpdateSetPacket::write(DataStream& ds) const {
|
|
|
|
ds.vuwrite(forConnection);
|
|
|
|
ds.writeMapContainer(deltas, [](DataStream& ds, EntityId const& entityId, ByteArray const& delta) {
|
|
|
|
ds.viwrite(entityId);
|
|
|
|
ds.write(delta);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityDestroyPacket::EntityDestroyPacket() {
|
|
|
|
entityId = NullEntityId;
|
|
|
|
death = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityDestroyPacket::EntityDestroyPacket(EntityId entityId, ByteArray finalNetState, bool death)
|
2024-02-19 15:55:19 +00:00
|
|
|
: entityId(entityId), finalNetState(std::move(finalNetState)), death(death) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void EntityDestroyPacket::read(DataStream& ds) {
|
|
|
|
ds.viread(entityId);
|
|
|
|
ds.read(finalNetState);
|
|
|
|
ds.read(death);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EntityDestroyPacket::write(DataStream& ds) const {
|
|
|
|
ds.viwrite(entityId);
|
|
|
|
ds.write(finalNetState);
|
|
|
|
ds.write(death);
|
|
|
|
}
|
|
|
|
|
|
|
|
HitRequestPacket::HitRequestPacket() {}
|
|
|
|
|
2024-02-19 15:55:19 +00:00
|
|
|
HitRequestPacket::HitRequestPacket(RemoteHitRequest remoteHitRequest) : remoteHitRequest(std::move(remoteHitRequest)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void HitRequestPacket::read(DataStream& ds) {
|
|
|
|
ds.read(remoteHitRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HitRequestPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(remoteHitRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
DamageRequestPacket::DamageRequestPacket() {}
|
|
|
|
|
|
|
|
DamageRequestPacket::DamageRequestPacket(RemoteDamageRequest remoteDamageRequest)
|
2024-02-19 15:55:19 +00:00
|
|
|
: remoteDamageRequest(std::move(remoteDamageRequest)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void DamageRequestPacket::read(DataStream& ds) {
|
|
|
|
ds.read(remoteDamageRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DamageRequestPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(remoteDamageRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
DamageNotificationPacket::DamageNotificationPacket() {}
|
|
|
|
|
|
|
|
DamageNotificationPacket::DamageNotificationPacket(RemoteDamageNotification remoteDamageNotification)
|
2024-02-19 15:55:19 +00:00
|
|
|
: remoteDamageNotification(std::move(remoteDamageNotification)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void DamageNotificationPacket::read(DataStream& ds) {
|
|
|
|
ds.read(remoteDamageNotification);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DamageNotificationPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(remoteDamageNotification);
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityMessagePacket::EntityMessagePacket() {}
|
|
|
|
|
|
|
|
EntityMessagePacket::EntityMessagePacket(Variant<EntityId, String> entityId, String message, JsonArray args, Uuid uuid, ConnectionId fromConnection)
|
2024-02-19 15:55:19 +00:00
|
|
|
: entityId(entityId), message(std::move(message)), args(std::move(args)), uuid(uuid), fromConnection(fromConnection) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void EntityMessagePacket::read(DataStream& ds) {
|
|
|
|
ds.read(entityId);
|
|
|
|
ds.read(message);
|
|
|
|
ds.read(args);
|
|
|
|
ds.read(uuid);
|
|
|
|
ds.read(fromConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EntityMessagePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(entityId);
|
|
|
|
ds.write(message);
|
|
|
|
ds.write(args);
|
|
|
|
ds.write(uuid);
|
|
|
|
ds.write(fromConnection);
|
|
|
|
}
|
|
|
|
|
2024-03-22 09:59:02 +00:00
|
|
|
void EntityMessagePacket::readJson(Json const& json) {
|
|
|
|
auto jEntityId = json.get("entityId");
|
|
|
|
if (jEntityId.canConvert(Json::Type::Int))
|
|
|
|
entityId = (EntityId)jEntityId.toInt();
|
|
|
|
else
|
|
|
|
entityId = jEntityId.toString();
|
|
|
|
message = json.getString("message");
|
|
|
|
args = json.getArray("args");
|
|
|
|
uuid = Uuid(json.getString("uuid"));
|
|
|
|
fromConnection = json.getUInt("fromConnection");
|
|
|
|
}
|
|
|
|
|
|
|
|
Json EntityMessagePacket::writeJson() const {
|
|
|
|
return JsonObject{
|
|
|
|
{"entityId", entityId.is<EntityId>() ? Json(entityId.get<EntityId>()) : Json(entityId.get<String>())},
|
|
|
|
{"message", message},
|
|
|
|
{"args", args},
|
|
|
|
{"uuid", uuid.hex()},
|
|
|
|
{"fromConnection", fromConnection}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
EntityMessageResponsePacket::EntityMessageResponsePacket() {}
|
|
|
|
|
|
|
|
EntityMessageResponsePacket::EntityMessageResponsePacket(Either<String, Json> response, Uuid uuid)
|
2024-02-19 15:55:19 +00:00
|
|
|
: response(std::move(response)), uuid(uuid) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void EntityMessageResponsePacket::read(DataStream& ds) {
|
|
|
|
ds.read(response);
|
|
|
|
ds.read(uuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EntityMessageResponsePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(response);
|
|
|
|
ds.write(uuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateWorldPropertiesPacket::UpdateWorldPropertiesPacket() {}
|
|
|
|
|
|
|
|
UpdateWorldPropertiesPacket::UpdateWorldPropertiesPacket(JsonObject const& updatedProperties)
|
|
|
|
: updatedProperties(updatedProperties) {}
|
|
|
|
|
|
|
|
void UpdateWorldPropertiesPacket::read(DataStream& ds) {
|
|
|
|
ds.readMapContainer(updatedProperties);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateWorldPropertiesPacket::write(DataStream& ds) const {
|
|
|
|
ds.writeMapContainer(updatedProperties);
|
|
|
|
}
|
|
|
|
|
2024-03-22 09:59:02 +00:00
|
|
|
|
|
|
|
void UpdateWorldPropertiesPacket::readJson(Json const& json) {
|
|
|
|
updatedProperties = json.getObject("updatedProperties");
|
|
|
|
}
|
|
|
|
|
|
|
|
Json UpdateWorldPropertiesPacket::writeJson() const {
|
|
|
|
return JsonObject{
|
|
|
|
{"updatedProperties", updatedProperties},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
UpdateTileProtectionPacket::UpdateTileProtectionPacket() {}
|
|
|
|
|
|
|
|
UpdateTileProtectionPacket::UpdateTileProtectionPacket(DungeonId dungeonId, bool isProtected)
|
|
|
|
: dungeonId(dungeonId), isProtected(isProtected) {}
|
|
|
|
|
|
|
|
void UpdateTileProtectionPacket::read(DataStream& ds) {
|
|
|
|
ds.read(dungeonId);
|
|
|
|
ds.read(isProtected);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateTileProtectionPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(dungeonId);
|
|
|
|
ds.write(isProtected);
|
|
|
|
}
|
|
|
|
|
2024-03-22 09:59:02 +00:00
|
|
|
void UpdateTileProtectionPacket::readJson(Json const& json) {
|
|
|
|
dungeonId = json.getUInt("dungeonId");
|
|
|
|
isProtected = json.getBool("isProtected");
|
|
|
|
}
|
|
|
|
|
|
|
|
Json UpdateTileProtectionPacket::writeJson() const {
|
|
|
|
return JsonObject{
|
|
|
|
{"dungeonId", dungeonId},
|
|
|
|
{"isProtected", isProtected}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
SetDungeonGravityPacket::SetDungeonGravityPacket() {}
|
|
|
|
|
|
|
|
SetDungeonGravityPacket::SetDungeonGravityPacket(DungeonId dungeonId, Maybe<float> gravity)
|
2024-02-19 15:55:19 +00:00
|
|
|
: dungeonId(std::move(dungeonId)), gravity(std::move(gravity)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void SetDungeonGravityPacket::read(DataStream& ds) {
|
|
|
|
ds.read(dungeonId);
|
|
|
|
ds.read(gravity);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetDungeonGravityPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(dungeonId);
|
|
|
|
ds.write(gravity);
|
|
|
|
}
|
|
|
|
|
2024-03-22 09:59:02 +00:00
|
|
|
void SetDungeonGravityPacket::readJson(Json const& json) {
|
|
|
|
dungeonId = json.getUInt("dungeonId");
|
|
|
|
gravity = json.optFloat("gravity");
|
|
|
|
}
|
|
|
|
|
|
|
|
Json SetDungeonGravityPacket::writeJson() const {
|
|
|
|
return JsonObject{
|
|
|
|
{"dungeonId", dungeonId},
|
|
|
|
{"gravity", jsonFromMaybe<float>(gravity)}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
SetDungeonBreathablePacket::SetDungeonBreathablePacket() {}
|
|
|
|
|
|
|
|
SetDungeonBreathablePacket::SetDungeonBreathablePacket(DungeonId dungeonId, Maybe<bool> breathable)
|
2024-02-19 15:55:19 +00:00
|
|
|
: dungeonId(std::move(dungeonId)), breathable(std::move(breathable)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void SetDungeonBreathablePacket::read(DataStream& ds) {
|
|
|
|
ds.read(dungeonId);
|
|
|
|
ds.read(breathable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetDungeonBreathablePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(dungeonId);
|
|
|
|
ds.write(breathable);
|
|
|
|
}
|
|
|
|
|
2024-03-22 09:59:02 +00:00
|
|
|
void SetDungeonBreathablePacket::readJson(Json const& json) {
|
|
|
|
dungeonId = json.getUInt("dungeonId");
|
|
|
|
breathable = json.optBool("breathable");
|
|
|
|
}
|
|
|
|
|
|
|
|
Json SetDungeonBreathablePacket::writeJson() const {
|
|
|
|
return JsonObject{
|
|
|
|
{"dungeonId", dungeonId},
|
|
|
|
{"breathable", jsonFromMaybe<bool>(breathable)}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
SetPlayerStartPacket::SetPlayerStartPacket() {}
|
|
|
|
|
|
|
|
SetPlayerStartPacket::SetPlayerStartPacket(Vec2F playerStart, bool respawnInWorld) : playerStart(playerStart), respawnInWorld(respawnInWorld) {}
|
|
|
|
|
|
|
|
void SetPlayerStartPacket::read(DataStream& ds) {
|
|
|
|
ds.read(playerStart);
|
|
|
|
ds.read(respawnInWorld);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetPlayerStartPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(playerStart);
|
|
|
|
ds.write(respawnInWorld);
|
|
|
|
}
|
|
|
|
|
2024-03-22 09:59:02 +00:00
|
|
|
void SetPlayerStartPacket::readJson(Json const& json) {
|
|
|
|
playerStart = jsonToVec2F(json.get("playerStart"));
|
|
|
|
respawnInWorld = json.getBool("respawnInWorld");
|
|
|
|
}
|
|
|
|
|
|
|
|
Json SetPlayerStartPacket::writeJson() const {
|
|
|
|
return JsonObject{
|
|
|
|
{"playerStart", jsonFromVec2F(playerStart)},
|
|
|
|
{"respawnInWorld", respawnInWorld}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
FindUniqueEntityResponsePacket::FindUniqueEntityResponsePacket() {}
|
|
|
|
|
|
|
|
FindUniqueEntityResponsePacket::FindUniqueEntityResponsePacket(String uniqueEntityId, Maybe<Vec2F> entityPosition)
|
2024-02-19 15:55:19 +00:00
|
|
|
: uniqueEntityId(std::move(uniqueEntityId)), entityPosition(std::move(entityPosition)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void FindUniqueEntityResponsePacket::read(DataStream& ds) {
|
|
|
|
ds.read(uniqueEntityId);
|
|
|
|
ds.read(entityPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FindUniqueEntityResponsePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(uniqueEntityId);
|
|
|
|
ds.write(entityPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
PongPacket::PongPacket() {}
|
2024-04-04 03:35:36 +00:00
|
|
|
PongPacket::PongPacket(int64_t time) : time(time) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
2024-04-04 03:35:36 +00:00
|
|
|
void PongPacket::readLegacy(DataStream& ds) {
|
2023-06-20 04:33:09 +00:00
|
|
|
// Packets can't be empty, read the trash data
|
|
|
|
ds.read<bool>();
|
2024-04-04 03:35:36 +00:00
|
|
|
time = 0;
|
2023-06-20 04:33:09 +00:00
|
|
|
}
|
|
|
|
|
2024-04-04 03:35:36 +00:00
|
|
|
void PongPacket::read(DataStream& ds) {
|
|
|
|
ds.readVlqI(time);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PongPacket::writeLegacy(DataStream& ds) const {
|
2023-06-20 04:33:09 +00:00
|
|
|
// Packets can't be empty, write some trash data
|
|
|
|
ds.write<bool>(false);
|
|
|
|
}
|
|
|
|
|
2024-04-04 03:35:36 +00:00
|
|
|
void PongPacket::write(DataStream& ds) const {
|
|
|
|
ds.writeVlqI(time);
|
|
|
|
}
|
|
|
|
|
2024-03-17 06:33:31 +00:00
|
|
|
StepUpdatePacket::StepUpdatePacket() : remoteTime(0.0) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
2024-03-18 11:09:48 +00:00
|
|
|
StepUpdatePacket::StepUpdatePacket(double remoteTime) : remoteTime(remoteTime) {}
|
2024-03-17 06:33:31 +00:00
|
|
|
|
|
|
|
void StepUpdatePacket::readLegacy(DataStream& ds) {
|
|
|
|
auto steps = ds.readVlqU();
|
|
|
|
remoteTime = double(steps) / 60.0;
|
|
|
|
}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void StepUpdatePacket::read(DataStream& ds) {
|
2024-03-17 12:09:42 +00:00
|
|
|
ds.read(remoteTime);
|
2024-03-17 06:33:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StepUpdatePacket::writeLegacy(DataStream& ds) const {
|
|
|
|
ds.writeVlqU((uint64_t)round(remoteTime * 60.0));
|
2023-06-20 04:33:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StepUpdatePacket::write(DataStream& ds) const {
|
2024-03-17 06:33:31 +00:00
|
|
|
ds.write(remoteTime);
|
2023-06-20 04:33:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SystemWorldStartPacket::SystemWorldStartPacket() {}
|
|
|
|
|
|
|
|
SystemWorldStartPacket::SystemWorldStartPacket(Vec3I location, List<ByteArray> objectStores, List<ByteArray> shipStores, pair<Uuid, SystemLocation> clientShip)
|
2024-02-19 15:55:19 +00:00
|
|
|
: location(std::move(location)), objectStores(std::move(objectStores)), shipStores(std::move(shipStores)), clientShip(std::move(clientShip)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void SystemWorldStartPacket::read(DataStream& ds) {
|
|
|
|
ds.read(location);
|
|
|
|
ds.read(objectStores);
|
|
|
|
ds.read(shipStores);
|
|
|
|
ds.read(clientShip);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemWorldStartPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(location);
|
|
|
|
ds.write(objectStores);
|
|
|
|
ds.write(shipStores);
|
|
|
|
ds.write(clientShip);
|
|
|
|
}
|
|
|
|
|
|
|
|
SystemWorldUpdatePacket::SystemWorldUpdatePacket() {}
|
|
|
|
|
|
|
|
SystemWorldUpdatePacket::SystemWorldUpdatePacket(HashMap<Uuid, ByteArray> objectUpdates, HashMap<Uuid, ByteArray> shipUpdates)
|
2024-02-19 15:55:19 +00:00
|
|
|
: objectUpdates(std::move(objectUpdates)), shipUpdates(std::move(shipUpdates)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void SystemWorldUpdatePacket::read(DataStream& ds) {
|
|
|
|
ds.read(objectUpdates);
|
|
|
|
ds.read(shipUpdates);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemWorldUpdatePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(objectUpdates);
|
|
|
|
ds.write(shipUpdates);
|
|
|
|
}
|
|
|
|
|
|
|
|
SystemObjectCreatePacket::SystemObjectCreatePacket() {}
|
|
|
|
|
2024-02-19 15:55:19 +00:00
|
|
|
SystemObjectCreatePacket::SystemObjectCreatePacket(ByteArray objectStore) : objectStore(std::move(objectStore)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void SystemObjectCreatePacket::read(DataStream& ds) {
|
|
|
|
ds.read(objectStore);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemObjectCreatePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(objectStore);
|
|
|
|
}
|
|
|
|
|
|
|
|
SystemObjectDestroyPacket::SystemObjectDestroyPacket() {}
|
|
|
|
|
2024-02-19 15:55:19 +00:00
|
|
|
SystemObjectDestroyPacket::SystemObjectDestroyPacket(Uuid objectUuid) : objectUuid(std::move(objectUuid)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void SystemObjectDestroyPacket::read(DataStream& ds) {
|
|
|
|
ds.read(objectUuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemObjectDestroyPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(objectUuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
SystemShipCreatePacket::SystemShipCreatePacket() {}
|
|
|
|
|
2024-02-19 15:55:19 +00:00
|
|
|
SystemShipCreatePacket::SystemShipCreatePacket(ByteArray shipStore) : shipStore(std::move(shipStore)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void SystemShipCreatePacket::read(DataStream& ds) {
|
|
|
|
ds.read(shipStore);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemShipCreatePacket::write(DataStream& ds) const {
|
|
|
|
ds.write(shipStore);
|
|
|
|
}
|
|
|
|
|
|
|
|
SystemShipDestroyPacket::SystemShipDestroyPacket() {}
|
|
|
|
|
2024-02-19 15:55:19 +00:00
|
|
|
SystemShipDestroyPacket::SystemShipDestroyPacket(Uuid shipUuid) : shipUuid(std::move(shipUuid)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void SystemShipDestroyPacket::read(DataStream& ds) {
|
|
|
|
ds.read(shipUuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemShipDestroyPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(shipUuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
SystemObjectSpawnPacket::SystemObjectSpawnPacket() {}
|
|
|
|
|
|
|
|
SystemObjectSpawnPacket::SystemObjectSpawnPacket(String typeName, Uuid uuid, Maybe<Vec2F> position, JsonObject parameters)
|
2024-02-19 15:55:19 +00:00
|
|
|
: typeName(std::move(typeName)), uuid(std::move(uuid)), position(std::move(position)), parameters(std::move(parameters)) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void SystemObjectSpawnPacket::read(DataStream& ds) {
|
|
|
|
ds.read(typeName);
|
|
|
|
ds.read(uuid);
|
|
|
|
ds.read(position);
|
|
|
|
ds.read(parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemObjectSpawnPacket::write(DataStream& ds) const {
|
|
|
|
ds.write(typeName);
|
|
|
|
ds.write(uuid);
|
|
|
|
ds.write(position);
|
|
|
|
ds.write(parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|