From e1df2b8e8866280f62159a5bc70d9aca390ca9bf Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 22 Jun 2011 10:34:02 +0200 Subject: Fix nickname for Vysper server git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@590 72836036-5685-4462-b002-a69064685172 --- .../control/network/ConnectionControl.java | 40 ++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'src/jrummikub') 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 actionQueue = new LinkedBlockingQueue(); 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() { -- cgit v1.2.3