File Source: ProcessNames.java

         /* 
    P/P   *  Method: com.dmdirc.parser.irc.ProcessNames__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 Names reply.
    27   */
    28  public class ProcessNames extends IRCProcessor {
    29  	/**
    30  	 * Process a Names reply.
    31  	 *
    32  	 * @param sParam Type of line to process ("366", "353")
    33  	 * @param token IRCTokenised line to process
    34  	 */
    35  	@Override
    36  	public void process(String sParam, String[] token) {
    37  		ChannelInfo iChannel;
        		 /* 
    P/P 		  *  Method: void process(String, String[])
        		  * 
        		  *  Preconditions:
        		  *    init'ed(this.myParser.stringConverter)
        		  *    sParam != null
        		  *    this.myParser.hChannelList != null
        		  *    token != null
        		  *    (soft) this.myParser != null
        		  *    (soft) init'ed(this.myParser.autoListMode)
        		  *    (soft) this.myParser.myCallbackManager != null
        		  *    (soft) this.myParser.myCallbackManager.callbackHash != null
        		  *    (soft) this.myParser.stringConverter.lowercase != null
        		  *    (soft) init'ed(this.myParser.stringConverter.lowercase[...])
        		  *    ...
        		  * 
        		  *  Presumptions:
        		  *    iChannel.hChannelUserList != null
        		  *    iChannel.myParser != null
        		  *    iChannel.myParser.cMyself@44 != null
        		  *    iChannel.myParser.h005Info != null
        		  *    iChannel.myParser.hChanModesOther != null
        		  *    ...
        		  * 
        		  *  Postconditions:
        		  *    init'ed(this.myParser.stringConverter)
        		  *    init'ed(new IRCStringConverter(getIRCStringConverter#1) num objects)
        		  *    new IRCStringConverter(getIRCStringConverter#1) num objects <= 1
        		  *    init'ed(new IRCStringConverter(getIRCStringConverter#1).limit)
        		  *    init'ed(new IRCStringConverter(getIRCStringConverter#1).lowercase)
        		  *    init'ed(new IRCStringConverter(getIRCStringConverter#1).uppercase)
        		  *    init'ed(new char[](IRCStringConverter#1) num objects)
        		  *    new char[](IRCStringConverter#1) num objects <= 1
        		  *    init'ed(new char[](IRCStringConverter#1).length)
        		  *    init'ed(new char[](IRCStringConverter#1)[...])
        		  *    ...
        		  * 
        		  *  Test Vectors:
        		  *    this.myParser.autoListMode: {0}, {1}
        		  *    iChannel.askedForListModes@44: {1}, {0}
        		  *    iChannel.bAddingNames: {1}, {0}
        		  *    java.lang.String:equals(...)@38: {0}, {1}
        		  */
    38  		if (sParam.equals("366")) {
    39  			// End of names
    40  			iChannel = getChannelInfo(token[3]);
    41  			if (iChannel == null) { return; }
    42  			
    43  			iChannel.setAddingNames(false);
    44  			callChannelGotNames(iChannel);
    45  			
    46  			if (!iChannel.hasAskedForListModes()) {
    47  				if (myParser.getAutoListMode()) {
    48  					iChannel.requestListModes();
    49  				}
    50  			}
    51  		} else {
    52  			// Names
    53  			
    54  			ClientInfo iClient;
    55  			ChannelClientInfo iChannelClient;
    56  			
    57  			iChannel = getChannelInfo(token[4]);
    58  		
    59  			if (iChannel == null) { return; }
    60  			
    61  			// If we are not expecting names, clear the current known names - this is fresh stuff!
    62  			if (!iChannel.isAddingNames()) { iChannel.emptyChannel(); }
    63  			iChannel.setAddingNames(true);
    64  			
    65  			String[] sNames = token[token.length-1].split(" ");
    66  			String sNameBit = "", sName = "";
    67  			StringBuilder sModes = new StringBuilder();
    68  			long nPrefix = 0;
    69  			for (int j = 0; j < sNames.length; ++j) {
    70  				sNameBit = sNames[j];
    71  				// If name is empty (ie there was an extra space) ignore it.
    72  				if (sNameBit.isEmpty()) { continue; }
    73  				// This next bit of code allows for any ircd which decides to use @+Foo in names
    74  				for (int i = 0; i < sNameBit.length(); ++i) {
    75  					Character cMode = sNameBit.charAt(i);
    76  					// hPrefixMap contains @, o, +, v this caused issue 107
    77  					// hPrefixModes only contains o, v so if the mode is in hPrefixMap
    78  					// and not in hPrefixModes, its ok to use.
    79  					if (myParser.hPrefixMap.containsKey(cMode) && !myParser.hPrefixModes.containsKey(cMode)) {
    80  						sModes.append(cMode);
    81  						nPrefix = nPrefix + myParser.hPrefixModes.get(myParser.hPrefixMap.get(cMode));
    82  					} else {
    83  						sName = sNameBit.substring(i);
    84  						break;
    85  					}
    86  				}
    87  				callDebugInfo(IRCParser.DEBUG_INFO, "Name: %s Modes: \"%s\" [%d]",sName,sModes.toString(),nPrefix);
    88  				
    89  				iClient = getClientInfo(sName);
    90  				if (iClient == null) { iClient = new ClientInfo(myParser, sName); myParser.addClient(iClient); }
    91  				iChannelClient = iChannel.addClient(iClient);
    92  				iChannelClient.setChanMode(nPrefix);
    93  
    94  				sName = "";
    95  				sModes = new StringBuilder();
    96  				nPrefix = 0;
    97  			}
    98  		}
    99  	}
   100  	
   101  	/**
   102  	 * Callback to all objects implementing the ChannelGotNames Callback.
   103  	 *
   104  	 * @see IChannelGotNames
   105  	 * @param cChannel Channel which the names reply is for
   106  	 * @return true if a method was called, false otherwise
   107  	 */
   108  	protected boolean callChannelGotNames(ChannelInfo cChannel) {
        		 /* 
    P/P 		  *  Method: bool callChannelGotNames(ChannelInfo)
        		  * 
        		  *  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("OnChannelGotNames").call(cChannel);
   110  	}
   111  	
   112  	/**
   113  	 * What does this IRCProcessor handle.
   114  	 *
   115  	 * @return String[] with the names of the tokens we handle.
   116  	 */
   117  	@Override
   118  	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;"353"
        		  *    return_value[1] == &amp;"366"
        		  */
   119  		return new String[]{"353", "366"};
   120  	} 
   121  	
   122  	/**
   123  	 * Create a new instance of the IRCProcessor Object.
   124  	 *
   125  	 * @param parser IRCParser That owns this IRCProcessor
   126  	 * @param manager ProcessingManager that is in charge of this IRCProcessor
   127  	 */
        	 /* 
    P/P 	  *  Method: void com.dmdirc.parser.irc.ProcessNames(IRCParser, ProcessingManager)
        	  * 
        	  *  Postconditions:
        	  *    this.myManager == manager
        	  *    init'ed(this.myManager)
        	  *    this.myParser == parser
        	  *    init'ed(this.myParser)
        	  */
   128  	protected ProcessNames (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
   129  
   130  }








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