Fix: Handle remote player disconnections.
This commit is contained in:
parent
81b8972742
commit
6aa204672e
@ -9,6 +9,7 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <fcntl.h>
|
||||
#include <netinet/in.h>
|
||||
#include <set>
|
||||
#include <cstdio>
|
||||
#include <future>
|
||||
#include <string>
|
||||
@ -278,6 +279,9 @@ void Bettola::render(void) {
|
||||
}
|
||||
|
||||
void Bettola::process_game_state(const BettolaLib::Network::GameStateMessage& msg) {
|
||||
/* Track remote players each update. */
|
||||
std::set<unsigned int> players_in_message;
|
||||
|
||||
for(unsigned int i = 0; i < msg.num_players; ++i) {
|
||||
const auto& player_state = msg.players[i];
|
||||
|
||||
@ -297,6 +301,7 @@ void Bettola::process_game_state(const BettolaLib::Network::GameStateMessage& ms
|
||||
}
|
||||
} else {
|
||||
/* Remote player. Find if we already know about them.. */
|
||||
players_in_message.insert(player_state.player_id);
|
||||
auto it = std::find_if(_remote_players.begin(), _remote_players.end(),
|
||||
[&](const RemotePlayer& p) {
|
||||
return p.get_id() == player_state.player_id;
|
||||
@ -311,7 +316,13 @@ void Bettola::process_game_state(const BettolaLib::Network::GameStateMessage& ms
|
||||
}
|
||||
}
|
||||
}
|
||||
/* TODO: Remove players fomr _remote_players if they are no longer in the msg. */
|
||||
_remote_players.erase(
|
||||
std::remove_if(_remote_players.begin(), _remote_players.end(),
|
||||
[&](const RemotePlayer& p) {
|
||||
return players_in_message.find(p.get_id()) == players_in_message.end();
|
||||
}),
|
||||
|
||||
_remote_players.end());
|
||||
}
|
||||
|
||||
bool Bettola::init_sdl(void) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user