Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

NewServer.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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.Main;
  25. import com.dmdirc.Server;
  26. import com.dmdirc.commandparser.CommandManager;
  27. import com.dmdirc.commandparser.CommandWindow;
  28. import com.dmdirc.commandparser.GlobalCommand;
  29. import com.dmdirc.identities.IdentityManager;
  30. /**
  31. * The new server command allows users to open a new server window.
  32. * @author chris
  33. */
  34. public final class NewServer extends GlobalCommand {
  35. /**
  36. * Creates a new instance of NewServer.
  37. */
  38. public NewServer() {
  39. super();
  40. CommandManager.registerCommand(this);
  41. }
  42. /** {@inheritDoc} */
  43. public void execute(final CommandWindow origin, final boolean isSilent,
  44. final String... args) {
  45. if (args.length == 0) {
  46. origin.addLine("commandUsage", Config.getCommandChar(), "newserver",
  47. "[--ssl] <host[:port]> [password]");
  48. return;
  49. }
  50. boolean ssl = false;
  51. String host = "";
  52. String pass = "";
  53. int port = 6667;
  54. int offset = 0;
  55. // Check for SSL
  56. if (args[offset].equalsIgnoreCase("--ssl")) {
  57. ssl = true;
  58. offset++;
  59. }
  60. // Check for port
  61. if (args[offset].indexOf(':') > -1) {
  62. String[] parts = args[offset].split(":");
  63. host = parts[0];
  64. try {
  65. port = Integer.parseInt(parts[1]);
  66. } catch (NumberFormatException ex) {
  67. origin.addLine("commandError", "Invalid port specified");
  68. return;
  69. }
  70. } else {
  71. host = args[offset];
  72. }
  73. // Check for password
  74. if (args.length > ++offset) {
  75. pass = implodeArgs(offset, args);
  76. }
  77. new Server(host, port, pass, ssl, IdentityManager.getProfiles().get(0));
  78. }
  79. /** {@inheritDoc}. */
  80. public String getName() {
  81. return "newserver";
  82. }
  83. /** {@inheritDoc}. */
  84. public boolean showInHelp() {
  85. return true;
  86. }
  87. /** {@inheritDoc}. */
  88. public boolean isPolyadic() {
  89. return true;
  90. }
  91. /** {@inheritDoc}. */
  92. public int getArity() {
  93. return 0;
  94. }
  95. /** {@inheritDoc}. */
  96. public String getHelp() {
  97. return "newserver [--ssl] <host[:port]> [password] - connect to a new server";
  98. }
  99. }