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.

Process004005.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (c) 2006-2008 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.parser;
  23. import com.dmdirc.parser.callbacks.CallbackOnGotNetwork;
  24. /**
  25. * Process ISUPPORT lines.
  26. */
  27. public class Process004005 extends IRCProcessor {
  28. /**
  29. * Process ISUPPORT lines.
  30. *
  31. * @param sParam Type of line to process ("005", "004")
  32. * @param token IRCTokenised line to process
  33. */
  34. @Override
  35. public void process(final String sParam, final String[] token) {
  36. if (sParam.equals("003")) {
  37. myParser.h005Info.put("003IRCD",token[token.length-1]);
  38. } else if (sParam.equals("004")) {
  39. // 004
  40. myParser.h005Info.put("004IRCD",token[4]);
  41. myParser.h005Info.put("USERMODES",token[5]);
  42. myParser.h005Info.put("USERCHANMODES",token[6]);
  43. myParser.parseUserModes();
  44. } else if (sParam.equals("005")) {
  45. // 005
  46. String[] Bits = null;
  47. String sKey = null, sValue = null;
  48. for (int i = 3; i < token.length ; i++) {
  49. Bits = token[i].split("=",2);
  50. sKey = Bits[0].toUpperCase();
  51. if (Bits.length == 2) { sValue = Bits[1]; } else { sValue = ""; }
  52. callDebugInfo(IRCParser.DEBUG_INFO, "%s => %s",sKey,sValue);
  53. myParser.h005Info.put(sKey,sValue);
  54. if (sKey.equals("NETWORK")) {
  55. myParser.sNetworkName = sValue;
  56. callGotNetwork();
  57. } else if (sKey.equals("CASEMAPPING")) {
  58. byte limit = (byte)4;
  59. if (sValue.equalsIgnoreCase("strict-rfc1459")) {
  60. limit = (byte)3;
  61. } else if (sValue.equalsIgnoreCase("ascii")) {
  62. limit = (byte)0;
  63. } else if (!sValue.equalsIgnoreCase("rfc1459")) {
  64. myParser.callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Unknown casemapping: '"+sValue+"' - assuming rfc1459", myParser.getLastLine()));
  65. }
  66. final boolean limitChanged = (myParser.getIRCStringConverter().getLimit() != limit);
  67. myParser.updateCharArrays(limit);
  68. if (limitChanged && myParser.knownClients() == 1) {
  69. // This means that the casemapping is not rfc1459
  70. // We have only added ourselves so far (from 001)
  71. // We can fix the hashtable easily.
  72. myParser.removeClient(myParser.getMyself());
  73. myParser.addClient(myParser.getMyself());
  74. }
  75. } else if (sKey.equals("CHANTYPES")) {
  76. myParser.parseChanPrefix();
  77. } else if (sKey.equals("PREFIX")) {
  78. myParser.parsePrefixModes();
  79. } else if (sKey.equals("CHANMODES")) {
  80. myParser.parseChanModes();
  81. } else if (sKey.equals("LISTMODE")) {
  82. // Support for potential future decent mode listing in the protocol
  83. //
  84. // See my proposal: http://shane.dmdirc.com/listmodes.php
  85. // Add listmode handler
  86. String[] handles = new String[2];
  87. handles[0] = sValue; // List mode item
  88. sValue = ""+(Integer.parseInt(sValue) + 1);
  89. myParser.h005Info.put("LISTMODEEND", sValue);
  90. handles[1] = sValue; // List mode end
  91. // Add listmode handlers
  92. try {
  93. myParser.getProcessingManager().addProcessor(handles, myParser.getProcessingManager().getProcessor("__LISTMODE__"));
  94. } catch (ProcessorNotFoundException e) { }
  95. }
  96. }
  97. }
  98. }
  99. /**
  100. * What does this IRCProcessor handle.
  101. *
  102. * @return String[] with the names of the tokens we handle.
  103. */
  104. @Override
  105. public String[] handles() {
  106. return new String[]{"003", "004", "005"};
  107. }
  108. /**
  109. * Callback to all objects implementing the GotNetwork Callback.
  110. * This takes no params of its own, but works them out itself.
  111. *
  112. * @see IGotNetwork
  113. * @return true if a method was called, false otherwise
  114. */
  115. protected boolean callGotNetwork() {
  116. final String networkName = myParser.sNetworkName;
  117. final String ircdVersion = myParser.getIRCD(false);
  118. final String ircdType = myParser.getIRCD(true);
  119. return ((CallbackOnGotNetwork) getCallbackManager().getCallbackType("OnGotNetwork")).call(networkName, ircdVersion, ircdType);
  120. }
  121. /**
  122. * Create a new instance of the IRCProcessor Object.
  123. *
  124. * @param parser IRCParser That owns this IRCProcessor
  125. * @param manager ProcessingManager that is in charge of this IRCProcessor
  126. */
  127. protected Process004005 (final IRCParser parser, final ProcessingManager manager) { super(parser, manager); }
  128. }