You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProcessKick.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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.CallbackOnChannelKick;
  26. import uk.org.ownage.dmdirc.parser.callbacks.interfaces.IChannelKick;
  27. /**
  28. * Process a channel kick.
  29. */
  30. public class ProcessKick extends IRCProcessor {
  31. /**
  32. * Process a channel kick.
  33. *
  34. * @param sParam Type of line to process ("KICK")
  35. * @param token IRCTokenised line to process
  36. */
  37. public void process(String sParam, String[] token) {
  38. ChannelClientInfo iChannelClient;
  39. ChannelClientInfo iChannelKicker;
  40. ChannelInfo iChannel;
  41. ClientInfo iClient;
  42. ClientInfo iKicker;
  43. String sReason = "";
  44. iClient = getClientInfo(token[3]);
  45. iKicker = getClientInfo(token[0]);
  46. iChannel = getChannelInfo(token[2]);
  47. if (iClient == null) { return; }
  48. if (myParser.alwaysUpdateClient && iKicker != null) {
  49. // To facilitate dmdirc formatter, get user information
  50. if (iKicker.getHost().equals("")) { iKicker.setUserBits(token[0],false); }
  51. }
  52. if (iChannel == null) {
  53. if (iClient != myParser.cMyself) {
  54. callErrorInfo(new ParserError(ParserError.errWarning, "Got kick for channel ("+token[2]+") that I am not on. [User: "+token[3]+"]"));
  55. }
  56. return;
  57. } else {
  58. if (token.length > 4) { sReason = token[token.length-1]; }
  59. iChannelClient = iChannel.getUser(iClient);
  60. iChannelKicker = iChannel.getUser(token[0]);
  61. callChannelKick(iChannel,iChannelClient,iChannelKicker,sReason,token[0]);
  62. iChannel.delClient(iClient);
  63. if (iClient == myParser.cMyself) {
  64. iChannel.emptyChannel();
  65. myParser.hChannelList.remove(iChannel.getName().toLowerCase());
  66. } else {
  67. // Check if client is still on any channel we are on
  68. if (!iClient.checkVisability()) {
  69. // if not, remove them from memory incase they quit without us seeing
  70. myParser.hClientList.remove(iClient.getNickname().toLowerCase());
  71. }
  72. }
  73. }
  74. }
  75. /**
  76. * Callback to all objects implementing the ChannelKick Callback.
  77. *
  78. * @see IChannelKick
  79. * @param cChannel Channel where the kick took place
  80. * @param cKickedClient ChannelClient that got kicked
  81. * @param cKickedByClient ChannelClient that did the kicking (may be null if server)
  82. * @param sReason Reason for kick (may be "")
  83. * @param sKickedByHost Hostname of Kicker (or servername)
  84. */
  85. protected boolean callChannelKick(ChannelInfo cChannel, ChannelClientInfo cKickedClient, ChannelClientInfo cKickedByClient, String sReason, String sKickedByHost) {
  86. CallbackOnChannelKick cb = (CallbackOnChannelKick)getCallbackManager().getCallbackType("OnChannelKick");
  87. if (cb != null) { return cb.call(cChannel, cKickedClient, cKickedByClient, sReason, sKickedByHost); }
  88. return false;
  89. }
  90. /**
  91. * What does this IRCProcessor handle.
  92. *
  93. * @return String[] with the names of the tokens we handle.
  94. */
  95. public String[] handles() {
  96. String[] iHandle = new String[1];
  97. iHandle[0] = "KICK";
  98. return iHandle;
  99. }
  100. /**
  101. * Create a new instance of the IRCProcessor Object
  102. *
  103. * @param parser IRCParser That owns this IRCProcessor
  104. * @param manager ProcessingManager that is in charge of this IRCProcessor
  105. */
  106. protected ProcessKick (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
  107. /**
  108. * Get SVN Version information.
  109. *
  110. * @return SVN Version String
  111. */
  112. public static String getSvnInfo () { return "$Id$"; }
  113. }