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.

ProcessWallops.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (c) 2006-2015 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.WallDesyncEvent;
  24. import com.dmdirc.parser.events.WallopEvent;
  25. import com.dmdirc.parser.events.WalluserEvent;
  26. import com.dmdirc.parser.interfaces.callbacks.WallDesyncListener;
  27. import com.dmdirc.parser.interfaces.callbacks.WallopListener;
  28. import com.dmdirc.parser.interfaces.callbacks.WalluserListener;
  29. import com.dmdirc.parser.irc.IRCParser;
  30. import com.dmdirc.parser.irc.ProcessingManager;
  31. import java.util.Date;
  32. /**
  33. * Process a WALLOPS Message.
  34. */
  35. public class ProcessWallops extends IRCProcessor {
  36. /**
  37. * Create a new instance of the IRCProcessor Object.
  38. *
  39. * @param parser IRCParser That owns this IRCProcessor
  40. * @param manager ProcessingManager that is in charge of this IRCProcessor
  41. */
  42. public ProcessWallops(final IRCParser parser, final ProcessingManager manager) {
  43. super(parser, manager, "WALLOPS");
  44. }
  45. /**
  46. * Process a Wallops Message.
  47. *
  48. * @param sParam Type of line to process ("WALLOPS")
  49. * @param token IRCTokenised line to process
  50. */
  51. @Override
  52. public void process(final String sParam, final String... token) {
  53. if (token.length < 3) {
  54. return;
  55. }
  56. String user = token[0];
  57. final String message = token[token.length - 1];
  58. if (user.charAt(0) == ':' && user.length() > 1) {
  59. user = user.substring(1);
  60. }
  61. final String[] bits = message.split(" ", 2);
  62. if (bits.length > 1) {
  63. if (message.charAt(0) == '*') {
  64. callWallop(bits[1], user);
  65. return;
  66. } else if (message.charAt(0) == '$') {
  67. callWalluser(bits[1], user);
  68. return;
  69. }
  70. }
  71. callWallDesync(message, user);
  72. }
  73. /**
  74. * Callback to all objects implementing the Wallop Callback.
  75. *
  76. * @see WallopListener
  77. * @param message The message
  78. * @param host Host of the user who sent the wallop
  79. */
  80. protected void callWallop(final String message, final String host) {
  81. getCallbackManager().publish(new WallopEvent(parser, new Date(), message, host));
  82. }
  83. /**
  84. * Callback to all objects implementing the Walluser Callback.
  85. *
  86. * @see WalluserListener
  87. * @param message The message
  88. * @param host Host of the user who sent the walluser
  89. */
  90. protected void callWalluser(final String message, final String host) {
  91. getCallbackManager().publish(new WalluserEvent(parser, new Date(), message, host));
  92. }
  93. /**
  94. * Callback to all objects implementing the WallDesync Callback.
  95. *
  96. * @see WallDesyncListener
  97. * @param message The message
  98. * @param host Host of the user who sent the WallDesync
  99. */
  100. protected void callWallDesync(final String message, final String host) {
  101. getCallbackManager().publish(new WallDesyncEvent(parser, new Date(), message, host));
  102. }
  103. }