Add ProcessPlayerPacket method to server's Networking

This commit is contained in:
David Cernat 2016-10-19 21:26:42 +03:00
parent f0fa5e8771
commit 2602c1f71a
2 changed files with 230 additions and 213 deletions

View file

@ -48,29 +48,10 @@ Networking::~Networking()
LOG_QUIT();
}
void Networking::Update(RakNet::Packet *packet)
void Networking::ProcessPlayerPacket(RakNet::Packet *packet)
{
Player *player = Players::GetPlayer(packet->guid);
RakNet::BitStream bsIn(&packet->data[1], packet->length, false);
{
RakNet::RakNetGUID ignoredGUID;
bsIn.Read(ignoredGUID);
(void)ignoredGUID;
}
playerController->SetStream(&bsIn, 0);
if (player == 0)
{
playerController->GetPacket(ID_HANDSHAKE)->RequestData(packet->guid);
Players::NewPlayer(packet->guid);
player = Players::GetPlayer(packet->guid);
playerController->GetPacket(ID_USER_MYID)->Send(Players::GetPlayer(packet->guid), false);
return;
}
PlayerPacket *myPacket = playerController->GetPacket(packet->data[0]);
if (packet->data[0] == ID_HANDSHAKE)
@ -379,6 +360,39 @@ void Networking::Update(RakNet::Packet *packet)
}
}
void Networking::Update(RakNet::Packet *packet)
{
Player *player = Players::GetPlayer(packet->guid);
RakNet::BitStream bsIn(&packet->data[1], packet->length, false);
{
RakNet::RakNetGUID ignoredGUID;
bsIn.Read(ignoredGUID);
(void)ignoredGUID;
}
if (player == 0)
{
playerController->SetStream(&bsIn, 0);
playerController->GetPacket(ID_HANDSHAKE)->RequestData(packet->guid);
Players::NewPlayer(packet->guid);
player = Players::GetPlayer(packet->guid);
playerController->GetPacket(ID_USER_MYID)->Send(Players::GetPlayer(packet->guid), false);
return;
}
else if (playerController->ContainsPacket(packet->data[0]))
{
playerController->SetStream(&bsIn, 0);
ProcessPlayerPacket(packet);
}
else if (worldController->ContainsPacket(packet->data[0]))
{
worldController->SetStream(&bsIn, 0);
}
}
void Networking::NewPlayer(RakNet::RakNetGUID guid)
{
playerController->GetPacket(ID_GAME_BASE_INFO)->RequestData(guid);

View file

@ -20,7 +20,10 @@ namespace mwmp
void NewPlayer(RakNet::RakNetGUID guid);
void DisconnectPlayer(RakNet::RakNetGUID guid);
void KickPlayer(RakNet::RakNetGUID guid);
void ProcessPlayerPacket(RakNet::Packet *packet);
void Update(RakNet::Packet *packet);
unsigned short NumberOfConnections() const;
unsigned int MaxConnections() const;