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.

ProcessJoin.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.CallbackOnChannelJoin;
  26. import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnChannelSelfJoin;
  27. import uk.org.ownage.dmdirc.parser.callbacks.interfaces.IChannelJoin;
  28. import uk.org.ownage.dmdirc.parser.callbacks.interfaces.IChannelSelfJoin;
  29. import java.util.Enumeration;
  30. /**
  31. * Process a channel join.
  32. */
  33. public class ProcessJoin extends IRCProcessor {
  34. /**
  35. * Process a channel join.
  36. *
  37. * @param sParam Type of line to process ("JOIN")
  38. * @param token IRCTokenised line to process
  39. */
  40. public void process(String sParam, String[] token) {
  41. // :nick!ident@host JOIN (:)#Channel
  42. Character cTemp;
  43. Byte nTemp;
  44. if (token.length < 3) { return; }
  45. ClientInfo iClient;
  46. ChannelInfo iChannel;
  47. ChannelClientInfo iChannelClient;
  48. iClient = myParser.getClientInfo(token[0]);
  49. iChannel = myParser.getChannelInfo(token[token.length-1]);
  50. if (iClient == null) {
  51. iClient = new ClientInfo(myParser, token[0]);
  52. myParser.hClientList.put(iClient.getNickname().toLowerCase(),iClient);
  53. }
  54. // Check to see if we know the host/ident for this client to facilitate dmdirc Formatter
  55. if (iClient.getHost().equals("")) { iClient.setUserBits(token[0],false); }
  56. if (iChannel == null) {
  57. if (iClient != myParser.cMyself) {
  58. callErrorInfo(new ParserError(ParserError.errWarning, "Got join for channel ("+token[token.length-1]+") that I am not on. [User: "+token[0]+"]"));
  59. }
  60. iChannel = new ChannelInfo(myParser, token[token.length-1]);
  61. myParser.hChannelList.put(iChannel.getName().toLowerCase(),iChannel);
  62. sendString("MODE "+iChannel.getName());
  63. // Find out the lists currently in use
  64. for (Enumeration e = myParser.hChanModesOther.keys(); e.hasMoreElements();) {
  65. cTemp = (Character)e.nextElement();
  66. nTemp = myParser.hChanModesOther.get(cTemp);
  67. if (nTemp == myParser.cmList) { sendString("MODE "+iChannel.getName()+" "+cTemp); }
  68. }
  69. callChannelSelfJoin(iChannel);
  70. } else {
  71. // This is only done if we are on the channel. Else we wait for names.
  72. iChannelClient = iChannel.addClient(iClient);
  73. callChannelJoin(iChannel, iChannelClient);
  74. }
  75. }
  76. /**
  77. * Callback to all objects implementing the ChannelJoin Callback.
  78. *
  79. * @see IChannelJoin
  80. * @param cChannel Channel Object
  81. * @param cChannelClient ChannelClient object for new person
  82. */
  83. protected boolean callChannelJoin(ChannelInfo cChannel, ChannelClientInfo cChannelClient) {
  84. CallbackOnChannelJoin cb = (CallbackOnChannelJoin)getCallbackManager().getCallbackType("OnChannelJoin");
  85. if (cb != null) { return cb.call(cChannel, cChannelClient); }
  86. return false;
  87. }
  88. /**
  89. * Callback to all objects implementing the ChannelSelfJoin Callback.
  90. *
  91. * @see IChannelSelfJoin
  92. * @param cChannel Channel Object
  93. */
  94. protected boolean callChannelSelfJoin(ChannelInfo cChannel) {
  95. CallbackOnChannelSelfJoin cb = (CallbackOnChannelSelfJoin)getCallbackManager().getCallbackType("OnChannelSelfJoin");
  96. if (cb != null) { return cb.call(cChannel); }
  97. return false;
  98. }
  99. /**
  100. * What does this IRCProcessor handle.
  101. *
  102. * @return String[] with the names of the tokens we handle.
  103. */
  104. public String[] handles() {
  105. String[] iHandle = new String[1];
  106. iHandle[0] = "JOIN";
  107. return iHandle;
  108. }
  109. /**
  110. * Create a new instance of the IRCProcessor Object
  111. *
  112. * @param parser IRCParser That owns this IRCProcessor
  113. * @param manager ProcessingManager that is in charge of this IRCProcessor
  114. */
  115. protected ProcessJoin (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
  116. /**
  117. * Get SVN Version information.
  118. *
  119. * @return SVN Version String
  120. */
  121. public static String getSvnInfo () { return "$Id$"; }
  122. }