饥荒服务器搭建 (docker)

本文最后更新于:2023年11月2日 下午

steam上玩饥荒如果是某一个人作为服务端的话, 那么其他人的延迟会取决于这个人的带宽和与他连接的延迟, 并且如果服务端掉线了, 其他人是无法继续游戏的, 总之是一个不怎么好的游戏体验

这时候就需要专用服务器 (Dedicated Server) 来进行配置, 这样无论何时, 几个人, 只要服务器处于运行状态就可以进行游戏.

然而官方的 server 配置过于复杂: https://dontstarve.fandom.com/wiki/Guides/Don’t_Starve_Together_Dedicated_Servers#On_Linux_(Debian)

这就驱动了第三方开发各种各样的脚本来方便部署, 其中 docker 就是一个特别好用的打包手段, 这里选择了 github 上 star 最多的一个仓库作为示例, 实际上其他的镜像也都大差不差: https://github.com/Jamesits/docker-dst-server

注: 本文面向对 linux 和 docker 有一定了解的人, 不对系统和依赖安装做过多介绍, 主要内容在于如何进行配置

0 - 预准备

系统: debian11 (linux系统应该均可)

docker 安装

直接参考官网教程就可以: https://docs.docker.com/engine/install

1 - 配置 docker compose

来源于官方示例: https://github.com/Jamesits/docker-dst-server/blob/master/docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
version: '3.5'
services:
dst-server:
image: jamesits/dst-server:latest
restart: "on-failure:5"
ports:
- "10999-11000:10999-11000/udp"
- "12346-12347:12346-12347/udp"
volumes:
- ./data:/data
stop_grace_period: 6m

新建一个文件夹, 将上述文件保存为 docker-compose.yml 后启动 docker-compose up, 这时就会在文件夹下生成如下所示的目录:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
├── Cluster_1    ## 配置地上世界和洞穴以及一些必要的配置
│ ├── Caves ## 洞穴配置
│ │ ├── modoverrides.lua ## mod参数配置
│ │ ├── server.ini ## 洞穴独立配置文件
│ │ ├── server_chat_log.txt ## 聊天日志
│ │ ├── server_log.txt ## 系统日志
│ │ └── worldgenoverride.lua ##世界地图配置
│ ├── Master ## 地上世界配置
│ │ ├── modoverrides.lua ## mod参数配置
│ │ ├── server.ini ## 洞穴独立配置文件
│ │ ├── server_chat_log.txt ## 聊天日志
│ │ ├── server_log.txt ## 系统日志
│ │ └── worldgenoverride.lua ##世界地图配置
│ ├── admin.txt ## 管理员名单
│ ├── blocklist.txt ## 黑名单
│ ├── cluster.ini ## 通用配置文件
│ ├── cluster_token.txt ## token
│ └── whitelist.txt ## 白名单
├── mods ## mod配置
│ └── dedicated_server_mods_setup.lua ## 保存服务器所用到的mod

2 - 申请 token

  • 客户端打开饥荒游戏
  • 点击左下角 account
  • 在弹出的浏览器中点击 游戏
  • 点击添加服务器, 然后记住 token
  • 到 docker 中将 token 黏贴到: ./data/DoNotStarveTogether/Cluster_1/cluster_token.txt
  • 进行 cluster 和 mod 等配置 (见下文), 然后重启即可

3 - 对 cluster 进行配置

需要修改的文件:

./data/DoNotStarveTogether/Cluster_1/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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
; Here is all the server configs you will ever want to change
[NETWORK]
; DO change the name and description please!
cluster_name = 老王艳春 ; 房间名
cluster_description = 老王艳春玩饥荒 ; 房间描述
cluster_password = 123123 ; 房间密码
offline_cluster = false ; 离线模式
lan_only_cluster = false ; 局域网模式
whitelist_slots = 1 ; 白名单模式
cluster_intention = social ; 游戏偏好,可选 cooperative, competitive, social, or madness,随便设置,没卵用
cluster_language = zh ; 语言
autosaver_enabled = true ; 自动保存
tick_rate = 30 ; 建议设置为 15-30, 数值越大服务器计算开销越大, 客户端通信频率越高

[GAMEPLAY]
game_mode = survival ; 游戏模式,可选 survival, endless or wilderness,与玩家死亡后的负面影响有关
max_players = 8 ; 最多游戏人数
pvp = false ; 是否开启玩家攻击
pause_when_empty = true ; 没有人的时候是否暂停游戏
vote_kick_enabled = false ; 投票踢人

; ----------- 以下的文件不用修改, 用自动生成的就可以

[STEAM]
steam_group_only = false
steam_group_id = 0
steam_group_admins = false

[MISC]
console_enabled = true
max_snapshots = 6

; ====================================================================
; STOP! Don't change configs below unless you know what you are doing.
; ====================================================================
[SHARD]
shard_enabled = true
bind_ip = 127.0.0.1
master_ip = 127.0.0.1
master_port = 10998
cluster_key = MsAhBOXhhnElO5IPKr4G

4 - mod 安装 (重点)

需要注意的是, 此 docker 镜像在 mod 安装时有bug, 具体可以参考这个ISSUE: https://github.com/Jamesits/docker-dst-server/issues/53

简单来说就是有些 mod 会装不上, 因为 v1 和 v2 的 mod 会下载到不同的文件夹中, 而 docker 中只处理了一个版本的 mod

以下会对如何修复做出介绍

通用 mod 安装

mod 的安装需要服务端和客户端都进行配置, 具体如下:

服务端配置 :

编辑: ./data/DoNotStarveTogether/Cluster_1/mods/dedicated_server_mods_setup.lua, 填写自己想安装的 mod id, 示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
--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("375859599") -- global position
ServerModSetup("378160973") -- health info
ServerModSetup("666155465") -- show me
ServerModSetup("501385076") -- 快速采集
ServerModSetup("1207269058") -- simple health bar

其中 mod id 就是点开 steam 的创意工坊, ?id=xxx 后跟的一串数字

注: mod 主要有 all_clients_require_mod , server_only_mod 以及 clients_only_mod, 服务器只需要安装前两个, 最后一个是客户端本地安装和配置的, 不需要在服务器上安装

上述配置主要是让服务端下载 mod, 然后对于 mod 的配置文件需要客户端进入游戏进行 ui 配置 (当然你能手写配置文件也行), 然后上传到服务器, 步骤如下:

客户端配置:

  • 首先需要客户端安装同样的 mod, 并在配置中进行自己想要的配置, 然后按如下步骤将客户端的配置上传到服务器:

  • 本地 上传 modoverrides.lua 文件到服务器对应目录

    • 本地保存位置: (mac 为例, windows 只是前缀不一样, 其他路径是一模一样的) /Documents/Klei/DoNotStarveTogether/xxxxx/Cluster_1/Master/modoverrides.lua
    • 服务器保存位置: /data/DoNotStarveTogether/Cluster_1/Master/modoverrides.lua
  • 在服务器上重启 docker compose restart 即可

mod 安装不上的 bug 以及解决方案

在 mod 安装过程中, 我发现有几个 mod 死活装不上, 查看 ISSUE 后发现原因:

原因是mod有两个版本, 一个安装在 ~/Library/Application Support/Steam/steamapps/workshop/content 中, 而另一个安装在 ~/Library/Application Support/Steam/steamapps/common/Don't Starve Together/dontstarve_steam.app/Contents/mods

docker 版本只会下载第一种mod, 不会下载第二种

这时候就需要手动将第一种 mod 的安装文件上传到服务器, 经测试服务器重启后可以正确解析和安装 mod, 方法如下:

  • 本地的 v2 mod 的位置: Library/Application Support/Steam/steamapps/common/Don't Starve Together/dontstarve_steam.app/Contents/mods/workshop-*

  • 服务器 v2 mod 的存放位置: /data/DoNotStarveTogether/Cluster_1/mods/

以我自己为例, 直接 scp 上传即可:

1
scp -r /Users/roccoshi/Library/Application Support/Steam/steamapps/common/Don't Starve Together/dontstarve_steam.app/Contents/mods/workshop-* moreality@<服务器IP>:/home/moreality/docker-apps/dst-server/data/DoNotStarveTogether/Cluster_1/mods/

然后重启就大功告成啦!


饥荒服务器搭建 (docker)
https://blog.roccoshi.top/posts/17791/
作者
Moreality
发布于
2023年7月22日
许可协议