|
|
|
//
|
|
|
|
// Created by koncord on 07.01.17.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <RakPeer.h>
|
|
|
|
#include <MessageIdentifiers.h>
|
|
|
|
#include <RakSleep.h>
|
|
|
|
#include <GetTime.h>
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <components/openmw-mp/Version.hpp>
|
|
|
|
|
|
|
|
#include "Utils.hpp"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
unsigned int PingRakNetServer(const char *addr, unsigned short port)
|
|
|
|
{
|
|
|
|
RakNet::Packet *packet;
|
|
|
|
bool done = false;
|
|
|
|
RakNet::TimeMS time = PING_UNREACHABLE;
|
|
|
|
|
|
|
|
RakNet::SocketDescriptor socketDescriptor{0, ""};
|
|
|
|
RakNet::RakPeerInterface *peer = RakNet::RakPeerInterface::GetInstance();
|
|
|
|
peer->Startup(1, &socketDescriptor, 1);
|
|
|
|
if (!peer->Ping(addr, port, false))
|
|
|
|
return time;
|
|
|
|
RakNet::TimeMS start = RakNet::GetTimeMS();
|
|
|
|
while (!done)
|
|
|
|
{
|
|
|
|
RakNet::TimeMS now = RakNet::GetTimeMS();
|
|
|
|
if (now - start >= PING_UNREACHABLE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
packet = peer->Receive();
|
|
|
|
if (!packet)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (packet->data[0])
|
|
|
|
{
|
|
|
|
case ID_DISCONNECTION_NOTIFICATION:
|
|
|
|
case ID_CONNECTION_LOST:
|
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
case ID_CONNECTED_PING:
|
|
|
|
case ID_UNCONNECTED_PONG:
|
[Browser] Rework browser for improved stability & clarity
(cherry picked from commits 5c79e7106f840ef217b9bf45ec5d3bd925825863, 57353cdffff3580566415039544fae15052e8d73, 15723adb9a0383d8ebb8b7e26849b2de70b9952d, 01a5196a92f27f0c09bd053daf4d779d0c113974, ed75563a94174ca38cb67beba9c0e35a810dfbd2, 3839a2dcfd8fbbc7598771ee604f9ff9eb08e044, 1fd16ba69c4893cfe7379ea6bb0f65e5ac59cd4b, 66283943c593a406592daf0b90491d42a2e80050, ba8613a179936631d6c5fa7ae6dedb8a5f3eb684, 5b8f4f3e92d662f36580b94184057b648be9f01d, 35b771b19e00a813350553f686c0971334bbc3b5, 043eb224e29ca7b41a738eb598e16131ccfedd1a, 05fac2f67d5281d72b48bdba0db14e6bd7974765)
7 years ago
|
|
|
{
|
|
|
|
RakNet::BitStream bsIn(&packet->data[1], packet->length, false);
|
|
|
|
bsIn.Read(time);
|
|
|
|
time = now - time;
|
|
|
|
done = true;
|
|
|
|
break;
|
[Browser] Rework browser for improved stability & clarity
(cherry picked from commits 5c79e7106f840ef217b9bf45ec5d3bd925825863, 57353cdffff3580566415039544fae15052e8d73, 15723adb9a0383d8ebb8b7e26849b2de70b9952d, 01a5196a92f27f0c09bd053daf4d779d0c113974, ed75563a94174ca38cb67beba9c0e35a810dfbd2, 3839a2dcfd8fbbc7598771ee604f9ff9eb08e044, 1fd16ba69c4893cfe7379ea6bb0f65e5ac59cd4b, 66283943c593a406592daf0b90491d42a2e80050, ba8613a179936631d6c5fa7ae6dedb8a5f3eb684, 5b8f4f3e92d662f36580b94184057b648be9f01d, 35b771b19e00a813350553f686c0971334bbc3b5, 043eb224e29ca7b41a738eb598e16131ccfedd1a, 05fac2f67d5281d72b48bdba0db14e6bd7974765)
7 years ago
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
peer->DeallocatePacket(packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
peer->Shutdown(0);
|
|
|
|
RakNet::RakPeerInterface::DestroyInstance(peer);
|
|
|
|
return time > PING_UNREACHABLE ? PING_UNREACHABLE : time;
|
|
|
|
}
|
|
|
|
|
|
|
|
ServerExtendedData getExtendedData(const char *addr, unsigned short port)
|
|
|
|
{
|
|
|
|
ServerExtendedData data;
|
|
|
|
RakNet::SocketDescriptor socketDescriptor = {0, ""};
|
|
|
|
RakNet::RakPeerInterface *peer = RakNet::RakPeerInterface::GetInstance();
|
|
|
|
peer->Startup(1, &socketDescriptor, 1);
|
|
|
|
|
|
|
|
stringstream sstr;
|
|
|
|
sstr << TES3MP_VERSION;
|
|
|
|
sstr << TES3MP_PROTO_VERSION;
|
|
|
|
|
[Browser] Rework browser for improved stability & clarity
(cherry picked from commits 5c79e7106f840ef217b9bf45ec5d3bd925825863, 57353cdffff3580566415039544fae15052e8d73, 15723adb9a0383d8ebb8b7e26849b2de70b9952d, 01a5196a92f27f0c09bd053daf4d779d0c113974, ed75563a94174ca38cb67beba9c0e35a810dfbd2, 3839a2dcfd8fbbc7598771ee604f9ff9eb08e044, 1fd16ba69c4893cfe7379ea6bb0f65e5ac59cd4b, 66283943c593a406592daf0b90491d42a2e80050, ba8613a179936631d6c5fa7ae6dedb8a5f3eb684, 5b8f4f3e92d662f36580b94184057b648be9f01d, 35b771b19e00a813350553f686c0971334bbc3b5, 043eb224e29ca7b41a738eb598e16131ccfedd1a, 05fac2f67d5281d72b48bdba0db14e6bd7974765)
7 years ago
|
|
|
std::string msg;
|
|
|
|
|
[Browser] Rework browser for improved stability & clarity
(cherry picked from commits 5c79e7106f840ef217b9bf45ec5d3bd925825863, 57353cdffff3580566415039544fae15052e8d73, 15723adb9a0383d8ebb8b7e26849b2de70b9952d, 01a5196a92f27f0c09bd053daf4d779d0c113974, ed75563a94174ca38cb67beba9c0e35a810dfbd2, 3839a2dcfd8fbbc7598771ee604f9ff9eb08e044, 1fd16ba69c4893cfe7379ea6bb0f65e5ac59cd4b, 66283943c593a406592daf0b90491d42a2e80050, ba8613a179936631d6c5fa7ae6dedb8a5f3eb684, 5b8f4f3e92d662f36580b94184057b648be9f01d, 35b771b19e00a813350553f686c0971334bbc3b5, 043eb224e29ca7b41a738eb598e16131ccfedd1a, 05fac2f67d5281d72b48bdba0db14e6bd7974765)
7 years ago
|
|
|
if (peer->Connect(addr, port, sstr.str().c_str(), (int)(sstr.str().size()), nullptr, 0, 3, 500, 0) != RakNet::CONNECTION_ATTEMPT_STARTED)
|
|
|
|
msg = "Connection attempt failed.\n";
|
|
|
|
|
|
|
|
|
|
|
|
int queue = 0;
|
|
|
|
while (queue == 0)
|
|
|
|
{
|
|
|
|
for (RakNet::Packet *packet = peer->Receive(); packet; peer->DeallocatePacket(
|
|
|
|
packet), packet = peer->Receive())
|
|
|
|
{
|
|
|
|
switch (packet->data[0])
|
|
|
|
{
|
|
|
|
case ID_CONNECTION_ATTEMPT_FAILED:
|
|
|
|
{
|
|
|
|
msg = "Connection failed.\n"
|
|
|
|
"Either the IP address is wrong or a firewall on either system is blocking\n"
|
|
|
|
"UDP packets on the port you have chosen.";
|
|
|
|
queue = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_INVALID_PASSWORD:
|
|
|
|
{
|
|
|
|
msg = "Connection failed.\n"
|
|
|
|
"The client or server is outdated.\n";
|
|
|
|
queue = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_CONNECTION_REQUEST_ACCEPTED:
|
|
|
|
{
|
|
|
|
msg = "Connection accepted.\n";
|
|
|
|
queue = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_DISCONNECTION_NOTIFICATION:
|
|
|
|
throw runtime_error("ID_DISCONNECTION_NOTIFICATION.\n");
|
|
|
|
case ID_CONNECTION_BANNED:
|
|
|
|
throw runtime_error("ID_CONNECTION_BANNED.\n");
|
|
|
|
case ID_CONNECTION_LOST:
|
|
|
|
throw runtime_error("ID_CONNECTION_LOST.\n");
|
|
|
|
default:
|
|
|
|
printf("Connection message with identifier %i has arrived in initialization.\n", packet->data[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
puts(msg.c_str());
|
|
|
|
|
|
|
|
if (queue == -1) // connection is failed
|
|
|
|
return data;
|
|
|
|
|
|
|
|
{
|
|
|
|
RakNet::BitStream bs;
|
|
|
|
bs.Write((unsigned char) (ID_USER_PACKET_ENUM + 1));
|
|
|
|
peer->Send(&bs, HIGH_PRIORITY, RELIABLE_ORDERED, 0, RakNet::UNASSIGNED_SYSTEM_ADDRESS, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
RakNet::Packet *packet;
|
|
|
|
bool done = false;
|
|
|
|
while (!done)
|
|
|
|
{
|
|
|
|
for (packet = peer->Receive(); packet; peer->DeallocatePacket(packet), packet = peer->Receive())
|
|
|
|
{
|
|
|
|
if (packet->data[0] == (ID_USER_PACKET_ENUM + 1))
|
|
|
|
{
|
|
|
|
RakNet::BitStream bs(packet->data, packet->length, false);
|
|
|
|
bs.IgnoreBytes(1);
|
|
|
|
size_t length = 0;
|
|
|
|
bs.Read(length);
|
|
|
|
for (size_t i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
RakNet::RakString str;
|
|
|
|
bs.Read(str);
|
[Browser] Rework browser for improved stability & clarity
(cherry picked from commits 5c79e7106f840ef217b9bf45ec5d3bd925825863, 57353cdffff3580566415039544fae15052e8d73, 15723adb9a0383d8ebb8b7e26849b2de70b9952d, 01a5196a92f27f0c09bd053daf4d779d0c113974, ed75563a94174ca38cb67beba9c0e35a810dfbd2, 3839a2dcfd8fbbc7598771ee604f9ff9eb08e044, 1fd16ba69c4893cfe7379ea6bb0f65e5ac59cd4b, 66283943c593a406592daf0b90491d42a2e80050, ba8613a179936631d6c5fa7ae6dedb8a5f3eb684, 5b8f4f3e92d662f36580b94184057b648be9f01d, 35b771b19e00a813350553f686c0971334bbc3b5, 043eb224e29ca7b41a738eb598e16131ccfedd1a, 05fac2f67d5281d72b48bdba0db14e6bd7974765)
7 years ago
|
|
|
data.players.emplace_back(str.C_String());
|
|
|
|
}
|
|
|
|
bs.Read(length);
|
|
|
|
for (size_t i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
RakNet::RakString str;
|
|
|
|
bs.Read(str);
|
[Browser] Rework browser for improved stability & clarity
(cherry picked from commits 5c79e7106f840ef217b9bf45ec5d3bd925825863, 57353cdffff3580566415039544fae15052e8d73, 15723adb9a0383d8ebb8b7e26849b2de70b9952d, 01a5196a92f27f0c09bd053daf4d779d0c113974, ed75563a94174ca38cb67beba9c0e35a810dfbd2, 3839a2dcfd8fbbc7598771ee604f9ff9eb08e044, 1fd16ba69c4893cfe7379ea6bb0f65e5ac59cd4b, 66283943c593a406592daf0b90491d42a2e80050, ba8613a179936631d6c5fa7ae6dedb8a5f3eb684, 5b8f4f3e92d662f36580b94184057b648be9f01d, 35b771b19e00a813350553f686c0971334bbc3b5, 043eb224e29ca7b41a738eb598e16131ccfedd1a, 05fac2f67d5281d72b48bdba0db14e6bd7974765)
7 years ago
|
|
|
data.plugins.emplace_back(str.C_String());
|
|
|
|
}
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
peer->Shutdown(0);
|
|
|
|
RakSleep(10);
|
|
|
|
RakNet::RakPeerInterface::DestroyInstance(peer);
|
|
|
|
return data;
|
|
|
|
}
|