⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 actionlistener.java.svn-base

📁 类似QQ的功能
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************* Jimm - Mobile Messaging - J2ME ICQ clone Copyright (C) 2003-08  Jimm Project This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. ******************************************************************************** File: src/jimm/comm/ActionListener.java Version: ###VERSION###  Date: ###DATE### Author(s): Manuel Linsmayer, Andreas Rossbacher, Spassky Alexander, Igor Palkin *******************************************************************************/package jimm.comm;import java.io.ByteArrayInputStream;import jimm.ContactList;import jimm.ContactItem;import jimm.DebugLog;import jimm.Jimm;import jimm.JimmUI;import jimm.MainThread;import jimm.JimmException;import jimm.Options;import jimm.SplashCanvas;import jimm.StatusInfo;//#sijapp cond.if (target!="DEFAULT")&(modules_FILES="true")#import jimm.FileTransfer;//#sijapp cond.end#public class ActionListener{	/** ************************************************************************* */	// Forwards received packet	protected void forward(Packet packet) throws JimmException	{		// Watch out for channel 4 (Disconnect) packets		if (packet instanceof DisconnectPacket)		{			DisconnectPacket disconnectPacket = (DisconnectPacket) packet;			// Throw exception			if (disconnectPacket.getError() == 0x0001)			{ // Multiple logins				throw (new JimmException(110, 0));			} else			{ // Unknown error				throw (new JimmException(100, 0));			}		}		/** *********************************************************************** */		// Watch out for requested offline messages		if (packet instanceof FromIcqSrvPacket) {			FromIcqSrvPacket fromIcqSrvPacket = (FromIcqSrvPacket) packet;			if (fromIcqSrvPacket.getFamily() == 0x0015) {				int subCommand = fromIcqSrvPacket.getSubcommand();				switch (subCommand) {					// Watch out for SRV_OFFLINEMSG					case FromIcqSrvPacket.SRV_OFFLINEMSG_SUBCMD:						// Get raw data						byte[] buf = fromIcqSrvPacket.getData();						// Check length						if (buf.length > 13) {							// Extract UIN							long uinRaw = Util.getDWord(buf, 0, false);							String uin = String.valueOf(uinRaw);							// Extract date of dispatch							long date = Util.createLongTime(									Util.getWord(buf, 4, false),									Util.getByte(buf, 6),									Util.getByte(buf, 7),									Util.getByte(buf, 8),									Util.getByte(buf, 9),									0);							// Get type							int type = Util.getWord(buf, 10, false);							// Get text length							int textLen = Util.getWord(buf, 12, false);							// Get text							String text = Util.removeCr(Util.byteArrayToString(buf, 14, textLen, Util.isDataUTF8(buf, 14, textLen)));							// Normal message							if (type == 0x0001) {								// Check length								if (buf.length != 14 + textLen) {									throw (new JimmException(116, 1));								}								// Forward message to contact list								PlainMessage message = new PlainMessage(uin, Options.getString(Options.OPTION_UIN), Util.gmtTimeToLocalTime(date), text, true);								MainThread.addMessageSerially(message);							} // URL message							else if (type == 0x0004) {								if (buf.length != 14 + textLen) {									throw (new JimmException(116, 1));								}								// Search for delimiter								int delim = text.indexOf(0xFE);								// Split message, if delimiter could be found								String urlText;								String url;								if (delim != -1) {									urlText = text.substring(0, delim);									url = text.substring(delim + 1);								} else {									urlText = text;									url = "";								}								// Forward message message to contact list								UrlMessage message = new UrlMessage(uin, Options.getString(Options.OPTION_UIN), Util.gmtTimeToLocalTime(date), url, urlText);								MainThread.addMessageSerially(message);							}						}						break;					// Watch out for SRV_DONEOFFLINEMSGS					case FromIcqSrvPacket.SRV_DONEOFFLINEMSGS_SUBCMD:						// Send a CLI_TOICQSRV/CLI_ACKOFFLINEMSGS packet						ToIcqSrvPacket reply = new ToIcqSrvPacket(0x00000000, Options.getString(Options.OPTION_UIN), ToIcqSrvPacket.CLI_ACKOFFLINEMSGS_SUBCMD, new byte[0], new byte[0]);						Icq.c.sendPacket(reply);						break;				}			}		}		// Watch out for channel 2 (SNAC) packets		else if (packet instanceof SnacPacket)		{			SnacPacket snacPacket = (SnacPacket) packet;			// Typing notify			//#sijapp cond.if target isnot "DEFAULT"#			if ((snacPacket.getFamily() == 0x0004)					&& (snacPacket.getCommand() == 0x0014)					&& Options.getInt(Options.OPTION_TYPING_MODE) > 0)			{				byte[] p = snacPacket.getData();				int uin_len = Util.getByte(p, 10);				String uin = Util.byteArrayToString(p, 11, uin_len);				int flag = Util.getWord(p, 11 + uin_len);				DebugLog.addText("Typing notify: " + flag);				if (flag == 0x0002)					//Begin typing					MainThread.BeginTyping(uin, true);				else					//End typing					MainThread.BeginTyping(uin, false);			}			//#sijapp cond.end#			// Error after requesting offline messages?			if ((snacPacket.getFamily() == 0x0015) && (snacPacket.getCommand() == 0x0001))			{				// Get data				byte[] buf = snacPacket.getData();				// Read the error code from the packet				int errCode = Util.getWord(buf, 0);				DebugLog.addText("Error after requesting offline messages, error code: " + errCode);			}			// Watch out for SRV_USERONLINE packets			else if ((snacPacket.getFamily() == SnacPacket.SRV_USERONLINE_FAMILY)					&& (snacPacket.getCommand() == SnacPacket.SRV_USERONLINE_COMMAND))			{				int xStatus = -1;				String xStatusMessage = null;//#sijapp cond.if (target!="DEFAULT")&(modules_FILES="true")#				// DC variables				byte[] internalIP = new byte[4];				byte[] externalIP = new byte[4];				int dcPort = 0;				int dcType = -1;				int icqProt = 0;				int authCookie = 0;//#sijapp cond.end#				boolean statusChange = true;				int dwFT1 = 0, dwFT2 = 0, dwFT3 = 0;				// int wVersion = 0;				byte[] capabilities_old = null; // Buffer for old style capabilities (TLV 0x000D)				byte[] capabilities_new = null; // Buffer for new style capabilities (TLV 0x0019)				//#sijapp cond.if target!="DEFAULT" & modules_AVATARS="true"#
				// Buddy Icon				byte[] biHash = new byte[16];	// Buffer for buddy icon md5 hash				//#sijapp cond.end#				// Time variables				int idle = -1;				int online = -1;				int signon = -1;				int regdate = -1;				// Get data				byte[] buf = snacPacket.getData();				// Get UIN of the contact changing status				int uinLen = Util.getByte(buf, 0);				String uin = Util.byteArrayToString(buf, 1, uinLen);				// Get new status and client capabilities				int status = ContactList.STATUS_ONLINE;				int marker = 1 + uinLen + 2;				int tlvNum = Util.getWord(buf, marker);				marker += 2;				for (int i = 0; i < tlvNum; i++)				{					int tlvType = Util.getWord(buf, marker);					byte[] tlvData = Util.getTlv(buf, marker);					if (tlvType == 0x0006) // STATUS					{						status = (int) Util.getDWord(tlvData, 0);					} else if (tlvType == 0x000D) // Old style CAPABILITIES					{						//DebugLog.addText("Old caps");						capabilities_old = tlvData;					} else if (tlvType == 0x0019) // New style CAPABILITIES					{						//DebugLog.addText("New caps");						capabilities_new = tlvData;					}					else if (tlvType == 0x001D)					{						int marker1d = 0;						while (tlvData.length > marker1d)						{							int bart_id = Util.getWord(tlvData, marker1d);							marker1d += 2;							int bart_flg = Util.getByte(tlvData, marker1d);							marker1d ++;							int bart_len = Util.getByte(tlvData, marker1d);							marker1d ++;							//#sijapp cond.if target!="DEFAULT" & modules_AVATARS="true"#							if ((bart_id == 0x0001) && (bart_flg == 0x0001))	// ICON HASH							{								System.arraycopy(tlvData, marker1d, biHash, 0, (bart_len < 17) ? bart_len : 0x0010);							}							else							//#sijapp cond.end#							if ((bart_id == 0x0002) && (bart_flg == 0x0004))							{								int textLen = (int)Util.getWord(tlvData, marker1d);								xStatusMessage = Util.byteArrayToString(tlvData, marker1d+2, textLen, true);								if (xStatusMessage == null) xStatusMessage = new String();							}							else if ((bart_id == 0x000E) && (bart_flg == 0x0000))							{								String strData = Util.byteArrayToString(tlvData, marker1d, bart_len, false);								xStatus = Icq.detectStandartXStatus(strData);							}							marker1d += bart_len;						}					}					//#sijapp cond.if (target != "DEFAULT") & (modules_FILES = "true")#					else if (tlvType == 0x000A) // External IP					{						System.arraycopy(tlvData, 0, externalIP, 0, 4);					}					else if (tlvType == 0x000c) // DC Infos					{						// dcMarker						int dcMarker = 0;						// Get internal IP						System.arraycopy(tlvData, dcMarker, internalIP, 0, 4);						dcMarker += 4;						// Get tcp port						dcPort = (int) Util.getDWord(tlvData, dcMarker);						dcMarker += 4;						// Get DC type						dcType = Util.getByte(tlvData, dcMarker);						dcMarker++;						// Get protocol version						icqProt = Util.getWord(tlvData, dcMarker);						dcMarker += 2;						// Get auth cookie						authCookie = (int) Util.getDWord(tlvData, dcMarker);						dcMarker += 12;						// Get data for client detection						dwFT1 = (int) Util.getDWord(tlvData, dcMarker);						dcMarker += 4;						dwFT2 = (int) Util.getDWord(tlvData, dcMarker);						dcMarker += 4;						dwFT3 = (int) Util.getDWord(tlvData, dcMarker);						statusChange = false;					}//#sijapp cond.end#										else if (tlvType == 0x0003) // Signon time					{						signon = (int) Util.gmtTimeToLocalTime(Util.byteArrayToLong(tlvData));						//System.out.println(Util.getDateString(false,signon));					} else if (tlvType == 0x0004) // Idle time					{						idle = (int) Util.byteArrayToLong(tlvData) / 256;					} else if (tlvType == 0x000F) // Online time					{						online = (int) Util.byteArrayToLong(tlvData);					} else if (tlvType == 0x0005) // Date of registration					{						regdate = (int) Util.byteArrayToLong(tlvData);					}					marker += 2 + 2 + tlvData.length;				}//#sijapp cond.if (target!="DEFAULT") & (modules_FILES="true") #								ContactItem item = ContactList.getItembyUIN(uin);				if (item != null)				{					byte[] capsArray = Icq.mergeCapabilities(capabilities_old, capabilities_new);					Icq.detectUserClientAndParseCaps(item, dwFT1, dwFT2, dwFT3, capsArray, icqProt, statusChange);					if (xStatus == -1)						xStatus = Icq.detectXStatus(capsArray);				}				MainThread.updateContactList(uin, status, xStatus, xStatusMessage, internalIP, externalIP, dcPort, dcType, icqProt, authCookie, signon, online, idle, regdate					//#sijapp cond.if modules_AVATARS="true"#
					, biHash					//#sijapp cond.end#				);//#sijapp cond.else#				MainThread.updateContactList(uin, status, -1, null, null, null, 0, 0, 0, 0, signon, online, idle, regdate					//#sijapp cond.if target!="DEFAULT" & modules_AVATARS="true"#
					, null					//#sijapp cond.end#				);//#sijapp cond.end#			}			/** ********************************************************************* */			// Watch out for SRV_USEROFFLINE packets			if ((snacPacket.getFamily() == SnacPacket.SRV_USEROFFLINE_FAMILY)					&& (snacPacket.getCommand() == SnacPacket.SRV_USEROFFLINE_COMMAND))			{				// Get raw data				byte[] buf = snacPacket.getData();				// Get UIN of the contact that goes offline				int uinLen = Util.getByte(buf, 0);				String uin = Util.byteArrayToString(buf, 1, uinLen);				// Update contact list				MainThread.userOffline(uin);			}			/** ********************************************************************* */			// Watch out for CLI_ACKMSG_COMMAND packets			else if ((snacPacket.getFamily() == SnacPacket.CLI_ACKMSG_FAMILY)					&& (snacPacket.getCommand() == SnacPacket.CLI_ACKMSG_COMMAND))			{				// Get raw data				byte[] buf = snacPacket.getData();								int msgId1 = (int)Util.getDWord(buf, 0);				int msgId2 = (int)Util.getDWord(buf, 4);								// Get length of the uin 				int uinLen = Util.getByte(buf, 10);				String uin = Util.byteArrayToString(buf, 11, uinLen);				// Get message type				int msgType = Util.getWord(buf, 58 + uinLen, false); // TODO: fix java.lang.ArrayIndexOutOfBoundsException				boolean gotStausMsg = false;				int skip = 0;				if (((msgType == Message.MESSAGE_TYPE_NORM) || (msgType == 26)) // 26 is sended from ICQ6					&& (msgId2 == 0x0002) 					&& Options.getBoolean(Options.OPTION_DELIV_MES_INFO))				{					MainThread.messageIsDelevered(uin, msgId1);					return;				}								if ((msgType >= Message.MESSAGE_TYPE_AWAY)	&& (msgType <= Message.MESSAGE_TYPE_FFC))				{					skip = 64;					gotStausMsg = true;				} 				if (msgType == Message.MESSAGE_TYPE_EXTENDED)				{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -