搭建饥荒联机版服务器

1. 前期准备

2. 搭建饥荒服务器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# 安装依赖
$ apt update
$ apt upgrade -y
$ apt-get install software-properties-common -y
$ add-apt-repository multiverse
$ dpkg --add-architecture i386
$ apt update
$ apt install libstdc++6 libgcc1 libcurl4-gnutls-dev:i386 lib32z1 lib32stdc++6 -y

# 安装steamcmd
$ mkdir ~/steamcmd
$ cd ~/steamcmd
$ wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz
$ tar -xvzf steamcmd_linux.tar.gz

# 安装饥荒联机版
$ ./steamcmd.sh
steam> force_install_dir ../dontstarvetogether_dedicated_server
steam> login anonymous
steam> app_update 343050 validate
steam> quit

# 创建存档文件夹
$ mkdir -p ~/.klei/DoNotStarveTogether/Cluster_1
$ cd ~/.klei/DoNotStarveTogether/Cluster_1

# 将之前建好的存档文件上传到该文件夹中

# 配置服务器Token
$ echo "xxxxxx" > cluster_token.txt
# 配置管理员ID
$ echo "xxxxxx" > adminlist.txt

# 查看这个地图用了哪些服务器MOD
$ cat ~/.klei/DoNotStarveTogether/Cluster_1/Master/modoverrides.lua
# 配置服务器订阅哪些MOD(用上面命令里的数字)
$ vim ~/dontstarvetogether_dedicated_server/mods/dedicated_server_mods_setup.lua
ServerModSetup("1185229307")
ServerModSetup("1207269058")
......

# 编写启动脚本
$ cd ~
$ vim boot.sh
#!/bin/bash

steamcmd_dir="$HOME/steamcmd"
install_dir="$HOME/dontstarvetogether_dedicated_server"
cluster_name="Cluster_1"
dontstarve_dir="$HOME/.klei/DoNotStarveTogether"

function fail() {
echo Error: "$@" >&2
exit 1
}

function check_for_file() {
if [ ! -e "$1" ]; then
fail "Missing file: $1"
fi
}

cd "$steamcmd_dir" || fail "Missing $steamcmd_dir directory!"
check_for_file "steamcmd.sh"
check_for_file "$dontstarve_dir/$cluster_name/cluster.ini"
check_for_file "$dontstarve_dir/$cluster_name/cluster_token.txt"
check_for_file "$dontstarve_dir/$cluster_name/Master/server.ini"
check_for_file "$dontstarve_dir/$cluster_name/Caves/server.ini"
check_for_file "$install_dir/bin"
cd "$install_dir/bin" || fail # 如果用64位这里改成bin64
run_shared=(./dontstarve_dedicated_server_nullrenderer) # 如果用64位这里改成dontstarve_dedicated_server_nullrenderer_x64
run_shared+=(-console)
run_shared+=(-cluster "$cluster_name")
run_shared+=(-monitor_parent_process $$)
run_shared+=(-shard)
"${run_shared[@]}" Caves | sed 's/^/Caves: /' &
"${run_shared[@]}" Master | sed 's/^/Master: /'

# 启动服务器
$ chmod u+x boot.sh
$ nohup ./boot.sh > root.log 2>&1 &
$ cat root.log | grep connected
Master: [00:01:10]: World xxx is now connected

3. 开放端口

  • ~/.klei/DoNotStarveTogether/Cluster_1/cluster.ini
  • ~/.klei/DoNotStarveTogether/Cluster_1/Master/server.ini
  • ~/.klei/DoNotStarveTogether/Cluster_1/Caves/server.ini
协议 端口 描述
UDP 10999 Master/server.ini
UDP 10998 Caves/server.ini
UDP 10888 cluster.ini
TCP 27017 steam master_server_port
UDP 27017 steam master_server_port
TCP 8767 steam authentication_port
UDP 8767 steam authentication_port

4. 更新饥荒服务器

1
2
3
4
5
6
7
8
9
10
$ cd ~/steamcmd
$ ./steamcmd.sh
steam> force_install_dir ../dontstarvetogether_dedicated_server
steam> login anonymous
steam> app_update 343050 validate
steam> quit

$ cat ~/update.sh
#!/bin/bash
./steamcmd.sh +force_install_dir ../dontstarvetogether_dedicated_server +login anonymous +app_update 343050 validate +quit

参考