File Source: ProcessNickInUse.java

         /* 
    P/P   *  Method: com.dmdirc.parser.irc.ProcessNickInUse__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 NickInUse message.
    27   * Parser implements handling of this if Pre-001 and no other handler found,
    28   * adding the NickInUse handler (addNickInUse) after 001 is prefered over before.<br><br>
    29   * <br>
    30   * If the first nickname is in use, and a NickInUse message is recieved before 001, we
    31   * will attempt to use the altnickname instead.<br>
    32   * If this also fails, we will start prepending _ (or the value of me.cPrepend) to the main nickname.
    33   */
    34  public class ProcessNickInUse extends IRCProcessor {
    35  	/**
    36  	 * Process a NickInUse message.
    37  	 * Parser implements handling of this if Pre-001 and no other handler found,
    38  	 * adding the NickInUse handler (addNickInUse) after 001 is prefered over before.<br><br>
    39  	 * <br>
    40  	 * If the first nickname is in use, and a NickInUse message is recieved before 001, we
    41  	 * will attempt to use the altnickname instead.<br>
    42  	 * If this also fails, we will start prepending _ (or the value of me.cPrepend) to the main nickname.
    43  	 *
    44  	 * @param sParam Type of line to process ("433")
    45  	 * @param token IRCTokenised line to process
    46  	 */
    47  	@Override
    48  	public void process(final String sParam, final String[] token) {
        		 /* 
    P/P 		  *  Method: void process(String, String[])
        		  * 
        		  *  Preconditions:
        		  *    token != null
        		  *    token.length >= 4
        		  *    init'ed(token[3])
        		  *    (soft) init'ed(this.myParser.me.nickname)
        		  *    (soft) init'ed(this.myParser.sThinkNickname)
        		  *    (soft) init'ed(this.myParser.stringConverter)
        		  *    (soft) init'ed(this.myParser.triedAlt)
        		  *    (soft) this.myParser != null
        		  *    (soft) this.myParser.cMyself != null
        		  *    (soft) init'ed(this.myParser.cMyself.bIsFake)
        		  *    ...
        		  * 
        		  *  Presumptions:
        		  *    getIRCStringConverter(...).lowercase != null
        		  *    getIRCStringConverter(...).lowercase.length >= 1
        		  * 
        		  *  Postconditions:
        		  *    init'ed(java.lang.String:substring(...)._tainted)
        		  *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
        		  *    possibly_updated(this.myParser.cMyself.myAwayReason)
        		  *    this.myParser.me.nickname == One-of{old this.myParser.me.nickname, &amp;java.lang.StringBuilder:toString(...), this.myParser.me.altNickname}
        		  *    init'ed(this.myParser.me.nickname)
        		  *    this.myParser.sThinkNickname == One-of{old this.myParser.sThinkNickname, old this.myParser.me.nickname, &amp;java.lang.StringBuilder:toString(...), this.myParser.me.altNickname}
        		  *    init'ed(this.myParser.sThinkNickname)
        		  *    init'ed(this.myParser.stringConverter)
        		  *    init'ed(this.myParser.triedAlt)
        		  *    new IRCStringConverter(getIRCStringConverter#1) num objects <= 1
        		  *    ...
        		  * 
        		  *  Test Vectors:
        		  *    this.myParser.triedAlt: {0}, {1}
        		  *    this.myParser.got001: {1}, {0}
        		  *    call(...)@76: {1}, {0}
        		  */
    49  		if (!callNickInUse(token[3])) {
    50  			// Manually handle nick in use.
    51  			callDebugInfo(IRCParser.DEBUG_INFO,"No Nick in use Handler.");
    52  			if (!myParser.got001) {
    53  				callDebugInfo(IRCParser.DEBUG_INFO,"Using inbuilt handler");
    54  				// If this is before 001 we will try and get a nickname, else we will leave the nick as-is
    55  				if (myParser.triedAlt) {
    56  					if (myParser.getIRCStringConverter().equalsIgnoreCase(myParser.sThinkNickname, myParser.me.getAltNickname())) {
    57  						myParser.sThinkNickname = myParser.me.getNickname();
    58  					}
    59  					myParser.setNickname(myParser.me.getPrependChar()+myParser.sThinkNickname);
    60  				} else {
    61  					myParser.setNickname(myParser.me.getAltNickname());
    62  					myParser.triedAlt = true; 
    63  				}
    64  			}
    65  		}
    66  	}
    67  	
    68  	/**
    69  	 * Callback to all objects implementing the NickInUse Callback.
    70  	 *
    71  	 * @param nickname Nickname that was wanted.
    72  	 * @see INickInUse
    73  	 * @return true if a method was called, false otherwise
    74  	 */
    75  	protected boolean callNickInUse(final String nickname) {
        		 /* 
    P/P 		  *  Method: bool callNickInUse(String)
        		  * 
        		  *  Preconditions:
        		  *    this.myParser != null
        		  *    this.myParser.myCallbackManager != null
        		  *    this.myParser.myCallbackManager.callbackHash != null
        		  * 
        		  *  Presumptions:
        		  *    getCallbackManager(...)@76 init'ed
        		  * 
        		  *  Postconditions:
        		  *    init'ed(return_value)
        		  */
    76  		return getCallbackManager().getCallbackType("OnNickInUse").call(nickname);
    77  	}
    78  	
    79  	/**
    80  	 * What does this IRCProcessor handle.
    81  	 *
    82  	 * @return String[] with the names of the tokens we handle.
    83  	 */
    84  	@Override
    85  	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;"433"
        		  */
    86  		return new String[]{"433"};
    87  	}
    88  	
    89  	/**
    90  	 * Create a new instance of the ProcessNickInUse Object.
    91  	 *
    92  	 * @param parser IRCParser That owns this object
    93  	 * @param manager ProcessingManager that is in charge of this object
    94  	 */
        	 /* 
    P/P 	  *  Method: void com.dmdirc.parser.irc.ProcessNickInUse(IRCParser, ProcessingManager)
        	  * 
        	  *  Postconditions:
        	  *    this.myManager == manager
        	  *    init'ed(this.myManager)
        	  *    this.myParser == parser
        	  *    init'ed(this.myParser)
        	  */
    95  	protected ProcessNickInUse (final IRCParser parser, final ProcessingManager manager) { super(parser, manager); }
    96  
    97  }








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