1 29 38 39 package org.planetamessenger.protocols.comvc; 40 41 42 43 class JComVcContactItem { 44 45 protected long nUserId; 46 protected String strIPAddress; 47 protected int nTCPPort; 48 protected int nUDPPort; 49 protected long nClientVersion; 50 protected long nTicket; 51 protected int nUserStatus; 52 53 54 JComVcContactItem() { 55 59 60 nUserId = 0; 61 strIPAddress = ""; 62 nTCPPort = 0; 63 nUDPPort = 0; 64 nClientVersion = 0; 65 nTicket = 0; 66 nUserStatus = JComVcConstants.STATUS_OFFLINE; 67 } 68 69 public boolean equals( Object obj ) { 70 79 80 JComVcContactItem item = ( JComVcContactItem ) obj; 81 82 return item.nUserId == nUserId; 83 } 84 85 static JComVcContactItem parseItem( java.lang.String strContactList ) { 86 96 97 String strTmp; 98 int nBeginIndex = strContactList.indexOf( "\r\n" ); 99 100 101 if( nBeginIndex < 0 ) 102 return null; 103 104 strTmp = strContactList.substring( 0, nBeginIndex ); 106 System.err.println( strTmp ); 107 108 JComVcContactItem contactItem = new JComVcContactItem(); 110 int nEndIndex = strTmp.indexOf( '|' ); 111 int nUserStatus; 112 113 if( nEndIndex < 0 ) 115 return null; 116 contactItem.nUserId = Long.parseLong( strTmp.substring( 0, nEndIndex ) ); 117 118 nBeginIndex = nEndIndex + 1; 120 if( ( nEndIndex = strTmp.indexOf( '|', nBeginIndex ) ) < 0 ) 121 return null; 122 contactItem.nTicket = Long.parseLong( strTmp.substring( nBeginIndex, nEndIndex ) ); 123 124 nBeginIndex = nEndIndex + 1; 126 if( ( nEndIndex = strTmp.indexOf( '|', nBeginIndex ) ) < 0 ) 127 return null; 128 contactItem.strIPAddress = strTmp.substring( nBeginIndex, nEndIndex ); 129 130 nBeginIndex = nEndIndex + 1; 132 if( ( nEndIndex = strTmp.indexOf( '|', nBeginIndex ) ) < 0 ) 133 return null; 134 contactItem.nTCPPort = Integer.parseInt( strTmp.substring( nBeginIndex, nEndIndex ) ); 135 136 nBeginIndex = nEndIndex + 1; 138 if( ( nEndIndex = strTmp.indexOf( '|', nBeginIndex ) ) < 0 ) 139 return null; 140 contactItem.nUDPPort = Integer.parseInt( strTmp.substring( nBeginIndex, nEndIndex ) ); 141 142 nBeginIndex = nEndIndex + 1; 144 if( ( nEndIndex = strTmp.indexOf( '|', nBeginIndex ) ) < 0 ) 145 return null; 146 147 nUserStatus = Integer.parseInt( strTmp.substring( nBeginIndex, nEndIndex ) ); 148 contactItem.nUserStatus = ( ( nUserStatus == JComVcConstants.STATUS_BUDDY_INVISIBLE ) ? JComVcConstants.STATUS_INVISIBLE : nUserStatus ); 149 150 nBeginIndex = nEndIndex + 1; 152 contactItem.nClientVersion = Long.parseLong( strTmp.substring( nBeginIndex ) ); 153 154 System.err.println( "JComVcContactItem.parseContactList() - UserId :" + contactItem.nUserId ); 155 System.err.println( "JComVcContactItem.parseContactList() - IP Address :" + contactItem.strIPAddress ); 156 System.err.println( "JComVcContactItem.parseContactList() - TCPPort :" + contactItem.nTCPPort ); 157 System.err.println( "JComVcContactItem.parseContactList() - UDPPort :" + contactItem.nUDPPort ); 158 System.err.println( "JComVcContactItem.parseContactList() - User Status :" + contactItem.nUserStatus ); 159 System.err.println( "JComVcContactItem.parseContactList() - Ticket :" + contactItem.nTicket ); 160 System.err.println( "JComVcContactItem.parseContactList() - Client Version :" + contactItem.nClientVersion ); 161 162 return contactItem; 163 } 164 165 static java.util.HashMap <Long , JComVcContactItem> parseList( java.lang.String strContactList ) { 166 176 177 java.util.HashMap <Long , JComVcContactItem> hContactList = new java.util.HashMap <Long , JComVcContactItem>(); 178 JComVcContactItem contactItem; 179 180 181 182 while( ( contactItem = JComVcContactItem.parseItem( strContactList ) ) != null ) { 183 184 Long userId = new Long ( contactItem.nUserId ); 185 186 hContactList.put( userId, contactItem ); 188 189 strContactList = strContactList.substring( strContactList.indexOf( "\r\n" ) + 2 ); System.err.println( "Contact List " + strContactList ); 192 } 193 194 return hContactList; 195 } 196 } 197 198 | Popular Tags |