1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-19 17:39:44 +00:00

[Server] Add PlayerProcessor

This commit is contained in:
Koncord 2017-04-01 02:35:34 +08:00
parent b01734888f
commit 020167df08
3 changed files with 76 additions and 0 deletions

View file

@ -79,6 +79,8 @@ set(SERVER
Script/Functions/Spells.cpp Script/Functions/Timer.cpp Script/Functions/Positions.cpp
Script/Functions/Cells.cpp Script/Functions/World.cpp Script/Functions/Miscellaneous.cpp
PlayerProcessor.cpp
Script/API/TimerAPI.cpp Script/API/PublicFnAPI.cpp
${PawnScript_Sources}
${LuaScript_Sources}

View file

@ -0,0 +1,39 @@
//
// Created by koncord on 31.03.17.
//
#include "PlayerProcessor.hpp"
#include "Networking.hpp"
//#include <boost/foreach.hpp>
using namespace mwmp;
PlayerProcessor::processors_t PlayerProcessor::processors;
void PlayerProcessor::AddProcessor(PlayerProcessor *processor) noexcept
{
for(auto &p : processors)
{
if(processor->packetID == p.first)
throw std::logic_error("processor " + p.second->strPacketID + " already registered. Check " +
processor->className + " and " + p.second->className);
}
processors.insert(processors_t::value_type(processor->GetPacketID(), processor));
}
bool PlayerProcessor::Process(RakNet::Packet &packet) noexcept
{
//BOOST_FOREACH(processors_t::value_type &processor, processors)
for(auto &processor : processors)
{
if(processor.first == packet.data[0])
{
Player *player = Players::getPlayer(packet.guid);
PlayerPacket *myPacket = Networking::get().getPlayerController()->GetPacket(packet.data[0]);
processor.second->Do(*myPacket, *player);
return true;
}
}
return false;
}

View file

@ -0,0 +1,35 @@
//
// Created by koncord on 31.03.17.
//
#ifndef OPENMW_BASEPLAYERPROCESSOR_HPP
#define OPENMW_BASEPLAYERPROCESSOR_HPP
#include <components/openmw-mp/Base/BasePacketProcessor.hpp>
#include <components/openmw-mp/Packets/BasePacket.hpp>
#include <components/openmw-mp/NetworkMessages.hpp>
#include <unordered_map>
#include <memory>
//#include <boost/unordered_map.hpp>
//#include <boost/shared_ptr.hpp>
#include "Player.hpp"
namespace mwmp
{
class PlayerProcessor : public BasePacketProcessor
{
public:
virtual void Do(PlayerPacket &packet, Player &player) = 0;
static bool Process(RakNet::Packet &packet) noexcept;
static void AddProcessor(PlayerProcessor *processor) noexcept;
//typedef boost::unordered_map<unsigned char, boost::shared_ptr<PlayerProcessor> > processors_t;
typedef std::unordered_map<unsigned char, std::unique_ptr<PlayerProcessor> > processors_t;
private:
static processors_t processors;
};
}
#endif //OPENMW_BASEPLAYERPROCESSOR_HPP