Esempio n. 1
0
        public void Disconnect()
        {
            while (this.data_out.Count > 0)
            {
                try
                {
                    byte[] packet;

                    if (this.data_out.TryPeek(out packet))
                    {
                        this.Sock.Send(packet);
                        Stats.DataSent += (ulong)packet.Length;

                        while (!this.data_out.TryDequeue(out packet))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                catch { break; }
            }

            try { this.Sock.Disconnect(false); }
            catch { }
            try { this.Sock.Shutdown(SocketShutdown.Both); }
            catch { }
            try { this.Sock.Close(); }
            catch { }
            try { this.Sock.Dispose(); }
            catch { }

            this.SocketConnected = false;

            if (this.LoginPhase == LinkLogin.Ready)
            {
                LeafPool.Leaves.ForEachWhere(x => x.SendPacket(HubOutbound.HubLeafDisconnected(x, this)),
                                             x => x.Ident != this.Ident && x.LoginPhase == LinkLogin.Ready);
            }
        }