import * as path from "path";
import { WsServer } from "tsrpc";
import { serviceProto } from './shared/protocols/serviceProto';
import { worldManager } from './managers/WorldManager';

// Create the Server
export const server = new WsServer(serviceProto, {
    port: 3000,
    // Remove this to use binary mode (remove from the client too)
    json: true
});

// Initialize before server start
async function init() {
    await server.autoImplementApi(path.resolve(__dirname, 'api'));

    // 初始化游戏世界
    console.log('正在初始化游戏世界...');
    worldManager.initialize();
    console.log('游戏世界初始化完成');
};

// Entry function
async function main() {
    await init();
    await server.start();
}
main();