mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-06 09:45:32 +00:00
[General] Create SystemPacket category and move Handshake packet to it
This commit is contained in:
parent
5762a36fc2
commit
20d1e7654c
27 changed files with 442 additions and 104 deletions
|
@ -41,12 +41,14 @@ Networking::Networking(RakNet::RakPeerInterface *peer) : mclient(nullptr)
|
|||
|
||||
CellController::create();
|
||||
|
||||
systemPacketController = new SystemPacketController(peer);
|
||||
playerPacketController = new PlayerPacketController(peer);
|
||||
actorPacketController = new ActorPacketController(peer);
|
||||
objectPacketController = new ObjectPacketController(peer);
|
||||
worldstatePacketController = new WorldstatePacketController(peer);
|
||||
|
||||
// Set send stream
|
||||
systemPacketController->SetStream(0, &bsOut);
|
||||
playerPacketController->SetStream(0, &bsOut);
|
||||
actorPacketController->SetStream(0, &bsOut);
|
||||
objectPacketController->SetStream(0, &bsOut);
|
||||
|
@ -69,6 +71,7 @@ Networking::~Networking()
|
|||
CellController::destroy();
|
||||
|
||||
sThis = 0;
|
||||
delete systemPacketController;
|
||||
delete playerPacketController;
|
||||
delete actorPacketController;
|
||||
delete objectPacketController;
|
||||
|
@ -85,15 +88,15 @@ bool Networking::isPassworded() const
|
|||
return serverPassword != TES3MP_DEFAULT_PASSW;
|
||||
}
|
||||
|
||||
void Networking::processPlayerPacket(RakNet::Packet *packet)
|
||||
void Networking::processSystemPacket(RakNet::Packet *packet)
|
||||
{
|
||||
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();
|
||||
|
||||
if (!myPacket->isPacketValid())
|
||||
|
@ -110,7 +113,7 @@ void Networking::processPlayerPacket(RakNet::Packet *packet)
|
|||
return;
|
||||
}
|
||||
|
||||
if (player->serverPassword != serverPassword)
|
||||
if (baseSystem.serverPassword != serverPassword)
|
||||
{
|
||||
if (isPassworded())
|
||||
{
|
||||
|
@ -128,6 +131,13 @@ void Networking::processPlayerPacket(RakNet::Packet *packet)
|
|||
player->setHandshake();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void Networking::processPlayerPacket(RakNet::Packet *packet)
|
||||
{
|
||||
Player *player = Players::getPlayer(packet->guid);
|
||||
|
||||
PlayerPacket *myPacket = playerPacketController->GetPacket(packet->data[0]);
|
||||
|
||||
if (!player->isHandshaked())
|
||||
{
|
||||
|
@ -283,8 +293,8 @@ bool Networking::preInit(RakNet::Packet *packet, RakNet::BitStream &bsIn)
|
|||
packetPreInit.setChecksums(&tmp);
|
||||
packetPreInit.Send(packet->systemAddress);
|
||||
Players::newPlayer(packet->guid); // create player if connection allowed
|
||||
playerPacketController->SetStream(&bsIn, nullptr); // and request handshake
|
||||
playerPacketController->GetPacket(ID_HANDSHAKE)->RequestData(packet->guid);
|
||||
systemPacketController->SetStream(&bsIn, nullptr); // and request handshake
|
||||
systemPacketController->GetPacket(ID_SYSTEM_HANDSHAKE)->RequestData(packet->guid);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -293,7 +303,12 @@ bool Networking::preInit(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);
|
||||
processPlayerPacket(packet);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef 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/ActorPacketController.hpp>
|
||||
#include <components/openmw-mp/Controllers/ObjectPacketController.hpp>
|
||||
|
@ -25,6 +26,7 @@ namespace mwmp
|
|||
void unbanAddress(const char *ipAddress);
|
||||
RakNet::SystemAddress getSystemAddress(RakNet::RakNetGUID guid);
|
||||
|
||||
void processSystemPacket(RakNet::Packet *packet);
|
||||
void processPlayerPacket(RakNet::Packet *packet);
|
||||
void processActorPacket(RakNet::Packet *packet);
|
||||
void processObjectPacket(RakNet::Packet *packet);
|
||||
|
@ -40,6 +42,7 @@ namespace mwmp
|
|||
|
||||
void stopServer(int code);
|
||||
|
||||
SystemPacketController *getSystemPacketController() const;
|
||||
PlayerPacketController *getPlayerPacketController() const;
|
||||
ActorPacketController *getActorPacketController() const;
|
||||
ObjectPacketController *getObjectPacketController() const;
|
||||
|
@ -80,10 +83,12 @@ namespace mwmp
|
|||
TPlayers *players;
|
||||
MasterClient *mclient;
|
||||
|
||||
BaseSystem baseSystem;
|
||||
BaseActorList baseActorList;
|
||||
BaseObjectList baseObjectList;
|
||||
BaseWorldstate baseWorldstate;
|
||||
|
||||
SystemPacketController *systemPacketController;
|
||||
PlayerPacketController *playerPacketController;
|
||||
ActorPacketController *actorPacketController;
|
||||
ObjectPacketController *objectPacketController;
|
||||
|
|
|
@ -95,15 +95,18 @@ add_openmw_dir (mwbase
|
|||
inputmanager windowmanager statemanager
|
||||
)
|
||||
|
||||
add_openmw_dir (mwmp Main Networking LocalPlayer DedicatedPlayer PlayerList LocalActor DedicatedActor ActorList ObjectList
|
||||
Worldstate Cell CellController GUIController MechanicsHelper RecordHelper ScriptController
|
||||
add_openmw_dir (mwmp Main Networking LocalSystem LocalPlayer DedicatedPlayer PlayerList LocalActor DedicatedActor ActorList
|
||||
ObjectList Worldstate Cell CellController GUIController MechanicsHelper RecordHelper ScriptController
|
||||
)
|
||||
|
||||
add_openmw_dir (mwmp/GUI GUIChat GUILogin PlayerMarkerCollection GUIDialogList TextInputDialog
|
||||
)
|
||||
|
||||
add_openmw_dir(mwmp/processors BaseClientPacketProcessor PlayerProcessor ObjectProcessor ActorProcessor WorldstateProcessor
|
||||
ProcessorInitializer
|
||||
add_openmw_dir(mwmp/processors BaseClientPacketProcessor SystemProcessor PlayerProcessor ObjectProcessor ActorProcessor
|
||||
WorldstateProcessor ProcessorInitializer
|
||||
)
|
||||
|
||||
add_openmw_dir (mwmp/processors/system ProcessorSystemHandshake
|
||||
)
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
add_openmw_dir (mwmp/processors/player ProcessorChatMessage ProcessorGUIMessageBox ProcessorHandshake
|
||||
ProcessorUserDisconnected ProcessorUserMyID ProcessorGameSettings ProcessorPlayerAnimFlags ProcessorPlayerAnimPlay
|
||||
ProcessorPlayerAttack ProcessorPlayerAttribute ProcessorPlayerBaseInfo ProcessorPlayerBehavior ProcessorPlayerBook
|
||||
ProcessorPlayerBounty ProcessorPlayerCast ProcessorPlayerCellChange ProcessorPlayerCellState ProcessorPlayerCharClass
|
||||
ProcessorPlayerCharGen ProcessorPlayerDeath ProcessorPlayerDisposition ProcessorPlayerEquipment ProcessorPlayerFaction
|
||||
ProcessorPlayerInput ProcessorPlayerInventory ProcessorPlayerItemUse ProcessorPlayerJail ProcessorPlayerJournal
|
||||
ProcessorPlayerLevel ProcessorPlayerMiscellaneous ProcessorPlayerMomentum ProcessorPlayerPosition ProcessorPlayerQuickKeys
|
||||
ProcessorPlayerReputation ProcessorPlayerResurrect ProcessorPlayerShapeshift ProcessorPlayerSkill
|
||||
ProcessorPlayerSpeech ProcessorPlayerSpellbook ProcessorPlayerStatsDynamic ProcessorPlayerTopic
|
||||
ProcessorPlayerPlaceholder
|
||||
add_openmw_dir (mwmp/processors/player ProcessorChatMessage ProcessorGUIMessageBox ProcessorUserDisconnected
|
||||
ProcessorUserMyID ProcessorGameSettings ProcessorPlayerAnimFlags ProcessorPlayerAnimPlay ProcessorPlayerAttack
|
||||
ProcessorPlayerAttribute ProcessorPlayerBaseInfo ProcessorPlayerBehavior ProcessorPlayerBook ProcessorPlayerBounty
|
||||
ProcessorPlayerCast ProcessorPlayerCellChange ProcessorPlayerCellState ProcessorPlayerCharClass ProcessorPlayerCharGen
|
||||
ProcessorPlayerDeath ProcessorPlayerDisposition ProcessorPlayerEquipment ProcessorPlayerFaction ProcessorPlayerInput
|
||||
ProcessorPlayerInventory ProcessorPlayerItemUse ProcessorPlayerJail ProcessorPlayerJournal ProcessorPlayerLevel
|
||||
ProcessorPlayerMiscellaneous ProcessorPlayerMomentum ProcessorPlayerPosition ProcessorPlayerQuickKeys ProcessorPlayerReputation
|
||||
ProcessorPlayerResurrect ProcessorPlayerShapeshift ProcessorPlayerSkill ProcessorPlayerSpeech ProcessorPlayerSpellbook
|
||||
ProcessorPlayerStatsDynamic ProcessorPlayerTopic ProcessorPlayerPlaceholder
|
||||
)
|
||||
|
||||
add_openmw_dir (mwmp/processors/object BaseObjectProcessor
|
||||
|
|
20
apps/openmw/mwmp/LocalSystem.cpp
Normal file
20
apps/openmw/mwmp/LocalSystem.cpp
Normal file
|
@ -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();
|
||||
}
|
23
apps/openmw/mwmp/LocalSystem.hpp
Normal file
23
apps/openmw/mwmp/LocalSystem.hpp
Normal file
|
@ -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 "Networking.hpp"
|
||||
#include "LocalSystem.hpp"
|
||||
#include "LocalPlayer.hpp"
|
||||
#include "DedicatedPlayer.hpp"
|
||||
#include "PlayerList.hpp"
|
||||
|
@ -84,6 +85,7 @@ Main::Main()
|
|||
{
|
||||
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "tes3mp started");
|
||||
mNetworking = new Networking();
|
||||
mLocalSystem = new LocalSystem();
|
||||
mLocalPlayer = new LocalPlayer();
|
||||
mGUIController = new GUIController();
|
||||
mCellController = new CellController();
|
||||
|
@ -96,6 +98,7 @@ Main::~Main()
|
|||
{
|
||||
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "tes3mp stopped");
|
||||
delete mNetworking;
|
||||
delete mLocalSystem;
|
||||
delete mLocalPlayer;
|
||||
delete mCellController;
|
||||
delete mGUIController;
|
||||
|
@ -144,7 +147,7 @@ bool Main::init(std::vector<std::string> &content, Files::Collections &collectio
|
|||
pMain->server = address.substr(0, delimPos);
|
||||
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);
|
||||
|
||||
|
@ -177,7 +180,6 @@ void Main::frame(float dt)
|
|||
get().updateWorld(dt);
|
||||
|
||||
get().getGUIController()->update(dt);
|
||||
|
||||
}
|
||||
|
||||
void Main::updateWorld(float dt) const
|
||||
|
@ -216,12 +218,16 @@ Networking *Main::getNetworking() const
|
|||
return mNetworking;
|
||||
}
|
||||
|
||||
LocalSystem *Main::getLocalSystem() const
|
||||
{
|
||||
return mLocalSystem;
|
||||
}
|
||||
|
||||
LocalPlayer *Main::getLocalPlayer() const
|
||||
{
|
||||
return mLocalPlayer;
|
||||
}
|
||||
|
||||
|
||||
GUIController *Main::getGUIController() const
|
||||
{
|
||||
return mGUIController;
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace mwmp
|
|||
{
|
||||
class GUIController;
|
||||
class CellController;
|
||||
class LocalSystem;
|
||||
class LocalPlayer;
|
||||
class Networking;
|
||||
|
||||
|
@ -32,6 +33,7 @@ namespace mwmp
|
|||
static std::string getResDir();
|
||||
|
||||
Networking *getNetworking() const;
|
||||
LocalSystem *getLocalSystem() const;
|
||||
LocalPlayer *getLocalPlayer() const;
|
||||
GUIController *getGUIController() const;
|
||||
CellController *getCellController() const;
|
||||
|
@ -48,6 +50,7 @@ namespace mwmp
|
|||
///< not implemented
|
||||
static Main *pMain;
|
||||
Networking *mNetworking;
|
||||
LocalSystem *mLocalSystem;
|
||||
LocalPlayer *mLocalPlayer;
|
||||
|
||||
GUIController *mGUIController;
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "Networking.hpp"
|
||||
#include "Main.hpp"
|
||||
#include "processors/ProcessorInitializer.hpp"
|
||||
#include "processors/SystemProcessor.hpp"
|
||||
#include "processors/PlayerProcessor.hpp"
|
||||
#include "processors/ObjectProcessor.hpp"
|
||||
#include "processors/ActorProcessor.hpp"
|
||||
|
@ -193,8 +194,9 @@ string listComparison(PacketPreInit::PluginContainer checksums, PacketPreInit::P
|
|||
return sstr.str();
|
||||
}
|
||||
|
||||
Networking::Networking(): peer(RakNet::RakPeerInterface::GetInstance()), playerPacketController(peer),
|
||||
actorPacketController(peer), objectPacketController(peer), worldstatePacketController(peer)
|
||||
Networking::Networking(): peer(RakNet::RakPeerInterface::GetInstance()), systemPacketController(peer),
|
||||
playerPacketController(peer), actorPacketController(peer), objectPacketController(peer),
|
||||
worldstatePacketController(peer)
|
||||
{
|
||||
|
||||
RakNet::SocketDescriptor sd;
|
||||
|
@ -202,6 +204,7 @@ Networking::Networking(): peer(RakNet::RakPeerInterface::GetInstance()), playerP
|
|||
auto b = peer->Startup(1, &sd, 1);
|
||||
RakAssert(b==RakNet::CRABNET_STARTED);
|
||||
|
||||
systemPacketController.SetStream(0, &bsOut);
|
||||
playerPacketController.SetStream(0, &bsOut);
|
||||
actorPacketController.SetStream(0, &bsOut);
|
||||
objectPacketController.SetStream(0, &bsOut);
|
||||
|
@ -344,7 +347,7 @@ void Networking::connect(const std::string &ip, unsigned short port, std::vector
|
|||
else
|
||||
preInit(content, collections);
|
||||
|
||||
getLocalPlayer()->guid = peer->GetMyGUID();
|
||||
getLocalPlayer()->guid = getLocalSystem()->guid = peer->GetMyGUID();
|
||||
}
|
||||
|
||||
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)
|
||||
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))
|
||||
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)
|
||||
{
|
||||
return playerPacketController.GetPacket(id);
|
||||
|
@ -465,6 +478,11 @@ WorldstatePacket *Networking::getWorldstatePacket(RakNet::MessageID id)
|
|||
return worldstatePacketController.GetPacket(id);
|
||||
}
|
||||
|
||||
LocalSystem *Networking::getLocalSystem()
|
||||
{
|
||||
return mwmp::Main::get().getLocalSystem();
|
||||
}
|
||||
|
||||
LocalPlayer *Networking::getLocalPlayer()
|
||||
{
|
||||
return mwmp::Main::get().getLocalPlayer();
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#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/ActorPacketController.hpp>
|
||||
#include <components/openmw-mp/Controllers/ObjectPacketController.hpp>
|
||||
|
@ -14,6 +15,7 @@
|
|||
|
||||
#include <components/files/collections.hpp>
|
||||
|
||||
#include "LocalSystem.hpp"
|
||||
#include "ActorList.hpp"
|
||||
#include "ObjectList.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 update();
|
||||
|
||||
SystemPacket *getSystemPacket(RakNet::MessageID id);
|
||||
PlayerPacket *getPlayerPacket(RakNet::MessageID id);
|
||||
ActorPacket *getActorPacket(RakNet::MessageID id);
|
||||
ObjectPacket *getObjectPacket(RakNet::MessageID id);
|
||||
|
@ -42,6 +45,7 @@ namespace mwmp
|
|||
|
||||
bool isConnected();
|
||||
|
||||
LocalSystem *getLocalSystem();
|
||||
LocalPlayer *getLocalPlayer();
|
||||
ActorList *getActorList();
|
||||
ObjectList *getObjectList();
|
||||
|
@ -53,6 +57,7 @@ namespace mwmp
|
|||
RakNet::SystemAddress serverAddr;
|
||||
RakNet::BitStream bsOut;
|
||||
|
||||
SystemPacketController systemPacketController;
|
||||
PlayerPacketController playerPacketController;
|
||||
ActorPacketController actorPacketController;
|
||||
ObjectPacketController objectPacketController;
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#include "ProcessorInitializer.hpp"
|
||||
|
||||
#include "SystemProcessor.hpp"
|
||||
#include "system/ProcessorSystemHandshake.hpp"
|
||||
|
||||
#include "PlayerProcessor.hpp"
|
||||
#include "player/ProcessorChatMessage.hpp"
|
||||
#include "player/ProcessorGUIMessageBox.hpp"
|
||||
#include "player/ProcessorHandshake.hpp"
|
||||
#include "player/ProcessorUserDisconnected.hpp"
|
||||
#include "player/ProcessorGameSettings.hpp"
|
||||
#include "player/ProcessorPlayerAnimFlags.hpp"
|
||||
|
@ -103,9 +105,10 @@ using namespace mwmp;
|
|||
|
||||
void ProcessorInitializer()
|
||||
{
|
||||
SystemProcessor::AddProcessor(new ProcessorSystemHandshake());
|
||||
|
||||
PlayerProcessor::AddProcessor(new ProcessorChatMessage());
|
||||
PlayerProcessor::AddProcessor(new ProcessorGUIMessageBox());
|
||||
PlayerProcessor::AddProcessor(new ProcessorHandshake());
|
||||
PlayerProcessor::AddProcessor(new ProcessorUserDisconnected());
|
||||
PlayerProcessor::AddProcessor(new ProcessorGameSettings());
|
||||
PlayerProcessor::AddProcessor(new ProcessorPlayerAnimFlags());
|
||||
|
|
49
apps/openmw/mwmp/processors/SystemProcessor.cpp
Normal file
49
apps/openmw/mwmp/processors/SystemProcessor.cpp
Normal file
|
@ -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;
|
||||
}
|
25
apps/openmw/mwmp/processors/SystemProcessor.hpp
Normal file
25
apps/openmw/mwmp/processors/SystemProcessor.hpp
Normal file
|
@ -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
|
||||
BaseActor BaseObject BasePacketProcessor BasePlayer BaseStructs BaseWorldstate
|
||||
BaseActor BaseObject BasePacketProcessor BasePlayer BaseStructs BaseSystem BaseWorldstate
|
||||
)
|
||||
|
||||
add_component_dir (openmw-mp/Controllers
|
||||
PlayerPacketController ActorPacketController ObjectPacketController WorldstatePacketController
|
||||
SystemPacketController PlayerPacketController ActorPacketController ObjectPacketController WorldstatePacketController
|
||||
)
|
||||
|
||||
add_component_dir(openmw-mp/Master
|
||||
|
@ -178,10 +178,16 @@ add_component_dir (openmw-mp/Packets/Actor
|
|||
PacketActorSpeech PacketActorStatsDynamic
|
||||
)
|
||||
|
||||
add_component_dir (openmw-mp/Packets/System
|
||||
SystemPacket
|
||||
|
||||
PacketSystemHandshake
|
||||
)
|
||||
|
||||
add_component_dir (openmw-mp/Packets/Player
|
||||
PlayerPacket
|
||||
|
||||
PacketHandshake PacketChatMessage PacketGUIBoxes PacketGameSettings
|
||||
PacketChatMessage PacketGUIBoxes PacketGameSettings
|
||||
|
||||
PacketPlayerBaseInfo PacketPlayerCharGen PacketPlayerActiveSkills PacketPlayerAnimFlags PacketPlayerAnimPlay
|
||||
PacketPlayerAttack PacketPlayerAttribute PacketPlayerBehavior PacketPlayerBook PacketPlayerBounty
|
||||
|
|
|
@ -185,7 +185,6 @@ namespace mwmp
|
|||
}
|
||||
|
||||
RakNet::RakNetGUID guid;
|
||||
std::string serverPassword;
|
||||
|
||||
GUIMessageBox guiMessageBox;
|
||||
|
||||
|
|
31
components/openmw-mp/Base/BaseSystem.hpp
Normal file
31
components/openmw-mp/Base/BaseSystem.hpp
Normal file
|
@ -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/PacketChatMessage.hpp"
|
||||
#include "../Packets/Player/PacketPlayerCharGen.hpp"
|
||||
#include "../Packets/Player/PacketHandshake.hpp"
|
||||
#include "../Packets/Player/PacketGUIBoxes.hpp"
|
||||
#include "../Packets/Player/PacketLoaded.hpp"
|
||||
#include "../Packets/Player/PacketGameSettings.hpp"
|
||||
|
@ -56,7 +55,6 @@ mwmp::PlayerPacketController::PlayerPacketController(RakNet::RakPeerInterface *p
|
|||
{
|
||||
AddPacket<PacketDisconnect>(&packets, peer);
|
||||
AddPacket<PacketChatMessage>(&packets, peer);
|
||||
AddPacket<PacketHandshake>(&packets, peer);
|
||||
AddPacket<PacketGUIBoxes>(&packets, peer);
|
||||
AddPacket<PacketLoaded>(&packets, peer);
|
||||
AddPacket<PacketGameSettings>(&packets, peer);
|
||||
|
|
38
components/openmw-mp/Controllers/SystemPacketController.cpp
Normal file
38
components/openmw-mp/Controllers/SystemPacketController.cpp
Normal file
|
@ -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;
|
||||
}
|
27
components/openmw-mp/Controllers/SystemPacketController.hpp
Normal file
27
components/openmw-mp/Controllers/SystemPacketController.hpp
Normal file
|
@ -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_CHAT_MESSAGE,
|
||||
|
||||
ID_HANDSHAKE,
|
||||
ID_SYSTEM_HANDSHAKE,
|
||||
ID_LOADED,
|
||||
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
|
31
components/openmw-mp/Packets/System/SystemPacket.cpp
Normal file
31
components/openmw-mp/Packets/System/SystemPacket.cpp
Normal file
|
@ -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;
|
||||
}
|
30
components/openmw-mp/Packets/System/SystemPacket.hpp
Normal file
30
components/openmw-mp/Packets/System/SystemPacket.hpp
Normal file
|
@ -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…
Reference in a new issue