diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index e6ec0cff..5a0bb9fc 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -25,4 +25,4 @@ jobs: - name: Build run docker image run: docker build -t ${{ secrets.DOCKER_USERNAME }}/thuai7_run:latest -f ./dependency/Dockerfile/Dockerfile_run . - name: Push run image to DockerHub - run: docker push ${{ secrets.DOCKER_USERNAME }}/thuai7_run:latest \ No newline at end of file + run: docker push ${{ secrets.DOCKER_USERNAME }}/thuai7_run:latest diff --git a/dependency/Dockerfile/Docker_run_client b/dependency/Dockerfile/Docker_run_client new file mode 100644 index 00000000..1d6b633e --- /dev/null +++ b/dependency/Dockerfile/Docker_run_client @@ -0,0 +1,29 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0.204-jammy-amd64 AS build +MAINTAINER eesast +WORKDIR /usr/local +COPY . . +RUN dotnet publish logic/Server/Server.csproj -c Release -o /usr/local/Server --self-contained true -r linux-x64 + +FROM eesast/thuai7_base:base +MAINTAINER eesast +WORKDIR /usr/local +COPY --from=build /usr/local/Server . +RUN mkdir /usr/local/team1 && mkdir /usr/local/team2 && mkdir /usr/local/playback +<<<<<<<< HEAD:dependency/Dockerfile/Docker_run_client +COPY ./dependency/shell/run_client.sh . +======== +COPY ./dependency/shell/run_server.sh . +>>>>>>>> 218cff729c2110699b9e40a0d97a740f58e75462:dependency/Dockerfile/Dockerfile_run_server +COPY ./CAPI/python /usr/local/PlayerCode/CAPI/python +COPY ./dependency/proto /usr/local/PlayerCode/dependency/proto +COPY ./dependency/shell /usr/local/PlayerCode/dependency/shell +WORKDIR /usr/local/PlayerCode/CAPI/python +RUN bash ../../dependency/shell/generate_proto.sh + +WORKDIR /usr/local +<<<<<<<< HEAD:dependency/Dockerfile/Docker_run_client +ENTRYPOINT [ "bash","./run_client.sh" ] +======== +RUN export TERMINAL=SERVER +ENTRYPOINT [ "bash","./run.sh" ] +>>>>>>>> 218cff729c2110699b9e40a0d97a740f58e75462:dependency/Dockerfile/Dockerfile_run_server diff --git a/dependency/Dockerfile/Docker_run_server b/dependency/Dockerfile/Docker_run_server new file mode 100644 index 00000000..aa5984dd --- /dev/null +++ b/dependency/Dockerfile/Docker_run_server @@ -0,0 +1,20 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0.204-jammy-amd64 AS build +MAINTAINER eesast +WORKDIR /usr/local +COPY . . +RUN dotnet publish logic/Server/Server.csproj -c Release -o /usr/local/Server --self-contained true -r linux-x64 + +FROM eesast/thuai7_base:base +MAINTAINER eesast +WORKDIR /usr/local +COPY --from=build /usr/local/Server . +RUN mkdir /usr/local/team1 && mkdir /usr/local/team2 && mkdir /usr/local/playback +COPY ./dependency/shell/run_server.sh . +COPY ./CAPI/python /usr/local/PlayerCode/CAPI/python +COPY ./dependency/proto /usr/local/PlayerCode/dependency/proto +COPY ./dependency/shell /usr/local/PlayerCode/dependency/shell +WORKDIR /usr/local/PlayerCode/CAPI/python +RUN bash ../../dependency/shell/generate_proto.sh + +WORKDIR /usr/local +ENTRYPOINT [ "bash","./run_server.sh" ] diff --git a/dependency/Dockerfile/Dockerfile_run_server b/dependency/Dockerfile/Dockerfile_run_server index ce73ee77..1d6b633e 100644 --- a/dependency/Dockerfile/Dockerfile_run_server +++ b/dependency/Dockerfile/Dockerfile_run_server @@ -9,7 +9,11 @@ MAINTAINER eesast WORKDIR /usr/local COPY --from=build /usr/local/Server . RUN mkdir /usr/local/team1 && mkdir /usr/local/team2 && mkdir /usr/local/playback +<<<<<<<< HEAD:dependency/Dockerfile/Docker_run_client +COPY ./dependency/shell/run_client.sh . +======== COPY ./dependency/shell/run_server.sh . +>>>>>>>> 218cff729c2110699b9e40a0d97a740f58e75462:dependency/Dockerfile/Dockerfile_run_server COPY ./CAPI/python /usr/local/PlayerCode/CAPI/python COPY ./dependency/proto /usr/local/PlayerCode/dependency/proto COPY ./dependency/shell /usr/local/PlayerCode/dependency/shell @@ -17,5 +21,9 @@ WORKDIR /usr/local/PlayerCode/CAPI/python RUN bash ../../dependency/shell/generate_proto.sh WORKDIR /usr/local +<<<<<<<< HEAD:dependency/Dockerfile/Docker_run_client +ENTRYPOINT [ "bash","./run_client.sh" ] +======== RUN export TERMINAL=SERVER ENTRYPOINT [ "bash","./run.sh" ] +>>>>>>>> 218cff729c2110699b9e40a0d97a740f58e75462:dependency/Dockerfile/Dockerfile_run_server diff --git a/dependency/shell/run_client.sh b/dependency/shell/run_client.sh index 82dd13b7..61a09d5e 100644 --- a/dependency/shell/run_client.sh +++ b/dependency/shell/run_client.sh @@ -6,6 +6,64 @@ python_dir=/usr/local/PlayerCode/CAPI/python/PyAPI python_main_dir=/usr/local/PlayerCode/CAPI/python playback_dir=/usr/local/playback +sleep 5 +for k in {1..2} +do + pushd /usr/local/team$k + if [ $k -eq 1 ]; then + for i in {1..4} + do + j=$((i - 1)) + if [ -f "./player$i.py" ]; then + cp -r $python_main_dir $python_main_dir$i + cp -f ./player$i.py $python_main_dir$i/PyAPI/AI.py + nice -0 python3 $python_main_dir$i/PyAPI/main.py -I 127.0.0.1 -P 8888 -p $j > $playback_dir/team$k-player$j.log 2>&1 & + elif [ -f "./capi$i" ]; then + nice -0 ./capi$i -I 127.0.0.1 -P 8888 -p $j > $playback_dir/team$k-player$j.log 2>&1 & + else + echo "ERROR. $i is not found." + fi + done + else + for i in {5..5} + do + j=$((i - 1)) + if [ -f "./player$i.py" ]; then + cp -r $python_main_dir $python_main_dir$i + cp -f ./player$i.py $python_main_dir$i/PyAPI/AI.py + nice -0 python3 $python_main_dir$i/PyAPI/main.py -I 127.0.0.1 -P 8888 -p $j > $playback_dir/team$k-player$j.log 2>&1 & + elif [ -f "./capi$i" ]; then + nice -0 ./capi$i -I 127.0.0.1 -P 8888 -p $j > $playback_dir/team$k-player$j.log 2>&1 & + else + echo "ERROR. $i is not found." + fi + done + fi + popd +done + +sleep 10 + +if [ -f $playback_dir/start.lock ]; then + ps -p $server_pid + while [ $? -eq 0 ] + do + sleep 1 + ps -p $server_pid > /dev/null 2>&1 + done + # result=$(cat /usr/local/playback/result.json) + # score0=$(echo "$result" | grep -oP '(?<="Student":)\d+') + # score1=$(echo "$result" | grep -oP '(?<="Tricker":)\d+') + # curl $URL -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" -d '{"result":[{"team_id":0, "score":'${score0}'}, {"team_id":1, "score":'${score1}'}], "mode":'${MODE}'}'> $playback_dir/send.log 2>&1 + touch $playback_dir/finish.lock + echo "Finish" +else + echo "Failed to start game." + touch $playback_dir/finish.lock + touch temp.lock + mv -f temp.lock $playback_dir/video.thuaipb + kill -9 $server_pid +fi for k in {1..2} do pushd /usr/local/team$k diff --git a/dependency/shell/run_server.sh b/dependency/shell/run_server.sh index 92ebf477..d833794d 100644 --- a/dependency/shell/run_server.sh +++ b/dependency/shell/run_server.sh @@ -7,6 +7,35 @@ python_main_dir=/usr/local/PlayerCode/CAPI/python playback_dir=/usr/local/playback if [ $EXPOSED -eq 1 ]; then + nice -10 ./Server --port 8888 --TeamCount 2 --ShipNum 4 --resultFileName $playback_dir/result --gameTimeInSecond $TIME --mode $MODE --mapResource $MAP --url $URL --token $TOKEN --fileName $playback_dir/video --startLockFile $playback_dir/start.lock > $playback_dir/server.log 2>&1 & + server_pid=$! +else + nice -10 ./Server --port 8888 --TeamCount 2 --ShipNum 4 --resultFileName $playback_dir/result --gameTimeInSecond $TIME --mode $MODE --mapResource $MAP --notAllowSpectator --url $URL --token $TOKEN --fileName $playback_dir/video --startLockFile $playback_dir/start.lock > $playback_dir/server.log 2>&1 & + server_pid=$! +fi +sleep 5 +for k in {1..2} +do + pushd /usr/local/team$k + for i in {1..5} + do + j=$((i - 1)) + if [ -f "./player$i.py" ]; then + cp -r $python_main_dir $python_main_dir$i + cp -f ./player$i.py $python_main_dir$i/PyAPI/AI.py + nice -0 python3 $python_main_dir$i/PyAPI/main.py -I 127.0.0.1 -P 8888 -p $j > $playback_dir/team$k-player$j.log 2>&1 & + elif [ -f "./capi$i" ]; then + nice -0 ./capi$i -I 127.0.0.1 -P 8888 -p $j > $playback_dir/team$k-player$j.log 2>&1 & + else + echo "ERROR. $i is not found." + fi + done + popd +done + + + +sleep 10 nice -10 ./Server --ip 127.0.0.1 --port 8888 --teamCount 2 --shipNum 4 --resultFileName $playback_dir/result --gameTimeInSecond $TIME --mode $MODE --mapResource $MAP --url $URL --token $TOKEN --fileName $playback_dir/video --startLockFile $playback_dir/start.lock > $playback_dir/server.log 2>&1 & server_pid=$! else diff --git a/installer/Data/MD5FileData.cs b/installer/Data/MD5FileData.cs index dc742c7a..5f1f3451 100644 --- a/installer/Data/MD5FileData.cs +++ b/installer/Data/MD5FileData.cs @@ -32,7 +32,7 @@ public class TVersion public Version TemplateVersion = new Version(1, 0, 0, 2); // 本体版本 [JsonInclude] - public Version InstallerVersion = new Version(1, 0, 0, 2); + public Version InstallerVersion = new Version(1, 0, 1, 0); public static bool operator <(TVersion l, TVersion r) { return l.LibVersion < r.LibVersion || l.TemplateVersion < r.TemplateVersion || l.InstallerVersion < r.InstallerVersion; diff --git a/installer/Manual.md b/installer/Manual.md index b63facc5..090f6f86 100644 --- a/installer/Manual.md +++ b/installer/Manual.md @@ -30,19 +30,19 @@ **启动器的正常工作可能需要管理员权限** -#### 一般调试流程 +#### 本地调试流程 -1. 输入 `IP` 和 `Port`,默认为 `127.0.0.1` 和 `8888` +1. 输入 `Port`,默认为 `8888` 2. 选择 `Server` 调整 `Team Count` 和 `Ship Count`,启动 *Server* -3. 选择 `Client` 加入对应的数量的 *Player*,调整各个 *Player* 的参数和 `Language` 后启动 *Client* +3. 选择 `Client`,输入 `127.0.0.1`,加入对应的数量的 *Player*,调整各个 *Player* 的参数和 `Language` 后启动 *Client* - *Player* 数量为 $\mathrm{TeamCount}*(\mathrm{ShipCount}+1)$, *Player* 全部加入后 *Server* 才会开始游戏 - `Player ID` 为 `0` 表示 `Home`,其他为 `Ship` - - `Player Mode` 为 `API` 表示选手在 *CAPI* 中写的代码;为 `Manual` 表示一个手动操控的 *Player*。手动操控模式下,`Player ID` 不能为 `0`,`Ship Type` 不能为 `0`,同时一台电脑不建议有多个手动操控的 *Player*。 + - `Player Mode` 为 `API` 表示执行选手在 *CAPI* 中写的代码的 *Player*;为 `Manual` 表示一个手动操控的 *Player*。手动操控模式下,`Player ID` 不能为 `0`,`Ship Type` 不能为 `0`,同时一台电脑不建议有多个手动操控的 *Player*。 #### 联机调试流程 -1. 多台电脑输入相同的 `IP` 和 `Port`,`IP` 可以通过在 cmd 中输入 `ipconfig` 查看 -2. 其中一台电脑启动 *Server* +1. 其中一台电脑启动 *Server* +2. 多台电脑输入 *Server* 电脑的 `IP` 和 `Port`,`IP` 可以通过在 cmd 中输入 `ipconfig` 查看 3. 所有电脑凑够对应数量的 *Player*,启动 *Client* ### Playback diff --git a/installer/Page/DebugPage.xaml b/installer/Page/DebugPage.xaml index 5e1a4536..8d8aeb5a 100644 --- a/installer/Page/DebugPage.xaml +++ b/installer/Page/DebugPage.xaml @@ -10,7 +10,6 @@ RowDefinitions="*,*,*,*,*,*,*,*,*,*" ColumnDefinitions="*"> - + + + - -