|
|
|
@ -212,18 +212,15 @@ void Networking::processWorldstatePacket(RakNet::Packet *packet)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Networking::update(RakNet::Packet *packet)
|
|
|
|
|
bool Networking::preInit(RakNet::Packet *packet, RakNet::BitStream &bsIn)
|
|
|
|
|
{
|
|
|
|
|
Player *player = Players::getPlayer(packet->guid);
|
|
|
|
|
|
|
|
|
|
RakNet::BitStream bsIn(&packet->data[1], packet->length, false);
|
|
|
|
|
|
|
|
|
|
bsIn.IgnoreBytes((unsigned int) RakNet::RakNetGUID::size()); // Ignore GUID from received packet
|
|
|
|
|
|
|
|
|
|
if (player == nullptr)
|
|
|
|
|
{
|
|
|
|
|
if (packet->data[0] == ID_GAME_PREINIT)
|
|
|
|
|
if (packet->data[0] != ID_GAME_PREINIT)
|
|
|
|
|
{
|
|
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s sent wrong first packet (ID_GAME_PREINIT was expected)",
|
|
|
|
|
packet->systemAddress.ToString());
|
|
|
|
|
peer->CloseConnection(packet->systemAddress, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DEBUG_PRINTF("ID_GAME_PREINIT");
|
|
|
|
|
PacketPreInit::PluginContainer plugins;
|
|
|
|
|
|
|
|
|
@ -236,7 +233,7 @@ void Networking::update(RakNet::Packet *packet)
|
|
|
|
|
{
|
|
|
|
|
LOG_APPEND(Log::LOG_ERROR, "Invalid packetPreInit");
|
|
|
|
|
peer->CloseConnection(packet->systemAddress, false); // close connection without notification
|
|
|
|
|
return;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto plugin = plugins.begin();
|
|
|
|
@ -257,7 +254,6 @@ void Networking::update(RakNet::Packet *packet)
|
|
|
|
|
// the server
|
|
|
|
|
if (it == hashList.end())
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else // name is incorrect
|
|
|
|
|
break;
|
|
|
|
@ -280,20 +276,20 @@ void Networking::update(RakNet::Packet *packet)
|
|
|
|
|
PacketPreInit::PluginContainer tmp;
|
|
|
|
|
packetPreInit.setChecksums(&tmp);
|
|
|
|
|
packetPreInit.Send(packet->systemAddress);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
Players::newPlayer(packet->guid); // create player if connection allowed
|
|
|
|
|
playerPacketController->SetStream(&bsIn, nullptr); // and request handshake
|
|
|
|
|
playerPacketController->GetPacket(ID_HANDSHAKE)->RequestData(packet->guid);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
playerPacketController->SetStream(&bsIn, 0);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
playerPacketController->GetPacket(ID_HANDSHAKE)->RequestData(packet->guid);
|
|
|
|
|
Players::newPlayer(packet->guid);
|
|
|
|
|
player = Players::getPlayer(packet->guid);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (playerPacketController->ContainsPacket(packet->data[0]))
|
|
|
|
|
void Networking::update(RakNet::Packet *packet, RakNet::BitStream &bsIn)
|
|
|
|
|
{
|
|
|
|
|
if (playerPacketController->ContainsPacket(packet->data[0]))
|
|
|
|
|
{
|
|
|
|
|
playerPacketController->SetStream(&bsIn, 0);
|
|
|
|
|
playerPacketController->SetStream(&bsIn, nullptr);
|
|
|
|
|
processPlayerPacket(packet);
|
|
|
|
|
}
|
|
|
|
|
else if (actorPacketController->ContainsPacket(packet->data[0]))
|
|
|
|
@ -531,10 +527,19 @@ int Networking::mainLoop()
|
|
|
|
|
case ID_UNCONNECTED_PING:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
update(packet);
|
|
|
|
|
{
|
|
|
|
|
RakNet::BitStream bsIn(&packet->data[1], packet->length, false);
|
|
|
|
|
bsIn.IgnoreBytes((unsigned int) RakNet::RakNetGUID::size()); // Ignore GUID from received packet
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Players::isPlayerExists(packet->guid))
|
|
|
|
|
update(packet, bsIn);
|
|
|
|
|
else
|
|
|
|
|
preInit(packet, bsIn);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
TimerAPI::Tick();
|
|
|
|
|
this_thread::sleep_for(chrono::milliseconds(1));
|
|
|
|
|
}
|
|
|
|
|