///<summary>Raises the SimConnecting Event</summary>
 /// <param name="e">A SimConnectingEventArgs object containing
 /// the data sent from the simulator</param>
 protected virtual void OnSimConnecting(SimConnectingEventArgs e)
 {
     EventHandler<SimConnectingEventArgs> handler = m_SimConnecting;
     if (handler != null)
         handler(this, e);
 }
        /// <summary>
        /// Connect to a simulator
        /// </summary>
        /// <param name="endPoint">IP address and port to connect to</param>
        /// <param name="handle">Handle for this simulator, to identify its
        /// location in the grid</param>
        /// <param name="setDefault">Whether to set CurrentSim to this new
        /// connection, use this if the avatar is moving in to this simulator</param>
        /// <param name="seedcaps">URL of the capabilities server to use for
        /// this sim connection</param>
        /// <returns>A Simulator object on success, otherwise null</returns>
        public Simulator Connect(IPEndPoint endPoint, ulong handle, bool setDefault, string seedcaps)
        {
            Simulator simulator = FindSimulator(endPoint);

            if (simulator == null)
            {
                // We're not tracking this sim, create a new Simulator object
                simulator = new Simulator(Client, endPoint, handle);

                // Immediately add this simulator to the list of current sims. It will be removed if the
                // connection fails
                lock (Simulators) Simulators.Add(simulator);
            }

            if (!simulator.Connected)
            {
                if (!connected)
                {
                    // Mark that we are connecting/connected to the grid
                    //
                    connected = true;

                    // Open the queues in case this is a reconnect and they were shut down
                    PacketInbox.Open();
                    PacketOutbox.Open();

                    // Start the packet decoding thread
                    Thread decodeThread = new Thread(new ThreadStart(IncomingPacketHandler));
                    decodeThread.Name = "Incoming UDP packet dispatcher";
                    decodeThread.Start();

                    // Start the packet sending thread
                    Thread sendThread = new Thread(new ThreadStart(OutgoingPacketHandler));
                    sendThread.Name = "Outgoing UDP packet dispatcher";
                    sendThread.Start();
                }

                // raise the SimConnecting event and allow any event
                // subscribers to cancel the connection
                if (m_SimConnecting != null)
                {
                    SimConnectingEventArgs args = new SimConnectingEventArgs(simulator);
                    OnSimConnecting(args);

                    if (args.Cancel)
                    {
                        // Callback is requesting that we abort this connection
                        lock (Simulators)
                        {
                            Simulators.Remove(simulator);
                        }
                        return null;
                    }
                }

                // Attempt to establish a connection to the simulator
                if (simulator.Connect(setDefault))
                {
                    if (DisconnectTimer == null)
                    {
                        // Start a timer that checks if we've been disconnected
                        DisconnectTimer = new Timer(new TimerCallback(DisconnectTimer_Elapsed), null,
                            Client.Settings.SIMULATOR_TIMEOUT, Client.Settings.SIMULATOR_TIMEOUT);
                    }

                    if (setDefault)
                    {
                        SetCurrentSim(simulator, seedcaps);
                    }

                    // Raise the SimConnected event
                    if (m_SimConnected != null)
                    {
                        OnSimConnected(new SimConnectedEventArgs(simulator));
                    }

                    // If enabled, send an AgentThrottle packet to the server to increase our bandwidth
                    if (Client.Settings.SEND_AGENT_THROTTLE)
                    {
                        Client.Throttle.Set(simulator);
                    }

                    return simulator;
                }
                else
                {
                    // Connection failed, remove this simulator from our list and destroy it
                    lock (Simulators)
                    {
                        Simulators.Remove(simulator);
                    }

                    return null;
                }
            }
            else if (setDefault)
            {
                // Move in to this simulator
                simulator.handshakeComplete = false;
                simulator.UseCircuitCode(true);
                Client.Self.CompleteAgentMovement(simulator);

                // We're already connected to this server, but need to set it to the default
                SetCurrentSim(simulator, seedcaps);

                // Send an initial AgentUpdate to complete our movement in to the sim
                if (Client.Settings.SEND_AGENT_UPDATES)
                {
                    Client.Self.Movement.SendUpdate(true, simulator);
                }

                return simulator;
            }
            else
            {
                // Already connected to this simulator and wasn't asked to set it as the default,
                // just return a reference to the existing object
                return simulator;
            }
        }
예제 #3
0
 public virtual void Network_OnSimConnecting(object sender, SimConnectingEventArgs e)
 { e.Cancel = !OnEvent("On-Sim-Connecting", paramNamesOnSimConnecting, paramTypesOnSimConnecting, e); }
예제 #4
0
 void Network_SimConnecting(object sender, SimConnectingEventArgs e)
 {
     Logger.Log("Sim connecting " + e.Simulator.Handle + " " + e.Simulator.Name, Helpers.LogLevel.Info);
 }
예제 #5
0
 public override void Network_OnSimConnecting(object sender, SimConnectingEventArgs e)
 {
     //LeaveSimulator(simulator);
     e.Cancel = false;// base.Network_OnSimConnecting(simulator);
 }