We have a game implemented using SignalR, which has several players and joined to a group. However, some players may suddenly off-line, and we want to start robots to replace the left players. Our current issue is when we let one player off line, but game seems stuck there. Is there a way to re-join the remaining players and the started robot and continue the game? Thank you.
-
How do you determine that a player gone off-line? – cassandrad Aug 18 '17 at 08:23
-
By checking the OnDisconnect event. – chong chu Aug 19 '17 at 03:25
-
You can't rely on that event. For example, player has bad internet connection. From client side it would look like there is something with internet and it would try to re-connect. From server side it would look like the client has disconnected and it will fire OnDisconnected event. As far as I remember, there is 30 secs timeout before server decides that client has disconnected if there are no pings from the client. So, the player isn't actually disconnected. – cassandrad Aug 19 '17 at 07:53
1 Answers
If I understood your problem correctly, you have a multiplayer game where each user is connected with a SignalR connection. You have players going offline, which you are able to know on the server through the OnDisconnect event, and you want to replace those players with your own bot players.
I am assuming each player will have a unique Id. This unique Id NEEDS to be mapped with the connectionId to be able to achieve exact replacement. The uniqueId could also be the connectionId itself.
For your problem's solution you will need to:
- Find out which uniqueId/connectionId went offline.
- Create a new connection to the Hub server from another client, which will be your Robot player.
- Replace the player's uniqueId/connectionId(the one who went offline) with your active Robot player's uniqueId/connectionId.
- Transfer the state from the offline player to the Robot player.
However, your player might not respond until the Disconnect timeout, which is 30seconds by default. Reduce the DisconnectTimeout in case you want to know very quickly if your player has gone offline.
Note: Check the performance impact of reducing timeout on your application before you go ahead.

- 345
- 1
- 10