参考
-
Docker 配置部分参考了
GitHub - Jamesits/docker-dst-server: Don't Starve Together dedicated server in Docker! -
Mod 配置部分参考了
Guides/Don’t Starve Together Dedicated Servers | Don't Starve Wiki | Fandom
步骤
总体上可以分成两个步骤:1. 搭基本的服务器,2. 加上mod。其中第一步看参考链接的第一个即可,第二个步骤我找到了一个自己的方法。
1 搭建基本服务器
1.1 启动Docker
docker-compose.yml
:
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:
- ~/.klei/DoNotStarveTogether:/data
stop_grace_period: 6m
可以看到配置文件中告诉我们了服务器的配置在 ~/.klei/DoNotStarveTogether
这里。我个人在 Linux 上的具体路径是这样的:/home/username/.klei/DoNotStarveTogether/DoNotStarveTogether/Cluster_1/
。如果你的不一样,你就一直往下找到 Cluster_1
目录即可。目录中有以下内容:
adminlist.txt blocklist.txt Caves cluster.ini cluster_token.txt Master mods whitelist.txt
docker compose up
直接启动起来之后会报错,显示缺少 token,大概的步骤是:你需要先在 klei 网站上建立一个 server,获取 token 并放到文件 cluster_token.txt
中,且你需要自行修改一下启动配置文件 cluster.ini
,这里面配置了服务器名等信息。这个时候 ctrl + c
退出来 docker,先参考如下步骤把这两个文件改一下:
1.2 Server Configuration
If you don’t already have a set of server config in your data directory, we will generate one for you. Start server once using the command above, and you will see:
Creating default server config...
Please fill in `DoNotStarveTogether/Cluster_1/cluster_token.txt` with your cluster token and restart server!
To generate a cluster token (as of 2019-11-02):
- Open a genuine copy of Don’t Starve Together client and log in
- Click “Play” to go to the main menu
- click “account” button on the bottom left of the main menu
- In the popup browser, click “GAMES” on the top nav bar
- Click “Don’t Starve Toegther Servers” button on the top right
- Scroll down to “ADD NEW SERVER” section, fill in a server name (it is not important), and copy the generated token
The token looks like pds-g^aaaaaaaaa-q^jaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa=
. Then either set DST_CLUSTER_TOKEN
environment variable during docker run
, or paste the token into your_data_directory/DoNotStarveTogether/Cluster_1/cluster_token.txt
.
If you need to add mods, change world generation config, etc., please do it now. Don’t forget to edit your_data_directory/DoNotStarveTogether/Cluster_1/cluster.ini
and get your server an unique name!
After you finish this, re-run start server command, and the server should be running.
1.3 启动(此时还没有加 mod)
当上面两个文件修改好之后,docker compose up
看看是不是成功启动了,再看看是不是能搜索到并且连进去,如果可以就说明前面的步骤都成功了。
2 加上 mod
首先讲讲这一步的理论原理。我们的服务器需要下载下来需要的 mod,然后要在配置文件里面启用mod。其中下载 mod 的配置文件为 mods/dedicated_server_mods_setup.lua
,在这里面使用 ServerModSetup
的 mod 会自动下载下来,这个函数的名字最开始误导了我,以为会自动启用,然而并不是,启用需要另外配置。
参考链接中说启用 mod 有两种方法,一是编辑 mods/modsettings.lua
文件,直接 ForceEnableMod
函数强制启用,然而我试了下这个方法没有成功。二是使用 modoverrides.lua
文件来启用 mod。实际上这个文件是 mod 的配置文件,在这里面的 mod 都会被启用。
问题来了,我们应该如何知道配置文件该怎么写呢?只需要本地开个服务器把 mod 启用了,然后再看看本地的配置文件怎么写的就行√
理论原理介绍结束,下面开始实际操作。
2.1 本机建立服务器
我们需要在本地的饥荒里面先开一个服务器(记得创建洞穴,因为server里面是默认有洞穴的,而我写这个帖子的时候,本机开服务器是默认没有洞穴的)。然后在服务器里面把你要用到的mod都启用,创建世界,选择人物进入世界之后就可以退出了,因为我们只是需要这个档创建的配置文件而已。
2.2 复制 mod 配置文件内容来配置 mod 的启用
你的电脑上会有一个类似 C:\Users\username\Documents\Klei\DoNotStarveTogether\id\Cluster_1
的文件夹,这个文件夹保存着你刚刚创建的饥荒服务器的配置信息(如果你本机开了多个服务器,找不到是哪个id了,建议把别的都删了,只保留刚建的,这样比较好找)。目录下有 Caves
和 Master
两个目录,刚好对应服务器上面的 Caves
和 Master
。这两个文件夹里面都有一个叫做 modoverrides.lua
的文件(不出意外的话这两个文件内容是一样的,因为主世界和洞穴里面用的 mod 都一样)。这个文件的内容大概是这样:
return {
["workshop-1207269058"]={ configuration_options={ }, enabled=true },
["workshop-1432504104"]={
configuration_options={ diff="", language="AUTO", skill=1, skillkey="KEY_V" },
enabled=true
},
...
}
我们要在服务器上面的 Caves
和 Master
中也分别创建 modoverrides.lua
文件,且内容分别与本地的要对应。
2.3 配置 mod 的下载
在上一步的 modoverrides.lua
文件中,我们可以注意到每个开了的mod都有对应的配置项,不难看出例子中 ["workshop-1207269058"]
中的 1207269058
是模组的id。我们找到服务器配置目录下 mods/dedicated_server_mods_setup.lua
文件并写入类似这样的内容:
--# Simple Health Bar DST
ServerModSetup("1207269058")
每个 mod 都写一行即可,引号中的为 mod 的 id,即你需要把 modoverrides.lua
文件中的 mod 的 id 一个个在这里都写进去。这也很好理解,你启用的 mod 都要先下载下来对吧。
2.4 启动服务(此时是加了 mod 的)
上面都配好之后,docker compose up
看看能不能成功启动并成功连上进去,看看 mod 是不是打上了。如果可以的话就 ctrl + c
退出再 docker compose up -d
在后台运行即可。
2.5 后续更新
每次饥荒更新,都需要上服务器手动更新一下,使用 docker compose down
再重新 docker compose up -d
即可自动更新并启动。
我遇到的其他问题
我在配完以上步骤后还是遇到了问题,通过看报错输出发现有一个模组加载失败了,其他模组没有遇到这个问题,于是我删除了这个模组的配置文件重新启动 docker,成功。
参考配置
这里给出我的配置文件,供参考:
mods/dedicated_server_mods_setup.lua
--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")
--# Simple Health Bar DST
ServerModSetup("1207269058")
--#Insight
ServerModSetup("2189004162")
--#Show Me (中文)
ServerModSetup("2287303119")
--#Health Info
ServerModSetup("375859599")
--#Global Positions
ServerModSetup("378160973")
--#Yakumo Yukari Alpha v12
ServerModSetup("1432504104")
--#Scheme Network(Custom Wormhole)
ServerModSetup("1602267559")
--#Myth Characters-神话人物
ServerModSetup("1699194522")
--#[Arknights]Amiya
ServerModSetup("1892210190")
--#Myth Words Theme-神话书说
ServerModSetup("1991746508")
--#Smart Chest
ServerModSetup("2097358269")
--#Increased Stack size
ServerModSetup("2519429353")
--#大背包 Big Bag-新
ServerModSetup("2574469496")
Master/modoverrides.lua
和 Caves/modoverrides.lua
return {
["workshop-1207269058"]={ configuration_options={ }, enabled=true },
["workshop-1432504104"]={
configuration_options={ diff="", language="AUTO", skill=1, skillkey="KEY_V" },
enabled=true
},
["workshop-1602267559"]={
configuration_options={
alter="townportaltalisman",
alterval=50,
craftable=true,
ignoreboss=false,
ignoredanger=false,
language="AUTO",
spawncost=100,
usecost=50
},
enabled=true
},
["workshop-1699194522"]={ configuration_options={ }, enabled=true },
["workshop-1892210190"]={ configuration_options={ Language="nil", TuneMode="normal" }, enabled=true },
["workshop-1991746508"]={ configuration_options={ Language="A", ShowBuff=true }, enabled=true },
["workshop-2097358269"]={
configuration_options={
collect_items_dist0=1,
collect_items_dist1=6,
dragonflychest=1,
icebox=1,
is_collect_drop=1,
is_collect_lootdropper=1,
is_collect_open=1,
is_collect_periodicspawner=1,
is_collect_take=1,
iscollectone=1,
minisign_dist=1.5,
saltbox=1,
treasurechest=1,
["收集时机"]=false,
["收集种类限制"]=false,
["箱子种类"]=false,
["距离设置 (4 == 一块地皮)"]=false
},
enabled=true
},
["workshop-2189004162"]={
configuration_options={
DEBUG_ENABLED=false,
DEBUG_SHOW_DISABLED=false,
DEBUG_SHOW_NOTIMPLEMENTED=false,
DEBUG_SHOW_PREFAB=false,
alt_only_information=false,
appeasement_value="undefined",
attack_range_type="undefined",
battlesong_range="both",
blink_range=true,
boss_indicator=true,
bottle_indicator=true,
crash_reporter=false,
display_attack_range="undefined",
display_cawnival="undefined",
display_crafting_lookup_button=true,
display_fertilizer="undefined",
display_finiteuses=true,
display_fishing_information="undefined",
display_food="undefined",
display_harvestable=true,
display_health="undefined",
display_hunger="undefined",
display_insight_menu_button=true,
display_mob_attack_damage="undefined",
display_perishable="undefined",
display_pickable=true,
display_plant_stressors="undefined",
display_pollination="undefined",
display_sanity="undefined",
display_sanityaura="undefined",
display_shared_stats="undefined",
display_shelter_info="undefined",
display_spawner_information="undefined",
display_timers="undefined",
display_unwrappable="undefined",
display_upgradeable="undefined",
display_weather="undefined",
display_weighable="undefined",
display_world_events="undefined",
display_worldmigrator="undefined",
display_yotb_appraisal="undefined",
display_yotb_winners="undefined",
domestication_information="undefined",
extended_info_indicator=true,
follower_info="undefined",
food_effects=true,
food_memory="undefined",
food_order="interface",
food_style="long",
food_units=true,
fuel_highlighting=false,
fuel_highlighting_color="RED",
fuel_verbosity="undefined",
growth_verbosity="undefined",
herd_information="undefined",
highlighting=true,
highlighting_color="GREEN",
hover_range_indicator=true,
hunt_indicator="undefined",
info_preload="undefined",
info_style="text",
item_worth="undefined",
itemtile_display="percentages",
klaus_sack_markers="undefined",
language="automatic",
lightningrod_range=1,
naughtiness_verbosity="undefined",
nightmareclock_display="undefined",
notable_indicator=true,
orchestrina_indicator="undefined",
pipspook_indicator=true,
refresh_delay="undefined",
repair_values="undefined",
sinkhole_marks=2,
soil_moisture=2,
soil_nutrients="undefined",
soil_nutrients_needs_hat="undefined",
stewer_chef="undefined",
text_coloring=true,
time_style="gametime",
unique_info="undefined",
weapon_damage="undefined",
wortox_soul_range=true,
["信息控制"]=0,
["指示器"]=0,
["杂项"]=0,
["格式"]=0,
["调试"]=0,
["食物相关"]=0
},
enabled=true
},
["workshop-2287303119"]={
configuration_options={
[""]=0,
T_crop=true,
chestB=-1,
chestG=-1,
chestR=-1,
display_hp=1,
food_estimation=-1,
food_order=0,
food_style=0,
item_info_mod=0,
lang="Auto",
show_buddle_item=1,
show_food_units=-1,
show_uses=-1
},
enabled=true
},
["workshop-2519429353"]={ configuration_options={ MAXSTACKSIZE=99 }, enabled=true },
["workshop-2574469496"]={
configuration_options={
BAGINBAG=false,
BAGSIZE=1,
BIGBAGPICK=false,
BIGBAGWATER=false,
CONTAINERDRAG_SWITCH="KEY_F1",
FRESH=false,
HEATROCKTEMPERATURE=false,
KEEPFRESH=false,
LANG=1,
LIGHT=false,
NICEBIGBAGSIZE=2,
RECIPE=3,
STACK=false,
WALKSPEED=0.75
},
enabled=true
},
["workshop-375859599"]={
configuration_options={
divider=5,
random_health_value=0,
random_range=0,
send_unknwon_prefabs=false,
show_type=0,
unknwon_prefabs=1,
use_blacklist=true
},
enabled=true
},
["workshop-378160973"]={
configuration_options={
ENABLEPINGS=true,
FIREOPTIONS=2,
OVERRIDEMODE=false,
SHAREMINIMAPPROGRESS=true,
SHOWFIREICONS=true,
SHOWPLAYERICONS=true,
SHOWPLAYERSOPTIONS=2
},
enabled=true
}
}