/// <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); }
/// <summary> /// Handles the client's answer. If it matches the client's name /// then initialize them as a Cluster Client. /// </summary> /// <param name="server">The Master Server to run this on.</param> /// <param name="fromClient">The client sending this packet.</param> /// <param name="packet">The packet containing the answer and extra data.</param> internal static void AnswerPassphrase(this MasterServer server, int fromClient, Packet packet) { string answer = packet.ReadString(); string clusterName = packet.ReadString(); // The requested name for this cluster. if (answer == server.clients[fromClient].name) { server.InitializeCluster(fromClient, clusterName); } else { server.Message(fromClient, "Incorrect passphrase. Disconnecting."); server.DisconnectClient(fromClient); MasterServer.DebugServer(server.serverTypeName, $"Disconnecting Client#{fromClient} for answering their passphrase incorrectly."); return; } }