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

📄 rdesktop.java

📁 cygwin 是一个在windows平台上运行的unix模拟环境
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* Rdesktop.java
 * Component: ProperJavaRDP
 * 
 * Revision: $Revision: 1.7 $
 * Author: $Author: telliott $
 * Date: $Date: 2005/09/27 14:15:39 $
 *
 * Copyright (c) 2005 Propero Limited
 *
 * Purpose: Main class, launches session
 *
 * 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
 * 
 * (See gpl.txt for details of the GNU General Public License.)
 * 
 */
package net.propero.rdp;

import java.io.InputStream;
import java.net.*;
import java.awt.*;

import net.propero.rdp.keymapping.KeyCode_FileBased;
import net.propero.rdp.rdp5.Rdp5;
import net.propero.rdp.rdp5.VChannels;
import net.propero.rdp.rdp5.cliprdr.ClipChannel;
import net.propero.rdp.tools.SendEvent;

import org.apache.log4j.*;
import gnu.getopt.*;

public class Rdesktop {
    
    /**
     * Translate a disconnect code into a textual description of the reason for the disconnect
     * @param reason Integer disconnect code received from server
     * @return Text description of the reason for disconnection
     */
    static String textDisconnectReason(int reason)
    {
        String text;

        switch (reason)
        {
            case exDiscReasonNoInfo:
                text = "No information available";
                break;

            case exDiscReasonAPIInitiatedDisconnect:
                text = "Server initiated disconnect";
                break;

            case exDiscReasonAPIInitiatedLogoff:
                text = "Server initiated logoff";
                break;

            case exDiscReasonServerIdleTimeout:
                text = "Server idle timeout reached";
                break;

            case exDiscReasonServerLogonTimeout:
                text = "Server logon timeout reached";
                break;

            case exDiscReasonReplacedByOtherConnection:
                text = "Another user connected to the session";
                break;

            case exDiscReasonOutOfMemory:
                text = "The server is out of memory";
                break;

            case exDiscReasonServerDeniedConnection:
                text = "The server denied the connection";
                break;

            case exDiscReasonServerDeniedConnectionFips:
                text = "The server denied the connection for security reason";
                break;

            case exDiscReasonLicenseInternal:
                text = "Internal licensing error";
                break;

            case exDiscReasonLicenseNoLicenseServer:
                text = "No license server available";
                break;

            case exDiscReasonLicenseNoLicense:
                text = "No valid license available";
                break;

            case exDiscReasonLicenseErrClientMsg:
                text = "Invalid licensing message";
                break;

            case exDiscReasonLicenseHwidDoesntMatchLicense:
                text = "Hardware id doesn't match software license";
                break;

            case exDiscReasonLicenseErrClientLicense:
                text = "Client license error";
                break;

            case exDiscReasonLicenseCantFinishProtocol:
                text = "Network error during licensing protocol";
                break;

            case exDiscReasonLicenseClientEndedProtocol:
                text = "Licensing protocol was not completed";
                break;

            case exDiscReasonLicenseErrClientEncryption:
                text = "Incorrect client license enryption";
                break;

            case exDiscReasonLicenseCantUpgradeLicense:
                text = "Can't upgrade license";
                break;

            case exDiscReasonLicenseNoRemoteConnections:
                text = "The server is not licensed to accept remote connections";
                break;

            default:
                if (reason > 0x1000 && reason < 0x7fff)
                {
                    text = "Internal protocol error";
                }
                else
                {
                    text = "Unknown reason";
                }
        }
        return text;
    }

    /* RDP5 disconnect PDU */
    public static final int exDiscReasonNoInfo = 0x0000;
    public static final int exDiscReasonAPIInitiatedDisconnect = 0x0001;
    public static final int exDiscReasonAPIInitiatedLogoff = 0x0002;
    public static final int exDiscReasonServerIdleTimeout = 0x0003;
    public static final int exDiscReasonServerLogonTimeout = 0x0004;
    public static final int exDiscReasonReplacedByOtherConnection = 0x0005;
    public static final int exDiscReasonOutOfMemory = 0x0006;
    public static final int exDiscReasonServerDeniedConnection = 0x0007;
    public static final int exDiscReasonServerDeniedConnectionFips = 0x0008;
    public static final int exDiscReasonLicenseInternal = 0x0100;
    public static final int exDiscReasonLicenseNoLicenseServer = 0x0101;
    public static final int exDiscReasonLicenseNoLicense = 0x0102;
    public static final int exDiscReasonLicenseErrClientMsg = 0x0103;
    public static final int exDiscReasonLicenseHwidDoesntMatchLicense = 0x0104;
    public static final int exDiscReasonLicenseErrClientLicense = 0x0105;
    public static final int exDiscReasonLicenseCantFinishProtocol = 0x0106;
    public static final int exDiscReasonLicenseClientEndedProtocol = 0x0107;
    public static final int exDiscReasonLicenseErrClientEncryption = 0x0108;
    public static final int exDiscReasonLicenseCantUpgradeLicense = 0x0109;
    public static final int exDiscReasonLicenseNoRemoteConnections = 0x010a;
    
    static Logger logger = Logger.getLogger("net.propero.rdp");

	static boolean keep_running;

	static boolean loggedon;

	static boolean readytosend;

	static boolean showTools;

	static final String keyMapPath = "keymaps/";

	static String mapFile = "en-gb";

	static String keyMapLocation = "";

	static SendEvent toolFrame = null;
    

	/**
	 * Outputs version and usage information via System.err
	 * 
	 */
	public static void usage() {
		System.err.println("properJavaRDP version " + Version.version);
		System.err.println("Usage: java net.propero.rdp.Rdesktop [options] server[:port]");
		System.err.println("	-b 							bandwidth saving (good for 56k modem, but higher latency");
		System.err.println("	-c DIR						working directory");
		System.err.println("	-d DOMAIN					logon domain");
		System.err.println("	-f[l]						full-screen mode [with Linux KDE optimization]");
		System.err.println("	-g WxH						desktop geometry");
		System.err.println("	-m MAPFILE					keyboard mapping file for terminal server");
		System.err.println("	-l LEVEL					logging level {DEBUG, INFO, WARN, ERROR, FATAL}");
		System.err.println("	-n HOSTNAME					client hostname");
		System.err.println("	-p PASSWORD					password");
		System.err.println("	-s SHELL					shell");
		System.err.println("	-t NUM						RDP port (default 3389)");
		System.err.println("	-T TITLE					window title");
		System.err.println("	-u USERNAME					user name");
		System.err.println("	-o BPP						bits-per-pixel for display");
        System.err.println("    -r path                     path to load licence from (requests and saves licence from server if not found)");
        System.err.println("    --save_licence              request and save licence from server");
        System.err.println("    --load_licence              load licence from file");
        System.err.println("    --console                   connect to console");
		System.err.println("	--debug_key 				show scancodes sent for each keypress etc");
		System.err.println("	--debug_hex 				show bytes sent and received");
		System.err.println("	--no_remap_hash 			disable hash remapping");
		System.err.println("	--quiet_alt 				enable quiet alt fix");
		System.err.println("	--no_encryption				disable encryption from client to server");
		System.err.println("	--use_rdp4					use RDP version 4");
        //System.err.println("    --enable_menu               enable menu bar");
        System.err.println("	--log4j_config=FILE			use FILE for log4j configuration");
        System.err.println("Example: java net.propero.rdp.Rdesktop -g 800x600 -l WARN m52.propero.int");
		Rdesktop.exit(0, null, null, true);
	}
  
  
	/**
	 * 
	 * @param args
	 * @throws OrderException
	 * @throws RdesktopException
	 */
	public static void main(String[] args) throws OrderException,
			RdesktopException {
        
        // Ensure that static variables are properly initialised
        keep_running = true;
        loggedon = false;
        readytosend = false;
        showTools = false;
        mapFile = "en-gb";
        keyMapLocation = "";
        toolFrame = null;

		BasicConfigurator.configure();
		logger.setLevel(Level.INFO);

		// Attempt to run a native RDP Client

		RDPClientChooser Chooser = new RDPClientChooser();

		if (Chooser.RunNativeRDPClient(args)) {
            if(!Common.underApplet) System.exit(0);
		}

		// Failed to run native client, drop back to Java client instead.

		// parse arguments

		int logonflags = Rdp.RDP_LOGON_NORMAL;

		boolean fKdeHack = false;
		int c;
		String arg;
		StringBuffer sb = new StringBuffer();
		LongOpt[] alo = new LongOpt[15];
		alo[0] = new LongOpt("debug_key", LongOpt.NO_ARGUMENT, null, 0);
		alo[1] = new LongOpt("debug_hex", LongOpt.NO_ARGUMENT, null, 0);
		alo[2] = new LongOpt("no_paste_hack", LongOpt.NO_ARGUMENT, null, 0);
		alo[3] = new LongOpt("log4j_config", LongOpt.REQUIRED_ARGUMENT, sb, 0);
		alo[4] = new LongOpt("packet_tools", LongOpt.NO_ARGUMENT, null, 0);
		alo[5] = new LongOpt("quiet_alt", LongOpt.NO_ARGUMENT, sb, 0);
		alo[6] = new LongOpt("no_remap_hash", LongOpt.NO_ARGUMENT, null, 0);
		alo[7] = new LongOpt("no_encryption", LongOpt.NO_ARGUMENT, null, 0);
		alo[8] = new LongOpt("use_rdp4", LongOpt.NO_ARGUMENT, null, 0);
		alo[9] = new LongOpt("use_ssl", LongOpt.NO_ARGUMENT, null, 0);
        alo[10] = new LongOpt("enable_menu", LongOpt.NO_ARGUMENT, null, 0);
        alo[11] = new LongOpt("console", LongOpt.NO_ARGUMENT, null, 0);
        alo[12] = new LongOpt("load_licence", LongOpt.NO_ARGUMENT, null, 0);
        alo[13] = new LongOpt("save_licence", LongOpt.NO_ARGUMENT, null, 0);
        alo[14] = new LongOpt("persistent_caching", LongOpt.NO_ARGUMENT, null, 0);
        
		String progname = "properJavaRDP";

		Getopt g = new Getopt("properJavaRDP", args,
				"bc:d:f::g:k:l:m:n:p:s:t:T:u:o:r:", alo);

		ClipChannel clipChannel = new ClipChannel();

		while ((c = g.getopt()) != -1) {
			switch (c) {

			case 0:
				switch (g.getLongind()) {
				case 0:
					Options.debug_keyboard = true;
					break;
				case 1:
					Options.debug_hexdump = true;
					break;
				case 2:
					break;
				case 3:
					arg = g.getOptarg();
					PropertyConfigurator.configure(arg);
					logger.info("Log4j using config file " + arg);
					break;
				case 4:
					showTools = true;
					break;
				case 5:
					Options.altkey_quiet = true;
					break;
				case 6:
					Options.remap_hash = false;
					break;
				case 7:
					Options.packet_encryption = false;
					break;
				case 8:
					Options.use_rdp5 = false;
					//Options.server_bpp = 8;
					Options.set_bpp(8);
					break;
				case 9:
					Options.use_ssl = true;
					break;
                case 10:
                    Options.enable_menu = true;
                    break;
                case 11:
                    Options.console_session = true;
                    break;
                case 12:
                    Options.load_licence = true;
                    break;
                case 13:
                    Options.save_licence = true;
                    break;
                case 14:
                    Options.persistent_bitmap_caching = true;
                    break;
				default:
					usage();
				}
				break;

			case 'o':
				Options.set_bpp(Integer.parseInt(g.getOptarg()));
				break;
			case 'b':
				Options.low_latency = false;
				break;
			case 'm':
				mapFile = g.getOptarg();
				break;
			case 'c':
				Options.directory = g.getOptarg();
				break;
			case 'd':
				Options.domain = g.getOptarg();
				break;
			case 'f':
				Dimension screen_size = Toolkit.getDefaultToolkit()
						.getScreenSize();
				// ensure width a multiple of 4
				Options.width = screen_size.width & ~3;
				Options.height = screen_size.height;
				Options.fullscreen = true;
				arg = g.getOptarg();
				if (arg != null) {
					if (arg.charAt(0) == 'l')
						fKdeHack = true;
					else {
						System.err.println(progname
								+ ": Invalid fullscreen option '" + arg + "'");
						usage();
					}
				}
				break;
			case 'g':
				arg = g.getOptarg();
				int cut = arg.indexOf("x", 0);
				if (cut == -1) {
					System.err.println(progname + ": Invalid geometry: " + arg);
					usage();
				}
				Options.width = Integer.parseInt(arg.substring(0, cut)) & ~3;
				Options.height = Integer.parseInt(arg.substring(cut + 1));
				break;
			case 'k':
				arg = g.getOptarg();
				//Options.keylayout = KeyLayout.strToCode(arg);

⌨️ 快捷键说明

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