📄 gtavirtualhostudp.java
字号:
/*
* Created on Feb 15, 2006
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package org.GTADS.proxy;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
/**
* @author sday
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class GTAVirtualHostUDP extends Thread{
public static GTAVirtualHostUDP instance;
private DatagramSocket virtualUDPHostSocket;
private int listenPort = 2351;
private int sendPort = 2350;
private byte[] udpData = new byte[256];
private boolean initial = true;
public static GTAVirtualHostUDP getInstance(){
if (instance == null){
instance = new GTAVirtualHostUDP();
}
return instance;
}
public static void clearInstance(){
if (instance != null){
if (instance.virtualUDPHostSocket != null){
instance.virtualUDPHostSocket.close();
}
instance.stop();
instance = null;
}
}
public GTAVirtualHostUDP (){
// if (Proxy.isSpecial){
// listenPort = 2350;
// sendPort = 2351;
// }
start();
}
public void run(){
byte[] buffer = new byte[256];
DatagramPacket p = new DatagramPacket(buffer, buffer.length);
try {
virtualUDPHostSocket = new DatagramSocket(listenPort);
while (true){
// During gameplay take all UDP Packets recieved from game
// and send them to remote player
virtualUDPHostSocket.receive(p);
Proxy.getInstance().sendUDPClientData(Proxy.getByteOffset(p.getData(),0,p.getLength()));
}
} catch (IOException ioe){
return;
}
}
public void sendUDPDataToGame(byte[] data) throws IOException {
if (initial){
initial = false;
virtualUDPHostSocket.connect(InetAddress.getByName("localhost"), sendPort);
}
try {
Thread.sleep(1);
DatagramPacket p = new DatagramPacket(data,data.length);
virtualUDPHostSocket.send(p);
} catch (InterruptedException ie) {
return;
}
}
public void processVHostUDP(byte[] data) throws IOException {
sendUDPDataToGame(data);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -