Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ProcessQuit.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. import com.dmdirc.parser.interfaces.ChannelClientInfo;
  24. import com.dmdirc.parser.interfaces.ChannelInfo;
  25. import com.dmdirc.parser.interfaces.ClientInfo;
  26. import com.dmdirc.parser.interfaces.callbacks.ChannelQuitListener;
  27. import com.dmdirc.parser.interfaces.callbacks.QuitListener;
  28. import java.util.ArrayList;
  29. /**
  30. * Process a Quit message.
  31. */
  32. public class ProcessQuit extends IRCProcessor {
  33. /**
  34. * Process a Quit message.
  35. *
  36. * @param sParam Type of line to process ("QUIT")
  37. * @param token IRCTokenised line to process
  38. */
  39. @Override
  40. public void process(final String sParam, final String[] token) {
  41. // :nick!ident@host QUIT
  42. // :nick!ident@host QUIT :reason
  43. if (token.length < 2) { return; }
  44. IRCClientInfo iClient;
  45. IRCChannelClientInfo iChannelClient;
  46. iClient = getClientInfo(token[0]);
  47. if (iClient == null) { return; }
  48. if (IRCParser.ALWAYS_UPDATECLIENT && iClient.getHostname().isEmpty()) {
  49. // This may seem pointless - updating before they leave - but the formatter needs it!
  50. iClient.setUserBits(token[0],false);
  51. }
  52. String sReason = "";
  53. if (token.length > 2) { sReason = token[token.length-1]; }
  54. ArrayList<IRCChannelInfo> channelList = new ArrayList<IRCChannelInfo>(myParser.getChannels());
  55. for (IRCChannelInfo iChannel : channelList) {
  56. iChannelClient = iChannel.getChannelClient(iClient);
  57. if (iChannelClient != null) {
  58. if (myParser.removeAfterCallback) { callChannelQuit(iChannel,iChannelClient,sReason); }
  59. if (iClient == myParser.getLocalClient()) {
  60. iChannel.emptyChannel();
  61. myParser.removeChannel(iChannel);
  62. } else {
  63. iChannel.delClient(iClient);
  64. }
  65. if (!myParser.removeAfterCallback) { callChannelQuit(iChannel,iChannelClient,sReason); }
  66. }
  67. }
  68. if (myParser.removeAfterCallback) { callQuit(iClient,sReason); }
  69. if (iClient == myParser.getLocalClient()) {
  70. myParser.clearClients();
  71. } else {
  72. myParser.removeClient(iClient);
  73. }
  74. if (!myParser.removeAfterCallback) { callQuit(iClient,sReason); }
  75. }
  76. /**
  77. * Callback to all objects implementing the ChannelQuit Callback.
  78. *
  79. * @see IChannelQuit
  80. * @param cChannel Channel that user was on
  81. * @param cChannelClient User thats quitting
  82. * @param sReason Quit reason
  83. * @return true if a method was called, false otherwise
  84. */
  85. protected boolean callChannelQuit(final ChannelInfo cChannel, final ChannelClientInfo cChannelClient, final String sReason) {
  86. return getCallbackManager().getCallbackType(ChannelQuitListener.class).call(cChannel, cChannelClient, sReason);
  87. }
  88. /**
  89. * Callback to all objects implementing the Quit Callback.
  90. *
  91. * @see IQuit
  92. * @param cClient Client Quitting
  93. * @param sReason Reason for quitting (may be "")
  94. * @return true if a method was called, false otherwise
  95. */
  96. protected boolean callQuit(final ClientInfo cClient, final String sReason) {
  97. return getCallbackManager().getCallbackType(QuitListener.class).call(cClient, sReason);
  98. }
  99. /**
  100. * What does this IRCProcessor handle.
  101. *
  102. * @return String[] with the names of the tokens we handle.
  103. */
  104. @Override
  105. public String[] handles() {
  106. return new String[]{"QUIT"};
  107. }
  108. /**
  109. * Create a new instance of the IRCProcessor Object.
  110. *
  111. * @param parser IRCParser That owns this IRCProcessor
  112. * @param manager ProcessingManager that is in charge of this IRCProcessor
  113. */
  114. protected ProcessQuit (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
  115. }