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.common.User; public class ServerMessageCommand implements Command { String text; public ServerMessageCommand() { } public ServerMessageCommand(String text) { this.text = text; } public int perform(Client client, User user) { /** Notify the user */ client.getUserInterface().println(text); /** Return silently. */ return Connection.SEND_NONE; } public void decode(ByteBuffer in) { StringBuffer textBuffer = new StringBuffer(); while(in.remaining() >= 2) { textBuffer.append(in.getChar()); } text = textBuffer.toString(); } public void encode(ByteBuffer out) { for(int i = 0; i < text.length(); i++) { out.putChar(text.charAt(i)); } } }