1 29 38 39 package org.planetamessenger.protocols.msn; 40 41 import org.hn.sleek.jmml.*; 42 import org.planetamessenger.plugin.*; 43 import java.util.*; 44 45 49 public class JMSNPlugin extends JPlugin implements MessengerClientListener, JMessengerEventListener { 50 51 MessengerServerManager session = null; 52 Hash hProfileNotification = null; 53 Hash hEmailNotification = null; 54 String strPasswd = null; 55 56 57 60 public JMSNPlugin() { 61 62 } 63 64 68 public void onCreate() { 69 70 super.onCreate(); 71 72 JPluginCapabilities capabilities = getPluginCapabilities(); 73 74 capabilities.putBool( JPluginCapabilities.CAPABILITY_OFFLINE_MESSAGE, true ); 76 capabilities.putBool( JPluginCapabilities.CAPABILITY_PRIVACY_CONTROL_ENABLED, true ); 77 capabilities.putBool( JPluginCapabilities.CAPABILITY_BLOCK_CONTACT, true ); 78 setPluginCapabilities( capabilities ); 79 80 session = MessengerServerManager.newInstance(); 81 session.addMessengerClientListener( this ); 82 addMessengerEventListener( this ); 83 84 addStatus( JPlugin.STATUS_ONLINE, ContactStatus.ONLINE ); 86 addStatus( JPlugin.STATUS_OFFLINE, ContactStatus.OFFLINE ); 87 addStatus( JPlugin.STATUS_INVISIBLE, ContactStatus.APPEAR_OFFLINE ); 88 addStatus( JPlugin.STATUS_BUSY, ContactStatus.BUSY ); 89 addStatus( JPlugin.STATUS_IDLE, ContactStatus.IDLE ); 90 addStatus( JPlugin.STATUS_DND, ContactStatus.BE_RIGHT_BACK ); 91 addStatus( JPlugin.STATUS_AWAY, ContactStatus.AWAY ); 92 addStatus( JPlugin.STATUS_ON_PHONE, ContactStatus.ON_THE_PHONE ); 93 addStatus( JPlugin.STATUS_ON_LUNCH, ContactStatus.OUT_TO_LUNCH ); 94 } 95 96 100 public void onLogin( int nPluginStatus ) { 101 102 try { 103 session.signIn( getUserId(), getPassword(), ( String ) translateStatusToPlugin( nPluginStatus ) ); 104 this.strPasswd = getPassword(); 105 } catch( MSNException e ) { 106 System.err.println( "JMSNPlugin.onLogin() - " + e ); 107 } 108 } 109 110 113 public void onLogout() { 114 115 try { 116 session.signOut(); 117 } catch( MSNException e ) { 118 System.err.println( "JMSNPlugin.onLogout() - " + e ); 119 } 120 } 121 122 126 public void onAddUserToContactList( java.lang.String strUserId ) { 127 128 if( session != null ) 129 try { 130 session.addToContactList( new Contact( strUserId, ContactList.FORWARD_LIST ) ); 131 } catch( MSNException e ) { 132 System.err.println( "JMSNPlugin.onAddUserToContactList() - " + e ); 133 } 134 } 135 136 141 public void onRemoveUserFromContactList( java.lang.String strUserId ) { 142 143 if( session != null ) { 144 try { 145 if( session.getContactList().getContact( strUserId ).isContact() ) { 146 Contact contact = new Contact( strUserId, ContactList.FORWARD_LIST ); 147 session.removeFromContactList( contact ); 148 } 149 } catch( MSNException e ) { 150 System.err.println( "JMSNPlugin.onRemoveUserFromContactList() - " + e ); 151 } 152 } 153 } 154 155 163 public void onSendMessage( java.lang.String strToUser, java.lang.String msg, int nMsgType ) { 164 165 try { 166 session.sendMessage( strToUser, msg ); 167 } catch( MSNException e ) { 168 System.err.println( "JMSNPlugin.onSendMessage() - " + e ); 169 } 170 } 171 172 180 public void onRequestAuthorization( java.lang.String strUserId, java.lang.String strNickName ) { 181 182 } 183 184 189 public void onBuddyDetails( java.lang.String strUserId ) { 190 191 } 192 193 197 public void onAuthorizeBuddy( java.lang.String strUserId ) { 198 199 onChangePrivacy( strUserId, PRIVACY_UNBLOCK_USER ); 200 } 201 202 206 public void onUnauthorizeBuddy( java.lang.String strUserId ) { 207 208 onChangePrivacy( strUserId, PRIVACY_BLOCK_USER ); 209 } 210 211 215 public void onPluginStatusChanged( int nStatus ) { 216 217 try { 218 session.setStatus( ( String ) translateStatusToPlugin( nStatus ) ); 219 } catch( MSNException e ) { 220 System.err.println( "JMSNPlugin.onPluginStatusChanged() - " + e ); 221 } 222 } 223 224 233 public void onRegisterExistingUser( String strNickName, String strNewUserId, String strPasswd ) { 234 235 JUserInfo userInfo = new JUserInfo( strNewUserId, strNickName, strPasswd, JPlugin.STATUS_ONLINE ); 236 237 setUserInfo( userInfo ); 238 fireOnLogin(); 239 } 240 241 250 public void onRegisterNewUser( java.lang.String strNickName, java.lang.StringBuffer strNewUserId, java.lang.String strPasswd ) { 251 252 fireOnRegisterUserFailed(); } 254 255 259 public void onUnregisterUser() { 260 261 if( isConnected() ) { 262 fireOnLogout(); 263 fireOnUnregisterUserSuccessfull(); 264 } 265 } 266 267 272 public void onChangePassword( java.lang.String strNewPasswd ) { 273 274 fireOnPasswordChangedSuccessfull( strNewPasswd ); 275 } 276 277 287 public void onChangePrivacy( java.lang.String strUserId, int nPrivacyType ) { 288 289 switch( nPrivacyType ) { 290 291 case PRIVACY_BLOCK_USER : { 292 try { 293 session.blockContact( strUserId ); 294 } catch( MSNException e ) { 295 System.err.println( "JMSNPlugin.onChangePrivacy() - " + e ); 296 } 297 } break; 298 299 case PRIVACY_UNBLOCK_USER : { 300 try { 301 session.allowContact( strUserId ); 302 } catch( MSNException e ) { 303 System.err.println( "JMSNPlugin.onChangePrivacy() - " + e ); 304 } 305 } 306 } 307 } 308 309 314 public void onPrivacyChanged() { 315 316 } 317 318 321 public void onPluginPropertiesUpdated() { 322 323 if( isConnected() ) { 324 try { 325 System.err.println( "JMSNPlugin.onPluginPropertiesUpdated() - MSN properties updated by user" ); 326 327 session.setFriendlyName( getAliasName() ); 328 } catch( MSNException e ) { 329 System.err.println( "JMSNPlugin.onPluginPropertiesUpdated() - " + e ); 330 } 331 } 332 } 333 334 338 public boolean isConnected() { 339 340 return session.isConnected(); 341 } 342 343 348 public void loginAccepted() { 349 350 System.err.println( "JMSNPlugin.loginAccepted() - reached" ); 351 fireOnLoginAccepted(); 352 fireOnRegisterUserSucessfull(); 354 358 try { 359 session.setFriendlyName( getAliasName() ); 360 } catch( MSNException e ) { 361 System.err.println( "JMSNPlugin.loginAccepted() - " + e ); 362 } 363 } 364 365 369 public void loginError() { 370 371 System.err.println( "JMSNPlugin.loginError() - reached" ); 372 fireOnLoginFailed(); 373 fireOnRegisterUserFailed(); } 375 376 381 public void incomingMessage( IncomingMessageEvent event ) { 382 383 System.err.println( "JMSNPlugin.incomingMessage() - Message from " + event.getUserName() ); 384 385 fireOnReceiveMessage( event.getUserName(), null, event.getMessage() ); 386 } 387 388 393 public void contactPropertyChanged( ContactChangeEvent event ) { 394 395 System.err.println( "JMSNPlugin.contactPropertyChanged() - " + event ); 396 397 switch( event.getProperty() ) { 399 400 case Contact.STATUS : 401 fireOnBuddyStatusChanged( event.getUserName(), translateStatusFromPlugin( event.getNewValue().toString() ) ); 402 break; 403 404 case Contact.FRIENDLY_NAME : 405 getKernelManager().getContactListManager().updateScreenName( this, event.getUserName(), event.getNewValue().toString() ); 406 break; 407 408 case Contact.CAPABILITIES : 409 System.err.println( "JMSNPlugin.contactPropertyChanged() - Contact capabilities changed to [" + event.getNewValue().toString() + "]" ); 410 break; 411 } 412 } 413 414 420 public void reverseListChanged( String strUserName ) { 421 422 System.err.println( "JMSNPlugin.reverseListChanged() - " + strUserName ); 423 } 424 425 429 public void serverDisconnected() { 430 431 System.err.println( "JMSNPlugin.serverDisconnected()" ); 432 433 fireOnLogout(); 434 } 435 436 442 public void groupReceived( int nGroupId, String strGroupName ) { 443 444 } 445 446 451 public void groupAdded( int nGroupId, String strGroupName ) { 452 453 } 454 455 460 public void groupRemoved( int nGroupId, String strGroupName ) { 461 462 } 463 464 469 public void groupRenamed( int nGroupId, String strNewGroupName ) { 470 471 } 472 473 480 public void contactReceived( org.hn.sleek.jmml.Contact contact ) { 481 482 JContactListItem contactItem = getKernelManager().getContactListManager().getContact( this, contact.getUserName() ); 483 484 485 if( contactItem == null ) { 486 487 if( contact.isContact() ) { 489 getKernelManager().getContactListManager().addToContactList( this, contact.getFriendlyName(), contact.getUserName() ); 490 contactItem = getKernelManager().getContactListManager().getContact( this, contact.getUserName() ); 491 } 492 493 } 497 498 if( contactItem != null ) { 500 contactItem.setBlocked( contact.isBlocked() ); 501 contactItem.setVisible( contact.isAllowed() ); 502 getKernelManager().getContactListManager().updatePrivacy( contactItem ); 503 } 504 } 505 506 510 public void contactAdded( org.hn.sleek.jmml.Contact contact ) { 511 512 if( contact.isReverse() ) 514 fireOnBuddyRequestAuthorization( contact.getUserName(), contact.getFriendlyName() ); 515 } 516 517 521 public void contactRemoved( org.hn.sleek.jmml.Contact contact ) { 522 523 } 524 525 529 public void contactAddedFailed( int nReason ) { 530 531 } 532 533 537 public void contactRemovedFailed( int nReason ) { 538 539 } 540 541 546 public void userTyping( Contact contact ) { 547 548 System.err.println( "JMSNPlugin.userTyping() - " + contact.getUserName() + " is typing a message" ); 549 fireOnUserTyping( contact.getUserName() ); 550 } 551 552 556 public void errorReceived( int nErrorCode ) { 557 558 System.err.println( "JMSNPlugin.errorReceived() - Protocol error received" ); 559 } 560 561 566 public void serverNotificationMessage( int nMessageType, Hash hServerData ) { 567 568 System.err.println( "JMSNPlugin.serverNotificationMessage() - Message type " + nMessageType ); 569 hServerData.toString(); 570 571 switch( nMessageType ) { 572 573 case MSNConstants.MSG_NEW_EMAIL_NOTIFICATION : 574 case MSNConstants.MSG_INITIAL_EMAIL_NOTIFICATION : hEmailNotification = hServerData; break; 575 576 default : if( ( nMessageType >= MSNConstants.MSG_PROFILE_MESSAGES_BEGIN ) && 577 ( nMessageType <= MSNConstants.MSG_PROFILE_MESSAGES_END ) ) { 578 System.err.println( "JMSNPlugin.serverNotificationMessage() - Profile received" ); 579 hProfileNotification = hServerData; 580 581 try { 582 session.requestServiceURL( MSNConstants.SERVICE_URL_INBOX ); 583 } catch( MSNException e ) { 584 System.err.println( "JMSNPlugin.serverNotificationMessage() - " + e ); 585 } 586 } 587 588 } 589 } 590 591 598 public void urlReceived( int nURLId, String strFolderPath, String strHttpAddress ) { 599 600 EMailHandler email = new EMailHandler( getUserId(), strPasswd, hProfileNotification, hEmailNotification, nURLId, strFolderPath, strHttpAddress ); 601 602 System.err.println( "JMSNPlugin.urlReceived() - " + email.toString() ); 603 } 604 605 609 public void noticeReceived( String strNotificationMessage ) { 610 611 System.err.println( "JMSNPlugin.noticeReceived() - " + strNotificationMessage ); 612 } 613 614 621 public void participantOnChat( Contact contact, int nContactNumber, int nNumParticipants ) { 622 623 System.err.println( "JMSNPlugin.participantOnChat() - " + contact.getFriendlyName() + "(" + contact.getUserName() + ") is contact " + nContactNumber + " of " + nNumParticipants ); 624 } 625 626 } 627 | Popular Tags |