Exemplo n.º 1
0
        /// <summary>
        /// Gives the client an ID and checks if the current username belongs to them.
        /// </summary>
        /// <param name="server">The Master Server to run this on.</param>
        /// <param name="toClient">The client's new ID.</param>
        /// <param name="username">The client's username to validate.</param>
        internal static void ValidateLogin(this MasterServer server, int fromClient, Packet packet)
        {
            string username = packet.ReadString();

            // If the username's length is less than 3, disconnect the client and warn them.
            if (username.Length < 3)
            {
                server.Message(fromClient, "Please enter a username longer than 2 characters. Disconnecting.");
                server.DisconnectClient(fromClient);

                MasterServer.DebugServer(server.serverTypeName, $"Disconnecting Client#{fromClient} for having the username '{username}' which is too short.");

                return;
            }

            server.InitializeLogin(fromClient, username);
        }