// // Created by koncord on 26.02.18. // #pragma once #include #include #include namespace mwmp { template class BasePacketController { public: bool ContainsPacket(RakNet::MessageID id) const { return packets.count(id) == 1; } PacketT *GetPacket(RakNet::MessageID id) { return packets.at(id).get(); //operator[] calls rehash() if key not found, that not applicable here. } void SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream) { for (const auto &packet : packets) packet.second->SetStreams(inStream, outStream); } typedef std::unordered_map > packets_t; protected: template inline void static AddPacket(packets_t *packets, RakNet::RakPeerInterface *peer) { auto packet = new T(peer); RakNet::MessageID packetId = packet->GetPacketID(); packets->emplace(packetId, packet); } protected: packets_t packets; }; }