// notifes client both players are connectd and game can be stated public void notifyClientsWithStartGame(DTO_Player whiteCheckersPlayer, DTO_Player blackCheckersPlayer) { foreach (KeyValuePair <int, IClientCallBack> pair in clients) { pair.Value.UpdateClientGameStartOk(whiteCheckersPlayer, blackCheckersPlayer); } }
// notifies opponent player on game over and winner player info public void OnPlayerWon(DTO_Player wonPlayer) { foreach (KeyValuePair <int, IClientCallBack> pair in clients) { if (pair.Key != wonPlayer.Id) { pair.Value.UpdateClientWithGameWinner(wonPlayer); } } }
public void addClient(DTO_Player player, IClientCallBack client) { if (clients.ContainsKey(player.Id)) { clients[player.Id] = client; } else { clients.Add(player.Id, client); } }
public void onClientDisconnect(DTO_Player client) { foreach (KeyValuePair <int, IClientCallBack> pair in clients) { if (pair.Key != client.Id) { pair.Value.NotifyClientOpponentDisconnected(); } } clients.Clear(); }
// updaes opponent player on checker move public void updateClientOnCheckerMove(DTO_Player movingCheckerPlayer, DTO_Checker checker, string eatenCheckerID) { foreach (KeyValuePair <int, IClientCallBack> pair in clients) { if (pair.Key != movingCheckerPlayer.Id) { pair.Value.UpdateClientWithCheckerMove(checker); if (eatenCheckerID != null) { pair.Value.UpdateClientRemoveEatenChecker(eatenCheckerID); } } } }
// checks whenever this client allredy connected this method used due to fact that when client // application crashes wcf service dont know about it and thinks client is still alive. public bool isClientAllredyConnected(DTO_Player player) { foreach (KeyValuePair <int, IClientCallBack> pair in clients) { if (pair.Key == player.Id) { try { pair.Value.isConnected(); return(true); } catch (FaultException) { //System.Net.WebException //System.ServiceModel.ServerTooBusyException return(false); } } } return(false); }