package com.zombie.game;

import com.zombie.game.server.GameWebSocketServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GameServerMain {
    private static final Logger logger = LoggerFactory.getLogger(GameServerMain.class);

    public static void main(String[] args) throws Exception {
        int port = 8080;
        if (args.length > 0) {
            try {
                port = Integer.parseInt(args[0]);
            } catch (NumberFormatException e) {
                logger.warn("Invalid port number, using default: 8080");
            }
        }

        GameWebSocketServer server = new GameWebSocketServer(port);
        server.start();

        logger.info("ZP2 Server started on port {}", port);

        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            logger.info("Shutting down server...");
            try {
                server.stop();
            } catch (Exception e) {
                logger.error("Error during shutdown", e);
            }
        }));
    }
}
