您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ProcessNames.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.CallbackOnChannelGotNames;
  26. import uk.org.ownage.dmdirc.parser.callbacks.interfaces.IChannelGotNames;
  27. /**
  28. * Process a Names reply.
  29. */
  30. public class ProcessNames extends IRCProcessor {
  31. /**
  32. * Process a Names reply.
  33. *
  34. * @param sParam Type of line to process ("366", "353")
  35. * @param token IRCTokenised line to process
  36. */
  37. public void process(String sParam, String[] token) {
  38. ChannelInfo iChannel;
  39. if (sParam.equals("366")) {
  40. // End of names
  41. iChannel = getChannelInfo(token[3]);
  42. if (iChannel != null) {
  43. iChannel.bAddingNames = false;
  44. callChannelGotNames(iChannel);
  45. }
  46. } else {
  47. // Names
  48. ClientInfo iClient;
  49. ChannelClientInfo iChannelClient;
  50. iChannel = getChannelInfo(token[4]);
  51. if (iChannel == null) {
  52. callErrorInfo(new ParserError(ParserError.errWarning, "Got names for channel ("+token[4]+") that I am not on."));
  53. iChannel = new ChannelInfo(myParser, token[4]);
  54. myParser.hChannelList.put(iChannel.getName().toLowerCase(),iChannel);
  55. }
  56. // If we are not expecting names, clear the current known names - this is fresh stuff!
  57. if (!iChannel.bAddingNames) { iChannel.emptyChannel(); }
  58. iChannel.bAddingNames = true;
  59. String[] sNames = token[token.length-1].split(" ");
  60. String sNameBit = "", sModes = "", sName = "";
  61. int nPrefix = 0;
  62. for (int j = 0; j < sNames.length; ++j) {
  63. sNameBit = sNames[j];
  64. for (int i = 0; i < sNameBit.length(); ++i) {
  65. Character cMode = sNameBit.charAt(i);
  66. if (myParser.hPrefixMap.containsKey(cMode)) {
  67. // hPrefixMap contains @, o, +, v this caused issue 107
  68. // hPrefixModes only contains o, v so if the mode is in hPrefixMap
  69. // and not in hPrefixModes, its ok to use.
  70. if (!myParser.hPrefixModes.containsKey(cMode)) {
  71. sModes = sModes+cMode;
  72. nPrefix = nPrefix + myParser.hPrefixModes.get(myParser.hPrefixMap.get(cMode));
  73. }
  74. } else {
  75. sName = sNameBit.substring(i);
  76. break;
  77. }
  78. }
  79. callDebugInfo(myParser.ndInfo, "Name: %s Modes: \"%s\" [%d]",sName,sModes,nPrefix);
  80. iClient = getClientInfo(sName);
  81. if (iClient == null) { iClient = new ClientInfo(myParser, sName); myParser.hClientList.put(iClient.getNickname().toLowerCase(),iClient); }
  82. iChannelClient = iChannel.addClient(iClient);
  83. iChannelClient.setChanMode(nPrefix);
  84. sName = "";
  85. sModes = "";
  86. nPrefix = 0;
  87. }
  88. }
  89. }
  90. /**
  91. * Callback to all objects implementing the ChannelGotNames Callback.
  92. *
  93. * @see IChannelGotNames
  94. * @param cChannel Channel which the names reply is for
  95. */
  96. protected boolean callChannelGotNames(ChannelInfo cChannel) {
  97. CallbackOnChannelGotNames cb = (CallbackOnChannelGotNames)getCallbackManager().getCallbackType("OnChannelGotNames");
  98. if (cb != null) { return cb.call(cChannel); }
  99. return false;
  100. }
  101. /**
  102. * What does this IRCProcessor handle.
  103. *
  104. * @return String[] with the names of the tokens we handle.
  105. */
  106. public String[] handles() {
  107. String[] iHandle = new String[2];
  108. iHandle[0] = "353";
  109. iHandle[1] = "366";
  110. return iHandle;
  111. }
  112. /**
  113. * Create a new instance of the IRCProcessor Object
  114. *
  115. * @param parser IRCParser That owns this IRCProcessor
  116. * @param manager ProcessingManager that is in charge of this IRCProcessor
  117. */
  118. protected ProcessNames (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
  119. }