File Source: ProcessJoin.java

         /* 
    P/P   *  Method: com.dmdirc.parser.irc.ProcessJoin__static_init
          */
     1  /*
     2   * Copyright (c) 2006-2009 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  
    23  package com.dmdirc.parser.irc;
    24  
    25  /**
    26   * Process a channel join.
    27   */
    28  public class ProcessJoin extends IRCProcessor {
    29  
    30  	/**
    31  	 * Process a channel join.
    32  	 *
    33  	 * @param sParam Type of line to process ("JOIN")
    34  	 * @param token IRCTokenised line to process
    35  	 */
    36  	@Override
    37  	public void process(final String sParam, final String[] token) {
        		 /* 
    P/P 		  *  Method: void process(String, String[])
        		  * 
        		  *  Preconditions:
        		  *    sParam != null
        		  *    token != null
        		  *    token.length <= 232
        		  *    (soft) init'ed(this.myParser.stringConverter)
        		  *    (soft) this.myParser != null
        		  *    (soft) init'ed(this.myParser...lastLine)
        		  *    (soft) this.myParser...myCallbackManager != null
        		  *    (soft) this.myParser...myCallbackManager.callbackHash != null
        		  *    (soft) this.myParser.cMyself != null
        		  *    (soft) init'ed(this.myParser.currentSocketState)
        		  *    ...
        		  * 
        		  *  Presumptions:
        		  *    iChannel.hChannelUserList@55 != null
        		  *    iChannel.myParser@55 != null
        		  *    iChannel.sName@55 != null
        		  *    iClient.myChannelClientInfos@54 != null
        		  *    iClient.myParser@54 != null
        		  *    ...
        		  * 
        		  *  Postconditions:
        		  *    init'ed(java.lang.String:substring(...)._tainted)
        		  *    possibly_updated(this.myParser.cMyself.myAwayReason)
        		  *    init'ed(this.myParser.stringConverter)
        		  *    new IRCStringConverter(getIRCStringConverter#1) num objects <= 1
        		  *    new IRCStringConverter(getIRCStringConverter#1) num objects == 0
        		  *    init'ed(new IRCStringConverter(getIRCStringConverter#1).limit)
        		  *    possibly_updated(new IRCStringConverter(getIRCStringConverter#1).limit)
        		  *    init'ed(new IRCStringConverter(getIRCStringConverter#1).lowercase)
        		  *    possibly_updated(new IRCStringConverter(getIRCStringConverter#1).lowercase)
        		  *    init'ed(new IRCStringConverter(getIRCStringConverter#1).uppercase)
        		  *    ...
        		  * 
        		  *  Test Vectors:
        		  *    token.length: {5..232}, {0..2}
        		  *    java.lang.String:equals(...)@38: {0}, {1}
        		  *    java.lang.String:isEmpty(...)@62: {0}, {1}
        		  */
    38  		if (sParam.equals("329")) {
    39  			if (token.length < 5) { return; }
    40  			ChannelInfo iChannel = myParser.getChannelInfo(token[3]);
    41  			if (iChannel != null) {
    42  				try {
    43  					iChannel.setCreateTime(Integer.parseInt(token[4]));
    44  				} catch (NumberFormatException nfe) { /* Oh well, not a normal ircd I guess */ }
    45  			}
    46  		} else {
    47  			// :nick!ident@host JOIN (:)#Channel
    48  			Byte nTemp;
    49  			if (token.length < 3) { return; }
    50  			ClientInfo iClient;
    51  			ChannelInfo iChannel;
    52  			ChannelClientInfo iChannelClient;
    53  			
    54  			iClient = myParser.getClientInfo(token[0]);
    55  			iChannel = myParser.getChannelInfo(token[token.length-1]);
    56  			
    57  			if (iClient == null) { 
    58  				iClient = new ClientInfo(myParser, token[0]);
    59  				myParser.addClient(iClient);
    60  			}
    61  			// Check to see if we know the host/ident for this client to facilitate dmdirc Formatter
    62  			if (iClient.getHost().isEmpty()) { iClient.setUserBits(token[0],false); }
    63  			if (iChannel != null) {
    64  				if (iClient == myParser.getMyself()) {
    65  					try {
    66  						if (iChannel.getUser(iClient) != null) {
    67  							// If we are joining a channel we are already on, fake a part from
    68  							// the channel internally, and rejoin.
    69  							myParser.getProcessingManager().process("PART", token);
    70  						} else {
    71  							// Otherwise we have a channel known, that we are not in?
    72  							myParser.callErrorInfo(new ParserError(ParserError.ERROR_FATAL, "Joined known channel that we wern't already on..", myParser.getLastLine()));
    73  						}
    74  					} catch (ProcessorNotFoundException e) { }
    75  				} else if (iChannel.getUser(iClient) != null) {
    76  					// Client joined channel that we already know of.
    77  					return;
    78  				} else {
    79  					// This is only done if we are already the channel, and it isn't us that
    80  					// joined.
    81  					iChannelClient = iChannel.addClient(iClient);
    82  					callChannelJoin(iChannel, iChannelClient);
    83  					return;
    84  				}
    85  			}
    86  			//if (iClient != myParser.getMyself()) {
    87  				// callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got join for channel ("+token[token.length-1]+") that I am not on. [Me: "+myParser.getMyself()+"]", myParser.getLastLine()));
    88  			//}
    89  			iChannel = new ChannelInfo(myParser, token[token.length-1]);
    90  			// Add ourself to the channel, this will be overridden by the NAMES reply
    91  			iChannel.addClient(iClient);
    92  			myParser.addChannel(iChannel);
    93  			sendString("MODE "+iChannel.getName());
    94  			
    95  			callChannelSelfJoin(iChannel);
    96  		}
    97  	}
    98  	
    99  
   100  	/**
   101  	 * Callback to all objects implementing the ChannelJoin Callback.
   102  	 *
   103  	 * @see IChannelJoin
   104  	 * @param cChannel Channel Object
   105  	 * @param cChannelClient ChannelClient object for new person
   106  	 * @return true if a method was called, false otherwise
   107  	 */
   108  	protected boolean callChannelJoin(final ChannelInfo cChannel, final ChannelClientInfo cChannelClient) {
        		 /* 
    P/P 		  *  Method: bool callChannelJoin(ChannelInfo, ChannelClientInfo)
        		  * 
        		  *  Preconditions:
        		  *    this.myParser != null
        		  *    this.myParser.myCallbackManager != null
        		  *    this.myParser.myCallbackManager.callbackHash != null
        		  * 
        		  *  Presumptions:
        		  *    getCallbackManager(...)@109 init'ed
        		  * 
        		  *  Postconditions:
        		  *    init'ed(return_value)
        		  */
   109  		return getCallbackManager().getCallbackType("OnChannelJoin").call(cChannel, cChannelClient);
   110  	}
   111  	
   112  	/**
   113  	 * Callback to all objects implementing the ChannelSelfJoin Callback.
   114  	 *
   115  	 * @see IChannelSelfJoin
   116  	 * @param cChannel Channel Object
   117  	 * @return true if a method was called, false otherwise
   118  	 */
   119  	protected boolean callChannelSelfJoin(final ChannelInfo cChannel) {
        		 /* 
    P/P 		  *  Method: bool callChannelSelfJoin(ChannelInfo)
        		  * 
        		  *  Preconditions:
        		  *    this.myParser != null
        		  *    this.myParser.myCallbackManager != null
        		  *    this.myParser.myCallbackManager.callbackHash != null
        		  * 
        		  *  Presumptions:
        		  *    getCallbackManager(...)@120 init'ed
        		  * 
        		  *  Postconditions:
        		  *    init'ed(return_value)
        		  */
   120  		return  getCallbackManager().getCallbackType("OnChannelSelfJoin").call(cChannel);
   121  	}
   122  	
   123  	/**
   124  	 * What does this IRCProcessor handle.
   125  	 *
   126  	 * @return String[] with the names of the tokens we handle.
   127  	 */
   128  	@Override
   129  	public String[] handles() {
        		 /* 
    P/P 		  *  Method: String[] handles()
        		  * 
        		  *  Postconditions:
        		  *    return_value == &amp;new String[](handles#1)
        		  *    new String[](handles#1) num objects == 1
        		  *    return_value.length == 2
        		  *    return_value[0] == &amp;"JOIN"
        		  *    return_value[1] == &amp;"329"
        		  */
   130  		return new String[]{"JOIN", "329"};
   131  	} 
   132  	
   133  	/**
   134  	 * Create a new instance of the IRCProcessor Object.
   135  	 *
   136  	 * @param parser IRCParser That owns this IRCProcessor
   137  	 * @param manager ProcessingManager that is in charge of this IRCProcessor
   138  	 */
        	 /* 
    P/P 	  *  Method: void com.dmdirc.parser.irc.ProcessJoin(IRCParser, ProcessingManager)
        	  * 
        	  *  Postconditions:
        	  *    this.myManager == manager
        	  *    init'ed(this.myManager)
        	  *    this.myParser == parser
        	  *    init'ed(this.myParser)
        	  */
   139  	protected ProcessJoin (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
   140  
   141  }








SofCheck Inspector Build Version : 2.17854
ProcessJoin.java 2009-Jun-25 01:54:24
ProcessJoin.class 2009-Sep-02 17:04:16