Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ProcessWallops.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (c) 2006-2008 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. * SVN: $Id: ProcessWallops.java 1970 2007-09-05 18:33:06Z chris87 $
  23. */
  24. package com.dmdirc.parser;
  25. import com.dmdirc.parser.callbacks.CallbackOnWallDesync;
  26. import com.dmdirc.parser.callbacks.CallbackOnWallop;
  27. import com.dmdirc.parser.callbacks.CallbackOnWalluser;
  28. /**
  29. * Process a WALLOPS Message.
  30. */
  31. public class ProcessWallops extends IRCProcessor {
  32. /**
  33. * Process a Wallops Message.
  34. *
  35. * @param sParam Type of line to process ("WALLOPS")
  36. * @param token IRCTokenised line to process
  37. */
  38. public void process(String sParam, String[] token) {
  39. if (token.length < 3) { return; }
  40. String user = token[0];
  41. String message = token[token.length-1];
  42. if (user.charAt(0) == ':' && user.length() > 1) { user = user.substring(1); }
  43. String[] bits = message.split(" ", 2);
  44. if (bits.length > 1) {
  45. if (message.charAt(0) == '*') {
  46. callWallop(bits[1], user);
  47. return;
  48. } else if (message.charAt(0) == '$') {
  49. callWalluser(bits[1], user);
  50. return;
  51. }
  52. }
  53. callWallDesync(message, user);
  54. }
  55. /**
  56. * Callback to all objects implementing the Wallop Callback.
  57. *
  58. * @see IWallop
  59. * @param host Host of the user who sent the wallop
  60. * @param message The message
  61. * @return true if a method was called, false otherwise
  62. */
  63. protected boolean callWallop(String message, String host) {
  64. CallbackOnWallop cb = (CallbackOnWallop)getCallbackManager().getCallbackType("OnWallop");
  65. if (cb != null) { return cb.call(message, host); }
  66. return false;
  67. }
  68. /**
  69. * Callback to all objects implementing the Walluser Callback.
  70. *
  71. * @see IWalluser
  72. * @param host Host of the user who sent the walluser
  73. * @param message The message
  74. * @return true if a method was called, false otherwise
  75. */
  76. protected boolean callWalluser(String message, String host) {
  77. CallbackOnWalluser cb = (CallbackOnWalluser)getCallbackManager().getCallbackType("OnWalluser");
  78. if (cb != null) { return cb.call(message, host); }
  79. return false;
  80. }
  81. /**
  82. * Callback to all objects implementing the WallDesync Callback.
  83. *
  84. * @see IWallDesync
  85. * @param host Host of the user who sent the WallDesync
  86. * @param message The message
  87. * @return true if a method was called, false otherwise
  88. */
  89. protected boolean callWallDesync(String message, String host) {
  90. CallbackOnWallDesync cb = (CallbackOnWallDesync)getCallbackManager().getCallbackType("OnWallDesync");
  91. if (cb != null) { return cb.call(message, host); }
  92. return false;
  93. }
  94. /**
  95. * What does this IRCProcessor handle.
  96. *
  97. * @return String[] with the names of the tokens we handle.
  98. */
  99. public String[] handles() {
  100. String[] iHandle = new String[]{"WALLOPS"};
  101. return iHandle;
  102. }
  103. /**
  104. * Create a new instance of the IRCProcessor Object.
  105. *
  106. * @param parser IRCParser That owns this IRCProcessor
  107. * @param manager ProcessingManager that is in charge of this IRCProcessor
  108. */
  109. protected ProcessWallops (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
  110. }