package com.eactive.eai.adapter.socket2.protocol.admin;

import com.eactive.eai.adapter.socket2.protocol.ISocketAdapter;
import com.eactive.eai.adapter.socket2.protocol.ProtocolHandler;
import org.apache.mina.common.IoSession;

public class TelnetAdminHandler extends ProtocolHandler {
	public TelnetAdminHandler(ISocketAdapter adapter) {
		super(adapter);
	}
	
	@Override
	public void sessionOpened(IoSession session) {
		session.write("WELCOME");
		session.write("cmd> " + (byte) 0xF8);
	}
	
	@Override
	public void messageReceived(IoSession session, Object message) throws Exception {
		String msg =  message.toString().trim();		
		// System.out.println("<RECV> " + msg);

		if ("quit".equals(msg) || "exit".equals(msg)) {
			session.write("bye......");
			sessionPool.remove(session);
			session.close();
			return;
		}

		session.write(msg);
		session.write("\r\ncmd> ");
		session.write((byte) 0x22);
	}
}
