Skip to content

Commit

Permalink
Add command line argument parsing to server and client
Browse files Browse the repository at this point in the history
- Add port option
- Separate launcher code into their own class.
  • Loading branch information
pehala committed Sep 4, 2020
1 parent 527049f commit 82c03e6
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 446 deletions.
17 changes: 17 additions & 0 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,30 @@
<version>3.6.6.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- Build CLI model on the compile time instead on the runtime -->
<configuration>
<annotationProcessorPaths>
<path>
<groupId>info.picocli</groupId>
<artifactId>picocli-codegen</artifactId>
<version>${picocli.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-Aproject=${project.groupId}/${project.artifactId}</arg>
</compilerArgs>
</configuration>
</plugin>

<plugin>
Expand Down
109 changes: 109 additions & 0 deletions client/src/main/java/org/moparforia/client/Game.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package org.moparforia.client;

import agolf.AGolf;

import javax.swing.*;
import java.applet.Applet;
import java.applet.AppletContext;
import java.applet.AppletStub;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

public class Game {
private static final int WIDTH = 735;
private static final int HEIGHT = 525;

public Game(JFrame frame, String server, int port, String lang, boolean verbose) {
Applet game = new AGolf();


game.setStub(new Stub(server, lang, port, verbose));
game.setSize(WIDTH, HEIGHT);
game.init();
game.start();
frame.add(game);
frame.setSize(WIDTH + 20, HEIGHT + 40);
frame.setResizable(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

class Stub implements AppletStub {
private final Map<String, String> params;
private String server;

public Stub(String server, String lang, int port, boolean verbose) {
this.server = server;
params = new HashMap<String, String>();
params.put("initmessage", "Loading game...");
params.put("ld_page", "javascript:Playray.Notify.delegate({ jvm: { version: '%v', vendor: '%w', t1: '%r', t2: '%f' } })");
params.put("image", "/appletloader_playforia.gif");
/*if(serverBox.isSelected()) {
params.put("server", "149.255.111.161" + ":" + g.port);
} else {
params.put("server", "game05.playforia.net" + ":" + g.port);
}*/
params.put("server", server + ":" + port);
//params.put("server", "192.168.1.23:" + g.port);

//params.put("locale", "en");
//params.put("lang", en_US);

params.put("locale", lang.substring(0, 2)); //use first part of en_US, fi_FI or sv_SE
params.put("lang", lang);
params.put("sitename", "playray");
params.put("quitpage", "http://www.playforia.com/games/");
params.put("regremindshowtime", "3,8,15,25,50,100,1000");
params.put("registerpage", "http://www.playforia.com/account/create/");
params.put("creditpage", "http://www.playforia.com/shop/buy/");
params.put("userinfopage", "http://www.playforia.com/community/user/");
params.put("userinfotarget", "_blank");
params.put("userlistpage", "javascript:Playray.GameFaceGallery('%n','#99FF99','agolf','%s')");
params.put("guestautologin", "true");
params.put("disableguestlobbychat", "true");
params.put("json", "Playray.Notify.delegate(%o)");
params.put("centerimage", "true");
params.put("java_arguments", "-Xmx128m");
params.put("localizationUrl", "");
params.put("sharedLocalizationUrl", "");
params.put("verbose", Boolean.toString(verbose));

//if(serverBox.isSelected())
//params.put("tracktestmode", "true");
//params.put("session", "7vkBHjUIcQKg-J,c2bXzYdy,lJd");
//params.put("sessionlang", "en");
}

public boolean isActive() {
return true;
}

public URL getDocumentBase() {
try {
return new URL("http://" + this.server + "/AGolf/");
} catch (Exception ex) {
System.err.println("getdocumentbase exc eption");
return null;
}
}

public URL getCodeBase() {
return getDocumentBase();
}

public String getParameter(String name) {
if (!params.containsKey(name))
return "";
return params.get(name);
}

public AppletContext getAppletContext() {
return null;
}


public void appletResize(int width, int height) {
}
}
}
Loading

0 comments on commit 82c03e6

Please sign in to comment.