1 29 38 39 package org.planetamessenger.protocols.comvc; 40 import java.lang.*; 41 42 43 44 public class JComVcSession { 45 46 protected JClientEngine clientEngine; 47 48 49 50 private void selfTest( int nTestType, int nUserId, java.lang.String strUserName, java.lang.String strPasswd, long nUserIds[] ) { 51 60 61 JUserDetails userDetails = new JUserDetails(); 62 63 64 userDetails.setName( strUserName ); 65 userDetails.setNick( strUserName ); 66 userDetails.setPassword( strPasswd ); 67 userDetails.setUserId( nUserId ); 68 69 setUser( userDetails ); 70 71 switch( nTestType ) { 72 73 case JComVcConstants.COMVC_CREATE_USER : { 74 if( !createNewUser() ) 75 System.out.println( "Create user error" ); 76 else 77 System.out.println( "User " + strUserName + " was created. The User Id is " + clientEngine.userDetails.getUserId() ); 78 } break; 79 80 case JComVcConstants.COMVC_BUDDY_LIST : { 81 for( int nCount = 0; nCount < java.lang.reflect.Array.getLength( nUserIds ); nCount++ ) 82 addToContactList( nUserIds[nCount], true ); 83 } 84 85 case JComVcConstants.COMVC_USER_LOGIN : { 86 if( !login( JComVcConstants.STATUS_ONLINE ) ) 87 System.out.println( "User login error" ); 88 else 89 System.out.println( "User " + strUserName + " logged in" ); 90 } break; 91 } 92 93 94 if( ( ( nTestType == JComVcConstants.COMVC_BUDDY_LIST ) || ( nTestType == JComVcConstants.COMVC_USER_LOGIN ) ) && ( getStatus() != JComVcConstants.STATUS_OFFLINE ) ) { 95 int nCommand = 0; 96 97 while( nCommand != 'e' ) { 98 System.out.print( "Command : " ); 99 100 try { 101 nCommand = System.in.read(); 102 } catch( java.io.IOException e ) { 103 System.err.println( e ); 104 } 105 106 switch( nCommand ) { 107 108 case 'm' : { 109 112 121 124 sendMessage( 1322237, "Eae manow recebeu ???" ); 126 127 } 129 } 130 } 131 132 } 133 134 clientEngine.logout(); 135 } 136 137 public JComVcSession() { 138 142 143 clientEngine = new JClientEngine(); 144 } 145 146 void addComVcEventListener( JComVcEventListener listener ) { 147 155 156 clientEngine.addComVcEventListener( listener ); 157 } 158 159 public boolean createNewUser() { 160 166 167 return clientEngine.createNewUser(); 168 } 169 170 public boolean changePassword( java.lang.String strOldPasswd, java.lang.String strNewPasswd ) { 171 177 178 return clientEngine.changePassword( strOldPasswd, strNewPasswd ); 179 } 180 181 public JBuddyDetails getBuddyDetails( long nUserId ) { 182 188 189 return clientEngine.getBuddyDetails( nUserId ); 190 } 191 192 public boolean login( int nInitialStatus ) { 193 200 201 return clientEngine.login( nInitialStatus ); 202 } 203 204 public boolean logout() { 205 208 209 return clientEngine.logout(); 210 } 211 212 public void setUser( JUserDetails userDetails ) { 213 220 221 clientEngine.setUser( userDetails ); 222 } 223 224 public JUserDetails getUser() { 225 229 230 return clientEngine.getUser(); 231 } 232 233 public boolean setStatus( int nStatus ) { 234 240 241 return clientEngine.setStatus( nStatus ); 242 } 243 244 public int getStatus() { 245 249 250 return clientEngine.getStatus(); 251 } 252 253 public boolean addToContactList( long nUserId, boolean bRequestAuth ) { 254 263 264 return clientEngine.addToContactList( nUserId, bRequestAuth ); 265 } 266 267 boolean removeFromContactList( long nUserId ) { 268 275 276 return clientEngine.removeFromContactList( nUserId ); 277 } 278 279 public void clearContactList() { 280 283 284 clientEngine.clearContactList(); 285 } 286 287 public boolean authorizeUser( long nUserId ) { 288 295 296 return clientEngine.authorizeUser( nUserId ); 297 } 298 299 boolean sendMessage( long nUserId, java.lang.String strMsg ) { 300 308 309 return clientEngine.sendMessage( nUserId, strMsg ); 310 } 311 312 public static void main( String [] args ) { 313 321 322 JComVcSession comVcSession = new JComVcSession(); 323 long aUserIds[] = null; 324 325 326 if( args.length < 4 ) { 327 System.out.println( "Number of parameters invalid" ); 328 System.out.println( "Usage: JComVcSession TypeOfTest UserId UserName Password ...list of buddies...." ); 329 return; 330 } 331 332 if( args.length > 4 ) { 333 aUserIds = new long[args.length - 4]; 334 335 for( int nCount = 0; nCount < ( args.length - 4 ); nCount++ ) 336 aUserIds[nCount] = Long.parseLong( args[nCount+4] ); 337 } 338 339 comVcSession.selfTest( Integer.parseInt( args[0] ), Integer.parseInt( args[1] ), args[2], args[3], aUserIds ); 340 } 341 } 342 343 | Popular Tags |