File Source: ProcessKick.java

         /* 
    P/P   *  Method: com.dmdirc.parser.irc.ProcessKick__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 kick.
    27   */
    28  public class ProcessKick extends IRCProcessor {
    29  
    30  	/**
    31  	 * Process a channel kick.
    32  	 *
    33  	 * @param sParam Type of line to process ("KICK")
    34  	 * @param token IRCTokenised line to process
    35  	 */
    36  	@Override
    37  	public void process(final String sParam, final String[] token) {
    38  		ChannelClientInfo iChannelClient;
    39  		ChannelClientInfo iChannelKicker;
    40  		ChannelInfo iChannel;
    41  		ClientInfo iClient;
    42  		ClientInfo iKicker;
        		 /* 
    P/P 		  *  Method: void process(String, String[])
        		  * 
        		  *  Preconditions:
        		  *    this.myParser.hClientList != null
        		  *    token != null
        		  *    token[2] != null
        		  *    token[3] != null
        		  *    (soft) init'ed(this.myParser.stringConverter)
        		  *    (soft) this.myParser != null
        		  *    (soft) init'ed(this.myParser.cMyself)
        		  *    (soft) this.myParser.hChannelList != null
        		  *    (soft) init'ed(this.myParser.lastLine)
        		  *    (soft) this.myParser.myCallbackManager != null
        		  *    ...
        		  * 
        		  *  Presumptions:
        		  *    iChannel.hChannelUserList != null
        		  *    iChannel.myParser != null
        		  *    iChannel.myParser.hClientList != null
        		  *    iChannel.myParser.stringConverter.lowercase@63 != null
        		  *    iChannel.myParser.stringConverter.lowercase@70 != null
        		  *    ...
        		  * 
        		  *  Postconditions:
        		  *    init'ed(this.myParser.stringConverter)
        		  *    new IRCStringConverter(getIRCStringConverter#1) num objects <= 1
        		  *    new char[](IRCStringConverter#1) num objects == new IRCStringConverter(getIRCStringConverter#1) num objects
        		  *    new char[](IRCStringConverter#2) num objects == new IRCStringConverter(getIRCStringConverter#1) num objects
        		  *    new IRCStringConverter(getIRCStringConverter#1) num objects == 0
        		  *    new char[](IRCStringConverter#1) num objects == 0
        		  *    new char[](IRCStringConverter#2) num objects == 0
        		  *    init'ed(new IRCStringConverter(getIRCStringConverter#1).limit)
        		  *    new IRCStringConverter(getIRCStringConverter#1).limit == 4
        		  *    not_init'ed(new IRCStringConverter(getIRCStringConverter#1).limit)
        		  *    ...
        		  * 
        		  *  Test Vectors:
        		  *    this.myParser.removeAfterCallback: {0}, {1}
        		  *    token.length: {4}, {5..232}
        		  *    java.lang.String:isEmpty(...)@53: {0}, {1}
        		  */
    43  		String sReason = "";
    44  		
    45  		iClient = getClientInfo(token[3]);
    46  		iKicker = getClientInfo(token[0]);
    47  		iChannel = getChannelInfo(token[2]);
    48  		
    49  		if (iClient == null) { return; }
    50  		
    51  		if (IRCParser.ALWAYS_UPDATECLIENT && iKicker != null) {
    52  			// To facilitate dmdirc formatter, get user information
    53  			if (iKicker.getHost().isEmpty()) { iKicker.setUserBits(token[0],false); }
    54  		}
    55  
    56  		if (iChannel == null) { 
    57  			if (iClient != myParser.getMyself()) {
    58  				callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got kick for channel ("+token[2]+") that I am not on. [User: "+token[3]+"]", myParser.getLastLine()));
    59  			}
    60  			return;
    61  		} else {
    62  			if (token.length > 4) { sReason = token[token.length-1]; }
    63  			iChannelClient = iChannel.getUser(iClient);
    64  			if (iChannelClient == null) {
    65  				// callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got kick for channel ("+token[2]+") for a non-existant user. [User: "+token[0]+"]", myParser.getLastLine()));
    66  				return;
    67  			}
    68  			iChannelKicker = iChannel.getUser(token[0]);
    69  			if (myParser.removeAfterCallback) { callChannelKick(iChannel,iChannelClient,iChannelKicker,sReason,token[0]); }
    70  			iChannel.delClient(iClient);
    71  			if (!myParser.removeAfterCallback) { callChannelKick(iChannel,iChannelClient,iChannelKicker,sReason,token[0]); }
    72  			if (iClient == myParser.getMyself()) {
    73  				iChannel.emptyChannel();
    74  				myParser.removeChannel(iChannel);
    75  			}
    76  		}
    77  	}
    78  	
    79  	/**
    80  	 * Callback to all objects implementing the ChannelKick Callback.
    81  	 *
    82  	 * @see IChannelKick
    83  	 * @param cChannel Channel where the kick took place
    84  	 * @param cKickedClient ChannelClient that got kicked
    85  	 * @param cKickedByClient ChannelClient that did the kicking (may be null if server)
    86  	 * @param sReason Reason for kick (may be "")
    87  	 * @param sKickedByHost Hostname of Kicker (or servername)
    88  	 * @return true if a method was called, false otherwise
    89  	 */
    90  	protected boolean callChannelKick(ChannelInfo cChannel, ChannelClientInfo cKickedClient, ChannelClientInfo cKickedByClient, String sReason, String sKickedByHost) {
        		 /* 
    P/P 		  *  Method: bool callChannelKick(ChannelInfo, ChannelClientInfo, ChannelClientInfo, String, String)
        		  * 
        		  *  Preconditions:
        		  *    this.myParser != null
        		  *    this.myParser.myCallbackManager != null
        		  *    this.myParser.myCallbackManager.callbackHash != null
        		  * 
        		  *  Presumptions:
        		  *    getCallbackManager(...)@91 init'ed
        		  * 
        		  *  Postconditions:
        		  *    init'ed(return_value)
        		  */
    91  		return getCallbackManager().getCallbackType("OnChannelKick").call(cChannel, cKickedClient, cKickedByClient, sReason, sKickedByHost);
    92  	}
    93  	
    94  	/**
    95  	 * What does this IRCProcessor handle.
    96  	 *
    97  	 * @return String[] with the names of the tokens we handle.
    98  	 */
    99  	@Override
   100  	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 == 1
        		  *    return_value[0] == &amp;"KICK"
        		  */
   101  		return new String[]{"KICK"};
   102  	} 
   103  	
   104  	/**
   105  	 * Create a new instance of the IRCProcessor Object.
   106  	 *
   107  	 * @param parser IRCParser That owns this IRCProcessor
   108  	 * @param manager ProcessingManager that is in charge of this IRCProcessor
   109  	 */
        	 /* 
    P/P 	  *  Method: void com.dmdirc.parser.irc.ProcessKick(IRCParser, ProcessingManager)
        	  * 
        	  *  Postconditions:
        	  *    this.myManager == manager
        	  *    init'ed(this.myManager)
        	  *    this.myParser == parser
        	  *    init'ed(this.myParser)
        	  */
   110  	protected ProcessKick (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
   111  
   112  }








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