Sketcher2 source code
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.

58 lines
1.4 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 KickCommand implements Command {
int targetKey;
String reason;
public KickCommand() {
}
public KickCommand(int targetKey, String reason) {
this.targetKey = targetKey;
this.reason = reason;
}
public int perform(Client client, User user) {
if(user != null && user.isViewer()) {
return Connection.SEND_NONE;
}
User targetUser = client.getUserMap().remove(targetKey);
client.getUserInterface().println(targetUser.getName() + " was kicked out (" + reason + ")");
if(targetUser == client.getConnection().getUser()) {
client.getConnection().setTimeOfDeath(System.currentTimeMillis());
}
if(client.isSoundEnabled()) {
UserInterface.AUDIO_KICK.play();
}
return Connection.SEND_NONE;
}
public void decode(ByteBuffer in) {
targetKey = in.getInt();
StringBuffer reasonBuffer = new StringBuffer();
while(in.remaining() >= 2) {
reasonBuffer.append(in.getChar());
}
reason = reasonBuffer.toString();
}
public void encode(ByteBuffer out) {
out.putInt(targetKey);
for(int i = 0; i < reason.length(); i++) {
out.putChar(reason.charAt(i));
}
}
}