[Server] Move all message handlers to PlayerProcessors

0.6.1
Koncord 7 years ago
parent 020167df08
commit e8a5fd1cd0

@ -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}

@ -3,6 +3,7 @@
//
#include "Player.hpp"
#include "init_processors.hpp"
#include <RakPeer.h>
#include <Kbhit.h>
#include <components/openmw-mp/NetworkMessages.hpp>
@ -16,8 +17,10 @@
#include "Networking.hpp"
#include "MasterClient.hpp"
#include "Cell.hpp"
#include "PlayerProcessor.hpp"
#include <components/openmw-mp/Version.hpp>
#include <components/openmw-mp/Packets/PacketPreInit.hpp>
#include <apps/openmw-mp/processors/ProcessorPlayerPos.hpp>
using namespace mwmp;
using namespace std;
@ -45,6 +48,8 @@ Networking::Networking(RakNet::RakPeerInterface *peer)
Script::Call<Script::CallbackIdentity("OnServerInit")>();
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<Script::CallbackIdentity("OnPlayerCellChange")>(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<Script::CallbackIdentity("OnPlayerCellState")>(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<Script::CallbackIdentity("OnPlayerAttributesChange")>(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<Script::CallbackIdentity("OnPlayerSkillsChange")>(player->getId());
}
break;
}
case ID_PLAYER_LEVEL:
{
if (!player->creatureStats.mDead)
{
myPacket->setPlayer(player);
myPacket->Read();
//myPacket->Send(player, true);
Script::Call<Script::CallbackIdentity("OnPlayerLevelChange")>(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<Script::CallbackIdentity("OnPlayerEquipmentChange")>(player->getId());
break;
}
case ID_PLAYER_INVENTORY:
{
DEBUG_PRINTF("ID_PLAYER_INVENTORY\n");
myPacket->setPlayer(player);
myPacket->Read();
Script::Call<Script::CallbackIdentity("OnPlayerInventoryChange")>(player->getId());
break;
}
case ID_PLAYER_SPELLBOOK:
{
DEBUG_PRINTF("ID_PLAYER_SPELLBOOK\n");
myPacket->setPlayer(player);
myPacket->Read();
Script::Call<Script::CallbackIdentity("OnPlayerSpellbookChange")>(player->getId());
break;
}
case ID_PLAYER_JOURNAL:
{
DEBUG_PRINTF("ID_PLAYER_JOURNAL\n");
myPacket->setPlayer(player);
myPacket->Read();
Script::Call<Script::CallbackIdentity("OnPlayerJournalChange")>(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::duration<double>>(
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<Script::CallbackIdentity("OnPlayerDeath")>(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<Script::CallbackIdentity("OnPlayerResurrect")>(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<Script::CallbackIdentity("OnPlayerSendMessage")> result = true;
Script::Call<Script::CallbackIdentity("OnPlayerSendMessage")>(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<Script::CallbackIdentity("OnPlayerEndCharGen")>(player->getId());
break;
}
case ID_GUI_MESSAGEBOX:
{
DEBUG_PRINTF("ID_GUI_MESSAGEBOX\n");
myPacket->setPlayer(player);
myPacket->Read();
Script::Call<Script::CallbackIdentity("OnGUIAction")>(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)

@ -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());
}

@ -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

@ -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<Script::CallbackIdentity("OnPlayerSendMessage")> result = true;
Script::Call<Script::CallbackIdentity("OnPlayerSendMessage")>(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

@ -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<Script::CallbackIdentity("OnGUIAction")>(player.getId(), (int)player.guiMessageBox.id,
player.guiMessageBox.data.c_str());
}
};
}
#endif //OPENMW_PROCESSORGUIMESSAGEBOX_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<Script::CallbackIdentity("OnPlayerLevelChange")>(player.getId());
}
}
};
}
#endif //OPENMW_PROCESSORLEVEL_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

@ -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<Script::CallbackIdentity("OnPlayerAttributesChange")>(player.getId());
}
}
};
}
#endif //OPENMW_PROCESSORPLAYERATTRIBUTE_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 <components/openmw-mp/Controllers/PlayerPacketController.hpp>
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<Script::CallbackIdentity("OnPlayerCellChange")>(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

@ -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 <components/openmw-mp/Controllers/PlayerPacketController.hpp>
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<Script::CallbackIdentity("OnPlayerCellState")>(player.getId());
}
};
}
#endif //OPENMW_PROCESSORPLAYERCELLSTATE_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

@ -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<Script::CallbackIdentity("OnPlayerEndCharGen")>(player.getId());
}
};
}
#endif //OPENMW_PROCESSORPLAYERCHARGEN_HPP

@ -0,0 +1,52 @@
//
// Created by koncord on 01.04.17.
//
#ifndef OPENMW_PROCESSORPLAYERDEATH_HPP
#define OPENMW_PROCESSORPLAYERDEATH_HPP
#include "../PlayerProcessor.hpp"
#include <chrono>
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::duration<double>>(
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<Script::CallbackIdentity("OnPlayerDeath")>(player.getId(), reason, killer->getId());
}
};
}
#endif //OPENMW_PROCESSORPLAYERDEATH_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

@ -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

@ -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<Script::CallbackIdentity("OnPlayerEquipmentChange")>(player.getId());
}
};
}
#endif //OPENMW_PROCESSORPLAYEREQUIPMENT_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<Script::CallbackIdentity("OnPlayerInventoryChange")>(player.getId());
}
};
}
#endif //OPENMW_PROCESSORPLAYERINVENTORY_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<Script::CallbackIdentity("OnPlayerJournalChange")>(player.getId());
}
};
}
#endif //OPENMW_PROCESSORPLAYERJOURNAL_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

@ -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<Script::CallbackIdentity("OnPlayerResurrect")>(player.getId());
}
};
}
#endif //OPENMW_PROCESSORPLAYERRESURRECT_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<Script::CallbackIdentity("OnPlayerSkillsChange")>(player.getId());
}
}
};
}
#endif //OPENMW_PROCESSORPLAYERSKILL_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<Script::CallbackIdentity("OnPlayerSpellbookChange")>(player.getId());
}
};
}
#endif //OPENMW_PROCESSORPLAYERSPELLBOOK_HPP
Loading…
Cancel
Save