openmw-tes3coop/components/openmw-mp/PacketsController.cpp

82 lines
2.7 KiB
C++
Raw Normal View History

//
// Created by koncord on 15.01.16.
//
2016-08-29 12:26:22 +00:00
#include <boost/shared_ptr.hpp>
#include <boost/foreach.hpp>
#include <boost/make_shared.hpp>
2016-08-29 13:00:19 +00:00
#include "Packets/PacketClass.hpp"
#include "Packets/PacketPosition.hpp"
#include "Packets/PacketBaseInfo.hpp"
#include "components/openmw-mp/Packets/PacketEquiped.hpp"
#include "Packets/PacketAttack.hpp"
#include "Packets/PacketDynamicStatsBase.hpp"
#include "Packets/PacketDynamicStatsCurrent.hpp"
#include "Packets/PacketResurrect.hpp"
#include "Packets/PacketDie.hpp"
#include "Packets/PacketCell.hpp"
#include "Packets/PacketSendMyID.hpp"
#include "Packets/PacketDisconnect.hpp"
#include "Packets/PacketDrawState.hpp"
#include "Packets/PacketChatMessage.hpp"
#include "Packets/PacketCharGen.hpp"
#include "Packets/PacketAttribute.hpp"
#include "Packets/PacketSkill.hpp"
2016-09-25 11:28:25 +00:00
#include "Packets/PacketLevel.hpp"
#include "Packets/PacketHandshake.hpp"
#include "Packets/PacketGUIBoxes.hpp"
2016-08-30 05:24:31 +00:00
#include "Packets/PacketTime.hpp"
2016-09-18 03:50:01 +00:00
#include "Packets/PacketLoaded.hpp"
#include "PacketsController.hpp"
2016-08-29 12:26:22 +00:00
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)
{
2016-08-29 12:26:22 +00:00
AddPacket<PacketPosition>(&packets, peer);
AddPacket<PacketCell>(&packets, peer);
AddPacket<PacketBaseInfo>(&packets, peer);
AddPacket<PacketEquiped>(&packets, peer);
AddPacket<PacketAttack>(&packets, peer);
AddPacket<PacketDynamicStatsBase>(&packets, peer);
AddPacket<PacketDynamicStatsCurrent>(&packets, peer);
2016-08-29 12:26:22 +00:00
AddPacket<PacketResurrect>(&packets, peer);
AddPacket<PacketDie>(&packets, peer);
AddPacket<PacketDrawState>(&packets, peer);
AddPacket<PacketSendMyID>(&packets, peer);
AddPacket<PacketDisconnect>(&packets, peer);
AddPacket<PacketChatMessage>(&packets, peer);
AddPacket<PacketCharGen>(&packets, peer);
AddPacket<PacketAttribute>(&packets, peer);
AddPacket<PacketSkill>(&packets, peer);
2016-09-25 11:28:25 +00:00
AddPacket<PacketLevel>(&packets, peer);
2016-08-29 12:26:22 +00:00
AddPacket<PacketHandshake>(&packets, peer);
AddPacket<PacketGUIBoxes>(&packets, peer);
2016-08-29 13:00:19 +00:00
AddPacket<PacketClass>(&packets, peer);
2016-08-30 05:24:31 +00:00
AddPacket<PacketTime>(&packets, peer);
2016-09-18 03:50:01 +00:00
AddPacket<PacketLoaded>(&packets, peer);
}
mwmp::BasePacket *mwmp::PacketsController::GetPacket(RakNet::MessageID id)
{
2016-08-29 12:26:22 +00:00
return packets[(unsigned char)id].get();
}
void mwmp::PacketsController::SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream)
{
2016-08-29 12:26:22 +00:00
BOOST_FOREACH( packets_t::value_type &packet, packets )
packet.second->SetStreams(inStream, outStream);
}