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);
|
if (packet->data[0] != ID_GAME_PREINIT)
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
|
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");
|
DEBUG_PRINTF("ID_GAME_PREINIT");
|
||||||
PacketPreInit::PluginContainer plugins;
|
PacketPreInit::PluginContainer plugins;
|
||||||
|
|
||||||
|
@ -236,7 +233,7 @@ void Networking::update(RakNet::Packet *packet)
|
||||||
{
|
{
|
||||||
LOG_APPEND(Log::LOG_ERROR, "Invalid packetPreInit");
|
LOG_APPEND(Log::LOG_ERROR, "Invalid packetPreInit");
|
||||||
peer->CloseConnection(packet->systemAddress, false); // close connection without notification
|
peer->CloseConnection(packet->systemAddress, false); // close connection without notification
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto plugin = plugins.begin();
|
auto plugin = plugins.begin();
|
||||||
|
@ -257,7 +254,6 @@ void Networking::update(RakNet::Packet *packet)
|
||||||
// the server
|
// the server
|
||||||
if (it == hashList.end())
|
if (it == hashList.end())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
else // name is incorrect
|
else // name is incorrect
|
||||||
break;
|
break;
|
||||||
|
@ -280,20 +276,20 @@ void Networking::update(RakNet::Packet *packet)
|
||||||
PacketPreInit::PluginContainer tmp;
|
PacketPreInit::PluginContainer tmp;
|
||||||
packetPreInit.setChecksums(&tmp);
|
packetPreInit.setChecksums(&tmp);
|
||||||
packetPreInit.Send(packet->systemAddress);
|
packetPreInit.Send(packet->systemAddress);
|
||||||
}
|
Players::newPlayer(packet->guid); // create player if connection allowed
|
||||||
return;
|
playerPacketController->SetStream(&bsIn, nullptr); // and request handshake
|
||||||
}
|
|
||||||
|
|
||||||
playerPacketController->SetStream(&bsIn, 0);
|
|
||||||
|
|
||||||
playerPacketController->GetPacket(ID_HANDSHAKE)->RequestData(packet->guid);
|
playerPacketController->GetPacket(ID_HANDSHAKE)->RequestData(packet->guid);
|
||||||
Players::newPlayer(packet->guid);
|
return true;
|
||||||
player = Players::getPlayer(packet->guid);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else if (playerPacketController->ContainsPacket(packet->data[0]))
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Networking::update(RakNet::Packet *packet, RakNet::BitStream &bsIn)
|
||||||
{
|
{
|
||||||
playerPacketController->SetStream(&bsIn, 0);
|
if (playerPacketController->ContainsPacket(packet->data[0]))
|
||||||
|
{
|
||||||
|
playerPacketController->SetStream(&bsIn, nullptr);
|
||||||
processPlayerPacket(packet);
|
processPlayerPacket(packet);
|
||||||
}
|
}
|
||||||
else if (actorPacketController->ContainsPacket(packet->data[0]))
|
else if (actorPacketController->ContainsPacket(packet->data[0]))
|
||||||
|
@ -531,10 +527,19 @@ int Networking::mainLoop()
|
||||||
case ID_UNCONNECTED_PING:
|
case ID_UNCONNECTED_PING:
|
||||||
break;
|
break;
|
||||||
default:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
TimerAPI::Tick();
|
TimerAPI::Tick();
|
||||||
this_thread::sleep_for(chrono::milliseconds(1));
|
this_thread::sleep_for(chrono::milliseconds(1));
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace mwmp
|
||||||
void processActorPacket(RakNet::Packet *packet);
|
void processActorPacket(RakNet::Packet *packet);
|
||||||
void processObjectPacket(RakNet::Packet *packet);
|
void processObjectPacket(RakNet::Packet *packet);
|
||||||
void processWorldstatePacket(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 short numberOfConnections() const;
|
||||||
unsigned int maxConnections() const;
|
unsigned int maxConnections() const;
|
||||||
|
@ -65,6 +65,7 @@ namespace mwmp
|
||||||
|
|
||||||
void postInit();
|
void postInit();
|
||||||
private:
|
private:
|
||||||
|
bool preInit(RakNet::Packet *packet, RakNet::BitStream &bsIn);
|
||||||
PacketPreInit::PluginContainer getPluginListSample();
|
PacketPreInit::PluginContainer getPluginListSample();
|
||||||
std::string serverPassword;
|
std::string serverPassword;
|
||||||
static Networking *sThis;
|
static Networking *sThis;
|
||||||
|
|
Loading…
Reference in a new issue