You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.2 KiB
49 lines
1.2 KiB
package com.jotuntech.sketcher.client.command;
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import com.jotuntech.sketcher.client.Client;
|
|
import com.jotuntech.sketcher.client.Command;
|
|
import com.jotuntech.sketcher.client.Connection;
|
|
import com.jotuntech.sketcher.client.UserInterface;
|
|
import com.jotuntech.sketcher.common.User;
|
|
|
|
public class SignOutCommand implements Command {
|
|
String message;
|
|
|
|
public SignOutCommand() {
|
|
message = new String();
|
|
}
|
|
|
|
public SignOutCommand(String message) {
|
|
this.message = message;
|
|
}
|
|
|
|
public int perform(Client client, User user) {
|
|
client.getUserMap().removeByValue(user);
|
|
|
|
if(user != null) {
|
|
client.getUserInterface().println(user.getName() + " has disconnected (" + message + ")");
|
|
}
|
|
|
|
if(client.isSoundEnabled()) {
|
|
UserInterface.AUDIO_SIGN_OUT.play();
|
|
}
|
|
|
|
return Connection.SEND_NONE;
|
|
}
|
|
|
|
public void decode(ByteBuffer in) {
|
|
StringBuffer messageBuffer = new StringBuffer();
|
|
while(in.remaining() >= 2) {
|
|
messageBuffer.append(in.getChar());
|
|
}
|
|
message = messageBuffer.toString();
|
|
}
|
|
|
|
public void encode(ByteBuffer out) {
|
|
for(int i = 0; i < message.length(); i++) {
|
|
out.putChar(message.charAt(i));
|
|
}
|
|
}
|
|
}
|
|
|