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

📄 proxygui.java

📁 是一款国外的网络游戏平台的源码*不是类似浩方那种虚拟局域网技术
💻 JAVA
字号:
/*
 * Created on Oct 16, 2005
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package org.GTADS.proxy;

import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.net.ServerSocket;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JFrame;

import org.GTADS.client.ClientLoginScreen;
import org.GTADS.client.DSChatClient;
import org.GTADS.client.DialogManager;
import org.GTADS.client.GameroomWindowDialog;
import org.GTADS.debug.*;
import org.GTADS.messenger.MessageAdapter;
import org.GTADS.protocol.MetaData;
import org.GTADS.client.swing.*;

/**
 * @author sday
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class ProxyGUI extends GTADSFrame implements ActionListener{
	public static ProxyGUI instance;
	private GTADSTextField ipAddressBox = new GTADSTextField();
	private GTADSCheckBox hostOnly = new GTADSCheckBox();
	private GTADSButton startProxy = new GTADSButton();
	private GTADSLabel statusLabel = new GTADSLabel();
	private GTADSPanel mainProxyPanel = new GTADSPanel();
	private GTADSPanel proxyPanel1 = new GTADSPanel();
	private GTADSPanel proxyPanel2 = new GTADSPanel();
	private GTADSPanel proxyPanel3 = new GTADSPanel();
	private GTADSLabel hostOnlyLabel = new GTADSLabel("Host IP");
	
	private boolean proxyStarted = false;
	private boolean isHostOnly = false;
	public boolean isStandAlone = true;
	public CodeTime ct = new CodeTime();
	
	public static String PROXY_READY = "Proxy Ready";
	public static String PROXY_LISTENING = "Proxy Listening...";
	
	
	public static ProxyGUI getInstance(){
		synchronized(ProxyGUI.class){
			if (instance == null){
				instance = new ProxyGUI();
			}
		}
		return instance;
	}
	
	public static ProxyGUI getInstance(String IPAddress){
		if (instance == null){
			instance = new ProxyGUI(IPAddress);
		}
		return instance;
	}
	
	public static void clearInstance() {
			if (instance != null){
				if (instance.proxyStarted){
					instance.pressStartProxyButton();
				}
				Proxy.clearInstance();
				instance.hide();
				instance.dispose();
				instance = null;
			}
	}
	
	ProxyGUI() {
		init();
	}
	
	public ProxyGUI(String IPAddress){
		isStandAlone = false;
		init();
		if (IPAddress == null){
			hostOnly.setSelected(true);
			isHostOnly = true;
			pressStartProxyButton();
		}
		else {
			ipAddressBox.setText(IPAddress);
		}
	}
	
	private void setUpComponents(){
		ipAddressBox.setColumns(20);
		startProxy.setText("Start");
		statusLabel.setText(PROXY_READY);
		proxyPanel1.add(hostOnlyLabel);
		proxyPanel1.add(ipAddressBox);
		proxyPanel2.add(new GTADSLabel("Host Only"));
		proxyPanel2.add(hostOnly);
		proxyPanel2.add(Box.createHorizontalStrut(10));
		proxyPanel2.add(statusLabel);
		proxyPanel3.add(Box.createHorizontalStrut(25));
		proxyPanel3.add(startProxy);
		
		
		hostOnly.addActionListener(this);
		startProxy.addActionListener(this);
		
		
	}
	private void init(){
		mainProxyPanel.setLayout(new BoxLayout(mainProxyPanel, BoxLayout.Y_AXIS));
		proxyPanel1.setLayout(new FlowLayout(FlowLayout.LEFT));
		proxyPanel2.setLayout(new FlowLayout(FlowLayout.LEFT));
		proxyPanel3.setLayout(new FlowLayout(FlowLayout.LEFT));
		
		//this.setSize(500,500);
		this.setTitle("GTADS Proxy");
		if (isStandAlone)
			this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		else
			this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		
		this.addWindowListener(new WindowAdapter() {
			public void windowClosed(WindowEvent e){
				ProxyGUI.clearInstance();
			}
		});
		
		setUpComponents();
		mainProxyPanel.add(proxyPanel1);
		mainProxyPanel.add(proxyPanel2);
		mainProxyPanel.add(proxyPanel3);

		setContentPane(mainProxyPanel);
		pack();
		
		show();
	}
	
	public void actionPerformed(ActionEvent e){
		if (e.getSource().equals(hostOnly)){
				isHostOnly = !isHostOnly;
				
				if (isHostOnly){
					this.ipAddressBox.setVisible(false);
					this.hostOnlyLabel.setVisible(false);
					ipAddressBox.setText("");
					ipAddressBox.enable(false);
				}
				else {
					this.ipAddressBox.setVisible(true);
					this.hostOnlyLabel.setVisible(true);
					ipAddressBox.enable(true);
				}
		}
		if (e.getSource().equals(startProxy)){
			pressStartProxyButton();
		}
	}
	
	public void pressStartProxyButton(){
		proxyStarted = !proxyStarted;
		if (proxyStarted){
			startProxy.setText("Stop");
			try {
				if (!isStandAlone){
					if (isHostOnly && proxyStarted){
						this.ipAddressBox.setVisible(false);
						this.hostOnlyLabel.setVisible(false);
						MetaData hostIsReady = new MetaData(ClientLoginScreen.getInstance().getUsername(),
								MetaData.GAME, MetaData.HOST_READY);
						MessageAdapter.sendData(null,DSChatClient.ClientSocket,hostIsReady,
								GameroomWindowDialog.getInstance().getGameroomName());
					}
					else {
						killDirectPlay();
						this.ipAddressBox.setVisible(true);
						this.hostOnlyLabel.setVisible(true);
					}
				}
				Proxy.getInstance();
			} catch (IOException ioe){
				pressStartProxyButton();
			}
		}
		else {
			startProxy.setText("Start");
			if (isHostOnly && !proxyStarted){
				try {
				MetaData hostIsReady = new MetaData(ClientLoginScreen.getInstance().getUsername(),
						MetaData.GAME, MetaData.STOP_PROXY);
				MessageAdapter.sendData(null,DSChatClient.ClientSocket,hostIsReady,
						GameroomWindowDialog.getInstance().getGameroomName());
				} catch (IOException ioe){
				}
			}
			Proxy.clearInstance();
		}
	}
	
	private void killDirectPlay() throws IOException{
		// As a workaround until We can get a 3rd party app/lib to kill the
		// dplaysvr.exe we need to just issue a dialog box
		try {
		ServerSocket directPlayTest = new ServerSocket(47624);
		} catch (IOException ioe){
			DialogManager.ErrorDialog("Process dplaysvr.exe (dplaysrv) is running\n Please kill process and try again");
			throw ioe;
		}
		
//		String windows_XP = "5.1";
//		String windows_2000 = "5.0";
//		String windowsVersion = System.getProperty("os.version");
//		
//		try {
//			if (windowsVersion.equalsIgnoreCase(windows_XP)){
//				String[] killDplaySrv = {"tskill.exe", "dplaysvr"};
//				Process child = Runtime.getRuntime().exec(killDplaySrv);
//				child.waitFor();
//			}
//			else if (windowsVersion.equalsIgnoreCase(windows_2000)){
//				String[] killDplaySrv = {"ntsd.exe", "-pn", "\"dplaysvr.exe\"", "-c", "\"q\""};
//				Process child = Runtime.getRuntime().exec(killDplaySrv);
//				child.waitFor();
//			}
//			
//		} catch (IOException ioe) {
//			ioe.printStackTrace();
//			//				 output your exception here...
//		} catch (InterruptedException ie) {
//			//				 output your exception here...
//		}
	}
	
	public boolean isProxyHosting(){
		return isHostOnly;
	}
	
	public static void main(String[] args) {
		ProxyGUI.getInstance();
	}
	
	public void setStatusLabel(String s){
		statusLabel.setText(s);
	}
	
	public String getIpAddress(){
		return ipAddressBox.getText();
	}
}

⌨️ 快捷键说明

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