最后更新于 2019 年 1 月 10 日
本文以 Ubuntu 16.04,64 位系统为例,介绍如何搭建 Don’t Starve Together 联机服务器。
准备工作 划分 swap 分区如果您需要改变 swap 大小,参照这篇 文章。
安装依赖1 2 3 4 5 dpkg --add-architecture i386 apt update apt dist-upgrade -y apt autoremove -y apt install screen vim lib32gcc1 lib32stdc++6 libcurl4-gnutls-dev:i386 -y
添加并切换用户 安装 SteamCMD1 2 3 wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz tar -xvzf steamcmd_linux.tar.gz mkdir server_dst
安装 DST1 2 3 4 5 ./steamcmd.sh login anonymous force_install_dir /home/dst/server_dst app_update 343050 validate quit
获取令牌在你本地电脑登录游戏后,进入按键盘上~进入饥荒控制台。输入TheNet:GenerateClusterToken()
,将会生成一个令牌文件——
在 Windows:
/My Documents/Klei/DoNotStarveTogether/cluster_token.txt
在 Linux:
~/.klei/DoNotStarveTogether/cluster_token.txt
在 Mac OS X:
~/Documents/Klei/DoNotStarveTogether/cluster_token.txt
Ubuntu 服务器可以新建一个存档配置文件夹:
1 mkdir -p ~/.klei/DoNotStarveTogether/MyDediServer/Master
将此令牌上传到Ubuntu服务器上的 ~/.klei/DoNotStarveTogether/MyDediServer/
目录中。
配置文件 游戏配置在本地电脑登录游戏后,新建一个饥荒房间,期间选择你喜欢的配置。进入游戏后退出即可。参照获取令牌一节,在电脑的 DoNotStarveTogether
文件夹里找到刚刚创建的配置文件夹。例如找到了 MyDediServer/Master/worldgenoverride.lua
文件,将其上传到 /home/dst/.klei/DoNotStarveTogether/MyDediServer/Master/worldgenoverride.lua
。如果需要开启洞穴,则寻找相应的文件,上传到 /home/dst/.klei/DoNotStarveTogether/MyDediServer/Caves/worldgenoverride.lua
。
连接配置1 vim /home/dst/.klei/DoNotStarveTogether/MyDediServer/cluster.ini
/home/dst/.klei/DoNotStarveTogether/MyDediServer/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 [GAMEPLAY] game_mode = endlessmax_players = 6 pvp = false pause_when_empty = true [NETWORK] lan_only_cluster = false cluster_intention = socialcluster_password = 密码cluster_description = 描述cluster_name = 名字offline_cluster = false autosaver_enabled = true enable_vote_kick = false [MISC] console_enabled = true [SHARD] shard_enabled = false bind_ip = 127.0 .0.1 master_ip = 127.0 .0.1 master_port = 10898 cluster_key = defaultPass
说明:
game_mode: survival, endless or wilderness
cluster_intention: cooperative, competitive, social, or madness
地上连接1 vim /home/dst/.klei/DoNotStarveTogether/MyDediServer/Master/server.ini
/home/dst/.klei/DoNotStarveTogether/MyDediServer/Master/server.ini 1 2 3 4 5 6 7 8 9 10 11 12 [NETWORK] server_port = 10999 [SHARD] is_master = true [STEAM] master_server_port = 27017 authentication_port = 8769 [ACCOUNT] encode_user_path = true
洞穴连接1 vim /home/dst/.klei/DoNotStarveTogether/MyDediServer/Caves/server.ini
/home/dst/.klei/DoNotStarveTogether/MyDediServer/Caves/server.ini 1 2 3 4 5 6 7 8 9 10 [NETWORK] server_port = 11000 [SHARD] is_master = false name = Caves[STEAM] master_server_port = 12348 authentication_port = 12347
Mods 安装和配置 安装首先你需要知道 mod 的 id 。到创意工坊,mod 的详情页,把 url 后面的数字参数复制出来,那个就是编号,例如 https://steamcommunity.com/sharedfiles/filedetails/?id=683832500
那么 ``683832500` 就是 mod 的 id 。
把你需要的 mod 按如下方式添加:
1 vim /home/dst/server_dst/mods/dedicated_server_mods_setup.lua
写入你一些想要添加的 mod,例如:
/home/dst/server_dst/mods/dedicated_server_mods_setup.lua 1 2 3 4 5 ServerModSetup("656256171" ) ServerModSetup("458587300" ) ServerModSetup("387385956" ) ServerModSetup("597710604" ) ServerModSetup("375859599" )
配置在本地电脑开一个新游戏,选上你想要添加的mod,创建世界后退出。去 klei 下存档找到 modoverrides.lua
这个文件,然后上传到服务器 /home/dst/.klei/DoNotStarveTogether/MyDediServer/Master/
下。
当然你也可以手动在服务器上创建一个新的配置,内容示例:
1 vim /home/dst/.klei/DoNotStarveTogether/MyDediServer/Master/modoverrides.lua
/home/dst/.klei/DoNotStarveTogether/MyDediServer/Master/modoverrides.lua 1 2 3 4 5 6 7 8 9 10 11 12 13 return { ["workshop-597710604" ] = { enabled = true }, ["workshop-375859599" ] = { enabled = true }, ["workshop-458587300" ] = { enabled = true }, ["workshop-656256171" ] = { enabled = true , configuration_options ={ give_dubloons= 3 , rec_gold = 1 , rec_dubloon = 1 , } }, }
洞穴配置同理。
创建启动脚本1 vim /home/dst/server_dst/bin/start.sh
/home/dst/server_dst/bin/start.sh 1 ./dontstarve_dedicated_server_nullrenderer -console -cluster MyDediServer -shard Master
如果需要开启洞穴,另添加:
1 vim /home/dst/server_dst/bin/start2.sh
/home/dst/server_dst/bin/start2.sh 1 ./dontstarve_dedicated_server_nullrenderer -console -cluster MyDediServer -shard Caves
创建重启脚本1 vim /home/dst/server_dst/bin/restart.sh
/home/dst/server_dst/bin/restart.sh 1 2 3 4 5 6 7 8 9 10 11 12 13 #!/bin/sh name_folder="/home/dst/server_dst/bin" start_overworld="sh start.sh" screen -dr dst_server1 -X -S quit cd ${name_folder} screen -dmS dst_server1 ${start_overworld}
如果需要开启洞穴,另添加:
1 vim /home/dst/server_dst/bin/restart2.sh
/home/dst/server_dst/bin/restart2.sh 1 2 3 4 5 6 7 8 9 10 11 12 13 #!/bin/sh name_folder="/home/dst/server_dst/bin" start_cave="sh start2.sh" screen -dr dst_server2 -X -S quit cd ${name_folder} screen -dmS dst_server2 ${start_cave}
创建更新脚本1 vim /home/dst/server_dst/bin/update.sh
无洞穴版/home/dst/server_dst/bin/update.sh 1 2 3 4 5 6 7 8 screen -dr dst_server1 -X quit cp /home/dst/server_dst/mods/dedicated_server_mods_setup.lua /home/dst/server_dst/mods/.dedicated_server_mods_setup.luacd /home/dst./steamcmd.sh +login anonymous +force_install_dir /home/dst/server_dst +app_update 343050 validate +quit sleep 10cp /home/dst/server_dst/mods/.dedicated_server_mods_setup.lua /home/dst/server_dst/mods/dedicated_server_mods_setup.luash /home/dst/server_dst/bin/restart.sh
带洞穴版/home/dst/server_dst/bin/update.sh 1 2 3 4 5 6 7 8 9 10 screen -dr dst_server1 -X quit screen -dr dst_server2 -X quit cp /home/dst/server_dst/mods/dedicated_server_mods_setup.lua /home/dst/server_dst/mods/.dedicated_server_mods_setup.luacd /home/dst./steamcmd.sh +login anonymous +force_install_dir /home/dst/server_dst +app_update 343050 validate +quit sleep 10cp /home/dst/server_dst/mods/.dedicated_server_mods_setup.lua /home/dst/server_dst/mods/dedicated_server_mods_setup.luash /home/dst/server_dst/bin/restart.sh sh /home/dst/server_dst/bin/restart2.sh
创建自动更新任务/home/dst/cron 1 0 3 * * * sh /home/dst/server_dst/bin/update.sh
表示在每日凌晨 3 点更新游戏(注意服务器的时区是否恰当)。
运行1 sh /home/dst/server_dst/bin/restart.sh
如果开启洞穴,另运行:
1 sh /home/dst/server_dst/bin/restart2.sh
查看日志1 tail -f /home/dst/.klei/DoNotStarveTogether/MyDediServer/Master/server_log.txt
如果开启了洞穴,另运行:
1 tail -f /home/dst/.klei/DoNotStarveTogether/MyDediServer/Caves/server_log.txt
ReferencesHow to setup dedicated server with cave on Linux
How to install,configure and update mods on Dedicated Server
在 Linux(Ubuntu) 中搭建饥荒联机版服务器