From fcc793a0af52b67cb0d7e63bf2293cbb4385a5b2 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 17 Oct 2016 18:47:16 +0300 Subject: [PATCH 01/34] Create a new BasePacket that PlayerPacket inherits from --- components/CMakeLists.txt | 4 +- components/openmw-mp/Packets/BasePacket.cpp | 37 ++++++++ components/openmw-mp/Packets/BasePacket.hpp | 93 +++++++++++++++++++ components/openmw-mp/Packets/PlayerPacket.cpp | 20 +--- components/openmw-mp/Packets/PlayerPacket.hpp | 65 +------------ components/openmw-mp/PacketsController.cpp | 2 +- 6 files changed, 137 insertions(+), 84 deletions(-) create mode 100644 components/openmw-mp/Packets/BasePacket.cpp create mode 100644 components/openmw-mp/Packets/BasePacket.hpp diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index a5574e106..d0212861a 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -148,8 +148,8 @@ add_component_dir (version add_component_dir (openmw-mp Log PacketsController - Packets/PlayerPacket Packets/PacketBaseInfo Packets/PacketPosition Packets/PacketEquipment Packets/PacketAttack - Packets/PacketDynamicStats Packets/PacketCell Packets/PacketDrawState Packets/PacketChatMessage + Packets/BasePacket Packets/PlayerPacket Packets/PacketBaseInfo Packets/PacketPosition Packets/PacketEquipment + Packets/PacketAttack Packets/PacketDynamicStats Packets/PacketCell Packets/PacketDrawState Packets/PacketChatMessage Packets/PacketCharGen Packets/PacketAttribute Packets/PacketSkill Packets/PacketLevel Packets/PacketHandshake Packets/PacketGUIBoxes Packets/PacketClass Packets/PacketTime) diff --git a/components/openmw-mp/Packets/BasePacket.cpp b/components/openmw-mp/Packets/BasePacket.cpp new file mode 100644 index 000000000..408b95c7e --- /dev/null +++ b/components/openmw-mp/Packets/BasePacket.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include "BasePacket.hpp" + +using namespace mwmp; + +BasePacket::BasePacket(RakNet::RakPeerInterface *peer) +{ + packetID = 0; + priority = HIGH_PRIORITY; + reliability = RELIABLE_ORDERED; + this->peer = peer; +} + +BasePacket::~BasePacket() +{ + +} + +void BasePacket::SetReadStream(RakNet::BitStream *bitStream) +{ + bsRead = bitStream; +} + +void BasePacket::SetSendStream(RakNet::BitStream *bitStream) +{ + bsSend = bitStream; +} + +void BasePacket::SetStreams(RakNet::BitStream *inStream, RakNet::BitStream *outStream) +{ + if (inStream != 0) + bsRead = inStream; + if (outStream != 0) + bsSend = outStream; +} \ No newline at end of file diff --git a/components/openmw-mp/Packets/BasePacket.hpp b/components/openmw-mp/Packets/BasePacket.hpp new file mode 100644 index 000000000..88b963734 --- /dev/null +++ b/components/openmw-mp/Packets/BasePacket.hpp @@ -0,0 +1,93 @@ +#ifndef OPENMW_BASEPACKET_HPP +#define OPENMW_BASEPACKET_HPP + +#include +#include +#include +#include +#include + + +namespace mwmp +{ + class BasePacket + { + public: + BasePacket(RakNet::RakPeerInterface *peer); + + ~BasePacket(); + + void SetReadStream(RakNet::BitStream *bitStream); + void SetSendStream(RakNet::BitStream *bitStream); + void SetStreams(RakNet::BitStream *inStream, RakNet::BitStream *outStream); + + static size_t headerSize() + { + return (size_t)(1 + RakNet::RakNetGUID::size()); // packetID + RakNetGUID (uint64_t) + } + + unsigned char GetPacketID() + { + return packetID; + } + + protected: + template + void RW(templateType &data, unsigned int size, bool write) + { + if (write) + bs->Write(data, size); + else + bs->Read(data, size); + } + + template + void RW(templateType &data, bool write) + { + if (write) + bs->Write(data); + else + bs->Read(data); + } + + void RW(bool &data, bool write) + { + char _data; + if (write) + { + _data = data; + bs->Write(_data); + } + else + { + bs->Read(_data); + data = _data; + } + } + + + void RW(std::string &str, bool write) + { + if (write) + { + RakNet::RakString rstr(str.c_str()); + bs->Write(rstr); + } + else + { + RakNet::RakString rstr; + bs->Read(rstr); + str = rstr.C_String(); + } + } + + protected: + unsigned char packetID; + PacketReliability reliability; + PacketPriority priority; + RakNet::BitStream *bsRead, *bsSend, *bs; + RakNet::RakPeerInterface *peer; + }; +} + +#endif //OPENMW_BASEPACKET_HPP diff --git a/components/openmw-mp/Packets/PlayerPacket.cpp b/components/openmw-mp/Packets/PlayerPacket.cpp index 08ef332af..823be9ab7 100644 --- a/components/openmw-mp/Packets/PlayerPacket.cpp +++ b/components/openmw-mp/Packets/PlayerPacket.cpp @@ -17,7 +17,7 @@ void PlayerPacket::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send) } } -PlayerPacket::PlayerPacket(RakNet::RakPeerInterface *peer) +PlayerPacket::PlayerPacket(RakNet::RakPeerInterface *peer) : BasePacket(peer) { packetID = 0; priority = HIGH_PRIORITY; @@ -49,16 +49,6 @@ void PlayerPacket::Read(BasePlayer *player) Packet(bsRead, player, false); } -void PlayerPacket::SetReadStream(RakNet::BitStream *bitStream) -{ - bsRead = bitStream; -} - -void PlayerPacket::SetSendStream(RakNet::BitStream *bitStream) -{ - bsSend = bitStream; -} - void PlayerPacket::RequestData(RakNet::RakNetGUID player) { bsSend->ResetWritePointer(); @@ -66,11 +56,3 @@ void PlayerPacket::RequestData(RakNet::RakNetGUID player) bsSend->Write(player); peer->Send(bsSend, HIGH_PRIORITY, RELIABLE_ORDERED, 0, player, false); } - -void PlayerPacket::SetStreams(RakNet::BitStream *inStream, RakNet::BitStream *outStream) -{ - if (inStream != 0) - bsRead = inStream; - if (outStream != 0) - bsSend = outStream; -} \ No newline at end of file diff --git a/components/openmw-mp/Packets/PlayerPacket.hpp b/components/openmw-mp/Packets/PlayerPacket.hpp index fe45f1e23..9281baf87 100644 --- a/components/openmw-mp/Packets/PlayerPacket.hpp +++ b/components/openmw-mp/Packets/PlayerPacket.hpp @@ -7,10 +7,12 @@ #include #include +#include "BasePacket.hpp" + namespace mwmp { - class PlayerPacket + class PlayerPacket : public BasePacket { public: PlayerPacket(RakNet::RakPeerInterface *peer); @@ -25,10 +27,6 @@ namespace mwmp virtual void RequestData(RakNet::RakNetGUID player); - void SetReadStream(RakNet::BitStream *bitStream); - void SetSendStream(RakNet::BitStream *bitStream); - void SetStreams(RakNet::BitStream *inStream, RakNet::BitStream *outStream); - static size_t headerSize() { return (size_t)(1 + RakNet::RakNetGUID::size()); // packetID + RakNetGUID (uint64_t) @@ -39,65 +37,8 @@ namespace mwmp return packetID; } - protected: - template - void RW(templateType &data, unsigned int size, bool write) - { - if (write) - bs->Write(data, size); - else - bs->Read(data, size); - } - - template - void RW(templateType &data, bool write) - { - if (write) - bs->Write(data); - else - bs->Read(data); - } - - void RW(bool &data, bool write) - { - char _data; - if (write) - { - _data = data; - bs->Write(_data); - } - else - { - bs->Read(_data); - data = _data; - } - } - - - void RW(std::string &str, bool write) - { - if (write) - { - RakNet::RakString rstr(str.c_str()); - bs->Write(rstr); - } - else - { - RakNet::RakString rstr; - bs->Read(rstr); - str = rstr.C_String(); - } - } - protected: BasePlayer *player; - unsigned char packetID; - PacketReliability reliability; - PacketPriority priority; - - private: - RakNet::BitStream *bsRead, *bsSend, *bs; - RakNet::RakPeerInterface *peer; }; } diff --git a/components/openmw-mp/PacketsController.cpp b/components/openmw-mp/PacketsController.cpp index e27f33c4d..19f82f938 100644 --- a/components/openmw-mp/PacketsController.cpp +++ b/components/openmw-mp/PacketsController.cpp @@ -9,7 +9,7 @@ #include "Packets/PacketClass.hpp" #include "Packets/PacketPosition.hpp" #include "Packets/PacketBaseInfo.hpp" -#include "components/openmw-mp/Packets/PacketEquipment.hpp" +#include "Packets/PacketEquipment.hpp" #include "Packets/PacketAttack.hpp" #include "Packets/PacketDynamicStats.hpp" #include "Packets/PacketResurrect.hpp" From 5e0c0dd5f1ba1c6ad1b431816675abf3b725d7aa Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 19 Oct 2016 13:00:33 +0300 Subject: [PATCH 02/34] Use logger in server's Networking MainLoop --- apps/openmw-mp/Networking.cpp | 24 +++++++++++-------- components/openmw-mp/Packets/PlayerPacket.cpp | 4 ++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index ed5506820..67c63865f 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -47,7 +47,6 @@ Networking::~Networking() void Networking::Update(RakNet::Packet *packet) { - Player *player = Players::GetPlayer(packet->guid); RakNet::BitStream bsIn(&packet->data[1], packet->length, false); @@ -73,7 +72,6 @@ void Networking::Update(RakNet::Packet *packet) if (packet->data[0] == ID_HANDSHAKE) { - DEBUG_PRINTF("ID_HANDSHAKE\n"); string passw = "SuperPassword"; myPacket->Read(player); @@ -448,31 +446,37 @@ int Networking::MainLoop() switch (packet->data[0]) { case ID_REMOTE_DISCONNECTION_NOTIFICATION: - printf("Another client has disconnected.\n"); + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Client at %s has disconnected", + packet->systemAddress.ToString()); break; case ID_REMOTE_CONNECTION_LOST: - printf("Another client has lost connection.\n"); + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Client at %s has lost connection", + packet->systemAddress.ToString()); break; case ID_REMOTE_NEW_INCOMING_CONNECTION: - printf("Another client has connected.\n"); + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Client at %s has connected", + packet->systemAddress.ToString()); break; case ID_CONNECTION_REQUEST_ACCEPTED: // client to server { - printf("Our connection request has been accepted.\n"); + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Our connection request has been accepted"); break; } case ID_NEW_INCOMING_CONNECTION: - printf("A connection is incoming.\n"); + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "A connection is incoming from %s", + packet->systemAddress.ToString()); break; case ID_NO_FREE_INCOMING_CONNECTIONS: - printf("The server is full.\n"); + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "The server is full"); break; case ID_DISCONNECTION_NOTIFICATION: - printf("A client has disconnected.\n"); + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Client at %s has disconnected", + packet->systemAddress.ToString()); DisconnectPlayer(packet->guid); break; case ID_CONNECTION_LOST: - printf("A client has lost connection.\n"); + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Client at %s has lost connection", + packet->systemAddress.ToString()); DisconnectPlayer(packet->guid); break; default: diff --git a/components/openmw-mp/Packets/PlayerPacket.cpp b/components/openmw-mp/Packets/PlayerPacket.cpp index 823be9ab7..bebac49b6 100644 --- a/components/openmw-mp/Packets/PlayerPacket.cpp +++ b/components/openmw-mp/Packets/PlayerPacket.cpp @@ -49,10 +49,10 @@ void PlayerPacket::Read(BasePlayer *player) Packet(bsRead, player, false); } -void PlayerPacket::RequestData(RakNet::RakNetGUID player) +void PlayerPacket::RequestData(RakNet::RakNetGUID guid) { bsSend->ResetWritePointer(); bsSend->Write(packetID); bsSend->Write(player); - peer->Send(bsSend, HIGH_PRIORITY, RELIABLE_ORDERED, 0, player, false); + peer->Send(bsSend, HIGH_PRIORITY, RELIABLE_ORDERED, 0, guid, false); } From d2212ef80b9dbe645831b187c4ec56d469b03490 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 19 Oct 2016 16:31:07 +0300 Subject: [PATCH 03/34] Rename PacketsController into PlayerPacketController --- apps/openmw-mp/Networking.cpp | 4 +- apps/openmw-mp/Networking.hpp | 6 +- apps/openmw/mwmp/Networking.hpp | 4 +- components/CMakeLists.txt | 2 +- .../PlayerPacketController.cpp} | 58 +++++++++---------- .../PlayerPacketController.hpp} | 16 ++--- 6 files changed, 41 insertions(+), 49 deletions(-) rename components/openmw-mp/{PacketsController.cpp => Controllers/PlayerPacketController.cpp} (50%) rename components/openmw-mp/{PacketsController.hpp => Controllers/PlayerPacketController.hpp} (58%) diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index 67c63865f..4c6e9055a 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -26,7 +26,7 @@ Networking::Networking(RakNet::RakPeerInterface *peer) this->peer = peer; players = Players::GetPlayers(); - controller = new PacketsController(peer); + controller = new PlayerPacketController(peer); controller->SetStream(0, &bsOut); // set send stream @@ -411,7 +411,7 @@ void Networking::DisconnectPlayer(RakNet::RakNetGUID guid) Players::DeletePlayer(guid); } -PacketsController *Networking::GetController() const +PlayerPacketController *Networking::GetController() const { return controller; } diff --git a/apps/openmw-mp/Networking.hpp b/apps/openmw-mp/Networking.hpp index 04399d69a..a19376485 100644 --- a/apps/openmw-mp/Networking.hpp +++ b/apps/openmw-mp/Networking.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_NETWORKING_HPP #define OPENMW_NETWORKING_HPP -#include +#include #include "Player.hpp" namespace mwmp @@ -27,7 +27,7 @@ namespace mwmp void StopServer(int code); - PacketsController *GetController() const; + PlayerPacketController *GetController() const; static const Networking &Get(); static Networking *GetPtr(); @@ -37,7 +37,7 @@ namespace mwmp RakNet::BitStream bsOut; TPlayers *players; - PacketsController *controller; + PlayerPacketController *controller; bool running; int exitCode; diff --git a/apps/openmw/mwmp/Networking.hpp b/apps/openmw/mwmp/Networking.hpp index 430a6d849..bc2dd9c4c 100644 --- a/apps/openmw/mwmp/Networking.hpp +++ b/apps/openmw/mwmp/Networking.hpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include namespace mwmp { @@ -51,7 +51,7 @@ namespace mwmp RakNet::SystemAddress serverAddr; RakNet::BitStream bsOut; - PacketsController controller; + PlayerPacketController controller; void ReceiveMessage(RakNet::Packet *packet); LocalPlayer *getLocalPlayer(); diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index d0212861a..61fc1fda7 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -147,7 +147,7 @@ add_component_dir (version add_component_dir (openmw-mp Log - PacketsController + Controllers/PlayerPacketController Packets/BasePacket Packets/PlayerPacket Packets/PacketBaseInfo Packets/PacketPosition Packets/PacketEquipment Packets/PacketAttack Packets/PacketDynamicStats Packets/PacketCell Packets/PacketDrawState Packets/PacketChatMessage Packets/PacketCharGen Packets/PacketAttribute Packets/PacketSkill Packets/PacketLevel Packets/PacketHandshake diff --git a/components/openmw-mp/PacketsController.cpp b/components/openmw-mp/Controllers/PlayerPacketController.cpp similarity index 50% rename from components/openmw-mp/PacketsController.cpp rename to components/openmw-mp/Controllers/PlayerPacketController.cpp index 19f82f938..1e283fe65 100644 --- a/components/openmw-mp/PacketsController.cpp +++ b/components/openmw-mp/Controllers/PlayerPacketController.cpp @@ -1,44 +1,40 @@ -// -// Created by koncord on 15.01.16. -// - #include #include #include -#include "Packets/PacketClass.hpp" -#include "Packets/PacketPosition.hpp" -#include "Packets/PacketBaseInfo.hpp" -#include "Packets/PacketEquipment.hpp" -#include "Packets/PacketAttack.hpp" -#include "Packets/PacketDynamicStats.hpp" -#include "Packets/PacketResurrect.hpp" -#include "Packets/PacketDie.hpp" -#include "Packets/PacketCell.hpp" -#include "Packets/PacketSendMyID.hpp" -#include "Packets/PacketDisconnect.hpp" -#include "Packets/PacketDrawState.hpp" -#include "Packets/PacketChatMessage.hpp" -#include "Packets/PacketCharGen.hpp" -#include "Packets/PacketAttribute.hpp" -#include "Packets/PacketSkill.hpp" -#include "Packets/PacketLevel.hpp" -#include "Packets/PacketHandshake.hpp" -#include "Packets/PacketGUIBoxes.hpp" -#include "Packets/PacketTime.hpp" -#include "Packets/PacketLoaded.hpp" +#include "../Packets/PacketClass.hpp" +#include "../Packets/PacketPosition.hpp" +#include "../Packets/PacketBaseInfo.hpp" +#include "../Packets/PacketEquipment.hpp" +#include "../Packets/PacketAttack.hpp" +#include "../Packets/PacketDynamicStats.hpp" +#include "../Packets/PacketResurrect.hpp" +#include "../Packets/PacketDie.hpp" +#include "../Packets/PacketCell.hpp" +#include "../Packets/PacketSendMyID.hpp" +#include "../Packets/PacketDisconnect.hpp" +#include "../Packets/PacketDrawState.hpp" +#include "../Packets/PacketChatMessage.hpp" +#include "../Packets/PacketCharGen.hpp" +#include "../Packets/PacketAttribute.hpp" +#include "../Packets/PacketSkill.hpp" +#include "../Packets/PacketLevel.hpp" +#include "../Packets/PacketHandshake.hpp" +#include "../Packets/PacketGUIBoxes.hpp" +#include "../Packets/PacketTime.hpp" +#include "../Packets/PacketLoaded.hpp" -#include "PacketsController.hpp" +#include "PlayerPacketController.hpp" template -inline void AddPacket(mwmp::PacketsController::packets_t *packets, RakNet::RakPeerInterface *peer) +inline void AddPacket(mwmp::PlayerPacketController::packets_t *packets, RakNet::RakPeerInterface *peer) { T *packet = new T(peer); - typedef mwmp::PacketsController::packets_t::value_type value_t; + typedef mwmp::PlayerPacketController::packets_t::value_type value_t; packets->insert(value_t(packet->GetPacketID(), value_t::second_type(packet))); } -mwmp::PacketsController::PacketsController(RakNet::RakPeerInterface *peer) +mwmp::PlayerPacketController::PlayerPacketController(RakNet::RakPeerInterface *peer) { AddPacket(&packets, peer); AddPacket(&packets, peer); @@ -68,12 +64,12 @@ mwmp::PacketsController::PacketsController(RakNet::RakPeerInterface *peer) } -mwmp::PlayerPacket *mwmp::PacketsController::GetPacket(RakNet::MessageID id) +mwmp::PlayerPacket *mwmp::PlayerPacketController::GetPacket(RakNet::MessageID id) { return packets[(unsigned char)id].get(); } -void mwmp::PacketsController::SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream) +void mwmp::PlayerPacketController::SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream) { BOOST_FOREACH( packets_t::value_type &packet, packets ) packet.second->SetStreams(inStream, outStream); diff --git a/components/openmw-mp/PacketsController.hpp b/components/openmw-mp/Controllers/PlayerPacketController.hpp similarity index 58% rename from components/openmw-mp/PacketsController.hpp rename to components/openmw-mp/Controllers/PlayerPacketController.hpp index f112743cf..efb104a07 100644 --- a/components/openmw-mp/PacketsController.hpp +++ b/components/openmw-mp/Controllers/PlayerPacketController.hpp @@ -1,22 +1,18 @@ -// -// Created by koncord on 15.01.16. -// - -#ifndef OPENMW_PACKETSCONTROLLER_HPP -#define OPENMW_PACKETSCONTROLLER_HPP +#ifndef OPENMW_PLAYERPACKETCONTROLLER_HPP +#define OPENMW_PLAYERPACKETCONTROLLER_HPP #include -#include "Packets/PlayerPacket.hpp" +#include "../Packets/PlayerPacket.hpp" #include #include namespace mwmp { - class PacketsController + class PlayerPacketController { public: - PacketsController(RakNet::RakPeerInterface *peer); + PlayerPacketController(RakNet::RakPeerInterface *peer); PlayerPacket *GetPacket(RakNet::MessageID id); void SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream); @@ -26,4 +22,4 @@ namespace mwmp }; } -#endif //OPENMW_PACKETSCONTROLLER_HPP +#endif //OPENMW_PLAYERPACKETCONTROLLER_HPP From bda1f867fd3212962085b0113a0b0b1b14f43bc5 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 19 Oct 2016 16:54:39 +0300 Subject: [PATCH 04/34] Rename server's GetController() method into GetPlayerController() --- apps/openmw-mp/Networking.cpp | 52 +++++++++---------- apps/openmw-mp/Networking.hpp | 4 +- apps/openmw-mp/Script/Functions/CharClass.cpp | 2 +- apps/openmw-mp/Script/Functions/Chat.cpp | 4 +- apps/openmw-mp/Script/Functions/GUI.cpp | 6 +-- apps/openmw-mp/Script/Functions/Items.cpp | 4 +- apps/openmw-mp/Script/Functions/Stats.cpp | 24 ++++----- .../Script/Functions/Translocations.cpp | 8 +-- apps/openmw-mp/Script/Functions/World.cpp | 6 +-- 9 files changed, 55 insertions(+), 55 deletions(-) diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index 4c6e9055a..3ea2395e5 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -26,9 +26,9 @@ Networking::Networking(RakNet::RakPeerInterface *peer) this->peer = peer; players = Players::GetPlayers(); - controller = new PlayerPacketController(peer); + playerController = new PlayerPacketController(peer); - controller->SetStream(0, &bsOut); // set send stream + playerController->SetStream(0, &bsOut); // set send stream running = true; exitCode = 0; @@ -41,7 +41,7 @@ Networking::~Networking() Script::Call(false); sThis = 0; - delete controller; + delete playerController; LOG_QUIT(); } @@ -57,18 +57,18 @@ void Networking::Update(RakNet::Packet *packet) (void)ignoredGUID; } - controller->SetStream(&bsIn, 0); + playerController->SetStream(&bsIn, 0); if (player == 0) { - controller->GetPacket(ID_HANDSHAKE)->RequestData(packet->guid); + playerController->GetPacket(ID_HANDSHAKE)->RequestData(packet->guid); Players::NewPlayer(packet->guid); player = Players::GetPlayer(packet->guid); - controller->GetPacket(ID_USER_MYID)->Send(Players::GetPlayer(packet->guid), false); + playerController->GetPacket(ID_USER_MYID)->Send(Players::GetPlayer(packet->guid), false); return; } - PlayerPacket *myPacket = controller->GetPacket(packet->data[0]); + PlayerPacket *myPacket = playerController->GetPacket(packet->data[0]); if (packet->data[0] == ID_HANDSHAKE) { @@ -116,7 +116,7 @@ void Networking::Update(RakNet::Packet *packet) if (!result) { - controller->GetPacket(ID_USER_DISCONNECTED)->Send(Players::GetPlayer(packet->guid), false); + playerController->GetPacket(ID_USER_DISCONNECTED)->Send(Players::GetPlayer(packet->guid), false); Players::DeletePlayer(packet->guid); return; } @@ -263,7 +263,7 @@ void Networking::Update(RakNet::Packet *packet) } myPacket->Send(player, true); - controller->GetPacket(ID_GAME_DYNAMICSTATS)->RequestData(player->GetAttack()->target); + playerController->GetPacket(ID_GAME_DYNAMICSTATS)->RequestData(player->GetAttack()->target); } break; } @@ -308,8 +308,8 @@ void Networking::Update(RakNet::Packet *packet) //packetResurrect.Read(player); player->CreatureStats()->mDead = false; myPacket->Send(player, true); - controller->GetPacket(ID_GAME_POS)->RequestData(player->guid); - controller->GetPacket(ID_GAME_CELL)->RequestData(player->guid); + playerController->GetPacket(ID_GAME_POS)->RequestData(player->guid); + playerController->GetPacket(ID_GAME_CELL)->RequestData(player->guid); Script::Call(player->GetID()); @@ -378,23 +378,23 @@ void Networking::Update(RakNet::Packet *packet) void Networking::NewPlayer(RakNet::RakNetGUID guid) { - controller->GetPacket(ID_GAME_BASE_INFO)->RequestData(guid); - controller->GetPacket(ID_GAME_DYNAMICSTATS)->RequestData(guid); - controller->GetPacket(ID_GAME_POS)->RequestData(guid); - controller->GetPacket(ID_GAME_CELL)->RequestData(guid); - controller->GetPacket(ID_GAME_EQUIPMENT)->RequestData(guid); + playerController->GetPacket(ID_GAME_BASE_INFO)->RequestData(guid); + playerController->GetPacket(ID_GAME_DYNAMICSTATS)->RequestData(guid); + playerController->GetPacket(ID_GAME_POS)->RequestData(guid); + playerController->GetPacket(ID_GAME_CELL)->RequestData(guid); + playerController->GetPacket(ID_GAME_EQUIPMENT)->RequestData(guid); for (TPlayers::iterator pl = players->begin(); pl != players->end(); pl++) //sending other players to new player { if (pl->first == guid) continue; - controller->GetPacket(ID_GAME_BASE_INFO)->Send(pl->second, guid); - controller->GetPacket(ID_GAME_DYNAMICSTATS)->Send(pl->second, guid); - controller->GetPacket(ID_GAME_ATTRIBUTE)->Send(pl->second, guid); - controller->GetPacket(ID_GAME_SKILL)->Send(pl->second, guid); - controller->GetPacket(ID_GAME_POS)->Send(pl->second, guid); - controller->GetPacket(ID_GAME_CELL)->Send(pl->second, guid); - controller->GetPacket(ID_GAME_EQUIPMENT)->Send(pl->second, guid); + playerController->GetPacket(ID_GAME_BASE_INFO)->Send(pl->second, guid); + playerController->GetPacket(ID_GAME_DYNAMICSTATS)->Send(pl->second, guid); + playerController->GetPacket(ID_GAME_ATTRIBUTE)->Send(pl->second, guid); + playerController->GetPacket(ID_GAME_SKILL)->Send(pl->second, guid); + playerController->GetPacket(ID_GAME_POS)->Send(pl->second, guid); + playerController->GetPacket(ID_GAME_CELL)->Send(pl->second, guid); + playerController->GetPacket(ID_GAME_EQUIPMENT)->Send(pl->second, guid); } } @@ -407,13 +407,13 @@ void Networking::DisconnectPlayer(RakNet::RakNetGUID guid) if (!player) return; Script::Call(player->GetID()); - controller->GetPacket(ID_USER_DISCONNECTED)->Send(player, true); + playerController->GetPacket(ID_USER_DISCONNECTED)->Send(player, true); Players::DeletePlayer(guid); } -PlayerPacketController *Networking::GetController() const +PlayerPacketController *Networking::GetPlayerController() const { - return controller; + return playerController; } const Networking &Networking::Get() diff --git a/apps/openmw-mp/Networking.hpp b/apps/openmw-mp/Networking.hpp index a19376485..d11c4f37b 100644 --- a/apps/openmw-mp/Networking.hpp +++ b/apps/openmw-mp/Networking.hpp @@ -27,7 +27,7 @@ namespace mwmp void StopServer(int code); - PlayerPacketController *GetController() const; + PlayerPacketController *GetPlayerController() const; static const Networking &Get(); static Networking *GetPtr(); @@ -37,7 +37,7 @@ namespace mwmp RakNet::BitStream bsOut; TPlayers *players; - PlayerPacketController *controller; + PlayerPacketController *playerController; bool running; int exitCode; diff --git a/apps/openmw-mp/Script/Functions/CharClass.cpp b/apps/openmw-mp/Script/Functions/CharClass.cpp index 5bb7cd81b..42dc6a911 100644 --- a/apps/openmw-mp/Script/Functions/CharClass.cpp +++ b/apps/openmw-mp/Script/Functions/CharClass.cpp @@ -15,7 +15,7 @@ void CharClassFunctions::SendClass(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player,); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_CHARCLASS)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_CHARCLASS)->Send(player, false); } void CharClassFunctions::SetDefaultClass(unsigned short pid, const char *id) noexcept diff --git a/apps/openmw-mp/Script/Functions/Chat.cpp b/apps/openmw-mp/Script/Functions/Chat.cpp index f7b878aeb..07c0c3783 100644 --- a/apps/openmw-mp/Script/Functions/Chat.cpp +++ b/apps/openmw-mp/Script/Functions/Chat.cpp @@ -15,9 +15,9 @@ void ScriptFunctions::SendMessage(unsigned short pid, const char *message, bool DEBUG_PRINTF("System: %s", message); - mwmp::Networking::Get().GetController()->GetPacket(ID_CHAT_MESSAGE)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_CHAT_MESSAGE)->Send(player, false); if (broadcast) - mwmp::Networking::Get().GetController()->GetPacket(ID_CHAT_MESSAGE)->Send(player, true); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_CHAT_MESSAGE)->Send(player, true); } void ScriptFunctions::CleanChat(unsigned short pid) diff --git a/apps/openmw-mp/Script/Functions/GUI.cpp b/apps/openmw-mp/Script/Functions/GUI.cpp index f613883d9..3e7146ede 100644 --- a/apps/openmw-mp/Script/Functions/GUI.cpp +++ b/apps/openmw-mp/Script/Functions/GUI.cpp @@ -18,7 +18,7 @@ void GUIFunctions::_MessageBox(unsigned short pid, int id, const char *label) no player->guiMessageBox.label = label; player->guiMessageBox.type = Player::GUIMessageBox::MessageBox; - mwmp::Networking::Get().GetController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(player, false); } void GUIFunctions::CustomMessageBox(unsigned short pid, int id, const char *label, const char *buttons) noexcept @@ -31,7 +31,7 @@ void GUIFunctions::CustomMessageBox(unsigned short pid, int id, const char *labe player->guiMessageBox.buttons = buttons; player->guiMessageBox.type = Player::GUIMessageBox::CustomMessageBox; - mwmp::Networking::Get().GetController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(player, false); } void GUIFunctions::InputDialog(unsigned short pid, int id, const char *label) noexcept @@ -43,7 +43,7 @@ void GUIFunctions::InputDialog(unsigned short pid, int id, const char *label) no player->guiMessageBox.label = label; player->guiMessageBox.type = Player::GUIMessageBox::InputDialog; - mwmp::Networking::Get().GetController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(player, false); } void GUIFunctions::SetMapVisibility(unsigned short targetPID, unsigned short affectedPID, unsigned short state) noexcept diff --git a/apps/openmw-mp/Script/Functions/Items.cpp b/apps/openmw-mp/Script/Functions/Items.cpp index 812854201..3d70af35a 100644 --- a/apps/openmw-mp/Script/Functions/Items.cpp +++ b/apps/openmw-mp/Script/Functions/Items.cpp @@ -65,6 +65,6 @@ void ItemFunctions::SendEquipment(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_EQUIPMENT)->Send(player, false); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_EQUIPMENT)->Send(player, true); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_EQUIPMENT)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_EQUIPMENT)->Send(player, true); } diff --git a/apps/openmw-mp/Script/Functions/Stats.cpp b/apps/openmw-mp/Script/Functions/Stats.cpp index 7a7131f5d..018d18646 100644 --- a/apps/openmw-mp/Script/Functions/Stats.cpp +++ b/apps/openmw-mp/Script/Functions/Stats.cpp @@ -454,14 +454,14 @@ void StatsFunctions::SetCharGenStage(unsigned short pid, int start, int end) noe player->CharGenStage()->current = start; player->CharGenStage()->end = end; - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_CHARGEN)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_CHARGEN)->Send(player, false); } void StatsFunctions::Resurrect(unsigned short pid) { Player *player; GET_PLAYER(pid, player,); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_RESURRECT)->RequestData(player->guid); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_RESURRECT)->RequestData(player->guid); } void StatsFunctions::SendBaseInfo(unsigned short pid) noexcept @@ -469,16 +469,16 @@ void StatsFunctions::SendBaseInfo(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player,); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_BASE_INFO)->Send(player, false); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_BASE_INFO)->Send(player, true); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_BASE_INFO)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_BASE_INFO)->Send(player, true); } void StatsFunctions::SendDynamicStats(unsigned short pid) noexcept { Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_DYNAMICSTATS)->Send(player, false); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_DYNAMICSTATS)->Send(player, true); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_DYNAMICSTATS)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_DYNAMICSTATS)->Send(player, true); } void StatsFunctions::SendAttributes(unsigned short pid) noexcept @@ -486,8 +486,8 @@ void StatsFunctions::SendAttributes(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player,); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_ATTRIBUTE)->Send(player, false); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_ATTRIBUTE)->Send(player, true); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_ATTRIBUTE)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_ATTRIBUTE)->Send(player, true); } void StatsFunctions::SendSkills(unsigned short pid) noexcept @@ -495,8 +495,8 @@ void StatsFunctions::SendSkills(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player,); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_SKILL)->Send(player, false); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_SKILL)->Send(player, true); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_SKILL)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_SKILL)->Send(player, true); } void StatsFunctions::SendLevel(unsigned short pid) noexcept @@ -504,6 +504,6 @@ void StatsFunctions::SendLevel(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_LEVEL)->Send(player, false); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_LEVEL)->Send(player, true); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_LEVEL)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_LEVEL)->Send(player, true); } diff --git a/apps/openmw-mp/Script/Functions/Translocations.cpp b/apps/openmw-mp/Script/Functions/Translocations.cpp index 3c468650e..202b91095 100644 --- a/apps/openmw-mp/Script/Functions/Translocations.cpp +++ b/apps/openmw-mp/Script/Functions/Translocations.cpp @@ -58,7 +58,7 @@ void TranslocationFunctions::SetPos(unsigned short pid, double x, double y, doub player->Position()->pos[1] = y; player->Position()->pos[2] = z; - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_POS)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_POS)->Send(player, false); } void TranslocationFunctions::SetCell(unsigned short pid, const char *name) noexcept @@ -80,7 +80,7 @@ void TranslocationFunctions::SetCell(unsigned short pid, const char *name) noexc player->GetCell()->mName = name; - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_CELL)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_CELL)->Send(player, false); } const char* TranslocationFunctions::GetCell(unsigned short pid) noexcept @@ -111,7 +111,7 @@ void TranslocationFunctions::SetExterior(unsigned short pid, int x, int y) noexc player->GetCell()->mCellId.mIndex.mX = x; player->GetCell()->mCellId.mIndex.mY = y; - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_CELL)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_CELL)->Send(player, false); } int TranslocationFunctions::GetExteriorX(unsigned short pid) noexcept @@ -183,5 +183,5 @@ void TranslocationFunctions::SetAngle(unsigned short pid, double x, double y, do player->Position()->rot[1] = y; player->Position()->rot[2] = z; - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_POS)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_POS)->Send(player, false); } diff --git a/apps/openmw-mp/Script/Functions/World.cpp b/apps/openmw-mp/Script/Functions/World.cpp index 15c22592f..a666fb1cc 100644 --- a/apps/openmw-mp/Script/Functions/World.cpp +++ b/apps/openmw-mp/Script/Functions/World.cpp @@ -17,7 +17,7 @@ void WorldFunctions::SetHour(unsigned short pid, double hour) noexcept player->month = -1; player->day = -1; - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_TIME)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_TIME)->Send(player, false); } void WorldFunctions::SetMonth(unsigned short pid, int month) noexcept @@ -29,7 +29,7 @@ void WorldFunctions::SetMonth(unsigned short pid, int month) noexcept player->month = month; player->day = -1; - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_TIME)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_TIME)->Send(player, false); } @@ -42,5 +42,5 @@ void WorldFunctions::SetDay(unsigned short pid, int day) noexcept player->month = -1; player->day = day; - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_TIME)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_TIME)->Send(player, false); } From d99463d75293930e365e63f7a7c052486c9cbc31 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 19 Oct 2016 18:56:12 +0300 Subject: [PATCH 05/34] Fix show-stopping mistake in PlayerPacket --- components/openmw-mp/Packets/PlayerPacket.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/openmw-mp/Packets/PlayerPacket.cpp b/components/openmw-mp/Packets/PlayerPacket.cpp index bebac49b6..338b7de27 100644 --- a/components/openmw-mp/Packets/PlayerPacket.cpp +++ b/components/openmw-mp/Packets/PlayerPacket.cpp @@ -53,6 +53,6 @@ void PlayerPacket::RequestData(RakNet::RakNetGUID guid) { bsSend->ResetWritePointer(); bsSend->Write(packetID); - bsSend->Write(player); + bsSend->Write(guid); peer->Send(bsSend, HIGH_PRIORITY, RELIABLE_ORDERED, 0, guid, false); } From 790d41e278d26a0075f5b43e6a57c9e8cd8071d4 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 19 Oct 2016 19:37:10 +0300 Subject: [PATCH 06/34] Move PlayerPackets into their own subfolder --- apps/openmw/mwmp/Networking.hpp | 18 ++++---- components/CMakeLists.txt | 11 +++-- .../Controllers/PlayerPacketController.cpp | 42 +++++++++---------- .../Controllers/PlayerPacketController.hpp | 2 +- .../Packets/{ => Player}/PacketAttack.cpp | 0 .../Packets/{ => Player}/PacketAttack.hpp | 2 +- .../Packets/{ => Player}/PacketAttribute.cpp | 0 .../Packets/{ => Player}/PacketAttribute.hpp | 2 +- .../Packets/{ => Player}/PacketBaseInfo.cpp | 0 .../Packets/{ => Player}/PacketBaseInfo.hpp | 2 +- .../Packets/{ => Player}/PacketCell.cpp | 0 .../Packets/{ => Player}/PacketCell.hpp | 2 +- .../Packets/{ => Player}/PacketCharGen.cpp | 0 .../Packets/{ => Player}/PacketCharGen.hpp | 2 +- .../{ => Player}/PacketChatMessage.cpp | 0 .../{ => Player}/PacketChatMessage.hpp | 2 +- .../Packets/{ => Player}/PacketClass.cpp | 0 .../Packets/{ => Player}/PacketClass.hpp | 2 +- .../Packets/{ => Player}/PacketDie.hpp | 2 +- .../Packets/{ => Player}/PacketDisconnect.hpp | 2 +- .../Packets/{ => Player}/PacketDrawState.cpp | 0 .../Packets/{ => Player}/PacketDrawState.hpp | 2 +- .../{ => Player}/PacketDynamicStats.cpp | 0 .../{ => Player}/PacketDynamicStats.hpp | 2 +- .../Packets/{ => Player}/PacketEquipment.cpp | 0 .../Packets/{ => Player}/PacketEquipment.hpp | 2 +- .../Packets/{ => Player}/PacketGUIBoxes.cpp | 0 .../Packets/{ => Player}/PacketGUIBoxes.hpp | 2 +- .../Packets/{ => Player}/PacketHandshake.cpp | 0 .../Packets/{ => Player}/PacketHandshake.hpp | 2 +- .../Packets/{ => Player}/PacketLevel.cpp | 0 .../Packets/{ => Player}/PacketLevel.hpp | 2 +- .../Packets/{ => Player}/PacketLoaded.hpp | 2 +- .../Packets/{ => Player}/PacketPosition.cpp | 0 .../Packets/{ => Player}/PacketPosition.hpp | 2 +- .../Packets/{ => Player}/PacketResurrect.hpp | 2 +- .../Packets/{ => Player}/PacketSendMyID.hpp | 2 +- .../Packets/{ => Player}/PacketSkill.cpp | 0 .../Packets/{ => Player}/PacketSkill.hpp | 2 +- .../Packets/{ => Player}/PacketTime.cpp | 0 .../Packets/{ => Player}/PacketTime.hpp | 2 +- .../Packets/{ => Player}/PlayerPacket.cpp | 0 .../Packets/{ => Player}/PlayerPacket.hpp | 2 +- 43 files changed, 60 insertions(+), 57 deletions(-) rename components/openmw-mp/Packets/{ => Player}/PacketAttack.cpp (100%) rename components/openmw-mp/Packets/{ => Player}/PacketAttack.hpp (85%) rename components/openmw-mp/Packets/{ => Player}/PacketAttribute.cpp (100%) rename components/openmw-mp/Packets/{ => Player}/PacketAttribute.hpp (87%) rename components/openmw-mp/Packets/{ => Player}/PacketBaseInfo.cpp (100%) rename components/openmw-mp/Packets/{ => Player}/PacketBaseInfo.hpp (85%) rename components/openmw-mp/Packets/{ => Player}/PacketCell.cpp (100%) rename components/openmw-mp/Packets/{ => Player}/PacketCell.hpp (84%) rename components/openmw-mp/Packets/{ => Player}/PacketCharGen.cpp (100%) rename components/openmw-mp/Packets/{ => Player}/PacketCharGen.hpp (85%) rename components/openmw-mp/Packets/{ => Player}/PacketChatMessage.cpp (100%) rename components/openmw-mp/Packets/{ => Player}/PacketChatMessage.hpp (86%) rename components/openmw-mp/Packets/{ => Player}/PacketClass.cpp (100%) rename components/openmw-mp/Packets/{ => Player}/PacketClass.hpp (85%) rename components/openmw-mp/Packets/{ => Player}/PacketDie.hpp (90%) rename components/openmw-mp/Packets/{ => Player}/PacketDisconnect.hpp (87%) rename components/openmw-mp/Packets/{ => Player}/PacketDrawState.cpp (100%) rename components/openmw-mp/Packets/{ => Player}/PacketDrawState.hpp (85%) rename components/openmw-mp/Packets/{ => Player}/PacketDynamicStats.cpp (100%) rename components/openmw-mp/Packets/{ => Player}/PacketDynamicStats.hpp (86%) rename components/openmw-mp/Packets/{ => Player}/PacketEquipment.cpp (100%) rename components/openmw-mp/Packets/{ => Player}/PacketEquipment.hpp (85%) rename components/openmw-mp/Packets/{ => Player}/PacketGUIBoxes.cpp (100%) rename components/openmw-mp/Packets/{ => Player}/PacketGUIBoxes.hpp (85%) rename components/openmw-mp/Packets/{ => Player}/PacketHandshake.cpp (100%) rename components/openmw-mp/Packets/{ => Player}/PacketHandshake.hpp (85%) rename components/openmw-mp/Packets/{ => Player}/PacketLevel.cpp (100%) rename components/openmw-mp/Packets/{ => Player}/PacketLevel.hpp (85%) rename components/openmw-mp/Packets/{ => Player}/PacketLoaded.hpp (84%) rename components/openmw-mp/Packets/{ => Player}/PacketPosition.cpp (100%) rename components/openmw-mp/Packets/{ => Player}/PacketPosition.hpp (85%) rename components/openmw-mp/Packets/{ => Player}/PacketResurrect.hpp (90%) rename components/openmw-mp/Packets/{ => Player}/PacketSendMyID.hpp (86%) rename components/openmw-mp/Packets/{ => Player}/PacketSkill.cpp (100%) rename components/openmw-mp/Packets/{ => Player}/PacketSkill.hpp (87%) rename components/openmw-mp/Packets/{ => Player}/PacketTime.cpp (100%) rename components/openmw-mp/Packets/{ => Player}/PacketTime.hpp (84%) rename components/openmw-mp/Packets/{ => Player}/PlayerPacket.cpp (100%) rename components/openmw-mp/Packets/{ => Player}/PlayerPacket.hpp (95%) diff --git a/apps/openmw/mwmp/Networking.hpp b/apps/openmw/mwmp/Networking.hpp index bc2dd9c4c..f9b06794c 100644 --- a/apps/openmw/mwmp/Networking.hpp +++ b/apps/openmw/mwmp/Networking.hpp @@ -10,15 +10,15 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include namespace mwmp diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 61fc1fda7..0260e9cb5 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -148,10 +148,13 @@ add_component_dir (version add_component_dir (openmw-mp Log Controllers/PlayerPacketController - Packets/BasePacket Packets/PlayerPacket Packets/PacketBaseInfo Packets/PacketPosition Packets/PacketEquipment - Packets/PacketAttack Packets/PacketDynamicStats Packets/PacketCell Packets/PacketDrawState Packets/PacketChatMessage - Packets/PacketCharGen Packets/PacketAttribute Packets/PacketSkill Packets/PacketLevel Packets/PacketHandshake - Packets/PacketGUIBoxes Packets/PacketClass Packets/PacketTime) + Packets/BasePacket Packets/Player/PlayerPacket + Packets/Player/PacketBaseInfo Packets/Player/PacketPosition Packets/Player/PacketEquipment + Packets/Player/PacketAttack Packets/Player/PacketDynamicStats Packets/Player/PacketCell + Packets/Player/PacketDrawState Packets/Player/PacketChatMessage Packets/Player/PacketCharGen + Packets/Player/PacketAttribute Packets/Player/PacketSkill Packets/Player/PacketLevel + Packets/Player/PacketHandshake Packets/Player/PacketGUIBoxes Packets/Player/PacketClass + Packets/Player/PacketTime) add_component_dir (fallback fallback validate diff --git a/components/openmw-mp/Controllers/PlayerPacketController.cpp b/components/openmw-mp/Controllers/PlayerPacketController.cpp index 1e283fe65..ed232d985 100644 --- a/components/openmw-mp/Controllers/PlayerPacketController.cpp +++ b/components/openmw-mp/Controllers/PlayerPacketController.cpp @@ -2,27 +2,27 @@ #include #include -#include "../Packets/PacketClass.hpp" -#include "../Packets/PacketPosition.hpp" -#include "../Packets/PacketBaseInfo.hpp" -#include "../Packets/PacketEquipment.hpp" -#include "../Packets/PacketAttack.hpp" -#include "../Packets/PacketDynamicStats.hpp" -#include "../Packets/PacketResurrect.hpp" -#include "../Packets/PacketDie.hpp" -#include "../Packets/PacketCell.hpp" -#include "../Packets/PacketSendMyID.hpp" -#include "../Packets/PacketDisconnect.hpp" -#include "../Packets/PacketDrawState.hpp" -#include "../Packets/PacketChatMessage.hpp" -#include "../Packets/PacketCharGen.hpp" -#include "../Packets/PacketAttribute.hpp" -#include "../Packets/PacketSkill.hpp" -#include "../Packets/PacketLevel.hpp" -#include "../Packets/PacketHandshake.hpp" -#include "../Packets/PacketGUIBoxes.hpp" -#include "../Packets/PacketTime.hpp" -#include "../Packets/PacketLoaded.hpp" +#include "../Packets/Player/PacketClass.hpp" +#include "../Packets/Player/PacketPosition.hpp" +#include "../Packets/Player/PacketBaseInfo.hpp" +#include "../Packets/Player/PacketEquipment.hpp" +#include "../Packets/Player/PacketAttack.hpp" +#include "../Packets/Player/PacketDynamicStats.hpp" +#include "../Packets/Player/PacketResurrect.hpp" +#include "../Packets/Player/PacketDie.hpp" +#include "../Packets/Player/PacketCell.hpp" +#include "../Packets/Player/PacketSendMyID.hpp" +#include "../Packets/Player/PacketDisconnect.hpp" +#include "../Packets/Player/PacketDrawState.hpp" +#include "../Packets/Player/PacketChatMessage.hpp" +#include "../Packets/Player/PacketCharGen.hpp" +#include "../Packets/Player/PacketAttribute.hpp" +#include "../Packets/Player/PacketSkill.hpp" +#include "../Packets/Player/PacketLevel.hpp" +#include "../Packets/Player/PacketHandshake.hpp" +#include "../Packets/Player/PacketGUIBoxes.hpp" +#include "../Packets/Player/PacketTime.hpp" +#include "../Packets/Player/PacketLoaded.hpp" #include "PlayerPacketController.hpp" diff --git a/components/openmw-mp/Controllers/PlayerPacketController.hpp b/components/openmw-mp/Controllers/PlayerPacketController.hpp index efb104a07..1938edb50 100644 --- a/components/openmw-mp/Controllers/PlayerPacketController.hpp +++ b/components/openmw-mp/Controllers/PlayerPacketController.hpp @@ -3,7 +3,7 @@ #include -#include "../Packets/PlayerPacket.hpp" +#include "../Packets/Player/PlayerPacket.hpp" #include #include diff --git a/components/openmw-mp/Packets/PacketAttack.cpp b/components/openmw-mp/Packets/Player/PacketAttack.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketAttack.cpp rename to components/openmw-mp/Packets/Player/PacketAttack.cpp diff --git a/components/openmw-mp/Packets/PacketAttack.hpp b/components/openmw-mp/Packets/Player/PacketAttack.hpp similarity index 85% rename from components/openmw-mp/Packets/PacketAttack.hpp rename to components/openmw-mp/Packets/Player/PacketAttack.hpp index cbc64bcca..415d5f78a 100644 --- a/components/openmw-mp/Packets/PacketAttack.hpp +++ b/components/openmw-mp/Packets/Player/PacketAttack.hpp @@ -6,7 +6,7 @@ #define OPENMW_PACKETATTACK_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketAttribute.cpp b/components/openmw-mp/Packets/Player/PacketAttribute.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketAttribute.cpp rename to components/openmw-mp/Packets/Player/PacketAttribute.cpp diff --git a/components/openmw-mp/Packets/PacketAttribute.hpp b/components/openmw-mp/Packets/Player/PacketAttribute.hpp similarity index 87% rename from components/openmw-mp/Packets/PacketAttribute.hpp rename to components/openmw-mp/Packets/Player/PacketAttribute.hpp index 461587f23..4a60347da 100644 --- a/components/openmw-mp/Packets/PacketAttribute.hpp +++ b/components/openmw-mp/Packets/Player/PacketAttribute.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_PACKETATTRIBUTE_HPP #define OPENMW_PACKETATTRIBUTE_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketBaseInfo.cpp b/components/openmw-mp/Packets/Player/PacketBaseInfo.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketBaseInfo.cpp rename to components/openmw-mp/Packets/Player/PacketBaseInfo.cpp diff --git a/components/openmw-mp/Packets/PacketBaseInfo.hpp b/components/openmw-mp/Packets/Player/PacketBaseInfo.hpp similarity index 85% rename from components/openmw-mp/Packets/PacketBaseInfo.hpp rename to components/openmw-mp/Packets/Player/PacketBaseInfo.hpp index 4b7e33896..91a6bee0f 100644 --- a/components/openmw-mp/Packets/PacketBaseInfo.hpp +++ b/components/openmw-mp/Packets/Player/PacketBaseInfo.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_PACKETBASEINFO_HPP #define OPENMW_PACKETBASEINFO_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketCell.cpp b/components/openmw-mp/Packets/Player/PacketCell.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketCell.cpp rename to components/openmw-mp/Packets/Player/PacketCell.cpp diff --git a/components/openmw-mp/Packets/PacketCell.hpp b/components/openmw-mp/Packets/Player/PacketCell.hpp similarity index 84% rename from components/openmw-mp/Packets/PacketCell.hpp rename to components/openmw-mp/Packets/Player/PacketCell.hpp index 74ca1faab..b130202b4 100644 --- a/components/openmw-mp/Packets/PacketCell.hpp +++ b/components/openmw-mp/Packets/Player/PacketCell.hpp @@ -6,7 +6,7 @@ #define OPENMW_PACKETCELL_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketCharGen.cpp b/components/openmw-mp/Packets/Player/PacketCharGen.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketCharGen.cpp rename to components/openmw-mp/Packets/Player/PacketCharGen.cpp diff --git a/components/openmw-mp/Packets/PacketCharGen.hpp b/components/openmw-mp/Packets/Player/PacketCharGen.hpp similarity index 85% rename from components/openmw-mp/Packets/PacketCharGen.hpp rename to components/openmw-mp/Packets/Player/PacketCharGen.hpp index c9d51f9e1..7df1e43ff 100644 --- a/components/openmw-mp/Packets/PacketCharGen.hpp +++ b/components/openmw-mp/Packets/Player/PacketCharGen.hpp @@ -6,7 +6,7 @@ #define OPENMW_PACKETCHARGEN_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketChatMessage.cpp b/components/openmw-mp/Packets/Player/PacketChatMessage.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketChatMessage.cpp rename to components/openmw-mp/Packets/Player/PacketChatMessage.cpp diff --git a/components/openmw-mp/Packets/PacketChatMessage.hpp b/components/openmw-mp/Packets/Player/PacketChatMessage.hpp similarity index 86% rename from components/openmw-mp/Packets/PacketChatMessage.hpp rename to components/openmw-mp/Packets/Player/PacketChatMessage.hpp index 0decedd65..c15dc1083 100644 --- a/components/openmw-mp/Packets/PacketChatMessage.hpp +++ b/components/openmw-mp/Packets/Player/PacketChatMessage.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_PACKETCHATMESSAGE_HPP #define OPENMW_PACKETCHATMESSAGE_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketClass.cpp b/components/openmw-mp/Packets/Player/PacketClass.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketClass.cpp rename to components/openmw-mp/Packets/Player/PacketClass.cpp diff --git a/components/openmw-mp/Packets/PacketClass.hpp b/components/openmw-mp/Packets/Player/PacketClass.hpp similarity index 85% rename from components/openmw-mp/Packets/PacketClass.hpp rename to components/openmw-mp/Packets/Player/PacketClass.hpp index 6ae1dea8e..f8ce75dc5 100644 --- a/components/openmw-mp/Packets/PacketClass.hpp +++ b/components/openmw-mp/Packets/Player/PacketClass.hpp @@ -6,7 +6,7 @@ #define OPENMW_PACKETCLASS_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketDie.hpp b/components/openmw-mp/Packets/Player/PacketDie.hpp similarity index 90% rename from components/openmw-mp/Packets/PacketDie.hpp rename to components/openmw-mp/Packets/Player/PacketDie.hpp index 15622465c..88dbac404 100644 --- a/components/openmw-mp/Packets/PacketDie.hpp +++ b/components/openmw-mp/Packets/Player/PacketDie.hpp @@ -6,7 +6,7 @@ #define OPENMW_PACKETDIE_HPP -#include +#include #include namespace mwmp diff --git a/components/openmw-mp/Packets/PacketDisconnect.hpp b/components/openmw-mp/Packets/Player/PacketDisconnect.hpp similarity index 87% rename from components/openmw-mp/Packets/PacketDisconnect.hpp rename to components/openmw-mp/Packets/Player/PacketDisconnect.hpp index 154a31f32..39cdbcbc1 100644 --- a/components/openmw-mp/Packets/PacketDisconnect.hpp +++ b/components/openmw-mp/Packets/Player/PacketDisconnect.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_PACKETDISCONNECT_HPP #define OPENMW_PACKETDISCONNECT_HPP -#include +#include #include namespace mwmp diff --git a/components/openmw-mp/Packets/PacketDrawState.cpp b/components/openmw-mp/Packets/Player/PacketDrawState.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketDrawState.cpp rename to components/openmw-mp/Packets/Player/PacketDrawState.cpp diff --git a/components/openmw-mp/Packets/PacketDrawState.hpp b/components/openmw-mp/Packets/Player/PacketDrawState.hpp similarity index 85% rename from components/openmw-mp/Packets/PacketDrawState.hpp rename to components/openmw-mp/Packets/Player/PacketDrawState.hpp index c1fb4b991..7aa20750c 100644 --- a/components/openmw-mp/Packets/PacketDrawState.hpp +++ b/components/openmw-mp/Packets/Player/PacketDrawState.hpp @@ -6,7 +6,7 @@ #define OPENMW_PACKETDRAWSTATE_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketDynamicStats.cpp b/components/openmw-mp/Packets/Player/PacketDynamicStats.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketDynamicStats.cpp rename to components/openmw-mp/Packets/Player/PacketDynamicStats.cpp diff --git a/components/openmw-mp/Packets/PacketDynamicStats.hpp b/components/openmw-mp/Packets/Player/PacketDynamicStats.hpp similarity index 86% rename from components/openmw-mp/Packets/PacketDynamicStats.hpp rename to components/openmw-mp/Packets/Player/PacketDynamicStats.hpp index c4c8e8ff2..8c03445bc 100644 --- a/components/openmw-mp/Packets/PacketDynamicStats.hpp +++ b/components/openmw-mp/Packets/Player/PacketDynamicStats.hpp @@ -6,7 +6,7 @@ #define OPENMW_PACKAGEDYNAMICSTATS_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketEquipment.cpp b/components/openmw-mp/Packets/Player/PacketEquipment.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketEquipment.cpp rename to components/openmw-mp/Packets/Player/PacketEquipment.cpp diff --git a/components/openmw-mp/Packets/PacketEquipment.hpp b/components/openmw-mp/Packets/Player/PacketEquipment.hpp similarity index 85% rename from components/openmw-mp/Packets/PacketEquipment.hpp rename to components/openmw-mp/Packets/Player/PacketEquipment.hpp index 5b677f555..d0134a577 100644 --- a/components/openmw-mp/Packets/PacketEquipment.hpp +++ b/components/openmw-mp/Packets/Player/PacketEquipment.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_PACKETEQUIPMENT_HPP #define OPENMW_PACKETEQUIPMENT_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketGUIBoxes.cpp b/components/openmw-mp/Packets/Player/PacketGUIBoxes.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketGUIBoxes.cpp rename to components/openmw-mp/Packets/Player/PacketGUIBoxes.cpp diff --git a/components/openmw-mp/Packets/PacketGUIBoxes.hpp b/components/openmw-mp/Packets/Player/PacketGUIBoxes.hpp similarity index 85% rename from components/openmw-mp/Packets/PacketGUIBoxes.hpp rename to components/openmw-mp/Packets/Player/PacketGUIBoxes.hpp index ace0bf771..8d71257f9 100644 --- a/components/openmw-mp/Packets/PacketGUIBoxes.hpp +++ b/components/openmw-mp/Packets/Player/PacketGUIBoxes.hpp @@ -6,7 +6,7 @@ #define OPENMW_PACKETGUIBOXES_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketHandshake.cpp b/components/openmw-mp/Packets/Player/PacketHandshake.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketHandshake.cpp rename to components/openmw-mp/Packets/Player/PacketHandshake.cpp diff --git a/components/openmw-mp/Packets/PacketHandshake.hpp b/components/openmw-mp/Packets/Player/PacketHandshake.hpp similarity index 85% rename from components/openmw-mp/Packets/PacketHandshake.hpp rename to components/openmw-mp/Packets/Player/PacketHandshake.hpp index b5846d433..539be878b 100644 --- a/components/openmw-mp/Packets/PacketHandshake.hpp +++ b/components/openmw-mp/Packets/Player/PacketHandshake.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_PACKETHANDSHAKE_HPP #define OPENMW_PACKETHANDSHAKE_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketLevel.cpp b/components/openmw-mp/Packets/Player/PacketLevel.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketLevel.cpp rename to components/openmw-mp/Packets/Player/PacketLevel.cpp diff --git a/components/openmw-mp/Packets/PacketLevel.hpp b/components/openmw-mp/Packets/Player/PacketLevel.hpp similarity index 85% rename from components/openmw-mp/Packets/PacketLevel.hpp rename to components/openmw-mp/Packets/Player/PacketLevel.hpp index aa61dcc10..8537e954d 100644 --- a/components/openmw-mp/Packets/PacketLevel.hpp +++ b/components/openmw-mp/Packets/Player/PacketLevel.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_PACKETLEVEL_HPP #define OPENMW_PACKETLEVEL_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketLoaded.hpp b/components/openmw-mp/Packets/Player/PacketLoaded.hpp similarity index 84% rename from components/openmw-mp/Packets/PacketLoaded.hpp rename to components/openmw-mp/Packets/Player/PacketLoaded.hpp index 35565150d..8f58a4938 100644 --- a/components/openmw-mp/Packets/PacketLoaded.hpp +++ b/components/openmw-mp/Packets/Player/PacketLoaded.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_PACKETLOADED_HPP #define OPENMW_PACKETLOADED_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketPosition.cpp b/components/openmw-mp/Packets/Player/PacketPosition.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketPosition.cpp rename to components/openmw-mp/Packets/Player/PacketPosition.cpp diff --git a/components/openmw-mp/Packets/PacketPosition.hpp b/components/openmw-mp/Packets/Player/PacketPosition.hpp similarity index 85% rename from components/openmw-mp/Packets/PacketPosition.hpp rename to components/openmw-mp/Packets/Player/PacketPosition.hpp index d15baa946..33c60a6a8 100644 --- a/components/openmw-mp/Packets/PacketPosition.hpp +++ b/components/openmw-mp/Packets/Player/PacketPosition.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_PACKETPOSITION_HPP #define OPENMW_PACKETPOSITION_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketResurrect.hpp b/components/openmw-mp/Packets/Player/PacketResurrect.hpp similarity index 90% rename from components/openmw-mp/Packets/PacketResurrect.hpp rename to components/openmw-mp/Packets/Player/PacketResurrect.hpp index 4588fbbfd..f24d81d62 100644 --- a/components/openmw-mp/Packets/PacketResurrect.hpp +++ b/components/openmw-mp/Packets/Player/PacketResurrect.hpp @@ -6,7 +6,7 @@ #define OPENMW_PACKETRESURRECT_HPP -#include +#include #include namespace mwmp diff --git a/components/openmw-mp/Packets/PacketSendMyID.hpp b/components/openmw-mp/Packets/Player/PacketSendMyID.hpp similarity index 86% rename from components/openmw-mp/Packets/PacketSendMyID.hpp rename to components/openmw-mp/Packets/Player/PacketSendMyID.hpp index 32ddbe8c9..5e6fa802c 100644 --- a/components/openmw-mp/Packets/PacketSendMyID.hpp +++ b/components/openmw-mp/Packets/Player/PacketSendMyID.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_PACKETSENDMYID_HPP #define OPENMW_PACKETSENDMYID_HPP -#include +#include #include namespace mwmp diff --git a/components/openmw-mp/Packets/PacketSkill.cpp b/components/openmw-mp/Packets/Player/PacketSkill.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketSkill.cpp rename to components/openmw-mp/Packets/Player/PacketSkill.cpp diff --git a/components/openmw-mp/Packets/PacketSkill.hpp b/components/openmw-mp/Packets/Player/PacketSkill.hpp similarity index 87% rename from components/openmw-mp/Packets/PacketSkill.hpp rename to components/openmw-mp/Packets/Player/PacketSkill.hpp index 3f58db341..d7af6c56b 100644 --- a/components/openmw-mp/Packets/PacketSkill.hpp +++ b/components/openmw-mp/Packets/Player/PacketSkill.hpp @@ -6,7 +6,7 @@ #define OPENMW_PACKETSKILL_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketTime.cpp b/components/openmw-mp/Packets/Player/PacketTime.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketTime.cpp rename to components/openmw-mp/Packets/Player/PacketTime.cpp diff --git a/components/openmw-mp/Packets/PacketTime.hpp b/components/openmw-mp/Packets/Player/PacketTime.hpp similarity index 84% rename from components/openmw-mp/Packets/PacketTime.hpp rename to components/openmw-mp/Packets/Player/PacketTime.hpp index bb7521ff8..69efa442b 100644 --- a/components/openmw-mp/Packets/PacketTime.hpp +++ b/components/openmw-mp/Packets/Player/PacketTime.hpp @@ -6,7 +6,7 @@ #define OPENMW_TIMEPACKET_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PlayerPacket.cpp b/components/openmw-mp/Packets/Player/PlayerPacket.cpp similarity index 100% rename from components/openmw-mp/Packets/PlayerPacket.cpp rename to components/openmw-mp/Packets/Player/PlayerPacket.cpp diff --git a/components/openmw-mp/Packets/PlayerPacket.hpp b/components/openmw-mp/Packets/Player/PlayerPacket.hpp similarity index 95% rename from components/openmw-mp/Packets/PlayerPacket.hpp rename to components/openmw-mp/Packets/Player/PlayerPacket.hpp index 9281baf87..54c085db9 100644 --- a/components/openmw-mp/Packets/PlayerPacket.hpp +++ b/components/openmw-mp/Packets/Player/PlayerPacket.hpp @@ -7,7 +7,7 @@ #include #include -#include "BasePacket.hpp" +#include namespace mwmp From 285f89573d0b884f67fa1c896ab9f7ff672b57ab Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 19 Oct 2016 20:36:11 +0300 Subject: [PATCH 07/34] Create placeholders for WorldPacket classes --- components/CMakeLists.txt | 9 ++- .../Controllers/WorldPacketController.cpp | 32 ++++++++++ .../Controllers/WorldPacketController.hpp | 25 ++++++++ components/openmw-mp/NetworkMessages.hpp | 4 +- .../Packets/World/PacketObjectRemoval.cpp | 14 +++++ .../Packets/World/PacketObjectRemoval.hpp | 17 ++++++ .../openmw-mp/Packets/World/WorldPacket.cpp | 58 +++++++++++++++++++ .../openmw-mp/Packets/World/WorldPacket.hpp | 46 +++++++++++++++ 8 files changed, 201 insertions(+), 4 deletions(-) create mode 100644 components/openmw-mp/Controllers/WorldPacketController.cpp create mode 100644 components/openmw-mp/Controllers/WorldPacketController.hpp create mode 100644 components/openmw-mp/Packets/World/PacketObjectRemoval.cpp create mode 100644 components/openmw-mp/Packets/World/PacketObjectRemoval.hpp create mode 100644 components/openmw-mp/Packets/World/WorldPacket.cpp create mode 100644 components/openmw-mp/Packets/World/WorldPacket.hpp diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 0260e9cb5..417528d23 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -147,14 +147,17 @@ add_component_dir (version add_component_dir (openmw-mp Log - Controllers/PlayerPacketController - Packets/BasePacket Packets/Player/PlayerPacket + Controllers/PlayerPacketController Controllers/WorldPacketController + Packets/BasePacket Packets/Player/PlayerPacket Packets/World/WorldPacket + Packets/Player/PacketBaseInfo Packets/Player/PacketPosition Packets/Player/PacketEquipment Packets/Player/PacketAttack Packets/Player/PacketDynamicStats Packets/Player/PacketCell Packets/Player/PacketDrawState Packets/Player/PacketChatMessage Packets/Player/PacketCharGen Packets/Player/PacketAttribute Packets/Player/PacketSkill Packets/Player/PacketLevel Packets/Player/PacketHandshake Packets/Player/PacketGUIBoxes Packets/Player/PacketClass - Packets/Player/PacketTime) + Packets/Player/PacketTime + + Packets/World/PacketObjectRemoval) add_component_dir (fallback fallback validate diff --git a/components/openmw-mp/Controllers/WorldPacketController.cpp b/components/openmw-mp/Controllers/WorldPacketController.cpp new file mode 100644 index 000000000..3a077892e --- /dev/null +++ b/components/openmw-mp/Controllers/WorldPacketController.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +#include "../Packets/World/PacketObjectRemoval.hpp" + +#include "WorldPacketController.hpp" + +template +inline void AddPacket(mwmp::WorldPacketController::packets_t *packets, RakNet::RakPeerInterface *peer) +{ + T *packet = new T(peer); + typedef mwmp::WorldPacketController::packets_t::value_type value_t; + packets->insert(value_t(packet->GetPacketID(), value_t::second_type(packet))); +} + +mwmp::WorldPacketController::WorldPacketController(RakNet::RakPeerInterface *peer) +{ + AddPacket(&packets, peer); +} + + +mwmp::WorldPacket *mwmp::WorldPacketController::GetPacket(RakNet::MessageID id) +{ + return packets[(unsigned char)id].get(); +} + +void mwmp::WorldPacketController::SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream) +{ + BOOST_FOREACH( packets_t::value_type &packet, packets ) + packet.second->SetStreams(inStream, outStream); +} \ No newline at end of file diff --git a/components/openmw-mp/Controllers/WorldPacketController.hpp b/components/openmw-mp/Controllers/WorldPacketController.hpp new file mode 100644 index 000000000..8831a2e66 --- /dev/null +++ b/components/openmw-mp/Controllers/WorldPacketController.hpp @@ -0,0 +1,25 @@ +#ifndef OPENMW_WORLDPACKETCONTROLLER_HPP +#define OPENMW_WORLDPACKETCONTROLLER_HPP + + +#include +#include "../Packets/World/WorldPacket.hpp" +#include +#include + +namespace mwmp +{ + class WorldPacketController + { + public: + WorldPacketController(RakNet::RakPeerInterface *peer); + WorldPacket *GetPacket(RakNet::MessageID id); + void SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream); + + typedef std::map > packets_t; + private: + packets_t packets; + }; +} + +#endif //OPENMW_WORLDPACKETCONTROLLER_HPP diff --git a/components/openmw-mp/NetworkMessages.hpp b/components/openmw-mp/NetworkMessages.hpp index d6177a7d2..1bcd02b08 100644 --- a/components/openmw-mp/NetworkMessages.hpp +++ b/components/openmw-mp/NetworkMessages.hpp @@ -30,7 +30,9 @@ enum GameMessages ID_HANDSHAKE, ID_LOADED, ID_GUI_MESSAGEBOX, - ID_GAME_TIME + ID_GAME_TIME, + + ID_WORLD_OBJECT_REMOVAL }; diff --git a/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp b/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp new file mode 100644 index 000000000..a13dc548b --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp @@ -0,0 +1,14 @@ +#include +#include "PacketObjectRemoval.hpp" + +using namespace mwmp; + +PacketObjectRemoval::PacketObjectRemoval(RakNet::RakPeerInterface *peer) : WorldPacket(peer) +{ + packetID = ID_WORLD_OBJECT_REMOVAL; +} + +void PacketObjectRemoval::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send) +{ + WorldPacket::Packet(bs, player, send); +} diff --git a/components/openmw-mp/Packets/World/PacketObjectRemoval.hpp b/components/openmw-mp/Packets/World/PacketObjectRemoval.hpp new file mode 100644 index 000000000..2469dee37 --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketObjectRemoval.hpp @@ -0,0 +1,17 @@ +#ifndef OPENMW_PACKETOBJECTREMOVAL_HPP +#define OPENMW_PACKETOBJECTREMOVAL_HPP + +#include + +namespace mwmp +{ + class PacketObjectRemoval : public WorldPacket + { + public: + PacketObjectRemoval(RakNet::RakPeerInterface *peer); + + virtual void Packet(RakNet::BitStream *bs, BasePlayer *player, bool send); + }; +} + +#endif //OPENMW_PACKETOBJECTREMOVAL_HPP diff --git a/components/openmw-mp/Packets/World/WorldPacket.cpp b/components/openmw-mp/Packets/World/WorldPacket.cpp new file mode 100644 index 000000000..7bc634d83 --- /dev/null +++ b/components/openmw-mp/Packets/World/WorldPacket.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include "WorldPacket.hpp" + +using namespace mwmp; + +void WorldPacket::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send) +{ + this->player = player; + this->bs = bs; + + if (send) + { + bs->Write(packetID); + bs->Write(player->guid); + } +} + +WorldPacket::WorldPacket(RakNet::RakPeerInterface *peer) : BasePacket(peer) +{ + packetID = 0; + priority = HIGH_PRIORITY; + reliability = RELIABLE_ORDERED; + this->peer = peer; +} + +WorldPacket::~WorldPacket() +{ + +} + +void WorldPacket::Send(BasePlayer *player, RakNet::AddressOrGUID destination) +{ + bsSend->ResetWritePointer(); + Packet(bsSend, player, true); + peer->Send(bsSend, priority, reliability, 0, destination, false); +} + +void WorldPacket::Send(BasePlayer *player, bool toOther) +{ + bsSend->ResetWritePointer(); + Packet(bsSend, player, true); + peer->Send(bsSend, priority, reliability, 0, player->guid, toOther); +} + +void WorldPacket::Read(BasePlayer *player) +{ + Packet(bsRead, player, false); +} + +void WorldPacket::RequestData(RakNet::RakNetGUID guid) +{ + bsSend->ResetWritePointer(); + bsSend->Write(packetID); + bsSend->Write(guid); + peer->Send(bsSend, HIGH_PRIORITY, RELIABLE_ORDERED, 0, guid, false); +} diff --git a/components/openmw-mp/Packets/World/WorldPacket.hpp b/components/openmw-mp/Packets/World/WorldPacket.hpp new file mode 100644 index 000000000..9dc0fe8f8 --- /dev/null +++ b/components/openmw-mp/Packets/World/WorldPacket.hpp @@ -0,0 +1,46 @@ +#ifndef OPENMW_WORLDPACKET_HPP +#define OPENMW_WORLDPACKET_HPP + +#include +#include +#include +#include +#include + +#include + + +namespace mwmp +{ + class WorldPacket : public BasePacket + { + public: + WorldPacket(RakNet::RakPeerInterface *peer); + + ~WorldPacket(); + + virtual void Packet(RakNet::BitStream *bs, BasePlayer *player, bool send); + + virtual void Send(BasePlayer *player, bool toOtherPlayers = true); + virtual void Send(BasePlayer *player, RakNet::AddressOrGUID destination); + virtual void Read(BasePlayer *player); + + virtual void RequestData(RakNet::RakNetGUID player); + + static size_t headerSize() + { + return (size_t)(1 + RakNet::RakNetGUID::size()); // packetID + RakNetGUID (uint64_t) + } + + unsigned char GetPacketID() + { + return packetID; + } + + protected: + BasePlayer *player; + + }; +} + +#endif //OPENMW_WORLDPACKET_HPP From f1ec01cc6beda8deac0e326a1d8a63d052adf06d Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 19 Oct 2016 20:51:51 +0300 Subject: [PATCH 08/34] Add WorldPacketController to server's Networking --- apps/openmw-mp/Networking.cpp | 10 +++++++++- apps/openmw-mp/Networking.hpp | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index 3ea2395e5..dfb2e8ab1 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -27,8 +27,11 @@ Networking::Networking(RakNet::RakPeerInterface *peer) players = Players::GetPlayers(); playerController = new PlayerPacketController(peer); + worldController = new WorldPacketController(peer); - playerController->SetStream(0, &bsOut); // set send stream + // Set send stream + playerController->SetStream(0, &bsOut); + worldController->SetStream(0, &bsOut); running = true; exitCode = 0; @@ -416,6 +419,11 @@ PlayerPacketController *Networking::GetPlayerController() const return playerController; } +WorldPacketController *Networking::GetWorldController() const +{ + return worldController; +} + const Networking &Networking::Get() { return *sThis; diff --git a/apps/openmw-mp/Networking.hpp b/apps/openmw-mp/Networking.hpp index d11c4f37b..3d541c7f9 100644 --- a/apps/openmw-mp/Networking.hpp +++ b/apps/openmw-mp/Networking.hpp @@ -6,6 +6,7 @@ #define OPENMW_NETWORKING_HPP #include +#include #include "Player.hpp" namespace mwmp @@ -28,6 +29,8 @@ namespace mwmp void StopServer(int code); PlayerPacketController *GetPlayerController() const; + WorldPacketController *GetWorldController() const; + static const Networking &Get(); static Networking *GetPtr(); @@ -38,6 +41,7 @@ namespace mwmp TPlayers *players; PlayerPacketController *playerController; + WorldPacketController *worldController; bool running; int exitCode; From f0fa5e8771832e21ebdec131abc72c8d86f44f02 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 19 Oct 2016 21:15:59 +0300 Subject: [PATCH 09/34] Add ContainsPacket method to packet controllers --- .../openmw-mp/Controllers/PlayerPacketController.cpp | 11 ++++++++++- .../openmw-mp/Controllers/PlayerPacketController.hpp | 2 ++ .../openmw-mp/Controllers/WorldPacketController.cpp | 11 ++++++++++- .../openmw-mp/Controllers/WorldPacketController.hpp | 2 ++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/components/openmw-mp/Controllers/PlayerPacketController.cpp b/components/openmw-mp/Controllers/PlayerPacketController.cpp index ed232d985..5817069fe 100644 --- a/components/openmw-mp/Controllers/PlayerPacketController.cpp +++ b/components/openmw-mp/Controllers/PlayerPacketController.cpp @@ -73,4 +73,13 @@ void mwmp::PlayerPacketController::SetStream(RakNet::BitStream *inStream, RakNet { BOOST_FOREACH( packets_t::value_type &packet, packets ) packet.second->SetStreams(inStream, outStream); -} \ No newline at end of file +} + +bool mwmp::PlayerPacketController::ContainsPacket(RakNet::MessageID id) +{ + BOOST_FOREACH(packets_t::value_type &packet, packets) { + if (packet.first == id) + return true; + } + return false; +} diff --git a/components/openmw-mp/Controllers/PlayerPacketController.hpp b/components/openmw-mp/Controllers/PlayerPacketController.hpp index 1938edb50..fc2927c65 100644 --- a/components/openmw-mp/Controllers/PlayerPacketController.hpp +++ b/components/openmw-mp/Controllers/PlayerPacketController.hpp @@ -16,6 +16,8 @@ namespace mwmp PlayerPacket *GetPacket(RakNet::MessageID id); void SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream); + bool ContainsPacket(RakNet::MessageID id); + typedef std::map > packets_t; private: packets_t packets; diff --git a/components/openmw-mp/Controllers/WorldPacketController.cpp b/components/openmw-mp/Controllers/WorldPacketController.cpp index 3a077892e..b3295ceb8 100644 --- a/components/openmw-mp/Controllers/WorldPacketController.cpp +++ b/components/openmw-mp/Controllers/WorldPacketController.cpp @@ -29,4 +29,13 @@ void mwmp::WorldPacketController::SetStream(RakNet::BitStream *inStream, RakNet: { BOOST_FOREACH( packets_t::value_type &packet, packets ) packet.second->SetStreams(inStream, outStream); -} \ No newline at end of file +} + +bool mwmp::WorldPacketController::ContainsPacket(RakNet::MessageID id) +{ + BOOST_FOREACH(packets_t::value_type &packet, packets) { + if (packet.first == id) + return true; + } + return false; +} diff --git a/components/openmw-mp/Controllers/WorldPacketController.hpp b/components/openmw-mp/Controllers/WorldPacketController.hpp index 8831a2e66..d96a8c886 100644 --- a/components/openmw-mp/Controllers/WorldPacketController.hpp +++ b/components/openmw-mp/Controllers/WorldPacketController.hpp @@ -16,6 +16,8 @@ namespace mwmp WorldPacket *GetPacket(RakNet::MessageID id); void SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream); + bool ContainsPacket(RakNet::MessageID id); + typedef std::map > packets_t; private: packets_t packets; From 2602c1f71ac5c650a2e1c33489f149474973430e Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 19 Oct 2016 21:26:42 +0300 Subject: [PATCH 10/34] Add ProcessPlayerPacket method to server's Networking --- apps/openmw-mp/Networking.cpp | 396 ++++++++++++++++++---------------- apps/openmw-mp/Networking.hpp | 3 + 2 files changed, 208 insertions(+), 191 deletions(-) diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index dfb2e8ab1..ef17a3743 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -48,29 +48,10 @@ Networking::~Networking() LOG_QUIT(); } -void Networking::Update(RakNet::Packet *packet) +void Networking::ProcessPlayerPacket(RakNet::Packet *packet) { Player *player = Players::GetPlayer(packet->guid); - RakNet::BitStream bsIn(&packet->data[1], packet->length, false); - - { - RakNet::RakNetGUID ignoredGUID; - bsIn.Read(ignoredGUID); - (void)ignoredGUID; - } - - playerController->SetStream(&bsIn, 0); - - if (player == 0) - { - playerController->GetPacket(ID_HANDSHAKE)->RequestData(packet->guid); - Players::NewPlayer(packet->guid); - player = Players::GetPlayer(packet->guid); - playerController->GetPacket(ID_USER_MYID)->Send(Players::GetPlayer(packet->guid), false); - return; - } - PlayerPacket *myPacket = playerController->GetPacket(packet->data[0]); if (packet->data[0] == ID_HANDSHAKE) @@ -127,7 +108,7 @@ void Networking::Update(RakNet::Packet *packet) else if (packet->data[0] == ID_GAME_BASE_INFO) { LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_GAME_BASE_INFO about %s", - player->Npc()->mName.c_str()); + player->Npc()->mName.c_str()); myPacket->Read(player); myPacket->Send(player, true); @@ -146,236 +127,269 @@ void Networking::Update(RakNet::Packet *packet) { /*case ID_GAME_BASE_INFO: { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_GAME_BASE_INFO about %s", - player->Npc()->mName.c_str()); + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_GAME_BASE_INFO about %s", + player->Npc()->mName.c_str()); - myPacket->Read(player); - myPacket->Send(player, true); + myPacket->Read(player); + myPacket->Send(player, true); - break; + break; }*/ - case ID_GAME_POS: - { - //DEBUG_PRINTF("ID_GAME_POS \n"); - - if (!player->CreatureStats()->mDead) - { - myPacket->Read(player); - myPacket->Send(player, true); //send to other clients - } + case ID_GAME_POS: + { + //DEBUG_PRINTF("ID_GAME_POS \n"); - break; - } - case ID_GAME_CELL: + if (!player->CreatureStats()->mDead) { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_GAME_CELL from %s", - player->Npc()->mName.c_str()); + myPacket->Read(player); + myPacket->Send(player, true); //send to other clients + } - if (!player->CreatureStats()->mDead) - { - myPacket->Read(player); + break; + } + case ID_GAME_CELL: + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_GAME_CELL from %s", + player->Npc()->mName.c_str()); - LOG_APPEND(Log::LOG_INFO, "- Moved to %s", - player->GetCell()->getDescription().c_str()); + if (!player->CreatureStats()->mDead) + { + myPacket->Read(player); - myPacket->Send(player, true); //send to other clients - Script::Call(player->GetID()); - } - else - { - LOG_APPEND(Log::LOG_INFO, "- Ignored because %s is dead", - player->Npc()->mName.c_str()); - } + LOG_APPEND(Log::LOG_INFO, "- Moved to %s", + player->GetCell()->getDescription().c_str()); - break; + myPacket->Send(player, true); //send to other clients + Script::Call(player->GetID()); } - case ID_GAME_ATTRIBUTE: + else { + LOG_APPEND(Log::LOG_INFO, "- Ignored because %s is dead", + player->Npc()->mName.c_str()); + } - if (!player->CreatureStats()->mDead) - { - myPacket->Read(player); - myPacket->Send(player, true); - - Script::Call(player->GetID()); - } + break; + } + case ID_GAME_ATTRIBUTE: + { - break; - } - case ID_GAME_SKILL: + if (!player->CreatureStats()->mDead) { + myPacket->Read(player); + myPacket->Send(player, true); - if (!player->CreatureStats()->mDead) - { - myPacket->Read(player); - myPacket->Send(player, true); + Script::Call(player->GetID()); + } - Script::Call(player->GetID()); - } + break; + } + case ID_GAME_SKILL: + { - break; - } - case ID_GAME_LEVEL: + if (!player->CreatureStats()->mDead) { + myPacket->Read(player); + myPacket->Send(player, true); - if (!player->CreatureStats()->mDead) - { - myPacket->Read(player); - myPacket->Send(player, true); + Script::Call(player->GetID()); + } - Script::Call(player->GetID()); - } + break; + } + case ID_GAME_LEVEL: + { - break; - } - case ID_GAME_EQUIPMENT: + if (!player->CreatureStats()->mDead) { - DEBUG_PRINTF("ID_GAME_EQUIPMENT\n"); - myPacket->Read(player); myPacket->Send(player, true); - Script::Call(player->GetID()); - - break; + Script::Call(player->GetID()); } - case ID_GAME_ATTACK: - { - DEBUG_PRINTF("ID_GAME_ATTACK\n"); + break; + } + case ID_GAME_EQUIPMENT: + { + DEBUG_PRINTF("ID_GAME_EQUIPMENT\n"); - if (!player->CreatureStats()->mDead) - { - myPacket->Read(player); + myPacket->Read(player); + myPacket->Send(player, true); - Player *target = Players::GetPlayer(player->GetAttack()->target); + Script::Call(player->GetID()); - if (target == nullptr) - target = player; + break; + } + + case ID_GAME_ATTACK: + { + DEBUG_PRINTF("ID_GAME_ATTACK\n"); + + if (!player->CreatureStats()->mDead) + { + myPacket->Read(player); - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Player: %s attaked %s state: %d", player->Npc()->mName.c_str(), - target->Npc()->mName.c_str(), player->GetAttack()->pressed == 1); - if (player->GetAttack()->pressed == 0) + Player *target = Players::GetPlayer(player->GetAttack()->target); + + if (target == nullptr) + target = player; + + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Player: %s attaked %s state: %d", player->Npc()->mName.c_str(), + target->Npc()->mName.c_str(), player->GetAttack()->pressed == 1); + if (player->GetAttack()->pressed == 0) + { + LOG_APPEND(Log::LOG_VERBOSE, "success: %d", player->GetAttack()->success == 1); + if (player->GetAttack()->success == 1) { - LOG_APPEND(Log::LOG_VERBOSE, "success: %d", player->GetAttack()->success == 1); - if (player->GetAttack()->success == 1) - { - LOG_APPEND(Log::LOG_VERBOSE, "damage: %d", player->GetAttack()->damage == 1); - player->setLastAttackerID(target->GetID()); - } + LOG_APPEND(Log::LOG_VERBOSE, "damage: %d", player->GetAttack()->damage == 1); + player->setLastAttackerID(target->GetID()); } - - myPacket->Send(player, true); - playerController->GetPacket(ID_GAME_DYNAMICSTATS)->RequestData(player->GetAttack()->target); } - break; - } - case ID_GAME_DYNAMICSTATS: - { - DEBUG_PRINTF("ID_GAME_DYNAMICSTATS\n"); - myPacket->Read(player); myPacket->Send(player, true); - break; + playerController->GetPacket(ID_GAME_DYNAMICSTATS)->RequestData(player->GetAttack()->target); } + break; + } - case ID_GAME_DIE: - { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_GAME_DIE from %s", - player->Npc()->mName.c_str()); + case ID_GAME_DYNAMICSTATS: + { + DEBUG_PRINTF("ID_GAME_DYNAMICSTATS\n"); + myPacket->Read(player); + myPacket->Send(player, true); + break; + } - Player *killer = Players::GetPlayer(player->getLastAttackerID()); + case ID_GAME_DIE: + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_GAME_DIE from %s", + player->Npc()->mName.c_str()); - short reason = 0; // unknown; + Player *killer = Players::GetPlayer(player->getLastAttackerID()); - if (!killer) - killer = player; - else if (killer->GetID() == player->GetID()) - reason = 2; //suicide - else - reason = 1; //killed + short reason = 0; // unknown; - player->resetLastAttacker(); + if (!killer) + killer = player; + else if (killer->GetID() == player->GetID()) + reason = 2; //suicide + else + reason = 1; //killed - player->CreatureStats()->mDead = true; - myPacket->Send(player, true); + player->resetLastAttacker(); - Script::Call(player->GetID(), reason, killer->GetID()); + player->CreatureStats()->mDead = true; + myPacket->Send(player, true); - break; - } + Script::Call(player->GetID(), reason, killer->GetID()); - case ID_GAME_RESURRECT: - { - DEBUG_PRINTF("ID_GAME_RESURRECT\n"); - //packetResurrect.Read(player); - player->CreatureStats()->mDead = false; - myPacket->Send(player, true); - playerController->GetPacket(ID_GAME_POS)->RequestData(player->guid); - playerController->GetPacket(ID_GAME_CELL)->RequestData(player->guid); + break; + } - Script::Call(player->GetID()); + case ID_GAME_RESURRECT: + { + DEBUG_PRINTF("ID_GAME_RESURRECT\n"); + //packetResurrect.Read(player); + player->CreatureStats()->mDead = false; + myPacket->Send(player, true); + playerController->GetPacket(ID_GAME_POS)->RequestData(player->guid); + playerController->GetPacket(ID_GAME_CELL)->RequestData(player->guid); - break; - } + Script::Call(player->GetID()); - case ID_GAME_DRAWSTATE: + break; + } + + case ID_GAME_DRAWSTATE: + { + DEBUG_PRINTF("ID_GAME_DRAWSTATE\n"); + myPacket->Read(player); + myPacket->Send(player, true); + break; + } + + case ID_CHAT_MESSAGE: + { + DEBUG_PRINTF("ID_CHAT_MESSAGE\n"); + myPacket->Read(player); + Script::CallBackReturn result = true; + Script::Call(result, player->GetID(), player->ChatMessage()->c_str()); + + if (result) { - DEBUG_PRINTF("ID_GAME_DRAWSTATE\n"); - myPacket->Read(player); + *player->ChatMessage() = player->Npc()->mName + " (" + std::to_string(player->GetID()) + "): " + + *player->ChatMessage() + "\n"; + myPacket->Send(player, false); myPacket->Send(player, true); - break; } + break; + } + case ID_GAME_CHARGEN: + { + DEBUG_PRINTF("ID_GAME_CHARGEN\n"); + myPacket->Read(player); - case ID_CHAT_MESSAGE: + if (player->CharGenStage()->current == player->CharGenStage()->end && player->CharGenStage()->current != 0) { - DEBUG_PRINTF("ID_CHAT_MESSAGE\n"); - myPacket->Read(player); - Script::CallBackReturn result = true; - Script::Call(result, player->GetID(), player->ChatMessage()->c_str()); - - if (result) - { - *player->ChatMessage() = player->Npc()->mName + " (" + std::to_string(player->GetID()) + "): " - + *player->ChatMessage() + "\n"; - myPacket->Send(player, false); - myPacket->Send(player, true); - } - break; + Script::Call(player->GetID()); + cout << "RACE: " << player->Npc()->mRace << endl; } - case ID_GAME_CHARGEN: - { - DEBUG_PRINTF("ID_GAME_CHARGEN\n"); - myPacket->Read(player); + break; + } - if (player->CharGenStage()->current == player->CharGenStage()->end && player->CharGenStage()->current != 0) - { - Script::Call(player->GetID()); - cout << "RACE: " << player->Npc()->mRace << endl; - } - break; - } + case ID_GUI_MESSAGEBOX: + { + DEBUG_PRINTF("ID_GUI_MESSAGEBOX\n"); + myPacket->Read(player); - case ID_GUI_MESSAGEBOX: - { - DEBUG_PRINTF("ID_GUI_MESSAGEBOX\n"); - myPacket->Read(player); + Script::Call(player->GetID(), (int)player->guiMessageBox.id, + player->guiMessageBox.data.c_str()); + break; + } - Script::Call(player->GetID(), (int)player->guiMessageBox.id, - player->guiMessageBox.data.c_str()); - break; - } + case ID_GAME_CHARCLASS: + { + DEBUG_PRINTF("ID_GAME_CHARCLASS\n"); + myPacket->Read(player); + break; + } - case ID_GAME_CHARCLASS: - { - DEBUG_PRINTF("ID_GAME_CHARCLASS\n"); - myPacket->Read(player); - break; - } + default: + printf("Message with identifier %i has arrived.\n", packet->data[0]); + break; + } +} - default: - printf("Message with identifier %i has arrived.\n", packet->data[0]); - break; +void Networking::Update(RakNet::Packet *packet) +{ + Player *player = Players::GetPlayer(packet->guid); + + RakNet::BitStream bsIn(&packet->data[1], packet->length, false); + + { + RakNet::RakNetGUID ignoredGUID; + bsIn.Read(ignoredGUID); + (void)ignoredGUID; + } + + if (player == 0) + { + playerController->SetStream(&bsIn, 0); + + playerController->GetPacket(ID_HANDSHAKE)->RequestData(packet->guid); + Players::NewPlayer(packet->guid); + player = Players::GetPlayer(packet->guid); + playerController->GetPacket(ID_USER_MYID)->Send(Players::GetPlayer(packet->guid), false); + return; + } + else if (playerController->ContainsPacket(packet->data[0])) + { + playerController->SetStream(&bsIn, 0); + ProcessPlayerPacket(packet); + } + else if (worldController->ContainsPacket(packet->data[0])) + { + worldController->SetStream(&bsIn, 0); } } diff --git a/apps/openmw-mp/Networking.hpp b/apps/openmw-mp/Networking.hpp index 3d541c7f9..e6dfa0583 100644 --- a/apps/openmw-mp/Networking.hpp +++ b/apps/openmw-mp/Networking.hpp @@ -20,7 +20,10 @@ namespace mwmp void NewPlayer(RakNet::RakNetGUID guid); void DisconnectPlayer(RakNet::RakNetGUID guid); void KickPlayer(RakNet::RakNetGUID guid); + + void ProcessPlayerPacket(RakNet::Packet *packet); void Update(RakNet::Packet *packet); + unsigned short NumberOfConnections() const; unsigned int MaxConnections() const; From d0328f2553c9fa611c9640bbb512deba254690a7 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 19 Oct 2016 21:44:17 +0300 Subject: [PATCH 11/34] Add placeholder ProcessWorldPacket method to server's Networking --- apps/openmw-mp/Networking.cpp | 35 ++++++++++++++++++++++++++++++++++- apps/openmw-mp/Networking.hpp | 1 + 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index ef17a3743..fc765ffeb 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -355,11 +355,38 @@ void Networking::ProcessPlayerPacket(RakNet::Packet *packet) } default: - printf("Message with identifier %i has arrived.\n", packet->data[0]); + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Unhandled PlayerPacket with identifier %i has arrived", + packet->data[0]); break; } } +void Networking::ProcessWorldPacket(RakNet::Packet *packet) +{ + Player *player = Players::GetPlayer(packet->guid); + + if (!player->isHandshaked() || player->LoadedState() != Player::POSTLOADED) + return; + + switch (packet->data[0]) + { + + case ID_WORLD_OBJECT_REMOVAL: + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_WORLD_OBJECT_REMOVAL from %s", + player->Npc()->mName.c_str()); + + break; + } + + default: + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Unhandled WorldPacket with identifier %i has arrived", + packet->data[0]); + break; + } + +} + void Networking::Update(RakNet::Packet *packet) { Player *player = Players::GetPlayer(packet->guid); @@ -390,6 +417,12 @@ void Networking::Update(RakNet::Packet *packet) else if (worldController->ContainsPacket(packet->data[0])) { worldController->SetStream(&bsIn, 0); + ProcessWorldPacket(packet); + } + else + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Unhandled Raknet packet with identifier %i has arrived", + packet->data[0]); } } diff --git a/apps/openmw-mp/Networking.hpp b/apps/openmw-mp/Networking.hpp index e6dfa0583..afba73f49 100644 --- a/apps/openmw-mp/Networking.hpp +++ b/apps/openmw-mp/Networking.hpp @@ -22,6 +22,7 @@ namespace mwmp void KickPlayer(RakNet::RakNetGUID guid); void ProcessPlayerPacket(RakNet::Packet *packet); + void ProcessWorldPacket(RakNet::Packet *packet); void Update(RakNet::Packet *packet); unsigned short NumberOfConnections() const; From e27d1857efecf85ce44fb55c1fd481f17c091c18 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 19 Oct 2016 22:06:11 +0300 Subject: [PATCH 12/34] Fix formatting in previous changes made by tes3mp to OpenMW's core --- apps/openmw/mwclass/npc.cpp | 14 +++++++------- apps/openmw/mwmechanics/actors.cpp | 2 +- apps/openmw/mwmechanics/combat.cpp | 10 +++++----- apps/openmw/mwmechanics/spellcasting.cpp | 6 +++--- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index d8f5e57a0..97c193a57 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -551,7 +551,7 @@ namespace MWClass void Npc::hit(const MWWorld::Ptr& ptr, float attackStrength, int type) const { - if(mwmp::Main::get().getNetworking()->isDedicatedPlayer(ptr)) + if (mwmp::Main::get().getNetworking()->isDedicatedPlayer(ptr)) return; MWBase::World *world = MWBase::Environment::get().getWorld(); @@ -594,16 +594,16 @@ namespace MWClass float hitchance = MWMechanics::getHitChance(ptr, victim, ptr.getClass().getSkill(ptr, weapskill)); - if(ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) + if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) { mwmp::Main::get().getLocalPlayer()->GetAttack()->success = true; - if(mwmp::Main::get().getNetworking()->isDedicatedPlayer(victim)) + if (mwmp::Main::get().getNetworking()->isDedicatedPlayer(victim)) mwmp::Main::get().getLocalPlayer()->GetAttack()->target =mwmp::Players::GetPlayer(victim)->guid; } if(Misc::Rng::roll0to99() >= hitchance) { - if(ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) + if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) { mwmp::Main::get().getLocalPlayer()->GetAttack()->success = false; mwmp::Main::get().getLocalPlayer()->sendAttack(0); @@ -843,7 +843,7 @@ namespace MWClass } - if(attacker == MWMechanics::getPlayer() && mwmp::Main::get().getNetworking()->isDedicatedPlayer(ptr)) + if (attacker == MWMechanics::getPlayer() && mwmp::Main::get().getNetworking()->isDedicatedPlayer(ptr)) { mwmp::Attack *_atk = mwmp::Main::get().getLocalPlayer()->GetAttack(); _atk->damage = damage; @@ -853,7 +853,7 @@ namespace MWClass mwmp::Main::get().getLocalPlayer()->sendAttack(0); // todo: make this sensitive to different weapon types } - if(ptr == MWMechanics::getPlayer()) + if (ptr == MWMechanics::getPlayer()) { mwmp::Main::get().getLocalPlayer()->updateDynamicStats(true); mwmp::Main::get().getLocalPlayer()->updatePosition(true); // fix position after getting damage; @@ -863,7 +863,7 @@ namespace MWClass boost::shared_ptr Npc::activate (const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const { - if(actor == MWMechanics::getPlayer() && mwmp::Main::get().getNetworking()->isDedicatedPlayer(ptr)) + if (actor == MWMechanics::getPlayer() && mwmp::Main::get().getNetworking()->isDedicatedPlayer(ptr)) return boost::shared_ptr(new MWWorld::FailedAction("Not implemented.")); // player got activated by another NPC if(ptr == MWMechanics::getPlayer()) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 5b6e762a0..5eb9adf87 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -1039,7 +1039,7 @@ namespace MWMechanics mwmp::Main::get().getLocalPlayer()->prepareAttack(2, state); } - if(mwmp::Main::get().getNetworking()->isDedicatedPlayer(iter->first)) + if (mwmp::Main::get().getNetworking()->isDedicatedPlayer(iter->first)) iter->second->getCharacterController()->setAttackingOrSpell(mwmp::Main::get().getNetworking()->Attack(iter->first)); diff --git a/apps/openmw/mwmechanics/combat.cpp b/apps/openmw/mwmechanics/combat.cpp index 9a3282f47..ddc4af4cb 100644 --- a/apps/openmw/mwmechanics/combat.cpp +++ b/apps/openmw/mwmechanics/combat.cpp @@ -117,13 +117,13 @@ namespace MWMechanics bool isDedicated = mwmp::Main::get().getNetworking()->isDedicatedPlayer(blocker); - if(attacker == MWMechanics::getPlayer()) + if (attacker == MWMechanics::getPlayer()) mwmp::Main::get().getLocalPlayer()->GetAttack()->block = false; - if((!isDedicated && Misc::Rng::roll0to99() < x) || + if ((!isDedicated && Misc::Rng::roll0to99() < x) || (isDedicated && mwmp::Players::GetPlayer(blocker)->GetAttack()->block == 1)) { - if(attacker == MWMechanics::getPlayer()) + if (attacker == MWMechanics::getPlayer()) mwmp::Main::get().getLocalPlayer()->GetAttack()->block = true; // Reduce shield durability by incoming damage @@ -180,7 +180,7 @@ namespace MWMechanics void projectileHit(const MWWorld::Ptr &attacker, const MWWorld::Ptr &victim, MWWorld::Ptr weapon, const MWWorld::Ptr &projectile, const osg::Vec3f& hitPosition, float attackStrength) { - if(mwmp::Main::get().getNetworking()->isDedicatedPlayer(attacker)) + if (mwmp::Main::get().getNetworking()->isDedicatedPlayer(attacker)) return; MWBase::World *world = MWBase::Environment::get().getWorld(); const MWWorld::Store &gmst = world->getStore().get(); @@ -202,7 +202,7 @@ namespace MWMechanics int skillValue = attacker.getClass().getSkill(attacker, weapon.getClass().getEquipmentSkill(weapon)); - if(attacker == MWBase::Environment::get().getWorld()->getPlayerPtr()) + if (attacker == MWBase::Environment::get().getWorld()->getPlayerPtr()) mwmp::Main::get().getLocalPlayer()->GetAttack()->success = true; if (Misc::Rng::roll0to99() >= getHitChance(attacker, victim, skillValue)) diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index 9aee1d00f..a5c4176eb 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -799,13 +799,13 @@ namespace MWMechanics bool isDedicated = mwmp::Main::get().getNetworking()->isDedicatedPlayer(mCaster); - if(mCaster == getPlayer()) + if (mCaster == getPlayer()) { mwmp::Main::get().getLocalPlayer()->GetAttack()->success = true; mwmp::Main::get().getLocalPlayer()->GetAttack()->pressed = true; } - if(isDedicated) + if (isDedicated) { mwmp::Players::GetPlayer(mCaster)->GetAttack()->pressed = false; } @@ -821,7 +821,7 @@ namespace MWMechanics fail = true; } - if(mCaster == getPlayer()) + if (mCaster == getPlayer()) { mwmp::Main::get().getLocalPlayer()->sendAttack(1); mwmp::Main::get().getLocalPlayer()->GetAttack()->pressed = false; From f218613231349387f839608f1169f6905bee0805 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 19 Oct 2016 22:49:35 +0300 Subject: [PATCH 13/34] Rename client Networking's GetPacket method into GetPlayerPacket --- apps/openmw/mwmp/GUIChat.cpp | 2 +- apps/openmw/mwmp/GUIController.cpp | 4 ++-- apps/openmw/mwmp/LocalPlayer.cpp | 36 +++++++++++++++--------------- apps/openmw/mwmp/Main.cpp | 4 ++-- apps/openmw/mwmp/Networking.cpp | 19 +++++++++++----- apps/openmw/mwmp/Networking.hpp | 8 +++++-- 6 files changed, 42 insertions(+), 31 deletions(-) diff --git a/apps/openmw/mwmp/GUIChat.cpp b/apps/openmw/mwmp/GUIChat.cpp index 1e83fd21d..fda7012a3 100644 --- a/apps/openmw/mwmp/GUIChat.cpp +++ b/apps/openmw/mwmp/GUIChat.cpp @@ -129,7 +129,7 @@ namespace mwmp *localPlayer->ChatMessage() = str; RakNet::BitStream bs; - networking->GetPacket(ID_CHAT_MESSAGE)->Packet(&bs, localPlayer, true); + networking->GetPlayerPacket(ID_CHAT_MESSAGE)->Packet(&bs, localPlayer, true); networking->SendData(&bs); } diff --git a/apps/openmw/mwmp/GUIController.cpp b/apps/openmw/mwmp/GUIController.cpp index 087f22d8d..dbc20aa89 100644 --- a/apps/openmw/mwmp/GUIController.cpp +++ b/apps/openmw/mwmp/GUIController.cpp @@ -109,7 +109,7 @@ void mwmp::GUIController::OnInputBoxDone(MWGui::WindowBase *parWindow) printf("GUIController::OnInputBoxDone: %s.\n",mInputBox->getTextInput().c_str()); Main::get().getLocalPlayer()->guiMessageBox.data = mInputBox->getTextInput(); - Main::get().getNetworking()->GetPacket(ID_GUI_MESSAGEBOX)->Send(Main::get().getLocalPlayer()); + Main::get().getNetworking()->GetPlayerPacket(ID_GUI_MESSAGEBOX)->Send(Main::get().getLocalPlayer()); MWBase::Environment::get().getWindowManager()->removeDialog(mInputBox); mInputBox = 0; @@ -155,7 +155,7 @@ void mwmp::GUIController::update(float dt) printf("Pressed: %d\n", pressedButton); calledMessageBox = false; Main::get().getLocalPlayer()->guiMessageBox.data = MyGUI::utility::toString(pressedButton); - Main::get().getNetworking()->GetPacket(ID_GUI_MESSAGEBOX)->Send(Main::get().getLocalPlayer()); + Main::get().getNetworking()->GetPlayerPacket(ID_GUI_MESSAGEBOX)->Send(Main::get().getLocalPlayer()); } } diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index ccb0b74d7..5fe974e42 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -89,7 +89,7 @@ bool LocalPlayer::charGenThread() // todo: need fix (*BirthSign()) = world->getPlayer().getBirthSign(); LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Sending ID_GAME_BASE_INFO to server with my CharGen info"); - GetNetworking()->GetPacket(ID_GAME_BASE_INFO)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_BASE_INFO)->Send(this); if (CharGenStage()->end != 1) { @@ -98,11 +98,11 @@ bool LocalPlayer::charGenThread() // todo: need fix updateSkills(true); updateLevel(true); sendClass(); - GetNetworking()->GetPacket(ID_GAME_CHARGEN)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_CHARGEN)->Send(this); } CharGenStage()->end = 0; /*RakNet::BitStream bs; - GetNetworking()->GetPacket(ID_GAME_BASE_INFO)->Packet(&bs, this, true); + GetNetworking()->GetPlayerPacket(ID_GAME_BASE_INFO)->Packet(&bs, this, true); GetNetworking()->SendData(&bs);*/ } @@ -127,7 +127,7 @@ bool LocalPlayer::charGenThread() // todo: need fix windowManager->pushGuiMode(MWGui::GM_Review); break; } - GetNetworking()->GetPacket(ID_GAME_CHARGEN)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_CHARGEN)->Send(this); CharGenStage()->current++; return false; @@ -162,7 +162,7 @@ void LocalPlayer::updateDynamicStats(bool forceUpdate) timer = 0; - GetNetworking()->GetPacket(ID_GAME_DYNAMICSTATS)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_DYNAMICSTATS)->Send(this); } } } @@ -184,7 +184,7 @@ void LocalPlayer::updateAttributes(bool forceUpdate) if (isUpdating || forceUpdate) { - GetNetworking()->GetPacket(ID_GAME_ATTRIBUTE)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_ATTRIBUTE)->Send(this); } } @@ -220,7 +220,7 @@ void LocalPlayer::updateSkills(bool forceUpdate) if (isUpdating || forceUpdate) { NpcStats()->mLevelProgress = ptrNpcStats.getLevelProgress(); - GetNetworking()->GetPacket(ID_GAME_SKILL)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_SKILL)->Send(this); } } @@ -232,7 +232,7 @@ void LocalPlayer::updateLevel(bool forceUpdate) if (ptrNpcStats.getLevel() != CreatureStats()->mLevel || forceUpdate) { CreatureStats()->mLevel = ptrNpcStats.getLevel(); - GetNetworking()->GetPacket(ID_GAME_LEVEL)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_LEVEL)->Send(this); // Also update skills to refresh level progress and attribute bonuses // for next level up @@ -272,7 +272,7 @@ void LocalPlayer::updatePosition(bool forceUpdate) Dir()->pos[1] = move.mPosition[1]; Dir()->pos[2] = move.mPosition[2]; - GetNetworking()->GetPacket(ID_GAME_POS)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_POS)->Send(this); } else if (isJumping && world->isOnGround(player)) { @@ -284,7 +284,7 @@ void LocalPlayer::updatePosition(bool forceUpdate) { sentJumpEnd = true; (*Position()) = ptrPos; - GetNetworking()->GetPacket(ID_GAME_POS)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_POS)->Send(this); } } @@ -333,7 +333,7 @@ void LocalPlayer::updateCell(bool forceUpdate) updatePosition(true); RakNet::BitStream bs; - GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_CELL)->Packet(&bs, this, true); + GetNetworking()->GetPlayerPacket((RakNet::MessageID) ID_GAME_CELL)->Packet(&bs, this, true); GetNetworking()->SendData(&bs); // Also update skill progress @@ -396,7 +396,7 @@ void LocalPlayer::updateInventory(bool forceUpdate) { RakNet::BitStream bs; bs.ResetWritePointer(); - GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_EQUIPMENT)->Packet(&bs, this, true); + GetNetworking()->GetPlayerPacket((RakNet::MessageID) ID_GAME_EQUIPMENT)->Packet(&bs, this, true); GetNetworking()->SendData(&bs); invChanged = false; } @@ -426,7 +426,7 @@ void LocalPlayer::updateAttackState(bool forceUpdate) GetAttack()->refid = spell; /*RakNet::BitStream bs; - GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_ATTACK)->Packet(&bs, this, true); + GetNetworking()->GetPlayerPacket((RakNet::MessageID) ID_GAME_ATTACK)->Packet(&bs, this, true); GetNetworking()->SendData(&bs);*/ } else if (state == MWMechanics::DrawState_Weapon) @@ -457,7 +457,7 @@ void LocalPlayer::updateDeadState(bool forceUpdate) { CreatureStats()->mDead = true; RakNet::BitStream bs; - GetNetworking()->GetPacket((RakNet::MessageID)ID_GAME_DIE)->Packet(&bs, this, true); + GetNetworking()->GetPlayerPacket((RakNet::MessageID)ID_GAME_DIE)->Packet(&bs, this, true); GetNetworking()->SendData(&bs); isDead = true; } @@ -524,7 +524,7 @@ void LocalPlayer::updateDrawStateAndFlags(bool forceUpdate) mwmp::Main::get().getLocalPlayer()->updatePosition(true); // fix position after jump; RakNet::BitStream bs; - GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_DRAWSTATE)->Packet(&bs, this, true); + GetNetworking()->GetPlayerPacket((RakNet::MessageID) ID_GAME_DRAWSTATE)->Packet(&bs, this, true); GetNetworking()->SendData(&bs); //timer = 0; } @@ -695,7 +695,7 @@ void LocalPlayer::sendClass() else charClass.mId = cls->mId; - GetNetworking()->GetPacket(ID_GAME_CHARCLASS)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_CHARCLASS)->Send(this); } void LocalPlayer::sendAttack(char type) @@ -713,7 +713,7 @@ void LocalPlayer::sendAttack(char type) GetAttack()->type = type; GetAttack()->pressed = false; RakNet::BitStream bs; - GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_ATTACK)->Packet(&bs, this, true); + GetNetworking()->GetPlayerPacket((RakNet::MessageID) ID_GAME_ATTACK)->Packet(&bs, this, true); GetNetworking()->SendData(&bs); } @@ -744,6 +744,6 @@ void LocalPlayer::prepareAttack(char type, bool state) GetAttack()->attacker = guid; RakNet::BitStream bs; - GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_ATTACK)->Packet(&bs, this, true); + GetNetworking()->GetPlayerPacket((RakNet::MessageID) ID_GAME_ATTACK)->Packet(&bs, this, true); GetNetworking()->SendData(&bs); } diff --git a/apps/openmw/mwmp/Main.cpp b/apps/openmw/mwmp/Main.cpp index 20c11cb33..8c3ab61fe 100644 --- a/apps/openmw/mwmp/Main.cpp +++ b/apps/openmw/mwmp/Main.cpp @@ -189,8 +189,8 @@ void Main::UpdateWorld(float dt) const init = false; LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Sending ID_GAME_BASE_INFO to server"); - mNetworking->GetPacket(ID_GAME_BASE_INFO)->Send(getLocalPlayer()); - mNetworking->GetPacket(ID_LOADED)->Send(getLocalPlayer()); + mNetworking->GetPlayerPacket(ID_GAME_BASE_INFO)->Send(getLocalPlayer()); + mNetworking->GetPlayerPacket(ID_LOADED)->Send(getLocalPlayer()); mLocalPlayer->updateDynamicStats(true); get().getGUIController()->setChatVisible(true); } diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index d14945545..46e9ab7c0 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -24,7 +24,7 @@ using namespace std; using namespace mwmp; -Networking::Networking(): peer(RakNet::RakPeerInterface::GetInstance()), controller(peer) +Networking::Networking(): peer(RakNet::RakPeerInterface::GetInstance()), playerController(peer), worldController(peer) { RakNet::SocketDescriptor sd; @@ -32,7 +32,9 @@ Networking::Networking(): peer(RakNet::RakPeerInterface::GetInstance()), control RakNet::StartupResult b = peer->Startup(1,&sd, 1); RakAssert(b==RAKNET_STARTED); - controller.SetStream(0, &bsOut); + playerController.SetStream(0, &bsOut); + worldController.SetStream(0, &bsOut); + connected = 0; } @@ -178,7 +180,7 @@ void Networking::ReceiveMessage(RakNet::Packet *packet) if (id != myid) pl = Players::GetPlayer(id); - PlayerPacket *myPacket = controller.GetPacket(packet->data[0]); + PlayerPacket *myPacket = playerController.GetPacket(packet->data[0]); switch (packet->data[0]) { @@ -409,7 +411,7 @@ void Networking::ReceiveMessage(RakNet::Packet *packet) myPacket->Send(getLocalPlayer(), serverAddr); getLocalPlayer()->updateDynamicStats(true); - controller.GetPacket(ID_GAME_DYNAMICSTATS)->Send(getLocalPlayer(), serverAddr); + playerController.GetPacket(ID_GAME_DYNAMICSTATS)->Send(getLocalPlayer(), serverAddr); } else if (pl != 0) { @@ -618,9 +620,14 @@ void Networking::ReceiveMessage(RakNet::Packet *packet) } } -PlayerPacket *Networking::GetPacket(RakNet::MessageID id) +PlayerPacket *Networking::GetPlayerPacket(RakNet::MessageID id) +{ + return playerController.GetPacket(id); +} + +WorldPacket *Networking::GetWorldPacket(RakNet::MessageID id) { - return controller.GetPacket(id); + return worldController.GetPacket(id); } LocalPlayer *Networking::getLocalPlayer() diff --git a/apps/openmw/mwmp/Networking.hpp b/apps/openmw/mwmp/Networking.hpp index f9b06794c..fff9703b2 100644 --- a/apps/openmw/mwmp/Networking.hpp +++ b/apps/openmw/mwmp/Networking.hpp @@ -20,6 +20,7 @@ #include #include #include +#include namespace mwmp { @@ -33,7 +34,9 @@ namespace mwmp void Connect(const std::string& ip, unsigned short port); void Update(); void SendData(RakNet::BitStream *bitStream); - PlayerPacket *GetPacket(RakNet::MessageID id); + + PlayerPacket *GetPlayerPacket(RakNet::MessageID id); + WorldPacket *GetWorldPacket(RakNet::MessageID id); bool isDedicatedPlayer(const MWWorld::Ptr &ptr); bool Attack(const MWWorld::Ptr &ptr); @@ -51,7 +54,8 @@ namespace mwmp RakNet::SystemAddress serverAddr; RakNet::BitStream bsOut; - PlayerPacketController controller; + PlayerPacketController playerController; + WorldPacketController worldController; void ReceiveMessage(RakNet::Packet *packet); LocalPlayer *getLocalPlayer(); From a42d5f2429d4614f1054fe2ebb53cd58b6fdaebf Mon Sep 17 00:00:00 2001 From: David Cernat Date: Thu, 20 Oct 2016 12:53:48 +0300 Subject: [PATCH 14/34] Make client send placeholder ID_WORLD_OBJECT_REMOVAL to server --- apps/openmw/mwworld/worldimp.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 96422fe9e..267e88dfc 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -17,6 +17,8 @@ #include +#include "../mwmp/Main.hpp" + #include "../mwbase/environment.hpp" #include "../mwbase/soundmanager.hpp" #include "../mwbase/mechanicsmanager.hpp" @@ -1103,6 +1105,8 @@ namespace MWWorld && mWorldScene->getActiveCells().find(ptr.getCell()) != mWorldScene->getActiveCells().end() && ptr.getRefData().isEnabled()) { + mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_REMOVAL)->Send(mwmp::Main::get().getLocalPlayer()); + mWorldScene->removeObjectFromScene (ptr); mLocalScripts.remove (ptr); removeContainerScripts (ptr); From b2845cd17ccb0c06e3eb2e6d1f023a356741473f Mon Sep 17 00:00:00 2001 From: David Cernat Date: Thu, 20 Oct 2016 14:28:19 +0300 Subject: [PATCH 15/34] Create and start using WorldEvent class --- apps/openmw/mwmp/Networking.cpp | 6 +++++ apps/openmw/mwmp/Networking.hpp | 2 ++ apps/openmw/mwworld/worldimp.cpp | 4 ++- components/openmw-mp/Base/WorldEvent.hpp | 26 +++++++++++++++++++ .../openmw-mp/Packets/Player/PlayerPacket.hpp | 2 +- .../Packets/World/PacketObjectRemoval.cpp | 4 +-- .../Packets/World/PacketObjectRemoval.hpp | 2 +- .../openmw-mp/Packets/World/WorldPacket.cpp | 20 +++++++------- .../openmw-mp/Packets/World/WorldPacket.hpp | 14 +++++----- 9 files changed, 58 insertions(+), 22 deletions(-) create mode 100644 components/openmw-mp/Base/WorldEvent.hpp diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 46e9ab7c0..1fbcc8f14 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -18,6 +18,7 @@ #include "../mwstate/statemanagerimp.hpp" #include #include +#include #include "DedicatedPlayer.hpp" #include "Main.hpp" @@ -635,6 +636,11 @@ LocalPlayer *Networking::getLocalPlayer() return mwmp::Main::get().getLocalPlayer(); } +WorldEvent *Networking::createWorldEvent() +{ + return new WorldEvent(getLocalPlayer()->guid); +} + bool Networking::isDedicatedPlayer(const MWWorld::Ptr &ptr) { if (ptr.mRef == 0) diff --git a/apps/openmw/mwmp/Networking.hpp b/apps/openmw/mwmp/Networking.hpp index fff9703b2..9acfaf96c 100644 --- a/apps/openmw/mwmp/Networking.hpp +++ b/apps/openmw/mwmp/Networking.hpp @@ -48,6 +48,8 @@ namespace mwmp bool isConnected(); + WorldEvent *createWorldEvent(); + private: bool connected; RakNet::RakPeerInterface *peer; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 267e88dfc..872471ebb 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -17,6 +17,7 @@ #include +#include #include "../mwmp/Main.hpp" #include "../mwbase/environment.hpp" @@ -1105,7 +1106,8 @@ namespace MWWorld && mWorldScene->getActiveCells().find(ptr.getCell()) != mWorldScene->getActiveCells().end() && ptr.getRefData().isEnabled()) { - mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_REMOVAL)->Send(mwmp::Main::get().getLocalPlayer()); + mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); + mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_REMOVAL)->Send(event); mWorldScene->removeObjectFromScene (ptr); mLocalScripts.remove (ptr); diff --git a/components/openmw-mp/Base/WorldEvent.hpp b/components/openmw-mp/Base/WorldEvent.hpp new file mode 100644 index 000000000..e70427b4c --- /dev/null +++ b/components/openmw-mp/Base/WorldEvent.hpp @@ -0,0 +1,26 @@ +#ifndef OPENMW_WORLDEVENT_HPP +#define OPENMW_WORLDEVENT_HPP + +#include + +namespace mwmp +{ + class WorldEvent + { + public: + + WorldEvent(RakNet::RakNetGUID guid) : guid(guid) + { + + } + + WorldEvent() + { + + } + + RakNet::RakNetGUID guid; + }; +} + +#endif //OPENMW_WORLDEVENT_HPP diff --git a/components/openmw-mp/Packets/Player/PlayerPacket.hpp b/components/openmw-mp/Packets/Player/PlayerPacket.hpp index 54c085db9..8d4953183 100644 --- a/components/openmw-mp/Packets/Player/PlayerPacket.hpp +++ b/components/openmw-mp/Packets/Player/PlayerPacket.hpp @@ -25,7 +25,7 @@ namespace mwmp virtual void Send(BasePlayer *player, RakNet::AddressOrGUID destination); virtual void Read(BasePlayer *player); - virtual void RequestData(RakNet::RakNetGUID player); + virtual void RequestData(RakNet::RakNetGUID guid); static size_t headerSize() { diff --git a/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp b/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp index a13dc548b..2c4e02297 100644 --- a/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp @@ -8,7 +8,7 @@ PacketObjectRemoval::PacketObjectRemoval(RakNet::RakPeerInterface *peer) : World packetID = ID_WORLD_OBJECT_REMOVAL; } -void PacketObjectRemoval::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send) +void PacketObjectRemoval::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) { - WorldPacket::Packet(bs, player, send); + WorldPacket::Packet(bs, event, send); } diff --git a/components/openmw-mp/Packets/World/PacketObjectRemoval.hpp b/components/openmw-mp/Packets/World/PacketObjectRemoval.hpp index 2469dee37..1046ad0e0 100644 --- a/components/openmw-mp/Packets/World/PacketObjectRemoval.hpp +++ b/components/openmw-mp/Packets/World/PacketObjectRemoval.hpp @@ -10,7 +10,7 @@ namespace mwmp public: PacketObjectRemoval(RakNet::RakPeerInterface *peer); - virtual void Packet(RakNet::BitStream *bs, BasePlayer *player, bool send); + virtual void Packet(RakNet::BitStream *bs, WorldEvent *event, bool send); }; } diff --git a/components/openmw-mp/Packets/World/WorldPacket.cpp b/components/openmw-mp/Packets/World/WorldPacket.cpp index 7bc634d83..543c6c5d6 100644 --- a/components/openmw-mp/Packets/World/WorldPacket.cpp +++ b/components/openmw-mp/Packets/World/WorldPacket.cpp @@ -5,15 +5,15 @@ using namespace mwmp; -void WorldPacket::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send) +void WorldPacket::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) { - this->player = player; + this->event = event; this->bs = bs; if (send) { bs->Write(packetID); - bs->Write(player->guid); + bs->Write(event->guid); } } @@ -30,23 +30,23 @@ WorldPacket::~WorldPacket() } -void WorldPacket::Send(BasePlayer *player, RakNet::AddressOrGUID destination) +void WorldPacket::Send(WorldEvent *event, RakNet::AddressOrGUID destination) { bsSend->ResetWritePointer(); - Packet(bsSend, player, true); + Packet(bsSend, event, true); peer->Send(bsSend, priority, reliability, 0, destination, false); } -void WorldPacket::Send(BasePlayer *player, bool toOther) +void WorldPacket::Send(WorldEvent *event, bool toOther) { bsSend->ResetWritePointer(); - Packet(bsSend, player, true); - peer->Send(bsSend, priority, reliability, 0, player->guid, toOther); + Packet(bsSend, event, true); + peer->Send(bsSend, priority, reliability, 0, event->guid, toOther); } -void WorldPacket::Read(BasePlayer *player) +void WorldPacket::Read(WorldEvent *event) { - Packet(bsRead, player, false); + Packet(bsRead, event, false); } void WorldPacket::RequestData(RakNet::RakNetGUID guid) diff --git a/components/openmw-mp/Packets/World/WorldPacket.hpp b/components/openmw-mp/Packets/World/WorldPacket.hpp index 9dc0fe8f8..8ad187870 100644 --- a/components/openmw-mp/Packets/World/WorldPacket.hpp +++ b/components/openmw-mp/Packets/World/WorldPacket.hpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include @@ -19,13 +19,13 @@ namespace mwmp ~WorldPacket(); - virtual void Packet(RakNet::BitStream *bs, BasePlayer *player, bool send); + virtual void Packet(RakNet::BitStream *bs, WorldEvent *event, bool send); - virtual void Send(BasePlayer *player, bool toOtherPlayers = true); - virtual void Send(BasePlayer *player, RakNet::AddressOrGUID destination); - virtual void Read(BasePlayer *player); + virtual void Send(WorldEvent *event, bool toOtherPlayers = true); + virtual void Send(WorldEvent *event, RakNet::AddressOrGUID destination); + virtual void Read(WorldEvent *event); - virtual void RequestData(RakNet::RakNetGUID player); + virtual void RequestData(RakNet::RakNetGUID guid); static size_t headerSize() { @@ -38,7 +38,7 @@ namespace mwmp } protected: - BasePlayer *player; + WorldEvent *event; }; } From ac666edebd658ed25dfa6abd1611402e70f1f6fe Mon Sep 17 00:00:00 2001 From: David Cernat Date: Thu, 20 Oct 2016 22:15:47 +0300 Subject: [PATCH 16/34] Add a CellRef to WorldEvent --- apps/openmw-mp/Networking.cpp | 6 ++++++ apps/openmw/mwworld/livecellref.hpp | 2 +- apps/openmw/mwworld/worldimp.cpp | 3 +++ components/openmw-mp/Base/WorldEvent.hpp | 11 +++++++++++ .../openmw-mp/Packets/World/PacketObjectRemoval.cpp | 2 ++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index fc765ffeb..aa7937fba 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -368,6 +368,9 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) if (!player->isHandshaked() || player->LoadedState() != Player::POSTLOADED) return; + WorldPacket *myPacket = worldController->GetPacket(packet->data[0]); + WorldEvent *event = new WorldEvent(player->guid); + switch (packet->data[0]) { @@ -375,6 +378,9 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) { LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_WORLD_OBJECT_REMOVAL from %s", player->Npc()->mName.c_str()); + + myPacket->Read(event); + myPacket->Send(event, true); break; } diff --git a/apps/openmw/mwworld/livecellref.hpp b/apps/openmw/mwworld/livecellref.hpp index f42e1611a..91495eed2 100644 --- a/apps/openmw/mwworld/livecellref.hpp +++ b/apps/openmw/mwworld/livecellref.hpp @@ -28,7 +28,7 @@ namespace MWWorld */ MWWorld::CellRef mRef; - /* Added by TES3MP to prevent dedicated players' references from automatically + /* Added by tes3mp to prevent dedicated players' references from automatically * and unpredictably moving across exterior cell boundaries on clients */ bool canChangeCell; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 872471ebb..d7fd3281f 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1106,7 +1106,10 @@ namespace MWWorld && mWorldScene->getActiveCells().find(ptr.getCell()) != mWorldScene->getActiveCells().end() && ptr.getRefData().isEnabled()) { + // Added by tes3mp mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); + event->CellRef()->mRefID = ptr.getCellRef().getRefId(); + event->CellRef()->mRefNum = ptr.getCellRef().getRefNum(); mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_REMOVAL)->Send(event); mWorldScene->removeObjectFromScene (ptr); diff --git a/components/openmw-mp/Base/WorldEvent.hpp b/components/openmw-mp/Base/WorldEvent.hpp index e70427b4c..e384bbe10 100644 --- a/components/openmw-mp/Base/WorldEvent.hpp +++ b/components/openmw-mp/Base/WorldEvent.hpp @@ -1,6 +1,7 @@ #ifndef OPENMW_WORLDEVENT_HPP #define OPENMW_WORLDEVENT_HPP +#include #include namespace mwmp @@ -19,7 +20,17 @@ namespace mwmp } + virtual ESM::CellRef *CellRef() + { + return &ref; + } + RakNet::RakNetGUID guid; + + protected: + + ESM::CellRef ref; + }; } diff --git a/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp b/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp index 2c4e02297..0c6b68f53 100644 --- a/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp @@ -11,4 +11,6 @@ PacketObjectRemoval::PacketObjectRemoval(RakNet::RakPeerInterface *peer) : World void PacketObjectRemoval::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) { WorldPacket::Packet(bs, event, send); + + RW(*event->CellRef(), send); } From 36f218876a635e77188695a4f6394fd8f6bccdd5 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Fri, 21 Oct 2016 19:23:56 +0300 Subject: [PATCH 17/34] Add ProcessPlayerPacket and ProcessWorldPacket to client's Networking --- apps/openmw/mwmp/Networking.cpp | 714 +++++++++++++++++--------------- apps/openmw/mwmp/Networking.hpp | 2 + 2 files changed, 373 insertions(+), 343 deletions(-) diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 1fbcc8f14..5a9f76934 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -166,13 +166,9 @@ void Networking::Connect(const std::string &ip, unsigned short port) } } -void Networking::ReceiveMessage(RakNet::Packet *packet) +void Networking::ProcessPlayerPacket(RakNet::Packet *packet) { RakNet::RakNetGUID id; - - if (packet->length < 2) - return; - RakNet::BitStream bsIn(&packet->data[1], packet->length, false); bsIn.Read(id); @@ -185,439 +181,471 @@ void Networking::ReceiveMessage(RakNet::Packet *packet) switch (packet->data[0]) { - case ID_HANDSHAKE: - { - (*getLocalPlayer()->GetPassw()) = "SuperPassword"; - myPacket->Send(getLocalPlayer(), serverAddr); - break; - } - case ID_GAME_BASE_INFO: + case ID_HANDSHAKE: + { + (*getLocalPlayer()->GetPassw()) = "SuperPassword"; + myPacket->Send(getLocalPlayer(), serverAddr); + break; + } + case ID_GAME_BASE_INFO: + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Received ID_GAME_BASE_INFO from server"); + + if (id == myid) { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Received ID_GAME_BASE_INFO from server"); + LOG_APPEND(Log::LOG_INFO, "%s", "- Packet was about my id"); - if (id == myid) + if (packet->length == myPacket->headerSize()) { - LOG_APPEND(Log::LOG_INFO, "%s", "- Packet was about my id"); - - if (packet->length == myPacket->headerSize()) - { - LOG_APPEND(Log::LOG_INFO, "%s", "- Requesting info"); - myPacket->Send(getLocalPlayer(), serverAddr); - } - else - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - LOG_APPEND(Log::LOG_INFO, "%s", "- Updating LocalPlayer"); - getLocalPlayer()->updateChar(); - } + LOG_APPEND(Log::LOG_INFO, "%s", "- Requesting info"); + myPacket->Send(getLocalPlayer(), serverAddr); } else { - LOG_APPEND(Log::LOG_INFO, "- Packet was about %s", pl == 0 ? "new player" : pl->Npc()->mName.c_str()); - - if (pl == 0) - { - LOG_APPEND(Log::LOG_INFO, "%s", "- Exchanging data with new player"); - pl = Players::NewPlayer(id); - } - - myPacket->Packet(&bsIn, pl, false); - Players::CreatePlayer(id); + myPacket->Packet(&bsIn, getLocalPlayer(), false); + LOG_APPEND(Log::LOG_INFO, "%s", "- Updating LocalPlayer"); + getLocalPlayer()->updateChar(); } - break; } - case ID_GAME_POS: + else { - if (id == myid) + LOG_APPEND(Log::LOG_INFO, "- Packet was about %s", pl == 0 ? "new player" : pl->Npc()->mName.c_str()); + + if (pl == 0) { - if (packet->length != myPacket->headerSize()) - { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "ID_GAME_POS changed by server"); - myPacket->Packet(&bsIn, getLocalPlayer(), false); - getLocalPlayer()->setPosition(); - } - else - getLocalPlayer()->updatePosition(true); + LOG_APPEND(Log::LOG_INFO, "%s", "- Exchanging data with new player"); + pl = Players::NewPlayer(id); } - else if (pl != 0) - myPacket->Packet(&bsIn, pl, false); - break; + + myPacket->Packet(&bsIn, pl, false); + Players::CreatePlayer(id); } - case ID_USER_MYID: + break; + } + case ID_GAME_POS: + { + if (id == myid) { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Received ID_USER_MYID from server"); - myid = id; - getLocalPlayer()->guid = id; - break; + if (packet->length != myPacket->headerSize()) + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "ID_GAME_POS changed by server"); + myPacket->Packet(&bsIn, getLocalPlayer(), false); + getLocalPlayer()->setPosition(); + } + else + getLocalPlayer()->updatePosition(true); } - case ID_USER_DISCONNECTED: - { - if (id == myid) - MWBase::Environment::get().getStateManager()->requestQuit(); - else if (pl != 0) - Players::DisconnectPlayer(id); + else if (pl != 0) + myPacket->Packet(&bsIn, pl, false); + break; + } + case ID_USER_MYID: + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Received ID_USER_MYID from server"); + myid = id; + getLocalPlayer()->guid = id; + break; + } + case ID_USER_DISCONNECTED: + { + if (id == myid) + MWBase::Environment::get().getStateManager()->requestQuit(); + else if (pl != 0) + Players::DisconnectPlayer(id); - } - case ID_GAME_EQUIPMENT: + } + case ID_GAME_EQUIPMENT: + { + if (id == myid) { - if (id == myid) + if (packet->length == myPacket->headerSize()) { - if (packet->length == myPacket->headerSize()) - { - getLocalPlayer()->updateInventory(true); - } - else - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - getLocalPlayer()->setInventory(); - } + getLocalPlayer()->updateInventory(true); } - else if (pl != 0) + else { - myPacket->Packet(&bsIn, pl, false); - pl->UpdateInventory(); + myPacket->Packet(&bsIn, getLocalPlayer(), false); + getLocalPlayer()->setInventory(); } - break; } - case ID_GAME_ATTACK: + else if (pl != 0) + { + myPacket->Packet(&bsIn, pl, false); + pl->UpdateInventory(); + } + break; + } + case ID_GAME_ATTACK: + { + if (pl != 0) { - if (pl != 0) + myPacket->Packet(&bsIn, pl, false); + + //cout << "Player: " << pl->Npc()->mName << " pressed: " << (pl->GetAttack()->pressed == 1) << endl; + if (pl->GetAttack()->pressed == 0) { - myPacket->Packet(&bsIn, pl, false); + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Attack success: %s", + pl->GetAttack()->success ? "true" : "false"); - //cout << "Player: " << pl->Npc()->mName << " pressed: " << (pl->GetAttack()->pressed == 1) << endl; - if (pl->GetAttack()->pressed == 0) + if (pl->GetAttack()->success == 1) { - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Attack success: %s", - pl->GetAttack()->success ? "true" : "false"); - - if (pl->GetAttack()->success == 1) - { - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Damage: %f", - pl->GetAttack()->damage); - } + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Damage: %f", + pl->GetAttack()->damage); } + } - MWMechanics::CreatureStats &stats = pl->getPtr().getClass().getNpcStats(pl->getPtr()); - stats.getSpells().setSelectedSpell(pl->GetAttack()->refid); + MWMechanics::CreatureStats &stats = pl->getPtr().getClass().getNpcStats(pl->getPtr()); + stats.getSpells().setSelectedSpell(pl->GetAttack()->refid); - MWWorld::Ptr victim; - if (pl->GetAttack()->target == getLocalPlayer()->guid) - victim = MWBase::Environment::get().getWorld()->getPlayerPtr(); - else if (Players::GetPlayer(pl->GetAttack()->target) != 0) - victim = Players::GetPlayer(pl->GetAttack()->target)->getPtr(); + MWWorld::Ptr victim; + if (pl->GetAttack()->target == getLocalPlayer()->guid) + victim = MWBase::Environment::get().getWorld()->getPlayerPtr(); + else if (Players::GetPlayer(pl->GetAttack()->target) != 0) + victim = Players::GetPlayer(pl->GetAttack()->target)->getPtr(); - MWWorld::Ptr attacker; - attacker = pl->getPtr(); + MWWorld::Ptr attacker; + attacker = pl->getPtr(); - // Get the weapon used (if hand-to-hand, weapon = inv.end()) - if (*pl->DrawState() == 1) + // Get the weapon used (if hand-to-hand, weapon = inv.end()) + if (*pl->DrawState() == 1) + { + MWWorld::InventoryStore &inv = attacker.getClass().getInventoryStore(attacker); + MWWorld::ContainerStoreIterator weaponslot = inv.getSlot( + MWWorld::InventoryStore::Slot_CarriedRight); + MWWorld::Ptr weapon = ((weaponslot != inv.end()) ? *weaponslot : MWWorld::Ptr()); + if (!weapon.isEmpty() && weapon.getTypeName() != typeid(ESM::Weapon).name()) + weapon = MWWorld::Ptr(); + + if (victim.mRef != 0) { - MWWorld::InventoryStore &inv = attacker.getClass().getInventoryStore(attacker); - MWWorld::ContainerStoreIterator weaponslot = inv.getSlot( - MWWorld::InventoryStore::Slot_CarriedRight); - MWWorld::Ptr weapon = ((weaponslot != inv.end()) ? *weaponslot : MWWorld::Ptr()); - if (!weapon.isEmpty() && weapon.getTypeName() != typeid(ESM::Weapon).name()) - weapon = MWWorld::Ptr(); - - if (victim.mRef != 0) + bool healthdmg; + if (!weapon.isEmpty()) + healthdmg = true; + else { - bool healthdmg; - if (!weapon.isEmpty()) - healthdmg = true; - else - { - MWMechanics::CreatureStats &otherstats = victim.getClass().getCreatureStats(victim); - healthdmg = otherstats.isParalyzed() || otherstats.getKnockedDown(); - } - - if (!weapon.isEmpty()) - MWMechanics::blockMeleeAttack(attacker, victim, weapon, pl->GetAttack()->damage, 1); - pl->getPtr().getClass().onHit(victim, pl->GetAttack()->damage, healthdmg, weapon, attacker, osg::Vec3f(), - pl->GetAttack()->success); + MWMechanics::CreatureStats &otherstats = victim.getClass().getCreatureStats(victim); + healthdmg = otherstats.isParalyzed() || otherstats.getKnockedDown(); } + + if (!weapon.isEmpty()) + MWMechanics::blockMeleeAttack(attacker, victim, weapon, pl->GetAttack()->damage, 1); + pl->getPtr().getClass().onHit(victim, pl->GetAttack()->damage, healthdmg, weapon, attacker, osg::Vec3f(), + pl->GetAttack()->success); } - else - { - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "SpellId: %s", - pl->GetAttack()->refid.c_str()); - } } - break; + else + { + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "SpellId: %s", + pl->GetAttack()->refid.c_str()); + } } - case ID_GAME_DYNAMICSTATS: + break; + } + case ID_GAME_DYNAMICSTATS: + { + if (id == myid) { - if (id == myid) + if (packet->length == myPacket->headerSize()) { - if (packet->length == myPacket->headerSize()) - { - getLocalPlayer()->updateDynamicStats(true); - } - else - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - getLocalPlayer()->setDynamicStats(); - } + getLocalPlayer()->updateDynamicStats(true); } - else if (pl != 0) + else { - myPacket->Packet(&bsIn, pl, false); - - MWWorld::Ptr ptrPlayer = pl->getPtr(); - MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer); - MWMechanics::DynamicStat value; - - for (int i = 0; i < 3; ++i) - { - value.readState(pl->CreatureStats()->mDynamic[i]); - ptrCreatureStats->setDynamic(i, value); - } + myPacket->Packet(&bsIn, getLocalPlayer(), false); + getLocalPlayer()->setDynamicStats(); } - break; } - case ID_GAME_DIE: + else if (pl != 0) { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Received ID_GAME_DIE from server"); - if (id == myid) - { - MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWMechanics::DynamicStat health = player.getClass().getCreatureStats(player).getHealth(); - health.setCurrent(0); - player.getClass().getCreatureStats(player).setHealth(health); - myPacket->Send(getLocalPlayer(), serverAddr); - } - else if (pl != 0) + myPacket->Packet(&bsIn, pl, false); + + MWWorld::Ptr ptrPlayer = pl->getPtr(); + MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer); + MWMechanics::DynamicStat value; + + for (int i = 0; i < 3; ++i) { - LOG_APPEND(Log::LOG_INFO, "- Packet was about %s", pl->Npc()->mName.c_str()); - MWMechanics::DynamicStat health; - pl->CreatureStats()->mDead = true; - health.readState(pl->CreatureStats()->mDynamic[0]); - health.setCurrent(0); - health.writeState(pl->CreatureStats()->mDynamic[0]); - pl->getPtr().getClass().getCreatureStats(pl->getPtr()).setHealth(health); + value.readState(pl->CreatureStats()->mDynamic[i]); + ptrCreatureStats->setDynamic(i, value); } - break; } - case ID_GAME_RESURRECT: + break; + } + case ID_GAME_DIE: + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Received ID_GAME_DIE from server"); + if (id == myid) { - if (id == myid) - { - MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - player.getClass().getCreatureStats(player).resurrect(); - ESM::Position pos; - MWBase::Environment::get().getWorld()->findInteriorPosition("Pelagiad, Fort Pelagiad", pos); - MWBase::Environment::get().getWorld()->changeToInteriorCell("Pelagiad, Fort Pelagiad", pos, true); - (*getLocalPlayer()->Position()) = pos; - (*getLocalPlayer()->GetCell()) = *player.getCell()->getCell(); - myPacket->Send(getLocalPlayer(), serverAddr); + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); + MWMechanics::DynamicStat health = player.getClass().getCreatureStats(player).getHealth(); + health.setCurrent(0); + player.getClass().getCreatureStats(player).setHealth(health); + myPacket->Send(getLocalPlayer(), serverAddr); + } + else if (pl != 0) + { + LOG_APPEND(Log::LOG_INFO, "- Packet was about %s", pl->Npc()->mName.c_str()); + MWMechanics::DynamicStat health; + pl->CreatureStats()->mDead = true; + health.readState(pl->CreatureStats()->mDynamic[0]); + health.setCurrent(0); + health.writeState(pl->CreatureStats()->mDynamic[0]); + pl->getPtr().getClass().getCreatureStats(pl->getPtr()).setHealth(health); + } + break; + } + case ID_GAME_RESURRECT: + { + if (id == myid) + { + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); + player.getClass().getCreatureStats(player).resurrect(); + ESM::Position pos; + MWBase::Environment::get().getWorld()->findInteriorPosition("Pelagiad, Fort Pelagiad", pos); + MWBase::Environment::get().getWorld()->changeToInteriorCell("Pelagiad, Fort Pelagiad", pos, true); + (*getLocalPlayer()->Position()) = pos; + (*getLocalPlayer()->GetCell()) = *player.getCell()->getCell(); + myPacket->Send(getLocalPlayer(), serverAddr); - getLocalPlayer()->updateDynamicStats(true); - playerController.GetPacket(ID_GAME_DYNAMICSTATS)->Send(getLocalPlayer(), serverAddr); - } - else if (pl != 0) - { - pl->CreatureStats()->mDead = false; - if (pl->CreatureStats()->mDynamic[0].mMod < 1) - pl->CreatureStats()->mDynamic[0].mMod = 1; - pl->CreatureStats()->mDynamic[0].mCurrent = pl->CreatureStats()->mDynamic[0].mMod; + getLocalPlayer()->updateDynamicStats(true); + playerController.GetPacket(ID_GAME_DYNAMICSTATS)->Send(getLocalPlayer(), serverAddr); + } + else if (pl != 0) + { + pl->CreatureStats()->mDead = false; + if (pl->CreatureStats()->mDynamic[0].mMod < 1) + pl->CreatureStats()->mDynamic[0].mMod = 1; + pl->CreatureStats()->mDynamic[0].mCurrent = pl->CreatureStats()->mDynamic[0].mMod; - pl->getPtr().getClass().getCreatureStats(pl->getPtr()).resurrect(); + pl->getPtr().getClass().getCreatureStats(pl->getPtr()).resurrect(); - MWMechanics::DynamicStat health; - health.readState(pl->CreatureStats()->mDynamic[0]); - pl->getPtr().getClass().getCreatureStats(pl->getPtr()).setHealth(health); - } - break; + MWMechanics::DynamicStat health; + health.readState(pl->CreatureStats()->mDynamic[0]); + pl->getPtr().getClass().getCreatureStats(pl->getPtr()).setHealth(health); } - case ID_GAME_CELL: + break; + } + case ID_GAME_CELL: + { + if (id == myid) { - if (id == myid) - { - if (packet->length == myPacket->headerSize()) - getLocalPlayer()->updateCell(true); - else - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - getLocalPlayer()->setCell(); - } - } - else if (pl != 0) + if (packet->length == myPacket->headerSize()) + getLocalPlayer()->updateCell(true); + else { - myPacket->Packet(&bsIn, pl, false); - pl->updateCell(); + myPacket->Packet(&bsIn, getLocalPlayer(), false); + getLocalPlayer()->setCell(); } - break; } - case ID_GAME_DRAWSTATE: + else if (pl != 0) { - if (id == myid) - getLocalPlayer()->updateDrawStateAndFlags(true); - else if (pl != 0) - { - myPacket->Packet(&bsIn, pl, false); - pl->UpdateDrawState(); - } - break; + myPacket->Packet(&bsIn, pl, false); + pl->updateCell(); } - case ID_CHAT_MESSAGE: + break; + } + case ID_GAME_DRAWSTATE: + { + if (id == myid) + getLocalPlayer()->updateDrawStateAndFlags(true); + else if (pl != 0) { - std::string message; - if (id == myid) - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - message = *getLocalPlayer()->ChatMessage(); - } - else if (pl != 0) - { - myPacket->Packet(&bsIn, pl, false); - message = *pl->ChatMessage(); - } - Main::get().getGUIController()->PrintChatMessage(message); + myPacket->Packet(&bsIn, pl, false); + pl->UpdateDrawState(); + } + break; + } + case ID_CHAT_MESSAGE: + { + std::string message; + if (id == myid) + { + myPacket->Packet(&bsIn, getLocalPlayer(), false); + message = *getLocalPlayer()->ChatMessage(); + } + else if (pl != 0) + { + myPacket->Packet(&bsIn, pl, false); + message = *pl->ChatMessage(); + } + Main::get().getGUIController()->PrintChatMessage(message); - break; + break; + } + case ID_GAME_CHARGEN: + { + if (id == myid) + { + myPacket->Packet(&bsIn, getLocalPlayer(), false); } - case ID_GAME_CHARGEN: + break; + } + case ID_GAME_ATTRIBUTE: + { + if (id == myid) { - if (id == myid) + if (packet->length == myPacket->headerSize()) + { + getLocalPlayer()->updateAttributes(true); + } + else { myPacket->Packet(&bsIn, getLocalPlayer(), false); + getLocalPlayer()->setAttributes(); } - break; } - case ID_GAME_ATTRIBUTE: + else if (pl != 0) { - if (id == myid) - { - if (packet->length == myPacket->headerSize()) - { - getLocalPlayer()->updateAttributes(true); - } - else - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - getLocalPlayer()->setAttributes(); - } - } - else if (pl != 0) - { - myPacket->Packet(&bsIn, pl, false); + myPacket->Packet(&bsIn, pl, false); - MWWorld::Ptr ptrPlayer = pl->getPtr(); - MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer); - MWMechanics::AttributeValue attributeValue; + MWWorld::Ptr ptrPlayer = pl->getPtr(); + MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer); + MWMechanics::AttributeValue attributeValue; - for (int i = 0; i < 8; ++i) - { - attributeValue.readState(pl->CreatureStats()->mAttributes[i]); - ptrCreatureStats->setAttribute(i, attributeValue); - } + for (int i = 0; i < 8; ++i) + { + attributeValue.readState(pl->CreatureStats()->mAttributes[i]); + ptrCreatureStats->setAttribute(i, attributeValue); } - break; } - case ID_GAME_SKILL: + break; + } + case ID_GAME_SKILL: + { + if (id == myid) { - if (id == myid) + if (packet->length == myPacket->headerSize()) { - if (packet->length == myPacket->headerSize()) - { - getLocalPlayer()->updateSkills(true); - } - else - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - getLocalPlayer()->setSkills(); - } + getLocalPlayer()->updateSkills(true); } - else if (pl != 0) + else { - myPacket->Packet(&bsIn, pl, false); + myPacket->Packet(&bsIn, getLocalPlayer(), false); + getLocalPlayer()->setSkills(); + } + } + else if (pl != 0) + { + myPacket->Packet(&bsIn, pl, false); - MWWorld::Ptr ptrPlayer = pl->getPtr(); - MWMechanics::NpcStats *ptrNpcStats = &ptrPlayer.getClass().getNpcStats(ptrPlayer); - MWMechanics::SkillValue skillValue; + MWWorld::Ptr ptrPlayer = pl->getPtr(); + MWMechanics::NpcStats *ptrNpcStats = &ptrPlayer.getClass().getNpcStats(ptrPlayer); + MWMechanics::SkillValue skillValue; - for (int i = 0; i < 27; ++i) - { - skillValue.readState(pl->NpcStats()->mSkills[i]); - ptrNpcStats->setSkill(i, skillValue); - } + for (int i = 0; i < 27; ++i) + { + skillValue.readState(pl->NpcStats()->mSkills[i]); + ptrNpcStats->setSkill(i, skillValue); } - break; } - case ID_GAME_LEVEL: + break; + } + case ID_GAME_LEVEL: + { + if (id == myid) { - if (id == myid) + if (packet->length == myPacket->headerSize()) { - if (packet->length == myPacket->headerSize()) - { - getLocalPlayer()->updateLevel(true); - } - else - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - getLocalPlayer()->setLevel(); - } + getLocalPlayer()->updateLevel(true); } - else if (pl != 0) + else { - myPacket->Packet(&bsIn, pl, false); - - MWWorld::Ptr ptrPlayer = pl->getPtr(); - MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer); - - ptrCreatureStats->setLevel(pl->CreatureStats()->mLevel); + myPacket->Packet(&bsIn, getLocalPlayer(), false); + getLocalPlayer()->setLevel(); } - break; } - case ID_GUI_MESSAGEBOX: + else if (pl != 0) { - if (id == myid) - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); + myPacket->Packet(&bsIn, pl, false); - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "ID_GUI_MESSAGEBOX, Type %d, MSG %s", - getLocalPlayer()->guiMessageBox.type, - getLocalPlayer()->guiMessageBox.label.c_str()); + MWWorld::Ptr ptrPlayer = pl->getPtr(); + MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer); - if (getLocalPlayer()->guiMessageBox.type == BasePlayer::GUIMessageBox::MessageBox) - Main::get().getGUIController()->ShowMessageBox(getLocalPlayer()->guiMessageBox); - else if (getLocalPlayer()->guiMessageBox.type == BasePlayer::GUIMessageBox::CustomMessageBox) - Main::get().getGUIController()->ShowCustomMessageBox(getLocalPlayer()->guiMessageBox); - else if (getLocalPlayer()->guiMessageBox.type == BasePlayer::GUIMessageBox::InputDialog) - Main::get().getGUIController()->ShowInputBox(getLocalPlayer()->guiMessageBox); - } - break; + ptrCreatureStats->setLevel(pl->CreatureStats()->mLevel); } - case ID_GAME_CHARCLASS: + break; + } + case ID_GUI_MESSAGEBOX: + { + if (id == myid) { - if (id == myid) - { - if (packet->length == myPacket->headerSize()) - getLocalPlayer()->sendClass(); - else - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - getLocalPlayer()->setClass(); - } - } - break; + myPacket->Packet(&bsIn, getLocalPlayer(), false); + + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "ID_GUI_MESSAGEBOX, Type %d, MSG %s", + getLocalPlayer()->guiMessageBox.type, + getLocalPlayer()->guiMessageBox.label.c_str()); + + if (getLocalPlayer()->guiMessageBox.type == BasePlayer::GUIMessageBox::MessageBox) + Main::get().getGUIController()->ShowMessageBox(getLocalPlayer()->guiMessageBox); + else if (getLocalPlayer()->guiMessageBox.type == BasePlayer::GUIMessageBox::CustomMessageBox) + Main::get().getGUIController()->ShowCustomMessageBox(getLocalPlayer()->guiMessageBox); + else if (getLocalPlayer()->guiMessageBox.type == BasePlayer::GUIMessageBox::InputDialog) + Main::get().getGUIController()->ShowInputBox(getLocalPlayer()->guiMessageBox); } - case ID_GAME_TIME: + break; + } + case ID_GAME_CHARCLASS: + { + if (id == myid) { - if (id == myid) + if (packet->length == myPacket->headerSize()) + getLocalPlayer()->sendClass(); + else { myPacket->Packet(&bsIn, getLocalPlayer(), false); - MWBase::World *world = MWBase::Environment::get().getWorld(); - if (getLocalPlayer()->hour != -1) - world->setHour(getLocalPlayer()->hour); - else if (getLocalPlayer()->day != -1) - world->setDay(getLocalPlayer()->day); - else if (getLocalPlayer()->month != -1) - world->setMonth(getLocalPlayer()->month); + getLocalPlayer()->setClass(); } } - default: - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Custom message with identifier %i has arrived in initialization.", packet->data[0]); + break; + } + case ID_GAME_TIME: + { + if (id == myid) + { + myPacket->Packet(&bsIn, getLocalPlayer(), false); + MWBase::World *world = MWBase::Environment::get().getWorld(); + if (getLocalPlayer()->hour != -1) + world->setHour(getLocalPlayer()->hour); + else if (getLocalPlayer()->day != -1) + world->setDay(getLocalPlayer()->day); + else if (getLocalPlayer()->month != -1) + world->setMonth(getLocalPlayer()->month); + } + } + default: + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Unhandled PlayerPacket with identifier %i has arrived", + packet->data[0]); + } +} + +void Networking::ProcessWorldPacket(RakNet::Packet *packet) +{ + WorldPacket *myPacket = worldController.GetPacket(packet->data[0]); + + switch (packet->data[0]) + { + case ID_WORLD_OBJECT_REMOVAL: + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Received ID_WORLD_OBJECT_REMOVAL"); + } + default: + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Unhandled WorldPacket with identifier %i has arrived", + packet->data[0]); + } +} + +void Networking::ReceiveMessage(RakNet::Packet *packet) +{ + if (packet->length < 2) + return; + + if (playerController.ContainsPacket(packet->data[0])) + { + ProcessPlayerPacket(packet); + } + else if (worldController.ContainsPacket(packet->data[0])) + { + ProcessWorldPacket(packet); } } diff --git a/apps/openmw/mwmp/Networking.hpp b/apps/openmw/mwmp/Networking.hpp index 9acfaf96c..9c03510f8 100644 --- a/apps/openmw/mwmp/Networking.hpp +++ b/apps/openmw/mwmp/Networking.hpp @@ -59,6 +59,8 @@ namespace mwmp PlayerPacketController playerController; WorldPacketController worldController; + void ProcessPlayerPacket(RakNet::Packet *packet); + void ProcessWorldPacket(RakNet::Packet *packet); void ReceiveMessage(RakNet::Packet *packet); LocalPlayer *getLocalPlayer(); }; From 32dc8cf63fb8f7263513320c8985a06a8e70e702 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Fri, 21 Oct 2016 20:44:15 +0300 Subject: [PATCH 18/34] Read contents of ID_WORLD_OBJECT_REMOVAL on client --- apps/openmw/mwmp/Networking.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 5a9f76934..7e8a1c0c1 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -611,6 +611,7 @@ void Networking::ProcessPlayerPacket(RakNet::Packet *packet) else if (getLocalPlayer()->month != -1) world->setMonth(getLocalPlayer()->month); } + break; } default: LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Unhandled PlayerPacket with identifier %i has arrived", @@ -620,13 +621,30 @@ void Networking::ProcessPlayerPacket(RakNet::Packet *packet) void Networking::ProcessWorldPacket(RakNet::Packet *packet) { + RakNet::RakNetGUID id; + RakNet::BitStream bsIn(&packet->data[1], packet->length, false); + bsIn.Read(id); + + DedicatedPlayer *pl = 0; + static RakNet::RakNetGUID myid = getLocalPlayer()->guid; + if (id != myid) + pl = Players::GetPlayer(id); + WorldPacket *myPacket = worldController.GetPacket(packet->data[0]); + WorldEvent *event = new WorldEvent(id); switch (packet->data[0]) { case ID_WORLD_OBJECT_REMOVAL: { + myPacket->Packet(&bsIn, event, false); + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Received ID_WORLD_OBJECT_REMOVAL"); + LOG_APPEND(Log::LOG_WARN, "- cellRefId: %s, %i", + event->CellRef()->mRefID.c_str(), + event->CellRef()->mRefNum); + + break; } default: LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Unhandled WorldPacket with identifier %i has arrived", From 565e7e4b9f445111b9d7f7aa50e1457cb645334d Mon Sep 17 00:00:00 2001 From: David Cernat Date: Fri, 21 Oct 2016 21:57:05 +0300 Subject: [PATCH 19/34] Create and implement placeholder for ID_WORLD_OBJECT_CREATION --- apps/openmw-mp/Networking.cpp | 11 +++++++++++ apps/openmw/mwmp/Networking.cpp | 4 ++++ components/CMakeLists.txt | 2 +- .../Controllers/WorldPacketController.cpp | 2 ++ components/openmw-mp/NetworkMessages.hpp | 1 + .../Packets/World/PacketObjectCreation.cpp | 16 ++++++++++++++++ .../Packets/World/PacketObjectCreation.hpp | 17 +++++++++++++++++ 7 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 components/openmw-mp/Packets/World/PacketObjectCreation.cpp create mode 100644 components/openmw-mp/Packets/World/PacketObjectCreation.hpp diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index aa7937fba..37e3f94bf 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -374,6 +374,17 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) switch (packet->data[0]) { + case ID_WORLD_OBJECT_CREATION: + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_WORLD_OBJECT_CREATION from %s", + player->Npc()->mName.c_str()); + + myPacket->Read(event); + myPacket->Send(event, true); + + break; + } + case ID_WORLD_OBJECT_REMOVAL: { LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_WORLD_OBJECT_REMOVAL from %s", diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 7e8a1c0c1..bc0680a09 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -635,6 +635,10 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) switch (packet->data[0]) { + case ID_WORLD_OBJECT_CREATION: + { + break; + } case ID_WORLD_OBJECT_REMOVAL: { myPacket->Packet(&bsIn, event, false); diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 417528d23..843f30475 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -157,7 +157,7 @@ add_component_dir (openmw-mp Packets/Player/PacketHandshake Packets/Player/PacketGUIBoxes Packets/Player/PacketClass Packets/Player/PacketTime - Packets/World/PacketObjectRemoval) + Packets/World/PacketObjectCreation Packets/World/PacketObjectRemoval) add_component_dir (fallback fallback validate diff --git a/components/openmw-mp/Controllers/WorldPacketController.cpp b/components/openmw-mp/Controllers/WorldPacketController.cpp index b3295ceb8..d7be1666c 100644 --- a/components/openmw-mp/Controllers/WorldPacketController.cpp +++ b/components/openmw-mp/Controllers/WorldPacketController.cpp @@ -2,6 +2,7 @@ #include #include +#include "../Packets/World/PacketObjectCreation.hpp" #include "../Packets/World/PacketObjectRemoval.hpp" #include "WorldPacketController.hpp" @@ -16,6 +17,7 @@ inline void AddPacket(mwmp::WorldPacketController::packets_t *packets, RakNet::R mwmp::WorldPacketController::WorldPacketController(RakNet::RakPeerInterface *peer) { + AddPacket(&packets, peer); AddPacket(&packets, peer); } diff --git a/components/openmw-mp/NetworkMessages.hpp b/components/openmw-mp/NetworkMessages.hpp index 1bcd02b08..d5c65908a 100644 --- a/components/openmw-mp/NetworkMessages.hpp +++ b/components/openmw-mp/NetworkMessages.hpp @@ -32,6 +32,7 @@ enum GameMessages ID_GUI_MESSAGEBOX, ID_GAME_TIME, + ID_WORLD_OBJECT_CREATION, ID_WORLD_OBJECT_REMOVAL }; diff --git a/components/openmw-mp/Packets/World/PacketObjectCreation.cpp b/components/openmw-mp/Packets/World/PacketObjectCreation.cpp new file mode 100644 index 000000000..d5adb8f7a --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketObjectCreation.cpp @@ -0,0 +1,16 @@ +#include +#include "PacketObjectCreation.hpp" + +using namespace mwmp; + +PacketObjectCreation::PacketObjectCreation(RakNet::RakPeerInterface *peer) : WorldPacket(peer) +{ + packetID = ID_WORLD_OBJECT_REMOVAL; +} + +void PacketObjectCreation::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) +{ + WorldPacket::Packet(bs, event, send); + + RW(*event->CellRef(), send); +} diff --git a/components/openmw-mp/Packets/World/PacketObjectCreation.hpp b/components/openmw-mp/Packets/World/PacketObjectCreation.hpp new file mode 100644 index 000000000..7cbf801d6 --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketObjectCreation.hpp @@ -0,0 +1,17 @@ +#ifndef OPENMW_PACKETOBJECTCREATION_HPP +#define OPENMW_PACKETOBJECTCREATION_HPP + +#include + +namespace mwmp +{ + class PacketObjectCreation : public WorldPacket + { + public: + PacketObjectCreation(RakNet::RakPeerInterface *peer); + + virtual void Packet(RakNet::BitStream *bs, WorldEvent *event, bool send); + }; +} + +#endif //OPENMW_PACKETOBJECTCREATION_HPP From 8080cceac636b9ca5f476f687ee644088e2ddbdb Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 22 Oct 2016 12:45:19 +0300 Subject: [PATCH 20/34] Add some placeholder code so Stanislav can test it --- apps/openmw-mp/Networking.cpp | 5 +++++ apps/openmw/mwmp/Networking.cpp | 10 ++++++++++ apps/openmw/mwworld/worldimp.cpp | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index 37e3f94bf..f0c83ef23 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -391,6 +391,11 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) player->Npc()->mName.c_str()); myPacket->Read(event); + + LOG_APPEND(Log::LOG_WARN, "- %s", event->CellRef()->mRefID.c_str()); + + LOG_APPEND(Log::LOG_WARN, "- %i", event->CellRef()->mRefNum); + myPacket->Send(event, true); break; diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index bc0680a09..4ff5d2491 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -633,10 +633,16 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) WorldPacket *myPacket = worldController.GetPacket(packet->data[0]); WorldEvent *event = new WorldEvent(id); + MWWorld::CellStore *ptrCellStore = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell(); + switch (packet->data[0]) { case ID_WORLD_OBJECT_CREATION: { + MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), event->CellRef()->mRefID, 1); + + MWBase::Environment::get().getWorld()->placeObject(ref.getPtr(), ptrCellStore, event->CellRef()->mPos); + break; } case ID_WORLD_OBJECT_REMOVAL: @@ -648,6 +654,10 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) event->CellRef()->mRefID.c_str(), event->CellRef()->mRefNum); + //MWWorld::Ptr object = ptrCellStore->search(event->CellRef()->mRefID); + //MWBase::Environment::get().getWorld()->deleteObject(object); + + break; } default: diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index d7fd3281f..567351ef8 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1108,10 +1108,16 @@ namespace MWWorld { // Added by tes3mp mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); + event->CellRef()->mRefID = ptr.getCellRef().getRefId(); event->CellRef()->mRefNum = ptr.getCellRef().getRefNum(); mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_REMOVAL)->Send(event); + printf("Sending ID_WORLD_OBJECT_REMOVAL about\n%s\n%s\n%i\n", + ptr.getCellRef().getRefId().c_str(), + event->CellRef()->mRefID.c_str(), + event->CellRef()->mRefNum); + mWorldScene->removeObjectFromScene (ptr); mLocalScripts.remove (ptr); removeContainerScripts (ptr); From 92463c4a036ce0baf08b80589c96df15f32308a4 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 22 Oct 2016 14:13:16 +0300 Subject: [PATCH 21/34] Fix Windows server crash caused by printing event->CellRef()->mRefID --- apps/openmw-mp/Networking.cpp | 6 +++--- apps/openmw/mwmp/Networking.cpp | 10 +++++----- apps/openmw/mwworld/worldimp.cpp | 9 +++++---- components/openmw-mp/Base/WorldEvent.hpp | 11 +---------- .../openmw-mp/Packets/World/PacketObjectCreation.cpp | 3 ++- .../openmw-mp/Packets/World/PacketObjectRemoval.cpp | 3 ++- 6 files changed, 18 insertions(+), 24 deletions(-) diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index f0c83ef23..fa66029c9 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -370,6 +370,7 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) WorldPacket *myPacket = worldController->GetPacket(packet->data[0]); WorldEvent *event = new WorldEvent(player->guid); + event->cellRef.blank(); switch (packet->data[0]) { @@ -392,9 +393,8 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) myPacket->Read(event); - LOG_APPEND(Log::LOG_WARN, "- %s", event->CellRef()->mRefID.c_str()); - - LOG_APPEND(Log::LOG_WARN, "- %i", event->CellRef()->mRefNum); + LOG_APPEND(Log::LOG_WARN, "- %s", event->cellRef.mRefID.c_str()); + LOG_APPEND(Log::LOG_WARN, "- %i", event->cellRef.mRefNum); myPacket->Send(event, true); diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 4ff5d2491..90688ce7e 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -639,9 +639,9 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) { case ID_WORLD_OBJECT_CREATION: { - MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), event->CellRef()->mRefID, 1); + MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), event->cellRef.mRefID, 1); - MWBase::Environment::get().getWorld()->placeObject(ref.getPtr(), ptrCellStore, event->CellRef()->mPos); + MWBase::Environment::get().getWorld()->placeObject(ref.getPtr(), ptrCellStore, event->cellRef.mPos); break; } @@ -651,10 +651,10 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Received ID_WORLD_OBJECT_REMOVAL"); LOG_APPEND(Log::LOG_WARN, "- cellRefId: %s, %i", - event->CellRef()->mRefID.c_str(), - event->CellRef()->mRefNum); + event->cellRef.mRefID.c_str(), + event->cellRef.mRefNum); - //MWWorld::Ptr object = ptrCellStore->search(event->CellRef()->mRefID); + //MWWorld::Ptr object = ptrCellStore->search(event->cellRef.mRefID); //MWBase::Environment::get().getWorld()->deleteObject(object); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 567351ef8..326fba1ec 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1108,15 +1108,16 @@ namespace MWWorld { // Added by tes3mp mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); + event->cellRef.blank(); - event->CellRef()->mRefID = ptr.getCellRef().getRefId(); - event->CellRef()->mRefNum = ptr.getCellRef().getRefNum(); + event->cellRef.mRefID = ptr.getCellRef().getRefId(); + event->cellRef.mRefNum = ptr.getCellRef().getRefNum(); mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_REMOVAL)->Send(event); printf("Sending ID_WORLD_OBJECT_REMOVAL about\n%s\n%s\n%i\n", ptr.getCellRef().getRefId().c_str(), - event->CellRef()->mRefID.c_str(), - event->CellRef()->mRefNum); + event->cellRef.mRefID.c_str(), + event->cellRef.mRefNum); mWorldScene->removeObjectFromScene (ptr); mLocalScripts.remove (ptr); diff --git a/components/openmw-mp/Base/WorldEvent.hpp b/components/openmw-mp/Base/WorldEvent.hpp index e384bbe10..c2a88ff80 100644 --- a/components/openmw-mp/Base/WorldEvent.hpp +++ b/components/openmw-mp/Base/WorldEvent.hpp @@ -20,17 +20,8 @@ namespace mwmp } - virtual ESM::CellRef *CellRef() - { - return &ref; - } - RakNet::RakNetGUID guid; - - protected: - - ESM::CellRef ref; - + ESM::CellRef cellRef; }; } diff --git a/components/openmw-mp/Packets/World/PacketObjectCreation.cpp b/components/openmw-mp/Packets/World/PacketObjectCreation.cpp index d5adb8f7a..02ccd2417 100644 --- a/components/openmw-mp/Packets/World/PacketObjectCreation.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectCreation.cpp @@ -12,5 +12,6 @@ void PacketObjectCreation::Packet(RakNet::BitStream *bs, WorldEvent *event, bool { WorldPacket::Packet(bs, event, send); - RW(*event->CellRef(), send); + RW(event->cellRef.mRefID, send); + RW(event->cellRef.mRefNum, send); } diff --git a/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp b/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp index 0c6b68f53..a23cad4da 100644 --- a/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp @@ -12,5 +12,6 @@ void PacketObjectRemoval::Packet(RakNet::BitStream *bs, WorldEvent *event, bool { WorldPacket::Packet(bs, event, send); - RW(*event->CellRef(), send); + RW(event->cellRef.mRefID, send); + RW(event->cellRef.mRefNum, send); } From cc98a25dcfecc1d2e2afc9ef1d91bf3c0af77838 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 22 Oct 2016 16:47:11 +0300 Subject: [PATCH 22/34] Add searchByRefNum method to OpenMW's CellStore --- apps/openmw/mwmp/Networking.cpp | 8 ++++++-- apps/openmw/mwworld/cellstore.cpp | 8 ++++++++ apps/openmw/mwworld/cellstore.hpp | 3 +++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 90688ce7e..80f8192ba 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -654,9 +654,13 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) event->cellRef.mRefID.c_str(), event->cellRef.mRefNum); - //MWWorld::Ptr object = ptrCellStore->search(event->cellRef.mRefID); + MWWorld::Ptr ptrFound = ptrCellStore->searchByRefNum(event->cellRef.mRefNum); + + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i", + ptrFound.getCellRef().getRefId().c_str(), + ptrFound.getCellRef().getRefNum()); + //MWBase::Environment::get().getWorld()->deleteObject(object); - break; } diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index e5c9e779e..c3f2dca42 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -433,6 +433,14 @@ namespace MWWorld return Ptr(); } + // Added by tes3mp + Ptr CellStore::searchByRefNum (ESM::RefNum refNum) + { + SearchByRefNumVisitor searchVisitor(refNum); + forEach(searchVisitor); + return searchVisitor.mFound; + } + float CellStore::getWaterLevel() const { if (isExterior()) diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index 1aee13132..45f4a6606 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -228,6 +228,9 @@ namespace MWWorld Ptr searchViaActorId (int id); ///< Will return an empty Ptr if cell is not loaded. + Ptr searchByRefNum (ESM::RefNum refNum); + ///< Added by tes3mp + float getWaterLevel() const; void setWaterLevel (float level); From b3d6dad0c5b2b0fab92ed38889a95b179ab0091f Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 22 Oct 2016 17:10:57 +0300 Subject: [PATCH 23/34] Send ID_WORLD_OBJECT_REMOVAL from actiontake.cpp and not worldimp.cpp --- apps/openmw/mwmp/Networking.cpp | 2 +- apps/openmw/mwworld/actiontake.cpp | 16 ++++++++++++++++ apps/openmw/mwworld/worldimp.cpp | 16 ---------------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 80f8192ba..10db928cb 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -660,7 +660,7 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) ptrFound.getCellRef().getRefId().c_str(), ptrFound.getCellRef().getRefNum()); - //MWBase::Environment::get().getWorld()->deleteObject(object); + MWBase::Environment::get().getWorld()->deleteObject(ptrFound); break; } diff --git a/apps/openmw/mwworld/actiontake.cpp b/apps/openmw/mwworld/actiontake.cpp index 4e6135764..02d80de69 100644 --- a/apps/openmw/mwworld/actiontake.cpp +++ b/apps/openmw/mwworld/actiontake.cpp @@ -1,5 +1,8 @@ #include "actiontake.hpp" +#include +#include "../mwmp/Main.hpp" + #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwbase/windowmanager.hpp" @@ -17,6 +20,19 @@ namespace MWWorld MWBase::Environment::get().getMechanicsManager()->itemTaken( actor, getTarget(), MWWorld::Ptr(), getTarget().getRefData().getCount()); actor.getClass().getContainerStore (actor).add (getTarget(), getTarget().getRefData().getCount(), actor); + + // Added by tes3mp + mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); + event->cellRef.blank(); + + event->cellRef.mRefID = getTarget().getCellRef().getRefId(); + event->cellRef.mRefNum = getTarget().getCellRef().getRefNum(); + mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_REMOVAL)->Send(event); + + printf("Sending ID_WORLD_OBJECT_REMOVAL about %s\n%i\n", + event->cellRef.mRefID.c_str(), + event->cellRef.mRefNum); + MWBase::Environment::get().getWorld()->deleteObject (getTarget()); } } diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 326fba1ec..96422fe9e 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -17,9 +17,6 @@ #include -#include -#include "../mwmp/Main.hpp" - #include "../mwbase/environment.hpp" #include "../mwbase/soundmanager.hpp" #include "../mwbase/mechanicsmanager.hpp" @@ -1106,19 +1103,6 @@ namespace MWWorld && mWorldScene->getActiveCells().find(ptr.getCell()) != mWorldScene->getActiveCells().end() && ptr.getRefData().isEnabled()) { - // Added by tes3mp - mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); - event->cellRef.blank(); - - event->cellRef.mRefID = ptr.getCellRef().getRefId(); - event->cellRef.mRefNum = ptr.getCellRef().getRefNum(); - mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_REMOVAL)->Send(event); - - printf("Sending ID_WORLD_OBJECT_REMOVAL about\n%s\n%s\n%i\n", - ptr.getCellRef().getRefId().c_str(), - event->cellRef.mRefID.c_str(), - event->cellRef.mRefNum); - mWorldScene->removeObjectFromScene (ptr); mLocalScripts.remove (ptr); removeContainerScripts (ptr); From 40f1db2d8689a8d2242f9448e2a453bc385ed042 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 22 Oct 2016 17:47:21 +0300 Subject: [PATCH 24/34] Create SearchByRefNumCustomVisitor in CellStore that returns entire Ptr --- apps/openmw/mwworld/cellstore.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index c3f2dca42..6be2075c4 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -168,6 +168,30 @@ namespace return true; } }; + + // Added by tes3mp + template + struct SearchByRefNumCustomVisitor + { + PtrType mFound; + ESM::RefNum mRefNumToFind; + + SearchByRefNumCustomVisitor(const ESM::RefNum& toFind) + : mFound(NULL) + , mRefNumToFind(toFind) + { + } + + bool operator()(const PtrType& ptr) + { + if (ptr.getCellRef().getRefNum() == mRefNumToFind) + { + mFound = ptr; + return false; + } + return true; + } + }; } namespace MWWorld @@ -436,7 +460,7 @@ namespace MWWorld // Added by tes3mp Ptr CellStore::searchByRefNum (ESM::RefNum refNum) { - SearchByRefNumVisitor searchVisitor(refNum); + SearchByRefNumCustomVisitor searchVisitor(refNum); forEach(searchVisitor); return searchVisitor.mFound; } From 3c49157ed77e9e23fdc0ee12deaecdce8db24fbe Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 22 Oct 2016 18:05:32 +0300 Subject: [PATCH 25/34] Rename WorldPackets to ID_WORLD_OBJECT_DELETE and ID_WORLD_OBJECT_PLACE --- apps/openmw-mp/Networking.cpp | 8 ++++---- apps/openmw/mwmp/Networking.cpp | 6 +++--- apps/openmw/mwworld/actiontake.cpp | 4 ++-- components/CMakeLists.txt | 2 +- .../Controllers/WorldPacketController.cpp | 8 ++++---- components/openmw-mp/NetworkMessages.hpp | 4 ++-- .../Packets/World/PacketObjectCreation.cpp | 17 ----------------- .../Packets/World/PacketObjectCreation.hpp | 17 ----------------- .../Packets/World/PacketObjectDelete.cpp | 17 +++++++++++++++++ .../Packets/World/PacketObjectDelete.hpp | 17 +++++++++++++++++ .../Packets/World/PacketObjectPlace.cpp | 17 +++++++++++++++++ .../Packets/World/PacketObjectPlace.hpp | 17 +++++++++++++++++ .../Packets/World/PacketObjectRemoval.cpp | 17 ----------------- .../Packets/World/PacketObjectRemoval.hpp | 17 ----------------- 14 files changed, 84 insertions(+), 84 deletions(-) delete mode 100644 components/openmw-mp/Packets/World/PacketObjectCreation.cpp delete mode 100644 components/openmw-mp/Packets/World/PacketObjectCreation.hpp create mode 100644 components/openmw-mp/Packets/World/PacketObjectDelete.cpp create mode 100644 components/openmw-mp/Packets/World/PacketObjectDelete.hpp create mode 100644 components/openmw-mp/Packets/World/PacketObjectPlace.cpp create mode 100644 components/openmw-mp/Packets/World/PacketObjectPlace.hpp delete mode 100644 components/openmw-mp/Packets/World/PacketObjectRemoval.cpp delete mode 100644 components/openmw-mp/Packets/World/PacketObjectRemoval.hpp diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index fa66029c9..adfc7c992 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -375,9 +375,9 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) switch (packet->data[0]) { - case ID_WORLD_OBJECT_CREATION: + case ID_WORLD_OBJECT_PLACE: { - LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_WORLD_OBJECT_CREATION from %s", + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_WORLD_OBJECT_PLACE from %s", player->Npc()->mName.c_str()); myPacket->Read(event); @@ -386,9 +386,9 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) break; } - case ID_WORLD_OBJECT_REMOVAL: + case ID_WORLD_OBJECT_DELETE: { - LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_WORLD_OBJECT_REMOVAL from %s", + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_WORLD_OBJECT_DELETE from %s", player->Npc()->mName.c_str()); myPacket->Read(event); diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 10db928cb..174a348ac 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -637,7 +637,7 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) switch (packet->data[0]) { - case ID_WORLD_OBJECT_CREATION: + case ID_WORLD_OBJECT_PLACE: { MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), event->cellRef.mRefID, 1); @@ -645,11 +645,11 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) break; } - case ID_WORLD_OBJECT_REMOVAL: + case ID_WORLD_OBJECT_DELETE: { myPacket->Packet(&bsIn, event, false); - LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Received ID_WORLD_OBJECT_REMOVAL"); + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Received ID_WORLD_OBJECT_DELETE"); LOG_APPEND(Log::LOG_WARN, "- cellRefId: %s, %i", event->cellRef.mRefID.c_str(), event->cellRef.mRefNum); diff --git a/apps/openmw/mwworld/actiontake.cpp b/apps/openmw/mwworld/actiontake.cpp index 02d80de69..b56492e38 100644 --- a/apps/openmw/mwworld/actiontake.cpp +++ b/apps/openmw/mwworld/actiontake.cpp @@ -27,9 +27,9 @@ namespace MWWorld event->cellRef.mRefID = getTarget().getCellRef().getRefId(); event->cellRef.mRefNum = getTarget().getCellRef().getRefNum(); - mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_REMOVAL)->Send(event); + mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_DELETE)->Send(event); - printf("Sending ID_WORLD_OBJECT_REMOVAL about %s\n%i\n", + printf("Sending ID_WORLD_OBJECT_DELETE about %s\n%i\n", event->cellRef.mRefID.c_str(), event->cellRef.mRefNum); diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 843f30475..47896b9dd 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -157,7 +157,7 @@ add_component_dir (openmw-mp Packets/Player/PacketHandshake Packets/Player/PacketGUIBoxes Packets/Player/PacketClass Packets/Player/PacketTime - Packets/World/PacketObjectCreation Packets/World/PacketObjectRemoval) + Packets/World/PacketObjectDelete Packets/World/PacketObjectPlace) add_component_dir (fallback fallback validate diff --git a/components/openmw-mp/Controllers/WorldPacketController.cpp b/components/openmw-mp/Controllers/WorldPacketController.cpp index d7be1666c..119c0b581 100644 --- a/components/openmw-mp/Controllers/WorldPacketController.cpp +++ b/components/openmw-mp/Controllers/WorldPacketController.cpp @@ -2,8 +2,8 @@ #include #include -#include "../Packets/World/PacketObjectCreation.hpp" -#include "../Packets/World/PacketObjectRemoval.hpp" +#include "../Packets/World/PacketObjectPlace.hpp" +#include "../Packets/World/PacketObjectDelete.hpp" #include "WorldPacketController.hpp" @@ -17,8 +17,8 @@ inline void AddPacket(mwmp::WorldPacketController::packets_t *packets, RakNet::R mwmp::WorldPacketController::WorldPacketController(RakNet::RakPeerInterface *peer) { - AddPacket(&packets, peer); - AddPacket(&packets, peer); + AddPacket(&packets, peer); + AddPacket(&packets, peer); } diff --git a/components/openmw-mp/NetworkMessages.hpp b/components/openmw-mp/NetworkMessages.hpp index d5c65908a..e3a733f27 100644 --- a/components/openmw-mp/NetworkMessages.hpp +++ b/components/openmw-mp/NetworkMessages.hpp @@ -32,8 +32,8 @@ enum GameMessages ID_GUI_MESSAGEBOX, ID_GAME_TIME, - ID_WORLD_OBJECT_CREATION, - ID_WORLD_OBJECT_REMOVAL + ID_WORLD_OBJECT_PLACE, + ID_WORLD_OBJECT_DELETE }; diff --git a/components/openmw-mp/Packets/World/PacketObjectCreation.cpp b/components/openmw-mp/Packets/World/PacketObjectCreation.cpp deleted file mode 100644 index 02ccd2417..000000000 --- a/components/openmw-mp/Packets/World/PacketObjectCreation.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include "PacketObjectCreation.hpp" - -using namespace mwmp; - -PacketObjectCreation::PacketObjectCreation(RakNet::RakPeerInterface *peer) : WorldPacket(peer) -{ - packetID = ID_WORLD_OBJECT_REMOVAL; -} - -void PacketObjectCreation::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) -{ - WorldPacket::Packet(bs, event, send); - - RW(event->cellRef.mRefID, send); - RW(event->cellRef.mRefNum, send); -} diff --git a/components/openmw-mp/Packets/World/PacketObjectCreation.hpp b/components/openmw-mp/Packets/World/PacketObjectCreation.hpp deleted file mode 100644 index 7cbf801d6..000000000 --- a/components/openmw-mp/Packets/World/PacketObjectCreation.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef OPENMW_PACKETOBJECTCREATION_HPP -#define OPENMW_PACKETOBJECTCREATION_HPP - -#include - -namespace mwmp -{ - class PacketObjectCreation : public WorldPacket - { - public: - PacketObjectCreation(RakNet::RakPeerInterface *peer); - - virtual void Packet(RakNet::BitStream *bs, WorldEvent *event, bool send); - }; -} - -#endif //OPENMW_PACKETOBJECTCREATION_HPP diff --git a/components/openmw-mp/Packets/World/PacketObjectDelete.cpp b/components/openmw-mp/Packets/World/PacketObjectDelete.cpp new file mode 100644 index 000000000..d4432c6c9 --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketObjectDelete.cpp @@ -0,0 +1,17 @@ +#include +#include "PacketObjectDelete.hpp" + +using namespace mwmp; + +PacketObjectDelete::PacketObjectDelete(RakNet::RakPeerInterface *peer) : WorldPacket(peer) +{ + packetID = ID_WORLD_OBJECT_DELETE; +} + +void PacketObjectDelete::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) +{ + WorldPacket::Packet(bs, event, send); + + RW(event->cellRef.mRefID, send); + RW(event->cellRef.mRefNum, send); +} diff --git a/components/openmw-mp/Packets/World/PacketObjectDelete.hpp b/components/openmw-mp/Packets/World/PacketObjectDelete.hpp new file mode 100644 index 000000000..d3042bc67 --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketObjectDelete.hpp @@ -0,0 +1,17 @@ +#ifndef OPENMW_PACKETOBJECTDELETE_HPP +#define OPENMW_PACKETOBJECTDELETE_HPP + +#include + +namespace mwmp +{ + class PacketObjectDelete : public WorldPacket + { + public: + PacketObjectDelete(RakNet::RakPeerInterface *peer); + + virtual void Packet(RakNet::BitStream *bs, WorldEvent *event, bool send); + }; +} + +#endif //OPENMW_PACKETOBJECTDELETE_HPP diff --git a/components/openmw-mp/Packets/World/PacketObjectPlace.cpp b/components/openmw-mp/Packets/World/PacketObjectPlace.cpp new file mode 100644 index 000000000..73de27d9d --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketObjectPlace.cpp @@ -0,0 +1,17 @@ +#include +#include "PacketObjectPlace.hpp" + +using namespace mwmp; + +PacketObjectPlace::PacketObjectPlace(RakNet::RakPeerInterface *peer) : WorldPacket(peer) +{ + packetID = ID_WORLD_OBJECT_DELETE; +} + +void PacketObjectPlace::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) +{ + WorldPacket::Packet(bs, event, send); + + RW(event->cellRef.mRefID, send); + RW(event->cellRef.mRefNum, send); +} diff --git a/components/openmw-mp/Packets/World/PacketObjectPlace.hpp b/components/openmw-mp/Packets/World/PacketObjectPlace.hpp new file mode 100644 index 000000000..cea0263dd --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketObjectPlace.hpp @@ -0,0 +1,17 @@ +#ifndef OPENMW_PACKETOBJECTPLACE_HPP +#define OPENMW_PACKETOBJECTPLACE_HPP + +#include + +namespace mwmp +{ + class PacketObjectPlace : public WorldPacket + { + public: + PacketObjectPlace(RakNet::RakPeerInterface *peer); + + virtual void Packet(RakNet::BitStream *bs, WorldEvent *event, bool send); + }; +} + +#endif //OPENMW_PACKETOBJECTPLACE_HPP diff --git a/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp b/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp deleted file mode 100644 index a23cad4da..000000000 --- a/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include "PacketObjectRemoval.hpp" - -using namespace mwmp; - -PacketObjectRemoval::PacketObjectRemoval(RakNet::RakPeerInterface *peer) : WorldPacket(peer) -{ - packetID = ID_WORLD_OBJECT_REMOVAL; -} - -void PacketObjectRemoval::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) -{ - WorldPacket::Packet(bs, event, send); - - RW(event->cellRef.mRefID, send); - RW(event->cellRef.mRefNum, send); -} diff --git a/components/openmw-mp/Packets/World/PacketObjectRemoval.hpp b/components/openmw-mp/Packets/World/PacketObjectRemoval.hpp deleted file mode 100644 index 1046ad0e0..000000000 --- a/components/openmw-mp/Packets/World/PacketObjectRemoval.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef OPENMW_PACKETOBJECTREMOVAL_HPP -#define OPENMW_PACKETOBJECTREMOVAL_HPP - -#include - -namespace mwmp -{ - class PacketObjectRemoval : public WorldPacket - { - public: - PacketObjectRemoval(RakNet::RakPeerInterface *peer); - - virtual void Packet(RakNet::BitStream *bs, WorldEvent *event, bool send); - }; -} - -#endif //OPENMW_PACKETOBJECTREMOVAL_HPP From 2e57e256752b8474e2a5baf69bef0d4cf92d4e0d Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 22 Oct 2016 18:19:57 +0300 Subject: [PATCH 26/34] Only delete object from ID_WORLD_OBJECT_DELETE if it actually exists --- apps/openmw/mwmp/Networking.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 174a348ac..69dd5ef86 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -656,11 +656,14 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) MWWorld::Ptr ptrFound = ptrCellStore->searchByRefNum(event->cellRef.mRefNum); - LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i", - ptrFound.getCellRef().getRefId().c_str(), - ptrFound.getCellRef().getRefNum()); + if (ptrFound) + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i", + ptrFound.getCellRef().getRefId().c_str(), + ptrFound.getCellRef().getRefNum()); - MWBase::Environment::get().getWorld()->deleteObject(ptrFound); + MWBase::Environment::get().getWorld()->deleteObject(ptrFound); + } break; } From 103b1e3f721ffb7c645915730f5fc2cc2a39c3c4 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 22 Oct 2016 18:44:13 +0300 Subject: [PATCH 27/34] Send CellId in ID_WORLD_OBJECT_DELETE --- apps/openmw/mwmp/Networking.cpp | 2 +- apps/openmw/mwworld/actiontake.cpp | 4 +++- components/openmw-mp/Base/WorldEvent.hpp | 3 +++ components/openmw-mp/Packets/World/PacketObjectDelete.cpp | 5 +++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 69dd5ef86..1380349b6 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -633,7 +633,7 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) WorldPacket *myPacket = worldController.GetPacket(packet->data[0]); WorldEvent *event = new WorldEvent(id); - MWWorld::CellStore *ptrCellStore = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell(); + MWWorld::CellStore *ptrCellStore = MWBase::Environment::get().getWorld()->getCell(event->cellId); switch (packet->data[0]) { diff --git a/apps/openmw/mwworld/actiontake.cpp b/apps/openmw/mwworld/actiontake.cpp index b56492e38..8e2fa13e6 100644 --- a/apps/openmw/mwworld/actiontake.cpp +++ b/apps/openmw/mwworld/actiontake.cpp @@ -8,6 +8,8 @@ #include "../mwbase/windowmanager.hpp" #include "../mwbase/mechanicsmanager.hpp" +#include "../mwworld/cellstore.hpp" + #include "class.hpp" #include "containerstore.hpp" @@ -23,8 +25,8 @@ namespace MWWorld // Added by tes3mp mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); - event->cellRef.blank(); + event->cellId = getTarget().getCell()->getCell()->getCellId(); event->cellRef.mRefID = getTarget().getCellRef().getRefId(); event->cellRef.mRefNum = getTarget().getCellRef().getRefNum(); mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_DELETE)->Send(event); diff --git a/components/openmw-mp/Base/WorldEvent.hpp b/components/openmw-mp/Base/WorldEvent.hpp index c2a88ff80..05056a528 100644 --- a/components/openmw-mp/Base/WorldEvent.hpp +++ b/components/openmw-mp/Base/WorldEvent.hpp @@ -1,6 +1,7 @@ #ifndef OPENMW_WORLDEVENT_HPP #define OPENMW_WORLDEVENT_HPP +#include #include #include @@ -21,6 +22,8 @@ namespace mwmp } RakNet::RakNetGUID guid; + + ESM::CellId cellId; ESM::CellRef cellRef; }; } diff --git a/components/openmw-mp/Packets/World/PacketObjectDelete.cpp b/components/openmw-mp/Packets/World/PacketObjectDelete.cpp index d4432c6c9..25c252cd5 100644 --- a/components/openmw-mp/Packets/World/PacketObjectDelete.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectDelete.cpp @@ -14,4 +14,9 @@ void PacketObjectDelete::Packet(RakNet::BitStream *bs, WorldEvent *event, bool s RW(event->cellRef.mRefID, send); RW(event->cellRef.mRefNum, send); + + RW(event->cellId.mPaged, send); + RW(event->cellId.mIndex.mX, send); + RW(event->cellId.mIndex.mY, send); + RW(event->cellId.mWorldspace, send); } From 6e43baf73e61f51984049d789af698afe24052f2 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 22 Oct 2016 20:09:13 +0300 Subject: [PATCH 28/34] Send Cell instead of CellId because of problems with the latter --- apps/openmw/mwmp/Networking.cpp | 9 ++++++++- apps/openmw/mwworld/actiontake.cpp | 3 ++- components/openmw-mp/Base/WorldEvent.hpp | 2 +- .../openmw-mp/Packets/World/PacketObjectDelete.cpp | 8 ++++---- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 1380349b6..c29219f84 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -633,7 +633,7 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) WorldPacket *myPacket = worldController.GetPacket(packet->data[0]); WorldEvent *event = new WorldEvent(id); - MWWorld::CellStore *ptrCellStore = MWBase::Environment::get().getWorld()->getCell(event->cellId); + MWWorld::CellStore *ptrCellStore; switch (packet->data[0]) { @@ -649,10 +649,17 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) { myPacket->Packet(&bsIn, event, false); + if (event->cell.isExterior()) + ptrCellStore = MWBase::Environment::get().getWorld()->getExterior(event->cell.mData.mX, event->cell.mData.mY); + else + ptrCellStore = MWBase::Environment::get().getWorld()->getInterior(event->cell.mName); + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Received ID_WORLD_OBJECT_DELETE"); LOG_APPEND(Log::LOG_WARN, "- cellRefId: %s, %i", event->cellRef.mRefID.c_str(), event->cellRef.mRefNum); + LOG_APPEND(Log::LOG_WARN, "- cell: %s", + event->cell.getDescription().c_str()); MWWorld::Ptr ptrFound = ptrCellStore->searchByRefNum(event->cellRef.mRefNum); diff --git a/apps/openmw/mwworld/actiontake.cpp b/apps/openmw/mwworld/actiontake.cpp index 8e2fa13e6..1fc6b04c9 100644 --- a/apps/openmw/mwworld/actiontake.cpp +++ b/apps/openmw/mwworld/actiontake.cpp @@ -26,7 +26,8 @@ namespace MWWorld // Added by tes3mp mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); - event->cellId = getTarget().getCell()->getCell()->getCellId(); + event->cell = *getTarget().getCell()->getCell(); + event->cellRef.mRefID = getTarget().getCellRef().getRefId(); event->cellRef.mRefNum = getTarget().getCellRef().getRefNum(); mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_DELETE)->Send(event); diff --git a/components/openmw-mp/Base/WorldEvent.hpp b/components/openmw-mp/Base/WorldEvent.hpp index 05056a528..455d485a3 100644 --- a/components/openmw-mp/Base/WorldEvent.hpp +++ b/components/openmw-mp/Base/WorldEvent.hpp @@ -23,7 +23,7 @@ namespace mwmp RakNet::RakNetGUID guid; - ESM::CellId cellId; + ESM::Cell cell; ESM::CellRef cellRef; }; } diff --git a/components/openmw-mp/Packets/World/PacketObjectDelete.cpp b/components/openmw-mp/Packets/World/PacketObjectDelete.cpp index 25c252cd5..4b28cc46a 100644 --- a/components/openmw-mp/Packets/World/PacketObjectDelete.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectDelete.cpp @@ -15,8 +15,8 @@ void PacketObjectDelete::Packet(RakNet::BitStream *bs, WorldEvent *event, bool s RW(event->cellRef.mRefID, send); RW(event->cellRef.mRefNum, send); - RW(event->cellId.mPaged, send); - RW(event->cellId.mIndex.mX, send); - RW(event->cellId.mIndex.mY, send); - RW(event->cellId.mWorldspace, send); + RW(event->cell.mData.mFlags, send); + RW(event->cell.mCellId.mIndex.mX, send); + RW(event->cell.mCellId.mIndex.mY, send); + RW(event->cell.mName, send); } From 2b98e349ce1ec940d386fe5f7a4523c30cc539b5 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 22 Oct 2016 20:15:32 +0300 Subject: [PATCH 29/34] Fix include for WorldEvent --- components/openmw-mp/Base/WorldEvent.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/openmw-mp/Base/WorldEvent.hpp b/components/openmw-mp/Base/WorldEvent.hpp index 455d485a3..0348f3500 100644 --- a/components/openmw-mp/Base/WorldEvent.hpp +++ b/components/openmw-mp/Base/WorldEvent.hpp @@ -1,7 +1,7 @@ #ifndef OPENMW_WORLDEVENT_HPP #define OPENMW_WORLDEVENT_HPP -#include +#include #include #include From d0027ae3e750056f75e80c12a93b97314f661cd9 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sun, 23 Oct 2016 12:53:49 +0300 Subject: [PATCH 30/34] Set correct packetID for ID_WORLD_OBJECT_PLACE --- components/openmw-mp/Packets/World/PacketObjectPlace.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/openmw-mp/Packets/World/PacketObjectPlace.cpp b/components/openmw-mp/Packets/World/PacketObjectPlace.cpp index 73de27d9d..946c055c6 100644 --- a/components/openmw-mp/Packets/World/PacketObjectPlace.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectPlace.cpp @@ -5,7 +5,7 @@ using namespace mwmp; PacketObjectPlace::PacketObjectPlace(RakNet::RakPeerInterface *peer) : WorldPacket(peer) { - packetID = ID_WORLD_OBJECT_DELETE; + packetID = ID_WORLD_OBJECT_PLACE; } void PacketObjectPlace::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) From 17f66e4e905465582d91e6cc71a3330ed3270e1d Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sun, 23 Oct 2016 13:30:32 +0300 Subject: [PATCH 31/34] Implement ID_WORLD_OBJECT_PLACE --- apps/openmw/mwgui/hud.cpp | 16 ++++++++++++++++ apps/openmw/mwmp/Networking.cpp | 13 ++++++------- apps/openmw/mwworld/actiontake.cpp | 5 +---- .../Packets/World/PacketObjectPlace.cpp | 6 ++++++ 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index b5c8dc8bb..917fdb02b 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -1,5 +1,9 @@ #include "hud.hpp" +#include +#include "../mwmp/Main.hpp" +#include "../mwworld/cellstore.hpp" + #include #include #include @@ -51,6 +55,18 @@ namespace MWGui if (setNewOwner) dropped.getCellRef().setOwner(""); + // Added by tes3mp + mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); + event->cell = *dropped.getCell()->getCell(); + event->cellRef.mRefID = dropped.getCellRef().getRefId(); + event->cellRef.mRefNum = dropped.getCellRef().getRefNum(); + event->cellRef.mPos = dropped.getCellRef().getPosition(); + mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_PLACE)->Send(event); + + printf("Sending ID_WORLD_OBJECT_PLACE about %s\n%i\n", + event->cellRef.mRefID.c_str(), + event->cellRef.mRefNum); + return dropped; } diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index c29219f84..7ee853ff2 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -632,9 +632,15 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) WorldPacket *myPacket = worldController.GetPacket(packet->data[0]); WorldEvent *event = new WorldEvent(id); + myPacket->Packet(&bsIn, event, false); MWWorld::CellStore *ptrCellStore; + if (event->cell.isExterior()) + ptrCellStore = MWBase::Environment::get().getWorld()->getExterior(event->cell.mData.mX, event->cell.mData.mY); + else + ptrCellStore = MWBase::Environment::get().getWorld()->getInterior(event->cell.mName); + switch (packet->data[0]) { case ID_WORLD_OBJECT_PLACE: @@ -647,13 +653,6 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) } case ID_WORLD_OBJECT_DELETE: { - myPacket->Packet(&bsIn, event, false); - - if (event->cell.isExterior()) - ptrCellStore = MWBase::Environment::get().getWorld()->getExterior(event->cell.mData.mX, event->cell.mData.mY); - else - ptrCellStore = MWBase::Environment::get().getWorld()->getInterior(event->cell.mName); - LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Received ID_WORLD_OBJECT_DELETE"); LOG_APPEND(Log::LOG_WARN, "- cellRefId: %s, %i", event->cellRef.mRefID.c_str(), diff --git a/apps/openmw/mwworld/actiontake.cpp b/apps/openmw/mwworld/actiontake.cpp index 1fc6b04c9..5778fa308 100644 --- a/apps/openmw/mwworld/actiontake.cpp +++ b/apps/openmw/mwworld/actiontake.cpp @@ -2,14 +2,13 @@ #include #include "../mwmp/Main.hpp" +#include "../mwworld/cellstore.hpp" #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwbase/windowmanager.hpp" #include "../mwbase/mechanicsmanager.hpp" -#include "../mwworld/cellstore.hpp" - #include "class.hpp" #include "containerstore.hpp" @@ -25,9 +24,7 @@ namespace MWWorld // Added by tes3mp mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); - event->cell = *getTarget().getCell()->getCell(); - event->cellRef.mRefID = getTarget().getCellRef().getRefId(); event->cellRef.mRefNum = getTarget().getCellRef().getRefNum(); mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_DELETE)->Send(event); diff --git a/components/openmw-mp/Packets/World/PacketObjectPlace.cpp b/components/openmw-mp/Packets/World/PacketObjectPlace.cpp index 946c055c6..b9f50e168 100644 --- a/components/openmw-mp/Packets/World/PacketObjectPlace.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectPlace.cpp @@ -14,4 +14,10 @@ void PacketObjectPlace::Packet(RakNet::BitStream *bs, WorldEvent *event, bool se RW(event->cellRef.mRefID, send); RW(event->cellRef.mRefNum, send); + RW(event->cellRef.mPos, send); + + RW(event->cell.mData.mFlags, send); + RW(event->cell.mCellId.mIndex.mX, send); + RW(event->cell.mCellId.mIndex.mY, send); + RW(event->cell.mName, send); } From cbc132612a7a80a212a7f3f4ff6bd02b981ac03f Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sun, 23 Oct 2016 16:33:53 +0300 Subject: [PATCH 32/34] Use mRefNum.mIndex instead of just mRefNum and add extra debug --- apps/openmw-mp/Networking.cpp | 9 +++++++-- apps/openmw/mwgui/hud.cpp | 2 +- apps/openmw/mwmp/Networking.cpp | 14 ++++++++++---- apps/openmw/mwworld/actiontake.cpp | 8 ++++++-- .../openmw-mp/Packets/World/PacketObjectDelete.cpp | 2 +- .../openmw-mp/Packets/World/PacketObjectPlace.cpp | 2 +- 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index adfc7c992..de3ca9f0e 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -393,8 +393,13 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) myPacket->Read(event); - LOG_APPEND(Log::LOG_WARN, "- %s", event->cellRef.mRefID.c_str()); - LOG_APPEND(Log::LOG_WARN, "- %i", event->cellRef.mRefNum); + LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %i, %i, %i, %s", + event->cellRef.mRefID.c_str(), + event->cellRef.mRefNum.mIndex, + event->cell.mData.mFlags, + event->cell.mCellId.mIndex.mX, + event->cell.mCellId.mIndex.mY, + event->cell.mName.c_str()); myPacket->Send(event, true); diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 917fdb02b..09f610d98 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -65,7 +65,7 @@ namespace MWGui printf("Sending ID_WORLD_OBJECT_PLACE about %s\n%i\n", event->cellRef.mRefID.c_str(), - event->cellRef.mRefNum); + event->cellRef.mRefNum.mIndex); return dropped; } diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 7ee853ff2..752499b54 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -637,9 +637,13 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) MWWorld::CellStore *ptrCellStore; if (event->cell.isExterior()) + { ptrCellStore = MWBase::Environment::get().getWorld()->getExterior(event->cell.mData.mX, event->cell.mData.mY); + } else + { ptrCellStore = MWBase::Environment::get().getWorld()->getInterior(event->cell.mName); + } switch (packet->data[0]) { @@ -654,11 +658,13 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) case ID_WORLD_OBJECT_DELETE: { LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Received ID_WORLD_OBJECT_DELETE"); - LOG_APPEND(Log::LOG_WARN, "- cellRefId: %s, %i", + LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %i, %i, %i, %s", event->cellRef.mRefID.c_str(), - event->cellRef.mRefNum); - LOG_APPEND(Log::LOG_WARN, "- cell: %s", - event->cell.getDescription().c_str()); + event->cellRef.mRefNum.mIndex, + event->cell.mData.mFlags, + event->cell.mCellId.mIndex.mX, + event->cell.mCellId.mIndex.mY, + event->cell.mName.c_str()); MWWorld::Ptr ptrFound = ptrCellStore->searchByRefNum(event->cellRef.mRefNum); diff --git a/apps/openmw/mwworld/actiontake.cpp b/apps/openmw/mwworld/actiontake.cpp index 5778fa308..9f86a9063 100644 --- a/apps/openmw/mwworld/actiontake.cpp +++ b/apps/openmw/mwworld/actiontake.cpp @@ -29,9 +29,13 @@ namespace MWWorld event->cellRef.mRefNum = getTarget().getCellRef().getRefNum(); mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_DELETE)->Send(event); - printf("Sending ID_WORLD_OBJECT_DELETE about %s\n%i\n", + printf("Sending ID_WORLD_OBJECT_DELETE about\n- cellRef: %s, %i\n- cell: %i, %i, %i, %s", event->cellRef.mRefID.c_str(), - event->cellRef.mRefNum); + event->cellRef.mRefNum.mIndex, + event->cell.mData.mFlags, + event->cell.mCellId.mIndex.mX, + event->cell.mCellId.mIndex.mY, + event->cell.mName.c_str()); MWBase::Environment::get().getWorld()->deleteObject (getTarget()); } diff --git a/components/openmw-mp/Packets/World/PacketObjectDelete.cpp b/components/openmw-mp/Packets/World/PacketObjectDelete.cpp index 4b28cc46a..aaac1e4bc 100644 --- a/components/openmw-mp/Packets/World/PacketObjectDelete.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectDelete.cpp @@ -13,7 +13,7 @@ void PacketObjectDelete::Packet(RakNet::BitStream *bs, WorldEvent *event, bool s WorldPacket::Packet(bs, event, send); RW(event->cellRef.mRefID, send); - RW(event->cellRef.mRefNum, send); + RW(event->cellRef.mRefNum.mIndex, send); RW(event->cell.mData.mFlags, send); RW(event->cell.mCellId.mIndex.mX, send); diff --git a/components/openmw-mp/Packets/World/PacketObjectPlace.cpp b/components/openmw-mp/Packets/World/PacketObjectPlace.cpp index b9f50e168..52c96e177 100644 --- a/components/openmw-mp/Packets/World/PacketObjectPlace.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectPlace.cpp @@ -13,7 +13,7 @@ void PacketObjectPlace::Packet(RakNet::BitStream *bs, WorldEvent *event, bool se WorldPacket::Packet(bs, event, send); RW(event->cellRef.mRefID, send); - RW(event->cellRef.mRefNum, send); + RW(event->cellRef.mRefNum.mIndex, send); RW(event->cellRef.mPos, send); RW(event->cell.mData.mFlags, send); From 0a44bea91db98b03ea1665e47c2f08b464764126 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sun, 23 Oct 2016 16:55:30 +0300 Subject: [PATCH 33/34] Send cell coordinates in tes3mp using mData instead of mCellId.mIndex --- apps/openmw-mp/Networking.cpp | 7 ++----- apps/openmw-mp/Script/Functions/Translocations.cpp | 8 ++++---- apps/openmw/mwmp/DedicatedPlayer.cpp | 2 +- apps/openmw/mwmp/LocalPlayer.cpp | 8 ++++---- apps/openmw/mwmp/Networking.cpp | 5 +---- apps/openmw/mwworld/actiontake.cpp | 7 ++----- components/openmw-mp/Packets/Player/PacketCell.cpp | 6 ++---- components/openmw-mp/Packets/World/PacketObjectDelete.cpp | 4 ++-- components/openmw-mp/Packets/World/PacketObjectPlace.cpp | 4 ++-- 9 files changed, 20 insertions(+), 31 deletions(-) diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index de3ca9f0e..6b629fbe1 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -393,13 +393,10 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) myPacket->Read(event); - LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %i, %i, %i, %s", + LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s", event->cellRef.mRefID.c_str(), event->cellRef.mRefNum.mIndex, - event->cell.mData.mFlags, - event->cell.mCellId.mIndex.mX, - event->cell.mCellId.mIndex.mY, - event->cell.mName.c_str()); + event->cell.getDescription().c_str()); myPacket->Send(event, true); diff --git a/apps/openmw-mp/Script/Functions/Translocations.cpp b/apps/openmw-mp/Script/Functions/Translocations.cpp index 202b91095..2fa2964bc 100644 --- a/apps/openmw-mp/Script/Functions/Translocations.cpp +++ b/apps/openmw-mp/Script/Functions/Translocations.cpp @@ -108,8 +108,8 @@ void TranslocationFunctions::SetExterior(unsigned short pid, int x, int y) noexc player->GetCell()->mData.mFlags &= ~ESM::Cell::Interior; } - player->GetCell()->mCellId.mIndex.mX = x; - player->GetCell()->mCellId.mIndex.mY = y; + player->GetCell()->mData.mX = x; + player->GetCell()->mData.mY = y; mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_CELL)->Send(player, false); } @@ -118,14 +118,14 @@ int TranslocationFunctions::GetExteriorX(unsigned short pid) noexcept { Player *player; GET_PLAYER(pid, player,0); - return player->GetCell()->mCellId.mIndex.mX; + return player->GetCell()->mData.mX; } int TranslocationFunctions::GetExteriorY(unsigned short pid) noexcept { Player *player; GET_PLAYER(pid, player,0); - return player->GetCell()->mCellId.mIndex.mY; + return player->GetCell()->mData.mY; } bool TranslocationFunctions::IsInExterior(unsigned short pid) noexcept diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index 271b556ae..022ade342 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -427,7 +427,7 @@ void DedicatedPlayer::updateCell() MWWorld::CellStore *cellStore; if (cell.isExterior() == 1) - cellStore = world->getExterior(cell.mCellId.mIndex.mX, cell.mCellId.mIndex.mY); + cellStore = world->getExterior(cell.mData.mX, cell.mData.mY); else if (!cell.mName.empty()) cellStore = world->getInterior(cell.mName); // Go no further if cell data is invalid diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 5fe974e42..041698db1 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -308,11 +308,11 @@ void LocalPlayer::updateCell(bool forceUpdate) } else if (ptrCell->isExterior()) { - if (ptrCell->mCellId.mIndex.mX != GetCell()->mCellId.mIndex.mX) + if (ptrCell->mData.mX != GetCell()->mData.mX) { shouldUpdate = true; } - else if (ptrCell->mCellId.mIndex.mY != GetCell()->mCellId.mIndex.mY) + else if (ptrCell->mData.mY != GetCell()->mData.mY) { shouldUpdate = true; } @@ -613,8 +613,8 @@ void LocalPlayer::setCell() world->getPlayer().setTeleported(true); - int x = GetCell()->mCellId.mIndex.mX; - int y = GetCell()->mCellId.mIndex.mY; + int x = GetCell()->mData.mX; + int y = GetCell()->mData.mY; if (GetCell()->isExterior()) { diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 752499b54..afa0ff799 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -661,10 +661,7 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %i, %i, %i, %s", event->cellRef.mRefID.c_str(), event->cellRef.mRefNum.mIndex, - event->cell.mData.mFlags, - event->cell.mCellId.mIndex.mX, - event->cell.mCellId.mIndex.mY, - event->cell.mName.c_str()); + event->cell.getDescription().c_str()); MWWorld::Ptr ptrFound = ptrCellStore->searchByRefNum(event->cellRef.mRefNum); diff --git a/apps/openmw/mwworld/actiontake.cpp b/apps/openmw/mwworld/actiontake.cpp index 9f86a9063..d057ad071 100644 --- a/apps/openmw/mwworld/actiontake.cpp +++ b/apps/openmw/mwworld/actiontake.cpp @@ -29,13 +29,10 @@ namespace MWWorld event->cellRef.mRefNum = getTarget().getCellRef().getRefNum(); mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_DELETE)->Send(event); - printf("Sending ID_WORLD_OBJECT_DELETE about\n- cellRef: %s, %i\n- cell: %i, %i, %i, %s", + printf("Sending ID_WORLD_OBJECT_DELETE about\n- cellRef: %s, %i\n- cell: %s", event->cellRef.mRefID.c_str(), event->cellRef.mRefNum.mIndex, - event->cell.mData.mFlags, - event->cell.mCellId.mIndex.mX, - event->cell.mCellId.mIndex.mY, - event->cell.mName.c_str()); + event->cell.getDescription().c_str()); MWBase::Environment::get().getWorld()->deleteObject (getTarget()); } diff --git a/components/openmw-mp/Packets/Player/PacketCell.cpp b/components/openmw-mp/Packets/Player/PacketCell.cpp index 991774382..67b3ed43f 100644 --- a/components/openmw-mp/Packets/Player/PacketCell.cpp +++ b/components/openmw-mp/Packets/Player/PacketCell.cpp @@ -18,9 +18,7 @@ void mwmp::PacketCell::Packet(RakNet::BitStream *bs, mwmp::BasePlayer *player, b PlayerPacket::Packet(bs, player, send); RW(player->GetCell()->mData.mFlags, send); - - RW(player->GetCell()->mCellId.mIndex.mX, send); - RW(player->GetCell()->mCellId.mIndex.mY, send); - + RW(player->GetCell()->mData.mX, send); + RW(player->GetCell()->mData.mY, send); RW(player->GetCell()->mName, send); } diff --git a/components/openmw-mp/Packets/World/PacketObjectDelete.cpp b/components/openmw-mp/Packets/World/PacketObjectDelete.cpp index aaac1e4bc..510f079c7 100644 --- a/components/openmw-mp/Packets/World/PacketObjectDelete.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectDelete.cpp @@ -16,7 +16,7 @@ void PacketObjectDelete::Packet(RakNet::BitStream *bs, WorldEvent *event, bool s RW(event->cellRef.mRefNum.mIndex, send); RW(event->cell.mData.mFlags, send); - RW(event->cell.mCellId.mIndex.mX, send); - RW(event->cell.mCellId.mIndex.mY, send); + RW(event->cell.mData.mX, send); + RW(event->cell.mData.mY, send); RW(event->cell.mName, send); } diff --git a/components/openmw-mp/Packets/World/PacketObjectPlace.cpp b/components/openmw-mp/Packets/World/PacketObjectPlace.cpp index 52c96e177..d87907352 100644 --- a/components/openmw-mp/Packets/World/PacketObjectPlace.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectPlace.cpp @@ -17,7 +17,7 @@ void PacketObjectPlace::Packet(RakNet::BitStream *bs, WorldEvent *event, bool se RW(event->cellRef.mPos, send); RW(event->cell.mData.mFlags, send); - RW(event->cell.mCellId.mIndex.mX, send); - RW(event->cell.mCellId.mIndex.mY, send); + RW(event->cell.mData.mX, send); + RW(event->cell.mData.mY, send); RW(event->cell.mName, send); } From 025a847fd1c85bd5e145d0f65f5a751ce730a268 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sun, 23 Oct 2016 17:03:47 +0300 Subject: [PATCH 34/34] Send an ID_WORLD_OBJECT_DELETE whenever ingame scripts delete objects --- apps/openmw/mwscript/miscextensions.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 1830be693..31a8126b0 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -2,6 +2,9 @@ #include +#include +#include "../mwmp/Main.hpp" + #include #include #include @@ -668,7 +671,16 @@ namespace MWScript runtime.pop(); if (parameter == 1) + { + // Added by tes3mp + mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); + event->cell = *ptr.getCell()->getCell(); + event->cellRef.mRefID = ptr.getCellRef().getRefId(); + event->cellRef.mRefNum = ptr.getCellRef().getRefNum(); + mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_DELETE)->Send(event); + MWBase::Environment::get().getWorld()->deleteObject(ptr); + } else if (parameter == 0) MWBase::Environment::get().getWorld()->undeleteObject(ptr); else