1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-24 23:23:51 +00:00
openmw-tes3mp/components/openmw-mp/Packets/Worldstate/PacketClientScriptSettings.cpp
David Cernat e424bd9bc3 [General] Implement ClientScriptSettings packet, part 2
The packet can now set which client globals get packets sent about them when their values change on clients.
2019-09-14 09:37:19 +03:00

51 lines
1.3 KiB
C++

#include "PacketClientScriptSettings.hpp"
#include <components/openmw-mp/NetworkMessages.hpp>
using namespace mwmp;
PacketClientScriptSettings::PacketClientScriptSettings(RakNet::RakPeerInterface *peer) : WorldstatePacket(peer)
{
packetID = ID_CLIENT_SCRIPT_SETTINGS;
orderChannel = CHANNEL_WORLDSTATE;
}
void PacketClientScriptSettings::Packet(RakNet::BitStream *bs, bool send)
{
WorldstatePacket::Packet(bs, send);
uint32_t clientScriptsCount;
if (send)
clientScriptsCount = static_cast<uint32_t>(worldstate->synchronizedClientScriptIds.size());
RW(clientScriptsCount, send);
if (!send)
{
worldstate->synchronizedClientScriptIds.clear();
worldstate->synchronizedClientScriptIds.resize(clientScriptsCount);
}
for (auto &&clientScriptId : worldstate->synchronizedClientScriptIds)
{
RW(clientScriptId, send);
}
uint32_t clientGlobalsCount;
if (send)
clientGlobalsCount = static_cast<uint32_t>(worldstate->synchronizedClientGlobalIds.size());
RW(clientGlobalsCount, send);
if (!send)
{
worldstate->synchronizedClientGlobalIds.clear();
worldstate->synchronizedClientGlobalIds.resize(clientGlobalsCount);
}
for (auto &&clientGlobalId : worldstate->synchronizedClientGlobalIds)
{
RW(clientGlobalId, send);
}
}