[General] Move handling of client globals to ClientScriptGlobal packet

ClientScriptGlobal is a new Worldstate packet that handles short, long and float values for global variables in clientside scripts.

Previously, short values were handled by the ScriptGlobalShort packet, while a partially implemented ScriptGlobalFloat packet also existed, but both of those packets were Object packets because they were added near the end of 2016 when only Player and Object packets existed (with the latter actually being called WorldEvent packets at the time). Both ScriptGlobalShort and ScriptGlobalFloat have now been removed.

The serverside script functions previously used to interact with ScriptGlobalShort have, however, been kept so they can be adjusted to work with local variables in clientside scripts instead in a future commit.
pull/556/head
David Cernat 5 years ago
parent c9b3ec1ca4
commit e6c626f127

@ -123,15 +123,15 @@ set(PROCESSORS_OBJECT
processors/object/ProcessorObjectState.hpp processors/object/ProcessorObjectTrap.hpp processors/object/ProcessorObjectState.hpp processors/object/ProcessorObjectTrap.hpp
processors/object/ProcessorScriptLocalShort.hpp processors/object/ProcessorScriptLocalFloat.hpp processors/object/ProcessorScriptLocalShort.hpp processors/object/ProcessorScriptLocalFloat.hpp
processors/object/ProcessorScriptMemberShort.hpp processors/object/ProcessorScriptMemberFloat.hpp processors/object/ProcessorScriptMemberShort.hpp processors/object/ProcessorScriptMemberFloat.hpp
processors/object/ProcessorScriptGlobalShort.hpp processors/object/ProcessorScriptGlobalFloat.hpp
processors/object/ProcessorVideoPlay.hpp processors/object/ProcessorVideoPlay.hpp
) )
source_group(tes3mp-server\\processors\\object FILES ${PROCESSORS_OBJECT}) source_group(tes3mp-server\\processors\\object FILES ${PROCESSORS_OBJECT})
set(PROCESSORS_WORLDSTATE set(PROCESSORS_WORLDSTATE
processors/worldstate/ProcessorRecordDynamic.hpp processors/worldstate/ProcessorWorldKillCount.hpp processors/worldstate/ProcessorClientScriptGlobal.hpp processors/worldstate/ProcessorRecordDynamic.hpp
processors/worldstate/ProcessorWorldMap.hpp processors/worldstate/ProcessorWorldWeather.hpp processors/worldstate/ProcessorWorldKillCount.hpp processors/worldstate/ProcessorWorldMap.hpp
processors/worldstate/ProcessorWorldWeather.hpp
) )
source_group(tes3mp-server\\processors\\worldstate FILES ${PROCESSORS_WORLDSTATE}) source_group(tes3mp-server\\processors\\worldstate FILES ${PROCESSORS_WORLDSTATE})

@ -745,13 +745,15 @@ void ObjectFunctions::SendVideoPlay(bool sendToOtherPlayers, bool skipAttachedPl
void ObjectFunctions::SendScriptGlobalShort(bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept void ObjectFunctions::SendScriptGlobalShort(bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept
{ {
mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_SCRIPT_GLOBAL_SHORT); /*
mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_CLIENT_SCRIPT_GLOBAL);
packet->setObjectList(&writeObjectList); packet->setObjectList(&writeObjectList);
if (!skipAttachedPlayer) if (!skipAttachedPlayer)
packet->Send(false); packet->Send(false);
if (sendToOtherPlayers) if (sendToOtherPlayers)
packet->Send(true); packet->Send(true);
*/
} }
void ObjectFunctions::SendConsoleCommand(bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept void ObjectFunctions::SendConsoleCommand(bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept

@ -33,6 +33,11 @@ void WorldstateFunctions::ClearMapChanges() noexcept
writeWorldstate.mapTiles.clear(); writeWorldstate.mapTiles.clear();
} }
void WorldstateFunctions::ClearClientGlobals() noexcept
{
writeWorldstate.clientGlobals.clear();
}
unsigned int WorldstateFunctions::GetKillChangesSize() noexcept unsigned int WorldstateFunctions::GetKillChangesSize() noexcept
{ {
return readWorldstate->killChanges.size(); return readWorldstate->killChanges.size();
@ -43,6 +48,11 @@ unsigned int WorldstateFunctions::GetMapChangesSize() noexcept
return readWorldstate->mapTiles.size(); return readWorldstate->mapTiles.size();
} }
unsigned int WorldstateFunctions::GetClientGlobalsSize() noexcept
{
return readWorldstate->clientGlobals.size();
}
const char *WorldstateFunctions::GetKillRefId(unsigned int index) noexcept const char *WorldstateFunctions::GetKillRefId(unsigned int index) noexcept
{ {
return readWorldstate->killChanges.at(index).refId.c_str(); return readWorldstate->killChanges.at(index).refId.c_str();
@ -88,6 +98,26 @@ int WorldstateFunctions::GetMapTileCellY(unsigned int index) noexcept
return readWorldstate->mapTiles.at(index).y; return readWorldstate->mapTiles.at(index).y;
} }
const char *WorldstateFunctions::GetClientGlobalId(unsigned int index) noexcept
{
return readWorldstate->clientGlobals.at(index).id.c_str();
}
unsigned short WorldstateFunctions::GetClientGlobalVariableType(unsigned int index) noexcept
{
return readWorldstate->clientGlobals.at(index).variableType;
}
int WorldstateFunctions::GetClientGlobalIntValue(unsigned int index) noexcept
{
return readWorldstate->clientGlobals.at(index).intValue;
}
double WorldstateFunctions::GetClientGlobalFloatValue(unsigned int index) noexcept
{
return readWorldstate->clientGlobals.at(index).floatValue;
}
void WorldstateFunctions::SetAuthorityRegion(const char* authorityRegion) noexcept void WorldstateFunctions::SetAuthorityRegion(const char* authorityRegion) noexcept
{ {
writeWorldstate.authorityRegion = authorityRegion; writeWorldstate.authorityRegion = authorityRegion;
@ -182,6 +212,26 @@ void WorldstateFunctions::AddKill(const char* refId, int number) noexcept
writeWorldstate.killChanges.push_back(kill); writeWorldstate.killChanges.push_back(kill);
} }
void WorldstateFunctions::AddClientGlobalInteger(const char* id, int intValue) noexcept
{
mwmp::ClientVariable clientVariable;
clientVariable.id = id;
clientVariable.variableType = mwmp::VARIABLE_TYPE::INTEGER;
clientVariable.intValue = intValue;
writeWorldstate.clientGlobals.push_back(clientVariable);
}
void WorldstateFunctions::AddClientGlobalFloat(const char* id, double floatValue) noexcept
{
mwmp::ClientVariable clientVariable;
clientVariable.id = id;
clientVariable.variableType = mwmp::VARIABLE_TYPE::FLOAT;
clientVariable.floatValue = floatValue;
writeWorldstate.clientGlobals.push_back(clientVariable);
}
void WorldstateFunctions::AddSynchronizedClientScriptId(const char *scriptId) noexcept void WorldstateFunctions::AddSynchronizedClientScriptId(const char *scriptId) noexcept
{ {
writeWorldstate.synchronizedClientScriptIds.push_back(scriptId); writeWorldstate.synchronizedClientScriptIds.push_back(scriptId);
@ -255,6 +305,22 @@ void WorldstateFunctions::LoadMapTileImageFile(int cellX, int cellY, const char*
} }
} }
void WorldstateFunctions::SendClientScriptGlobal(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept
{
Player *player;
GET_PLAYER(pid, player, );
writeWorldstate.guid = player->guid;
mwmp::WorldstatePacket *packet = mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_CLIENT_SCRIPT_GLOBAL);
packet->setWorldstate(&writeWorldstate);
if (!skipAttachedPlayer)
packet->Send(false);
if (sendToOtherPlayers)
packet->Send(true);
}
void WorldstateFunctions::SendClientScriptSettings(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept void WorldstateFunctions::SendClientScriptSettings(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept
{ {
Player *player; Player *player;
@ -271,7 +337,6 @@ void WorldstateFunctions::SendClientScriptSettings(unsigned short pid, bool send
packet->Send(true); packet->Send(true);
} }
void WorldstateFunctions::SendWorldKillCount(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept void WorldstateFunctions::SendWorldKillCount(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept
{ {
Player *player; Player *player;

@ -11,9 +11,11 @@
\ \
{"ClearKillChanges", WorldstateFunctions::ClearKillChanges},\ {"ClearKillChanges", WorldstateFunctions::ClearKillChanges},\
{"ClearMapChanges", WorldstateFunctions::ClearMapChanges},\ {"ClearMapChanges", WorldstateFunctions::ClearMapChanges},\
{"ClearClientGlobals", WorldstateFunctions::ClearClientGlobals},\
\ \
{"GetKillChangesSize", WorldstateFunctions::GetKillChangesSize},\ {"GetKillChangesSize", WorldstateFunctions::GetKillChangesSize},\
{"GetMapChangesSize", WorldstateFunctions::GetMapChangesSize},\ {"GetMapChangesSize", WorldstateFunctions::GetMapChangesSize},\
{"GetClientGlobalsSize", WorldstateFunctions::GetClientGlobalsSize},\
\ \
{"GetKillRefId", WorldstateFunctions::GetKillRefId},\ {"GetKillRefId", WorldstateFunctions::GetKillRefId},\
{"GetKillNumber", WorldstateFunctions::GetKillNumber},\ {"GetKillNumber", WorldstateFunctions::GetKillNumber},\
@ -27,6 +29,11 @@
{"GetMapTileCellX", WorldstateFunctions::GetMapTileCellX},\ {"GetMapTileCellX", WorldstateFunctions::GetMapTileCellX},\
{"GetMapTileCellY", WorldstateFunctions::GetMapTileCellY},\ {"GetMapTileCellY", WorldstateFunctions::GetMapTileCellY},\
\ \
{"GetClientGlobalId", WorldstateFunctions::GetClientGlobalId},\
{"GetClientGlobalVariableType", WorldstateFunctions::GetClientGlobalVariableType},\
{"GetClientGlobalIntValue", WorldstateFunctions::GetClientGlobalIntValue},\
{"GetClientGlobalFloatValue", WorldstateFunctions::GetClientGlobalFloatValue},\
\
{"SetAuthorityRegion", WorldstateFunctions::SetAuthorityRegion},\ {"SetAuthorityRegion", WorldstateFunctions::SetAuthorityRegion},\
\ \
{"SetWeatherRegion", WorldstateFunctions::SetWeatherRegion},\ {"SetWeatherRegion", WorldstateFunctions::SetWeatherRegion},\
@ -49,6 +56,8 @@
{"UseActorCollisionForPlacedObjects", WorldstateFunctions::UseActorCollisionForPlacedObjects},\ {"UseActorCollisionForPlacedObjects", WorldstateFunctions::UseActorCollisionForPlacedObjects},\
\ \
{"AddKill", WorldstateFunctions::AddKill},\ {"AddKill", WorldstateFunctions::AddKill},\
{"AddClientGlobalInteger", WorldstateFunctions::AddClientGlobalInteger},\
{"AddClientGlobalFloat", WorldstateFunctions::AddClientGlobalFloat},\
{"AddSynchronizedClientScriptId", WorldstateFunctions::AddSynchronizedClientScriptId},\ {"AddSynchronizedClientScriptId", WorldstateFunctions::AddSynchronizedClientScriptId},\
{"AddSynchronizedClientGlobalId", WorldstateFunctions::AddSynchronizedClientGlobalId},\ {"AddSynchronizedClientGlobalId", WorldstateFunctions::AddSynchronizedClientGlobalId},\
{"AddEnforcedCollisionRefId", WorldstateFunctions::AddEnforcedCollisionRefId},\ {"AddEnforcedCollisionRefId", WorldstateFunctions::AddEnforcedCollisionRefId},\
@ -62,6 +71,7 @@
{"SaveMapTileImageFile", WorldstateFunctions::SaveMapTileImageFile},\ {"SaveMapTileImageFile", WorldstateFunctions::SaveMapTileImageFile},\
{"LoadMapTileImageFile", WorldstateFunctions::LoadMapTileImageFile},\ {"LoadMapTileImageFile", WorldstateFunctions::LoadMapTileImageFile},\
\ \
{"SendClientScriptGlobal", WorldstateFunctions::SendClientScriptGlobal},\
{"SendClientScriptSettings", WorldstateFunctions::SendClientScriptSettings},\ {"SendClientScriptSettings", WorldstateFunctions::SendClientScriptSettings},\
{"SendWorldKillCount", WorldstateFunctions::SendWorldKillCount},\ {"SendWorldKillCount", WorldstateFunctions::SendWorldKillCount},\
{"SendWorldMap", WorldstateFunctions::SendWorldMap},\ {"SendWorldMap", WorldstateFunctions::SendWorldMap},\
@ -115,6 +125,15 @@ public:
*/ */
static void ClearMapChanges() noexcept; static void ClearMapChanges() noexcept;
/**
* \brief Clear the client globals for the write-only worldstate.
*
* This is used to initialize the sending of new ClientScriptGlobal packets.
*
* \return void
*/
static void ClearClientGlobals() noexcept;
/** /**
* \brief Get the number of indexes in the read worldstate's kill changes. * \brief Get the number of indexes in the read worldstate's kill changes.
* *
@ -129,6 +148,13 @@ public:
*/ */
static unsigned int GetMapChangesSize() noexcept; static unsigned int GetMapChangesSize() noexcept;
/**
* \brief Get the number of indexes in the read worldstate's client globals.
*
* \return The number of indexes.
*/
static unsigned int GetClientGlobalsSize() noexcept;
/** /**
* \brief Get the refId at a certain index in the read worldstate's kill count changes. * \brief Get the refId at a certain index in the read worldstate's kill count changes.
* *
@ -198,6 +224,42 @@ public:
*/ */
static int GetMapTileCellY(unsigned int index) noexcept; static int GetMapTileCellY(unsigned int index) noexcept;
/**
* \brief Get the id of the global variable at a certain index in the read worldstate's
* client globals.
*
* \param index The index of the client global.
* \return The id.
*/
static const char *GetClientGlobalId(unsigned int index) noexcept;
/**
* \brief Get the type of the global variable at a certain index in the read worldstate's
* client globals.
*
* \param index The index of the client global.
* \return The variable type (0 for INTEGER, 1 for FLOAT).
*/
static unsigned short GetClientGlobalVariableType(unsigned int index) noexcept;
/**
* \brief Get the integer value of the global variable at a certain index in the read
* worldstate's client globals.
*
* \param index The index of the client global.
* \return The integer value.
*/
static int GetClientGlobalIntValue(unsigned int index) noexcept;
/**
* \brief Get the float value of the global variable at a certain index in the read
* worldstate's client globals.
*
* \param index The index of the client global.
* \return The float value.
*/
static double GetClientGlobalFloatValue(unsigned int index) noexcept;
/** /**
* \brief Set the region affected by the next WorldRegionAuthority packet sent. * \brief Set the region affected by the next WorldRegionAuthority packet sent.
* *
@ -350,6 +412,24 @@ public:
*/ */
static void AddKill(const char* refId, int number) noexcept; static void AddKill(const char* refId, int number) noexcept;
/**
* \brief Add a new client global integer to the client globals.
*
* \param id The id of the client global.
* \param intValue The integer value of the client global.
* \return void
*/
static void AddClientGlobalInteger(const char* id, int intValue) noexcept;
/**
* \brief Add a new client global float to the client globals.
*
* \param id The id of the client global.
* \param floatValue The float value of the client global.
* \return void
*/
static void AddClientGlobalFloat(const char* id, double floatValue) noexcept;
/** /**
* \brief Add an ID to the list of script IDs whose variable changes should be sent to the * \brief Add an ID to the list of script IDs whose variable changes should be sent to the
* the server by clients. * the server by clients.
@ -439,6 +519,19 @@ public:
*/ */
static void LoadMapTileImageFile(int cellX, int cellY, const char* filePath) noexcept; static void LoadMapTileImageFile(int cellX, int cellY, const char* filePath) noexcept;
/**
* \brief Send a ClientScriptGlobal packet with the current client script globals in
* the write-only worldstate.
*
* \param pid The player ID attached to the packet.
* \param sendToOtherPlayers Whether this packet should be sent to players other than the
* player attached to the packet (false by default).
* \param skipAttachedPlayer Whether the packet should skip being sent to the player attached
* to the packet (false by default).
* \return void
*/
static void SendClientScriptGlobal(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept;
/** /**
* \brief Send a ClientScriptSettings packet with the current client script settings in * \brief Send a ClientScriptSettings packet with the current client script settings in
* the write-only worldstate. * the write-only worldstate.

@ -210,7 +210,7 @@ public:
{"OnWorldKillCount", Callback<unsigned short>()}, {"OnWorldKillCount", Callback<unsigned short>()},
{"OnWorldMap", Callback<unsigned short>()}, {"OnWorldMap", Callback<unsigned short>()},
{"OnWorldWeather", Callback<unsigned short>()}, {"OnWorldWeather", Callback<unsigned short>()},
{"OnScriptGlobalShort", Callback<unsigned short>()}, {"OnClientScriptGlobal", Callback<unsigned short>()},
{"OnMpNumIncrement", Callback<int>()}, {"OnMpNumIncrement", Callback<int>()},
{"OnRequestDataFileList", Callback<>()} {"OnRequestDataFileList", Callback<>()}
}; };

@ -74,10 +74,9 @@
#include "object/ProcessorScriptLocalFloat.hpp" #include "object/ProcessorScriptLocalFloat.hpp"
#include "object/ProcessorScriptMemberShort.hpp" #include "object/ProcessorScriptMemberShort.hpp"
#include "object/ProcessorScriptMemberFloat.hpp" #include "object/ProcessorScriptMemberFloat.hpp"
#include "object/ProcessorScriptGlobalShort.hpp"
#include "object/ProcessorScriptGlobalFloat.hpp"
#include "object/ProcessorVideoPlay.hpp" #include "object/ProcessorVideoPlay.hpp"
#include "WorldstateProcessor.hpp" #include "WorldstateProcessor.hpp"
#include "worldstate/ProcessorClientScriptGlobal.hpp"
#include "worldstate/ProcessorRecordDynamic.hpp" #include "worldstate/ProcessorRecordDynamic.hpp"
#include "worldstate/ProcessorWorldKillCount.hpp" #include "worldstate/ProcessorWorldKillCount.hpp"
#include "worldstate/ProcessorWorldMap.hpp" #include "worldstate/ProcessorWorldMap.hpp"
@ -157,10 +156,9 @@ void ProcessorInitializer()
ObjectProcessor::AddProcessor(new ProcessorScriptLocalFloat()); ObjectProcessor::AddProcessor(new ProcessorScriptLocalFloat());
ObjectProcessor::AddProcessor(new ProcessorScriptMemberShort()); ObjectProcessor::AddProcessor(new ProcessorScriptMemberShort());
ObjectProcessor::AddProcessor(new ProcessorScriptMemberFloat()); ObjectProcessor::AddProcessor(new ProcessorScriptMemberFloat());
ObjectProcessor::AddProcessor(new ProcessorScriptGlobalShort());
ObjectProcessor::AddProcessor(new ProcessorScriptGlobalFloat());
ObjectProcessor::AddProcessor(new ProcessorVideoPlay()); ObjectProcessor::AddProcessor(new ProcessorVideoPlay());
WorldstateProcessor::AddProcessor(new ProcessorClientScriptGlobal());
WorldstateProcessor::AddProcessor(new ProcessorRecordDynamic()); WorldstateProcessor::AddProcessor(new ProcessorRecordDynamic());
WorldstateProcessor::AddProcessor(new ProcessorWorldKillCount()); WorldstateProcessor::AddProcessor(new ProcessorWorldKillCount());
WorldstateProcessor::AddProcessor(new ProcessorWorldMap()); WorldstateProcessor::AddProcessor(new ProcessorWorldMap());

@ -1,18 +0,0 @@
#ifndef OPENMW_PROCESSORSCRIPTGLOBALFLOAT_HPP
#define OPENMW_PROCESSORSCRIPTGLOBALFLOAT_HPP
#include "../ObjectProcessor.hpp"
namespace mwmp
{
class ProcessorScriptGlobalFloat : public ObjectProcessor
{
public:
ProcessorScriptGlobalFloat()
{
BPP_INIT(ID_SCRIPT_GLOBAL_FLOAT)
}
};
}
#endif //OPENMW_PROCESSORSCRIPTGLOBALFLOAT_HPP

@ -1,25 +0,0 @@
#ifndef OPENMW_PROCESSORSCRIPTGLOBALSHORT_HPP
#define OPENMW_PROCESSORSCRIPTGLOBALSHORT_HPP
#include "../ObjectProcessor.hpp"
namespace mwmp
{
class ProcessorScriptGlobalShort : public ObjectProcessor
{
public:
ProcessorScriptGlobalShort()
{
BPP_INIT(ID_SCRIPT_GLOBAL_SHORT)
}
void Do(ObjectPacket &packet, Player &player, BaseObjectList &objectList) override
{
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Received %s from %s", strPacketID.c_str(), player.npc.mName.c_str());
Script::Call<Script::CallbackIdentity("OnScriptGlobalShort")>(player.getId());
}
};
}
#endif //OPENMW_PROCESSORSCRIPTGLOBALSHORT_HPP

@ -0,0 +1,25 @@
#ifndef OPENMW_PROCESSORCLIENTSCRIPTGLOBAL_HPP
#define OPENMW_PROCESSORCLIENTSCRIPTGLOBAL_HPP
#include "../WorldstateProcessor.hpp"
namespace mwmp
{
class ProcessorClientScriptGlobal : public WorldstateProcessor
{
public:
ProcessorClientScriptGlobal()
{
BPP_INIT(ID_CLIENT_SCRIPT_GLOBAL)
}
void Do(WorldstatePacket &packet, Player &player, BaseWorldstate &worldstate) override
{
DEBUG_PRINTF(strPacketID.c_str());
Script::Call<Script::CallbackIdentity("OnClientScriptGlobal")>(player.getId());
}
};
}
#endif //OPENMW_PROCESSORCLIENTSCRIPTGLOBAL_HPP

@ -133,13 +133,12 @@ add_openmw_dir (mwmp/processors/object BaseObjectProcessor
ProcessorObjectActivate ProcessorObjectAnimPlay ProcessorObjectAttach ProcessorObjectCollision ProcessorObjectDelete ProcessorObjectActivate ProcessorObjectAnimPlay ProcessorObjectAttach ProcessorObjectCollision ProcessorObjectDelete
ProcessorObjectHit ProcessorObjectLock ProcessorObjectMove ProcessorObjectPlace ProcessorObjectRotate ProcessorObjectHit ProcessorObjectLock ProcessorObjectMove ProcessorObjectPlace ProcessorObjectRotate
ProcessorObjectScale ProcessorObjectSpawn ProcessorObjectState ProcessorObjectTrap ProcessorScriptLocalShort ProcessorObjectScale ProcessorObjectSpawn ProcessorObjectState ProcessorObjectTrap ProcessorScriptLocalShort
ProcessorScriptLocalFloat ProcessorScriptMemberShort ProcessorScriptMemberFloat ProcessorScriptGlobalShort ProcessorScriptLocalFloat ProcessorScriptMemberShort ProcessorScriptMemberFloat
ProcessorScriptGlobalFloat
) )
add_openmw_dir (mwmp/processors/worldstate ProcessorCellReset ProcessorClientScriptSettings ProcessorRecordDynamic add_openmw_dir (mwmp/processors/worldstate ProcessorCellReset ProcessorClientScriptGlobal ProcessorClientScriptSettings
ProcessorWorldCollisionOverride ProcessorWorldDestinationOverride ProcessorWorldKillCount ProcessorWorldMap ProcessorRecordDynamic ProcessorWorldCollisionOverride ProcessorWorldDestinationOverride ProcessorWorldKillCount
ProcessorWorldRegionAuthority ProcessorWorldTime ProcessorWorldWeather ProcessorWorldMap ProcessorWorldRegionAuthority ProcessorWorldTime ProcessorWorldWeather
) )
# Main executable # Main executable

@ -867,16 +867,6 @@ void ObjectList::setMemberShorts()
} }
} }
void ObjectList::setGlobalShorts()
{
for (const auto &baseObject : baseObjects)
{
LOG_APPEND(TimedLog::LOG_VERBOSE, "- varName: %s, shortVal: %i", baseObject.varName.c_str(), baseObject.shortVal);
MWBase::Environment::get().getWorld()->setGlobalInt(baseObject.varName, baseObject.shortVal);
}
}
void ObjectList::playMusic() void ObjectList::playMusic()
{ {
for (const auto &baseObject : baseObjects) for (const auto &baseObject : baseObjects)
@ -1237,14 +1227,6 @@ void ObjectList::addScriptMemberShort(std::string refId, int index, int shortVal
addObject(baseObject); addObject(baseObject);
} }
void ObjectList::addScriptGlobalShort(std::string varName, int shortVal)
{
mwmp::BaseObject baseObject;
baseObject.varName = varName;
baseObject.shortVal = shortVal;
addObject(baseObject);
}
void ObjectList::sendObjectActivate() void ObjectList::sendObjectActivate()
{ {
mwmp::Main::get().getNetworking()->getObjectPacket(ID_OBJECT_ACTIVATE)->setObjectList(this); mwmp::Main::get().getNetworking()->getObjectPacket(ID_OBJECT_ACTIVATE)->setObjectList(this);
@ -1381,17 +1363,6 @@ void ObjectList::sendScriptMemberShort()
mwmp::Main::get().getNetworking()->getObjectPacket(ID_SCRIPT_MEMBER_SHORT)->Send(); mwmp::Main::get().getNetworking()->getObjectPacket(ID_SCRIPT_MEMBER_SHORT)->Send();
} }
void ObjectList::sendScriptGlobalShort()
{
LOG_MESSAGE_SIMPLE(TimedLog::LOG_VERBOSE, "Sending ID_SCRIPT_GLOBAL_SHORT");
for (const auto &baseObject : baseObjects)
LOG_APPEND(TimedLog::LOG_VERBOSE, "- varName: %s, shortVal: %i", baseObject.varName.c_str(), baseObject.shortVal);
mwmp::Main::get().getNetworking()->getObjectPacket(ID_SCRIPT_GLOBAL_SHORT)->setObjectList(this);
mwmp::Main::get().getNetworking()->getObjectPacket(ID_SCRIPT_GLOBAL_SHORT)->Send();
}
void ObjectList::sendContainer() void ObjectList::sendContainer()
{ {
LOG_MESSAGE_SIMPLE(TimedLog::LOG_VERBOSE, "Sending ID_CONTAINER"); LOG_MESSAGE_SIMPLE(TimedLog::LOG_VERBOSE, "Sending ID_CONTAINER");

@ -42,7 +42,6 @@ namespace mwmp
void setLocalShorts(MWWorld::CellStore* cellStore); void setLocalShorts(MWWorld::CellStore* cellStore);
void setLocalFloats(MWWorld::CellStore* cellStore); void setLocalFloats(MWWorld::CellStore* cellStore);
void setMemberShorts(); void setMemberShorts();
void setGlobalShorts();
void playMusic(); void playMusic();
void playVideo(); void playVideo();
@ -72,7 +71,6 @@ namespace mwmp
void addScriptLocalShort(const MWWorld::Ptr& ptr, int index, int shortVal); void addScriptLocalShort(const MWWorld::Ptr& ptr, int index, int shortVal);
void addScriptLocalFloat(const MWWorld::Ptr& ptr, int index, float floatVal); void addScriptLocalFloat(const MWWorld::Ptr& ptr, int index, float floatVal);
void addScriptMemberShort(std::string refId, int index, int shortVal); void addScriptMemberShort(std::string refId, int index, int shortVal);
void addScriptGlobalShort(std::string varName, int shortVal);
void sendObjectActivate(); void sendObjectActivate();
void sendObjectHit(); void sendObjectHit();
@ -90,7 +88,6 @@ namespace mwmp
void sendScriptLocalShort(); void sendScriptLocalShort();
void sendScriptLocalFloat(); void sendScriptLocalFloat();
void sendScriptMemberShort(); void sendScriptMemberShort();
void sendScriptGlobalShort();
void sendContainer(); void sendContainer();
void sendConsoleCommand(); void sendConsoleCommand();

@ -337,6 +337,33 @@ void Worldstate::markExploredMapTile(int cellX, int cellY)
exploredMapTiles.push_back(exploredTile); exploredMapTiles.push_back(exploredTile);
} }
void Worldstate::setClientGlobals()
{
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Received ID_CLIENT_SCRIPT_GLOBAL with the following global values:");
std::string debugMessage = "";
for (const auto &clientGlobal : clientGlobals)
{
if (TimedLog::GetLevel() <= TimedLog::LOG_INFO)
{
if (!debugMessage.empty())
debugMessage += ", ";
std::string valueAsString = clientGlobal.variableType == mwmp::VARIABLE_TYPE::INTEGER ?
std::to_string(clientGlobal.intValue) : std::to_string(clientGlobal.floatValue);
debugMessage += clientGlobal.id + ": " + valueAsString;
}
if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::INTEGER)
MWBase::Environment::get().getWorld()->setGlobalInt(clientGlobal.id, clientGlobal.intValue);
else if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::FLOAT)
MWBase::Environment::get().getWorld()->setGlobalInt(clientGlobal.id, clientGlobal.floatValue);
}
LOG_APPEND(TimedLog::LOG_INFO, "- %s", debugMessage.c_str());
}
void Worldstate::setKills() void Worldstate::setKills()
{ {
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Received ID_WORLD_KILL_COUNT with the following kill counts:"); LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Received ID_WORLD_KILL_COUNT with the following kill counts:");
@ -392,6 +419,40 @@ void Worldstate::setWeather()
weather.queuedWeather, weather.transitionFactor, forceWeather); weather.queuedWeather, weather.transitionFactor, forceWeather);
} }
void Worldstate::sendClientGlobal(std::string varName, int value)
{
clientGlobals.clear();
mwmp::ClientVariable clientVariable;
clientVariable.id = varName;
clientVariable.variableType = mwmp::VARIABLE_TYPE::INTEGER;
clientVariable.intValue = value;
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Sending ID_CLIENT_SCRIPT_GLOBAL with name %s, type integer, value %i", varName.c_str(), value);
clientGlobals.push_back(clientVariable);
getNetworking()->getWorldstatePacket(ID_CLIENT_SCRIPT_GLOBAL)->setWorldstate(this);
getNetworking()->getWorldstatePacket(ID_CLIENT_SCRIPT_GLOBAL)->Send();
}
void Worldstate::sendClientGlobal(std::string varName, float value)
{
clientGlobals.clear();
mwmp::ClientVariable clientVariable;
clientVariable.id = varName;
clientVariable.variableType = mwmp::VARIABLE_TYPE::FLOAT;
clientVariable.floatValue = value;
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Sending ID_CLIENT_SCRIPT_GLOBAL with name %s, type float, value %f", varName.c_str(), value);
clientGlobals.push_back(clientVariable);
getNetworking()->getWorldstatePacket(ID_CLIENT_SCRIPT_GLOBAL)->setWorldstate(this);
getNetworking()->getWorldstatePacket(ID_CLIENT_SCRIPT_GLOBAL)->Send();
}
void Worldstate::sendMapExplored(int cellX, int cellY, const std::vector<char>& imageData) void Worldstate::sendMapExplored(int cellX, int cellY, const std::vector<char>& imageData)
{ {
mapTiles.clear(); mapTiles.clear();

@ -18,10 +18,13 @@ namespace mwmp
bool containsExploredMapTile(int cellX, int cellY); bool containsExploredMapTile(int cellX, int cellY);
void markExploredMapTile(int cellX, int cellY); void markExploredMapTile(int cellX, int cellY);
void setClientGlobals();
void setKills(); void setKills();
void setMapExplored(); void setMapExplored();
void setWeather(); void setWeather();
void sendClientGlobal(std::string varName, int value);
void sendClientGlobal(std::string varName, float value);
void sendMapExplored(int cellX, int cellY, const std::vector<char>& imageData); void sendMapExplored(int cellX, int cellY, const std::vector<char>& imageData);
void sendWeather(std::string region, int currentWeather, int nextWeather, int queuedWeather, float transitionFactor); void sendWeather(std::string region, int currentWeather, int nextWeather, int queuedWeather, float transitionFactor);

@ -70,8 +70,6 @@
#include "object/ProcessorScriptLocalFloat.hpp" #include "object/ProcessorScriptLocalFloat.hpp"
#include "object/ProcessorScriptMemberShort.hpp" #include "object/ProcessorScriptMemberShort.hpp"
#include "object/ProcessorScriptMemberFloat.hpp" #include "object/ProcessorScriptMemberFloat.hpp"
#include "object/ProcessorScriptGlobalShort.hpp"
#include "object/ProcessorScriptGlobalFloat.hpp"
#include "object/ProcessorVideoPlay.hpp" #include "object/ProcessorVideoPlay.hpp"
#include "ActorProcessor.hpp" #include "ActorProcessor.hpp"
@ -92,6 +90,7 @@
#include "WorldstateProcessor.hpp" #include "WorldstateProcessor.hpp"
#include "worldstate/ProcessorCellReset.hpp" #include "worldstate/ProcessorCellReset.hpp"
#include "worldstate/ProcessorClientScriptGlobal.hpp"
#include "worldstate/ProcessorClientScriptSettings.hpp" #include "worldstate/ProcessorClientScriptSettings.hpp"
#include "worldstate/ProcessorRecordDynamic.hpp" #include "worldstate/ProcessorRecordDynamic.hpp"
#include "worldstate/ProcessorWorldCollisionOverride.hpp" #include "worldstate/ProcessorWorldCollisionOverride.hpp"
@ -173,8 +172,6 @@ void ProcessorInitializer()
ObjectProcessor::AddProcessor(new ProcessorScriptLocalFloat()); ObjectProcessor::AddProcessor(new ProcessorScriptLocalFloat());
ObjectProcessor::AddProcessor(new ProcessorScriptMemberShort()); ObjectProcessor::AddProcessor(new ProcessorScriptMemberShort());
ObjectProcessor::AddProcessor(new ProcessorScriptMemberFloat()); ObjectProcessor::AddProcessor(new ProcessorScriptMemberFloat());
ObjectProcessor::AddProcessor(new ProcessorScriptGlobalShort());
ObjectProcessor::AddProcessor(new ProcessorScriptGlobalFloat());
ObjectProcessor::AddProcessor(new ProcessorVideoPlay()); ObjectProcessor::AddProcessor(new ProcessorVideoPlay());
ActorProcessor::AddProcessor(new ProcessorActorAI()); ActorProcessor::AddProcessor(new ProcessorActorAI());
@ -193,6 +190,7 @@ void ProcessorInitializer()
ActorProcessor::AddProcessor(new ProcessorActorTest()); ActorProcessor::AddProcessor(new ProcessorActorTest());
WorldstateProcessor::AddProcessor(new ProcessorCellReset()); WorldstateProcessor::AddProcessor(new ProcessorCellReset());
WorldstateProcessor::AddProcessor(new ProcessorClientScriptGlobal());
WorldstateProcessor::AddProcessor(new ProcessorClientScriptSettings()); WorldstateProcessor::AddProcessor(new ProcessorClientScriptSettings());
WorldstateProcessor::AddProcessor(new ProcessorRecordDynamic()); WorldstateProcessor::AddProcessor(new ProcessorRecordDynamic());
WorldstateProcessor::AddProcessor(new ProcessorWorldCollisionOverride()); WorldstateProcessor::AddProcessor(new ProcessorWorldCollisionOverride());

@ -1,24 +0,0 @@
#ifndef OPENMW_PROCESSORSCRIPTGLOBALFLOAT_HPP
#define OPENMW_PROCESSORSCRIPTGLOBALFLOAT_HPP
#include "../ObjectProcessor.hpp"
namespace mwmp
{
class ProcessorScriptGlobalFloat final: public ObjectProcessor
{
public:
ProcessorScriptGlobalFloat()
{
BPP_INIT(ID_SCRIPT_GLOBAL_FLOAT)
}
virtual void Do(ObjectPacket &packet, ObjectList &objectList)
{
LOG_MESSAGE_SIMPLE(TimedLog::LOG_VERBOSE, "Received %s", strPacketID.c_str());
//objectList.setGlobalFloats();
}
};
}
#endif //OPENMW_PROCESSORSCRIPTGLOBALFLOAT_HPP

@ -1,24 +0,0 @@
#ifndef OPENMW_PROCESSORSCRIPTGLOBALSHORT_HPP
#define OPENMW_PROCESSORSCRIPTGLOBALSHORT_HPP
#include "../ObjectProcessor.hpp"
namespace mwmp
{
class ProcessorScriptGlobalShort final: public ObjectProcessor
{
public:
ProcessorScriptGlobalShort()
{
BPP_INIT(ID_SCRIPT_GLOBAL_SHORT)
}
virtual void Do(ObjectPacket &packet, ObjectList &objectList)
{
LOG_MESSAGE_SIMPLE(TimedLog::LOG_VERBOSE, "Received %s", strPacketID.c_str());
objectList.setGlobalShorts();
}
};
}
#endif //OPENMW_PROCESSORSCRIPTGLOBALSHORT_HPP

@ -0,0 +1,25 @@
#ifndef OPENMW_PROCESSORCLIENTSCRIPTGLOBAL_HPP
#define OPENMW_PROCESSORCLIENTSCRIPTGLOBAL_HPP
#include "../WorldstateProcessor.hpp"
namespace mwmp
{
class ProcessorClientScriptGlobal final: public WorldstateProcessor
{
public:
ProcessorClientScriptGlobal()
{
BPP_INIT(ID_CLIENT_SCRIPT_GLOBAL)
}
virtual void Do(WorldstatePacket &packet, Worldstate &worldstate)
{
mwmp::Main::get().getNetworking()->getWorldstate()->setClientGlobals();
}
};
}
#endif //OPENMW_PROCESSORCLIENTSCRIPTGLOBAL_HPP

@ -333,17 +333,13 @@ namespace MWScript
/* /*
Start of tes3mp addition Start of tes3mp addition
Send an ID_SCRIPT_GLOBAL_SHORT packet when a global short changes its value as long as Send an ID_CLIENT_SCRIPT_GLOBAL packet when a global short changes its value as long as
it is being set in a script that has been approved for packet sending or the global itself 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 has been set to always be synchronized
*/ */
if (sendPackets || mwmp::Main::isValidPacketGlobal(name)) if (sendPackets || mwmp::Main::isValidPacketGlobal(name))
{ {
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList(); mwmp::Main::get().getNetworking()->getWorldstate()->sendClientGlobal(name, value);
objectList->reset();
objectList->packetOrigin = ScriptController::getPacketOriginFromContextType(getContextType());
objectList->addScriptGlobalShort(name, value);
objectList->sendScriptGlobalShort();
} }
/* /*
End of tes3mp addition End of tes3mp addition
@ -354,11 +350,61 @@ namespace MWScript
void InterpreterContext::setGlobalLong (const std::string& name, int value) void InterpreterContext::setGlobalLong (const std::string& name, int value)
{ {
/*
Start of tes3mp addition
Avoid setting a global to a value it already is, preventing packet spam
*/
if (getGlobalLong(name) == value) return;
/*
End of tes3mp addition
*/
/*
Start of tes3mp addition
Send an ID_CLIENT_SCRIPT_GLOBAL packet when a global short changes its value as long as
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 || mwmp::Main::isValidPacketGlobal(name))
{
mwmp::Main::get().getNetworking()->getWorldstate()->sendClientGlobal(name, value);
}
/*
End of tes3mp addition
*/
MWBase::Environment::get().getWorld()->setGlobalInt (name, value); MWBase::Environment::get().getWorld()->setGlobalInt (name, value);
} }
void InterpreterContext::setGlobalFloat (const std::string& name, float value) void InterpreterContext::setGlobalFloat (const std::string& name, float value)
{ {
/*
Start of tes3mp addition
Avoid setting a global to a value it already is, preventing packet spam
*/
if (getGlobalFloat(name) == value) return;
/*
End of tes3mp addition
*/
/*
Start of tes3mp addition
Send an ID_CLIENT_SCRIPT_GLOBAL packet when a global short changes its value as long as
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 || mwmp::Main::isValidPacketGlobal(name))
{
mwmp::Main::get().getNetworking()->getWorldstate()->sendClientGlobal(name, value);
}
/*
End of tes3mp addition
*/
MWBase::Environment::get().getWorld()->setGlobalFloat (name, value); MWBase::Environment::get().getWorld()->setGlobalFloat (name, value);
} }

@ -208,15 +208,14 @@ add_component_dir (openmw-mp/Packets/Object
PacketObjectCollision PacketObjectDelete PacketObjectHit PacketObjectLock PacketObjectMove PacketObjectPlace PacketObjectCollision PacketObjectDelete PacketObjectHit PacketObjectLock PacketObjectMove PacketObjectPlace
PacketObjectRotate PacketObjectScale PacketObjectSpawn PacketObjectState PacketObjectTrap PacketMusicPlay PacketObjectRotate PacketObjectScale PacketObjectSpawn PacketObjectState PacketObjectTrap PacketMusicPlay
PacketVideoPlay PacketScriptLocalShort PacketScriptLocalFloat PacketScriptMemberShort PacketScriptMemberFloat PacketVideoPlay PacketScriptLocalShort PacketScriptLocalFloat PacketScriptMemberShort PacketScriptMemberFloat
PacketScriptGlobalShort PacketScriptGlobalFloat
) )
add_component_dir (openmw-mp/Packets/Worldstate add_component_dir (openmw-mp/Packets/Worldstate
WorldstatePacket WorldstatePacket
PacketCellCreate PacketCellReset PacketClientScriptSettings PacketRecordDynamic PacketWorldCollisionOverride PacketCellCreate PacketCellReset PacketClientScriptGlobal PacketClientScriptSettings PacketRecordDynamic
PacketWorldDestinationOverride PacketWorldKillCount PacketWorldMap PacketWorldRegionAuthority PacketWorldTime PacketWorldCollisionOverride PacketWorldDestinationOverride PacketWorldKillCount PacketWorldMap
PacketWorldWeather PacketWorldRegionAuthority PacketWorldTime PacketWorldWeather
) )
add_component_dir (fallback add_component_dir (fallback

@ -20,6 +20,22 @@ namespace mwmp
SERVER_SCRIPT = 5 SERVER_SCRIPT = 5
}; };
enum VARIABLE_TYPE
{
INTEGER,
FLOAT
};
struct ClientVariable
{
std::string id;
char variableType;
int intValue;
float floatValue;
};
struct Time struct Time
{ {
float hour; float hour;

@ -351,6 +351,8 @@ namespace mwmp
std::vector<std::string> synchronizedClientScriptIds; std::vector<std::string> synchronizedClientScriptIds;
std::vector<std::string> synchronizedClientGlobalIds; std::vector<std::string> synchronizedClientGlobalIds;
std::vector<ClientVariable> clientGlobals;
bool hasPlayerCollision; bool hasPlayerCollision;
bool hasActorCollision; bool hasActorCollision;
bool hasPlacedObjectCollision; bool hasPlacedObjectCollision;

@ -24,8 +24,6 @@
#include "../Packets/Object/PacketScriptLocalFloat.hpp" #include "../Packets/Object/PacketScriptLocalFloat.hpp"
#include "../Packets/Object/PacketScriptMemberShort.hpp" #include "../Packets/Object/PacketScriptMemberShort.hpp"
#include "../Packets/Object/PacketScriptMemberFloat.hpp" #include "../Packets/Object/PacketScriptMemberFloat.hpp"
#include "../Packets/Object/PacketScriptGlobalShort.hpp"
#include "../Packets/Object/PacketScriptGlobalFloat.hpp"
#include "ObjectPacketController.hpp" #include "ObjectPacketController.hpp"
@ -65,8 +63,6 @@ mwmp::ObjectPacketController::ObjectPacketController(RakNet::RakPeerInterface *p
AddPacket<PacketScriptLocalFloat>(&packets, peer); AddPacket<PacketScriptLocalFloat>(&packets, peer);
AddPacket<PacketScriptMemberShort>(&packets, peer); AddPacket<PacketScriptMemberShort>(&packets, peer);
AddPacket<PacketScriptMemberFloat>(&packets, peer); AddPacket<PacketScriptMemberFloat>(&packets, peer);
AddPacket<PacketScriptGlobalShort>(&packets, peer);
AddPacket<PacketScriptGlobalFloat>(&packets, peer);
} }

@ -1,4 +1,5 @@
#include "../Packets/Worldstate/PacketCellReset.hpp" #include "../Packets/Worldstate/PacketCellReset.hpp"
#include "../Packets/Worldstate/PacketClientScriptGlobal.hpp"
#include "../Packets/Worldstate/PacketClientScriptSettings.hpp" #include "../Packets/Worldstate/PacketClientScriptSettings.hpp"
#include "../Packets/Worldstate/PacketRecordDynamic.hpp" #include "../Packets/Worldstate/PacketRecordDynamic.hpp"
#include "../Packets/Worldstate/PacketWorldCollisionOverride.hpp" #include "../Packets/Worldstate/PacketWorldCollisionOverride.hpp"
@ -22,6 +23,7 @@ inline void AddPacket(mwmp::WorldstatePacketController::packets_t *packets, RakN
mwmp::WorldstatePacketController::WorldstatePacketController(RakNet::RakPeerInterface *peer) mwmp::WorldstatePacketController::WorldstatePacketController(RakNet::RakPeerInterface *peer)
{ {
AddPacket<PacketCellReset>(&packets, peer); AddPacket<PacketCellReset>(&packets, peer);
AddPacket<PacketClientScriptGlobal>(&packets, peer);
AddPacket<PacketClientScriptSettings>(&packets, peer); AddPacket<PacketClientScriptSettings>(&packets, peer);
AddPacket<PacketRecordDynamic>(&packets, peer); AddPacket<PacketRecordDynamic>(&packets, peer);
AddPacket<PacketWorldCollisionOverride>(&packets, peer); AddPacket<PacketWorldCollisionOverride>(&packets, peer);

@ -93,7 +93,7 @@ enum GameMessages
ID_SCRIPT_LOCAL_FLOAT, ID_SCRIPT_LOCAL_FLOAT,
ID_SCRIPT_MEMBER_SHORT, ID_SCRIPT_MEMBER_SHORT,
ID_SCRIPT_MEMBER_FLOAT, ID_SCRIPT_MEMBER_FLOAT,
ID_SCRIPT_GLOBAL_SHORT, ID_CLIENT_SCRIPT_GLOBAL,
ID_SCRIPT_GLOBAL_FLOAT, ID_SCRIPT_GLOBAL_FLOAT,
ID_GAME_SETTINGS, ID_GAME_SETTINGS,

@ -1,15 +0,0 @@
#include <components/openmw-mp/NetworkMessages.hpp>
#include "PacketScriptGlobalFloat.hpp"
using namespace mwmp;
PacketScriptGlobalFloat::PacketScriptGlobalFloat(RakNet::RakPeerInterface *peer) : ObjectPacket(peer)
{
packetID = ID_SCRIPT_GLOBAL_FLOAT;
}
void PacketScriptGlobalFloat::Object(BaseObject &baseObject, bool send)
{
RW(baseObject.varName, send);
RW(baseObject.floatVal, send);
}

@ -1,17 +0,0 @@
#ifndef OPENMW_PACKETSCRIPTGLOBALFLOAT_HPP
#define OPENMW_PACKETSCRIPTGLOBALFLOAT_HPP
#include <components/openmw-mp/Packets/Object/ObjectPacket.hpp>
namespace mwmp
{
class PacketScriptGlobalFloat : public ObjectPacket
{
public:
PacketScriptGlobalFloat(RakNet::RakPeerInterface *peer);
virtual void Object(BaseObject &baseObject, bool send);
};
}
#endif //OPENMW_PACKETSCRIPTGLOBALFLOAT_HPP

@ -1,15 +0,0 @@
#include <components/openmw-mp/NetworkMessages.hpp>
#include "PacketScriptGlobalShort.hpp"
using namespace mwmp;
PacketScriptGlobalShort::PacketScriptGlobalShort(RakNet::RakPeerInterface *peer) : ObjectPacket(peer)
{
packetID = ID_SCRIPT_GLOBAL_SHORT;
}
void PacketScriptGlobalShort::Object(BaseObject &baseObject, bool send)
{
RW(baseObject.varName, send);
RW(baseObject.shortVal, send);
}

@ -1,17 +0,0 @@
#ifndef OPENMW_PACKETSCRIPTGLOBALSHORT_HPP
#define OPENMW_PACKETSCRIPTGLOBALSHORT_HPP
#include <components/openmw-mp/Packets/Object/ObjectPacket.hpp>
namespace mwmp
{
class PacketScriptGlobalShort : public ObjectPacket
{
public:
PacketScriptGlobalShort(RakNet::RakPeerInterface *peer);
virtual void Object(BaseObject &baseObject, bool send);
};
}
#endif //OPENMW_PACKETSCRIPTGLOBALSHORT_HPP

@ -0,0 +1,39 @@
#include "PacketClientScriptGlobal.hpp"
#include <components/openmw-mp/NetworkMessages.hpp>
using namespace mwmp;
PacketClientScriptGlobal::PacketClientScriptGlobal(RakNet::RakPeerInterface *peer) : WorldstatePacket(peer)
{
packetID = ID_CLIENT_SCRIPT_GLOBAL;
orderChannel = CHANNEL_WORLDSTATE;
}
void PacketClientScriptGlobal::Packet(RakNet::BitStream *newBitstream, bool send)
{
WorldstatePacket::Packet(newBitstream, send);
uint32_t clientGlobalsCount;
if (send)
clientGlobalsCount = static_cast<uint32_t>(worldstate->clientGlobals.size());
RW(clientGlobalsCount, send);
if (!send)
{
worldstate->clientGlobals.clear();
worldstate->clientGlobals.resize(clientGlobalsCount);
}
for (auto &&clientGlobal : worldstate->clientGlobals)
{
RW(clientGlobal.id, send, true);
RW(clientGlobal.variableType, send);
if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::INTEGER)
RW(clientGlobal.intValue, send);
else if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::FLOAT)
RW(clientGlobal.floatValue, send);
}
}

@ -0,0 +1,18 @@
#ifndef OPENMW_PACKETCLIENTSCRIPTGLOBAL_HPP
#define OPENMW_PACKETCLIENTSCRIPTGLOBAL_HPP
#include <components/openmw-mp/Packets/Worldstate/WorldstatePacket.hpp>
#include <components/openmw-mp/NetworkMessages.hpp>
namespace mwmp
{
class PacketClientScriptGlobal: public WorldstatePacket
{
public:
PacketClientScriptGlobal(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *newBitstream, bool send);
};
}
#endif //OPENMW_PACKETCLIENTSCRIPTGLOBAL_HPP
Loading…
Cancel
Save