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.

ProcessNickInUse.java 3.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.CallbackOnNickInUse;
  26. import uk.org.ownage.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()) {
  51. // Manually handle nick in use.
  52. callDebugInfo(myParser.ndInfo,"No Nick in use Handler.");
  53. if (!myParser.Got001) {
  54. callDebugInfo(myParser.ndInfo,"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.sAltNickname); myParser.TriedAlt = true; }
  57. else {
  58. if (myParser.sThinkNickname.equalsIgnoreCase(myParser.me.sAltNickname)) { myParser.sThinkNickname = myParser.me.sNickname; }
  59. myParser.setNickname(myParser.me.cPrepend+myParser.sThinkNickname);
  60. }
  61. }
  62. }
  63. }
  64. /**
  65. * Callback to all objects implementing the NickInUse Callback.
  66. *
  67. * @see INickInUse
  68. */
  69. protected boolean callNickInUse() {
  70. CallbackOnNickInUse cb = (CallbackOnNickInUse)getCallbackManager().getCallbackType("OnNickInUse");
  71. if (cb != null) { return cb.call(); }
  72. return false;
  73. }
  74. /**
  75. * What does this IRCProcessor handle.
  76. *
  77. * @return String[] with the names of the tokens we handle.
  78. */
  79. public String[] handles() {
  80. String[] iHandle = new String[1];
  81. iHandle[0] = "433";
  82. return iHandle;
  83. }
  84. /**
  85. * Create a new instance of the IRCProcessor Object
  86. *
  87. * @param parser IRCParser That owns this IRCProcessor
  88. * @param manager ProcessingManager that is in charge of this IRCProcessor
  89. */
  90. protected ProcessNickInUse (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
  91. }