[General] Create SystemPacket category and move Handshake packet to it

pull/556/head
David Cernat 5 years ago
parent 5762a36fc2
commit 20d1e7654c

@ -41,12 +41,14 @@ Networking::Networking(RakNet::RakPeerInterface *peer) : mclient(nullptr)
CellController::create(); CellController::create();
systemPacketController = new SystemPacketController(peer);
playerPacketController = new PlayerPacketController(peer); playerPacketController = new PlayerPacketController(peer);
actorPacketController = new ActorPacketController(peer); actorPacketController = new ActorPacketController(peer);
objectPacketController = new ObjectPacketController(peer); objectPacketController = new ObjectPacketController(peer);
worldstatePacketController = new WorldstatePacketController(peer); worldstatePacketController = new WorldstatePacketController(peer);
// Set send stream // Set send stream
systemPacketController->SetStream(0, &bsOut);
playerPacketController->SetStream(0, &bsOut); playerPacketController->SetStream(0, &bsOut);
actorPacketController->SetStream(0, &bsOut); actorPacketController->SetStream(0, &bsOut);
objectPacketController->SetStream(0, &bsOut); objectPacketController->SetStream(0, &bsOut);
@ -69,6 +71,7 @@ Networking::~Networking()
CellController::destroy(); CellController::destroy();
sThis = 0; sThis = 0;
delete systemPacketController;
delete playerPacketController; delete playerPacketController;
delete actorPacketController; delete actorPacketController;
delete objectPacketController; delete objectPacketController;
@ -85,15 +88,15 @@ bool Networking::isPassworded() const
return serverPassword != TES3MP_DEFAULT_PASSW; return serverPassword != TES3MP_DEFAULT_PASSW;
} }
void Networking::processPlayerPacket(RakNet::Packet *packet) void Networking::processSystemPacket(RakNet::Packet *packet)
{ {
Player *player = Players::getPlayer(packet->guid); Player *player = Players::getPlayer(packet->guid);
PlayerPacket *myPacket = playerPacketController->GetPacket(packet->data[0]); SystemPacket *myPacket = systemPacketController->GetPacket(packet->data[0]);
if (packet->data[0] == ID_HANDSHAKE) if (packet->data[0] == ID_SYSTEM_HANDSHAKE)
{ {
myPacket->setPlayer(player); myPacket->setSystem(&baseSystem);
myPacket->Read(); myPacket->Read();
if (!myPacket->isPacketValid()) if (!myPacket->isPacketValid())
@ -110,7 +113,7 @@ void Networking::processPlayerPacket(RakNet::Packet *packet)
return; return;
} }
if (player->serverPassword != serverPassword) if (baseSystem.serverPassword != serverPassword)
{ {
if (isPassworded()) if (isPassworded())
{ {
@ -128,6 +131,13 @@ void Networking::processPlayerPacket(RakNet::Packet *packet)
player->setHandshake(); player->setHandshake();
return; return;
} }
}
void Networking::processPlayerPacket(RakNet::Packet *packet)
{
Player *player = Players::getPlayer(packet->guid);
PlayerPacket *myPacket = playerPacketController->GetPacket(packet->data[0]);
if (!player->isHandshaked()) if (!player->isHandshaked())
{ {
@ -283,8 +293,8 @@ bool Networking::preInit(RakNet::Packet *packet, RakNet::BitStream &bsIn)
packetPreInit.setChecksums(&tmp); packetPreInit.setChecksums(&tmp);
packetPreInit.Send(packet->systemAddress); packetPreInit.Send(packet->systemAddress);
Players::newPlayer(packet->guid); // create player if connection allowed Players::newPlayer(packet->guid); // create player if connection allowed
playerPacketController->SetStream(&bsIn, nullptr); // and request handshake systemPacketController->SetStream(&bsIn, nullptr); // and request handshake
playerPacketController->GetPacket(ID_HANDSHAKE)->RequestData(packet->guid); systemPacketController->GetPacket(ID_SYSTEM_HANDSHAKE)->RequestData(packet->guid);
return true; return true;
} }
@ -293,7 +303,12 @@ bool Networking::preInit(RakNet::Packet *packet, RakNet::BitStream &bsIn)
void Networking::update(RakNet::Packet *packet, RakNet::BitStream &bsIn) void Networking::update(RakNet::Packet *packet, RakNet::BitStream &bsIn)
{ {
if (playerPacketController->ContainsPacket(packet->data[0])) if (systemPacketController->ContainsPacket(packet->data[0]))
{
systemPacketController->SetStream(&bsIn, nullptr);
processSystemPacket(packet);
}
else if (playerPacketController->ContainsPacket(packet->data[0]))
{ {
playerPacketController->SetStream(&bsIn, nullptr); playerPacketController->SetStream(&bsIn, nullptr);
processPlayerPacket(packet); processPlayerPacket(packet);

@ -1,6 +1,7 @@
#ifndef OPENMW_NETWORKING_HPP #ifndef OPENMW_NETWORKING_HPP
#define OPENMW_NETWORKING_HPP #define OPENMW_NETWORKING_HPP
#include <components/openmw-mp/Controllers/SystemPacketController.hpp>
#include <components/openmw-mp/Controllers/PlayerPacketController.hpp> #include <components/openmw-mp/Controllers/PlayerPacketController.hpp>
#include <components/openmw-mp/Controllers/ActorPacketController.hpp> #include <components/openmw-mp/Controllers/ActorPacketController.hpp>
#include <components/openmw-mp/Controllers/ObjectPacketController.hpp> #include <components/openmw-mp/Controllers/ObjectPacketController.hpp>
@ -25,6 +26,7 @@ namespace mwmp
void unbanAddress(const char *ipAddress); void unbanAddress(const char *ipAddress);
RakNet::SystemAddress getSystemAddress(RakNet::RakNetGUID guid); RakNet::SystemAddress getSystemAddress(RakNet::RakNetGUID guid);
void processSystemPacket(RakNet::Packet *packet);
void processPlayerPacket(RakNet::Packet *packet); void processPlayerPacket(RakNet::Packet *packet);
void processActorPacket(RakNet::Packet *packet); void processActorPacket(RakNet::Packet *packet);
void processObjectPacket(RakNet::Packet *packet); void processObjectPacket(RakNet::Packet *packet);
@ -40,6 +42,7 @@ namespace mwmp
void stopServer(int code); void stopServer(int code);
SystemPacketController *getSystemPacketController() const;
PlayerPacketController *getPlayerPacketController() const; PlayerPacketController *getPlayerPacketController() const;
ActorPacketController *getActorPacketController() const; ActorPacketController *getActorPacketController() const;
ObjectPacketController *getObjectPacketController() const; ObjectPacketController *getObjectPacketController() const;
@ -80,10 +83,12 @@ namespace mwmp
TPlayers *players; TPlayers *players;
MasterClient *mclient; MasterClient *mclient;
BaseSystem baseSystem;
BaseActorList baseActorList; BaseActorList baseActorList;
BaseObjectList baseObjectList; BaseObjectList baseObjectList;
BaseWorldstate baseWorldstate; BaseWorldstate baseWorldstate;
SystemPacketController *systemPacketController;
PlayerPacketController *playerPacketController; PlayerPacketController *playerPacketController;
ActorPacketController *actorPacketController; ActorPacketController *actorPacketController;
ObjectPacketController *objectPacketController; ObjectPacketController *objectPacketController;

@ -95,15 +95,18 @@ add_openmw_dir (mwbase
inputmanager windowmanager statemanager inputmanager windowmanager statemanager
) )
add_openmw_dir (mwmp Main Networking LocalPlayer DedicatedPlayer PlayerList LocalActor DedicatedActor ActorList ObjectList add_openmw_dir (mwmp Main Networking LocalSystem LocalPlayer DedicatedPlayer PlayerList LocalActor DedicatedActor ActorList
Worldstate Cell CellController GUIController MechanicsHelper RecordHelper ScriptController ObjectList Worldstate Cell CellController GUIController MechanicsHelper RecordHelper ScriptController
) )
add_openmw_dir (mwmp/GUI GUIChat GUILogin PlayerMarkerCollection GUIDialogList TextInputDialog add_openmw_dir (mwmp/GUI GUIChat GUILogin PlayerMarkerCollection GUIDialogList TextInputDialog
) )
add_openmw_dir(mwmp/processors BaseClientPacketProcessor PlayerProcessor ObjectProcessor ActorProcessor WorldstateProcessor add_openmw_dir(mwmp/processors BaseClientPacketProcessor SystemProcessor PlayerProcessor ObjectProcessor ActorProcessor
ProcessorInitializer WorldstateProcessor ProcessorInitializer
)
add_openmw_dir (mwmp/processors/system ProcessorSystemHandshake
) )
add_openmw_dir (mwmp/processors/actor ProcessorActorAI ProcessorActorAnimFlags ProcessorActorAnimPlay ProcessorActorAttack add_openmw_dir (mwmp/processors/actor ProcessorActorAI ProcessorActorAnimFlags ProcessorActorAnimPlay ProcessorActorAttack
@ -111,16 +114,15 @@ add_openmw_dir (mwmp/processors/actor ProcessorActorAI ProcessorActorAnimFlags P
ProcessorActorList ProcessorActorPosition ProcessorActorSpeech ProcessorActorStatsDynamic ProcessorActorTest ProcessorActorList ProcessorActorPosition ProcessorActorSpeech ProcessorActorStatsDynamic ProcessorActorTest
) )
add_openmw_dir (mwmp/processors/player ProcessorChatMessage ProcessorGUIMessageBox ProcessorHandshake add_openmw_dir (mwmp/processors/player ProcessorChatMessage ProcessorGUIMessageBox ProcessorUserDisconnected
ProcessorUserDisconnected ProcessorUserMyID ProcessorGameSettings ProcessorPlayerAnimFlags ProcessorPlayerAnimPlay ProcessorUserMyID ProcessorGameSettings ProcessorPlayerAnimFlags ProcessorPlayerAnimPlay ProcessorPlayerAttack
ProcessorPlayerAttack ProcessorPlayerAttribute ProcessorPlayerBaseInfo ProcessorPlayerBehavior ProcessorPlayerBook ProcessorPlayerAttribute ProcessorPlayerBaseInfo ProcessorPlayerBehavior ProcessorPlayerBook ProcessorPlayerBounty
ProcessorPlayerBounty ProcessorPlayerCast ProcessorPlayerCellChange ProcessorPlayerCellState ProcessorPlayerCharClass ProcessorPlayerCast ProcessorPlayerCellChange ProcessorPlayerCellState ProcessorPlayerCharClass ProcessorPlayerCharGen
ProcessorPlayerCharGen ProcessorPlayerDeath ProcessorPlayerDisposition ProcessorPlayerEquipment ProcessorPlayerFaction ProcessorPlayerDeath ProcessorPlayerDisposition ProcessorPlayerEquipment ProcessorPlayerFaction ProcessorPlayerInput
ProcessorPlayerInput ProcessorPlayerInventory ProcessorPlayerItemUse ProcessorPlayerJail ProcessorPlayerJournal ProcessorPlayerInventory ProcessorPlayerItemUse ProcessorPlayerJail ProcessorPlayerJournal ProcessorPlayerLevel
ProcessorPlayerLevel ProcessorPlayerMiscellaneous ProcessorPlayerMomentum ProcessorPlayerPosition ProcessorPlayerQuickKeys ProcessorPlayerMiscellaneous ProcessorPlayerMomentum ProcessorPlayerPosition ProcessorPlayerQuickKeys ProcessorPlayerReputation
ProcessorPlayerReputation ProcessorPlayerResurrect ProcessorPlayerShapeshift ProcessorPlayerSkill ProcessorPlayerResurrect ProcessorPlayerShapeshift ProcessorPlayerSkill ProcessorPlayerSpeech ProcessorPlayerSpellbook
ProcessorPlayerSpeech ProcessorPlayerSpellbook ProcessorPlayerStatsDynamic ProcessorPlayerTopic ProcessorPlayerStatsDynamic ProcessorPlayerTopic ProcessorPlayerPlaceholder
ProcessorPlayerPlaceholder
) )
add_openmw_dir (mwmp/processors/object BaseObjectProcessor add_openmw_dir (mwmp/processors/object BaseObjectProcessor

@ -0,0 +1,20 @@
#include "LocalSystem.hpp"
#include "Main.hpp"
#include "Networking.hpp"
using namespace mwmp;
LocalSystem::LocalSystem()
{
}
LocalSystem::~LocalSystem()
{
}
Networking *LocalSystem::getNetworking()
{
return mwmp::Main::get().getNetworking();
}

@ -0,0 +1,23 @@
#ifndef OPENMW_LOCALSYSTEM_HPP
#define OPENMW_LOCALSYSTEM_HPP
#include <components/openmw-mp/Base/BaseSystem.hpp>
#include <RakNetTypes.h>
namespace mwmp
{
class Networking;
class LocalSystem : public BaseSystem
{
public:
LocalSystem();
virtual ~LocalSystem();
private:
Networking *getNetworking();
};
}
#endif //OPENMW_LOCALSYSTEM_HPP

@ -37,6 +37,7 @@
#include "Main.hpp" #include "Main.hpp"
#include "Networking.hpp" #include "Networking.hpp"
#include "LocalSystem.hpp"
#include "LocalPlayer.hpp" #include "LocalPlayer.hpp"
#include "DedicatedPlayer.hpp" #include "DedicatedPlayer.hpp"
#include "PlayerList.hpp" #include "PlayerList.hpp"
@ -84,6 +85,7 @@ Main::Main()
{ {
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "tes3mp started"); LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "tes3mp started");
mNetworking = new Networking(); mNetworking = new Networking();
mLocalSystem = new LocalSystem();
mLocalPlayer = new LocalPlayer(); mLocalPlayer = new LocalPlayer();
mGUIController = new GUIController(); mGUIController = new GUIController();
mCellController = new CellController(); mCellController = new CellController();
@ -96,6 +98,7 @@ Main::~Main()
{ {
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "tes3mp stopped"); LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "tes3mp stopped");
delete mNetworking; delete mNetworking;
delete mLocalSystem;
delete mLocalPlayer; delete mLocalPlayer;
delete mCellController; delete mCellController;
delete mGUIController; delete mGUIController;
@ -144,7 +147,7 @@ bool Main::init(std::vector<std::string> &content, Files::Collections &collectio
pMain->server = address.substr(0, delimPos); pMain->server = address.substr(0, delimPos);
pMain->port = atoi(address.substr(delimPos + 1).c_str()); pMain->port = atoi(address.substr(delimPos + 1).c_str());
} }
get().mLocalPlayer->serverPassword = serverPassword; get().mLocalSystem->serverPassword = serverPassword;
pMain->mNetworking->connect(pMain->server, pMain->port, content, collections); pMain->mNetworking->connect(pMain->server, pMain->port, content, collections);
@ -177,7 +180,6 @@ void Main::frame(float dt)
get().updateWorld(dt); get().updateWorld(dt);
get().getGUIController()->update(dt); get().getGUIController()->update(dt);
} }
void Main::updateWorld(float dt) const void Main::updateWorld(float dt) const
@ -216,12 +218,16 @@ Networking *Main::getNetworking() const
return mNetworking; return mNetworking;
} }
LocalSystem *Main::getLocalSystem() const
{
return mLocalSystem;
}
LocalPlayer *Main::getLocalPlayer() const LocalPlayer *Main::getLocalPlayer() const
{ {
return mLocalPlayer; return mLocalPlayer;
} }
GUIController *Main::getGUIController() const GUIController *Main::getGUIController() const
{ {
return mGUIController; return mGUIController;

@ -9,6 +9,7 @@ namespace mwmp
{ {
class GUIController; class GUIController;
class CellController; class CellController;
class LocalSystem;
class LocalPlayer; class LocalPlayer;
class Networking; class Networking;
@ -32,6 +33,7 @@ namespace mwmp
static std::string getResDir(); static std::string getResDir();
Networking *getNetworking() const; Networking *getNetworking() const;
LocalSystem *getLocalSystem() const;
LocalPlayer *getLocalPlayer() const; LocalPlayer *getLocalPlayer() const;
GUIController *getGUIController() const; GUIController *getGUIController() const;
CellController *getCellController() const; CellController *getCellController() const;
@ -48,6 +50,7 @@ namespace mwmp
///< not implemented ///< not implemented
static Main *pMain; static Main *pMain;
Networking *mNetworking; Networking *mNetworking;
LocalSystem *mLocalSystem;
LocalPlayer *mLocalPlayer; LocalPlayer *mLocalPlayer;
GUIController *mGUIController; GUIController *mGUIController;

@ -32,6 +32,7 @@
#include "Networking.hpp" #include "Networking.hpp"
#include "Main.hpp" #include "Main.hpp"
#include "processors/ProcessorInitializer.hpp" #include "processors/ProcessorInitializer.hpp"
#include "processors/SystemProcessor.hpp"
#include "processors/PlayerProcessor.hpp" #include "processors/PlayerProcessor.hpp"
#include "processors/ObjectProcessor.hpp" #include "processors/ObjectProcessor.hpp"
#include "processors/ActorProcessor.hpp" #include "processors/ActorProcessor.hpp"
@ -193,8 +194,9 @@ string listComparison(PacketPreInit::PluginContainer checksums, PacketPreInit::P
return sstr.str(); return sstr.str();
} }
Networking::Networking(): peer(RakNet::RakPeerInterface::GetInstance()), playerPacketController(peer), Networking::Networking(): peer(RakNet::RakPeerInterface::GetInstance()), systemPacketController(peer),
actorPacketController(peer), objectPacketController(peer), worldstatePacketController(peer) playerPacketController(peer), actorPacketController(peer), objectPacketController(peer),
worldstatePacketController(peer)
{ {
RakNet::SocketDescriptor sd; RakNet::SocketDescriptor sd;
@ -202,6 +204,7 @@ Networking::Networking(): peer(RakNet::RakPeerInterface::GetInstance()), playerP
auto b = peer->Startup(1, &sd, 1); auto b = peer->Startup(1, &sd, 1);
RakAssert(b==RakNet::CRABNET_STARTED); RakAssert(b==RakNet::CRABNET_STARTED);
systemPacketController.SetStream(0, &bsOut);
playerPacketController.SetStream(0, &bsOut); playerPacketController.SetStream(0, &bsOut);
actorPacketController.SetStream(0, &bsOut); actorPacketController.SetStream(0, &bsOut);
objectPacketController.SetStream(0, &bsOut); objectPacketController.SetStream(0, &bsOut);
@ -344,7 +347,7 @@ void Networking::connect(const std::string &ip, unsigned short port, std::vector
else else
preInit(content, collections); preInit(content, collections);
getLocalPlayer()->guid = peer->GetMyGUID(); getLocalPlayer()->guid = getLocalSystem()->guid = peer->GetMyGUID();
} }
void Networking::preInit(std::vector<std::string> &content, Files::Collections &collections) void Networking::preInit(std::vector<std::string> &content, Files::Collections &collections)
@ -423,7 +426,12 @@ void Networking::receiveMessage(RakNet::Packet *packet)
if (packet->length < 2) if (packet->length < 2)
return; return;
if (playerPacketController.ContainsPacket(packet->data[0])) if (systemPacketController.ContainsPacket(packet->data[0]))
{
if (!SystemProcessor::Process(*packet))
LOG_MESSAGE_SIMPLE(TimedLog::LOG_WARN, "Unhandled SystemPacket with identifier %i has arrived", packet->data[0]);
}
else if (playerPacketController.ContainsPacket(packet->data[0]))
{ {
if (!PlayerProcessor::Process(*packet)) if (!PlayerProcessor::Process(*packet))
LOG_MESSAGE_SIMPLE(TimedLog::LOG_WARN, "Unhandled PlayerPacket with identifier %i has arrived", packet->data[0]); LOG_MESSAGE_SIMPLE(TimedLog::LOG_WARN, "Unhandled PlayerPacket with identifier %i has arrived", packet->data[0]);
@ -445,6 +453,11 @@ void Networking::receiveMessage(RakNet::Packet *packet)
} }
} }
SystemPacket *Networking::getSystemPacket(RakNet::MessageID id)
{
return systemPacketController.GetPacket(id);
}
PlayerPacket *Networking::getPlayerPacket(RakNet::MessageID id) PlayerPacket *Networking::getPlayerPacket(RakNet::MessageID id)
{ {
return playerPacketController.GetPacket(id); return playerPacketController.GetPacket(id);
@ -465,6 +478,11 @@ WorldstatePacket *Networking::getWorldstatePacket(RakNet::MessageID id)
return worldstatePacketController.GetPacket(id); return worldstatePacketController.GetPacket(id);
} }
LocalSystem *Networking::getLocalSystem()
{
return mwmp::Main::get().getLocalSystem();
}
LocalPlayer *Networking::getLocalPlayer() LocalPlayer *Networking::getLocalPlayer()
{ {
return mwmp::Main::get().getLocalPlayer(); return mwmp::Main::get().getLocalPlayer();

@ -7,6 +7,7 @@
#include <components/openmw-mp/NetworkMessages.hpp> #include <components/openmw-mp/NetworkMessages.hpp>
#include <components/openmw-mp/Controllers/SystemPacketController.hpp>
#include <components/openmw-mp/Controllers/PlayerPacketController.hpp> #include <components/openmw-mp/Controllers/PlayerPacketController.hpp>
#include <components/openmw-mp/Controllers/ActorPacketController.hpp> #include <components/openmw-mp/Controllers/ActorPacketController.hpp>
#include <components/openmw-mp/Controllers/ObjectPacketController.hpp> #include <components/openmw-mp/Controllers/ObjectPacketController.hpp>
@ -14,6 +15,7 @@
#include <components/files/collections.hpp> #include <components/files/collections.hpp>
#include "LocalSystem.hpp"
#include "ActorList.hpp" #include "ActorList.hpp"
#include "ObjectList.hpp" #include "ObjectList.hpp"
#include "Worldstate.hpp" #include "Worldstate.hpp"
@ -30,6 +32,7 @@ namespace mwmp
void connect(const std::string& ip, unsigned short port, std::vector<std::string> &content, Files::Collections &collections); void connect(const std::string& ip, unsigned short port, std::vector<std::string> &content, Files::Collections &collections);
void update(); void update();
SystemPacket *getSystemPacket(RakNet::MessageID id);
PlayerPacket *getPlayerPacket(RakNet::MessageID id); PlayerPacket *getPlayerPacket(RakNet::MessageID id);
ActorPacket *getActorPacket(RakNet::MessageID id); ActorPacket *getActorPacket(RakNet::MessageID id);
ObjectPacket *getObjectPacket(RakNet::MessageID id); ObjectPacket *getObjectPacket(RakNet::MessageID id);
@ -42,6 +45,7 @@ namespace mwmp
bool isConnected(); bool isConnected();
LocalSystem *getLocalSystem();
LocalPlayer *getLocalPlayer(); LocalPlayer *getLocalPlayer();
ActorList *getActorList(); ActorList *getActorList();
ObjectList *getObjectList(); ObjectList *getObjectList();
@ -53,6 +57,7 @@ namespace mwmp
RakNet::SystemAddress serverAddr; RakNet::SystemAddress serverAddr;
RakNet::BitStream bsOut; RakNet::BitStream bsOut;
SystemPacketController systemPacketController;
PlayerPacketController playerPacketController; PlayerPacketController playerPacketController;
ActorPacketController actorPacketController; ActorPacketController actorPacketController;
ObjectPacketController objectPacketController; ObjectPacketController objectPacketController;

@ -1,9 +1,11 @@
#include "ProcessorInitializer.hpp" #include "ProcessorInitializer.hpp"
#include "SystemProcessor.hpp"
#include "system/ProcessorSystemHandshake.hpp"
#include "PlayerProcessor.hpp" #include "PlayerProcessor.hpp"
#include "player/ProcessorChatMessage.hpp" #include "player/ProcessorChatMessage.hpp"
#include "player/ProcessorGUIMessageBox.hpp" #include "player/ProcessorGUIMessageBox.hpp"
#include "player/ProcessorHandshake.hpp"
#include "player/ProcessorUserDisconnected.hpp" #include "player/ProcessorUserDisconnected.hpp"
#include "player/ProcessorGameSettings.hpp" #include "player/ProcessorGameSettings.hpp"
#include "player/ProcessorPlayerAnimFlags.hpp" #include "player/ProcessorPlayerAnimFlags.hpp"
@ -103,9 +105,10 @@ using namespace mwmp;
void ProcessorInitializer() void ProcessorInitializer()
{ {
SystemProcessor::AddProcessor(new ProcessorSystemHandshake());
PlayerProcessor::AddProcessor(new ProcessorChatMessage()); PlayerProcessor::AddProcessor(new ProcessorChatMessage());
PlayerProcessor::AddProcessor(new ProcessorGUIMessageBox()); PlayerProcessor::AddProcessor(new ProcessorGUIMessageBox());
PlayerProcessor::AddProcessor(new ProcessorHandshake());
PlayerProcessor::AddProcessor(new ProcessorUserDisconnected()); PlayerProcessor::AddProcessor(new ProcessorUserDisconnected());
PlayerProcessor::AddProcessor(new ProcessorGameSettings()); PlayerProcessor::AddProcessor(new ProcessorGameSettings());
PlayerProcessor::AddProcessor(new ProcessorPlayerAnimFlags()); PlayerProcessor::AddProcessor(new ProcessorPlayerAnimFlags());

@ -0,0 +1,49 @@
#include "../Networking.hpp"
#include "SystemProcessor.hpp"
#include "../Main.hpp"
using namespace mwmp;
template<class T>
typename BasePacketProcessor<T>::processors_t BasePacketProcessor<T>::processors;
SystemProcessor::~SystemProcessor()
{
}
bool SystemProcessor::Process(RakNet::Packet &packet)
{
RakNet::BitStream bsIn(&packet.data[1], packet.length, false);
bsIn.Read(guid);
SystemPacket *myPacket = Main::get().getNetworking()->getSystemPacket(packet.data[0]);
myPacket->SetReadStream(&bsIn);
/*if (myPacket == 0)
{
// error: packet not found
}*/
for (auto &processor : processors)
{
if (processor.first == packet.data[0])
{
myGuid = Main::get().getLocalSystem()->guid;
request = packet.length == myPacket->headerSize();
BaseSystem *system = 0;
system = Main::get().getLocalSystem();
if (!request && !processor.second->avoidReading && system != 0)
{
myPacket->setSystem(system);
myPacket->Read();
}
processor.second->Do(*myPacket, system);
return true;
}
}
return false;
}

@ -0,0 +1,25 @@
#ifndef OPENMW_SYSTEMPROCESSOR_HPP
#define OPENMW_SYSTEMPROCESSOR_HPP
#include <components/openmw-mp/TimedLog.hpp>
#include <components/openmw-mp/NetworkMessages.hpp>
#include <components/openmw-mp/Packets/System/SystemPacket.hpp>
#include "../LocalSystem.hpp"
#include "BaseClientPacketProcessor.hpp"
namespace mwmp
{
class SystemProcessor : public BasePacketProcessor<SystemProcessor>, public BaseClientPacketProcessor
{
public:
virtual void Do(SystemPacket &packet, BaseSystem *system) = 0;
static bool Process(RakNet::Packet &packet);
virtual ~SystemProcessor();
};
}
#endif //OPENMW_SYSTEMPROCESSOR_HPP

@ -1,24 +0,0 @@
#ifndef OPENMW_PROCESSORHANDSHAKE_HPP
#define OPENMW_PROCESSORHANDSHAKE_HPP
#include "../PlayerProcessor.hpp"
namespace mwmp
{
class ProcessorHandshake final: public PlayerProcessor
{
public:
ProcessorHandshake()
{
BPP_INIT(ID_HANDSHAKE)
}
virtual void Do(PlayerPacket &packet, BasePlayer *player)
{
packet.setPlayer(getLocalPlayer()); // player is 0 because myGuid will be set after ProcessUserMyID
packet.Send(serverAddr);
}
};
}
#endif //OPENMW_PROCESSORHANDSHAKE_HPP

@ -0,0 +1,28 @@
#ifndef OPENMW_PROCESSORSYSTEMHANDSHAKE_HPP
#define OPENMW_PROCESSORSYSTEMHANDSHAKE_HPP
#include <components/openmw-mp/Base/BaseSystem.hpp>
#include "apps/openmw/mwmp/Main.hpp"
#include "../SystemProcessor.hpp"
namespace mwmp
{
class ProcessorSystemHandshake final: public SystemProcessor
{
public:
ProcessorSystemHandshake()
{
BPP_INIT(ID_SYSTEM_HANDSHAKE)
}
virtual void Do(SystemPacket &packet, BaseSystem *system)
{
packet.setSystem(Main::get().getLocalSystem());
packet.Send(serverAddr);
}
};
}
#endif //OPENMW_PROCESSORSYSTEMHANDSHAKE_HPP

@ -155,11 +155,11 @@ add_component_dir (openmw-mp
) )
add_component_dir (openmw-mp/Base add_component_dir (openmw-mp/Base
BaseActor BaseObject BasePacketProcessor BasePlayer BaseStructs BaseWorldstate BaseActor BaseObject BasePacketProcessor BasePlayer BaseStructs BaseSystem BaseWorldstate
) )
add_component_dir (openmw-mp/Controllers add_component_dir (openmw-mp/Controllers
PlayerPacketController ActorPacketController ObjectPacketController WorldstatePacketController SystemPacketController PlayerPacketController ActorPacketController ObjectPacketController WorldstatePacketController
) )
add_component_dir(openmw-mp/Master add_component_dir(openmw-mp/Master
@ -178,10 +178,16 @@ add_component_dir (openmw-mp/Packets/Actor
PacketActorSpeech PacketActorStatsDynamic PacketActorSpeech PacketActorStatsDynamic
) )
add_component_dir (openmw-mp/Packets/System
SystemPacket
PacketSystemHandshake
)
add_component_dir (openmw-mp/Packets/Player add_component_dir (openmw-mp/Packets/Player
PlayerPacket PlayerPacket
PacketHandshake PacketChatMessage PacketGUIBoxes PacketGameSettings PacketChatMessage PacketGUIBoxes PacketGameSettings
PacketPlayerBaseInfo PacketPlayerCharGen PacketPlayerActiveSkills PacketPlayerAnimFlags PacketPlayerAnimPlay PacketPlayerBaseInfo PacketPlayerCharGen PacketPlayerActiveSkills PacketPlayerAnimFlags PacketPlayerAnimPlay
PacketPlayerAttack PacketPlayerAttribute PacketPlayerBehavior PacketPlayerBook PacketPlayerBounty PacketPlayerAttack PacketPlayerAttribute PacketPlayerBehavior PacketPlayerBook PacketPlayerBounty

@ -185,7 +185,6 @@ namespace mwmp
} }
RakNet::RakNetGUID guid; RakNet::RakNetGUID guid;
std::string serverPassword;
GUIMessageBox guiMessageBox; GUIMessageBox guiMessageBox;

@ -0,0 +1,31 @@
#ifndef OPENMW_BASESYSTEM_HPP
#define OPENMW_BASESYSTEM_HPP
#include <string>
#include <RakNetTypes.h>
namespace mwmp
{
class BaseSystem
{
public:
BaseSystem(RakNet::RakNetGUID guid) : guid(guid)
{
}
BaseSystem()
{
}
RakNet::RakNetGUID guid;
std::string playerName;
std::string serverPassword;
};
}
#endif //OPENMW_BASESYSTEM_HPP

@ -1,7 +1,6 @@
#include "../Packets/Player/PacketDisconnect.hpp" #include "../Packets/Player/PacketDisconnect.hpp"
#include "../Packets/Player/PacketChatMessage.hpp" #include "../Packets/Player/PacketChatMessage.hpp"
#include "../Packets/Player/PacketPlayerCharGen.hpp" #include "../Packets/Player/PacketPlayerCharGen.hpp"
#include "../Packets/Player/PacketHandshake.hpp"
#include "../Packets/Player/PacketGUIBoxes.hpp" #include "../Packets/Player/PacketGUIBoxes.hpp"
#include "../Packets/Player/PacketLoaded.hpp" #include "../Packets/Player/PacketLoaded.hpp"
#include "../Packets/Player/PacketGameSettings.hpp" #include "../Packets/Player/PacketGameSettings.hpp"
@ -56,7 +55,6 @@ mwmp::PlayerPacketController::PlayerPacketController(RakNet::RakPeerInterface *p
{ {
AddPacket<PacketDisconnect>(&packets, peer); AddPacket<PacketDisconnect>(&packets, peer);
AddPacket<PacketChatMessage>(&packets, peer); AddPacket<PacketChatMessage>(&packets, peer);
AddPacket<PacketHandshake>(&packets, peer);
AddPacket<PacketGUIBoxes>(&packets, peer); AddPacket<PacketGUIBoxes>(&packets, peer);
AddPacket<PacketLoaded>(&packets, peer); AddPacket<PacketLoaded>(&packets, peer);
AddPacket<PacketGameSettings>(&packets, peer); AddPacket<PacketGameSettings>(&packets, peer);

@ -0,0 +1,38 @@
#include "../Packets/System/PacketSystemHandshake.hpp"
#include "SystemPacketController.hpp"
template <typename T>
inline void AddPacket(mwmp::SystemPacketController::packets_t *packets, RakNet::RakPeerInterface *peer)
{
T *packet = new T(peer);
typedef mwmp::SystemPacketController::packets_t::value_type value_t;
packets->insert(value_t(packet->GetPacketID(), value_t::second_type(packet)));
}
mwmp::SystemPacketController::SystemPacketController(RakNet::RakPeerInterface *peer)
{
AddPacket<PacketSystemHandshake>(&packets, peer);
}
mwmp::SystemPacket *mwmp::SystemPacketController::GetPacket(RakNet::MessageID id)
{
return packets[(unsigned char)id].get();
}
void mwmp::SystemPacketController::SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream)
{
for(const auto &packet : packets)
packet.second->SetStreams(inStream, outStream);
}
bool mwmp::SystemPacketController::ContainsPacket(RakNet::MessageID id)
{
for(const auto &packet : packets)
{
if (packet.first == id)
return true;
}
return false;
}

@ -0,0 +1,27 @@
#ifndef OPENMW_SYSTEMPACKETCONTROLLER_HPP
#define OPENMW_SYSTEMPACKETCONTROLLER_HPP
#include <RakPeerInterface.h>
#include "../Packets/System/SystemPacket.hpp"
#include <unordered_map>
#include <memory>
namespace mwmp
{
class SystemPacketController
{
public:
SystemPacketController(RakNet::RakPeerInterface *peer);
SystemPacket *GetPacket(RakNet::MessageID id);
void SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream);
bool ContainsPacket(RakNet::MessageID id);
typedef std::unordered_map<unsigned char, std::unique_ptr<SystemPacket> > packets_t;
private:
packets_t packets;
};
}
#endif //OPENMW_SYSTEMPACKETCONTROLLER_HPP

@ -10,7 +10,7 @@ enum GameMessages
ID_USER_DISCONNECTED, ID_USER_DISCONNECTED,
ID_CHAT_MESSAGE, ID_CHAT_MESSAGE,
ID_HANDSHAKE, ID_SYSTEM_HANDSHAKE,
ID_LOADED, ID_LOADED,
ID_GUI_MESSAGEBOX, ID_GUI_MESSAGEBOX,

@ -1,22 +0,0 @@
#include <components/openmw-mp/NetworkMessages.hpp>
#include "PacketHandshake.hpp"
using namespace mwmp;
PacketHandshake::PacketHandshake(RakNet::RakPeerInterface *peer) : PlayerPacket(peer)
{
packetID = ID_HANDSHAKE;
orderChannel = CHANNEL_SYSTEM;
}
void PacketHandshake::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
if (!RW(player->npc.mName, send, true, maxNameLength) ||
!RW(player->serverPassword, send, true, maxPasswordLength))
{
packetValid = false;
return;
}
}

@ -1,20 +0,0 @@
#ifndef OPENMW_PACKETHANDSHAKE_HPP
#define OPENMW_PACKETHANDSHAKE_HPP
#include <components/openmw-mp/Packets/Player/PlayerPacket.hpp>
namespace mwmp
{
class PacketHandshake : public PlayerPacket
{
public:
PacketHandshake(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
const static uint32_t maxNameLength = 256;
const static uint32_t maxPasswordLength = 256;
};
}
#endif //OPENMW_PACKETHANDSHAKE_HPP

@ -0,0 +1,22 @@
#include <components/openmw-mp/NetworkMessages.hpp>
#include "PacketSystemHandshake.hpp"
using namespace mwmp;
PacketSystemHandshake::PacketSystemHandshake(RakNet::RakPeerInterface *peer) : SystemPacket(peer)
{
packetID = ID_SYSTEM_HANDSHAKE;
orderChannel = CHANNEL_SYSTEM;
}
void PacketSystemHandshake::Packet(RakNet::BitStream *bs, bool send)
{
SystemPacket::Packet(bs, send);
if (!RW(system->playerName, send, true, maxNameLength) ||
!RW(system->serverPassword, send, true, maxPasswordLength))
{
packetValid = false;
return;
}
}

@ -0,0 +1,20 @@
#ifndef OPENMW_PACKETSYSTEMHANDSHAKE_HPP
#define OPENMW_PACKETSYSTEMHANDSHAKE_HPP
#include <components/openmw-mp/Packets/System/SystemPacket.hpp>
namespace mwmp
{
class PacketSystemHandshake : public SystemPacket
{
public:
PacketSystemHandshake(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
const static uint32_t maxNameLength = 256;
const static uint32_t maxPasswordLength = 256;
};
}
#endif //OPENMW_PACKETSYSTEMHANDSHAKE_HPP

@ -0,0 +1,31 @@
#include <components/openmw-mp/NetworkMessages.hpp>
#include <PacketPriority.h>
#include <RakPeer.h>
#include "SystemPacket.hpp"
using namespace mwmp;
SystemPacket::SystemPacket(RakNet::RakPeerInterface *peer) : BasePacket(peer)
{
packetID = 0;
priority = HIGH_PRIORITY;
reliability = RELIABLE_ORDERED;
orderChannel = CHANNEL_SYSTEM;
this->peer = peer;
}
SystemPacket::~SystemPacket()
{
}
void SystemPacket::setSystem(BaseSystem *system)
{
this->system = system;
guid = system->guid;
}
BaseSystem *SystemPacket::getSystem()
{
return system;
}

@ -0,0 +1,30 @@
#ifndef OPENMW_SYSTEMPACKET_HPP
#define OPENMW_SYSTEMPACKET_HPP
#include <string>
#include <RakNetTypes.h>
#include <BitStream.h>
#include <PacketPriority.h>
#include <components/openmw-mp/Base/BaseSystem.hpp>
#include <components/openmw-mp/Packets/BasePacket.hpp>
namespace mwmp
{
class SystemPacket : public BasePacket
{
public:
SystemPacket(RakNet::RakPeerInterface *peer);
~SystemPacket();
void setSystem(BaseSystem *system);
BaseSystem *getSystem();
protected:
BaseSystem *system;
};
}
#endif //OPENMW_SYSTEMPACKET_HPP
Loading…
Cancel
Save