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.

ProcessListModes.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
  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 uk.org.ownage.dmdirc.parser;
  25. // import uk.org.ownage.dmdirc.parser.callbacks.;
  26. // import uk.org.ownage.dmdirc.parser.callbacks.interfaces.;
  27. /**
  28. * Process a List Modes.
  29. */
  30. public class ProcessListModes extends IRCProcessor {
  31. /**
  32. * Process a ListModes.
  33. *
  34. * @param sParam Type of line to process ("348", "349", "346", "347", "367", "368")
  35. * @param token IRCTokenised line to process
  36. */
  37. public void process(String sParam, String[] token) {
  38. //<- :uk.ircnet.org 348 DF|Laptop #dmdirc test2!*@*
  39. //<- :uk.ircnet.org 348 DF|Laptop #dmdirc test1!*@*
  40. //<- :uk.ircnet.org 349 DF|Laptop #dmdirc :End of Channel Exception List
  41. //<- :uk.ircnet.org 346 DF|Laptop #dmdirc test2!*@*
  42. //<- :uk.ircnet.org 346 DF|Laptop #dmdirc test1!*@*
  43. //<- :uk.ircnet.org 347 DF|Laptop #dmdirc :End of Channel Invite List
  44. //<- :neo.uk.CodersIRC.org 367 DF|Laptop #dmdirc test2!*@* DF|Laptop 1115086001
  45. //<- :neo.uk.CodersIRC.org 367 DF|Laptop #dmdirc test1!*@* DF|Laptop 1115086000
  46. //<- :neo.uk.CodersIRC.org 368 DF|Laptop #dmdirc :End of Channel Ban List
  47. ChannelInfo channel = getChannelInfo(token[3]);
  48. String item = "";
  49. String owner = "";
  50. long time = 0;
  51. char mode = 'b';
  52. boolean isItem = true; // true if item listing, false if "end of .." item
  53. if (channel == null) { return; }
  54. if (sParam.equals("367")) { mode = 'b'; isItem = true; }
  55. else if (sParam.equals("348")) { mode = 'e'; isItem = true; }
  56. else if (sParam.equals("346")) { mode = 'I'; isItem = true; }
  57. else if (sParam.equals("368")) { mode = 'b'; isItem = false; }
  58. else if (sParam.equals("349")) { mode = 'e'; isItem = false; }
  59. else if (sParam.equals("347")) { mode = 'I'; isItem = false; }
  60. if (isItem) {
  61. if (!channel.getAddState(mode)) {
  62. callDebugInfo(myParser.ndInfo, "New List Mode Batch: Clearing!");
  63. channel.getListModeParam(mode).clear();
  64. channel.setAddState(mode, true);
  65. }
  66. if (token.length > 6) {
  67. try { time = Long.parseLong(token[6]); } catch (Exception e) { time = 0; }
  68. }
  69. if (token.length > 5) { owner = token[5]; }
  70. if (token.length > 4) { item = token[4]; }
  71. if (!item.equals("")) {
  72. ChannelListModeItem clmi = new ChannelListModeItem(item, owner, time);
  73. callDebugInfo(myParser.ndInfo, "List Mode: %c [%s/%s/%d]",mode, item, owner, time);
  74. channel.setListModeParam(mode, clmi, true);
  75. }
  76. } else {
  77. channel.setAddState(mode, false);
  78. }
  79. }
  80. /**
  81. * What does this IRCProcessor handle.
  82. *
  83. * @return String[] with the names of the tokens we handle.
  84. */
  85. public String[] handles() {
  86. String[] iHandle = new String[6];
  87. iHandle[0] = "348";
  88. iHandle[1] = "349";
  89. iHandle[2] = "346";
  90. iHandle[3] = "347";
  91. iHandle[4] = "367";
  92. iHandle[5] = "368";
  93. return iHandle;
  94. }
  95. /**
  96. * Create a new instance of the IRCProcessor Object
  97. *
  98. * @param parser IRCParser That owns this IRCProcessor
  99. * @param manager ProcessingManager that is in charge of this IRCProcessor
  100. */
  101. protected ProcessListModes (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
  102. /**
  103. * Get SVN Version information.
  104. *
  105. * @return SVN Version String
  106. */
  107. public static String getSvnInfo () { return "$Id$"; }
  108. }