/// <summary> /// Force the communicator to sever it's connection. /// </summary> public void Disconnect() { lock (this) { try { if (pinger != null) { pinger.Running = false; } if (keepAliveTimer != null) { keepAliveTimer.Dispose(); } if (session != null) { session.Disconnect_async(new Disconnect_Callback()); } if (router != null) { router.destroySession_async(new RouterDestroySession_Callback()); } if (logger != null) { logger.Close(); } DestroyCommunicator(); } catch (System.Exception e) { if (logger != null) { logger.Error( "Unexpected error in the Disconnect() method: {0}", e); } else { Console.Error.WriteLine(e); } } finally { Connected = false; pinger = null; keepAliveTimer = null; session = null; router = null; factory = null; tankList = null; tankListNeedsRefresh = true; // weaponList = null; logger = null; } } }
/// <summary> /// Log into the server synchronously, which means it will block until it receives /// a response. /// </summary> /// <param name="user">Username to login with.</param> /// <param name="password">Password for the user.</param> /// <param name="version">Version of the client.</param> /// <param name="callback">Callback, called when the login finishes.</param> /// <exception cref="Network.Exceptions.LoginFailedException"> /// Thrown if the login failed.</exception> public void Login(string user, string password, VTankObject.Version version) { try { session = MainSessionPrxHelper.uncheckedCast( factory.VTankLogin(user, password, version)); pinger = new Pinger(session); if (KeepAlive) { keepAliveTimer = new Timer(new TimerCallback(OnKeepAlive), null, KeepAliveInterval, KeepAliveInterval); } } catch (Exceptions.PermissionDeniedException e) { logger.Info("Login() PermissionDeniedException: {0}", e.reason); throw new LoginFailedException(e.reason); } catch (Ice.Exception e) { logger.Error("Login() Ice.Exception: {0}", e); throw new UnknownException("Cannot connect to the server."); } catch (System.Exception e) { logger.Error("Login() System.Exception: {0}", e); throw new UnknownException("Cannot connect to the server."); } }
public override void ice_response(MainSessionPrx ret__) { if (callback != null) { Result <MainSessionPrx> result = new Result <MainSessionPrx>(ret__); callback(result); } }
/// <summary> /// Intercepts the login attempt in order to provide some internal handling. /// </summary> /// <param name="result">Result of the login attempt.</param> /// <param name="session">Session proxy, if one exists.</param> /// <param name="e">Exception thrown from the callback.</param> private void LoginCallback(Result <MainSessionPrx> result) { System.Exception e = result.Exception; if (result.Success) { if (KeepAlive) { keepAliveTimer = new Timer(new TimerCallback(OnKeepAlive), null, KeepAliveInterval, KeepAliveInterval); } session = result.ReturnedResult; session.GetTankList(); //session = MainSessionPrxHelper.uncheckedCast(session.ice_router(router)); pinger = new Pinger(session); } else { logger.Error("LoginCallback() Login attempt failed: {0}", e); if (e is PermissionDeniedException) { PermissionDeniedException ex = (PermissionDeniedException)e; e = new LoginFailedException(ex.reason); } else { e = new LoginFailedException("Unable to login."); } result.Exception = e; } remoteCallback(new Result(result.Success, session, result.Exception)); remoteCallback = null; }
public override void ice_response(MainSessionPrx ret__) { if (callback != null) { Result<MainSessionPrx> result = new Result<MainSessionPrx>(ret__); callback(result); } }