// // Created by koncord on 22.04.17. // #include #include #include "MasterData.hpp" #include "PacketMasterQuery.hpp" #include "ProxyMasterPacket.hpp" using namespace mwmp; using namespace std; using namespace RakNet; PacketMasterQuery::PacketMasterQuery(RakNet::RakPeerInterface *peer) : BasePacket(peer) { packetID = ID_MASTER_QUERY; orderChannel = CHANNEL_MASTER; reliability = RELIABLE_ORDERED_WITH_ACK_RECEIPT; } void PacketMasterQuery::Packet(RakNet::BitStream *bs, bool send) { this->bs = bs; if (send) bs->Write(packetID); int32_t serversCount = servers->size(); RW(serversCount, send); map::iterator serverIt; if (send) serverIt = servers->begin(); QueryData server; string addr; uint16_t port; while (serversCount--) { if (send) { addr = serverIt->first.ToString(false); port = serverIt->first.GetPort(); server = serverIt->second; } RW(addr, send); RW(port, send); ProxyMasterPacket::addServer(this, server, send); if(addr.empty()) { std::cerr << "Address empty. Aborting PacketMasterQuery::Packet" << std::endl; return; } if (send) serverIt++; else servers->insert(pair(SystemAddress(addr.c_str(), port), server)); } } void PacketMasterQuery::SetServers(map *serverMap) { servers = serverMap; }