private static void ExecMkServer(string command) { var parts = command.Remove(0, 8).Trim().Split(' '); var username = string.Empty; var server = string.Empty; var password = new Regex("\"(.*)\"", RegexOptions.IgnoreCase).Replace(new Regex("-p \".*\"", RegexOptions.IgnoreCase).Match(command).Value.Replace("-p ", ""), "$1"); for (int i = 0, l = parts.Length; i < l; i++) { switch (parts[i]) { case "-s": server = parts[i + 1]; break; case "-u": username = parts[i + 1]; break; } } while (server == string.Empty) { Console.Write(" -> Server name: "); server = _validateName(Console.ReadLine()?.Trim()); } while (username == string.Empty) { Console.Write(" -> Username: "******" -> Password (Leave blank to ignore (not recommended)): "); password = _password(); } try { Jsondb.CreateServer(server, username, password); Console.WriteLine("Server created."); } catch (Exception e) { Console.WriteLine("Unable to create the server: " + e.Message); } }
private void CreateServer(object sender, RoutedEventArgs e) { LockUi(); if (Jsondb.ServerExists(ServerNameBox.Text)) { new MessageWindow(this, "A server with this name already exist.", Title, MessageWindowButton.Ok, MessageWindowImage.Error).Open(); } else { Jsondb.CreateServer(ServerNameBox.Text, UsernameBox.Text, PasswordBox.Text); new MessageWindow(this, "The server is successfully created.", Title, MessageWindowButton.Ok, MessageWindowImage.Success).Open(); Close(); } UnlockUi(); }