Java IRC bot
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.2KB

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