OpenMetaverse.NetworkManager.DisconnectSim C# (CSharp) Method

DisconnectSim() public method

public DisconnectSim ( Simulator sim, bool sendCloseCircuit ) : void
sim Simulator
sendCloseCircuit bool
return void
        public void DisconnectSim(Simulator sim, bool sendCloseCircuit)
        {
            if (sim != null)
            {
                sim.Disconnect(sendCloseCircuit);

                // Fire the SimDisconnected event if a handler is registered
                if (OnSimDisconnected != null)
                {
                    try { OnSimDisconnected(sim, DisconnectType.NetworkTimeout); }
                    catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
                }

                lock (Simulators) Simulators.Remove(sim);

                if (Simulators.Count == 0) Shutdown(DisconnectType.SimShutdown);
            }
            else
            {
                Logger.Log("DisconnectSim() called with a null Simulator reference", Helpers.LogLevel.Warning, Client);
            }
        }

Usage Example

Example #1
0
        /// <summary>
        /// Send a raw byte array payload as a packet
        /// </summary>
        /// <param name="payload">The packet payload</param>
        /// <param name="setSequence">Whether the second, third, and fourth bytes
        /// should be modified to the current stream sequence number</param>
        public void SendPacketUnqueued(byte[] payload, bool setSequence)
        {
            try
            {
                if (setSequence && payload.Length > 3)
                {
                    uint sequence = (uint)Interlocked.Increment(ref Sequence);

                    payload[1] = (byte)(sequence >> 16);
                    payload[2] = (byte)(sequence >> 8);
                    payload[3] = (byte)(sequence % 256);
                }

                Stats.SentBytes += (ulong)payload.Length;
                ++Stats.SentPackets;

                UDPPacketBuffer buf = new UDPPacketBuffer(ipEndPoint);
                Buffer.BlockCopy(payload, 0, buf.Data, 0, payload.Length);
                buf.DataLength = payload.Length;

                AsyncBeginSend(buf);
            }
            catch (SocketException)
            {
                Logger.Log("Tried to send a " + payload.Length +
                           " byte payload on a closed socket, shutting down " + this.ToString(),
                           Helpers.LogLevel.Info, Client);

                Network.DisconnectSim(this, false);
                return;
            }
            catch (Exception e)
            {
                Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e);
            }
        }