private void OnConnectButtonClick() { if (m_remoteGameServer.IsConnected) { m_remoteGameServer.Disconnect(); } else { m_remoteGameServer.Connect(); } }
private static void InitGameOnConnectionStateChanged(bool preferRemote, string mapName, int playersCount, int botsCount, Action callback, Action <Error> error, INotification notification, IGameServer remoteGameServer) { ServerEventHandler <ValueChangedArgs <bool> > connectionStateChanged = null; connectionStateChanged = (Error e, ValueChangedArgs <bool> payload) => { #warning CHECK if actually unsubscribed if (!remoteGameServer.HasError(e)) { if (preferRemote) { if (!remoteGameServer.IsConnected) { remoteGameServer.Connect(); return; } } else { if (remoteGameServer.IsConnected) { remoteGameServer.Disconnect(); return; } } LogoffIfNeeded(() => { InitGame(mapName, 0, 0, playersCount, botsCount, callback, error); }); } else { notification.ShowError(e); LogoffIfNeeded(() => { InitGame(mapName, 0, 0, playersCount, botsCount, callback, error); }); } remoteGameServer.ConnectionStateChanged -= connectionStateChanged; }; remoteGameServer.ConnectionStateChanged += connectionStateChanged; }
public static void Init(string mapName, int playersCount, int botsCount, bool preferRemote, Action callback, Action <Error> error) { if (playersCount < 0) { throw new ArgumentOutOfRangeException("playersCount"); } if (botsCount < 0) { throw new ArgumentOutOfRangeException("botsCount"); } if (playersCount > GameConstants.MaxLocalPlayers) { throw new ArgumentException("playersCount > " + GameConstants.MaxLocalPlayers); } if (playersCount + botsCount > 8 || playersCount + botsCount < 2) { throw new ArgumentException("players + bots should be >= 2 and <= 8"); } //IProgressIndicator progress = Dependencies.Progress; //progress.IsVisible = true; INotification notification = Dependencies.Notification; IGameServer remoteGameServer = Dependencies.RemoteGameServer; if (preferRemote) { if (remoteGameServer.IsConnectionStateChanging) { InitGameOnConnectionStateChanged(preferRemote, mapName, playersCount, botsCount, callback, error, notification, remoteGameServer); } else if (!remoteGameServer.IsConnected) { InitGameOnConnectionStateChanged(preferRemote, mapName, playersCount, botsCount, callback, error, notification, remoteGameServer); remoteGameServer.Connect(); } else { LogoffIfNeeded(() => { InitGame(mapName, 0, 0, playersCount, botsCount, callback, error); }); } } else { if (remoteGameServer != null && remoteGameServer.IsConnectionStateChanging) { InitGameOnConnectionStateChanged(preferRemote, mapName, playersCount, botsCount, callback, error, notification, remoteGameServer); } else if (remoteGameServer != null && remoteGameServer.IsConnected) { InitGameOnConnectionStateChanged(preferRemote, mapName, playersCount, botsCount, callback, error, notification, remoteGameServer); remoteGameServer.Disconnect(); } else { LogoffIfNeeded(() => { InitGame(mapName, 0, 0, playersCount, botsCount, callback, error); }); } } }