Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Process004005.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. * SVN: $Id$
  23. */
  24. package com.dmdirc.parser;
  25. import com.dmdirc.parser.callbacks.CallbackOnGotNetwork;
  26. /**
  27. * Process ISUPPORT lines.
  28. */
  29. public class Process004005 extends IRCProcessor {
  30. /**
  31. * Process ISUPPORT lines.
  32. *
  33. * @param sParam Type of line to process ("005", "004")
  34. * @param token IRCTokenised line to process
  35. */
  36. public void process(String sParam, String[] token) {
  37. if (sParam.equals("004")) {
  38. // 004
  39. myParser.h005Info.put("004IRCD",token[4]);
  40. myParser.h005Info.put("USERMODES",token[5]);
  41. myParser.h005Info.put("USERCHANMODES",token[6]);
  42. myParser.parseUserModes();
  43. } else {
  44. // 005
  45. String[] Bits = null;
  46. String sKey = null, sValue = null;
  47. for (int i = 3; i < token.length ; i++) {
  48. Bits = token[i].split("=",2);
  49. sKey = Bits[0].toUpperCase();
  50. if (Bits.length == 2) { sValue = Bits[1]; } else { sValue = ""; }
  51. callDebugInfo(myParser.DEBUG_INFO, "%s => %s",sKey,sValue);
  52. myParser.h005Info.put(sKey,sValue);
  53. if (sKey.equals("NETWORK")) {
  54. myParser.sNetworkName = sValue;
  55. callGotNetwork();
  56. } else if (sKey.equals("CASEMAPPING")) {
  57. byte limit = (byte)4;
  58. if (sValue.equalsIgnoreCase("strict-rfc1459")) {
  59. limit = (byte)3;
  60. } else if (sValue.equalsIgnoreCase("ascii")) {
  61. limit = (byte)0;
  62. } else if (!sValue.equalsIgnoreCase("rfc1459")) {
  63. myParser.callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Unknown casemapping: '"+sValue+"' - assuming rfc1459", myParser.getLastLine()));
  64. }
  65. boolean limitChanged = (myParser.getLastLimit() != limit);
  66. myParser.updateCharArrays(limit);
  67. if (limitChanged) {
  68. if (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. } else if (myParser.knownClients() > 1) {
  75. // If this happens then something buggered up.
  76. // joining channels before 005, when the encoding is not rfc1459
  77. myParser.callErrorInfo(new ParserError(ParserError.ERROR_ERROR, "Casemapping has changed since we have seen other users!", myParser.getLastLine()));
  78. }
  79. if (myParser.knownChannels() > 0) {
  80. // If this happens then something buggered up.
  81. // joining channels before 005, when the encoding is not rfc1459
  82. myParser.callErrorInfo(new ParserError(ParserError.ERROR_ERROR, "Casemapping has changed since we joined channels!", myParser.getLastLine()));
  83. }
  84. }
  85. } else if (sKey.equals("CHANTYPES")) {
  86. myParser.parseChanPrefix();
  87. } else if (sKey.equals("PREFIX")) {
  88. myParser.parsePrefixModes();
  89. } else if (sKey.equals("CHANMODES")) {
  90. myParser.parseChanModes();
  91. } else if (sKey.equals("LISTMODE")) {
  92. // Support for potential future decent mode listing in the protocol
  93. //
  94. // See my proposal: http://shane.dmdirc.com/listmodes.php
  95. // Add listmode handler
  96. String[] handles = new String[2];
  97. handles[0] = sValue; // List mode item
  98. sValue = ""+(Integer.parseInt(sValue) + 1);
  99. myParser.h005Info.put("LISTMODEEND", sValue);
  100. handles[1] = sValue; // List mode end
  101. // Add listmode handlers
  102. try {
  103. myParser.getProcessingManager().addProcessor(handles, myParser.getProcessingManager().getProcessor("__LISTMODE__"));
  104. } catch (Exception e) { }
  105. }
  106. }
  107. }
  108. }
  109. /**
  110. * What does this IRCProcessor handle.
  111. *
  112. * @return String[] with the names of the tokens we handle.
  113. */
  114. public String[] handles() {
  115. String[] iHandle = new String[2];
  116. iHandle[0] = "004";
  117. iHandle[1] = "005";
  118. return iHandle;
  119. }
  120. /**
  121. * Callback to all objects implementing the GotNetwork Callback.
  122. * This takes no params of its own, but works them out itself.
  123. *
  124. * @see IGotNetwork
  125. * @return true if a method was called, false otherwise
  126. */
  127. protected boolean callGotNetwork() {
  128. String networkName = myParser.sNetworkName;
  129. String ircdVersion = myParser.getIRCD(false);
  130. String ircdType = myParser.getIRCD(true);
  131. CallbackOnGotNetwork cb = (CallbackOnGotNetwork)getCallbackManager().getCallbackType("OnGotNetwork");
  132. if (cb != null) { return cb.call(networkName, ircdVersion, ircdType); }
  133. return false;
  134. }
  135. /**
  136. * Create a new instance of the IRCProcessor Object.
  137. *
  138. * @param parser IRCParser That owns this IRCProcessor
  139. * @param manager ProcessingManager that is in charge of this IRCProcessor
  140. */
  141. protected Process004005 (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
  142. }