Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ProcessNickInUse.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 com.dmdirc.parser;
  25. import com.dmdirc.parser.callbacks.CallbackOnNickInUse;
  26. import com.dmdirc.parser.callbacks.interfaces.INickInUse;
  27. /**
  28. * Process a NickInUse message.
  29. * Parser implements handling of this if Pre-001 and no other handler found,
  30. * adding the NickInUse handler (addNickInUse) after 001 is prefered over before.<br><br>
  31. * <br>
  32. * If the first nickname is in use, and a NickInUse message is recieved before 001, we
  33. * will attempt to use the altnickname instead.<br>
  34. * If this also fails, we will start prepending _ (or the value of me.cPrepend) to the main nickname.
  35. */
  36. public class ProcessNickInUse extends IRCProcessor {
  37. /**
  38. * Process a NickInUse message.
  39. * Parser implements handling of this if Pre-001 and no other handler found,
  40. * adding the NickInUse handler (addNickInUse) after 001 is prefered over before.<br><br>
  41. * <br>
  42. * If the first nickname is in use, and a NickInUse message is recieved before 001, we
  43. * will attempt to use the altnickname instead.<br>
  44. * If this also fails, we will start prepending _ (or the value of me.cPrepend) to the main nickname.
  45. *
  46. * @param sParam Type of line to process ("433")
  47. * @param token IRCTokenised line to process
  48. */
  49. public void process(String sParam, String[] token) {
  50. if (!callNickInUse(token[3])) {
  51. // Manually handle nick in use.
  52. callDebugInfo(myParser.DEBUG_INFO,"No Nick in use Handler.");
  53. if (!myParser.got001) {
  54. callDebugInfo(myParser.DEBUG_INFO,"Using inbuilt handler");
  55. // If this is before 001 we will try and get a nickname, else we will leave the nick as-is
  56. if (!myParser.triedAlt) { myParser.setNickname(myParser.me.getAltNickname()); myParser.triedAlt = true; }
  57. else {
  58. if (myParser.sThinkNickname.equalsIgnoreCase(myParser.me.getAltNickname())) { myParser.sThinkNickname = myParser.me.getNickname(); }
  59. myParser.setNickname(myParser.me.getPrependChar()+myParser.sThinkNickname);
  60. }
  61. }
  62. }
  63. }
  64. /**
  65. * Callback to all objects implementing the NickInUse Callback.
  66. *
  67. * @param nickname Nickname that was wanted.
  68. * @see INickInUse
  69. */
  70. protected boolean callNickInUse(final String nickname) {
  71. CallbackOnNickInUse cb = (CallbackOnNickInUse)getCallbackManager().getCallbackType("OnNickInUse");
  72. if (cb != null) { return cb.call(nickname); }
  73. return false;
  74. }
  75. /**
  76. * What does this IRCProcessor handle.
  77. *
  78. * @return String[] with the names of the tokens we handle.
  79. */
  80. public String[] handles() {
  81. String[] iHandle = new String[1];
  82. iHandle[0] = "433";
  83. return iHandle;
  84. }
  85. /**
  86. * Create a new instance of the IRCProcessor Object
  87. *
  88. * @param parser IRCParser That owns this IRCProcessor
  89. * @param manager ProcessingManager that is in charge of this IRCProcessor
  90. */
  91. protected ProcessNickInUse (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
  92. /**
  93. * Get SVN Version information.
  94. *
  95. * @return SVN Version String
  96. */
  97. public static String getSvnInfo () { return "$Id$"; }
  98. }