summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-06-22 10:34:02 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-06-22 10:34:02 +0200
commite1df2b8e8866280f62159a5bc70d9aca390ca9bf (patch)
tree7038c25da3defd632fadff3dca14600575712df5
parent5b53a640eeac25451b83feee3e0552453e31789c (diff)
downloadJRummikub-e1df2b8e8866280f62159a5bc70d9aca390ca9bf.tar
JRummikub-e1df2b8e8866280f62159a5bc70d9aca390ca9bf.zip
Fix nickname for Vysper server
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@590 72836036-5685-4462-b002-a69064685172
-rw-r--r--src/jrummikub/control/network/ConnectionControl.java40
1 files changed, 38 insertions, 2 deletions
diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java
index f4d5f64..68bc44c 100644
--- a/src/jrummikub/control/network/ConnectionControl.java
+++ b/src/jrummikub/control/network/ConnectionControl.java
@@ -125,6 +125,7 @@ public class ConnectionControl implements IConnectionControl {
private BlockingQueue<Runnable> actionQueue = new LinkedBlockingQueue<Runnable>();
private volatile GameData offeredGame;
+ private volatile String nickname;
/**
* Creates new connection control
@@ -138,7 +139,7 @@ public class ConnectionControl implements IConnectionControl {
@Override
public String getNickname() {
- return muc.getNickname();
+ return nickname;
}
@Override
@@ -644,6 +645,9 @@ public class ConnectionControl implements IConnectionControl {
if (error == null) {
error = doJoin();
}
+ if (error == null) {
+ error = doFindNickname();
+ }
if (error == null) {
connection.addConnectionListener(new DisconnectListener());
@@ -691,7 +695,7 @@ public class ConnectionControl implements IConnectionControl {
DiscussionHistory history = new DiscussionHistory();
history.setMaxStanzas(0);
- String nickname = loginData.getUserName();
+ nickname = loginData.getUserName();
// Loop until a unused nickname is found
while (true) {
try {
@@ -724,6 +728,38 @@ public class ConnectionControl implements IConnectionControl {
return null;
}
+ private LoginError doFindNickname() {
+ final Message message = muc.createMessage();
+
+ PacketListener listener = new PacketListener() {
+ @Override
+ public void processPacket(Packet packet) {
+ if (packet.getPacketID().equals(message.getPacketID())) {
+ synchronized (ConnectRunner.this) {
+ nickname = StringUtils.parseResource(packet.getFrom());
+ ConnectRunner.this.notify();
+ }
+ }
+ }
+ };
+
+ synchronized (this) {
+ connection.addPacketListener(listener, new PacketTypeFilter(
+ Message.class));
+
+ connection.sendPacket(message);
+
+ try {
+ wait(5000);
+ } catch (InterruptedException e) {
+ }
+ }
+
+ connection.removePacketListener(listener);
+
+ return null;
+ }
+
private class DisconnectListener implements ConnectionListener {
@Override
public void connectionClosed() {