From e8a5fd1cd001e7a84ca8de31fd63af4a2a325474 Mon Sep 17 00:00:00 2001 From: Koncord Date: Sat, 1 Apr 2017 02:36:24 +0800 Subject: [PATCH] [Server] Move all message handlers to PlayerProcessors --- apps/openmw-mp/CMakeLists.txt | 1 + apps/openmw-mp/Networking.cpp | 369 +----------------- apps/openmw-mp/init_processors.cpp | 52 +++ apps/openmw-mp/init_processors.hpp | 11 + .../openmw-mp/processors/ProcessorChatMsg.hpp | 43 ++ .../processors/ProcessorGUIMessageBox.hpp | 36 ++ apps/openmw-mp/processors/ProcessorLevel.hpp | 35 ++ .../processors/ProcessorPlayerAttack.hpp | 59 +++ .../processors/ProcessorPlayerAttribute.hpp | 37 ++ .../processors/ProcessorPlayerCellChange.hpp | 93 +++++ .../processors/ProcessorPlayerCellState.hpp | 41 ++ .../processors/ProcessorPlayerCharClass.hpp | 32 ++ .../processors/ProcessorPlayerCharGen.hpp | 37 ++ .../processors/ProcessorPlayerDeath.hpp | 52 +++ .../processors/ProcessorPlayerDrawState.hpp | 37 ++ .../ProcessorPlayerDynamicStats.hpp | 34 ++ .../processors/ProcessorPlayerEquipment.hpp | 36 ++ .../processors/ProcessorPlayerInventory.hpp | 34 ++ .../processors/ProcessorPlayerJournal.hpp | 33 ++ .../processors/ProcessorPlayerPos.hpp | 35 ++ .../processors/ProcessorPlayerResurrect.hpp | 37 ++ .../processors/ProcessorPlayerSkill.hpp | 35 ++ .../processors/ProcessorPlayerSpellbook.hpp | 33 ++ 23 files changed, 850 insertions(+), 362 deletions(-) create mode 100644 apps/openmw-mp/init_processors.cpp create mode 100644 apps/openmw-mp/init_processors.hpp create mode 100644 apps/openmw-mp/processors/ProcessorChatMsg.hpp create mode 100644 apps/openmw-mp/processors/ProcessorGUIMessageBox.hpp create mode 100644 apps/openmw-mp/processors/ProcessorLevel.hpp create mode 100644 apps/openmw-mp/processors/ProcessorPlayerAttack.hpp create mode 100644 apps/openmw-mp/processors/ProcessorPlayerAttribute.hpp create mode 100644 apps/openmw-mp/processors/ProcessorPlayerCellChange.hpp create mode 100644 apps/openmw-mp/processors/ProcessorPlayerCellState.hpp create mode 100644 apps/openmw-mp/processors/ProcessorPlayerCharClass.hpp create mode 100644 apps/openmw-mp/processors/ProcessorPlayerCharGen.hpp create mode 100644 apps/openmw-mp/processors/ProcessorPlayerDeath.hpp create mode 100644 apps/openmw-mp/processors/ProcessorPlayerDrawState.hpp create mode 100644 apps/openmw-mp/processors/ProcessorPlayerDynamicStats.hpp create mode 100644 apps/openmw-mp/processors/ProcessorPlayerEquipment.hpp create mode 100644 apps/openmw-mp/processors/ProcessorPlayerInventory.hpp create mode 100644 apps/openmw-mp/processors/ProcessorPlayerJournal.hpp create mode 100644 apps/openmw-mp/processors/ProcessorPlayerPos.hpp create mode 100644 apps/openmw-mp/processors/ProcessorPlayerResurrect.hpp create mode 100644 apps/openmw-mp/processors/ProcessorPlayerSkill.hpp create mode 100644 apps/openmw-mp/processors/ProcessorPlayerSpellbook.hpp diff --git a/apps/openmw-mp/CMakeLists.txt b/apps/openmw-mp/CMakeLists.txt index c4d65f179..a8c1fc8ae 100644 --- a/apps/openmw-mp/CMakeLists.txt +++ b/apps/openmw-mp/CMakeLists.txt @@ -80,6 +80,7 @@ set(SERVER Script/Functions/Cells.cpp Script/Functions/World.cpp Script/Functions/Miscellaneous.cpp PlayerProcessor.cpp + init_processors.cpp Script/API/TimerAPI.cpp Script/API/PublicFnAPI.cpp ${PawnScript_Sources} diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index ee01f312d..81f0e3961 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -3,6 +3,7 @@ // #include "Player.hpp" +#include "init_processors.hpp" #include #include #include @@ -16,8 +17,10 @@ #include "Networking.hpp" #include "MasterClient.hpp" #include "Cell.hpp" +#include "PlayerProcessor.hpp" #include #include +#include using namespace mwmp; using namespace std; @@ -45,6 +48,8 @@ Networking::Networking(RakNet::RakPeerInterface *peer) Script::Call(); serverPassword = TES3MP_DEFAULT_PASSW; + + init_processors(); } Networking::~Networking() @@ -140,370 +145,10 @@ void Networking::processPlayerPacket(RakNet::Packet *packet) return; } - switch (packet->data[0]) - { - case ID_PLAYER_BASEINFO: - { - /*LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_BASEINFO about %s", player->npc.mName.c_str()); - - myPacket->Read(player); - myPacket->Send(player, true);*/ - - break; - } - case ID_PLAYER_POS: - { - //DEBUG_PRINTF("ID_PLAYER_POS \n"); - - if (!player->creatureStats.mDead) - { - myPacket->setPlayer(player); - myPacket->Read(); - //myPacket->Send(player, true); //send to other clients - - player->sendToLoaded(myPacket); - - } - - break; - } - case ID_PLAYER_CELL_CHANGE: - { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_CELL_CHANGE from %s", player->npc.mName.c_str()); - - if (!player->creatureStats.mDead) - { - myPacket->setPlayer(player); - myPacket->Read(); - - LOG_APPEND(Log::LOG_INFO, "- Moved to %s", player->cell.getDescription().c_str()); - - player->forEachLoaded([this](Player *pl, Player *other) { - - if (other == nullptr) - { - LOG_APPEND(Log::LOG_INFO, "- Tried to exchange information with nullptr!"); - LOG_APPEND(Log::LOG_INFO, "- Please report this to a developer"); - } - else - { - LOG_APPEND(Log::LOG_INFO, "- Started information exchange with %s", other->npc.mName.c_str()); - - playerController->GetPacket(ID_PLAYER_DYNAMICSTATS)->setPlayer(other); - playerController->GetPacket(ID_PLAYER_ATTRIBUTE)->setPlayer(other); - playerController->GetPacket(ID_PLAYER_POS)->setPlayer(other); - playerController->GetPacket(ID_PLAYER_SKILL)->setPlayer(other); - playerController->GetPacket(ID_PLAYER_EQUIPMENT)->setPlayer(other); - playerController->GetPacket(ID_PLAYER_DRAWSTATE)->setPlayer(other); - - playerController->GetPacket(ID_PLAYER_DYNAMICSTATS)->Send(pl->guid); - playerController->GetPacket(ID_PLAYER_ATTRIBUTE)->Send(pl->guid); - playerController->GetPacket(ID_PLAYER_POS)->Send(pl->guid); - playerController->GetPacket(ID_PLAYER_SKILL)->Send(pl->guid); - playerController->GetPacket(ID_PLAYER_EQUIPMENT)->Send(pl->guid); - playerController->GetPacket(ID_PLAYER_DRAWSTATE)->Send(pl->guid); - - playerController->GetPacket(ID_PLAYER_DYNAMICSTATS)->setPlayer(pl); - playerController->GetPacket(ID_PLAYER_ATTRIBUTE)->setPlayer(pl); - playerController->GetPacket(ID_PLAYER_SKILL)->setPlayer(pl); - playerController->GetPacket(ID_PLAYER_EQUIPMENT)->setPlayer(pl); - playerController->GetPacket(ID_PLAYER_DRAWSTATE)->setPlayer(pl); - - playerController->GetPacket(ID_PLAYER_DYNAMICSTATS)->Send(other->guid); - playerController->GetPacket(ID_PLAYER_ATTRIBUTE)->Send(other->guid); - playerController->GetPacket(ID_PLAYER_SKILL)->Send(other->guid); - playerController->GetPacket(ID_PLAYER_EQUIPMENT)->Send(other->guid); - playerController->GetPacket(ID_PLAYER_DRAWSTATE)->Send(other->guid); - - LOG_APPEND(Log::LOG_INFO, "- Finished information exchange with %s", other->npc.mName.c_str()); - } - }); - - playerController->GetPacket(ID_PLAYER_POS)->setPlayer(player); - playerController->GetPacket(ID_PLAYER_POS)->Send(); - myPacket->setPlayer(player); - myPacket->Send(true); //send to other clients - - Script::Call(player->getId()); - - LOG_APPEND(Log::LOG_INFO, "- Finished processing ID_PLAYER_CELL_CHANGE", player->cell.getDescription().c_str()); - } - else - LOG_APPEND(Log::LOG_INFO, "- Ignored because %s is dead", player->npc.mName.c_str()); - - break; - } - case ID_PLAYER_CELL_STATE: - { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_CELL_STATE from %s", player->npc.mName.c_str()); - - myPacket->setPlayer(player); - myPacket->Read(); - - CellController::get()->update(player); - - Script::Call(player->getId()); - - break; - } - case ID_PLAYER_ATTRIBUTE: - { - - if (!player->creatureStats.mDead) - { - myPacket->setPlayer(player); - myPacket->Read(); - //myPacket->Send(player, true); - - player->sendToLoaded(myPacket); - - Script::Call(player->getId()); - } - - break; - } - case ID_PLAYER_SKILL: - { - - if (!player->creatureStats.mDead) - { - myPacket->setPlayer(player); - myPacket->Read(); - //myPacket->Send(player, true); - player->sendToLoaded(myPacket); - - Script::Call(player->getId()); - } - - break; - } - case ID_PLAYER_LEVEL: - { - - if (!player->creatureStats.mDead) - { - myPacket->setPlayer(player); - myPacket->Read(); - //myPacket->Send(player, true); - - Script::Call(player->getId()); - } - - break; - } - case ID_PLAYER_EQUIPMENT: - { - DEBUG_PRINTF("ID_PLAYER_EQUIPMENT\n"); - - myPacket->setPlayer(player); - myPacket->Read(); - //myPacket->Send(player, true); - - player->sendToLoaded(myPacket); - - Script::Call(player->getId()); - - break; - } - - case ID_PLAYER_INVENTORY: - { - DEBUG_PRINTF("ID_PLAYER_INVENTORY\n"); - - myPacket->setPlayer(player); - myPacket->Read(); - - Script::Call(player->getId()); - - break; - } - - case ID_PLAYER_SPELLBOOK: - { - DEBUG_PRINTF("ID_PLAYER_SPELLBOOK\n"); - - myPacket->setPlayer(player); - myPacket->Read(); - - Script::Call(player->getId()); - - break; - } - - case ID_PLAYER_JOURNAL: - { - DEBUG_PRINTF("ID_PLAYER_JOURNAL\n"); - - myPacket->setPlayer(player); - myPacket->Read(); - - Script::Call(player->getId()); - break; - } - - case ID_PLAYER_ATTACK: - { - DEBUG_PRINTF("ID_PLAYER_ATTACK\n"); - - if (!player->creatureStats.mDead) - { - - myPacket->setPlayer(player); - myPacket->Read(); - - Player *target = Players::getPlayer(player->attack.target); - - if (target == nullptr) - target = player; - - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Player: %s attacked %s state: %d", player->npc.mName.c_str(), - target->npc.mName.c_str(), player->attack.pressed == 1); - if (player->attack.pressed == 0) - { - LOG_APPEND(Log::LOG_VERBOSE, "success: %d", player->attack.success == 1); - if (player->attack.success == 1) - { - LOG_APPEND(Log::LOG_VERBOSE, "damage: %d", player->attack.damage == 1); - target->setLastAttackerId(player->getId()); - target->setLastAttackerTime(std::chrono::steady_clock::now()); - } - } - - //myPacket->Send(player, true); - player->sendToLoaded(myPacket); - playerController->GetPacket(ID_PLAYER_DYNAMICSTATS)->RequestData(player->attack.target); - } - break; - } - - case ID_PLAYER_DYNAMICSTATS: - { - DEBUG_PRINTF("ID_PLAYER_DYNAMICSTATS\n"); - - myPacket->setPlayer(player); - myPacket->Read(); - //myPacket->Send(player, true); - - player->sendToLoaded(myPacket); - - break; - } - - case ID_PLAYER_DEATH: - { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_DEATH from %s", player->npc.mName.c_str()); - - Player *killer = Players::getPlayer(player->getLastAttackerId()); - - short reason = 0; // unknown; - double secondsSinceLastAttacker = chrono::duration_cast>( - chrono::steady_clock::now() - player->getLastAttackerTime()).count(); - - if (!killer) - killer = player; - - if (secondsSinceLastAttacker < 3.0f) - reason = 1; // killed - else - reason = 2; //suicide - - player->resetLastAttacker(); - - player->creatureStats.mDead = true; - - myPacket->setPlayer(player); - myPacket->Send(true); - - Script::Call(player->getId(), reason, killer->getId()); - - break; - } - - case ID_PLAYER_RESURRECT: - { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_RESURRECT from %s", player->npc.mName.c_str()); - - player->creatureStats.mDead = false; - - myPacket->setPlayer(player); - myPacket->Send(true); - - Script::Call(player->getId()); - - break; - } - - case ID_PLAYER_DRAWSTATE: - { - DEBUG_PRINTF("ID_PLAYER_DRAWSTATE\n"); - - myPacket->setPlayer(player); - myPacket->Read(); - //myPacket->Send(player, true); - - player->sendToLoaded(myPacket); - - break; - } - - case ID_CHAT_MESSAGE: - { - DEBUG_PRINTF("ID_CHAT_MESSAGE\n"); - - myPacket->setPlayer(player); - myPacket->Read(); - 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->setPlayer(player); - myPacket->Send(false); - myPacket->Send(true); - } - break; - } - case ID_PLAYER_CHARGEN: - { - DEBUG_PRINTF("ID_PLAYER_CHARGEN\n"); - - myPacket->setPlayer(player); - myPacket->Read(); - - if (player->charGenStage.current == player->charGenStage.end && player->charGenStage.current != 0) - Script::Call(player->getId()); - break; - } - - case ID_GUI_MESSAGEBOX: - { - DEBUG_PRINTF("ID_GUI_MESSAGEBOX\n"); - - myPacket->setPlayer(player); - myPacket->Read(); - - Script::Call(player->getId(), (int)player->guiMessageBox.id, - player->guiMessageBox.data.c_str()); - break; - } - - case ID_PLAYER_CHARCLASS: - { - DEBUG_PRINTF("ID_PLAYER_CHARCLASS\n"); - - myPacket->setPlayer(player); - myPacket->Read(); - break; - } - - default: + if(!PlayerProcessor::Process(*packet)) LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Unhandled PlayerPacket with identifier %i has arrived", packet->data[0]); - break; - } + } void Networking::processWorldPacket(RakNet::Packet *packet) diff --git a/apps/openmw-mp/init_processors.cpp b/apps/openmw-mp/init_processors.cpp new file mode 100644 index 000000000..1893d5e73 --- /dev/null +++ b/apps/openmw-mp/init_processors.cpp @@ -0,0 +1,52 @@ +// +// Created by koncord on 31.03.17. +// + +#include "init_processors.hpp" + +#include "PlayerProcessor.hpp" +#include "processors/ProcessorPlayerPos.hpp" +#include "processors/ProcessorPlayerCellChange.hpp" +#include "processors/ProcessorPlayerCellState.hpp" +#include "processors/ProcessorPlayerAttribute.hpp" +#include "processors/ProcessorPlayerSkill.hpp" +#include "processors/ProcessorLevel.hpp" +#include "processors/ProcessorPlayerEquipment.hpp" +#include "processors/ProcessorPlayerInventory.hpp" +#include "processors/ProcessorPlayerSpellbook.hpp" +#include "processors/ProcessorPlayerJournal.hpp" +#include "processors/ProcessorPlayerAttack.hpp" +#include "processors/ProcessorPlayerDynamicStats.hpp" +#include "processors/ProcessorPlayerDeath.hpp" +#include "processors/ProcessorPlayerResurrect.hpp" +#include "processors/ProcessorPlayerDrawState.hpp" +#include "processors/ProcessorChatMsg.hpp" +#include "processors/ProcessorPlayerCharGen.hpp" +#include "processors/ProcessorGUIMessageBox.hpp" +#include "processors/ProcessorPlayerCharClass.hpp" + + +using namespace mwmp; + +void init_processors() +{ + PlayerProcessor::AddProcessor(new ProcessorPlayerPos()); + PlayerProcessor::AddProcessor(new ProcessorPlayerCellChange()); + PlayerProcessor::AddProcessor(new ProcessorPlayerCellState()); + PlayerProcessor::AddProcessor(new ProcessorPlayerAttribute()); + PlayerProcessor::AddProcessor(new ProcessorPlayerSkill()); + PlayerProcessor::AddProcessor(new ProcessorLevel()); + PlayerProcessor::AddProcessor(new ProcessorPlayerEquipment()); + PlayerProcessor::AddProcessor(new ProcessorPlayerInventory()); + PlayerProcessor::AddProcessor(new ProcessorPlayerSpellbook()); + PlayerProcessor::AddProcessor(new ProcessorPlayerJournal()); + PlayerProcessor::AddProcessor(new ProcessorPlayerAttack()); + PlayerProcessor::AddProcessor(new ProcessorPlayerDynamicStats()); + PlayerProcessor::AddProcessor(new ProcessorPlayerDeath()); + PlayerProcessor::AddProcessor(new ProcessorPlayerResurrect()); + PlayerProcessor::AddProcessor(new ProcessorPlayerDrawState()); + PlayerProcessor::AddProcessor(new ProcessorChatMsg()); + PlayerProcessor::AddProcessor(new ProcessorPlayerCharGen()); + PlayerProcessor::AddProcessor(new ProcessorGUIMessageBox()); + PlayerProcessor::AddProcessor(new ProcessorPlayerCharClass()); +} \ No newline at end of file diff --git a/apps/openmw-mp/init_processors.hpp b/apps/openmw-mp/init_processors.hpp new file mode 100644 index 000000000..5c1ea410d --- /dev/null +++ b/apps/openmw-mp/init_processors.hpp @@ -0,0 +1,11 @@ +// +// Created by koncord on 31.03.17. +// + +#ifndef OPENMW_INIT_PROCESSORS_HPP +#define OPENMW_INIT_PROCESSORS_HPP + +void init_processors(); + + +#endif //OPENMW_INIT_PROCESSORS_HPP diff --git a/apps/openmw-mp/processors/ProcessorChatMsg.hpp b/apps/openmw-mp/processors/ProcessorChatMsg.hpp new file mode 100644 index 000000000..4200cfee3 --- /dev/null +++ b/apps/openmw-mp/processors/ProcessorChatMsg.hpp @@ -0,0 +1,43 @@ +// +// Created by koncord on 01.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERCHATMSG_HPP +#define OPENMW_PROCESSORPLAYERCHATMSG_HPP + + +#include "../PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorChatMsg : public PlayerProcessor + { + public: + ProcessorChatMsg() + { + BPP_INIT(ID_CHAT_MESSAGE) + } + + void Do(PlayerPacket &packet, Player &player) override + { + DEBUG_PRINTF(strPacketID.c_str()); + + packet.setPlayer(&player); + packet.Read(); + 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"; + + packet.setPlayer(&player); + packet.Send(false); + packet.Send(true); + } + } + }; +} + +#endif //OPENMW_PROCESSORPLAYERCHATMSG_HPP diff --git a/apps/openmw-mp/processors/ProcessorGUIMessageBox.hpp b/apps/openmw-mp/processors/ProcessorGUIMessageBox.hpp new file mode 100644 index 000000000..9d97701cc --- /dev/null +++ b/apps/openmw-mp/processors/ProcessorGUIMessageBox.hpp @@ -0,0 +1,36 @@ +// +// Created by koncord on 01.04.17. +// + +#ifndef OPENMW_PROCESSORGUIMESSAGEBOX_HPP +#define OPENMW_PROCESSORGUIMESSAGEBOX_HPP + + +#include "../PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorGUIMessageBox : public PlayerProcessor + { + public: + ProcessorGUIMessageBox() + { + BPP_INIT(ID_GUI_MESSAGEBOX) + } + + void Do(PlayerPacket &packet, Player &player) override + { + DEBUG_PRINTF(strPacketID.c_str()); + + packet.setPlayer(&player); + packet.Read(); + + Script::Call(player.getId(), (int)player.guiMessageBox.id, + player.guiMessageBox.data.c_str()); + } + }; +} + + + +#endif //OPENMW_PROCESSORGUIMESSAGEBOX_HPP diff --git a/apps/openmw-mp/processors/ProcessorLevel.hpp b/apps/openmw-mp/processors/ProcessorLevel.hpp new file mode 100644 index 000000000..5308c979e --- /dev/null +++ b/apps/openmw-mp/processors/ProcessorLevel.hpp @@ -0,0 +1,35 @@ +// +// Created by koncord on 01.04.17. +// + +#ifndef OPENMW_PROCESSORLEVEL_HPP +#define OPENMW_PROCESSORLEVEL_HPP + + +#include "../PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorLevel : public PlayerProcessor + { + public: + ProcessorLevel() + { + BPP_INIT(ID_PLAYER_LEVEL) + } + + void Do(PlayerPacket &packet, Player &player) override + { + if (!player.creatureStats.mDead) + { + packet.setPlayer(&player); + packet.Read(); + //packet.Send(&player, true); + + Script::Call(player.getId()); + } + } + }; +} + +#endif //OPENMW_PROCESSORLEVEL_HPP diff --git a/apps/openmw-mp/processors/ProcessorPlayerAttack.hpp b/apps/openmw-mp/processors/ProcessorPlayerAttack.hpp new file mode 100644 index 000000000..3f0d4c1b9 --- /dev/null +++ b/apps/openmw-mp/processors/ProcessorPlayerAttack.hpp @@ -0,0 +1,59 @@ +// +// Created by koncord on 01.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERATTACK_HPP +#define OPENMW_PROCESSORPLAYERATTACK_HPP + + +#include "../PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerAttack : public PlayerProcessor + { + PlayerPacketController *playerController; + public: + ProcessorPlayerAttack() + { + BPP_INIT(ID_PLAYER_ATTACK) + playerController = Networking::get().getPlayerController(); + } + + void Do(PlayerPacket &packet, Player &player) override + { + DEBUG_PRINTF(strPacketID.c_str()); + + if (!player.creatureStats.mDead) + { + + packet.setPlayer(&player); + packet.Read(); + + Player *target = Players::getPlayer(player.attack.target); + + if (target == nullptr) + target = &player; + + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Player: %s attacked %s state: %d", player.npc.mName.c_str(), + target->npc.mName.c_str(), player.attack.pressed == 1); + if (player.attack.pressed == 0) + { + LOG_APPEND(Log::LOG_VERBOSE, "success: %d", player.attack.success == 1); + if (player.attack.success == 1) + { + LOG_APPEND(Log::LOG_VERBOSE, "damage: %d", player.attack.damage == 1); + target->setLastAttackerId(player.getId()); + target->setLastAttackerTime(std::chrono::steady_clock::now()); + } + } + + //packet.Send(player, true); + player.sendToLoaded(&packet); + playerController->GetPacket(ID_PLAYER_DYNAMICSTATS)->RequestData(player.attack.target); + } + } + }; +} + +#endif //OPENMW_PROCESSORPLAYERATTACK_HPP diff --git a/apps/openmw-mp/processors/ProcessorPlayerAttribute.hpp b/apps/openmw-mp/processors/ProcessorPlayerAttribute.hpp new file mode 100644 index 000000000..78a7182f4 --- /dev/null +++ b/apps/openmw-mp/processors/ProcessorPlayerAttribute.hpp @@ -0,0 +1,37 @@ +// +// Created by koncord on 01.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERATTRIBUTE_HPP +#define OPENMW_PROCESSORPLAYERATTRIBUTE_HPP + + +#include "../PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerAttribute : public PlayerProcessor + { + public: + ProcessorPlayerAttribute() + { + BPP_INIT(ID_PLAYER_ATTRIBUTE) + } + + void Do(PlayerPacket &packet, Player &player) override + { + if (!player.creatureStats.mDead) + { + packet.setPlayer(&player); + packet.Read(); + //myPacket->Send(player, true); + + player.sendToLoaded(&packet); + + Script::Call(player.getId()); + } + } + }; +} + +#endif //OPENMW_PROCESSORPLAYERATTRIBUTE_HPP diff --git a/apps/openmw-mp/processors/ProcessorPlayerCellChange.hpp b/apps/openmw-mp/processors/ProcessorPlayerCellChange.hpp new file mode 100644 index 000000000..88bddcea0 --- /dev/null +++ b/apps/openmw-mp/processors/ProcessorPlayerCellChange.hpp @@ -0,0 +1,93 @@ +// +// Created by koncord on 01.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERCELLCHANGE_HPP +#define OPENMW_PROCESSORPLAYERCELLCHANGE_HPP + +#include "../PlayerProcessor.hpp" +#include "../Networking.hpp" +#include "../Script/Script.hpp" +#include + +namespace mwmp +{ + class ProcessorPlayerCellChange : public PlayerProcessor + { + PlayerPacketController *playerController; + public: + ProcessorPlayerCellChange() + { + BPP_INIT(ID_PLAYER_CELL_CHANGE) + playerController = Networking::get().getPlayerController(); + } + + void Do(PlayerPacket &packet, Player &player) override + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_CELL_CHANGE from %s", player.npc.mName.c_str()); + + if (!player.creatureStats.mDead) + { + packet.setPlayer(&player); + packet.Read(); + + LOG_APPEND(Log::LOG_INFO, "- Moved to %s", player.cell.getDescription().c_str()); + + player.forEachLoaded([this](Player *pl, Player *other) { + + if (other == nullptr) + { + LOG_APPEND(Log::LOG_INFO, "- Tried to exchange information with nullptr!"); + LOG_APPEND(Log::LOG_INFO, "- Please report this to a developer"); + } + else + { + LOG_APPEND(Log::LOG_INFO, "- Started information exchange with %s", other->npc.mName.c_str()); + + playerController->GetPacket(ID_PLAYER_DYNAMICSTATS)->setPlayer(other); + playerController->GetPacket(ID_PLAYER_ATTRIBUTE)->setPlayer(other); + playerController->GetPacket(ID_PLAYER_POS)->setPlayer(other); + playerController->GetPacket(ID_PLAYER_SKILL)->setPlayer(other); + playerController->GetPacket(ID_PLAYER_EQUIPMENT)->setPlayer(other); + playerController->GetPacket(ID_PLAYER_DRAWSTATE)->setPlayer(other); + + playerController->GetPacket(ID_PLAYER_DYNAMICSTATS)->Send(pl->guid); + playerController->GetPacket(ID_PLAYER_ATTRIBUTE)->Send(pl->guid); + playerController->GetPacket(ID_PLAYER_POS)->Send(pl->guid); + playerController->GetPacket(ID_PLAYER_SKILL)->Send(pl->guid); + playerController->GetPacket(ID_PLAYER_EQUIPMENT)->Send(pl->guid); + playerController->GetPacket(ID_PLAYER_DRAWSTATE)->Send(pl->guid); + + playerController->GetPacket(ID_PLAYER_DYNAMICSTATS)->setPlayer(pl); + playerController->GetPacket(ID_PLAYER_ATTRIBUTE)->setPlayer(pl); + playerController->GetPacket(ID_PLAYER_SKILL)->setPlayer(pl); + playerController->GetPacket(ID_PLAYER_EQUIPMENT)->setPlayer(pl); + playerController->GetPacket(ID_PLAYER_DRAWSTATE)->setPlayer(pl); + + playerController->GetPacket(ID_PLAYER_DYNAMICSTATS)->Send(other->guid); + playerController->GetPacket(ID_PLAYER_ATTRIBUTE)->Send(other->guid); + playerController->GetPacket(ID_PLAYER_SKILL)->Send(other->guid); + playerController->GetPacket(ID_PLAYER_EQUIPMENT)->Send(other->guid); + playerController->GetPacket(ID_PLAYER_DRAWSTATE)->Send(other->guid); + + LOG_APPEND(Log::LOG_INFO, "- Finished information exchange with %s", other->npc.mName.c_str()); + } + }); + + playerController->GetPacket(ID_PLAYER_POS)->setPlayer(&player); + playerController->GetPacket(ID_PLAYER_POS)->Send(); + packet.setPlayer(&player); + packet.Send(true); //send to other clients + + Script::Call(player.getId()); + + LOG_APPEND(Log::LOG_INFO, "- Finished processing ID_PLAYER_CELL_CHANGE", player.cell.getDescription().c_str()); + } + else + LOG_APPEND(Log::LOG_INFO, "- Ignored because %s is dead", player.npc.mName.c_str()); + } + }; +} + + +#endif //OPENMW_PROCESSORPLAYERCELLCHANGE_HPP diff --git a/apps/openmw-mp/processors/ProcessorPlayerCellState.hpp b/apps/openmw-mp/processors/ProcessorPlayerCellState.hpp new file mode 100644 index 000000000..56726cc40 --- /dev/null +++ b/apps/openmw-mp/processors/ProcessorPlayerCellState.hpp @@ -0,0 +1,41 @@ +// +// Created by koncord on 01.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERCELLSTATE_HPP +#define OPENMW_PROCESSORPLAYERCELLSTATE_HPP + + +#include "../PlayerProcessor.hpp" +#include "../Networking.hpp" +#include "../Script/Script.hpp" +#include + +namespace mwmp +{ + class ProcessorPlayerCellState : public PlayerProcessor + { + PlayerPacketController *playerController; + public: + ProcessorPlayerCellState() + { + BPP_INIT(ID_PLAYER_CELL_STATE) + playerController = Networking::get().getPlayerController(); + } + + void Do(PlayerPacket &packet, Player &player) override + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received %s from %s", strPacketID, player.npc.mName.c_str()); + + packet.setPlayer(&player); + packet.Read(); + + CellController::get()->update(&player); + + Script::Call(player.getId()); + } + }; +} + + +#endif //OPENMW_PROCESSORPLAYERCELLSTATE_HPP diff --git a/apps/openmw-mp/processors/ProcessorPlayerCharClass.hpp b/apps/openmw-mp/processors/ProcessorPlayerCharClass.hpp new file mode 100644 index 000000000..dfd471d0d --- /dev/null +++ b/apps/openmw-mp/processors/ProcessorPlayerCharClass.hpp @@ -0,0 +1,32 @@ +// +// Created by koncord on 01.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERCHARCLASS_HPP +#define OPENMW_PROCESSORPLAYERCHARCLASS_HPP + + +#include "../PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerCharClass : public PlayerProcessor + { + public: + ProcessorPlayerCharClass() + { + BPP_INIT(ID_PLAYER_CHARCLASS) + } + + void Do(PlayerPacket &packet, Player &player) override + { + DEBUG_PRINTF(strPacketID.c_str()); + + packet.setPlayer(&player); + packet.Read(); + } + }; +} + + +#endif //OPENMW_PROCESSORPLAYERCHARCLASS_HPP diff --git a/apps/openmw-mp/processors/ProcessorPlayerCharGen.hpp b/apps/openmw-mp/processors/ProcessorPlayerCharGen.hpp new file mode 100644 index 000000000..466c0be41 --- /dev/null +++ b/apps/openmw-mp/processors/ProcessorPlayerCharGen.hpp @@ -0,0 +1,37 @@ +// +// Created by koncord on 01.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERCHARGEN_HPP +#define OPENMW_PROCESSORPLAYERCHARGEN_HPP + + +#include "../PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerCharGen : public PlayerProcessor + { + public: + ProcessorPlayerCharGen() + { + BPP_INIT(ID_PLAYER_CHARGEN) + } + + void Do(PlayerPacket &packet, Player &player) override + { + DEBUG_PRINTF(strPacketID.c_str()); + + packet.setPlayer(&player); + packet.Read(); + + if (player.charGenStage.current == player.charGenStage.end && player.charGenStage.current != 0) + Script::Call(player.getId()); + } + }; +} + + + + +#endif //OPENMW_PROCESSORPLAYERCHARGEN_HPP diff --git a/apps/openmw-mp/processors/ProcessorPlayerDeath.hpp b/apps/openmw-mp/processors/ProcessorPlayerDeath.hpp new file mode 100644 index 000000000..98632f472 --- /dev/null +++ b/apps/openmw-mp/processors/ProcessorPlayerDeath.hpp @@ -0,0 +1,52 @@ +// +// Created by koncord on 01.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERDEATH_HPP +#define OPENMW_PROCESSORPLAYERDEATH_HPP + + +#include "../PlayerProcessor.hpp" +#include + +namespace mwmp +{ + class ProcessorPlayerDeath : public PlayerProcessor + { + public: + ProcessorPlayerDeath() + { + BPP_INIT(ID_PLAYER_DEATH) + } + + void Do(PlayerPacket &packet, Player &player) override + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received %s from %s", strPacketID.c_str(), player.npc.mName.c_str()); + + Player *killer = Players::getPlayer(player.getLastAttackerId()); + + short reason = 0; // unknown; + double secondsSinceLastAttacker = std::chrono::duration_cast>( + std::chrono::steady_clock::now() - player.getLastAttackerTime()).count(); + + if (!killer) + killer = &player; + + if (secondsSinceLastAttacker < 3.0f) + reason = 1; // killed + else + reason = 2; //suicide + + player.resetLastAttacker(); + + player.creatureStats.mDead = true; + + packet.setPlayer(&player); + packet.Send(true); + + Script::Call(player.getId(), reason, killer->getId()); + } + }; +} + +#endif //OPENMW_PROCESSORPLAYERDEATH_HPP diff --git a/apps/openmw-mp/processors/ProcessorPlayerDrawState.hpp b/apps/openmw-mp/processors/ProcessorPlayerDrawState.hpp new file mode 100644 index 000000000..e1a1b47a7 --- /dev/null +++ b/apps/openmw-mp/processors/ProcessorPlayerDrawState.hpp @@ -0,0 +1,37 @@ +// +// Created by koncord on 01.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERDRAWSTATE_HPP +#define OPENMW_PROCESSORPLAYERDRAWSTATE_HPP + + +#include "../PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerDrawState : public PlayerProcessor + { + public: + ProcessorPlayerDrawState() + { + BPP_INIT(ID_PLAYER_DRAWSTATE) + } + + void Do(PlayerPacket &packet, Player &player) override + { + DEBUG_PRINTF(strPacketID.c_str()); + + packet.setPlayer(&player); + packet.Read(); + //packet.Send(&player, true); + + player.sendToLoaded(&packet); + } + }; +} + + + + +#endif //OPENMW_PROCESSORPLAYERDRAWSTATE_HPP diff --git a/apps/openmw-mp/processors/ProcessorPlayerDynamicStats.hpp b/apps/openmw-mp/processors/ProcessorPlayerDynamicStats.hpp new file mode 100644 index 000000000..d09831ff3 --- /dev/null +++ b/apps/openmw-mp/processors/ProcessorPlayerDynamicStats.hpp @@ -0,0 +1,34 @@ +// +// Created by koncord on 01.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERDYNAMICSTATS_HPP +#define OPENMW_PROCESSORPLAYERDYNAMICSTATS_HPP + + +#include "../PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerDynamicStats : public PlayerProcessor + { + public: + ProcessorPlayerDynamicStats() + { + BPP_INIT(ID_PLAYER_DYNAMICSTATS) + } + + void Do(PlayerPacket &packet, Player &player) override + { + DEBUG_PRINTF(strPacketID.c_str()); + + packet.setPlayer(&player); + packet.Read(); + + player.sendToLoaded(&packet); + } + }; +} + + +#endif //OPENMW_PROCESSORPLAYERDYNAMICSTATS_HPP diff --git a/apps/openmw-mp/processors/ProcessorPlayerEquipment.hpp b/apps/openmw-mp/processors/ProcessorPlayerEquipment.hpp new file mode 100644 index 000000000..3aee9c5b9 --- /dev/null +++ b/apps/openmw-mp/processors/ProcessorPlayerEquipment.hpp @@ -0,0 +1,36 @@ +// +// Created by koncord on 01.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYEREQUIPMENT_HPP +#define OPENMW_PROCESSORPLAYEREQUIPMENT_HPP + + +#include "../PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerEquipment : public PlayerProcessor + { + public: + ProcessorPlayerEquipment() + { + BPP_INIT(ID_PLAYER_EQUIPMENT) + } + + void Do(PlayerPacket &packet, Player &player) override + { + DEBUG_PRINTF(strPacketID.c_str()); + + packet.setPlayer(&player); + packet.Read(); + //myPacket->Send(player, true); + + player.sendToLoaded(&packet); + + Script::Call(player.getId()); + } + }; +} + +#endif //OPENMW_PROCESSORPLAYEREQUIPMENT_HPP diff --git a/apps/openmw-mp/processors/ProcessorPlayerInventory.hpp b/apps/openmw-mp/processors/ProcessorPlayerInventory.hpp new file mode 100644 index 000000000..54dc914d3 --- /dev/null +++ b/apps/openmw-mp/processors/ProcessorPlayerInventory.hpp @@ -0,0 +1,34 @@ +// +// Created by koncord on 01.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERINVENTORY_HPP +#define OPENMW_PROCESSORPLAYERINVENTORY_HPP + +#include "../PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerInventory : public PlayerProcessor + { + public: + ProcessorPlayerInventory() + { + BPP_INIT(ID_PLAYER_INVENTORY) + } + + void Do(PlayerPacket &packet, Player &player) override + { + DEBUG_PRINTF(strPacketID.c_str()); + + packet.setPlayer(&player); + packet.Read(); + + Script::Call(player.getId()); + } + }; +} + + + +#endif //OPENMW_PROCESSORPLAYERINVENTORY_HPP diff --git a/apps/openmw-mp/processors/ProcessorPlayerJournal.hpp b/apps/openmw-mp/processors/ProcessorPlayerJournal.hpp new file mode 100644 index 000000000..d4e8db0d9 --- /dev/null +++ b/apps/openmw-mp/processors/ProcessorPlayerJournal.hpp @@ -0,0 +1,33 @@ +// +// Created by koncord on 01.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERJOURNAL_HPP +#define OPENMW_PROCESSORPLAYERJOURNAL_HPP + + +#include "../PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerJournal : public PlayerProcessor + { + public: + ProcessorPlayerJournal() + { + BPP_INIT(ID_PLAYER_JOURNAL) + } + + void Do(PlayerPacket &packet, Player &player) override + { + DEBUG_PRINTF(strPacketID.c_str()); + + packet.setPlayer(&player); + packet.Read(); + + Script::Call(player.getId()); + } + }; +} + +#endif //OPENMW_PROCESSORPLAYERJOURNAL_HPP diff --git a/apps/openmw-mp/processors/ProcessorPlayerPos.hpp b/apps/openmw-mp/processors/ProcessorPlayerPos.hpp new file mode 100644 index 000000000..7a802f5a9 --- /dev/null +++ b/apps/openmw-mp/processors/ProcessorPlayerPos.hpp @@ -0,0 +1,35 @@ +// +// Created by koncord on 31.03.17. +// + +#ifndef OPENMW_PROCESSORPLAYERPOS_HPP +#define OPENMW_PROCESSORPLAYERPOS_HPP + +#include "../PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerPos : public PlayerProcessor + { + public: + ProcessorPlayerPos() + { + BPP_INIT(ID_PLAYER_POS) + } + + void Do(PlayerPacket &packet, Player &player) override + { + //DEBUG_PRINTF(strPacketID); + if (!player.creatureStats.mDead) + { + packet.setPlayer(&player); + packet.Read(); + //myPacket.Send(player, true); //send to other clients + + player.sendToLoaded(&packet); + } + } + }; +} + +#endif //OPENMW_PROCESSORPLAYERPOS_HPP diff --git a/apps/openmw-mp/processors/ProcessorPlayerResurrect.hpp b/apps/openmw-mp/processors/ProcessorPlayerResurrect.hpp new file mode 100644 index 000000000..adda2c4ac --- /dev/null +++ b/apps/openmw-mp/processors/ProcessorPlayerResurrect.hpp @@ -0,0 +1,37 @@ +// +// Created by koncord on 01.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERRESURRECT_HPP +#define OPENMW_PROCESSORPLAYERRESURRECT_HPP + + +#include "../PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerResurrect : public PlayerProcessor + { + public: + ProcessorPlayerResurrect() + { + BPP_INIT(ID_PLAYER_RESURRECT) + } + + void Do(PlayerPacket &packet, Player &player) override + { + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Received %s from %s", strPacketID.c_str(), player.npc.mName.c_str()); + + player.creatureStats.mDead = false; + + packet.setPlayer(&player); + packet.Send(true); + + Script::Call(player.getId()); + } + }; +} + + + +#endif //OPENMW_PROCESSORPLAYERRESURRECT_HPP diff --git a/apps/openmw-mp/processors/ProcessorPlayerSkill.hpp b/apps/openmw-mp/processors/ProcessorPlayerSkill.hpp new file mode 100644 index 000000000..4882ad82c --- /dev/null +++ b/apps/openmw-mp/processors/ProcessorPlayerSkill.hpp @@ -0,0 +1,35 @@ +// +// Created by koncord on 01.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERSKILL_HPP +#define OPENMW_PROCESSORPLAYERSKILL_HPP + +#include "../PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerSkill : public PlayerProcessor + { + public: + ProcessorPlayerSkill() + { + BPP_INIT(ID_PLAYER_SKILL) + } + + void Do(PlayerPacket &packet, Player &player) override + { + if (!player.creatureStats.mDead) + { + packet.setPlayer(&player); + packet.Read(); + //myPacket->Send(player, true); + player.sendToLoaded(&packet); + + Script::Call(player.getId()); + } + } + }; +} + +#endif //OPENMW_PROCESSORPLAYERSKILL_HPP diff --git a/apps/openmw-mp/processors/ProcessorPlayerSpellbook.hpp b/apps/openmw-mp/processors/ProcessorPlayerSpellbook.hpp new file mode 100644 index 000000000..77e63f485 --- /dev/null +++ b/apps/openmw-mp/processors/ProcessorPlayerSpellbook.hpp @@ -0,0 +1,33 @@ +// +// Created by koncord on 01.04.17. +// + +#ifndef OPENMW_PROCESSORPLAYERSPELLBOOK_HPP +#define OPENMW_PROCESSORPLAYERSPELLBOOK_HPP + +#include "../PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerSpellbook : public PlayerProcessor + { + public: + ProcessorPlayerSpellbook() + { + BPP_INIT(ID_PLAYER_SPELLBOOK) + } + + void Do(PlayerPacket &packet, Player &player) override + { + DEBUG_PRINTF(strPacketID.c_str()); + + packet.setPlayer(&player); + packet.Read(); + + Script::Call(player.getId()); + } + }; +} + + +#endif //OPENMW_PROCESSORPLAYERSPELLBOOK_HPP