[General] Create SystemPacket category and move Handshake packet to it
parent
5762a36fc2
commit
20d1e7654c
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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…
Reference in New Issue