summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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() {