package com.olliemcclellan.chatserver;
import com.olliemcclellan.chatserver.packets.Packet;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.service.IoHandler;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;
/**
* IoHandler for accepting connections and receiving messages.
* @author Ollie
*/
public class ChatHandler implements IoHandler {
/**
* Called when a client connects to the server.
* @param is the session of the new client
* @throws Exception thrown if an error occurs while accepting the client connection
*/
@Override
public void sessionOpened(IoSession is) throws Exception {
// TODO: implement login procedure
throw new UnsupportedOperationException("Not supported yet.");
}
/**
* Called when the connection between the server and a client is closed.
* @param is the session of the disconnected
* @throws Exception thrown if an error occurs while closing the client connection
*/
@Override
public void sessionClosed(IoSession is) throws Exception {
throw new UnsupportedOperationException("Not supported yet.");
}
/**
* Called when a packet of data is received from a client
* @param is the session of the client which sent the message
* @param o the message (usually an IoBuffer)
* @throws Exception thrown if an error occurs while receiving a message
*/
@Override
public void messageReceived(IoSession is, Object o) throws Exception {
ChatServer.getInstance().getPacketManager().handle(new Packet((IoBuffer) o));
}
/**
* Not needed.
*/
@Override
public void sessionCreated(IoSession is) throws Exception {
}
/**
* Not needed.
*/
@Override
public void sessionIdle(IoSession is, IdleStatus is1) throws Exception {
}
/**
* Not needed.
*/
@Override
public void exceptionCaught(IoSession is, Throwable thrwbl) throws Exception {
}
/**
* Not needed.
*/
@Override
public void messageSent(IoSession is, Object o) throws Exception {
}
}