1 29 38 39 package org.planetamessenger.protocols.comvc; 40 41 import java.util.*; 42 import java.io.*; 43 import org.planetamessenger.net.*; 44 import org.planetamessenger.io.*; 45 46 47 48 class JComVcUDPEvents implements JDatagramEventListener { 49 50 JComVcEventListener eventListener; 51 HashMap hContactList; 52 53 54 55 JComVcUDPEvents( HashMap hContactList ) { 56 63 64 eventListener = null; 65 this.hContactList = hContactList; 66 } 67 68 void addComVcEventListener( JComVcEventListener listener ) { 69 77 78 eventListener = listener; 79 } 80 81 public void onClose() { 82 86 87 } 88 89 public void onReceive( java.net.DatagramPacket pak ) { 90 96 97 System.err.println( "JComVcUDPEvents.onReceive() [" + pak.getAddress().getHostAddress() + "] (" + pak.getLength() + " bytes)" ); 98 99 ByteArrayInputStream inStream = new ByteArrayInputStream( pak.getData() ); 100 JIOStream ioStream = new JIOStream(); 101 HashMap<String , String > hServerParms = new HashMap<String , String >(); 102 JComVcContactItem contactItem; 103 104 105 if( !ioStream.recv( inStream, hServerParms ) ) { 107 System.err.println( "JComVcUDPEvents.onReceive() - Server data error " + hServerParms.toString() ); 108 return; 109 } 110 111 System.err.println( "JComVcUDPEvents.onReceive(" + pak.getAddress().getHostAddress() + ") - Server sent " + hServerParms.toString() ); 112 113 if( !hServerParms.containsKey( JComVcConstants.COMVC_INPUT_FLAG ) && !hServerParms.containsKey( JComVcConstants.COMVC_OUTPUT_FLAG ) ) { 115 System.err.println( "JComVcUDPEvents.onReceive() - INP/OUT parameter error" ); 116 return; 117 } 118 119 Long lUserId = new Long ( Long.parseLong( hServerParms.get( JComVcConstants.COMVC_USERID_KEY ).toString() ) ); 121 122 if( hContactList.containsKey( lUserId ) ) { 123 contactItem = ( JComVcContactItem ) hContactList.get( lUserId ); 124 125 132 contactItem.strIPAddress = pak.getAddress().getHostAddress(); 134 contactItem.nTicket = Long.parseLong( hServerParms.get( JComVcConstants.COMVC_TICKET_KEY ).toString() ); 135 if( hServerParms.containsKey( JComVcConstants.COMVC_INPUT_FLAG ) ) { 137 138 int nUserStatus = Integer.parseInt( hServerParms.get( JComVcConstants.COMVC_STATUS_KEY ).toString() ); 139 140 contactItem.nTCPPort = Integer.parseInt( hServerParms.get( JComVcConstants.COMVC_PORT_KEY ).toString() ); 141 contactItem.nUDPPort = Integer.parseInt( hServerParms.get( JComVcConstants.COMVC_PORTUDP_KEY ).toString() ); 142 contactItem.nClientVersion = Long.parseLong( hServerParms.get( JComVcConstants.COMVC_VERSION_KEY ).toString() ); 143 contactItem.nUserStatus = ( ( nUserStatus == JComVcConstants.STATUS_BUDDY_INVISIBLE ) ? JComVcConstants.STATUS_INVISIBLE : nUserStatus ); 144 } 145 else 146 contactItem.nUserStatus = JComVcConstants.STATUS_OFFLINE; 147 148 if( eventListener != null ) 150 eventListener.onBuddyStatusChanged( contactItem.nUserId, contactItem.nUserStatus ); 151 } 152 else { 153 System.err.println( "JComVcUDPEvents.onReceive() - UserId [" + lUserId.longValue() + "] not found in ContactList" ); 154 } 155 } 156 157 public void onSend( java.net.DatagramPacket pak ) { 158 164 165 } 166 } 167 168 | Popular Tags |