From c8cbfbef62ea14f26c5833d235f6f55760beebf0 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 14 Feb 2017 19:31:56 +0200 Subject: [PATCH] [General] Sketch out server requests to players for container data --- apps/openmw-mp/Script/Functions/World.cpp | 10 ++++ apps/openmw-mp/Script/Functions/World.hpp | 62 +++++++++++---------- apps/openmw/mwmp/Networking.cpp | 9 ++- apps/openmw/mwmp/WorldEvent.cpp | 7 ++- apps/openmw/mwmp/WorldEvent.hpp | 4 +- apps/openmw/mwscript/interpretercontext.cpp | 2 +- components/openmw-mp/Base/BaseEvent.hpp | 5 +- 7 files changed, 65 insertions(+), 34 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/World.cpp b/apps/openmw-mp/Script/Functions/World.cpp index 656c1bef3..8ccc77f43 100644 --- a/apps/openmw-mp/Script/Functions/World.cpp +++ b/apps/openmw-mp/Script/Functions/World.cpp @@ -67,6 +67,11 @@ void WorldFunctions::SetBaseEventCell(const char* cellDescription) noexcept } } +void WorldFunctions::SetContainerChangesAction(int action) noexcept +{ + baseEvent->containerChanges.action = action; +} + void WorldFunctions::SetObjectRefId(const char* refId) noexcept { tempWorldObject.refId = refId; @@ -196,6 +201,11 @@ double WorldFunctions::GetObjectRotZ(unsigned int i) noexcept return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(i).pos.rot[2]; } +void WorldFunctions::SendContainer() noexcept +{ + mwmp::Networking::get().getWorldController()->GetPacket(ID_CONTAINER)->Send(baseEvent, baseEvent->guid); +} + void WorldFunctions::SendObjectDelete() noexcept { mwmp::Networking::get().getWorldController()->GetPacket(ID_OBJECT_DELETE)->Send(baseEvent, baseEvent->guid); diff --git a/apps/openmw-mp/Script/Functions/World.hpp b/apps/openmw-mp/Script/Functions/World.hpp index e28dd3de0..4cda3a16e 100644 --- a/apps/openmw-mp/Script/Functions/World.hpp +++ b/apps/openmw-mp/Script/Functions/World.hpp @@ -2,38 +2,41 @@ #define OPENMW_WORLD_HPP #define WORLDFUNCTIONS \ - {"CreateBaseEvent", WorldFunctions::CreateBaseEvent},\ + {"CreateBaseEvent", WorldFunctions::CreateBaseEvent},\ \ - {"AddWorldObject", WorldFunctions::AddWorldObject},\ - {"SetBaseEventCell", WorldFunctions::SetBaseEventCell},\ + {"AddWorldObject", WorldFunctions::AddWorldObject},\ + {"SetBaseEventCell", WorldFunctions::SetBaseEventCell},\ + {"SetContainerChangesAction", WorldFunctions::SetContainerChangesAction},\ \ - {"SetObjectRefId", WorldFunctions::SetObjectRefId},\ - {"SetObjectRefNumIndex", WorldFunctions::SetObjectRefNumIndex},\ - {"SetObjectCharge", WorldFunctions::SetObjectCharge},\ - {"SetObjectCount", WorldFunctions::SetObjectCount},\ - {"SetObjectGoldValue", WorldFunctions::SetObjectGoldValue},\ - {"SetObjectScale", WorldFunctions::SetObjectScale},\ - {"SetObjectDoorState", WorldFunctions::SetObjectDoorState},\ - {"SetObjectLockLevel", WorldFunctions::SetObjectLockLevel},\ - {"SetObjectPosition", WorldFunctions::SetObjectPosition},\ - {"SetObjectRotation", WorldFunctions::SetObjectRotation},\ + {"SetObjectRefId", WorldFunctions::SetObjectRefId},\ + {"SetObjectRefNumIndex", WorldFunctions::SetObjectRefNumIndex},\ + {"SetObjectCharge", WorldFunctions::SetObjectCharge},\ + {"SetObjectCount", WorldFunctions::SetObjectCount},\ + {"SetObjectGoldValue", WorldFunctions::SetObjectGoldValue},\ + {"SetObjectScale", WorldFunctions::SetObjectScale},\ + {"SetObjectDoorState", WorldFunctions::SetObjectDoorState},\ + {"SetObjectLockLevel", WorldFunctions::SetObjectLockLevel},\ + {"SetObjectPosition", WorldFunctions::SetObjectPosition},\ + {"SetObjectRotation", WorldFunctions::SetObjectRotation},\ \ - {"GetObjectChangesSize", WorldFunctions::GetObjectChangesSize},\ + {"GetObjectChangesSize", WorldFunctions::GetObjectChangesSize},\ \ - {"GetObjectRefId", WorldFunctions::GetObjectRefId},\ - {"GetObjectRefNumIndex", WorldFunctions::GetObjectRefNumIndex},\ - {"GetObjectCharge", WorldFunctions::GetObjectCharge},\ - {"GetObjectCount", WorldFunctions::GetObjectCount},\ - {"GetObjectGoldValue", WorldFunctions::GetObjectGoldValue},\ - {"GetObjectScale", WorldFunctions::GetObjectScale},\ - {"GetObjectDoorState", WorldFunctions::GetObjectDoorState},\ - {"GetObjectLockLevel", WorldFunctions::GetObjectLockLevel},\ - {"GetObjectPosX", WorldFunctions::GetObjectPosX},\ - {"GetObjectPosY", WorldFunctions::GetObjectPosY},\ - {"GetObjectPosZ", WorldFunctions::GetObjectPosZ},\ - {"GetObjectRotX", WorldFunctions::GetObjectRotX},\ - {"GetObjectRotY", WorldFunctions::GetObjectRotY},\ - {"GetObjectRotZ", WorldFunctions::GetObjectRotZ},\ + {"GetObjectRefId", WorldFunctions::GetObjectRefId},\ + {"GetObjectRefNumIndex", WorldFunctions::GetObjectRefNumIndex},\ + {"GetObjectCharge", WorldFunctions::GetObjectCharge},\ + {"GetObjectCount", WorldFunctions::GetObjectCount},\ + {"GetObjectGoldValue", WorldFunctions::GetObjectGoldValue},\ + {"GetObjectScale", WorldFunctions::GetObjectScale},\ + {"GetObjectDoorState", WorldFunctions::GetObjectDoorState},\ + {"GetObjectLockLevel", WorldFunctions::GetObjectLockLevel},\ + {"GetObjectPosX", WorldFunctions::GetObjectPosX},\ + {"GetObjectPosY", WorldFunctions::GetObjectPosY},\ + {"GetObjectPosZ", WorldFunctions::GetObjectPosZ},\ + {"GetObjectRotX", WorldFunctions::GetObjectRotX},\ + {"GetObjectRotY", WorldFunctions::GetObjectRotY},\ + {"GetObjectRotZ", WorldFunctions::GetObjectRotZ},\ + \ + {"SendContainer", WorldFunctions::SendContainer},\ \ {"SendObjectDelete", WorldFunctions::SendObjectDelete},\ {"SendObjectPlace", WorldFunctions::SendObjectPlace},\ @@ -54,6 +57,7 @@ public: static void AddWorldObject() noexcept; static void SetBaseEventCell(const char* cellDescription) noexcept; + static void SetContainerChangesAction(int action) noexcept; static void SetObjectRefId(const char* refId) noexcept; static void SetObjectRefNumIndex(int refNumIndex) noexcept; @@ -83,6 +87,8 @@ public: static double GetObjectRotY(unsigned int i) noexcept; static double GetObjectRotZ(unsigned int i) noexcept; + static void SendContainer() noexcept; + static void SendObjectDelete() noexcept; static void SendObjectPlace() noexcept; static void SendObjectScale() noexcept; diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 889c4abc1..b26b617ce 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -735,6 +735,7 @@ void Networking::processWorldPacket(RakNet::Packet *packet) WorldPacket *myPacket = worldController.GetPacket(packet->data[0]); WorldEvent *event = new WorldEvent(guid); + myPacket->Packet(&bsIn, event, false); switch (packet->data[0]) @@ -746,7 +747,13 @@ void Networking::processWorldPacket(RakNet::Packet *packet) if (!ptrCellStore) return; LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_CONTAINER"); - event->editContainer(ptrCellStore); + + // If we've received a request for information, comply with it + if (event->containerChanges.action == mwmp::ContainerChanges::REQUEST) + event->sendContainers(ptrCellStore); + // Otherwise, edit containers based on the information received + else + event->editContainers(ptrCellStore); break; } diff --git a/apps/openmw/mwmp/WorldEvent.cpp b/apps/openmw/mwmp/WorldEvent.cpp index e895fed06..824d57322 100644 --- a/apps/openmw/mwmp/WorldEvent.cpp +++ b/apps/openmw/mwmp/WorldEvent.cpp @@ -45,7 +45,12 @@ void WorldEvent::addContainerItem(ContainerItem containerItem) containerChanges.items.push_back(containerItem); } -void WorldEvent::editContainer(MWWorld::CellStore* cellStore) +void WorldEvent::sendContainers(MWWorld::CellStore* cellStore) +{ + +} + +void WorldEvent::editContainers(MWWorld::CellStore* cellStore) { WorldObject worldObject; diff --git a/apps/openmw/mwmp/WorldEvent.hpp b/apps/openmw/mwmp/WorldEvent.hpp index 70cb408e1..22edc527e 100644 --- a/apps/openmw/mwmp/WorldEvent.hpp +++ b/apps/openmw/mwmp/WorldEvent.hpp @@ -18,7 +18,9 @@ namespace mwmp void addObject(WorldObject worldObject); void addContainerItem(ContainerItem containerItem); - void editContainer(MWWorld::CellStore* cellStore); + void sendContainers(MWWorld::CellStore* cellStore); + + void editContainers(MWWorld::CellStore* cellStore); void placeObjects(MWWorld::CellStore* cellStore); void deleteObjects(MWWorld::CellStore* cellStore); void lockObjects(MWWorld::CellStore* cellStore); diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 2be4ea654..7312f704e 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -277,7 +277,7 @@ namespace MWScript return MWBase::Environment::get().getWindowManager()->isGuiMode(); */ - return 0; + return false; } int InterpreterContext::getGlobalShort (const std::string& name) const diff --git a/components/openmw-mp/Base/BaseEvent.hpp b/components/openmw-mp/Base/BaseEvent.hpp index 8a806b165..66368b518 100644 --- a/components/openmw-mp/Base/BaseEvent.hpp +++ b/components/openmw-mp/Base/BaseEvent.hpp @@ -63,10 +63,11 @@ namespace mwmp { SET = 0, ADD = 1, - REMOVE = 2 + REMOVE = 2, + REQUEST = 3 }; - int action; // 0 - Clear and set in entirety, 1 - Add item, 2 - Remove item + int action; // 0 - Clear and set in entirety, 1 - Add item, 2 - Remove item, 3 - Request items }; class BaseEvent