饥荒服务器搭建

Windows

服务端程序

  1. 在Steam搜索安装饥荒服务端

image-20230607182854221

  1. 进入安装路径,修改/bin/scipts 目录下的 launch_preconfigured_servers.bat

    1
    2
    3
    4
    5
    6
    7
    8
    
    @ECHO OFF
    
    set SteamAppId=322330
    set SteamGameId=322330
    
    cd ..
    start "Don't Starve Together Overworld" /D "%~dp0.." "%~dp0..\dontstarve_dedicated_server_nullrenderer.exe" -cluster Cluster_1 -console -shard Master
    start "Don't Starve Together Caves"     /D "%~dp0.." "%~dp0..\dontstarve_dedicated_server_nullrenderer.exe" -cluster Cluster_1 -console -shard Caves
    

存档

将需要的存档(默认位置在 文档/Klei/DoNotStarveTogether/[数字串]/Cluster_[Num])复制到 文档/Klei/DoNotStarveTogether

image-20230608021056930

设置存档中的配置文件 cluster.ini

 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
[GAMEPLAY]
game_mode = survival
max_players = 6
pvp = false
pause_when_empty = true


[NETWORK]
lan_only_cluster = false
cluster_password = 114514	# 密码
cluster_description = for406 	# 描述
cluster_name = End406	# 房间名
offline_cluster = false
cluster_language = zh
cluster_cloud_id = A0E93C2A0D009006


[MISC]
console_enabled = true


[SHARD]
shard_enabled = true
bind_ip = 127.0.0.1
master_ip = 127.0.0.1
master_port = 10888
cluster_key = defaultPass

令牌

到KLei官网(https://accounts.klei.com/account/game)

游戏-《饥荒:联机版》的游戏服务器 页面,添加新服务器,复制这串token

image-20230608001243943

在存档文件夹中,创建 cluster_token.txt 文件,将token放进去

Mod

到服务器所在目录文件夹下,找到 dedicated_server_mods_setup.lua 文件

如示例所示,追加 ServerModSetup("[Mod_id]") 到文件末尾

Mod_id 可以到已开启该Mod的存档中的 Master\modoverrides.lua 文件中寻找,也可以到创意工坊中该Mod的分享链接中获取

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
--There are two functions that will install mods, ServerModSetup and ServerModCollectionSetup. Put the calls to the functions in this file and they will be executed on boot.

--ServerModSetup takes a string of a specific mod's Workshop id. It will download and install the mod to your mod directory on boot.
	--The Workshop id can be found at the end of the url to the mod's Workshop page.
	--Example: http://steamcommunity.com/sharedfiles/filedetails/?id=350811795
	--ServerModSetup("350811795")

--ServerModCollectionSetup takes a string of a specific mod's Workshop id. It will download all the mods in the collection and install them to the mod directory on boot.
	--The Workshop id can be found at the end of the url to the collection's Workshop page.
	--Example: http://steamcommunity.com/sharedfiles/filedetails/?id=379114180
	--ServerModCollectionSetup("379114180")

ServerModSetup("1247122310")
ServerModSetup("1530801499")
ServerModSetup("2032685784")
ServerModSetup("2041908508")

开启服务器

双击 D:\Steam\steamapps\common\Don't Starve Together Dedicated Server\bin\scripts 下的 launch_preconfigured_servers.bat 批处理程序即可

关闭服务器

分别在两个窗口输入 c_shutdown()

其他

控制台连接服务器

1
c_connect(ip, port, password)

参考链接:https://www.bilibili.com/read/cv12698308/

Ubuntu

安装编译环境

1
2
3
4
sudo add-apt-repository multiverse
sudo dpkg --add-architecture i386
sudo apt update -y
sudo apt install lib32gcc1 libcurl4-gnutls-dev:i386 lib32stdc++6 lib32z1 -y

安装steamCMD

1
2
3
4
mkdir ~/steamcmd
cd ~/steamcmd
wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz
tar -xvzf steamcmd_linux.tar.gz

并运行

1
./steamcmd.sh

安装饥荒服务端

进入到steamcmd环境下后

1
2
3
4
login anonymous
force_install_dir ../dontstarvetogether_dedicated_server
app_update 343050 validate
quit

343050是饥荒在steam中的id

测试运行

1
2
cd ~/dontstarvetogether_dedicated_server/bin/
./dontstarve_dedicated_server_nullrenderer

可能会出现lib缺失的问题,解决方案如下

1
2
cd ~/dontstarvetogether_dedicated_server/bin/lib32
ln -s /usr/lib/libcurl.so.4 libcurl-gnutls.so.4

存档、Mod、令牌

参考上面Windows服务器的做法

运行

1
2
cd ~
touch start.sh

修改 start.sh 的内容如下

 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
#!/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

                            run_shared=(./dontstarve_dedicated_server_nullrenderer)
                            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: /'

steamcmd_dir 表示的是steam安装的位置 install_dir 表示的饥荒服务器安装的位置 cluster_name 表示的是地图的名字 donstarve_dir 表示的是地图的位置

修改权限

1
chmod u+x ~/start.sh

启动服务器

1
2
screen -S DST
./start.sh

可能出现的问题

1
bash: ./start.sh: /bin/bash^M: bad interpreter: No such file or directory

原因是文件的格式是dos,需要修改为unix

  1. 查看文件格式

  2. 用vim打开出错的文件

  3. ESC键 再按 shift+冒号

  4. 输入 set ff 回车 可以看见 该文件的格式 fileformat=dos

  5. shift + 冒号 输入 set ff=unix 回车

  6. 可以按 shift + 冒号set ff 查看 fileformat=unix

更新服务器

饥荒更新,重新下载

1
~/steamcmd/steamcmd.sh +login anonymous +force_install_dir ~/dontstarvetogether_dedicated_server/ +app_update 343050 validate +quit

参考链接:https://www.bilibili.com/read/cv7464303/

updatedupdated2023-08-262023-08-26