package com.github.noxan.aves.demo.chat;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.github.noxan.aves.auth.session.SessionManager;
import com.github.noxan.aves.auth.storage.InMemoryUsernamePasswordStorage;
import com.github.noxan.aves.net.Connection;
import com.github.noxan.aves.server.ServerHandler;
import com.github.noxan.aves.server.SocketServer;

public class ChatServer implements ServerHandler {
    public static void main(String[] args) {
        ChatServer server = new ChatServer();
        try {
            server.start();
        } catch(IOException e) {
            e.printStackTrace();
        }
    }

    private Logger logger = Logger.getLogger(getClass().getName());

    private InMemoryUsernamePasswordStorage storage;
    private SessionManager sessionManager;

    public ChatServer() {
        storage = new InMemoryUsernamePasswordStorage();
        sessionManager = new SessionManager(storage);
    }

    public void start() throws IOException {
        server.start();
    }

    @Override
    public void readData(Connection connection, Object data) {
        logger.log(Level.INFO, data.toString());
    }

    @Override
    public void clientConnect(Connection connection) {
        logger.log(Level.INFO, connection + " connected");
    }

    @Override
    public void clientDisconnect(Connection connection) {
        logger.log(Level.INFO, connection + " disconnected");
    }

    @Override
    public void clientLost(Connection connection) {
        logger.log(Level.INFO, connection + " lost");
    }
}

@@ -842,16 +842,50 @@
 nager;%0A%0A
+    private SocketServer server;%0A%0A
     publ
@@ -1013,16 +1013,57 @@
 orage);%0A
+        server = new SocketServer(this);%0A
     %7D%0A%0A 

create socketserver for chatserver