Skip to content

Commit

Permalink
Merge pull request eesast#285 from ONLOX/dev
Browse files Browse the repository at this point in the history
Installer v1.0.1.0
  • Loading branch information
DreamEnderKing authored Apr 27, 2024
2 parents 4138b5e + af69cc5 commit 575adb2
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
run: docker push ${{ secrets.DOCKER_USERNAME }}/thuai7_run:latest
29 changes: 29 additions & 0 deletions dependency/Dockerfile/Docker_run_client
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions dependency/Dockerfile/Docker_run_server
Original file line number Diff line number Diff line change
@@ -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" ]
8 changes: 8 additions & 0 deletions dependency/Dockerfile/Dockerfile_run_server
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ 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
58 changes: 58 additions & 0 deletions dependency/shell/run_client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions dependency/shell/run_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion installer/Data/MD5FileData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions installer/Manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 35 additions & 20 deletions installer/Page/DebugPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,33 @@
RowDefinitions="*,*,*,*,*,*,*,*,*,*"
ColumnDefinitions="*">


<VerticalStackLayout
Grid.Row="0"
Grid.RowSpan="9"
HorizontalOptions="Center"
VerticalOptions="Center">

<HorizontalStackLayout>
<Label
WidthRequest="170"
Text="Mode"
VerticalOptions="Center"
FontSize="{Binding ConstFontSize}"/>
<Picker
SelectedItem="{Binding Mode}"
WidthRequest="400">
<Picker.ItemsSource>
<x:Array
Type="{x:Type x:String}">
<x:String>Client</x:String>
<x:String>Server</x:String>
</x:Array>
</Picker.ItemsSource>
</Picker>
</HorizontalStackLayout>

<HorizontalStackLayout
IsVisible="{Binding IPVisible}">
<Label
WidthRequest="170"
Text="IP"
Expand All @@ -39,24 +58,6 @@
Text="{Binding Port}"
FontSize="16"/>
</HorizontalStackLayout>
<HorizontalStackLayout>
<Label
WidthRequest="170"
Text="Mode"
VerticalOptions="Center"
FontSize="{Binding ConstFontSize}"/>
<Picker
SelectedItem="{Binding Mode}"
WidthRequest="400">
<Picker.ItemsSource>
<x:Array
Type="{x:Type x:String}">
<x:String>Client</x:String>
<x:String>Server</x:String>
</x:Array>
</Picker.ItemsSource>
</Picker>
</HorizontalStackLayout>

<Label/>

Expand Down Expand Up @@ -146,6 +147,20 @@

<Grid
ColumnDefinitions="15,370,100,100,15">
<HorizontalStackLayout
Grid.Column="1">
<CheckBox
IsChecked="{Binding HaveSpectator}"/>
<Label
WidthRequest="90"
Text="Spectator"
HorizontalOptions="Center"
VerticalOptions="Center"/>
<Entry
WidthRequest="100"
IsEnabled="{Binding HaveSpectator}"
Text="{Binding SpectatorID}"/>
</HorizontalStackLayout>
<Button
Grid.Column="2"
Text="Add"
Expand Down Expand Up @@ -210,7 +225,7 @@


<VerticalStackLayout
IsVisible="{Binding ServerVisible}">
IsVisible="{Binding ServerVisible}">

<HorizontalStackLayout>
<Label
Expand Down
Loading

0 comments on commit 575adb2

Please sign in to comment.