2017-04-23 05:36:47 +00:00
|
|
|
#include <components/openmw-mp/NetworkMessages.hpp>
|
|
|
|
#include <iostream>
|
|
|
|
#include "MasterData.hpp"
|
|
|
|
#include "PacketMasterQuery.hpp"
|
|
|
|
#include "ProxyMasterPacket.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
using namespace mwmp;
|
|
|
|
using namespace RakNet;
|
|
|
|
|
|
|
|
PacketMasterQuery::PacketMasterQuery(RakNet::RakPeerInterface *peer) : BasePacket(peer)
|
|
|
|
{
|
|
|
|
packetID = ID_MASTER_QUERY;
|
|
|
|
orderChannel = CHANNEL_MASTER;
|
2017-07-31 10:58:51 +00:00
|
|
|
reliability = RELIABLE_ORDERED_WITH_ACK_RECEIPT;
|
2017-04-23 05:36:47 +00:00
|
|
|
}
|
|
|
|
|
2019-12-04 08:17:33 +00:00
|
|
|
void PacketMasterQuery::Packet(RakNet::BitStream *newBitstream, bool send)
|
2017-04-23 05:36:47 +00:00
|
|
|
{
|
2019-12-04 08:17:33 +00:00
|
|
|
bs = newBitstream;
|
2017-04-23 05:36:47 +00:00
|
|
|
if (send)
|
|
|
|
bs->Write(packetID);
|
|
|
|
|
2018-07-02 15:28:25 +00:00
|
|
|
int32_t serversCount = servers->size();
|
2017-04-23 05:36:47 +00:00
|
|
|
|
|
|
|
RW(serversCount, send);
|
|
|
|
|
2021-03-20 22:07:12 +00:00
|
|
|
std::map<SystemAddress, QueryData>::iterator serverIt;
|
2017-05-02 19:47:58 +00:00
|
|
|
if (send)
|
2017-04-23 05:36:47 +00:00
|
|
|
serverIt = servers->begin();
|
|
|
|
|
2017-04-24 11:58:48 +00:00
|
|
|
QueryData server;
|
2021-03-20 22:07:12 +00:00
|
|
|
std::string addr;
|
2018-07-02 15:28:25 +00:00
|
|
|
uint16_t port;
|
2017-05-31 05:37:11 +00:00
|
|
|
while (serversCount--)
|
2017-04-23 05:36:47 +00:00
|
|
|
{
|
2017-05-02 19:47:58 +00:00
|
|
|
if (send)
|
2017-04-23 05:36:47 +00:00
|
|
|
{
|
2017-05-20 08:46:59 +00:00
|
|
|
addr = serverIt->first.ToString(false);
|
|
|
|
port = serverIt->first.GetPort();
|
2017-04-23 05:36:47 +00:00
|
|
|
server = serverIt->second;
|
|
|
|
}
|
2017-05-20 08:46:59 +00:00
|
|
|
RW(addr, send);
|
|
|
|
RW(port, send);
|
2017-04-23 05:36:47 +00:00
|
|
|
|
|
|
|
ProxyMasterPacket::addServer(this, server, send);
|
|
|
|
|
2018-07-02 15:28:25 +00:00
|
|
|
if(addr.empty())
|
|
|
|
{
|
|
|
|
std::cerr << "Address empty. Aborting PacketMasterQuery::Packet" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-02 19:47:58 +00:00
|
|
|
if (send)
|
2017-04-23 05:36:47 +00:00
|
|
|
serverIt++;
|
|
|
|
else
|
2021-03-20 22:07:12 +00:00
|
|
|
servers->insert(std::pair<SystemAddress, QueryData>(SystemAddress(addr.c_str(), port), server));
|
2017-04-23 05:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-03-20 22:07:12 +00:00
|
|
|
void PacketMasterQuery::SetServers(std::map<SystemAddress, QueryData> *serverMap)
|
2017-04-23 05:36:47 +00:00
|
|
|
{
|
|
|
|
servers = serverMap;
|
|
|
|
}
|