diff --git a/client/pom.xml b/client/pom.xml index a3389d1f..d4a7ab8c 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -25,6 +25,10 @@ 3.6.6.Final compile + + info.picocli + picocli + @@ -32,6 +36,19 @@ org.apache.maven.plugins maven-compiler-plugin + + + + + info.picocli + picocli-codegen + ${picocli.version} + + + + -Aproject=${project.groupId}/${project.artifactId} + + diff --git a/client/src/main/java/org/moparforia/client/Game.java b/client/src/main/java/org/moparforia/client/Game.java new file mode 100644 index 00000000..f7be8e2a --- /dev/null +++ b/client/src/main/java/org/moparforia/client/Game.java @@ -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 params; + private String server; + + public Stub(String server, String lang, int port, boolean verbose) { + this.server = server; + params = new HashMap(); + 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) { + } + } +} diff --git a/client/src/main/java/org/moparforia/client/Launcher.java b/client/src/main/java/org/moparforia/client/Launcher.java index ac1fa563..039c53fb 100644 --- a/client/src/main/java/org/moparforia/client/Launcher.java +++ b/client/src/main/java/org/moparforia/client/Launcher.java @@ -1,28 +1,43 @@ package org.moparforia.client; -import agolf.AGolf; +import picocli.CommandLine; +import javax.imageio.ImageIO; import javax.swing.*; -import java.applet.Applet; -import java.applet.AppletContext; -import java.applet.AppletStub; import java.awt.*; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import java.util.TreeMap; +import java.text.ParseException; +import java.util.concurrent.Callable; /** * Playforia * 28.5.2013 */ -public class Launcher extends JFrame { - - private static Launcher instance; - private Applet game; - private Map gaemz; - private String selectedGame; - private JCheckBox serverBox; +@CommandLine.Command( + description = "Starts Minigolf Client", + name = "client", mixinStandardHelpOptions = true +) +public class Launcher implements Callable { + + private static final String DEFAULT_SERVER = "127.0.0.1"; + private static final int DEFAULT_PORT = 4242; + + // CLI options + @CommandLine.Option(names = {"--hostname", "-ip"}, + description = "Sets server hostname", + defaultValue = "") + private String hostname; + + @CommandLine.Option(names = {"--port", "-p"}, + description = "Sets server port", + defaultValue = "0") + private int port; + + @CommandLine.Option(names = {"--lang", "-l"}, + description = "Sets language of the game, available values: ${COMPLETION-CANDIDATES}", + defaultValue = "EN_US") + private Language lang; + + @CommandLine.Option(names = {"--verbose", "-v"}, description = "Set if you want verbose information") private static boolean verbose = false; public static boolean debug() { @@ -33,358 +48,50 @@ public static boolean isUsingCustomServer() { return true;//instance.serverBox.isSelected(); } - private int[] decodeCoords(String input) { - int result = Integer.valueOf(input, 36); - return new int[] { - result / 4 / 375, - result / 4 % 375, - result % 4 - }; - } - - private static String encodeCoords(int x, int y, int mod) { - int var4 = x * 375 * 4 + y * 4 + mod;//mod.. or something, possible values 0..3 - - String out; - for (out = Integer.toString(var4, 36); out.length() < 4; out = "0" + out) { - ; - } - - return out; - } - - public static void main(String[] args) throws Exception { - /*Pattern p = Pattern.compile("(game|lobby)\\t(challenge|accept|cancel|cfail|nc)\\t(t|f|refuse|[ -~]+)(?:\\t)?(\\d+)?(?:\\t)?(\\d+)?(?:\\t)?(\\d+)?(?:\\t)?(\\d+)?(?:\\t)?(\\d+)?(?:\\t)?(\\d+)?(?:\\t)?(\\d+)?(?:\\t)?(\\d+)?"); - System.out.println(p.matcher("lobby\tchallenge\t~Guest6171\t10\t1\t20\t60\t0\t1\t0\t0").matches()); - System.out.println(p.matcher("lobby\tcfail\trefuse").matches()); - System.out.println(p.matcher("lobby\tcancel\t~Guest6171").matches()); - System.out.println(p.matcher("lobby\taccept\t~Guest6171").matches()); - System.out.println(p.matcher("lobby\tnc\tt").matches()); - System.out.println(p.matcher("lobby\tnc\tf").matches()); - Matcher m = p.matcher("lobby\tchallenge\t~Guest6171\t10\t1\t20\t60\t0\t1\t0\t0"); - System.out.println(m.matches()); - for(int i = 1; i < m.groupCount(); i++) - System.out.println(m.group(i)); - */ - - //easily editable optional client launch options, at the moment supports custom server ip and language pack - //example: client.jar -server 125.456.789.123 -lang en_US - - String server = "127.0.0.1"; //dafault server ip - String lang = "en_US"; //dafault language package (comes with en_US, fi_FI and sv_SE) - - if(args.length==1){ //support for "legacy" .bats where only ip provided after jar - server=args[0]; - } - - for(int i = 0;ii+1){//finds -server launch option and checks that there is actually something after it - server = args[i+1]; //grabs the next string after -server - i++; - } - if(args[i].equals("-lang") && args.length>i+1){//finds -lang launch option and checks that there is actually something after it - lang = args[i+1]; //grabs the next string after -lang - i++; - } - if(args[i].equals("-verbose")){//finds -lang launch option and checks that there is actually something after it - verbose = true; - } - } - - instance = new Launcher(server,lang); //now provides language pack too - } - - static class ConnCipher { - - private int seed; - private int magic; - private int[][] randomsAscii; - private int[][] randomsOther; - - - public ConnCipher(int magic) { - this.magic = magic;// :-) - this.seed = -1; - this.randomsAscii = new int[2][125]; - this.randomsOther = new int[2][1920]; - } - - public void initialise(int newSeed) { - this.seed = newSeed; - - for (int i = 1; i <= 125; ++i) { - this.randomsAscii[1][i - 1] = -1; - } - - for (int i = 128; i <= 2047; ++i) { - this.randomsOther[1][i - 128] = -1; - } - - ConnRandom random = new ConnRandom((long) newSeed); - - int rand; - for (int index = 1; index <= 125;) { - rand = random.nextInt(1, 125); - while(this.randomsAscii[1][rand - 1] >= 0) { - rand = random.nextInt(1, 125); - } - this.randomsAscii[0][index - 1] = rand; - this.randomsAscii[1][rand - 1] = index; - index++; - } - - for (int index = 128; index <= 2047;) { - rand = random.nextInt(128, 2047); - while(this.randomsOther[1][rand - 128] >= 0) { - rand = random.nextInt(128, 2047); - } - this.randomsOther[0][index - 128] = rand; - this.randomsOther[1][rand - 128] = index; - index++; - } - - } - - protected void reset() { - this.seed = -1; - } - - public String encrypt(String input) { - if (this.seed == -1) { - return input; - } else { - char[] inputChars = input.toCharArray(); - int inputLength = inputChars.length; - StringBuilder output = new StringBuilder(inputLength + 2); - int firstRandom = (int) (1.0D + Math.random() * 125.0D); - int lastRandom = (int) (1.0D + Math.random() * 125.0D); - int randMod = magicMod(firstRandom, 1, inputLength + 1);// kek - output.append((char) this.increment(firstRandom)); - int seedling = this.seed % 99 - 49 + firstRandom - lastRandom;// lolol - for (int index = 0; index < inputLength; ++index) { - if (randMod == index + 1) { - output.append((char) this.increment(lastRandom)); - } - System.out.println("encrypt index: " + index); - - int curChar = inputChars[index]; - if (curChar >= 1 && curChar <= 127) {// ascii - if (curChar != '\n' && curChar != '\r') { - curChar = this.decrement(curChar); - curChar = magicMod(curChar, seedling, 1, 125); - ++seedling; - curChar = this.randomsAscii[0][curChar - 1]; - curChar = this.increment(curChar); - if (curChar >= 14 && curChar <= 127) {// '\r' + 1 - curChar = magicMod(curChar, this.magic - 9, 14, 127); - } - } - } else if (curChar >= 128 && curChar <= 2047) {// other - curChar = magicMod(curChar, seedling, 128, 2047); - seedling += 2; - curChar = this.randomsOther[0][curChar - 128]; - } - - output.append((char) curChar); - ++seedling; - } - - if (randMod == inputLength + 1) { - output.append((char) this.increment(lastRandom)); - } - - return output.toString(); - } - } - - public String decrypt(String input) { - if (this.seed == -1) { - return input; - } else { - char[] inputChars = input.toCharArray(); - int inputLength = inputChars.length; - StringBuilder output = new StringBuilder(inputLength - 2); - int firstRandom = this.decrement(inputChars[0]); - int randMod = magicMod(firstRandom, 1, inputLength - 1); - int lastRandom = this.decrement(inputChars[randMod]); - int seedling = lastRandom - firstRandom - (this.seed % 99 - 49); - int origInputLength = randMod < inputLength - 1 ? inputLength : inputLength - 1; - - for (int index = 1; index < origInputLength; ++index) { - if (index == randMod) { - ++index; - } - System.out.println("decrypt index: " + index); - - int curChar = inputChars[index]; - if (curChar >= 1 && curChar <= 127) {// ascii - if (curChar != '\n' && curChar != '\r') { - if (curChar >= 14 && curChar <= 127) {// '\r' + 1 - curChar = magicMod(curChar, 9 - this.magic, 14, 127); - } - - curChar = this.decrement(curChar); - curChar = this.randomsAscii[1][curChar - 1]; - curChar = magicMod(curChar, seedling, 1, 125); - --seedling; - curChar = this.increment(curChar); - } - } else if (curChar >= 128 && curChar <= 2047) {// other - curChar = this.randomsOther[1][curChar - 128]; - curChar = magicMod(curChar, seedling, 128, 2047); - seedling -= 2; - } - output.append((char) curChar); - --seedling; - } - - return output.toString(); - } - } - - private int decrement(int val) { - if (val > 13) { - --val; - } - - if (val > 10) { - --val; - } - - return val; - } - - private int increment(int val) { - if (val >= 10) { - ++val; - } - - if (val >= 13) { - ++val; - } - - return val; - } - - private static int magicMod(int val1, int val2, int min, int max) { - return magicMod(val1 + val2, min, max); - } - - /* - >>> [ f(i, 1, len("HURR") + 1) for i in range(-5, 6) ] - [5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5] - */ - private static int magicMod(int val, int min, int max) {// ( °͜ʖ °) - max -= min; - val -= min; - int modulus = max + 1; - if (val > max) { - val %= modulus; - } else if (val < 0) { - int var5 = (-val - 1) / modulus + 1; - val += var5 * modulus; - } - - val += min; - return val; - } - } - - - static class ConnRandom { - - // http://www.math.utah.edu/~beebe/java/random/README - // http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/util/Random.java - private final static long multiplier = 0x5DEECE66DL; - private final static long append = 0xBL; - private final static long mask = (1L << 48) - 1; - - private long nextseed; - - // http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/util/Random.java#Random.setSeed%28long%29 - protected ConnRandom(long seed) { - this.nextseed = (seed ^ multiplier) & mask; - } - - protected int nextInt(int min, int max) { - return min + this.nextInt() % (max - min + 1); - } - - private int nextInt() { - int next = this.next(); - if (next < 0) { - next = -next; - if (next < 0) { - next = 0; - } - } - - return next; - } - - // http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/util/Random.java#Random.next%28int%29 - private int next() { - this.nextseed = this.nextseed * multiplier + append & mask; - return (int) (this.nextseed >>> 16);// next seed for 32 bits - } - } - - - private void doMagic(Object parent, Component[] c, String initialValue) { - for (int i = 0; i < c.length; i++) { - if (c[i] instanceof JPanel) { - doMagic(c[i], ((JPanel) c[i]).getComponents(), initialValue); - } else if (c[i] instanceof JComboBox) { - JComboBox comboBox = (JComboBox) c[i]; - for (int j = 0; j < comboBox.getItemCount(); j++) - if (comboBox.getItemAt(j).toString().equals(initialValue)) { - comboBox.setSelectedIndex(j); - break; - } - serverBox = new JCheckBox("Use localhost"); - System.out.println("HUHUHUHUH"); - ((JPanel) parent).add(serverBox); + public static void main(String... args) throws Exception { + Launcher launcher = new Launcher(); + try { + CommandLine.ParseResult parseResult = new CommandLine(launcher).parseArgs(args); + if (!CommandLine.printHelpIfRequested(parseResult)) { + launcher.call(); } + } catch (CommandLine.ParameterException ex) { // command line arguments could not be parsed + System.err.println(ex.getMessage()); + ex.getCommandLine().usage(System.err); } } - public Launcher(String server, String lang) { - + private boolean showSettingDialog(JFrame frame, String server, int port) throws ParseException { JPanel pane = new JPanel(); + pane.setLayout(new GridLayout(4, 1)); + final JTextField serverField = new JTextField(); JLabel serverLabel = new JLabel("Hostname:"); serverField.setText(server); - - pane.setLayout(new GridLayout(2, 1)); pane.add(serverLabel); pane.add(serverField); - int option = JOptionPane.showConfirmDialog(this,pane,"Choose a server",JOptionPane.OK_CANCEL_OPTION); - if(option == JOptionPane.OK_OPTION) { - server = serverField.getText(); - - gaemz = new TreeMap(); - gaemz.put("AGolf", new Game(server, 4242, 735, 525)); - selectedGame = "AGolf"; - game = new AGolf(); - - - game.setStub(new Stub(server,lang,verbose)); - game.setSize(gaemz.get(selectedGame).width, gaemz.get(selectedGame).height); - game.init(); - game.start(); - add(game); - setSize(gaemz.get(selectedGame).width + 20, gaemz.get(selectedGame).height + 40); - setResizable(true); - setDefaultCloseOperation(EXIT_ON_CLOSE); - setVisible(true); + JSpinner portSpinner = new JSpinner(); + portSpinner.setModel(new SpinnerNumberModel(port,1, Integer.MAX_VALUE,1)); + JSpinner.NumberEditor editor = new JSpinner.NumberEditor(portSpinner,"#"); + // Align spinner values to the left + editor.getTextField().setHorizontalAlignment(JTextField.LEFT); + portSpinner.setEditor(editor); + JLabel portLabel = new JLabel("Port:"); + pane.add(portLabel); + pane.add(portSpinner); + + int result = JOptionPane.showConfirmDialog(frame, pane, "Choose a server", JOptionPane.OK_CANCEL_OPTION); + if (result == JOptionPane.OK_OPTION) { + this.hostname = serverField.getText(); + portSpinner.commitEdit(); + this.port = (Integer) portSpinner.getValue(); + return true; } else { - + return false; } - } - - private String[] login() { + private String[] login(JFrame frame) { JPanel pane = new JPanel(); pane.setLayout(new GridLayout(2, 2)); JLabel userLabel = new JLabel("user"); @@ -397,105 +104,51 @@ private String[] login() { pane.add(passLabel); pane.add(passField); - int option = JOptionPane.showConfirmDialog(this,pane,"Login",JOptionPane.OK_CANCEL_OPTION); - if(option == JOptionPane.OK_OPTION) { + int option = JOptionPane.showConfirmDialog(frame, pane, "Login", JOptionPane.OK_CANCEL_OPTION); + if (option == JOptionPane.OK_OPTION) { String user = userField.getText(); String pass = new String(passField.getPassword()); return new String[]{user, pass}; } else { - return new String[]{null,null}; + return new String[]{null, null}; } } - class Stub implements AppletStub { - private Map params; - - public Stub(String server,String lang, boolean verbose) { - Game g = gaemz.get(selectedGame); - params = new HashMap(); - 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", "/src/main/resources/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 + ":" + g.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://" + gaemz.get(selectedGame).host + "/" + selectedGame + "/"); - } catch (Exception ex) { - System.err.println("getdocumentbase exc eption"); - return null; + @Override + public Void call() throws Exception{ + JFrame frame = new JFrame(); + frame.setTitle("Minigolf"); + Image img = ImageIO.read(getClass().getResource("/icons/playforia.png")); + frame.setIconImage(img); + if (hostname.isEmpty() || port == 0) { + // Determine which of these was actually false + String temp_hostname = hostname.isEmpty() ? DEFAULT_SERVER : hostname; + int temp_port = port == 0 ? DEFAULT_PORT : port; + if (!showSettingDialog(frame, temp_hostname, temp_port)) { + System.err.println("Server needs to be specified for minigolf to run"); } } - public URL getCodeBase() { - return getDocumentBase(); - } + new Game(frame, hostname, port, lang.toString(), verbose); + return null; + } - public String getParameter(String name) { - if (!params.containsKey(name)) - return ""; - return params.get(name); - } - public AppletContext getAppletContext() { - return null; - } + enum Language { + EN_US("en_US"), + FI_FI("fi_FI"), + SV_SE("sv_SE"); + private final String custom_name; - public void appletResize(int width, int height) { + Language(String name) { + this.custom_name = name; } - } - - class Game { - public String host; - public int port; - public int width; - public int height; - public Game(String host, int port, int width, int height) { - this.host = host; - this.port = port; - this.width = width; - this.height = height; + @Override + public String toString() { + return this.custom_name; } } } diff --git a/pom.xml b/pom.xml index b1c485b7..88097386 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,7 @@ UTF-8 test.mainClass + 4.5.1 @@ -100,7 +101,11 @@ shared 1.0 - + + info.picocli + picocli + ${picocli.version} + diff --git a/server/pom.xml b/server/pom.xml index d70b8f78..e3fe645d 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -15,7 +15,7 @@ UTF-8 - org.moparforia.server.Server + org.moparforia.server.Launcher @@ -36,12 +36,29 @@ org.moparforia shared + + info.picocli + picocli + org.apache.maven.plugins maven-compiler-plugin + + + + + info.picocli + picocli-codegen + ${picocli.version} + + + + -Aproject=${project.groupId}/${project.artifactId} + + org.codehaus.mojo diff --git a/server/src/main/java/org/moparforia/server/Launcher.java b/server/src/main/java/org/moparforia/server/Launcher.java new file mode 100644 index 00000000..ae2cd397 --- /dev/null +++ b/server/src/main/java/org/moparforia/server/Launcher.java @@ -0,0 +1,41 @@ +package org.moparforia.server; + +import picocli.CommandLine; + +import java.util.concurrent.Callable; + +@CommandLine.Command( + description = "Starts Minigolf Server", + name = "server", mixinStandardHelpOptions = true +) +public class Launcher implements Callable { + + @CommandLine.Option(names = {"--hostname", "-ip"}, + description = "Sets server hostname", + defaultValue = "0.0.0.0") + private String host; + + @CommandLine.Option(names = {"--port", "-p"}, + description = "Sets server port", + defaultValue = "4242") + private int port; + + public static void main(String... args) { + Launcher launcher = new Launcher(); + try { + CommandLine.ParseResult parseResult = new CommandLine(launcher).parseArgs(args); + if (!CommandLine.printHelpIfRequested(parseResult)) { + launcher.call(); + } + } catch (CommandLine.ParameterException ex) { // command line arguments could not be parsed + System.err.println(ex.getMessage()); + ex.getCommandLine().usage(System.err); + } + } + + @Override + public Void call() { + new Server(host, port).start(); + return null; + } +} diff --git a/server/src/main/java/org/moparforia/server/Server.java b/server/src/main/java/org/moparforia/server/Server.java index 7f1af200..1ce96869 100644 --- a/server/src/main/java/org/moparforia/server/Server.java +++ b/server/src/main/java/org/moparforia/server/Server.java @@ -25,11 +25,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -public class Server implements Runnable { - public static void main(String[] args) { - new Server().start(); - } +public class Server implements Runnable { public static final boolean DEBUG = true; @@ -37,8 +34,10 @@ public static void main(String[] args) { private ChannelGroup allChannels = new DefaultChannelGroup(); private ConcurrentLinkedQueue events = new ConcurrentLinkedQueue(); private HashMap> packetHandlers = new HashMap>(); - private String host = "0.0.0.0"; - private int port = 4242; + + private String host; + private int port; + private HashMap lobbies = new HashMap(); //private ArrayList lobbies = new ArrayList(); //private HashMap games = new HashMap(); @@ -46,12 +45,21 @@ public static void main(String[] args) { private int playerIdCounter; private int gameIdCounter; - public Server() { + + public Server(String host, int port) { + this.host = host; + this.port = port; for (LobbyType lt : LobbyType.values()) { lobbies.put(lt, new Lobby(lt)); } } +// public Server() { +// for (LobbyType lt : LobbyType.values()) { +// lobbies.put(lt, new Lobby(lt)); +// } +// } + public int getNextPlayerId() { return playerIdCounter++; } @@ -185,7 +193,7 @@ public ChannelPipeline getPipeline() { @Override public void run() { - //noinspection InfiniteLoopStatement + System.out.println("Started server on host " + this.host + " with port " + this.port); while (true) { try { Thread.sleep(10); @@ -207,5 +215,4 @@ public void run() { } } } - }