Exemple #1
0
        /// <summary>
        /// Force the communicator to sever it's connection.
        /// </summary>
        public void Disconnect()
        {
            lock (this)
            {
                try
                {
                    Connected = false;

                    if (pinger != null)
                    {
                        pinger.Running = false;
                    }

                    if (keepAliveTimer != null)
                    {
                        keepAliveTimer.Dispose();
                    }

                    if (timerThread != null)
                    {
                        timerThread.Interrupt();
                    }

                    if (session != null)
                    {
                        session.destroy_async(new Destroy_Callback());
                    }

                    if (router != null)
                    {
                        router.destroySession_async(new GameRouterDestroySession_Callback());
                    }

                    if (logger != null)
                    {
                        logger.Close();
                    }

                    DestroyAdapter();
                    DestroyCommunicator();
                }
                catch (System.Exception e)
                {
                    logger.Error(
                        "Unexpected error in the Disconnect() method: {0}", e);
                }
                finally
                {
                    pinger         = null;
                    keepAliveTimer = null;
                    session        = null;
                    sessionOneway  = null;
                    router         = null;
                    auth           = null;
                    timerThread    = null;
                    logger         = null;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Join the game server. Once active, this officially joins the game.
        /// </summary>
        /// <param name="key">Key given by the main communicator after calling
        /// RequestJoinGameServer().</param>
        /// <returns>True if successful; false otherwise.</returns>
        public bool JoinServer(string key)
        {
            bool result = false;

            try
            {
                lock (this)
                {
                    adapter.activate();

                    ClientEventCallbackPrx clientCallback = ClientEventCallbackPrxHelper.
                                                            uncheckedCast(adapter.createProxy(clientIdentity));
                    ClockSynchronizerPrx clockCallback = ClockSynchronizerPrxHelper.
                                                         uncheckedCast(adapter.createProxy(clockIdentity));
                    session = auth.JoinServer(key, clockCallback, clientCallback);
                    // Configure the proxy.
                    session = GameInfoPrxHelper.uncheckedCast(
                        session.ice_router(router));
                    sessionOneway = GameInfoPrxHelper.uncheckedCast(
                        session.ice_oneway());

                    Refresh();

                    timerThread = new Thread(new ThreadStart(TimeTicker));
                    timerThread.Start();

                    if (KeepAlive)
                    {
                        keepAliveTimer = new Timer(new TimerCallback(OnKeepAlive),
                                                   null, KeepAliveInterval, KeepAliveInterval);
                    }

                    pinger = new Pinger(session);
                }

                result = true;
            }
            catch (Ice.IllegalIdentityException e)
            {
                logger.Error("JoinServer() No callbacks registered: {0}", e);
                throw new InvalidValueException("You must register callbacks first.");
            }
            catch (Exceptions.PermissionDeniedException e)
            {
                logger.Info("JoinServer() Failed (permission denied): {0}", e.reason);
            }
            catch (Ice.Exception e)
            {
                logger.Error("JoinServer() Ice.Exception: {0}", e);
            }
            catch (System.Exception e)
            {
                logger.Error("JoinServer() System.Exception: {0}", e);
            }

            return(result);
        }