@echo off
rem ------------------------------
rem huangyongxing@yeah.net
rem 模拟客户端编译运行管理
rem ------------------------------

cd %~dp0/
set BASEDIR=%cd%

cd %BASEDIR%

set APP_PATH=%cd%\config

set ERL=D:\Program Files\erl-23.3\bin\erl.exe
set WERL=D:\Program Files\erl-23.3\bin\werl.exe

rem set WERL=werl
rem set ERL=erl

rem 设置SVR_PATH（游戏服目录）
setlocal enabledelayedexpansion
cd %BASEDIR%\..\..\
set tmp=!cd!
endlocal & set SVR_PATH=%tmp%

set BEAM_PATH=%SVR_PATH%\ebin

:fun_main
    set inp=
    echo --------------------------------------------------------------------------
    echo     m  编译
    echo     s  开启模拟客户端管理器
    echo     q  退出
    echo --------------------------------------------------------------------------
    set /p inp=请输入指令:
    cd %APP_PATH%
    goto fun_routing

:fun_routing
    if "%inp%"=="m" call :fun_make
    if "%inp%"=="s" call :fun_start_simu
    if "%inp%"=="q" goto :EOF
    echo.
    goto fun_main

:fun_start_simu
    rem 切换到BEAM_PATH，以确保logs目录的相对位置正确
    cd %BEAM_PATH%
    set NODE_NAME=simu%RANDOM%@127.0.0.1
    set COOKIE=test
    rem start cmd /C ""%ERL%" +P 204800 +K true +A 100 +spp true -smp enable -hidden +sbwt none -name %NODE_NAME% -setcookie %COOKIE% -boot start_sasl -sasl sasl_error_logger false -sasl errlog_type error -pa %APP_PATH% -pa %SVR_PATH%\config -s cli_simu start & pause"
    start "" "%WERL%" +P 204800 +K true +A 100 +spp true -smp enable -hidden +sbwt none -name %NODE_NAME% -setcookie %COOKIE% -boot start_sasl -sasl sasl_error_logger false -sasl errlog_type error -pa %APP_PATH% -pa %SVR_PATH%\config -s cli_simu start
    goto :EOF

:fun_make
    cd %SVR_PATH%
    rem "%ERL%" -noinput -smp enable -make

    rem set makeOptions="[{i,\"include\"},{outdir,\"ebin\"}]"
    rem "%ERL%" -noinput -smp enable -eval "Files = filelib:wildcard(\"test/cli_simu/src/^*.erl\"), make:files(Files, %makeOptions%)" -s c q

    echo %SVR_PATH%
    "%ERL%" -noinput -smp enable -eval "Files = filelib:wildcard(\"test/cli_simu/src/^*^*/^*.erl\"), make:files(Files)" -s c q
    goto :EOF

