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

📄 sendmessageaction.java.svn-base

📁 类似QQ的功能
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************* Jimm - Mobile Messaging - J2ME ICQ clone Copyright (C) 2003-05  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/SendMessageAction.java Version: ###VERSION###  Date: ###DATE### Author(s): Manuel Linsmayer, Spassky Alexander, Andreas Rossbacher *******************************************************************************/package jimm.comm;import java.io.ByteArrayOutputStream;import jimm.ContactList;import jimm.ContactItem;import jimm.JimmException;import jimm.Options;public class SendMessageAction extends Action{	// Plain message	private PlainMessage plainMsg;//#sijapp cond.if (target!="DEFAULT")&(modules_FILES="true")#	// File transfer request message	private FileTransferMessage fileTrans;//#sijapp cond.end#	private int SEQ1 = 0xffff;		private int messId = -1;		public int getMessId()	{		return messId;	}	// Constructor	public SendMessageAction(Message msg)	{		super(false, true);				messId = (int)System.currentTimeMillis();				//#sijapp cond.if target!="DEFAULT"#		if (msg instanceof PlainMessage)		{			this.plainMsg = (PlainMessage) msg;			//#sijapp cond.if modules_FILES is"true"#			this.fileTrans = null;			//#sijapp cond.end#		}		//#sijapp cond.if modules_FILES is "true"#		else if (msg instanceof FileTransferMessage)		{			this.plainMsg = null;			this.fileTrans = (FileTransferMessage) msg;		}		//#sijapp cond.end#		//#sijapp cond.else#		//#		if (msg instanceof PlainMessage)		//#		{		//#			this.plainMsg = (PlainMessage) msg;		//#		}		//#sijapp cond.end#	}	// Init action	protected void init() throws JimmException	{		// Forward init request depending on message type		SEQ1--;		initPlainMsg();	}	// Init action for plain messages	private void initPlainMsg() throws JimmException	{		// Get receiver object		ContactItem rcvr;//#sijapp cond.if (target!="DEFAULT")&(modules_FILES="true")#		if (this.plainMsg != null)			rcvr = this.plainMsg.getRcvr();		else			rcvr = this.fileTrans.getRcvr();//#sijapp cond.else#//#        rcvr = this.plainMsg.getRcvr();//#sijapp cond.end#		// What message format/encoding should we use?		int type = 1;		boolean utf8;		utf8 = (rcvr.getIntValue (ContactItem.CONTACTITEM_STATUS) == 			ContactList.STATUS_OFFLINE) ? false : 			rcvr.hasCapability(Icq.CAPF_UTF8_INTERNAL);		//#sijapp cond.if (target!="DEFAULT")&(modules_FILES="true")#		if ((this.fileTrans != null)				&& (rcvr.getIntValue(ContactItem.CONTACTITEM_STATUS) != ContactList.STATUS_OFFLINE)				&& rcvr.hasCapability(Icq.CAPF_AIM_SERVERRELAY))		{			type = 2;		}//#sijapp cond.end#		if ((this.plainMsg != null)			&& ((this.plainMsg.getMessageType() >= Message.MESSAGE_TYPE_AWAY) 			&& (this.plainMsg.getMessageType() <= Message.MESSAGE_TYPE_FFC)))		{			type = 2;		}				if (Options.getBoolean(Options.OPTION_DELIV_MES_INFO)			&& rcvr.hasCapability(Icq.CAPF_AIM_SERVERRELAY)			&& (rcvr.getIntValue(ContactItem.CONTACTITEM_CLIENT) != Icq.CLI_STICQ)			&& (rcvr.getIntValue(ContactItem.CONTACTITEM_CLIENT) != Icq.CLI_TRILLIAN)			&& (rcvr.getIntValue(ContactItem.CONTACTITEM_STATUS) != ContactList.STATUS_OFFLINE))		{			type = 2;		}		//////////////////////		// Message format 1 //		//////////////////////				if (type == 1)		{			byte[] textRaw = 				utf8 ? 				Util.stringToUcs2beByteArray(Util.restoreCrLf(this.plainMsg.getText())) 				: Util.stringToByteArray(Util.restoreCrLf(this.plainMsg.getText()));							String uin = rcvr.getStringValue(ContactItem.CONTACTITEM_UIN);						ByteArrayOutputStream buffer = new ByteArrayOutputStream();			ByteArrayOutputStream tlvBuffer = new ByteArrayOutputStream();						// msg-id cookie 			Util.writeDWord(buffer, messId, true);			Util.writeDWord(buffer, type, true);						// message channel			Util.writeWord(buffer, type, true);						// UIN			Util.writeByte(buffer, uin.length());			Util.writeByteArray(buffer, uin.getBytes());						// ---------- message data TLV ------------- 			tlvBuffer.reset();						// Capabilities			Util.writeWord(tlvBuffer, 0x0501, true);			if (utf8)			{				Util.writeWord(tlvBuffer, 0x0002, true);				Util.writeWord(tlvBuffer, 0x0106, true);			} else			{				Util.writeWord(tlvBuffer, 0x0001, true);				Util.writeByte(tlvBuffer, 0x01);			}						// Type: message			Util.writeWord(tlvBuffer, 0x0101, true);						// Mess data len			Util.writeWord(tlvBuffer, 4+textRaw.length, true);						// MESSAGE.ENCODING			Util.writeDWord(tlvBuffer, utf8 ? 0x00020000 : 0x00000000, true);			Util.writeByteArray(tlvBuffer, textRaw);			Util.writeTLV(buffer, 0x0002, tlvBuffer.toByteArray(), true);						// ---------- Store offline TLV ------------- 			Util.writeTLV(buffer, 0x0006, null, true);						// ---------- req. serv delivery TLV ----------			if (Options.getBoolean(Options.OPTION_DELIV_MES_INFO)) Util.writeTLV(buffer, 0x0003, null, true);						// ----------- Send packet --------------			SnacPacket snacPkt = new SnacPacket(SnacPacket.CLI_SENDMSG_FAMILY,					SnacPacket.CLI_SENDMSG_COMMAND, 0, new byte[0], buffer.toByteArray());			Icq.sendPacket(snacPkt);		}		//////////////////////		// Message format 2 //		//////////////////////		else if (type == 2)		{			// System.out.println("Send TYPE 2");			// Get UIN			byte[] uinRaw = Util.stringToByteArray(rcvr					.getStringValue(ContactItem.CONTACTITEM_UIN));			// Get text			byte[] textRaw;			// Get filename if file transfer			byte[] filenameRaw;//#sijapp cond.if (target!="DEFAULT")&(modules_FILES="true")#			if (this.fileTrans == null)			{				textRaw = Util.stringToByteArray(Util.restoreCrLf(this.plainMsg						.getText()), true);				filenameRaw = new byte[0];			} else			{				textRaw = Util.stringToByteArray(this.fileTrans						.getDescription());				filenameRaw = Util.stringToByteArray(this.fileTrans						.getFilename());			}//#sijapp cond.else#//#			textRaw = Util.stringToByteArray( Util.restoreCrLf(this.plainMsg.getText()) );//#			filenameRaw = new byte[0];                //#sijapp cond.end#			// Set length			// file request: 192 + UIN len + file description (no null) +			// file name (null included)			// normal msg: 163 + UIN len + message length;			int p_sz = 0;//#sijapp cond.if (target!="DEFAULT")&(modules_FILES="true")#			if (this.fileTrans == null)			{				p_sz = 163 + uinRaw.length + textRaw.length;			} else			{				p_sz = 192 + uinRaw.length + textRaw.length						+ filenameRaw.length + 1;			}//#sijapp cond.else#//#			p_sz = 163 + uinRaw.length + textRaw.length;                //#sijapp cond.end#			//int tlv5len = 148;			//int tlv11len = 108;			// Build the packet			byte[] buf = new byte[p_sz];			int marker = 0;			Util.putDWord(buf, marker, messId); // CLI_SENDMSG.TIME			marker += 4;			Util.putDWord(buf, marker, type); // CLI_SENDMSG.ID			marker += 4;			Util.putWord(buf, marker, 0x0002); // CLI_SENDMSG.FORMAT			marker += 2;			Util.putByte(buf, marker, uinRaw.length); // CLI_SENDMSG.UIN			System.arraycopy(uinRaw, 0, buf, marker + 1, uinRaw.length);			marker += 1 + uinRaw.length;			//-----------------TYPE2 Specific Data-------------------			Util.putWord(buf, marker, 0x0005);			marker += 2;			// Length of TLV5 differs betweeen normal message and file requst//#sijapp cond.if (target!="DEFAULT")&(modules_FILES="true")#			if (this.fileTrans == null)			{				Util.putWord(buf, marker, 144 + textRaw.length, true);			} else			{				Util.putWord(buf, marker, 173 + textRaw.length						+ filenameRaw.length + 1);			}//#sijapp cond.else#//#			Util.putWord(buf, marker, 144 + textRaw.length, true);

⌨️ 快捷键说明

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