A combination of both strategies would likely yield the best results. Just keeping track of when user join/leave might not account for situations where the user is unexpectedly disconnected. A periodic poll would likely have to happen too often to get reasonably updated list of players joining and leaving.
So, update the list when a player joins or leaves and poll less periodically.
It depends is network traffic efficiency really important to you. If it is not you might have three actions in your server:
- connect - which will add user to a server list
- disconnect - which will delete user for a server list
- poll - which will periodically check all users alive status (simple ping with client app)
More complex but also better way is to use timers. Every user will have a separate timer when he joins. When the timer runs out, server will poll for his status.
- if he is alive server reset timer
- if he is not responding server will delete him from user list
It won`t generate as big lag as polling all users at once.
actions for the client
- "ping" response
In other words, you are not polling server at all until server will ask you for alive status.