mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-07-04 09:21:35 +00:00
[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.
This commit is contained in:
parent
3acfbad55d
commit
e424bd9bc3
8 changed files with 86 additions and 11 deletions
|
@ -158,6 +158,11 @@ void WorldstateFunctions::AddSynchronizedClientScriptId(const char *scriptId) no
|
||||||
writeWorldstate.synchronizedClientScriptIds.push_back(scriptId);
|
writeWorldstate.synchronizedClientScriptIds.push_back(scriptId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldstateFunctions::AddSynchronizedClientGlobalId(const char *globalId) noexcept
|
||||||
|
{
|
||||||
|
writeWorldstate.synchronizedClientGlobalIds.push_back(globalId);
|
||||||
|
}
|
||||||
|
|
||||||
void WorldstateFunctions::AddEnforcedCollisionRefId(const char *refId) noexcept
|
void WorldstateFunctions::AddEnforcedCollisionRefId(const char *refId) noexcept
|
||||||
{
|
{
|
||||||
writeWorldstate.enforcedCollisionRefIds.push_back(refId);
|
writeWorldstate.enforcedCollisionRefIds.push_back(refId);
|
||||||
|
@ -168,6 +173,11 @@ void WorldstateFunctions::ClearSynchronizedClientScriptIds() noexcept
|
||||||
writeWorldstate.synchronizedClientScriptIds.clear();
|
writeWorldstate.synchronizedClientScriptIds.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldstateFunctions::ClearSynchronizedClientGlobalIds() noexcept
|
||||||
|
{
|
||||||
|
writeWorldstate.synchronizedClientGlobalIds.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void WorldstateFunctions::ClearEnforcedCollisionRefIds() noexcept
|
void WorldstateFunctions::ClearEnforcedCollisionRefIds() noexcept
|
||||||
{
|
{
|
||||||
writeWorldstate.enforcedCollisionRefIds.clear();
|
writeWorldstate.enforcedCollisionRefIds.clear();
|
||||||
|
|
|
@ -44,9 +44,11 @@
|
||||||
{"UseActorCollisionForPlacedObjects", WorldstateFunctions::UseActorCollisionForPlacedObjects},\
|
{"UseActorCollisionForPlacedObjects", WorldstateFunctions::UseActorCollisionForPlacedObjects},\
|
||||||
\
|
\
|
||||||
{"AddSynchronizedClientScriptId", WorldstateFunctions::AddSynchronizedClientScriptId},\
|
{"AddSynchronizedClientScriptId", WorldstateFunctions::AddSynchronizedClientScriptId},\
|
||||||
|
{"AddSynchronizedClientGlobalId", WorldstateFunctions::AddSynchronizedClientGlobalId},\
|
||||||
{"AddEnforcedCollisionRefId", WorldstateFunctions::AddEnforcedCollisionRefId},\
|
{"AddEnforcedCollisionRefId", WorldstateFunctions::AddEnforcedCollisionRefId},\
|
||||||
\
|
\
|
||||||
{"ClearSynchronizedClientScriptIds", WorldstateFunctions::ClearSynchronizedClientScriptIds},\
|
{"ClearSynchronizedClientScriptIds", WorldstateFunctions::ClearSynchronizedClientScriptIds},\
|
||||||
|
{"ClearSynchronizedClientGlobalIds", WorldstateFunctions::ClearSynchronizedClientGlobalIds},\
|
||||||
{"ClearEnforcedCollisionRefIds", WorldstateFunctions::ClearEnforcedCollisionRefIds},\
|
{"ClearEnforcedCollisionRefIds", WorldstateFunctions::ClearEnforcedCollisionRefIds},\
|
||||||
\
|
\
|
||||||
{"SaveMapTileImageFile", WorldstateFunctions::SaveMapTileImageFile},\
|
{"SaveMapTileImageFile", WorldstateFunctions::SaveMapTileImageFile},\
|
||||||
|
@ -298,14 +300,23 @@ public:
|
||||||
static void UseActorCollisionForPlacedObjects(bool useActorCollision) noexcept;
|
static void UseActorCollisionForPlacedObjects(bool useActorCollision) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Add an ID to the list of script IDs whose variables should all be synchronized
|
* \brief Add an ID to the list of script IDs whose variable changes should be sent to the
|
||||||
* across players.
|
* the server by clients.
|
||||||
*
|
*
|
||||||
* \param scriptId The ID.
|
* \param scriptId The ID.
|
||||||
* \return void
|
* \return void
|
||||||
*/
|
*/
|
||||||
static void AddSynchronizedClientScriptId(const char* scriptId) noexcept;
|
static void AddSynchronizedClientScriptId(const char* scriptId) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Add an ID to the list of global IDs whose value changes should be sent to the
|
||||||
|
* server by clients.
|
||||||
|
*
|
||||||
|
* \param globalId The ID.
|
||||||
|
* \return void
|
||||||
|
*/
|
||||||
|
static void AddSynchronizedClientGlobalId(const char* globalId) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Add a refId to the list of refIds for which collision should be enforced
|
* \brief Add a refId to the list of refIds for which collision should be enforced
|
||||||
* irrespective of other settings.
|
* irrespective of other settings.
|
||||||
|
@ -316,13 +327,21 @@ public:
|
||||||
static void AddEnforcedCollisionRefId(const char* refId) noexcept;
|
static void AddEnforcedCollisionRefId(const char* refId) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Clear the list of script IDs whose variables should all be synchronized
|
* \brief Clear the list of script IDs whose variable changes should be sent to the
|
||||||
* across players.
|
* the server by clients.
|
||||||
*
|
*
|
||||||
* \return void
|
* \return void
|
||||||
*/
|
*/
|
||||||
static void ClearSynchronizedClientScriptIds() noexcept;
|
static void ClearSynchronizedClientScriptIds() noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Clear the list of global IDs whose value changes should be sent to the
|
||||||
|
* the server by clients.
|
||||||
|
*
|
||||||
|
* \return void
|
||||||
|
*/
|
||||||
|
static void ClearSynchronizedClientGlobalIds() noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Clear the list of refIds for which collision should be enforced irrespective
|
* \brief Clear the list of refIds for which collision should be enforced irrespective
|
||||||
* of other settings.
|
* of other settings.
|
||||||
|
|
|
@ -232,11 +232,21 @@ CellController *Main::getCellController() const
|
||||||
return mCellController;
|
return mCellController;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Main::isValidPacketScript(std::string script)
|
bool Main::isValidPacketScript(std::string scriptId)
|
||||||
{
|
{
|
||||||
mwmp::BaseWorldstate *worldstate = get().getNetworking()->getWorldstate();
|
mwmp::BaseWorldstate *worldstate = get().getNetworking()->getWorldstate();
|
||||||
|
|
||||||
if (Utils::vectorContains(worldstate->synchronizedClientScriptIds, script))
|
if (Utils::vectorContains(worldstate->synchronizedClientScriptIds, scriptId))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Main::isValidPacketGlobal(std::string globalId)
|
||||||
|
{
|
||||||
|
mwmp::BaseWorldstate *worldstate = get().getNetworking()->getWorldstate();
|
||||||
|
|
||||||
|
if (Utils::vectorContains(worldstate->synchronizedClientGlobalIds, globalId))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -26,7 +26,9 @@ namespace mwmp
|
||||||
static const Main &get();
|
static const Main &get();
|
||||||
static void frame(float dt);
|
static void frame(float dt);
|
||||||
|
|
||||||
static bool isValidPacketScript(std::string script);
|
static bool isValidPacketScript(std::string scriptId);
|
||||||
|
static bool isValidPacketGlobal(std::string globalId);
|
||||||
|
|
||||||
static std::string getResDir();
|
static std::string getResDir();
|
||||||
|
|
||||||
Networking *getNetworking() const;
|
Networking *getNetworking() const;
|
||||||
|
|
|
@ -18,7 +18,21 @@ namespace mwmp
|
||||||
|
|
||||||
virtual void Do(WorldstatePacket &packet, Worldstate &worldstate)
|
virtual void Do(WorldstatePacket &packet, Worldstate &worldstate)
|
||||||
{
|
{
|
||||||
// Placeholder
|
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Received ID_CLIENT_SCRIPT_SETTINGS making us send packets for the following globals:");
|
||||||
|
std::string debugMessage = "";
|
||||||
|
|
||||||
|
for (const auto &globalId : worldstate.synchronizedClientGlobalIds)
|
||||||
|
{
|
||||||
|
if (TimedLog::GetLevel() <= TimedLog::LOG_INFO)
|
||||||
|
{
|
||||||
|
if (!debugMessage.empty())
|
||||||
|
debugMessage += ", ";
|
||||||
|
|
||||||
|
debugMessage += globalId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_APPEND(TimedLog::LOG_INFO, "- %s", debugMessage.c_str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -323,10 +323,11 @@ namespace MWScript
|
||||||
/*
|
/*
|
||||||
Start of tes3mp addition
|
Start of tes3mp addition
|
||||||
|
|
||||||
Send an ID_SCRIPT_GLOBAL_SHORT packet every time a global short changes its value
|
Send an ID_SCRIPT_GLOBAL_SHORT packet when a global short changes its value as long as
|
||||||
in a script approved for packet sending
|
it is being set in a script that has been approved for packet sending or the global itself
|
||||||
|
has been set to always be synchronized
|
||||||
*/
|
*/
|
||||||
if (sendPackets)
|
if (sendPackets || mwmp::Main::isValidPacketGlobal(name))
|
||||||
{
|
{
|
||||||
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList();
|
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList();
|
||||||
objectList->reset();
|
objectList->reset();
|
||||||
|
|
|
@ -308,6 +308,7 @@ namespace mwmp
|
||||||
|
|
||||||
mwmp::Time time;
|
mwmp::Time time;
|
||||||
std::vector<std::string> synchronizedClientScriptIds;
|
std::vector<std::string> synchronizedClientScriptIds;
|
||||||
|
std::vector<std::string> synchronizedClientGlobalIds;
|
||||||
|
|
||||||
bool hasPlayerCollision;
|
bool hasPlayerCollision;
|
||||||
bool hasActorCollision;
|
bool hasActorCollision;
|
||||||
|
|
|
@ -30,4 +30,22 @@ void PacketClientScriptSettings::Packet(RakNet::BitStream *bs, bool send)
|
||||||
{
|
{
|
||||||
RW(clientScriptId, send);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue