123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- /*
- * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- * SVN: $Id$
- */
-
- package uk.org.ownage.dmdirc.parser;
-
- import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnChannelJoin;
- import uk.org.ownage.dmdirc.parser.callbacks.CallbackOnChannelSelfJoin;
- import uk.org.ownage.dmdirc.parser.callbacks.interfaces.IChannelJoin;
- import uk.org.ownage.dmdirc.parser.callbacks.interfaces.IChannelSelfJoin;
- import java.util.Enumeration;
-
- /**
- * Process a channel join.
- */
- public class ProcessJoin extends IRCProcessor {
- /**
- * Process a channel join.
- *
- * @param sParam Type of line to process ("JOIN")
- * @param token IRCTokenised line to process
- */
- public void process(String sParam, String[] token) {
- // :nick!ident@host JOIN (:)#Channel
- Character cTemp;
- Byte nTemp;
- if (token.length < 3) { return; }
- ClientInfo iClient;
- ChannelInfo iChannel;
- ChannelClientInfo iChannelClient;
-
- iClient = myParser.getClientInfo(token[0]);
- iChannel = myParser.getChannelInfo(token[token.length-1]);
-
- if (iClient == null) {
- iClient = new ClientInfo(myParser, token[0]);
- myParser.hClientList.put(iClient.getNickname().toLowerCase(),iClient);
- }
- // Check to see if we know the host/ident for this client to facilitate dmdirc Formatter
- if (iClient.getHost().equals("")) { iClient.setUserBits(token[0],false); }
- if (iChannel == null) {
- if (iClient != myParser.cMyself) {
- callErrorInfo(new ParserError(ParserError.errWarning, "Got join for channel ("+token[token.length-1]+") that I am not on. [User: "+token[0]+"]"));
- }
- iChannel = new ChannelInfo(myParser, token[token.length-1]);
- myParser.hChannelList.put(iChannel.getName().toLowerCase(),iChannel);
- sendString("MODE "+iChannel.getName());
-
- // Find out the lists currently in use
- for (Enumeration e = myParser.hChanModesOther.keys(); e.hasMoreElements();) {
- cTemp = (Character)e.nextElement();
- nTemp = myParser.hChanModesOther.get(cTemp);
- if (nTemp == myParser.cmList) { sendString("MODE "+iChannel.getName()+" "+cTemp); }
- }
- callChannelSelfJoin(iChannel);
- } else {
- // This is only done if we are on the channel. Else we wait for names.
- iChannelClient = iChannel.addClient(iClient);
- callChannelJoin(iChannel, iChannelClient);
- }
- }
-
- /**
- * Callback to all objects implementing the ChannelJoin Callback.
- *
- * @see IChannelJoin
- * @param cChannel Channel Object
- * @param cChannelClient ChannelClient object for new person
- */
- protected boolean callChannelJoin(ChannelInfo cChannel, ChannelClientInfo cChannelClient) {
- CallbackOnChannelJoin cb = (CallbackOnChannelJoin)getCallbackManager().getCallbackType("OnChannelJoin");
- if (cb != null) { return cb.call(cChannel, cChannelClient); }
- return false;
- }
-
- /**
- * Callback to all objects implementing the ChannelSelfJoin Callback.
- *
- * @see IChannelSelfJoin
- * @param cChannel Channel Object
- */
- protected boolean callChannelSelfJoin(ChannelInfo cChannel) {
- CallbackOnChannelSelfJoin cb = (CallbackOnChannelSelfJoin)getCallbackManager().getCallbackType("OnChannelSelfJoin");
- if (cb != null) { return cb.call(cChannel); }
- return false;
- }
-
- /**
- * What does this IRCProcessor handle.
- *
- * @return String[] with the names of the tokens we handle.
- */
- public String[] handles() {
- String[] iHandle = new String[1];
- iHandle[0] = "JOIN";
- return iHandle;
- }
-
- /**
- * Create a new instance of the IRCProcessor Object
- *
- * @param parser IRCParser That owns this IRCProcessor
- * @param manager ProcessingManager that is in charge of this IRCProcessor
- */
- protected ProcessJoin (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
-
- /**
- * Get SVN Version information.
- *
- * @return SVN Version String
- */
- public static String getSvnInfo () { return "$Id$"; }
- }
|