You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NewServer.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.commandparser.commands.global;
  23. import com.dmdirc.Config;
  24. import com.dmdirc.Server;
  25. import com.dmdirc.commandparser.CommandManager;
  26. import com.dmdirc.commandparser.GlobalCommand;
  27. import com.dmdirc.identities.IdentityManager;
  28. import com.dmdirc.ui.interfaces.InputWindow;
  29. /**
  30. * The new server command allows users to open a new server window.
  31. * @author chris
  32. */
  33. public final class NewServer extends GlobalCommand {
  34. /**
  35. * Creates a new instance of NewServer.
  36. */
  37. public NewServer() {
  38. super();
  39. CommandManager.registerCommand(this);
  40. }
  41. /** {@inheritDoc} */
  42. public void execute(final InputWindow origin, final boolean isSilent,
  43. final String... args) {
  44. if (args.length == 0) {
  45. origin.addLine("commandUsage", Config.getCommandChar(), "newserver",
  46. "[--ssl] <host[:port]> [password]");
  47. return;
  48. }
  49. boolean ssl = false;
  50. String host = "";
  51. String pass = "";
  52. int port = 6667;
  53. int offset = 0;
  54. // Check for SSL
  55. if (args[offset].equalsIgnoreCase("--ssl")) {
  56. ssl = true;
  57. offset++;
  58. }
  59. // Check for port
  60. if (args[offset].indexOf(':') > -1) {
  61. final String[] parts = args[offset].split(":");
  62. host = parts[0];
  63. try {
  64. port = Integer.parseInt(parts[1]);
  65. } catch (NumberFormatException ex) {
  66. origin.addLine("commandError", "Invalid port specified");
  67. return;
  68. }
  69. } else {
  70. host = args[offset];
  71. }
  72. // Check for password
  73. if (args.length > ++offset) {
  74. pass = implodeArgs(offset, args);
  75. }
  76. new Server(host, port, pass, ssl, IdentityManager.getProfiles().get(0));
  77. }
  78. /** {@inheritDoc}. */
  79. public String getName() {
  80. return "newserver";
  81. }
  82. /** {@inheritDoc}. */
  83. public boolean showInHelp() {
  84. return true;
  85. }
  86. /** {@inheritDoc}. */
  87. public boolean isPolyadic() {
  88. return true;
  89. }
  90. /** {@inheritDoc}. */
  91. public int getArity() {
  92. return 0;
  93. }
  94. /** {@inheritDoc}. */
  95. public String getHelp() {
  96. return "newserver [--ssl] <host[:port]> [password] - connect to a new server";
  97. }
  98. }