[Server] Move all world handlers to WorldProcessors

This commit is contained in:
Koncord 2017-04-03 05:46:46 +08:00
parent 3ab25fb3f1
commit f5600c508f
18 changed files with 492 additions and 208 deletions

View file

@ -18,9 +18,9 @@
#include "MasterClient.hpp"
#include "Cell.hpp"
#include "PlayerProcessor.hpp"
#include "WorldProcessor.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;
@ -165,214 +165,8 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
baseEvent.objectChanges.objects.clear();
baseEvent.guid = packet->guid;
switch (packet->data[0])
{
case ID_OBJECT_PLACE:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_PLACE from %s", player->npc.mName.c_str());
myPacket->setEvent(&baseEvent);
myPacket->Read();
myPacket->Send(true);
Script::Call<Script::CallbackIdentity("OnObjectPlace")>(player->getId(), baseEvent.cell.getDescription().c_str());
break;
}
case ID_OBJECT_DELETE:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_DELETE from %s", player->npc.mName.c_str());
myPacket->setEvent(&baseEvent);
myPacket->Read();
myPacket->Send(true);
Script::Call<Script::CallbackIdentity("OnObjectDelete")>(player->getId(), baseEvent.cell.getDescription().c_str());
break;
}
case ID_OBJECT_SCALE:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_SCALE from %s", player->npc.mName.c_str());
myPacket->setEvent(&baseEvent);
myPacket->Read();
myPacket->Send(true);
Script::Call<Script::CallbackIdentity("OnObjectScale")>(player->getId(), baseEvent.cell.getDescription().c_str());
break;
}
case ID_OBJECT_LOCK:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_LOCK from %s", player->npc.mName.c_str());
myPacket->setEvent(&baseEvent);
myPacket->Read();
myPacket->Send(true);
Script::Call<Script::CallbackIdentity("OnObjectLock")>(player->getId(), baseEvent.cell.getDescription().c_str());
break;
}
case ID_OBJECT_UNLOCK:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_UNLOCK from %s", player->npc.mName.c_str());
myPacket->setEvent(&baseEvent);
myPacket->Read();
myPacket->Send(true);
Script::Call<Script::CallbackIdentity("OnObjectUnlock")>(player->getId(), baseEvent.cell.getDescription().c_str());
break;
}
case ID_OBJECT_MOVE:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_MOVE from %s", player->npc.mName.c_str());
myPacket->setEvent(&baseEvent);
myPacket->Read();
myPacket->Send(true);
break;
}
case ID_OBJECT_ROTATE:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_ROTATE from %s", player->npc.mName.c_str());
myPacket->setEvent(&baseEvent);
myPacket->Read();
myPacket->Send(true);
break;
}
case ID_OBJECT_ANIM_PLAY:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_ANIM_PLAY from %s", player->npc.mName.c_str());
myPacket->setEvent(&baseEvent);
myPacket->Read();
myPacket->Send(true);
break;
}
case ID_DOOR_STATE:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_DOOR_STATE from %s", player->npc.mName.c_str());
myPacket->setEvent(&baseEvent);
myPacket->Read();
myPacket->Send(true);
Script::Call<Script::CallbackIdentity("OnDoorState")>(player->getId(), baseEvent.cell.getDescription().c_str());
break;
}
case ID_CONTAINER:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_CONTAINER from %s", player->npc.mName.c_str());
myPacket->setEvent(&baseEvent);
myPacket->Read();
LOG_APPEND(Log::LOG_WARN, "- action: %i", baseEvent.action);
// Until we have a timestamp-based system, send packets pertaining to more
// than one container (i.e. replies to server requests for container contents)
// only to players who have the container's cell loaded
if (baseEvent.action == BaseEvent::SET && baseEvent.objectChanges.count > 1)
CellController::get()->getCell(&baseEvent.cell)->sendToLoaded(myPacket, &baseEvent);
else
myPacket->Send(true);
Script::Call<Script::CallbackIdentity("OnContainer")>(player->getId(), baseEvent.cell.getDescription().c_str());
LOG_APPEND(Log::LOG_INFO, "- Finished processing ID_CONTAINER");
break;
}
case ID_SCRIPT_LOCAL_SHORT:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_LOCAL_SHORT from %s", player->npc.mName.c_str());
myPacket->setEvent(&baseEvent);
myPacket->Read();
myPacket->Send(true);
break;
}
case ID_SCRIPT_LOCAL_FLOAT:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_LOCAL_FLOAT from %s", player->npc.mName.c_str());
myPacket->setEvent(&baseEvent);
myPacket->Read();
myPacket->Send(true);
break;
}
case ID_SCRIPT_MEMBER_SHORT:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_MEMBER_SHORT from %s", player->npc.mName.c_str());
myPacket->setEvent(&baseEvent);
myPacket->Read();
myPacket->Send(true);
break;
}
case ID_SCRIPT_GLOBAL_SHORT:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_GLOBAL_SHORT from %s", player->npc.mName.c_str());
myPacket->setEvent(&baseEvent);
myPacket->Read();
myPacket->Send(true);
break;
}
case ID_MUSIC_PLAY:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_MUSIC_PLAY from %s", player->npc.mName.c_str());
myPacket->setEvent(&baseEvent);
myPacket->Read();
myPacket->Send(true);
break;
}
case ID_VIDEO_PLAY:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_VIDEO_PLAY from %s", player->npc.mName.c_str());
myPacket->setEvent(&baseEvent);
myPacket->Read();
myPacket->Send(true);
break;
}
default:
if(!WorldProcessor::Process(*packet))
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Unhandled WorldPacket with identifier %i has arrived", packet->data[0]);
break;
}
}

View file

@ -24,6 +24,23 @@
#include "processors/player/ProcessorPlayerCharGen.hpp"
#include "processors/player/ProcessorGUIMessageBox.hpp"
#include "processors/player/ProcessorPlayerCharClass.hpp"
#include "WorldProcessor.hpp"
#include "processors/world/ProcessorContainer.hpp"
#include "processors/world/ProcessorDoorState.hpp"
#include "processors/world/ProcessorMusicPlay.hpp"
#include "processors/world/ProcessorObjectAnimPlay.hpp"
#include "processors/world/ProcessorObjectDelete.hpp"
#include "processors/world/ProcessorObjectLock.hpp"
#include "processors/world/ProcessorObjectMove.hpp"
#include "processors/world/ProcessorObjectPlace.hpp"
#include "processors/world/ProcessorObjectRotate.hpp"
#include "processors/world/ProcessorObjectScale.hpp"
#include "processors/world/ProcessorObjectUnlock.hpp"
#include "processors/world/ProcessorScriptGlobalShort.hpp"
#include "processors/world/ProcessorScriptLocalFloat.hpp"
#include "processors/world/ProcessorScriptLocalShort.hpp"
#include "processors/world/ProcessorScriptMemberShort.hpp"
#include "processors/world/ProcessorVideoPlay.hpp"
using namespace mwmp;
@ -49,4 +66,21 @@ void ProcessorInitializer()
PlayerProcessor::AddProcessor(new ProcessorPlayerCharGen());
PlayerProcessor::AddProcessor(new ProcessorGUIMessageBox());
PlayerProcessor::AddProcessor(new ProcessorPlayerCharClass());
WorldProcessor::AddProcessor(new ProcessorContainer());
WorldProcessor::AddProcessor(new ProcessorDoorState());
WorldProcessor::AddProcessor(new ProcessorMusicPlay());
WorldProcessor::AddProcessor(new ProcessorObjectAnimPlay());
WorldProcessor::AddProcessor(new ProcessorObjectDelete());
WorldProcessor::AddProcessor(new ProcessorObjectLock());
WorldProcessor::AddProcessor(new ProcessorObjectMove());
WorldProcessor::AddProcessor(new ProcessorObjectPlace());
WorldProcessor::AddProcessor(new ProcessorObjectRotate());
WorldProcessor::AddProcessor(new ProcessorObjectScale());
WorldProcessor::AddProcessor(new ProcessorObjectUnlock());
WorldProcessor::AddProcessor(new ProcessorScriptGlobalShort());
WorldProcessor::AddProcessor(new ProcessorScriptLocalFloat());
WorldProcessor::AddProcessor(new ProcessorScriptLocalShort());
WorldProcessor::AddProcessor(new ProcessorScriptMemberShort());
WorldProcessor::AddProcessor(new ProcessorVideoPlay());
}

View file

@ -0,0 +1,39 @@
//
// Created by koncord on 03.04.17.
//
#ifndef OPENMW_PROCESSORCONTAINER_HPP
#define OPENMW_PROCESSORCONTAINER_HPP
#include "apps/openmw-mp/WorldProcessor.hpp"
namespace mwmp
{
class ProcessorContainer : public WorldProcessor
{
public:
ProcessorContainer()
{
BPP_INIT(ID_VIDEO_PLAY)
}
void Do(WorldPacket &packet, Player &player, BaseEvent &event) override
{
LOG_APPEND(Log::LOG_WARN, "- action: %i", event.action);
// Until we have a timestamp-based system, send packets pertaining to more
// than one container (i.e. replies to server requests for container contents)
// only to players who have the container's cell loaded
if (event.action == BaseEvent::SET && event.objectChanges.count > 1)
CellController::get()->getCell(&event.cell)->sendToLoaded(&packet, &event);
else
packet.Send(true);
Script::Call<Script::CallbackIdentity("OnContainer")>(player.getId(), event.cell.getDescription().c_str());
LOG_APPEND(Log::LOG_INFO, "- Finished processing ID_CONTAINER");
}
};
}
#endif //OPENMW_PROCESSORCONTAINER_HPP

View file

@ -0,0 +1,29 @@
//
// Created by koncord on 03.04.17.
//
#ifndef OPENMW_PROCESSORDOORSTATE_HPP
#define OPENMW_PROCESSORDOORSTATE_HPP
#include "apps/openmw-mp/WorldProcessor.hpp"
namespace mwmp
{
class ProcessorDoorState : public WorldProcessor
{
public:
ProcessorDoorState()
{
BPP_INIT(ID_DOOR_STATE)
}
void Do(WorldPacket &packet, Player &player, BaseEvent &event) override
{
packet.Send(true);
Script::Call<Script::CallbackIdentity("OnDoorState")>(player.getId(), event.cell.getDescription().c_str());
}
};
}
#endif //OPENMW_PROCESSORDOORSTATE_HPP

View file

@ -0,0 +1,27 @@
//
// Created by koncord on 03.04.17.
//
#ifndef OPENMW_PROCESSORMUSICPLAY_HPP
#define OPENMW_PROCESSORMUSICPLAY_HPP
#include "apps/openmw-mp/WorldProcessor.hpp"
namespace mwmp
{
class ProcessorMusicPlay : public WorldProcessor
{
public:
ProcessorMusicPlay()
{
BPP_INIT(ID_MUSIC_PLAY)
}
void Do(WorldPacket &packet, Player &player, BaseEvent &event) override
{
packet.Send(true);
}
};
}
#endif //OPENMW_PROCESSORMUSICPLAY_HPP

View file

@ -0,0 +1,27 @@
//
// Created by koncord on 03.04.17.
//
#ifndef OPENMW_PROCESSOROBJECTANIMPLAY_HPP
#define OPENMW_PROCESSOROBJECTANIMPLAY_HPP
#include "apps/openmw-mp/WorldProcessor.hpp"
namespace mwmp
{
class ProcessorObjectAnimPlay : public WorldProcessor
{
public:
ProcessorObjectAnimPlay()
{
BPP_INIT(ID_OBJECT_ANIM_PLAY)
}
void Do(WorldPacket &packet, Player &player, BaseEvent &event) override
{
packet.Send(true);
}
};
}
#endif //OPENMW_PROCESSOROBJECTANIMPLAY_HPP

View file

@ -0,0 +1,29 @@
//
// Created by koncord on 03.04.17.
//
#ifndef OPENMW_PROCESSOROBJECTDELETE_HPP
#define OPENMW_PROCESSOROBJECTDELETE_HPP
#include "apps/openmw-mp/WorldProcessor.hpp"
namespace mwmp
{
class ProcessorObjectDelete : public WorldProcessor
{
public:
ProcessorObjectDelete()
{
BPP_INIT(ID_OBJECT_DELETE)
}
void Do(WorldPacket &packet, Player &player, BaseEvent &event) override
{
packet.Send(true);
Script::Call<Script::CallbackIdentity("OnObjectDelete")>(player.getId(), event.cell.getDescription().c_str());
}
};
}
#endif //OPENMW_PROCESSOROBJECTDELETE_HPP

View file

@ -0,0 +1,29 @@
//
// Created by koncord on 03.04.17.
//
#ifndef OPENMW_PROCESSOROBJECTLOCK_HPP
#define OPENMW_PROCESSOROBJECTLOCK_HPP
#include "apps/openmw-mp/WorldProcessor.hpp"
namespace mwmp
{
class ProcessorObjectLock : public WorldProcessor
{
public:
ProcessorObjectLock()
{
BPP_INIT(ID_OBJECT_LOCK)
}
void Do(WorldPacket &packet, Player &player, BaseEvent &event) override
{
packet.Send(true);
Script::Call<Script::CallbackIdentity("OnObjectLock")>(player.getId(), event.cell.getDescription().c_str());
}
};
}
#endif //OPENMW_PROCESSOROBJECTLOCK_HPP

View file

@ -0,0 +1,27 @@
//
// Created by koncord on 03.04.17.
//
#ifndef OPENMW_PROCESSOROBJECTMOVE_HPP
#define OPENMW_PROCESSOROBJECTMOVE_HPP
#include "apps/openmw-mp/WorldProcessor.hpp"
namespace mwmp
{
class ProcessorObjectMove : public WorldProcessor
{
public:
ProcessorObjectMove()
{
BPP_INIT(ID_OBJECT_MOVE)
}
void Do(WorldPacket &packet, Player &player, BaseEvent &event) override
{
packet.Send(true);
}
};
}
#endif //OPENMW_PROCESSOROBJECTMOVE_HPP

View file

@ -0,0 +1,29 @@
//
// Created by koncord on 03.04.17.
//
#ifndef OPENMW_PROCESSOROBJECTPLACE_HPP
#define OPENMW_PROCESSOROBJECTPLACE_HPP
#include "apps/openmw-mp/WorldProcessor.hpp"
namespace mwmp
{
class ProcessorObjectPlace : public WorldProcessor
{
public:
ProcessorObjectPlace()
{
BPP_INIT(ID_OBJECT_PLACE)
}
void Do(WorldPacket &packet, Player &player, BaseEvent &event) override
{
packet.Send(true);
Script::Call<Script::CallbackIdentity("OnObjectPlace")>(player.getId(), event.cell.getDescription().c_str());
}
};
}
#endif //OPENMW_PROCESSOROBJECTPLACE_HPP

View file

@ -0,0 +1,27 @@
//
// Created by koncord on 03.04.17.
//
#ifndef OPENMW_PROCESSOROBJECTROTATE_HPP
#define OPENMW_PROCESSOROBJECTROTATE_HPP
#include "apps/openmw-mp/WorldProcessor.hpp"
namespace mwmp
{
class ProcessorObjectRotate : public WorldProcessor
{
public:
ProcessorObjectRotate()
{
BPP_INIT(ID_OBJECT_ROTATE)
}
void Do(WorldPacket &packet, Player &player, BaseEvent &event) override
{
packet.Send(true);
}
};
}
#endif //OPENMW_PROCESSOROBJECTROTATE_HPP

View file

@ -0,0 +1,29 @@
//
// Created by koncord on 03.04.17.
//
#ifndef OPENMW_PROCESSOROBJECTSCALE_HPP
#define OPENMW_PROCESSOROBJECTSCALE_HPP
#include "apps/openmw-mp/WorldProcessor.hpp"
namespace mwmp
{
class ProcessorObjectScale : public WorldProcessor
{
public:
ProcessorObjectScale()
{
BPP_INIT(ID_OBJECT_SCALE)
}
void Do(WorldPacket &packet, Player &player, BaseEvent &event) override
{
packet.Send(true);
Script::Call<Script::CallbackIdentity("OnObjectScale")>(player.getId(), event.cell.getDescription().c_str());
}
};
}
#endif //OPENMW_PROCESSOROBJECTSCALE_HPP

View file

@ -0,0 +1,29 @@
//
// Created by koncord on 03.04.17.
//
#ifndef OPENMW_PROCESSOROBJECTUNLOCK_HPP
#define OPENMW_PROCESSOROBJECTUNLOCK_HPP
#include "apps/openmw-mp/WorldProcessor.hpp"
namespace mwmp
{
class ProcessorObjectUnlock : public WorldProcessor
{
public:
ProcessorObjectUnlock()
{
BPP_INIT(ID_OBJECT_UNLOCK)
}
void Do(WorldPacket &packet, Player &player, BaseEvent &event) override
{
packet.Send(true);
Script::Call<Script::CallbackIdentity("OnObjectUnlock")>(player.getId(), event.cell.getDescription().c_str());
}
};
}
#endif //OPENMW_PROCESSOROBJECTUNLOCK_HPP

View file

@ -0,0 +1,27 @@
//
// Created by koncord on 03.04.17.
//
#ifndef OPENMW_PROCESSORSCRIPTGLOBALSHORT_HPP
#define OPENMW_PROCESSORSCRIPTGLOBALSHORT_HPP
#include "apps/openmw-mp/WorldProcessor.hpp"
namespace mwmp
{
class ProcessorScriptGlobalShort : public WorldProcessor
{
public:
ProcessorScriptGlobalShort()
{
BPP_INIT(ID_SCRIPT_GLOBAL_SHORT)
}
void Do(WorldPacket &packet, Player &player, BaseEvent &event) override
{
packet.Send(true);
}
};
}
#endif //OPENMW_PROCESSORSCRIPTGLOBALSHORT_HPP

View file

@ -0,0 +1,27 @@
//
// Created by koncord on 03.04.17.
//
#ifndef OPENMW_PROCESSORSCRIPTLOCALFLOAT_HPP
#define OPENMW_PROCESSORSCRIPTLOCALFLOAT_HPP
#include "apps/openmw-mp/WorldProcessor.hpp"
namespace mwmp
{
class ProcessorScriptLocalFloat : public WorldProcessor
{
public:
ProcessorScriptLocalFloat()
{
BPP_INIT(ID_SCRIPT_LOCAL_FLOAT)
}
void Do(WorldPacket &packet, Player &player, BaseEvent &event) override
{
packet.Send(true);
}
};
}
#endif //OPENMW_PROCESSORSCRIPTLOCALFLOAT_HPP

View file

@ -0,0 +1,27 @@
//
// Created by koncord on 03.04.17.
//
#ifndef OPENMW_PROCESSORSCRIPTLOCALSHORT_HPP
#define OPENMW_PROCESSORSCRIPTLOCALSHORT_HPP
#include "apps/openmw-mp/WorldProcessor.hpp"
namespace mwmp
{
class ProcessorScriptLocalShort : public WorldProcessor
{
public:
ProcessorScriptLocalShort()
{
BPP_INIT(ID_SCRIPT_LOCAL_SHORT)
}
void Do(WorldPacket &packet, Player &player, BaseEvent &event) override
{
packet.Send(true);
}
};
}
#endif //OPENMW_PROCESSORSCRIPTLOCALSHORT_HPP

View file

@ -0,0 +1,27 @@
//
// Created by koncord on 03.04.17.
//
#ifndef OPENMW_PROCESSORSCRIPTMEMBERSHORT_HPP
#define OPENMW_PROCESSORSCRIPTMEMBERSHORT_HPP
#include "apps/openmw-mp/WorldProcessor.hpp"
namespace mwmp
{
class ProcessorScriptMemberShort : public WorldProcessor
{
public:
ProcessorScriptMemberShort()
{
BPP_INIT(ID_SCRIPT_MEMBER_SHORT)
}
void Do(WorldPacket &packet, Player &player, BaseEvent &event) override
{
packet.Send(true);
}
};
}
#endif //OPENMW_PROCESSORSCRIPTMEMBERSHORT_HPP

View file

@ -0,0 +1,27 @@
//
// Created by koncord on 03.04.17.
//
#ifndef OPENMW_PROCESSORVIDEOPLAY_HPP
#define OPENMW_PROCESSORVIDEOPLAY_HPP
#include "apps/openmw-mp/WorldProcessor.hpp"
namespace mwmp
{
class ProcessorVideoPlay : public WorldProcessor
{
public:
ProcessorVideoPlay()
{
BPP_INIT(ID_VIDEO_PLAY)
}
void Do(WorldPacket &packet, Player &player, BaseEvent &event) override
{
packet.Send(true);
}
};
}
#endif //OPENMW_PROCESSORVIDEOPLAY_HPP