mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 09:53:50 +00:00
Simplified PacketsController
This commit is contained in:
parent
f67bad2260
commit
2054baf7d3
2 changed files with 36 additions and 148 deletions
|
@ -2,6 +2,10 @@
|
||||||
// Created by koncord on 15.01.16.
|
// Created by koncord on 15.01.16.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
|
#include <boost/make_shared.hpp>
|
||||||
|
|
||||||
#include "Packets/PacketPosition.hpp"
|
#include "Packets/PacketPosition.hpp"
|
||||||
#include "Packets/PacketBaseInfo.hpp"
|
#include "Packets/PacketBaseInfo.hpp"
|
||||||
#include "components/openmw-mp/Packets/PacketEquiped.hpp"
|
#include "components/openmw-mp/Packets/PacketEquiped.hpp"
|
||||||
|
@ -23,123 +27,48 @@
|
||||||
|
|
||||||
#include "PacketsController.hpp"
|
#include "PacketsController.hpp"
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline void AddPacket(mwmp::PacketsController::packets_t *packets, RakNet::RakPeerInterface *peer)
|
||||||
|
{
|
||||||
|
T *packet = new T(peer);
|
||||||
|
typedef mwmp::PacketsController::packets_t::value_type value_t;
|
||||||
|
packets->insert(value_t(packet->GetPacketID(), value_t::second_type(packet)));
|
||||||
|
}
|
||||||
|
|
||||||
mwmp::PacketsController::PacketsController(RakNet::RakPeerInterface *peer)
|
mwmp::PacketsController::PacketsController(RakNet::RakPeerInterface *peer)
|
||||||
{
|
{
|
||||||
packetPosition = new PacketPosition(peer);
|
AddPacket<PacketPosition>(&packets, peer);
|
||||||
packetCell = new PacketCell(peer);
|
AddPacket<PacketCell>(&packets, peer);
|
||||||
packetBaseInfo = new PacketBaseInfo(peer);
|
AddPacket<PacketBaseInfo>(&packets, peer);
|
||||||
packetEquiped = new PacketEquiped(peer);
|
AddPacket<PacketEquiped>(&packets, peer);
|
||||||
attributesAndStats = new PacketAttributesAndStats(peer);
|
|
||||||
packetAttack = new PacketAttack(peer);
|
|
||||||
packetMainStats = new PacketMainStats(peer);
|
|
||||||
packetResurrect = new PacketResurrect(peer);
|
|
||||||
packetDie = new PacketDie(peer);
|
|
||||||
packetDrawState = new PacketDrawState(peer);
|
|
||||||
|
|
||||||
packetSendMyID = new PacketSendMyID(peer);
|
AddPacket<PacketAttributesAndStats>(&packets, peer);
|
||||||
packetDisconnect = new PacketDisconnect(peer);
|
AddPacket<PacketAttack>(&packets, peer);
|
||||||
|
AddPacket<PacketMainStats>(&packets, peer);
|
||||||
|
AddPacket<PacketResurrect>(&packets, peer);
|
||||||
|
|
||||||
packetChatMessage = new PacketChatMessage(peer);
|
AddPacket<PacketDie>(&packets, peer);
|
||||||
packetCharGen = new PacketCharGen(peer);
|
AddPacket<PacketDrawState>(&packets, peer);
|
||||||
|
AddPacket<PacketSendMyID>(&packets, peer);
|
||||||
|
AddPacket<PacketDisconnect>(&packets, peer);
|
||||||
|
|
||||||
packetAttribute = new PacketAttribute(peer);
|
AddPacket<PacketChatMessage>(&packets, peer);
|
||||||
packetSkill = new PacketSkill(peer);
|
AddPacket<PacketCharGen>(&packets, peer);
|
||||||
|
AddPacket<PacketAttribute>(&packets, peer);
|
||||||
|
AddPacket<PacketSkill>(&packets, peer);
|
||||||
|
|
||||||
packetHandshake = new PacketHandshake(peer);
|
AddPacket<PacketHandshake>(&packets, peer);
|
||||||
|
AddPacket<PacketGUIBoxes>(&packets, peer);
|
||||||
packetGUIBoxes = new PacketGUIBoxes(peer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mwmp::BasePacket *mwmp::PacketsController::GetPacket(RakNet::MessageID id)
|
mwmp::BasePacket *mwmp::PacketsController::GetPacket(RakNet::MessageID id)
|
||||||
{
|
{
|
||||||
BasePacket * packet;
|
return packets[(unsigned char)id].get();
|
||||||
switch (id)
|
|
||||||
{
|
|
||||||
case ID_GAME_UPDATE_POS:
|
|
||||||
packet = packetPosition;
|
|
||||||
break;
|
|
||||||
case ID_GAME_CELL:
|
|
||||||
packet = packetCell;
|
|
||||||
break;
|
|
||||||
case ID_GAME_BASE_INFO:
|
|
||||||
packet = packetBaseInfo;
|
|
||||||
break;
|
|
||||||
case ID_GAME_UPDATE_EQUIPED:
|
|
||||||
packet = packetEquiped;
|
|
||||||
break;
|
|
||||||
case ID_GAME_UPDATE_SKILLS:
|
|
||||||
packet = attributesAndStats;
|
|
||||||
break;
|
|
||||||
case ID_GAME_ATTACK:
|
|
||||||
packet = packetAttack;
|
|
||||||
break;
|
|
||||||
case ID_GAME_UPDATE_BASESTATS:
|
|
||||||
packet = packetMainStats;
|
|
||||||
break;
|
|
||||||
case ID_GAME_RESURRECT:
|
|
||||||
packet = packetResurrect;
|
|
||||||
break;
|
|
||||||
case ID_GAME_DIE:
|
|
||||||
packet = packetDie;
|
|
||||||
break;
|
|
||||||
case ID_GAME_DRAWSTATE:
|
|
||||||
packet = packetDrawState;
|
|
||||||
break;
|
|
||||||
case ID_USER_MYID:
|
|
||||||
packet = packetSendMyID;
|
|
||||||
break;
|
|
||||||
case ID_USER_DISCONNECTED:
|
|
||||||
packet = packetDisconnect;
|
|
||||||
break;
|
|
||||||
case ID_CHAT_MESSAGE:
|
|
||||||
packet = packetChatMessage;
|
|
||||||
break;
|
|
||||||
case ID_GAME_CHARGEN:
|
|
||||||
packet = packetCharGen;
|
|
||||||
break;
|
|
||||||
case ID_GAME_ATTRIBUTE:
|
|
||||||
packet = packetAttribute;
|
|
||||||
break;
|
|
||||||
case ID_GAME_SKILL:
|
|
||||||
packet = packetSkill;
|
|
||||||
break;
|
|
||||||
case ID_HANDSHAKE:
|
|
||||||
packet = packetHandshake;
|
|
||||||
break;
|
|
||||||
case ID_GUI_MESSAGEBOX:
|
|
||||||
packet = packetGUIBoxes;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
packet = 0;
|
|
||||||
}
|
|
||||||
return packet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mwmp::PacketsController::SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream)
|
void mwmp::PacketsController::SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream)
|
||||||
{
|
{
|
||||||
packetPosition->SetStreams(inStream, outStream);
|
BOOST_FOREACH( packets_t::value_type &packet, packets )
|
||||||
packetCell->SetStreams(inStream, outStream);
|
packet.second->SetStreams(inStream, outStream);
|
||||||
packetBaseInfo->SetStreams(inStream, outStream);
|
|
||||||
packetEquiped->SetStreams(inStream, outStream);
|
|
||||||
attributesAndStats->SetStreams(inStream, outStream);
|
|
||||||
packetAttack->SetStreams(inStream, outStream);
|
|
||||||
packetMainStats->SetStreams(inStream, outStream);
|
|
||||||
packetResurrect->SetStreams(inStream, outStream);
|
|
||||||
packetDie->SetStreams(inStream, outStream);
|
|
||||||
packetDrawState->SetStreams(inStream, outStream);
|
|
||||||
|
|
||||||
packetSendMyID->SetStreams(inStream, outStream);
|
|
||||||
packetDisconnect->SetStreams(inStream, outStream);
|
|
||||||
|
|
||||||
packetChatMessage->SetStreams(inStream, outStream);
|
|
||||||
packetCharGen->SetStreams(inStream, outStream);
|
|
||||||
|
|
||||||
packetAttribute->SetStreams(inStream, outStream);
|
|
||||||
packetSkill->SetStreams(inStream, outStream);
|
|
||||||
|
|
||||||
packetHandshake->SetStreams(inStream, outStream);
|
|
||||||
|
|
||||||
packetGUIBoxes->SetStreams(inStream, outStream);
|
|
||||||
}
|
}
|
|
@ -8,62 +8,21 @@
|
||||||
|
|
||||||
#include <RakPeerInterface.h>
|
#include <RakPeerInterface.h>
|
||||||
#include "Packets/BasePacket.hpp"
|
#include "Packets/BasePacket.hpp"
|
||||||
|
#include <map>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
namespace mwmp
|
namespace mwmp
|
||||||
{
|
{
|
||||||
class PacketPosition;
|
|
||||||
class PacketCell;
|
|
||||||
class PacketBaseInfo;
|
|
||||||
class PacketEquiped;
|
|
||||||
class PacketAttributesAndStats;
|
|
||||||
class PacketAttack;
|
|
||||||
class PacketMainStats;
|
|
||||||
class PacketResurrect;
|
|
||||||
class PacketDie;
|
|
||||||
class PacketDrawState;
|
|
||||||
|
|
||||||
class PacketSendMyID;
|
|
||||||
class PacketDisconnect;
|
|
||||||
|
|
||||||
class PacketChatMessage;
|
|
||||||
class PacketCharGen;
|
|
||||||
|
|
||||||
class PacketAttribute;
|
|
||||||
class PacketSkill;
|
|
||||||
class PacketHandshake;
|
|
||||||
|
|
||||||
class PacketGUIBoxes;
|
|
||||||
|
|
||||||
class PacketsController
|
class PacketsController
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PacketsController(RakNet::RakPeerInterface *peer);
|
PacketsController(RakNet::RakPeerInterface *peer);
|
||||||
|
|
||||||
BasePacket *GetPacket(RakNet::MessageID id);
|
BasePacket *GetPacket(RakNet::MessageID id);
|
||||||
|
|
||||||
void SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream);
|
void SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream);
|
||||||
|
|
||||||
|
typedef std::map<unsigned char, boost::shared_ptr<BasePacket> > packets_t;
|
||||||
private:
|
private:
|
||||||
PacketPosition *packetPosition;
|
packets_t packets;
|
||||||
PacketCell *packetCell;
|
|
||||||
PacketBaseInfo *packetBaseInfo;
|
|
||||||
PacketEquiped *packetEquiped;
|
|
||||||
PacketAttributesAndStats *attributesAndStats;
|
|
||||||
PacketAttack *packetAttack;
|
|
||||||
PacketMainStats *packetMainStats;
|
|
||||||
PacketResurrect *packetResurrect;
|
|
||||||
PacketDie *packetDie;
|
|
||||||
PacketDrawState *packetDrawState;
|
|
||||||
|
|
||||||
PacketSendMyID *packetSendMyID;
|
|
||||||
PacketDisconnect *packetDisconnect;
|
|
||||||
|
|
||||||
PacketChatMessage *packetChatMessage;
|
|
||||||
PacketCharGen *packetCharGen;
|
|
||||||
PacketAttribute *packetAttribute;
|
|
||||||
PacketSkill *packetSkill;
|
|
||||||
PacketHandshake *packetHandshake;
|
|
||||||
PacketGUIBoxes *packetGUIBoxes;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue