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.

47 lines
1.2 KiB

package com.jotuntech.sketcher.server.command;
import java.nio.ByteBuffer;
import com.jotuntech.sketcher.common.Log;
import com.jotuntech.sketcher.server.Command;
import com.jotuntech.sketcher.server.Connection;
import com.jotuntech.sketcher.server.Server;
public class SignOutCommand implements Command {
String message;
public SignOutCommand() {
message = new String();
}
public SignOutCommand(String message) {
this.message = message;
}
public int perform(Server server, Connection connection) {
/** Set time of death */
connection.setTimeOfDeath(System.currentTimeMillis());
/** Log it */
if(connection.getUser() != null) {
Log.info(connection.getUser().getName() + " has signed out (" + message + ").");
}
/** Return and broadcast */
return connection.getUser() == null ? Connection.SEND_NONE : Connection.SEND_OTHERS;
}
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));
}
}
}