📄 gtavirtualplayerudp.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.*;
/**
* @author sday
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class GTAVirtualPlayerUDP extends Thread{
public static GTAVirtualPlayerUDP instance;
private DatagramSocket virtualUDPPlayerSocket;
private DatagramSocket virtualUDPSenderSocket;
private int listenPort = 2350;
private int sendPort = 2351;
private byte[] udpData = new byte[256];
private boolean initial = true;
public static GTAVirtualPlayerUDP getInstance() throws IOException{
if (instance == null){
instance = new GTAVirtualPlayerUDP();
}
return instance;
}
public static void clearInstance(){
if (instance != null){
if (instance.virtualUDPPlayerSocket != null)
instance.virtualUDPPlayerSocket.close();
if (instance.virtualUDPSenderSocket != null)
instance.virtualUDPSenderSocket.close();
instance = null;
}
}
public GTAVirtualPlayerUDP() throws IOException{
virtualUDPPlayerSocket = new DatagramSocket();
// listenPort = 2351;
// sendPort = 2350;
start();
}
public void run(){
byte[] buffer = new byte[256];
DatagramPacket p = new DatagramPacket(buffer, buffer.length);
try {
virtualUDPPlayerSocket = new DatagramSocket(listenPort);
while (true){
// During gameplay take all UDP Packets recieved from game
// and send them to remote player
virtualUDPPlayerSocket.receive(p);
Proxy.getInstance().sendUDPHostData(Proxy.getByteOffset(p.getData(),0,p.getLength()));
//System.out.println("Sending UDP Game data over proxy");
}
} catch (IOException ioe){
return;
}
}
public void sendUDPDataToGame(byte[] data) throws IOException {
if (initial){
initial = false;
virtualUDPPlayerSocket.connect(InetAddress.getByName("localhost"), sendPort);
}
try {
Thread.sleep(1);
DatagramPacket p = new DatagramPacket(data,data.length);
virtualUDPPlayerSocket.send(p);
//System.out.println("Sending UDP Game Data to game");
} catch (InterruptedException ie){
return;
}
}
public void processVPlayerUDP(byte[] data) throws IOException {
sendUDPDataToGame(data);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -