選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ProcessQuit.java 5.1KB

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