OpenMetaverse.Simulator.Connect C# (CSharp) Method

Connect() public method

Attempt to connect to this simulator
public Connect ( bool moveToSim ) : bool
moveToSim bool Whether to move our agent in to this sim or not
return bool
        public bool Connect(bool moveToSim)
        {
            if (connected)
            {
                Client.Self.CompleteAgentMovement(this);
                return true;
            }

            #region Start Timers

            // Destroy the timers
            if (AckTimer != null) AckTimer.Dispose();
            if (StatsTimer != null) StatsTimer.Dispose();
            if (PingTimer != null) PingTimer.Dispose();

            // Timer for sending out queued packet acknowledgements
            AckTimer = new Timer(AckTimer_Elapsed, null, Settings.NETWORK_TICK_INTERVAL, Settings.NETWORK_TICK_INTERVAL);
            // Timer for recording simulator connection statistics
            StatsTimer = new Timer(StatsTimer_Elapsed, null, 1000, 1000);
            // Timer for periodically pinging the simulator
            if (Client.Settings.SEND_PINGS)
                PingTimer = new Timer(PingTimer_Elapsed, null, Settings.PING_INTERVAL, Settings.PING_INTERVAL);

            #endregion Start Timers

            Logger.Log("Connecting to " + this.ToString(), Helpers.LogLevel.Info, Client);

            try
            {
                // Create the UDP connection
                Start();

                // Mark ourselves as connected before firing everything else up
                connected = true;

                // Send the UseCircuitCode packet to initiate the connection
                UseCircuitCodePacket use = new UseCircuitCodePacket();
                use.CircuitCode.Code = Network.CircuitCode;
                use.CircuitCode.ID = Client.Self.AgentID;
                use.CircuitCode.SessionID = Client.Self.SessionID;

                // Send the initial packet out
                SendPacket(use, true);

                Stats.ConnectTime = Environment.TickCount;

                if (!ConnectedEvent.WaitOne(Client.Settings.SIMULATOR_TIMEOUT, false))
                {
                    Logger.Log("Giving up on waiting for RegionHandshake for " + this.ToString(),
                        Helpers.LogLevel.Warning, Client);
                }

                // Move our agent in to the sim to complete the connection
                if (moveToSim) Client.Self.CompleteAgentMovement(this);

                if (Client.Settings.SEND_AGENT_UPDATES)
                    Client.Self.Movement.SendUpdate(true, this);

                return true;
            }
            catch (Exception e)
            {
                Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e);
            }

            return false;
        }