From d163f1b6dad4e727cf2e4462cc6925591d546604 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 8 Oct 2019 11:09:08 +0300 Subject: [PATCH] [General] Turn WorldKillCount into a Worldstate packet Rename the old WorldKillCount that was a Player packet into PlayerPlaceholder. Rename the unused CellCreate that was a Worldstate packet into WorldKillCount. On the server, move kill count-related script functions from QuestFunctions to WorldstateFunctions. --- apps/openmw-mp/CMakeLists.txt | 6 +- apps/openmw-mp/Script/Functions/Quests.cpp | 66 ------------------ apps/openmw-mp/Script/Functions/Quests.hpp | 68 +------------------ .../openmw-mp/Script/Functions/Worldstate.cpp | 46 +++++++++++++ .../openmw-mp/Script/Functions/Worldstate.hpp | 61 +++++++++++++++++ .../processors/ProcessorInitializer.cpp | 6 +- .../player/ProcessorPlayerPlaceholder.hpp | 23 +++++++ .../ProcessorWorldKillCount.hpp | 6 +- apps/openmw/CMakeLists.txt | 9 +-- apps/openmw/mwmechanics/actors.cpp | 2 +- apps/openmw/mwmp/LocalPlayer.cpp | 37 ---------- apps/openmw/mwmp/LocalPlayer.hpp | 2 - apps/openmw/mwmp/Worldstate.cpp | 39 +++++++++++ apps/openmw/mwmp/Worldstate.hpp | 2 + .../mwmp/processors/ProcessorInitializer.cpp | 8 +-- ...unt.hpp => ProcessorPlayerPlaceholder.hpp} | 14 ++-- .../worldstate/ProcessorCellCreate.hpp | 23 ------- .../worldstate/ProcessorWorldKillCount.hpp | 23 +++++++ components/CMakeLists.txt | 12 ++-- components/openmw-mp/Base/BasePlayer.hpp | 13 ---- components/openmw-mp/Base/BaseWorldstate.hpp | 7 ++ .../Controllers/PlayerPacketController.cpp | 4 +- .../WorldstatePacketController.cpp | 4 +- .../Player/PacketPlayerPlaceholder.cpp | 12 ++++ .../Player/PacketPlayerPlaceholder.hpp | 17 +++++ .../Packets/Player/PacketWorldKillCount.cpp | 33 --------- .../Packets/Worldstate/PacketCellCreate.cpp | 17 ----- .../Packets/Worldstate/PacketCellCreate.hpp | 18 ----- .../Worldstate/PacketWorldKillCount.cpp | 34 ++++++++++ .../PacketWorldKillCount.hpp | 5 +- 30 files changed, 306 insertions(+), 311 deletions(-) create mode 100644 apps/openmw-mp/processors/player/ProcessorPlayerPlaceholder.hpp rename apps/openmw-mp/processors/{player => worldstate}/ProcessorWorldKillCount.hpp (68%) rename apps/openmw/mwmp/processors/player/{ProcessorWorldKillCount.hpp => ProcessorPlayerPlaceholder.hpp} (54%) delete mode 100644 apps/openmw/mwmp/processors/worldstate/ProcessorCellCreate.hpp create mode 100644 apps/openmw/mwmp/processors/worldstate/ProcessorWorldKillCount.hpp create mode 100644 components/openmw-mp/Packets/Player/PacketPlayerPlaceholder.cpp create mode 100644 components/openmw-mp/Packets/Player/PacketPlayerPlaceholder.hpp delete mode 100644 components/openmw-mp/Packets/Player/PacketWorldKillCount.cpp delete mode 100644 components/openmw-mp/Packets/Worldstate/PacketCellCreate.cpp delete mode 100644 components/openmw-mp/Packets/Worldstate/PacketCellCreate.hpp create mode 100644 components/openmw-mp/Packets/Worldstate/PacketWorldKillCount.cpp rename components/openmw-mp/Packets/{Player => Worldstate}/PacketWorldKillCount.hpp (62%) diff --git a/apps/openmw-mp/CMakeLists.txt b/apps/openmw-mp/CMakeLists.txt index 0383dfe56..0daa3ccb6 100644 --- a/apps/openmw-mp/CMakeLists.txt +++ b/apps/openmw-mp/CMakeLists.txt @@ -101,7 +101,7 @@ set(PROCESSORS_PLAYER processors/player/ProcessorPlayerDisposition.hpp processors/player/ProcessorPlayerEquipment.hpp processors/player/ProcessorPlayerFaction.hpp processors/player/ProcessorPlayerInput.hpp processors/player/ProcessorPlayerInventory.hpp processors/player/ProcessorPlayerItemUse.hpp - processors/player/ProcessorPlayerJournal.hpp processors/player/ProcessorWorldKillCount.hpp + processors/player/ProcessorPlayerJournal.hpp processors/player/ProcessorPlayerPlaceholder.hpp processors/player/ProcessorPlayerLevel.hpp processors/player/ProcessorPlayerMiscellaneous.hpp processors/player/ProcessorPlayerPosition.hpp processors/player/ProcessorPlayerQuickKeys.hpp processors/player/ProcessorPlayerRest.hpp processors/player/ProcessorPlayerResurrect.hpp @@ -129,8 +129,8 @@ set(PROCESSORS_OBJECT source_group(tes3mp-server\\processors\\object FILES ${PROCESSORS_OBJECT}) set(PROCESSORS_WORLDSTATE - processors/worldstate/ProcessorRecordDynamic.hpp processors/worldstate/ProcessorWorldMap.hpp - processors/worldstate/ProcessorWorldWeather.hpp + processors/worldstate/ProcessorRecordDynamic.hpp processors/worldstate/ProcessorWorldKillCount.hpp + processors/worldstate/ProcessorWorldMap.hpp processors/worldstate/ProcessorWorldWeather.hpp ) source_group(tes3mp-server\\processors\\worldstate FILES ${PROCESSORS_WORLDSTATE}) diff --git a/apps/openmw-mp/Script/Functions/Quests.cpp b/apps/openmw-mp/Script/Functions/Quests.cpp index 9711a05ef..627fa3047 100644 --- a/apps/openmw-mp/Script/Functions/Quests.cpp +++ b/apps/openmw-mp/Script/Functions/Quests.cpp @@ -16,14 +16,6 @@ void QuestFunctions::ClearJournalChanges(unsigned short pid) noexcept player->journalChanges.journalItems.clear(); } -void QuestFunctions::ClearKillChanges(unsigned short pid) noexcept -{ - Player *player; - GET_PLAYER(pid, player, ); - - player->killChanges.kills.clear(); -} - unsigned int QuestFunctions::GetJournalChangesSize(unsigned short pid) noexcept { Player *player; @@ -32,14 +24,6 @@ unsigned int QuestFunctions::GetJournalChangesSize(unsigned short pid) noexcept return player->journalChanges.count; } -unsigned int QuestFunctions::GetKillChangesSize(unsigned short pid) noexcept -{ - Player *player; - GET_PLAYER(pid, player, 0); - - return player->killChanges.count; -} - void QuestFunctions::AddJournalEntry(unsigned short pid, const char* quest, unsigned int index, const char* actorRefId) noexcept { Player *player; @@ -88,18 +72,6 @@ void QuestFunctions::AddJournalIndex(unsigned short pid, const char* quest, unsi player->journalChanges.journalItems.push_back(journalItem); } -void QuestFunctions::AddKill(unsigned short pid, const char* refId, int number) noexcept -{ - Player *player; - GET_PLAYER(pid, player, ); - - mwmp::Kill kill; - kill.refId = refId; - kill.number = number; - - player->killChanges.kills.push_back(kill); -} - void QuestFunctions::SetReputation(unsigned short pid, int value) noexcept { Player *player; @@ -143,25 +115,6 @@ const char *QuestFunctions::GetJournalItemActorRefId(unsigned short pid, unsigne return player->journalChanges.journalItems.at(index).actorRefId.c_str(); } -const char *QuestFunctions::GetKillRefId(unsigned short pid, unsigned int index) noexcept -{ - Player *player; - GET_PLAYER(pid, player, ""); - - if (index >= player->killChanges.count) - return "invalid"; - - return player->killChanges.kills.at(index).refId.c_str(); -} - -int QuestFunctions::GetKillNumber(unsigned short pid, unsigned int index) noexcept -{ - Player *player; - GET_PLAYER(pid, player, 0); - - return player->killChanges.kills.at(index).number; -} - int QuestFunctions::GetReputation(unsigned short pid) noexcept { Player *player; @@ -184,20 +137,6 @@ void QuestFunctions::SendJournalChanges(unsigned short pid, bool sendToOtherPlay packet->Send(true); } -void QuestFunctions::SendKillChanges(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept -{ - Player *player; - GET_PLAYER(pid, player, ); - - mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_WORLD_KILL_COUNT); - packet->setPlayer(player); - - if (!skipAttachedPlayer) - packet->Send(false); - if (sendToOtherPlayers) - packet->Send(true); -} - void QuestFunctions::SendReputation(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept { Player *player; @@ -218,8 +157,3 @@ void QuestFunctions::InitializeJournalChanges(unsigned short pid) noexcept { ClearJournalChanges(pid); } - -void QuestFunctions::InitializeKillChanges(unsigned short pid) noexcept -{ - ClearKillChanges(pid); -} diff --git a/apps/openmw-mp/Script/Functions/Quests.hpp b/apps/openmw-mp/Script/Functions/Quests.hpp index 27912a928..5aec5100f 100644 --- a/apps/openmw-mp/Script/Functions/Quests.hpp +++ b/apps/openmw-mp/Script/Functions/Quests.hpp @@ -3,15 +3,12 @@ #define QUESTAPI \ {"ClearJournalChanges", QuestFunctions::ClearJournalChanges},\ - {"ClearKillChanges", QuestFunctions::ClearKillChanges},\ \ {"GetJournalChangesSize", QuestFunctions::GetJournalChangesSize},\ - {"GetKillChangesSize", QuestFunctions::GetKillChangesSize},\ \ {"AddJournalEntry", QuestFunctions::AddJournalEntry},\ {"AddJournalEntryWithTimestamp", QuestFunctions::AddJournalEntryWithTimestamp},\ {"AddJournalIndex", QuestFunctions::AddJournalIndex},\ - {"AddKill", QuestFunctions::AddKill},\ \ {"SetReputation", QuestFunctions::SetReputation},\ \ @@ -19,17 +16,13 @@ {"GetJournalItemIndex", QuestFunctions::GetJournalItemIndex},\ {"GetJournalItemType", QuestFunctions::GetJournalItemType},\ {"GetJournalItemActorRefId", QuestFunctions::GetJournalItemActorRefId},\ - {"GetKillRefId", QuestFunctions::GetKillRefId},\ - {"GetKillNumber", QuestFunctions::GetKillNumber},\ \ {"GetReputation", QuestFunctions::GetReputation},\ \ {"SendJournalChanges", QuestFunctions::SendJournalChanges},\ - {"SendKillChanges", QuestFunctions::SendKillChanges},\ {"SendReputation", QuestFunctions::SendReputation},\ \ - {"InitializeJournalChanges", QuestFunctions::InitializeJournalChanges},\ - {"InitializeKillChanges", QuestFunctions::InitializeKillChanges} + {"InitializeJournalChanges", QuestFunctions::InitializeJournalChanges} class QuestFunctions { @@ -45,16 +38,6 @@ public: */ static void ClearJournalChanges(unsigned short pid) noexcept; - /** - * \brief Clear the last recorded kill count changes for a player. - * - * This is used to initialize the sending of new WorldKillCount packets. - * - * \param pid The player ID whose kill count changes should be used. - * \return void - */ - static void ClearKillChanges(unsigned short pid) noexcept; - /** * \brief Get the number of indexes in a player's latest journal changes. * @@ -63,14 +46,6 @@ public: */ static unsigned int GetJournalChangesSize(unsigned short pid) noexcept; - /** - * \brief Get the number of indexes in a player's latest kill count changes. - * - * \param pid The player ID whose kill count changes should be used. - * \return The number of indexes. - */ - static unsigned int GetKillChangesSize(unsigned short pid) noexcept; - /** * \brief Add a new journal item of type ENTRY to the journal changes for a player, * with a specific timestamp. @@ -109,16 +84,6 @@ public: */ static void AddJournalIndex(unsigned short pid, const char* quest, unsigned int index) noexcept; - /** - * \brief Add a new kill count to the kill count changes for a player. - * - * \param pid The player ID whose kill count changes should be used. - * \param refId The refId of the kill count. - * \param number The number of kills in the kill count. - * \return void - */ - static void AddKill(unsigned short pid, const char* refId, int number) noexcept; - /** * \brief Set the reputation of a certain player. * @@ -166,24 +131,6 @@ public: */ static const char *GetJournalItemActorRefId(unsigned short pid, unsigned int index) noexcept; - /** - * \brief Get the refId at a certain index in a player's latest kill count changes. - * - * \param pid The player ID whose kill count changes should be used. - * \param index The index of the kill count. - * \return The refId. - */ - static const char *GetKillRefId(unsigned short pid, unsigned int index) noexcept; - - /** - * \brief Get the number of kills at a certain index in a player's latest kill count changes. - * - * \param pid The player ID whose kill count changes should be used. - * \param index The index of the kill count. - * \return The number of kills. - */ - static int GetKillNumber(unsigned short pid, unsigned int index) noexcept; - /** * \brief Get the a certain player's reputation. * @@ -204,18 +151,6 @@ public: */ static void SendJournalChanges(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept; - /** - * \brief Send a WorldKillCount packet with a player's recorded kill count changes. - * - * \param pid The player ID whose kill count changes should be used. - * \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 SendKillChanges(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept; - /** * \brief Send a PlayerReputation packet with a player's recorded reputation. * @@ -231,7 +166,6 @@ public: // All methods below are deprecated versions of methods from above static void InitializeJournalChanges(unsigned short pid) noexcept; - static void InitializeKillChanges(unsigned short pid) noexcept; private: diff --git a/apps/openmw-mp/Script/Functions/Worldstate.cpp b/apps/openmw-mp/Script/Functions/Worldstate.cpp index 164e3af45..6423275df 100644 --- a/apps/openmw-mp/Script/Functions/Worldstate.cpp +++ b/apps/openmw-mp/Script/Functions/Worldstate.cpp @@ -23,16 +23,36 @@ void WorldstateFunctions::CopyReceivedWorldstateToStore() noexcept writeWorldstate = *readWorldstate; } +void WorldstateFunctions::ClearKillChanges() noexcept +{ + writeWorldstate.killChanges.clear(); +} + void WorldstateFunctions::ClearMapChanges() noexcept { writeWorldstate.mapTiles.clear(); } +unsigned int WorldstateFunctions::GetKillChangesSize() noexcept +{ + return readWorldstate->killChanges.size(); +} + unsigned int WorldstateFunctions::GetMapChangesSize() noexcept { return readWorldstate->mapTiles.size(); } +const char *WorldstateFunctions::GetKillRefId(unsigned int index) noexcept +{ + return readWorldstate->killChanges.at(index).refId.c_str(); +} + +int WorldstateFunctions::GetKillNumber(unsigned int index) noexcept +{ + return readWorldstate->killChanges.at(index).number; +} + const char *WorldstateFunctions::GetWeatherRegion() noexcept { return readWorldstate->weather.region.c_str(); @@ -153,6 +173,15 @@ void WorldstateFunctions::UseActorCollisionForPlacedObjects(bool useActorCollisi writeWorldstate.useActorCollisionForPlacedObjects = useActorCollision; } +void WorldstateFunctions::AddKill(const char* refId, int number) noexcept +{ + mwmp::Kill kill; + kill.refId = refId; + kill.number = number; + + writeWorldstate.killChanges.push_back(kill); +} + void WorldstateFunctions::AddSynchronizedClientScriptId(const char *scriptId) noexcept { writeWorldstate.synchronizedClientScriptIds.push_back(scriptId); @@ -232,6 +261,23 @@ void WorldstateFunctions::SendClientScriptSettings(unsigned short pid, bool send packet->Send(true); } + +void WorldstateFunctions::SendWorldKillCount(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_WORLD_KILL_COUNT); + packet->setWorldstate(&writeWorldstate); + + if (!skipAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) + packet->Send(true); +} + void WorldstateFunctions::SendWorldMap(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept { Player *player; diff --git a/apps/openmw-mp/Script/Functions/Worldstate.hpp b/apps/openmw-mp/Script/Functions/Worldstate.hpp index d1c551c8c..d0d35b073 100644 --- a/apps/openmw-mp/Script/Functions/Worldstate.hpp +++ b/apps/openmw-mp/Script/Functions/Worldstate.hpp @@ -9,10 +9,15 @@ \ {"CopyReceivedWorldstateToStore", WorldstateFunctions::CopyReceivedWorldstateToStore},\ \ + {"ClearKillChanges", WorldstateFunctions::ClearKillChanges},\ {"ClearMapChanges", WorldstateFunctions::ClearMapChanges},\ \ + {"GetKillChangesSize", WorldstateFunctions::GetKillChangesSize},\ {"GetMapChangesSize", WorldstateFunctions::GetMapChangesSize},\ \ + {"GetKillRefId", WorldstateFunctions::GetKillRefId},\ + {"GetKillNumber", WorldstateFunctions::GetKillNumber},\ + \ {"GetWeatherRegion", WorldstateFunctions::GetWeatherRegion},\ {"GetWeatherCurrent", WorldstateFunctions::GetWeatherCurrent},\ {"GetWeatherNext", WorldstateFunctions::GetWeatherNext},\ @@ -43,6 +48,7 @@ {"SetPlacedObjectCollisionState", WorldstateFunctions::SetPlacedObjectCollisionState},\ {"UseActorCollisionForPlacedObjects", WorldstateFunctions::UseActorCollisionForPlacedObjects},\ \ + {"AddKill", WorldstateFunctions::AddKill},\ {"AddSynchronizedClientScriptId", WorldstateFunctions::AddSynchronizedClientScriptId},\ {"AddSynchronizedClientGlobalId", WorldstateFunctions::AddSynchronizedClientGlobalId},\ {"AddEnforcedCollisionRefId", WorldstateFunctions::AddEnforcedCollisionRefId},\ @@ -55,6 +61,7 @@ {"LoadMapTileImageFile", WorldstateFunctions::LoadMapTileImageFile},\ \ {"SendClientScriptSettings", WorldstateFunctions::SendClientScriptSettings},\ + {"SendWorldKillCount", WorldstateFunctions::SendWorldKillCount},\ {"SendWorldMap", WorldstateFunctions::SendWorldMap},\ {"SendWorldTime", WorldstateFunctions::SendWorldTime},\ {"SendWorldWeather", WorldstateFunctions::SendWorldWeather},\ @@ -87,6 +94,15 @@ public: */ static void CopyReceivedWorldstateToStore() noexcept; + /** + * \brief Clear the kill count changes for the write-only worldstate. + * + * This is used to initialize the sending of new WorldKillCount packets. + * + * \return void + */ + static void ClearKillChanges() noexcept; + /** * \brief Clear the map changes for the write-only worldstate. * @@ -103,6 +119,29 @@ public: */ static unsigned int GetMapChangesSize() noexcept; + /** + * \brief Get the number of indexes in the read worldstate's kill changes. + * + * \return The number of indexes. + */ + static unsigned int GetKillChangesSize() noexcept; + + /** + * \brief Get the refId at a certain index in the read worldstate's kill count changes. + * + * \param index The index of the kill count. + * \return The refId. + */ + static const char *GetKillRefId(unsigned int index) noexcept; + + /** + * \brief Get the number of kills at a certain index in the read worldstate's kill count changes. + * + * \param index The index of the kill count. + * \return The number of kills. + */ + static int GetKillNumber(unsigned int index) noexcept; + /** * \brief Get the weather region in the read worldstate. * @@ -299,6 +338,15 @@ public: */ static void UseActorCollisionForPlacedObjects(bool useActorCollision) noexcept; + /** + * \brief Add a new kill count to the kill count changes. + * + * \param refId The refId of the kill count. + * \param number The number of kills in the kill count. + * \return void + */ + static void AddKill(const char* refId, int number) noexcept; + /** * \brief Add an ID to the list of script IDs whose variable changes should be sent to the * the server by clients. @@ -384,6 +432,19 @@ public: */ static void SendClientScriptSettings(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept; + /** + * \brief Send a WorldKillCount packet with the current set of kill count changes 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 SendWorldKillCount(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept; + /** * \brief Send a WorldRegionAuthority packet establishing a certain player as the only one who * should process certain region-specific events (such as weather changes). diff --git a/apps/openmw-mp/processors/ProcessorInitializer.cpp b/apps/openmw-mp/processors/ProcessorInitializer.cpp index 9418ceb12..42bb49ca2 100644 --- a/apps/openmw-mp/processors/ProcessorInitializer.cpp +++ b/apps/openmw-mp/processors/ProcessorInitializer.cpp @@ -24,7 +24,7 @@ #include "player/ProcessorPlayerInventory.hpp" #include "player/ProcessorPlayerItemUse.hpp" #include "player/ProcessorPlayerJournal.hpp" -#include "player/ProcessorWorldKillCount.hpp" +#include "player/ProcessorPlayerPlaceholder.hpp" #include "player/ProcessorPlayerInput.hpp" #include "player/ProcessorPlayerLevel.hpp" #include "player/ProcessorPlayerMiscellaneous.hpp" @@ -77,6 +77,7 @@ #include "object/ProcessorVideoPlay.hpp" #include "WorldstateProcessor.hpp" #include "worldstate/ProcessorRecordDynamic.hpp" +#include "worldstate/ProcessorWorldKillCount.hpp" #include "worldstate/ProcessorWorldMap.hpp" #include "worldstate/ProcessorWorldWeather.hpp" @@ -104,7 +105,7 @@ void ProcessorInitializer() PlayerProcessor::AddProcessor(new ProcessorPlayerInventory()); PlayerProcessor::AddProcessor(new ProcessorPlayerItemUse()); PlayerProcessor::AddProcessor(new ProcessorPlayerJournal()); - PlayerProcessor::AddProcessor(new ProcessorWorldKillCount()); + PlayerProcessor::AddProcessor(new ProcessorPlayerPlaceholder()); PlayerProcessor::AddProcessor(new ProcessorPlayerInput()); PlayerProcessor::AddProcessor(new ProcessorPlayerLevel()); PlayerProcessor::AddProcessor(new ProcessorPlayerMiscellaneous()); @@ -157,6 +158,7 @@ void ProcessorInitializer() ObjectProcessor::AddProcessor(new ProcessorVideoPlay()); WorldstateProcessor::AddProcessor(new ProcessorRecordDynamic()); + WorldstateProcessor::AddProcessor(new ProcessorWorldKillCount()); WorldstateProcessor::AddProcessor(new ProcessorWorldMap()); WorldstateProcessor::AddProcessor(new ProcessorWorldWeather()); } diff --git a/apps/openmw-mp/processors/player/ProcessorPlayerPlaceholder.hpp b/apps/openmw-mp/processors/player/ProcessorPlayerPlaceholder.hpp new file mode 100644 index 000000000..a1f6dbc73 --- /dev/null +++ b/apps/openmw-mp/processors/player/ProcessorPlayerPlaceholder.hpp @@ -0,0 +1,23 @@ +#ifndef OPENMW_PROCESSORPLACEHOLDER_HPP +#define OPENMW_PROCESSORPLACEHOLDER_HPP + +#include "../PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerPlaceholder : public PlayerProcessor + { + public: + ProcessorPlayerPlaceholder() + { + BPP_INIT(ID_WORLD_KILL_COUNT) + } + + void Do(PlayerPacket &packet, Player &player) override + { + DEBUG_PRINTF(strPacketID.c_str()); + } + }; +} + +#endif //OPENMW_PROCESSORPLACEHOLDER_HPP diff --git a/apps/openmw-mp/processors/player/ProcessorWorldKillCount.hpp b/apps/openmw-mp/processors/worldstate/ProcessorWorldKillCount.hpp similarity index 68% rename from apps/openmw-mp/processors/player/ProcessorWorldKillCount.hpp rename to apps/openmw-mp/processors/worldstate/ProcessorWorldKillCount.hpp index 5cac71186..06bfc9128 100644 --- a/apps/openmw-mp/processors/player/ProcessorWorldKillCount.hpp +++ b/apps/openmw-mp/processors/worldstate/ProcessorWorldKillCount.hpp @@ -1,11 +1,11 @@ #ifndef OPENMW_PROCESSORWORLDKILLCOUNT_HPP #define OPENMW_PROCESSORWORLDKILLCOUNT_HPP -#include "../PlayerProcessor.hpp" +#include "../WorldstateProcessor.hpp" namespace mwmp { - class ProcessorWorldKillCount : public PlayerProcessor + class ProcessorWorldKillCount : public WorldstateProcessor { public: ProcessorWorldKillCount() @@ -13,7 +13,7 @@ namespace mwmp BPP_INIT(ID_WORLD_KILL_COUNT) } - void Do(PlayerPacket &packet, Player &player) override + void Do(WorldstatePacket &packet, Player &player, BaseWorldstate &worldstate) override { DEBUG_PRINTF(strPacketID.c_str()); diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 3f8ce4330..5f74b55e0 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -117,9 +117,10 @@ add_openmw_dir (mwmp/processors/player ProcessorChatMessage ProcessorGUIMessageB ProcessorPlayerBounty ProcessorPlayerCast ProcessorPlayerCellChange ProcessorPlayerCellState ProcessorPlayerCharClass ProcessorPlayerCharGen ProcessorPlayerDeath ProcessorPlayerDisposition ProcessorPlayerEquipment ProcessorPlayerFaction ProcessorPlayerInput ProcessorPlayerInventory ProcessorPlayerItemUse ProcessorPlayerJail ProcessorPlayerJournal - ProcessorWorldKillCount ProcessorPlayerLevel ProcessorPlayerMiscellaneous ProcessorPlayerMomentum ProcessorPlayerPosition - ProcessorPlayerQuickKeys ProcessorPlayerReputation ProcessorPlayerResurrect ProcessorPlayerShapeshift ProcessorPlayerSkill + ProcessorPlayerLevel ProcessorPlayerMiscellaneous ProcessorPlayerMomentum ProcessorPlayerPosition ProcessorPlayerQuickKeys + ProcessorPlayerReputation ProcessorPlayerResurrect ProcessorPlayerShapeshift ProcessorPlayerSkill ProcessorPlayerSpeech ProcessorPlayerSpellbook ProcessorPlayerStatsDynamic ProcessorPlayerTopic + ProcessorPlayerPlaceholder ) add_openmw_dir (mwmp/processors/object BaseObjectProcessor @@ -134,8 +135,8 @@ add_openmw_dir (mwmp/processors/object BaseObjectProcessor ProcessorScriptGlobalFloat ) -add_openmw_dir (mwmp/processors/worldstate ProcessorCellCreate ProcessorCellReset ProcessorClientScriptSettings - ProcessorRecordDynamic ProcessorWorldCollisionOverride ProcessorWorldMap ProcessorWorldRegionAuthority ProcessorWorldTime +add_openmw_dir (mwmp/processors/worldstate ProcessorCellReset ProcessorClientScriptSettings ProcessorRecordDynamic + ProcessorWorldCollisionOverride ProcessorWorldKillCount ProcessorWorldMap ProcessorWorldRegionAuthority ProcessorWorldTime ProcessorWorldWeather ) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index f6d1c8cc7..8a4fa8e58 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -1860,7 +1860,7 @@ namespace MWMechanics std::string refId = Misc::StringUtils::lowerCase(actor.getCellRef().getRefId()); int number = mDeathCount[refId]; - mwmp::Main::get().getLocalPlayer()->sendKill(refId, number); + mwmp::Main::get().getNetworking()->getWorldstate()->sendKill(refId, number); } /* End of tes3mp addition diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 05fec23a8..96c9b0c6b 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -1314,27 +1314,6 @@ void LocalPlayer::setFactions() } } -void LocalPlayer::setKills() -{ - LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Received ID_WORLD_KILL_COUNT with the following kill counts:"); - std::string debugMessage = ""; - - for (const auto &kill : killChanges.kills) - { - if (TimedLog::GetLevel() <= TimedLog::LOG_INFO) - { - if (!debugMessage.empty()) - debugMessage += ", "; - - debugMessage += kill.refId + ": " + std::to_string(kill.number); - } - - MWBase::Environment::get().getMechanicsManager()->setDeaths(kill.refId, kill.number); - } - - LOG_APPEND(TimedLog::LOG_INFO, "- %s", debugMessage.c_str()); -} - void LocalPlayer::setBooks() { MWWorld::Ptr ptrPlayer = getPlayerPtr(); @@ -1620,22 +1599,6 @@ void LocalPlayer::sendTopic(const std::string& topicId) getNetworking()->getPlayerPacket(ID_PLAYER_TOPIC)->Send(); } -void LocalPlayer::sendKill(const std::string& refId, int number) -{ - killChanges.kills.clear(); - - mwmp::Kill kill; - kill.refId = refId; - kill.number = number; - - LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Sending ID_WORLD_KILL_COUNT with refId %s, number %i", refId.c_str(), number); - - killChanges.kills.push_back(kill); - - getNetworking()->getPlayerPacket(ID_WORLD_KILL_COUNT)->setPlayer(this); - getNetworking()->getPlayerPacket(ID_WORLD_KILL_COUNT)->Send(); -} - void LocalPlayer::sendBook(const std::string& bookId) { bookChanges.books.clear(); diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index 648ad474d..f06e524e2 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -70,7 +70,6 @@ namespace mwmp void setSpellbook(); void setQuickKeys(); void setFactions(); - void setKills(); void setBooks(); void setShapeshift(); void setMarkLocation(); @@ -90,7 +89,6 @@ namespace mwmp void sendFactionExpulsionState(const std::string& factionId, bool isExpelled); void sendFactionReputation(const std::string& factionId, int reputation); void sendTopic(const std::string& topic); - void sendKill(const std::string& refId, int number); void sendBook(const std::string& bookId); void sendWerewolfState(bool isWerewolf); void sendMarkLocation(const ESM::Cell& newMarkCell, const ESM::Position& newMarkPosition); diff --git a/apps/openmw/mwmp/Worldstate.cpp b/apps/openmw/mwmp/Worldstate.cpp index f0e724910..1f0a9db40 100644 --- a/apps/openmw/mwmp/Worldstate.cpp +++ b/apps/openmw/mwmp/Worldstate.cpp @@ -4,6 +4,8 @@ #include "../mwgui/windowmanagerimp.hpp" +#include "../mwmechanics/mechanicsmanagerimp.hpp" + #include "../mwworld/player.hpp" #include "../mwworld/worldimp.hpp" @@ -311,6 +313,27 @@ void Worldstate::markExploredMapTile(int cellX, int cellY) exploredMapTiles.push_back(exploredTile); } +void Worldstate::setKills() +{ + LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Received ID_WORLD_KILL_COUNT with the following kill counts:"); + std::string debugMessage = ""; + + for (const auto &killChange : killChanges) + { + if (TimedLog::GetLevel() <= TimedLog::LOG_INFO) + { + if (!debugMessage.empty()) + debugMessage += ", "; + + debugMessage += killChange.refId + ": " + std::to_string(killChange.number); + } + + MWBase::Environment::get().getMechanicsManager()->setDeaths(killChange.refId, killChange.number); + } + + LOG_APPEND(TimedLog::LOG_INFO, "- %s", debugMessage.c_str()); +} + void Worldstate::setMapExplored() { for (const auto &mapTile : mapTiles) @@ -345,6 +368,22 @@ void Worldstate::setWeather() weather.queuedWeather, weather.transitionFactor, forceWeather); } +void Worldstate::sendKill(const std::string& refId, int number) +{ + killChanges.clear(); + + mwmp::Kill killChange; + killChange.refId = refId; + killChange.number = number; + + LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Sending ID_WORLD_KILL_COUNT with refId %s, number %i", refId.c_str(), number); + + killChanges.push_back(killChange); + + getNetworking()->getWorldstatePacket(ID_WORLD_KILL_COUNT)->setWorldstate(this); + getNetworking()->getWorldstatePacket(ID_WORLD_KILL_COUNT)->Send(); +} + void Worldstate::sendMapExplored(int cellX, int cellY, const std::vector& imageData) { mapTiles.clear(); diff --git a/apps/openmw/mwmp/Worldstate.hpp b/apps/openmw/mwmp/Worldstate.hpp index cba28381a..b608943fe 100644 --- a/apps/openmw/mwmp/Worldstate.hpp +++ b/apps/openmw/mwmp/Worldstate.hpp @@ -18,9 +18,11 @@ namespace mwmp bool containsExploredMapTile(int cellX, int cellY); void markExploredMapTile(int cellX, int cellY); + void setKills(); void setMapExplored(); void setWeather(); + void sendKill(const std::string& refId, int number); void sendMapExplored(int cellX, int cellY, const std::vector& imageData); void sendWeather(std::string region, int currentWeather, int nextWeather, int queuedWeather, float transitionFactor); diff --git a/apps/openmw/mwmp/processors/ProcessorInitializer.cpp b/apps/openmw/mwmp/processors/ProcessorInitializer.cpp index cb60d77c0..ec04cb807 100644 --- a/apps/openmw/mwmp/processors/ProcessorInitializer.cpp +++ b/apps/openmw/mwmp/processors/ProcessorInitializer.cpp @@ -28,7 +28,7 @@ #include "player/ProcessorPlayerItemUse.hpp" #include "player/ProcessorPlayerJail.hpp" #include "player/ProcessorPlayerJournal.hpp" -#include "player/ProcessorWorldKillCount.hpp" +#include "player/ProcessorPlayerPlaceholder.hpp" #include "player/ProcessorPlayerLevel.hpp" #include "player/ProcessorPlayerMiscellaneous.hpp" #include "player/ProcessorPlayerMomentum.hpp" @@ -89,11 +89,11 @@ #include "actor/ProcessorActorTest.hpp" #include "WorldstateProcessor.hpp" -#include "worldstate/ProcessorCellCreate.hpp" #include "worldstate/ProcessorCellReset.hpp" #include "worldstate/ProcessorClientScriptSettings.hpp" #include "worldstate/ProcessorRecordDynamic.hpp" #include "worldstate/ProcessorWorldCollisionOverride.hpp" +#include "worldstate/ProcessorWorldKillCount.hpp" #include "worldstate/ProcessorWorldMap.hpp" #include "worldstate/ProcessorWorldRegionAuthority.hpp" #include "worldstate/ProcessorWorldTime.hpp" @@ -130,7 +130,7 @@ void ProcessorInitializer() PlayerProcessor::AddProcessor(new ProcessorPlayerItemUse()); PlayerProcessor::AddProcessor(new ProcessorPlayerJail()); PlayerProcessor::AddProcessor(new ProcessorPlayerJournal()); - PlayerProcessor::AddProcessor(new ProcessorWorldKillCount()); + PlayerProcessor::AddProcessor(new ProcessorPlayerPlaceholder()); PlayerProcessor::AddProcessor(new ProcessorPlayerLevel()); PlayerProcessor::AddProcessor(new ProcessorPlayerMiscellaneous()); PlayerProcessor::AddProcessor(new ProcessorPlayerMomentum()); @@ -188,7 +188,7 @@ void ProcessorInitializer() ActorProcessor::AddProcessor(new ProcessorActorStatsDynamic()); ActorProcessor::AddProcessor(new ProcessorActorTest()); - WorldstateProcessor::AddProcessor(new ProcessorCellCreate()); + WorldstateProcessor::AddProcessor(new ProcessorWorldKillCount()); WorldstateProcessor::AddProcessor(new ProcessorCellReset()); WorldstateProcessor::AddProcessor(new ProcessorClientScriptSettings()); WorldstateProcessor::AddProcessor(new ProcessorRecordDynamic()); diff --git a/apps/openmw/mwmp/processors/player/ProcessorWorldKillCount.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerPlaceholder.hpp similarity index 54% rename from apps/openmw/mwmp/processors/player/ProcessorWorldKillCount.hpp rename to apps/openmw/mwmp/processors/player/ProcessorPlayerPlaceholder.hpp index eb1782602..162abdde1 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorWorldKillCount.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerPlaceholder.hpp @@ -1,16 +1,16 @@ -#ifndef OPENMW_PROCESSORWORLDKILLCOUNT_HPP -#define OPENMW_PROCESSORWORLDKILLCOUNT_HPP +#ifndef OPENMW_PROCESSORPLACEHOLDER_HPP +#define OPENMW_PROCESSORPLACEHOLDER_HPP #include "../PlayerProcessor.hpp" namespace mwmp { - class ProcessorWorldKillCount : public PlayerProcessor + class ProcessorPlayerPlaceholder : public PlayerProcessor { public: - ProcessorWorldKillCount() + ProcessorPlayerPlaceholder() { - BPP_INIT(ID_WORLD_KILL_COUNT) + BPP_INIT(ID_PLACEHOLDER) } virtual void Do(PlayerPacket &packet, BasePlayer *player) @@ -21,10 +21,10 @@ namespace mwmp } else if (player != 0) { - static_cast(player)->setKills(); + // Placeholder } } }; } -#endif //OPENMW_PROCESSORWORLDKILLCOUNT_HPP +#endif //OPENMW_PROCESSORPLACEHOLDER_HPP diff --git a/apps/openmw/mwmp/processors/worldstate/ProcessorCellCreate.hpp b/apps/openmw/mwmp/processors/worldstate/ProcessorCellCreate.hpp deleted file mode 100644 index 993eaf48a..000000000 --- a/apps/openmw/mwmp/processors/worldstate/ProcessorCellCreate.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef OPENMW_PROCESSORCELLCREATE_HPP -#define OPENMW_PROCESSORCELLCREATE_HPP - -#include "../WorldstateProcessor.hpp" - -namespace mwmp -{ - class ProcessorCellCreate : public WorldstateProcessor - { - public: - ProcessorCellCreate() - { - BPP_INIT(ID_PLACEHOLDER) - } - - virtual void Do(WorldstatePacket &packet, Worldstate &worldstate) - { - // Placeholder - } - }; -} - -#endif //OPENMW_PROCESSORCELLCREATE_HPP diff --git a/apps/openmw/mwmp/processors/worldstate/ProcessorWorldKillCount.hpp b/apps/openmw/mwmp/processors/worldstate/ProcessorWorldKillCount.hpp new file mode 100644 index 000000000..fc2e1de17 --- /dev/null +++ b/apps/openmw/mwmp/processors/worldstate/ProcessorWorldKillCount.hpp @@ -0,0 +1,23 @@ +#ifndef OPENMW_PROCESSORWORLDKILLCOUNT_HPP +#define OPENMW_PROCESSORWORLDKILLCOUNT_HPP + +#include "../WorldstateProcessor.hpp" + +namespace mwmp +{ + class ProcessorWorldKillCount : public WorldstateProcessor + { + public: + ProcessorWorldKillCount() + { + BPP_INIT(ID_WORLD_KILL_COUNT) + } + + virtual void Do(WorldstatePacket &packet, Worldstate &worldstate) + { + mwmp::Main::get().getNetworking()->getWorldstate()->setKills(); + } + }; +} + +#endif //OPENMW_PROCESSORWORLDKILLCOUNT_HPP diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 0481b9439..61f0441a4 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -187,10 +187,12 @@ add_component_dir (openmw-mp/Packets/Player PacketPlayerAttack PacketPlayerAttribute PacketPlayerBehavior PacketPlayerBook PacketPlayerBounty PacketPlayerCast PacketPlayerCellChange PacketPlayerCellState PacketPlayerClass PacketPlayerDeath PacketPlayerEquipment PacketPlayerFaction PacketPlayerInput PacketPlayerInventory PacketPlayerItemUse - PacketPlayerJail PacketPlayerJournal PacketWorldKillCount PacketPlayerLevel PacketPlayerMiscellaneous - PacketPlayerMomentum PacketPlayerPosition PacketPlayerQuickKeys PacketPlayerReputation PacketPlayerRest - PacketPlayerResurrect PacketPlayerShapeshift PacketPlayerSkill PacketPlayerSpeech PacketPlayerSpellbook - PacketPlayerStatsDynamic PacketPlayerTopic + PacketPlayerJail PacketPlayerJournal PacketPlayerLevel PacketPlayerMiscellaneous PacketPlayerMomentum + PacketPlayerPosition PacketPlayerQuickKeys PacketPlayerReputation PacketPlayerRest PacketPlayerResurrect + PacketPlayerShapeshift PacketPlayerSkill PacketPlayerSpeech PacketPlayerSpellbook PacketPlayerStatsDynamic + PacketPlayerTopic + + PacketPlayerPlaceholder ) add_component_dir (openmw-mp/Packets/Object @@ -209,7 +211,7 @@ add_component_dir (openmw-mp/Packets/Worldstate WorldstatePacket PacketCellCreate PacketCellReset PacketClientScriptSettings PacketRecordDynamic PacketWorldCollisionOverride - PacketWorldMap PacketWorldRegionAuthority PacketWorldTime PacketWorldWeather + PacketWorldKillCount PacketWorldMap PacketWorldRegionAuthority PacketWorldTime PacketWorldWeather ) add_component_dir (fallback diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index d66ae27f8..83b4f73f2 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -54,12 +54,6 @@ namespace mwmp std::string topicId; }; - struct Kill - { - std::string refId; - int number; - }; - struct Book { std::string bookId; @@ -121,12 +115,6 @@ namespace mwmp unsigned int count; }; - struct KillChanges - { - std::vector kills; - unsigned int count; - }; - struct BookChanges { std::vector books; @@ -260,7 +248,6 @@ namespace mwmp JournalChanges journalChanges; FactionChanges factionChanges; TopicChanges topicChanges; - KillChanges killChanges; BookChanges bookChanges; CellStateChanges cellStateChanges; diff --git a/components/openmw-mp/Base/BaseWorldstate.hpp b/components/openmw-mp/Base/BaseWorldstate.hpp index 5f8c11351..5301ec1fa 100644 --- a/components/openmw-mp/Base/BaseWorldstate.hpp +++ b/components/openmw-mp/Base/BaseWorldstate.hpp @@ -297,6 +297,12 @@ namespace mwmp float transitionFactor; }; + struct Kill + { + std::string refId; + int number; + }; + class BaseWorldstate { public: @@ -325,6 +331,7 @@ namespace mwmp std::string authorityRegion; + std::vector killChanges; std::vector enforcedCollisionRefIds; std::vector mapTiles; diff --git a/components/openmw-mp/Controllers/PlayerPacketController.cpp b/components/openmw-mp/Controllers/PlayerPacketController.cpp index 9b560fa97..a289d21d6 100644 --- a/components/openmw-mp/Controllers/PlayerPacketController.cpp +++ b/components/openmw-mp/Controllers/PlayerPacketController.cpp @@ -26,7 +26,7 @@ #include "../Packets/Player/PacketPlayerItemUse.hpp" #include "../Packets/Player/PacketPlayerJail.hpp" #include "../Packets/Player/PacketPlayerJournal.hpp" -#include "../Packets/Player/PacketWorldKillCount.hpp" +#include "../Packets/Player/PacketPlayerPlaceholder.hpp" #include "../Packets/Player/PacketPlayerLevel.hpp" #include "../Packets/Player/PacketPlayerMiscellaneous.hpp" #include "../Packets/Player/PacketPlayerMomentum.hpp" @@ -83,7 +83,7 @@ mwmp::PlayerPacketController::PlayerPacketController(RakNet::RakPeerInterface *p AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); - AddPacket(&packets, peer); + AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); diff --git a/components/openmw-mp/Controllers/WorldstatePacketController.cpp b/components/openmw-mp/Controllers/WorldstatePacketController.cpp index 6794448d7..bcfce8e1b 100644 --- a/components/openmw-mp/Controllers/WorldstatePacketController.cpp +++ b/components/openmw-mp/Controllers/WorldstatePacketController.cpp @@ -1,8 +1,8 @@ -#include "../Packets/Worldstate/PacketCellCreate.hpp" #include "../Packets/Worldstate/PacketCellReset.hpp" #include "../Packets/Worldstate/PacketClientScriptSettings.hpp" #include "../Packets/Worldstate/PacketRecordDynamic.hpp" #include "../Packets/Worldstate/PacketWorldCollisionOverride.hpp" +#include "../Packets/Worldstate/PacketWorldKillCount.hpp" #include "../Packets/Worldstate/PacketWorldMap.hpp" #include "../Packets/Worldstate/PacketWorldRegionAuthority.hpp" #include "../Packets/Worldstate/PacketWorldTime.hpp" @@ -20,11 +20,11 @@ inline void AddPacket(mwmp::WorldstatePacketController::packets_t *packets, RakN mwmp::WorldstatePacketController::WorldstatePacketController(RakNet::RakPeerInterface *peer) { - AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); + AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); diff --git a/components/openmw-mp/Packets/Player/PacketPlayerPlaceholder.cpp b/components/openmw-mp/Packets/Player/PacketPlayerPlaceholder.cpp new file mode 100644 index 000000000..7d9785122 --- /dev/null +++ b/components/openmw-mp/Packets/Player/PacketPlayerPlaceholder.cpp @@ -0,0 +1,12 @@ +#include +#include "PacketPlayerPlaceholder.hpp" + +mwmp::PacketPlayerPlaceholder::PacketPlayerPlaceholder(RakNet::RakPeerInterface *peer) : PlayerPacket(peer) +{ + packetID = ID_PLACEHOLDER; +} + +void mwmp::PacketPlayerPlaceholder::Packet(RakNet::BitStream *bs, bool send) +{ + // Placeholder +} diff --git a/components/openmw-mp/Packets/Player/PacketPlayerPlaceholder.hpp b/components/openmw-mp/Packets/Player/PacketPlayerPlaceholder.hpp new file mode 100644 index 000000000..bffb844d1 --- /dev/null +++ b/components/openmw-mp/Packets/Player/PacketPlayerPlaceholder.hpp @@ -0,0 +1,17 @@ +#ifndef OPENMW_PACKETPLACEHOLDER_HPP +#define OPENMW_PACKETPLACEHOLDER_HPP + +#include + +namespace mwmp +{ + class PacketPlayerPlaceholder : public PlayerPacket + { + public: + PacketPlayerPlaceholder(RakNet::RakPeerInterface *peer); + + virtual void Packet(RakNet::BitStream *bs, bool send); + }; +} + +#endif //OPENMW_PACKETPLACEHOLDER_HPP diff --git a/components/openmw-mp/Packets/Player/PacketWorldKillCount.cpp b/components/openmw-mp/Packets/Player/PacketWorldKillCount.cpp deleted file mode 100644 index 2cc77bab2..000000000 --- a/components/openmw-mp/Packets/Player/PacketWorldKillCount.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include "PacketWorldKillCount.hpp" - -mwmp::PacketWorldKillCount::PacketWorldKillCount(RakNet::RakPeerInterface *peer) : PlayerPacket(peer) -{ - packetID = ID_WORLD_KILL_COUNT; -} - -void mwmp::PacketWorldKillCount::Packet(RakNet::BitStream *bs, bool send) -{ - PlayerPacket::Packet(bs, send); - - if (send) - player->killChanges.count = (unsigned int)(player->killChanges.kills.size()); - else - player->killChanges.kills.clear(); - - RW(player->killChanges.count, send); - - for (unsigned int i = 0; i < player->killChanges.count; i++) - { - Kill kill; - - if (send) - kill = player->killChanges.kills.at(i); - - RW(kill.refId, send, true); - RW(kill.number, send); - - if (!send) - player->killChanges.kills.push_back(kill); - } -} diff --git a/components/openmw-mp/Packets/Worldstate/PacketCellCreate.cpp b/components/openmw-mp/Packets/Worldstate/PacketCellCreate.cpp deleted file mode 100644 index 31d650a00..000000000 --- a/components/openmw-mp/Packets/Worldstate/PacketCellCreate.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "PacketCellCreate.hpp" -#include - -using namespace mwmp; - -PacketCellCreate::PacketCellCreate(RakNet::RakPeerInterface *peer) : WorldstatePacket(peer) -{ - packetID = ID_PLACEHOLDER; - orderChannel = CHANNEL_SYSTEM; -} - -void PacketCellCreate::Packet(RakNet::BitStream *bs, bool send) -{ - WorldstatePacket::Packet(bs, send); - - // Placeholder -} diff --git a/components/openmw-mp/Packets/Worldstate/PacketCellCreate.hpp b/components/openmw-mp/Packets/Worldstate/PacketCellCreate.hpp deleted file mode 100644 index ebd5f7bfd..000000000 --- a/components/openmw-mp/Packets/Worldstate/PacketCellCreate.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef OPENMW_PACKETCELLCREATE_HPP -#define OPENMW_PACKETCELLCREATE_HPP - -#include -#include - -namespace mwmp -{ - class PacketCellCreate: public WorldstatePacket - { - public: - PacketCellCreate(RakNet::RakPeerInterface *peer); - - virtual void Packet(RakNet::BitStream *bs, bool send); - }; -} - -#endif //OPENMW_PACKETCELLCREATE_HPP diff --git a/components/openmw-mp/Packets/Worldstate/PacketWorldKillCount.cpp b/components/openmw-mp/Packets/Worldstate/PacketWorldKillCount.cpp new file mode 100644 index 000000000..0c158ecba --- /dev/null +++ b/components/openmw-mp/Packets/Worldstate/PacketWorldKillCount.cpp @@ -0,0 +1,34 @@ +#include "PacketWorldKillCount.hpp" +#include + +using namespace mwmp; + +PacketWorldKillCount::PacketWorldKillCount(RakNet::RakPeerInterface *peer) : WorldstatePacket(peer) +{ + packetID = ID_WORLD_KILL_COUNT; + orderChannel = CHANNEL_SYSTEM; +} + +void PacketWorldKillCount::Packet(RakNet::BitStream *bs, bool send) +{ + WorldstatePacket::Packet(bs, send); + + uint32_t killChangesCount; + + if (send) + killChangesCount = static_cast(worldstate->killChanges.size()); + + RW(killChangesCount, send); + + if (!send) + { + worldstate->killChanges.clear(); + worldstate->killChanges.resize(killChangesCount); + } + + for (auto &&killChange : worldstate->killChanges) + { + RW(killChange.refId, send, true); + RW(killChange.number, send); + } +} diff --git a/components/openmw-mp/Packets/Player/PacketWorldKillCount.hpp b/components/openmw-mp/Packets/Worldstate/PacketWorldKillCount.hpp similarity index 62% rename from components/openmw-mp/Packets/Player/PacketWorldKillCount.hpp rename to components/openmw-mp/Packets/Worldstate/PacketWorldKillCount.hpp index b55a617b9..921470238 100644 --- a/components/openmw-mp/Packets/Player/PacketWorldKillCount.hpp +++ b/components/openmw-mp/Packets/Worldstate/PacketWorldKillCount.hpp @@ -1,11 +1,12 @@ #ifndef OPENMW_PACKETWORLDKILLCOUNT_HPP #define OPENMW_PACKETWORLDKILLCOUNT_HPP -#include +#include +#include namespace mwmp { - class PacketWorldKillCount : public PlayerPacket + class PacketWorldKillCount: public WorldstatePacket { public: PacketWorldKillCount(RakNet::RakPeerInterface *peer);