Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ProcessNick.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.CallbackOnChannelNickChanged;
  26. import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnNickChanged;
  27. import uk.org.ownage.dmdirc.parser.callbacks.interfaces.IChannelNickChanged;
  28. import uk.org.ownage.dmdirc.parser.callbacks.interfaces.INickChanged;
  29. import java.util.Enumeration;
  30. /**
  31. * Process a Nick change.
  32. */
  33. public class ProcessNick extends IRCProcessor {
  34. /**
  35. * Process a Nick change.
  36. *
  37. * @param sParam Type of line to process ("NICK")
  38. * @param token IRCTokenised line to process
  39. */
  40. public void process(String sParam, String[] token) {
  41. ClientInfo iClient;
  42. ChannelClientInfo iChannelClient;
  43. ChannelInfo iChannel;
  44. iClient = getClientInfo(token[0]);
  45. if (iClient != null) {
  46. // Remove the client from the known clients list
  47. myParser.hClientList.remove(iClient.getNickname().toLowerCase());
  48. // Change the nickame
  49. iClient.setUserBits(token[2],true);
  50. // Readd the client
  51. myParser.hClientList.put(iClient.getNickname().toLowerCase(),iClient);
  52. for (Enumeration e = myParser.hChannelList.keys(); e.hasMoreElements();) {
  53. iChannel = myParser.hChannelList.get(e.nextElement());
  54. iChannelClient = iChannel.getUser(iClient);
  55. if (iChannelClient != null) {
  56. callChannelNickChanged(iChannel,iChannelClient,ClientInfo.parseHost(token[0]));
  57. }
  58. }
  59. callNickChanged(iClient, ClientInfo.parseHost(token[0]));
  60. }
  61. }
  62. /**
  63. * Callback to all objects implementing the ChannelNickChanged Callback.
  64. *
  65. * @see IChannelNickChanged
  66. * @param cChannel One of the channels that the user is on
  67. * @param cChannelClient Client changing nickname
  68. * @param sOldNick Nickname before change
  69. */
  70. protected boolean callChannelNickChanged(ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sOldNick) {
  71. CallbackOnChannelNickChanged cb = (CallbackOnChannelNickChanged)getCallbackManager().getCallbackType("OnChannelNickChanged");
  72. if (cb != null) { return cb.call(cChannel, cChannelClient, sOldNick); }
  73. return false;
  74. }
  75. /**
  76. * Callback to all objects implementing the NickChanged Callback.
  77. *
  78. * @see INickChanged
  79. * @param cClient Client changing nickname
  80. * @param sOldNick Nickname before change
  81. */
  82. protected boolean callNickChanged(ClientInfo cClient, String sOldNick) {
  83. CallbackOnNickChanged cb = (CallbackOnNickChanged)getCallbackManager().getCallbackType("OnNickChanged");
  84. if (cb != null) { return cb.call(cClient, sOldNick); }
  85. return false;
  86. }
  87. /**
  88. * What does this IRCProcessor handle.
  89. *
  90. * @return String[] with the names of the tokens we handle.
  91. */
  92. public String[] handles() {
  93. String[] iHandle = new String[1];
  94. iHandle[0] = "NICK";
  95. return iHandle;
  96. }
  97. /**
  98. * Create a new instance of the IRCProcessor Object
  99. *
  100. * @param parser IRCParser That owns this IRCProcessor
  101. * @param manager ProcessingManager that is in charge of this IRCProcessor
  102. */
  103. protected ProcessNick (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
  104. }