Disconnect() public method

public Disconnect ( string reason = "Disconnect" ) : void
reason string
return void
        public static void UpdateNetwork()
        {
            NetIncomingMessage msg;

            if (server == null)
                return;

            while ((msg = server.ReadMessage()) != null)
            {
                switch (msg.MessageType)
                {
                    case NetIncomingMessageType.VerboseDebugMessage:
                    case NetIncomingMessageType.DebugMessage:
                    case NetIncomingMessageType.ErrorMessage:
                    case NetIncomingMessageType.WarningMessage:
                        Console.WriteLine("{0}: {1}", msg.MessageType, msg.ReadString());
                        break;

                    case NetIncomingMessageType.StatusChanged:
                        {
                            if (msg.SenderConnection == null)
                                break;

                            NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte();
                            string reason = msg.ReadString();

                            Console.WriteLine("StatusChanged: {0} '{1}'", status, reason);

                            switch (status)
                            {
                                case NetConnectionStatus.Connected:
                                    {
                                        if (State == States.InGame && !AllowLateJoins)
                                        {
                                            // F**k off, no visitors
                                            msg.SenderConnection.Disconnect("Already in game, f**k off.");
                                            break;
                                        }

                                        if (Clients.Count == MaxPlayers)
                                        {
                                            msg.SenderConnection.Disconnect("Too crowded, f**k off.");
                                            break;
                                        }

                                        ServerClient client = new ServerClient(msg.SenderConnection, GenerateId());
                                        msg.SenderConnection.Tag = client;
                                        Clients.Add(client);
                                        break;
                                    }

                                case NetConnectionStatus.Disconnected:
                                    {
                                        if (msg.SenderConnection.Tag == null)
                                            break;

                                        ServerClient serverClient = (ServerClient)msg.SenderConnection.Tag;
                                        if (serverClient.Verified)
                                        {
                                            SendMessageToAllExcept(new PlayerDelete(serverClient.Id), serverClient.Id);

                                            ServerClient client = (ServerClient)msg.SenderConnection.Tag;
                                            client.Disconnect();
                                            Clients.Remove(client);

                                            // Card Czar left like the asshole he is
                                            if (serverClient.Id == currentCardCzar)
                                                DeclareWinner(Clients[random.Next(Clients.Count)].Id);
                                        }
                                        break;
                                    }
                            }
                            break;
                        }

                    case NetIncomingMessageType.Data:
                        {
                            if (msg.SenderConnection == null || msg.SenderConnection.Tag == null)
                                break;

                            ServerClient client = (ServerClient)msg.SenderConnection.Tag;
                            Packet packet = Packet.ReadFromMessage(msg);
                            client.HandleMessage(packet);
                            break;
                        }

                    default:
                        Console.WriteLine("Unhandled type: " + msg.MessageType);
                        break;
                }

                server.Recycle(msg);
            }

            HandleGame();
        }
        public static void UpdateNetwork()
        {
            NetIncomingMessage msg;

            if (server == null)
            {
                return;
            }

            while ((msg = server.ReadMessage()) != null)
            {
                switch (msg.MessageType)
                {
                case NetIncomingMessageType.VerboseDebugMessage:
                case NetIncomingMessageType.DebugMessage:
                case NetIncomingMessageType.ErrorMessage:
                case NetIncomingMessageType.WarningMessage:
                    Console.WriteLine("{0}: {1}", msg.MessageType, msg.ReadString());
                    break;

                case NetIncomingMessageType.StatusChanged:
                {
                    if (msg.SenderConnection == null)
                    {
                        break;
                    }

                    NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte();
                    string reason = msg.ReadString();

                    Console.WriteLine("StatusChanged: {0} '{1}'", status, reason);

                    switch (status)
                    {
                    case NetConnectionStatus.Connected:
                    {
                        if (State == States.InGame && !AllowLateJoins)
                        {
                            // F**k off, no visitors
                            msg.SenderConnection.Disconnect("Already in game, f**k off.");
                            break;
                        }

                        if (Clients.Count == Constants.MaxPlayerCount)
                        {
                            msg.SenderConnection.Disconnect("Too crowded, f**k off.");
                            break;
                        }

                        ServerClient client = new ServerClient(msg.SenderConnection, GenerateId());
                        msg.SenderConnection.Tag = client;
                        Clients.Add(client);

                        if (State == States.Lobby)
                        {
                            ServerList.Update();
                        }

                        break;
                    }

                    case NetConnectionStatus.Disconnected:
                    {
                        if (msg.SenderConnection.Tag == null)
                        {
                            break;
                        }

                        ServerClient serverClient = (ServerClient)msg.SenderConnection.Tag;
                        if (serverClient.Verified)
                        {
                            SendMessageToAllExcept(new PlayerDelete(serverClient.Id), serverClient.Id);

                            ServerClient client = (ServerClient)msg.SenderConnection.Tag;
                            client.Disconnect();
                            Clients.Remove(client);

                            // Card Czar left like the asshole he is
                            if (serverClient.Id == currentCardCzar)
                            {
                                DeclareWinner(Clients[Random.Next(Clients.Count)].Id);
                            }

                            if (State == States.Lobby)
                            {
                                ServerList.Update();
                            }
                        }
                        else
                        {
                            Clients.Remove((ServerClient)msg.SenderConnection.Tag);
                        }
                        break;
                    }
                    }
                    break;
                }

                case NetIncomingMessageType.Data:
                {
                    if (msg.SenderConnection == null || msg.SenderConnection.Tag == null)
                    {
                        break;
                    }

                    ServerClient client = (ServerClient)msg.SenderConnection.Tag;
                    Packet       packet = Packet.ReadFromMessage(msg);
                    client.HandleMessage(packet);
                    break;
                }

                default:
                    Console.WriteLine("Unhandled type: " + msg.MessageType);
                    break;
                }

                server.Recycle(msg);
            }

            HandleGame();
        }