forked from mirror/openmw-tes3mp
[Browser] Simplify PingRakNetServer()
This commit is contained in:
parent
a9fc096c9a
commit
7a6c12bc2a
1 changed files with 4 additions and 13 deletions
|
@ -18,27 +18,18 @@ unsigned int PingRakNetServer(const char *addr, unsigned short port)
|
||||||
{
|
{
|
||||||
RakNet::Packet *packet;
|
RakNet::Packet *packet;
|
||||||
bool done = false;
|
bool done = false;
|
||||||
int attempt = 0;
|
|
||||||
static const int timeout = 5;
|
|
||||||
static const int attempts = 5;
|
|
||||||
RakNet::TimeMS time = PING_UNREACHABLE;
|
RakNet::TimeMS time = PING_UNREACHABLE;
|
||||||
|
|
||||||
RakNet::SocketDescriptor socketDescriptor{0, ""};
|
RakNet::SocketDescriptor socketDescriptor{0, ""};
|
||||||
RakNet::RakPeerInterface *peer = RakNet::RakPeerInterface::GetInstance();
|
RakNet::RakPeerInterface *peer = RakNet::RakPeerInterface::GetInstance();
|
||||||
peer->Startup(1, &socketDescriptor, 1);
|
peer->Startup(1, &socketDescriptor, 1);
|
||||||
|
if (!peer->Ping(addr, port, false))
|
||||||
peer->Ping(addr, port, false);
|
return time;
|
||||||
while (!done)
|
while (!done)
|
||||||
{
|
{
|
||||||
packet = peer->Receive();
|
packet = peer->Receive();
|
||||||
if (!packet)
|
if (!packet)
|
||||||
{
|
|
||||||
if (attempt > attempts)
|
|
||||||
done = true;
|
|
||||||
attempt++;
|
|
||||||
RakSleep(timeout);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
switch (packet->data[0])
|
switch (packet->data[0])
|
||||||
{
|
{
|
||||||
|
@ -50,7 +41,7 @@ unsigned int PingRakNetServer(const char *addr, unsigned short port)
|
||||||
case ID_UNCONNECTED_PONG:
|
case ID_UNCONNECTED_PONG:
|
||||||
RakNet::BitStream bsIn(&packet->data[1], packet->length, false);
|
RakNet::BitStream bsIn(&packet->data[1], packet->length, false);
|
||||||
bsIn.Read(time);
|
bsIn.Read(time);
|
||||||
time = RakNet::GetTimeMS() - time - timeout;
|
time = RakNet::GetTimeMS() - time;
|
||||||
done = true;
|
done = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -59,7 +50,7 @@ unsigned int PingRakNetServer(const char *addr, unsigned short port)
|
||||||
|
|
||||||
peer->Shutdown(0);
|
peer->Shutdown(0);
|
||||||
RakNet::RakPeerInterface::DestroyInstance(peer);
|
RakNet::RakPeerInterface::DestroyInstance(peer);
|
||||||
return time;
|
return time > PING_UNREACHABLE ? PING_UNREACHABLE : time;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerExtendedData getExtendedData(const char *addr, unsigned short port)
|
ServerExtendedData getExtendedData(const char *addr, unsigned short port)
|
||||||
|
|
Loading…
Reference in a new issue