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 --- .../control/network/ConnectionControl.java | 40 +++++++++++++--------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'src/jrummikub/control/network') diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java index b5886ca..39fabf7 100644 --- a/src/jrummikub/control/network/ConnectionControl.java +++ b/src/jrummikub/control/network/ConnectionControl.java @@ -2,6 +2,8 @@ package jrummikub.control.network; import java.awt.Color; import java.io.Serializable; +import java.util.Collection; +import java.util.Iterator; import java.util.UUID; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; @@ -88,7 +90,7 @@ public class ConnectionControl implements IConnectionControl { } } - private final LoginData loginData; + private LoginData loginData; private volatile Connection connection; private volatile MultiUserChat muc; @@ -125,7 +127,7 @@ public class ConnectionControl implements IConnectionControl { * Creates new connection control * * @param loginData - * player's login data + * player's login data */ public ConnectionControl(LoginData loginData) { this.loginData = loginData; @@ -346,7 +348,8 @@ public class ConnectionControl implements IConnectionControl { protected void addData(DefaultPacketExtension extension) { extension.setValue("messageType", "change_color"); extension.setValue("uuid", uuid.toString()); - extension.setValue("color", Base64.encodeObject(color, Base64.GZIP)); + extension.setValue("color", + Base64.encodeObject(color, Base64.GZIP)); } }); } @@ -409,7 +412,8 @@ public class ConnectionControl implements IConnectionControl { protected void addData(DefaultPacketExtension extension) { extension.setValue("messageType", "table_update"); extension.setValue("uuid", uuid.toString()); - extension.setValue("table", Base64.encodeObject(table, Base64.GZIP)); + extension.setValue("table", + Base64.encodeObject(table, Base64.GZIP)); } }); } @@ -423,8 +427,8 @@ public class ConnectionControl implements IConnectionControl { protected void addData(DefaultPacketExtension extension) { extension.setValue("messageType", "turn_end"); extension.setValue("uuid", uuid.toString()); - extension.setValue("data", Base64.encodeObject(new TurnEndData(state, - invalidTurnInfo), Base64.GZIP)); + extension.setValue("data", Base64.encodeObject(new TurnEndData( + state, invalidTurnInfo), Base64.GZIP)); } }); } @@ -460,8 +464,8 @@ public class ConnectionControl implements IConnectionControl { protected void addData(DefaultPacketExtension extension) { extension.setValue("messageType", "game_offer"); extension.setValue("uuid", data.getGameID().toString()); - extension.setValue("gameSettings", - Base64.encodeObject(data.getGameSettings(), Base64.GZIP)); + extension.setValue("gameSettings", Base64.encodeObject( + data.getGameSettings(), Base64.GZIP)); } }); } @@ -512,8 +516,8 @@ public class ConnectionControl implements IConnectionControl { .getExtension(ELEMENT_NAME, NAMESPACE); if (((Message) packet).getType() == Message.Type.error) { - System.err.println("Received error message from '" + packet.getFrom() - + "'"); + System.err.println("Received error message from '" + + packet.getFrom() + "'"); return; } @@ -529,14 +533,15 @@ public class ConnectionControl implements IConnectionControl { String sender, String messageType) { if (messageType.equals("game_offer")) { UUID uuid = UUID.fromString(extension.getValue("uuid")); - GameSettings settings = (GameSettings) Base64.decodeToObject(extension - .getValue("gameSettings")); + GameSettings settings = (GameSettings) Base64 + .decodeToObject(extension.getValue("gameSettings")); fixGameSettings(settings); GameData gameData = new GameData(uuid, settings, sender); gameOfferEvent.emit(gameData); } else if (messageType.equals("game_withdrawal")) { - gameWithdrawalEvent.emit(UUID.fromString(extension.getValue("uuid"))); + gameWithdrawalEvent + .emit(UUID.fromString(extension.getValue("uuid"))); } else if (messageType.equals("game_request")) { if (offeredGame != null) { sendGameOffer(); @@ -649,7 +654,8 @@ public class ConnectionControl implements IConnectionControl { XMPPError xmppError = e.getXMPPError(); if (xmppError != null) { - if (xmppError.getType() == Type.WAIT && xmppError.getCode() == 504) { + if (xmppError.getType() == Type.WAIT + && xmppError.getCode() == 504) { return LoginError.UNKNOWN_HOST; } } @@ -661,7 +667,8 @@ public class ConnectionControl implements IConnectionControl { private LoginError doLogin() { try { - connection.login(loginData.getUserName(), loginData.getPassword(), + connection.login(loginData.getUserName(), + loginData.getPassword(), "JRummikub-" + StringUtils.randomString(8)); return null; } catch (XMPPException e) { @@ -691,7 +698,8 @@ public class ConnectionControl implements IConnectionControl { continue; } else { // An unknown error has occurred, cancel connect - if (xmppError != null && xmppError.getType() == Type.CANCEL + if (xmppError != null + && xmppError.getType() == Type.CANCEL && xmppError.getCode() == 404) { return LoginError.UNKNOWN_CHANNEL; } -- cgit v1.2.3