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.
48 lines
985 B
48 lines
985 B
package com.jotuntech.sketcher.server.command;
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import com.jotuntech.sketcher.common.User;
|
|
import com.jotuntech.sketcher.server.Command;
|
|
import com.jotuntech.sketcher.server.Connection;
|
|
import com.jotuntech.sketcher.server.Server;
|
|
|
|
public class SetColorCommand implements Command {
|
|
static boolean firstWhite = true;
|
|
int color;
|
|
|
|
public SetColorCommand() {
|
|
}
|
|
|
|
public SetColorCommand(int color) {
|
|
this.color = color;
|
|
}
|
|
|
|
public int perform(Server server, Connection connection) {
|
|
return perform(connection.getUser()) ? Connection.SEND_OTHERS : Connection.SEND_NONE;
|
|
}
|
|
|
|
private boolean perform(User user) {
|
|
if(user == null) {
|
|
/** Signed in users only */
|
|
return false;
|
|
}
|
|
|
|
if(user.isViewer()) {
|
|
return false;
|
|
}
|
|
|
|
user.setColor(color);
|
|
|
|
return true;
|
|
}
|
|
|
|
public void decode(ByteBuffer in) {
|
|
color = in.getInt();
|
|
}
|
|
|
|
public void encode(ByteBuffer out) {
|
|
out.putInt(color);
|
|
}
|
|
|
|
}
|
|
|