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

📄 icq.java.svn-base

📁 类似QQ的功能
💻 SVN-BASE
📖 第 1 页 / 共 5 页
字号:
		switch (Options.getInt(Options.OPTION_CONN_TYPE))		{			case Options.CONN_TYPE_SOCKET:				c = new SOCKETConnection();				break;			case Options.CONN_TYPE_HTTP:				c = new HTTPConnection();				break;			//#sijapp cond.if modules_PROXY is "true"#			case Options.CONN_TYPE_PROXY:				c = new SOCKSConnection();				break;			//#sijapp cond.end#		}		// Instantiate active actions vector		actAction = new Vector();		// Instantiate action listener		actListener = new ActionListener();		keepAliveTimerTask = new TimerTasks(TimerTasks.ICQ_KEEPALIVE);		long keepAliveInterv = Integer.parseInt(Options				.getString(Options.OPTION_CONN_ALIVE_INVTERV)) * 1000;		Jimm.getTimerRef().schedule(keepAliveTimerTask, keepAliveInterv,				keepAliveInterv);		// Catch All Exceptions		try		{			// Abort only in error state			while (Icq.thread == thread)			{				// Get next action				synchronized (this)				{					if (reqAction.size() > 0)					{						if ((actAction.size() == 1)								&& ((Action) actAction.elementAt(0))										.isExclusive())						{							newAction = null;						} else						{							if (reqAction != null && reqAction.size() != 0)								newAction = (Action) reqAction.elementAt(0);							if (((actAction.size() > 0) && newAction									.isExclusive())									|| (!newAction.isExecutable()))							{								newAction = null;							} else							{								if (reqAction != null && reqAction.size() != 0)									reqAction.removeElementAt(0);							}						}					} else					{						newAction = null;					}				}				// Set dcPacketAvailable to true if the peerC is not null and				// there is an packet waiting//#sijapp cond.if (target!="DEFAULT")&(modules_FILES="true")#				dcPacketAvailable = (peerC != null) ? ((peerC.available() > 0) ? true : false ) : false;//#sijapp cond.end#				// Set biPacketAvailable to true if the bartC is not null and				// there is an packet waiting				//#sijapp cond.if target!="DEFAULT" & modules_AVATARS="true"#				biPacketAvailable = (bartC != null) ? ((bartC.available() > 0) ? true : false ) : false;				//  #sijapp cond.end#				// Wait if a new action does not exist				if ((newAction == null) && (c.available() == 0)//#sijapp cond.if (target!="DEFAULT")&(modules_FILES="true")#					&& !dcPacketAvailable//#sijapp cond.end#				//#sijapp cond.if target!="DEFAULT" & modules_AVATARS="true"#					&& !biPacketAvailable				//  #sijapp cond.end#				)				{					try					{						synchronized (wait)						{							wait.wait(/*Icq.STANDBY*/);						}					} catch (InterruptedException e)					{						// Do nothing					}				}				// Initialize action				else if (newAction != null)				{					try					{						newAction.init();						actAction.addElement(newAction);					} catch (JimmException e)					{						JimmException.handleException(e);						if (e.isCritical())							throw (e);					}				}//#sijapp cond.if (target!="DEFAULT")&(modules_FILES="true")#				dcPacketAvailable = (peerC != null) ? ((peerC.available() > 0) ? true : false ) : false;//#sijapp cond.end#				//#sijapp cond.if target!="DEFAULT" & modules_AVATARS="true"#				biPacketAvailable = (bartC != null) ? ((bartC.available() > 0) ? true : false ) : false;				//  #sijapp cond.end#				// Read next packet, if available				Packet packet;				boolean consumed;				while (					(c.available() > 0)//#sijapp cond.if (target!="DEFAULT")&(modules_FILES="true")#					|| dcPacketAvailable//#sijapp cond.end#				//#sijapp cond.if target!="DEFAULT" & modules_AVATARS="true"#					|| biPacketAvailable				//  #sijapp cond.end#				)				{					// Try to get packet					packet = null;					try					{						if (c.available() > 0) packet = c.getPacket();						//  #sijapp cond.if target!="DEFAULT" & modules_FILES="true"#						else if (dcPacketAvailable) packet = peerC.getPacket();						//  #sijapp cond.end#						//#sijapp cond.if target!="DEFAULT" & modules_AVATARS="true"#						else if (biPacketAvailable) packet = bartC.getPacket();						//  #sijapp cond.end#					} catch (JimmException e)					{						JimmException.handleException(e);						if (e.isCritical())							throw (e);					}					// Forward received packet to all active actions and to the					// action listener					consumed = false;					for (int i = 0; i < actAction.size(); i++)					{						try						{							if (((Action) actAction.elementAt(i))									.forward(packet))							{								consumed = true;								break;							}						} catch (JimmException e)						{							JimmException.handleException(e);							if (e.isCritical()) throw (e);						}					}					if (!consumed)					{						try						{							actListener.forward(packet);						} catch (JimmException e)						{							JimmException.handleException(e);							if (e.isCritical()) throw (e);						}					}					//  #sijapp cond.if target!="DEFAULT" & modules_FILES="true"#					dcPacketAvailable = (peerC != null) ? ((peerC.available() > 0) ? true : false ) : false;					//  #sijapp cond.end#					//#sijapp cond.if target!="DEFAULT" & modules_AVATARS="true"#					biPacketAvailable = (bartC != null) ? ((bartC.available() > 0) ? true : false ) : false;					//  #sijapp cond.end#				}				// Remove completed actions				for (int i = 0; i < actAction.size(); i++)				{					if (((Action) actAction.elementAt(i)).isCompleted()							|| ((Action) actAction.elementAt(i)).isError())					{						actAction.removeElementAt(i--);					}				}			}		}		catch (Exception e)		{			DebugLog.addText ("MainThread: Exception: " + e.toString());			e.printStackTrace();			if (c != null) {// Construct and handle exception				JimmException f = new JimmException(141, 0, true);				JimmException.handleException(f);			}		}		if (!Options.getBoolean(Options.OPTION_RECONNECT) && c != null)		{			// Close connection			c.notifyToDisconnect();			resetServerCon();			/* Reset all contacts offine */			MainThread.resetContactsOffline();		}	}	public static boolean isNotCriticalConnectionError (int errcode) {		switch (errcode) {		    case 110:	// Login from another device		    case 111:	// Bad password		    case 112:	// Non-existant UIN		    case 117:	// Empty UIN and/or password		    case 119:	// "You need to allow network connection"		    case 122:	// Specified server host and/or port is invalid		    case 127:	// peer connection: specified server host and/or port is invalid			return false;		}		return true;	}	public static int getCurrentStatus()	{		return isConnected() ? (int) Options				.getLong(Options.OPTION_ONLINE_STATUS)				: ContactList.STATUS_OFFLINE;	}	static public void setInactiveTime(long inactiveTime) throws JimmException	{		byte[] buf = new byte[4];				Util.putDWord(buf, 0, inactiveTime);		sendPacket(new SnacPacket(0x0001, 0x0011, 0x0011, new byte[0], buf));	}	public static final int XSTATUS_CURRENT = -10;		static public void setOnlineStatus(int status, int xStatus, boolean dcInfo) throws JimmException	{		ByteArrayOutputStream statBuffer = new ByteArrayOutputStream();		ByteArrayOutputStream visBuffer = new ByteArrayOutputStream();				int onlineStatus = Util.translateStatusSend(status);				int visibilityItemId = Options.getInt(Options.OPTION_VISIBILITY_ID);		byte bCode = 0;		/* Main status */		if (status != -1)		{			/* Visiblity */			if (visibilityItemId != 0)			{				if (onlineStatus == Util.SET_STATUS_INVISIBLE)					bCode = (status == ContactList.STATUS_INVIS_ALL) ? (byte) 2 : (byte) 3;				else					bCode = (byte) 4;				Util.writeWord(visBuffer, 0, true);				Util.writeWord(visBuffer, 0, true);				Util.writeWord(visBuffer, visibilityItemId, true);				Util.writeWord(visBuffer, 4, true);				Util.writeWord(visBuffer, 5, true);				Util.writeWord(visBuffer, 0xCA, true);				Util.writeWord(visBuffer, 1, true);				Util.writeByte(visBuffer, bCode);							// Change privacy setting according to new status				if ((getVisibility() != bCode) && (onlineStatus == Util.SET_STATUS_INVISIBLE))				{					setVisibility(bCode);					SnacPacket reply2pre = new SnacPacket(							SnacPacket.CLI_ROSTERUPDATE_FAMILY,							SnacPacket.CLI_ROSTERUPDATE_COMMAND,							SnacPacket.CLI_ROSTERUPDATE_COMMAND, new byte[0], visBuffer.toByteArray());					sendPacket(reply2pre);				}			}					Util.writeWord(statBuffer, 0x06, true); // TLV (0x06)			Util.writeWord(statBuffer, 4, true); // TLV len			Util.writeDWord(statBuffer, onlineStatus|0x10000000, true);		}				// DC Info		if (dcInfo)		{			Util.writeWord(statBuffer, 0x0C, true);		// TLV (0x0C)			Util.writeWord(statBuffer, 0x25, true);		// TLV len			Util.writeDWord(statBuffer, 0xC0A80001, true);	// 192.168.0.1, cannot get own IP address			Util.writeDWord(statBuffer, 0x0000ABCD, true);	// Port 43981			Util.writeByte(statBuffer, 0x00);		// Firewall			Util.writeWord(statBuffer, 0x08, true);		// Support protocol version 8			Util.writeDWord(statBuffer, 0x00000000, true);			Util.writeDWord(statBuffer, 0x00000050, true);			Util.writeDWord(statBuffer, 0x00000003, true);			Util.writeDWord(statBuffer, 0xFFFFFFFE, true);			Util.writeDWord(statBuffer, 0x00010000, true);			Util.writeDWord(statBuffer, 0xFFFFFFFE, true);			Util.writeWord(statBuffer, 0x0000, true);		}		/* xStatus */		if (xStatus == XSTATUS_CURRENT) xStatus = Options.getInt(Options.OPTION_XSTATUS);		String statDescr = Options.getStatusString(StatusInfo.TYPE_X_STATUS, xStatus);		if (statDescr == null) statDescr = Options.emptyString;		byte[] szMoodId = Util.stringToByteArray(statDescr, true);		Util.writeWord(statBuffer, 0x1D, true); // TLV (0x1D)		String message = xStatus != -1 ? ("icqmood" + xStatus) : Options.emptyString;		Util.writeWord(statBuffer, 12 + szMoodId.length + message.length(), true); // TLV Length		Util.writeWord(statBuffer, 0x0002, true); // Text Status		Util.writeByte(statBuffer, 0x04);		Util.writeByte(statBuffer, szMoodId.length + 0x04);		Util.writeWord(statBuffer, szMoodId.length, true);		Util.writeByteArray(statBuffer, szMoodId);		Util.writeWord(statBuffer, 0x0000, true);		Util.writeWord(statBuffer, 0x000E, true);		Util.writeLenAndString(statBuffer, message, false);		if (statBuffer.size() != 0)		{			SnacPacket packet = new SnacPacket(SnacPacket.CLI_SETSTATUS_FAMILY,					SnacPacket.CLI_SETSTATUS_COMMAND, SnacPacket.CLI_SETSTATUS_COMMAND, new byte[0],					statBuffer.toByteArray());			sendPacket(packet);		}				// Change privacy setting according to new status		if ((status != -1) && (getVisibility() != bCode) && (visibilityItemId != 0 && onlineStatus != Util.SET_STATUS_INVISIBLE))		{			setVisibility(bCode);			SnacPacket reply2post = new SnacPacket(					SnacPacket.CLI_ROSTERUPDATE_FAMILY,					SnacPacket.CLI_ROSTERUPDATE_COMMAND,					SnacPacket.CLI_ROSTERUPDATE_COMMAND, new byte[0], visBuffer.toByteArray());			sendPacket(reply2post);		}		lastStatusChangeTime = Util.getDateString(true);	}	public static String getLastStatusChangeTime()	{		return lastStatusChangeTime;	}		static public void sendUserUnfoPacket() throws JimmException	{		ByteArrayOutputStream capsStream = new ByteArrayOutputStream();		byte[] packet = null;				try		{			byte[] ver = Util.stringToByteArray("###VERSION###");			int verLen = ver.length;			if (verLen > 10) verLen = 10;			for (int i = 0; i < verLen; i++) CAP_VERSION[i+5] = ver[i];    						capsStream.write(new byte[] {(byte)0x00, (byte)0x05, (byte)0x00, (byte)0x00});			capsStream.write(CAP_AIM_SERVERRELAY);			capsStream.write(CAP_AIM_ISICQ);			capsStream.write(CAP_ICHAT);			capsStream.write(CAP_UTF8);			//#sijapp cond.if target!="DEFAULT" & modules_AVATARS="true"#			capsStream.write(CAP_AVATAR);			//#sijapp cond.end#			capsStream.write(CAP_VERSION);			//#sijapp cond.if target!="DEFAULT"#			if (Options.getInt(Options.OPTION_TYPING_MODE) > 0) capsStream.write(CAP_MTN);			//#sijapp cond.end#						int xStatus = Options.getInt(Options.OPTION_XSTATUS);			if (xStatus != -1) capsStream.write(XSTATUS_CONSTS, xStatus*16, 16);						packet = capsStream.toByteArray();			Util.putWord(packet, 2, packet.length-4);

⌨️ 快捷键说明

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