From 63013dc82cc8718e40e9557cfd83991e72d72dae Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Wed, 22 Jun 2011 01:08:54 +0200 Subject: Integrated dedicated server git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@563 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/ApplicationControl.java | 61 ++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 5 deletions(-) (limited to 'src/jrummikub/control/ApplicationControl.java') diff --git a/src/jrummikub/control/ApplicationControl.java b/src/jrummikub/control/ApplicationControl.java index 7f5cf6d..6909ce1 100644 --- a/src/jrummikub/control/ApplicationControl.java +++ b/src/jrummikub/control/ApplicationControl.java @@ -5,6 +5,8 @@ import jrummikub.control.network.NetworkControl; import jrummikub.model.GameSettings; import jrummikub.model.GameState; import jrummikub.model.IRoundState; +import jrummikub.server.DedicatedServer; +import jrummikub.server.DedicatedServer.ServerStatus; import jrummikub.util.Connection; import jrummikub.util.IListener; import jrummikub.util.IListener1; @@ -25,6 +27,7 @@ public class ApplicationControl { private SaveControl saveControl; private GameControl gameControl; private Connection tempConnection; + private DedicatedServer server; private IView view; @@ -32,7 +35,7 @@ public class ApplicationControl { * Creates a new application control * * @param view - * the view to use + * the view to use */ public ApplicationControl(final IView view) { this.view = view; @@ -52,10 +55,11 @@ public class ApplicationControl { saveControl.getLoadEvent().add( new IListener3() { @Override - public void handle(GameSettings settings, GameState gameState, - IRoundState roundState) { + public void handle(GameSettings settings, + GameState gameState, IRoundState roundState) { abortControls(); - gameControl = new GameControl(settings, saveControl, view); + gameControl = new GameControl(settings, saveControl, + view); addGameControlListeners(gameControl); gameControl.continueGame(gameState, roundState); } @@ -132,7 +136,7 @@ public class ApplicationControl { * Create a new network login control */ private void createLoginControl(boolean reset) { - loginControl = new LoginControl(view); + loginControl = new LoginControl(view, this); loginControl.getLoginEvent().add(new IListener1() { @Override public void handle(LoginData loginData) { @@ -250,4 +254,51 @@ public class ApplicationControl { networkControl.startNetwork(); } + + /** + * Ensure the dedicated server is running + * + * @param password + * password to use, if empty "jrummikub" is used + * @return whether the server could be started + */ + public boolean startDedicatedServer(String password) { + if (password == "") { + password = "jrummikub"; + } + if (server == null) { + DedicatedServer newServer = new DedicatedServer(password); + ServerStatus status = newServer.start(); + switch (status) { + case STARTED: + server = newServer; + break; + case ALREADY_RUNNING: + view.showServerStartupError(true); + return false; + case ERROR: + view.showServerStartupError(false); + return false; + } + } + server.setServerPassword(password); + view.getLoginPanel().setServer(server.getHostName()); + view.getLoginPanel().setChannel( + "jrummikub@play." + server.getHostName()); + view.getLoginPanel().setDedicatedServerRunning(true); + return true; + } + + /** + * If the login given is to our own dedicated server, update it's password + * to match + * + * @param loginData + * login data of user trying to connect + */ + public void updateDedicatedServerPassword(LoginData loginData) { + if (server != null && server.getHostName() == loginData.getServerName()) { + server.setServerPassword(loginData.getPassword()); + } + } } -- cgit v1.2.3