forked from mirror/openmw-tes3mp
[Server] Move PreInit code to preInit method
This commit is contained in:
parent
1a9bf253f6
commit
b5c957c473
2 changed files with 86 additions and 80 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
playerPacketController->SetStream(&bsIn, 0);
|
||||
|
||||
Players::newPlayer(packet->guid); // create player if connection allowed
|
||||
playerPacketController->SetStream(&bsIn, nullptr); // and request handshake
|
||||
playerPacketController->GetPacket(ID_HANDSHAKE)->RequestData(packet->guid);
|
||||
Players::newPlayer(packet->guid);
|
||||
player = Players::getPlayer(packet->guid);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
else if (playerPacketController->ContainsPacket(packet->data[0]))
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace mwmp
|
|||
void processActorPacket(RakNet::Packet *packet);
|
||||
void processObjectPacket(RakNet::Packet *packet);
|
||||
void processWorldstatePacket(RakNet::Packet *packet);
|
||||
void update(RakNet::Packet *packet);
|
||||
void update(RakNet::Packet *packet, RakNet::BitStream &bsIn);
|
||||
|
||||
unsigned short numberOfConnections() const;
|
||||
unsigned int maxConnections() const;
|
||||
|
@ -65,6 +65,7 @@ namespace mwmp
|
|||
|
||||
void postInit();
|
||||
private:
|
||||
bool preInit(RakNet::Packet *packet, RakNet::BitStream &bsIn);
|
||||
PacketPreInit::PluginContainer getPluginListSample();
|
||||
std::string serverPassword;
|
||||
static Networking *sThis;
|
||||
|
|
Loading…
Reference in a new issue