summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control/ApplicationControl.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/control/ApplicationControl.java')
-rw-r--r--src/jrummikub/control/ApplicationControl.java61
1 files changed, 56 insertions, 5 deletions
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<GameSettings, GameState, IRoundState>() {
@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<LoginData>() {
@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());
+ }
+ }
}