Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ProcessQuit.java 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (c) 2006-2017 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.processors;
  23. import com.dmdirc.parser.events.ChannelQuitEvent;
  24. import com.dmdirc.parser.events.QuitEvent;
  25. import com.dmdirc.parser.interfaces.ChannelClientInfo;
  26. import com.dmdirc.parser.interfaces.ChannelInfo;
  27. import com.dmdirc.parser.interfaces.ClientInfo;
  28. import com.dmdirc.parser.irc.IRCChannelClientInfo;
  29. import com.dmdirc.parser.irc.IRCChannelInfo;
  30. import com.dmdirc.parser.irc.IRCClientInfo;
  31. import com.dmdirc.parser.irc.IRCParser;
  32. import com.dmdirc.parser.irc.TimestampedIRCProcessor;
  33. import java.time.LocalDateTime;
  34. import java.util.ArrayList;
  35. import javax.inject.Inject;
  36. /**
  37. * Process a Quit message.
  38. */
  39. public class ProcessQuit extends TimestampedIRCProcessor {
  40. /**
  41. * Create a new instance of the IRCProcessor Object.
  42. *
  43. * @param parser IRCParser That owns this IRCProcessor
  44. */
  45. @Inject
  46. public ProcessQuit(final IRCParser parser) {
  47. super(parser, "QUIT");
  48. }
  49. /**
  50. * Process a Quit message.
  51. *
  52. * @param date The LocalDateTime that this event occurred at.
  53. * @param sParam Type of line to process ("QUIT")
  54. * @param token IRCTokenised line to process
  55. */
  56. @Override
  57. public void process(final LocalDateTime date, final String sParam, final String... token) {
  58. // :nick!ident@host QUIT
  59. // :nick!ident@host QUIT :reason
  60. if (token.length < 2) {
  61. return;
  62. }
  63. final IRCClientInfo iClient = getClientInfo(token[0]);
  64. if (iClient == null) {
  65. return;
  66. }
  67. if (IRCParser.ALWAYS_UPDATECLIENT && iClient.getHostname().isEmpty()) {
  68. // This may seem pointless - updating before they leave - but the formatter needs it!
  69. iClient.setUserBits(token[0], false);
  70. }
  71. String sReason = "";
  72. if (token.length > 2) {
  73. sReason = token[token.length - 1];
  74. }
  75. final Iterable<IRCChannelInfo> channelList = new ArrayList<>(parser.getChannels());
  76. for (IRCChannelInfo iChannel : channelList) {
  77. final IRCChannelClientInfo iChannelClient = iChannel.getChannelClient(iClient);
  78. if (iChannelClient != null) {
  79. if (parser.getRemoveAfterCallback()) {
  80. callChannelQuit(date, iChannel, iChannelClient, sReason);
  81. }
  82. if (iClient == parser.getLocalClient()) {
  83. iChannel.emptyChannel();
  84. parser.removeChannel(iChannel);
  85. } else {
  86. iChannel.delClient(iClient);
  87. }
  88. if (!parser.getRemoveAfterCallback()) {
  89. callChannelQuit(date, iChannel, iChannelClient, sReason);
  90. }
  91. }
  92. }
  93. if (parser.getRemoveAfterCallback()) {
  94. callQuit(date, iClient, sReason);
  95. }
  96. if (iClient == parser.getLocalClient()) {
  97. parser.clearClients();
  98. } else {
  99. parser.removeClient(iClient);
  100. }
  101. if (!parser.getRemoveAfterCallback()) {
  102. callQuit(date, iClient, sReason);
  103. }
  104. }
  105. /**
  106. * Callback to all objects implementing the ChannelQuit Callback.
  107. *
  108. * @param date The LocalDateTime that this event occurred at.
  109. * @param cChannel Channel that user was on
  110. * @param cChannelClient User thats quitting
  111. * @param sReason Quit reason
  112. */
  113. protected void callChannelQuit(final LocalDateTime date, final ChannelInfo cChannel,
  114. final ChannelClientInfo cChannelClient, final String sReason) {
  115. getCallbackManager().publish(
  116. new ChannelQuitEvent(parser, LocalDateTime.now(), cChannel, cChannelClient,
  117. sReason));
  118. }
  119. /**
  120. * Callback to all objects implementing the Quit Callback.
  121. *
  122. * @param date The LocalDateTime that this event occurred at.
  123. * @param cClient Client Quitting
  124. * @param sReason Reason for quitting (may be "")
  125. */
  126. protected void callQuit(final LocalDateTime date, final ClientInfo cClient, final String sReason) {
  127. getCallbackManager().publish(new QuitEvent(parser, date, cClient, sReason));
  128. }
  129. }