Fix nickname for Vysper server
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@590 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
5b53a640ee
commit
e1df2b8e88
1 changed files with 38 additions and 2 deletions
|
@ -125,6 +125,7 @@ public class ConnectionControl implements IConnectionControl {
|
||||||
private BlockingQueue<Runnable> actionQueue = new LinkedBlockingQueue<Runnable>();
|
private BlockingQueue<Runnable> actionQueue = new LinkedBlockingQueue<Runnable>();
|
||||||
|
|
||||||
private volatile GameData offeredGame;
|
private volatile GameData offeredGame;
|
||||||
|
private volatile String nickname;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new connection control
|
* Creates new connection control
|
||||||
|
@ -138,7 +139,7 @@ public class ConnectionControl implements IConnectionControl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNickname() {
|
public String getNickname() {
|
||||||
return muc.getNickname();
|
return nickname;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -644,6 +645,9 @@ public class ConnectionControl implements IConnectionControl {
|
||||||
if (error == null) {
|
if (error == null) {
|
||||||
error = doJoin();
|
error = doJoin();
|
||||||
}
|
}
|
||||||
|
if (error == null) {
|
||||||
|
error = doFindNickname();
|
||||||
|
}
|
||||||
|
|
||||||
if (error == null) {
|
if (error == null) {
|
||||||
connection.addConnectionListener(new DisconnectListener());
|
connection.addConnectionListener(new DisconnectListener());
|
||||||
|
@ -691,7 +695,7 @@ public class ConnectionControl implements IConnectionControl {
|
||||||
DiscussionHistory history = new DiscussionHistory();
|
DiscussionHistory history = new DiscussionHistory();
|
||||||
history.setMaxStanzas(0);
|
history.setMaxStanzas(0);
|
||||||
|
|
||||||
String nickname = loginData.getUserName();
|
nickname = loginData.getUserName();
|
||||||
// Loop until a unused nickname is found
|
// Loop until a unused nickname is found
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
|
@ -724,6 +728,38 @@ public class ConnectionControl implements IConnectionControl {
|
||||||
return null;
|
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 {
|
private class DisconnectListener implements ConnectionListener {
|
||||||
@Override
|
@Override
|
||||||
public void connectionClosed() {
|
public void connectionClosed() {
|
||||||
|
|
Reference in a new issue