1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-26 00:04:43 +01:00

Refactor broadcasting code and logging

This commit is contained in:
Ted John
2019-05-05 14:28:10 +00:00
parent 4f0a733496
commit 04c04d197e
3 changed files with 39 additions and 30 deletions

View File

@@ -217,15 +217,18 @@ std::future<std::vector<ServerListEntry>> ServerList::FetchLocalServerListAsync(
constexpr auto RECV_DELAY_MS = 10;
constexpr auto RECV_WAIT_MS = 2000;
std::vector<ServerListEntry> entries;
auto broadcastAddress = "192.168.1.255";
std::string msg = "Are you an OpenRCT2 server?";
auto udpSocket = CreateUdpSocket();
auto len = udpSocket->SendData("192.168.1.255", 11754, msg.data(), msg.size());
log_verbose("Broadcasting %zu bytes to the LAN (%s)", msg.size(), broadcastAddress);
auto len = udpSocket->SendData(broadcastAddress, NETWORK_LAN_BROADCAST_PORT, msg.data(), msg.size());
if (len != msg.size())
{
throw std::runtime_error("Unable to broadcast server query.");
}
std::vector<ServerListEntry> entries;
char buffer[1024]{};
size_t recievedLen{};
std::unique_ptr<INetworkEndpoint> endpoint;
@@ -235,7 +238,7 @@ std::future<std::vector<ServerListEntry>> ServerList::FetchLocalServerListAsync(
if (p == NETWORK_READPACKET_SUCCESS)
{
auto sender = endpoint->GetHostname();
std::printf(">> Recieved packet from %s\n", sender.c_str());
log_verbose("Received %zu bytes back from %s", recievedLen, sender.c_str());
auto jinfo = Json::FromString(std::string_view(buffer));
auto ip4 = json_array();