package handlers.chat;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import main.Config;
import connection.ClientConnection;
import handlers.AbstractServerHandler;
import iteration.ConnectionIterationClientInterface;
import iteration.context.IterationContextInterface;
import iteration.context.ChatMessageContext;
import static main.ServerMain.getConnectionManager;
public class PostMessageHandler extends AbstractServerHandler implements
ConnectionIterationClientInterface
{
public void execute(ClientConnection connection, ObjectInputStream is,
ObjectOutputStream os) throws IOException, ClassNotFoundException
{
String message = is.readUTF();
if (Config.server.enableChat)
{
getConnectionManager().iterate(this,
new ChatMessageContext(connection.getNickname(), message));
}
}
public void iterate(ClientConnection currentClient, IterationContextInterface context)
{
ChatMessageContext customContext = context.queryPostMessageHandlerContext();
currentClient.sendChatMessage(customContext.getSenderName(), customContext
.getMessage());
}
}