fully implement KeepAlive behavior
This commit is contained in:
@@ -29,34 +29,36 @@ void EnetServer::Update() {
|
||||
do {
|
||||
switch (event.type) {
|
||||
case Nz::ENetEventType::Disconnect: {
|
||||
EnetConnexion* connexion = GetConnexion(event.peer->GetPeerId());
|
||||
if (!connexion)
|
||||
EnetConnection* connection = GetConnection(event.peer->GetPeerId());
|
||||
if (!connection)
|
||||
break;
|
||||
OnClientDisconnect(*connexion);
|
||||
OnClientDisconnect(*connection);
|
||||
RemoveConnection(connection->GetPeerId());
|
||||
break;
|
||||
}
|
||||
|
||||
case Nz::ENetEventType::DisconnectTimeout: {
|
||||
EnetConnexion* connexion = GetConnexion(event.peer->GetPeerId());
|
||||
if (!connexion)
|
||||
EnetConnection* connection = GetConnection(event.peer->GetPeerId());
|
||||
if (!connection)
|
||||
break;
|
||||
OnClientDisconnectTimeout(*connexion);
|
||||
OnClientDisconnectTimeout(*connection);
|
||||
RemoveConnection(connection->GetPeerId());
|
||||
break;
|
||||
}
|
||||
|
||||
case Nz::ENetEventType::IncomingConnect: {
|
||||
Nz::ENetPeer* peer = event.peer;
|
||||
auto con = std::make_unique<EnetConnexion>(peer);
|
||||
m_Connexion.insert({peer->GetPeerId(), std::move(con)});
|
||||
OnClientConnect(*GetConnexion(peer->GetPeerId()));
|
||||
auto con = std::make_unique<EnetConnection>(peer);
|
||||
m_Connections.insert({peer->GetPeerId(), std::move(con)});
|
||||
OnClientConnect(*GetConnection(peer->GetPeerId()));
|
||||
break;
|
||||
}
|
||||
|
||||
case Nz::ENetEventType::Receive: {
|
||||
EnetConnexion* connexion = GetConnexion(event.peer->GetPeerId());
|
||||
if (!connexion)
|
||||
EnetConnection* connection = GetConnection(event.peer->GetPeerId());
|
||||
if (!connection)
|
||||
break;
|
||||
connexion->Recieve(event.packet.m_packet->data);
|
||||
connection->Recieve(event.packet.m_packet->data);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -68,21 +70,28 @@ void EnetServer::Update() {
|
||||
}
|
||||
}
|
||||
|
||||
EnetConnexion* EnetServer::GetConnexion(std::uint16_t a_PeerId) {
|
||||
auto it = m_Connexion.find(a_PeerId);
|
||||
EnetConnection* EnetServer::GetConnection(std::uint16_t a_PeerId) {
|
||||
auto it = m_Connections.find(a_PeerId);
|
||||
|
||||
if (it == m_Connexion.end())
|
||||
if (it == m_Connections.end())
|
||||
return nullptr;
|
||||
|
||||
return it->second.get();
|
||||
}
|
||||
|
||||
/*void EnetServer::BroadcastPacket(const protocol::Packet& a_Packet, Nz::ENetPacketFlags a_Flags) {
|
||||
m_Host.Broadcast(0, a_Flags, std::move(a_Data));
|
||||
}*/
|
||||
void EnetServer::CloseConnection(std::uint16_t a_PeerId) {
|
||||
auto connection = GetConnection(a_PeerId);
|
||||
|
||||
void EnetServer::RemoveConnexion(std::uint16_t a_PeerId) {
|
||||
m_Connexion.erase(a_PeerId);
|
||||
if (!connection)
|
||||
return;
|
||||
|
||||
connection->m_Peer->DisconnectNow(0);
|
||||
OnClientDisconnect(*connection);
|
||||
RemoveConnection(a_PeerId);
|
||||
}
|
||||
|
||||
void EnetServer::RemoveConnection(std::uint16_t a_PeerId) {
|
||||
m_Connections.erase(a_PeerId);
|
||||
}
|
||||
|
||||
void EnetServer::Destroy() {
|
||||
|
||||
Reference in New Issue
Block a user