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); } }