Make launch script run it headless. Probably should be an option, w/e. Also patch file of my commits

This commit is contained in:
2025-11-20 20:58:47 +11:00
parent dbca745f05
commit 43b44f8171
2 changed files with 167 additions and 1 deletions

View File

@@ -0,0 +1,166 @@
diff --git a/launch.sh b/launch.sh
index 8ee709f..cd08c89 100755
--- a/launch.sh
+++ b/launch.sh
@@ -1,2 +1,2 @@
rm cls/connect2/*.class
-javac -source 1.6 -target 1.6 -classpath src -d cls src/connect2/Main.java && java -classpath cls connect2.Main
+javac -source 1.8 -target 1.8 -classpath src -d cls src/connect2/Main.java && java -classpath cls connect2.Main $*
diff --git a/src/connect2/ECHost.java b/src/connect2/ECHost.java
index a77977d..b4551c0 100644
--- a/src/connect2/ECHost.java
+++ b/src/connect2/ECHost.java
@@ -40,17 +40,27 @@ public class ECHost implements Runnable {
boolean terminated = false;
- public ECHost(int war3Version, String name, String sessionKey) {
+ public ECHost(int war3Version, String name, String sessionKey)
+ {
+ this(war3Version, name, sessionKey, "");
+ }
+ public ECHost(int war3Version, String name, String sessionKey, String broadcastIp) {
this.war3version = war3Version;
this.name = name;
this.sessionKey = sessionKey;
udpTargets = new ArrayList<SocketAddress>();
- try {
- udpTargets.add(new InetSocketAddress(InetAddress.getLocalHost(), 6112));
- udpTargets.add(new InetSocketAddress("255.255.255.255", 6112));
- } catch(UnknownHostException uhe) {
- System.out.println("[ECHost] UDP broadcast target error: " + uhe.getLocalizedMessage());
+ if (broadcastIp!="")
+ {
+ udpTargets.add(new InetSocketAddress(broadcastIp, 6112));
+ }
+ else
+ {
+ try {
+ udpTargets.add(new InetSocketAddress(InetAddress.getLocalHost(), 6112));
+ } catch(UnknownHostException uhe) {
+ System.out.println("[ECHost] UDP broadcast target error: " + uhe.getLocalizedMessage());
+ }
}
this.games = new HashMap<Integer, GameInfo>();
diff --git a/src/connect2/GuiApp.java b/src/connect2/GuiApp.java
index ca409e5..44d9270 100644
--- a/src/connect2/GuiApp.java
+++ b/src/connect2/GuiApp.java
@@ -9,8 +9,15 @@ import java.net.URI;
public class GuiApp implements ActionListener {
JButton launchBtn, exitBtn;
+ int port;
- public GuiApp(){
+ public GuiApp()
+ {
+ this(8333);
+ }
+ public GuiApp(int port)
+ {
+ this.port=port;
JFrame frame = new JFrame("WC3Connect-Java");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.launchBtn = new JButton("Launch");
@@ -22,7 +29,7 @@ public class GuiApp implements ActionListener {
if(!Desktop.isDesktopSupported() || !Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)){
this.launchBtn.setEnabled(false);
- this.launchBtn.setText("Open your webbrowser and go to: 127.0.0.1:8033");
+ this.launchBtn.setText("Open your webbrowser and go to: http://localhost:"+this.port+"/");
}
frame.getContentPane().add(this.launchBtn, BorderLayout.PAGE_START);
@@ -34,7 +41,7 @@ public class GuiApp implements ActionListener {
private void launch(){
try {
- Desktop.getDesktop().browse(URI.create("http://127.0.0.1:8333"));
+ Desktop.getDesktop().browse(URI.create("http://localhost:"+this.port+"/"));
} catch (IOException e1) {
e1.printStackTrace();
}
diff --git a/src/connect2/Main.java b/src/connect2/Main.java
index 06dd1fc..e4b2642 100644
--- a/src/connect2/Main.java
+++ b/src/connect2/Main.java
@@ -10,16 +10,21 @@ public class Main {
public static int Version = 2018102602;
public static void main(String[] args) throws java.io.IOException {
+ int port;
+ String broadcastIp;
+ if (args.length<2) {broadcastIp="";} else {broadcastIp=args[1];}
+ if (args.length<1) {port=8333;} else {port=Integer.parseInt(args[0]);}
+
ThirdPartyBotMap.put("192.99.6.98", "MMH-USA");
ThirdPartyBotMap.put("85.10.199.252", "MMH-Euro");
new Thread(new LoadThirdPartyThread()).start();
- new Web();
+ new Web(port,broadcastIp);
if(!GraphicsEnvironment.isHeadless()){
- new GuiApp();
+ new GuiApp(port);
} else {
- System.out.println("Open your webbrowser and go to: 127.0.0.1:8033");
+ System.out.println("Open your web browser and go to: http://localhost:"+port+"/");
}
}
diff --git a/src/connect2/Web.java b/src/connect2/Web.java
index ea0214d..4113770 100644
--- a/src/connect2/Web.java
+++ b/src/connect2/Web.java
@@ -24,7 +24,17 @@ public class Web {
private ECHost host = null;
private ECList list = null;
- public Web() throws IOException {
+ public String broadcastIp;
+
+ public Web() throws IOException
+ {
+ this(8333);
+ }
+ public Web(int port) throws IOException
+ {
+ this(port,"");
+ }
+ public Web(int port, String broadcastIp) throws IOException {
if(Main.Debug) {
Logger logger = Logger.getLogger("com.sun.net.httpserver");
ConsoleHandler ch = new ConsoleHandler();
@@ -32,7 +42,7 @@ public class Web {
ch.setLevel(Level.FINER);
logger.addHandler(ch);
}
- HttpServer server = HttpServer.create(new InetSocketAddress(8333), 0);
+ HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
server.createContext("/", new FileHandler());
server.createContext("/login", new LoginHandler(this));
server.createContext("/signup", new SignupHandler());
@@ -44,7 +54,9 @@ public class Web {
server.createContext("/validate", new ValidateHandler(this));
server.setExecutor(null);
server.start();
- System.out.println("[web] started on :8333");
+ System.out.println("[web] started on :"+port);
+
+ this.broadcastIp=broadcastIp;
}
static Map<String, String> getPostForm(HttpExchange httpExchange) throws IOException {
@@ -239,7 +251,7 @@ public class Web {
synchronized(web) {
web.loginResult = new LoginResult(obj.getInt("war3version"), obj.getString("name"), obj.getString("session_key2"));
if(web.host == null) {
- web.host = new ECHost(web.loginResult.war3Version, web.loginResult.name, web.loginResult.sessionKey);
+ web.host = new ECHost(web.loginResult.war3Version, web.loginResult.name, web.loginResult.sessionKey, web.broadcastIp);
web.host.init();
} else {
web.host.update(web.loginResult.war3Version, web.loginResult.name, web.loginResult.sessionKey);

View File

@@ -1,2 +1,2 @@
rm cls/connect2/*.class
javac -source 1.8 -target 1.8 -classpath src -d cls src/connect2/Main.java && java -classpath cls connect2.Main $*
javac -source 1.8 -target 1.8 -classpath src -d cls src/connect2/Main.java && DISPLAY= java -classpath cls connect2.Main $*