protected override void HandleClosure(SocketError err)
        {
            state = SlotState.SHUTDOWN;

            var slot = Interlocked.Exchange(ref assignedSlot, -2);

            if (slot >= 0)
            {
                ProgramLog.Users.Log("{0} @ {1}: connection closed ({2}).", RemoteAddress, slot, err);
                SlotManager.FreeSlot(slot);
                //Netplay.slots[slot].Reset ();
            }
            else
            {
                SlotManager.RemoveFromQueues(this);
                ProgramLog.Users.Log("{0}: connection closed ({1}).", RemoteAddress, err);
            }

            var player = Player;

            if (player != null)
            {
                player.Connection = null;
                player.Active     = false;
            }

            FreeSectionBuffer();

            lock (All)
            {
                if (indexInAll == All.Count - 1)
                {
                    All.RemoveAt(All.Count - 1);
                }
                else if (indexInAll >= 0)
                {
                    var other = All[All.Count - 1];
                    other.indexInAll = indexInAll;
                    All[indexInAll]  = other;
                    All.RemoveAt(All.Count - 1);
                    indexInAll = -1;
                }
            }
        }
        static void TimeoutLoop()
        {
            var conns = new List <ClientConnection> ();
            var msg   = NetMessage.PrepareThreadInstance();

            while (true)
            {
                Thread.Sleep(5000);

                lock (All) conns.AddRange(All);

                foreach (var conn in conns)
                {
                    conn.timeout += 5;

                    if (conn.State == SlotState.QUEUED)
                    {
                        if (conn.timeout >= Main.timeOut / 2)
                        {
                            msg.Clear();
                            msg.SendTileLoading(1, SlotManager.WaitingMessage(conn));
                            conn.Send(msg.Output);
                            conn.timeout = 0;
                        }
                    }
                    else if (conn.timeout >= Main.timeOut)
                    {
                        try
                        {
                            conn.Kick("Timed out.");
                        }
                        catch (Exception e)
                        {
                            ProgramLog.Log(e, "Exception in timeout thread");
                        }
                    }
                }

                conns.Clear();
            }
        }