搭建 Don't Starve Together 服务器
距离上次和大家一起玩饥荒,已经是两年前的事情了。犹记得那年的情人节,在游戏里发生的一件趣事,戳这里。
前几天应 @Mengyun 的邀请,再次来到饥荒世界。按照之前的服务器搭建步骤,踩了几个小坑,所以重新梳理了一遍,在此记录下来。
如果你还不知道这款游戏,可以在 饥荒 Wiki 和 Don’t Starve 中进行了解。这里涉及到的是 Don't Starve Together,即饥荒联机版。
搭建环境
为了稳定的游戏体验,服务器配置需满足以下要求:
- Internet (Upload) = 8Kbytes / player / s
- RAM = around 65Mbytes / player
- CPU = N/A
本人使用的是某国内云服务器,配置为:
- OS: Ubuntu Server 16.04.1 LTS 64-bit
- CPU: 2 Core
- RAM: 4GB
- Bandwidth: 1Mbps
安装步骤
Step 1 - 安装依赖包
$ sudo dpkg --add-architecture i386
$ sudo apt-get update
$ sudo apt-get install lib32gcc1
$ sudo apt-get install lib32stdc++6
$ sudo apt-get install libgcc1
$ sudo apt-get install libcurl4-gnutls-dev:i386
$ sudo apt-get install screen
Step 2 - 创建新用户
$ sudo useradd -m steam
$ sudo passwd steam
Step 3 - 给新用户添加 sudo 权限
$ sudo chmod u+w /etc/sudoers
$ sudo vim /etc/sudoers
将下面的配置添加在 /etc/sudoers
文件中,为新用户提供 sudo 权限:
steam ALL=(ALL:ALL) NOPASSWD: ALL
恢复原来的文件权限:
$ sudo chmod u-w /etc/sudoers
Step 4 - 切换至新用户
$ sudo su - steam
Step 5 - 安装 SteamCMD
$ mkdir ~/steamcmd && cd ~/steamcmd
$ sudo wget http://media.steampowered.com/installer/steamcmd_linux.tar.gz
$ tar -xvzf steamcmd_linux.tar.gz
$ ./steamcmd.sh +login anonymous +force_install_dir /home/steam/steamapps/DST +app_update 343050 validate +quit
如果安装成功,将会看到如下输出:
Update state (0x61) downloading, progress: 99.82 (1163384067 / 1165481219)
Success! App '343050' fully installed.
CWorkThreadPool::~CWorkThreadPool: work processing queue not empty: 1 items discarded.
Step 6 - 运行
$ cd /home/steam/steamapps/DST/bin/
$ screen -S "DST" ./dontstarve_dedicated_server_nullrenderer
此时将会看到 Your Server Will Not Start
提示:
[00:00:05]: FilesExistAsyncThread started (16501 files)...
[00:00:06]: [200] Account Failed (6): "E_INVALID_TOKEN"
[00:00:06]: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
[00:00:06]: !!!! Your Server Will Not Start !!!!
[00:00:06]: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
[00:00:06]: No auth token could be found.
[00:00:06]: To generate a cluster_token you must
[00:00:06]: open the console from a logged-in game
原因是服务器端没有配置 Token 文件。ctrl + c
终止 screen
。
Step 7 - 生成 Token
启动游戏客户端,在游戏主界面点击 Account
图标后,会在浏览器中打开 Token 生成页面。
滚动至页面底部,在右侧输入框中填写描述后点击 Generate Server Token
即可生成 Token,将 Token 复制到 cluster_token.txt
文件中。
$ vim ~/.klei/DoNotStarveTogether/Cluster_1/cluster_token.txt
Step 8 - 配置服务器
$ vim ~/.klei/DoNotStarveTogether/Cluster_1/cluster.ini
cluster.ini
[NETWORK]
cluster_name = A unique server name
cluster_description = A very nice server description
cluster_password = password
cluster_intention = cooperative | social | competitive | madness
[GAMEPLAY]
max_players = [1 - 64]
pvp = true | false
game_mode = endless | survival | wilderness
enable_autosaver = true | false
pause_when_empty = true | false
[MISC]
console_enabled = true | false
cluster.ini 示例
[NETWORK]
cluster_intention = cooperative
cluster_name = Hello, world!
cluster_description = This is a world of programmers.
cluster_password = 1024
[GAMEPLAY]
max_players = 12
pvp = false
game_mode = endless
enable_autosaver = true
pause_when_empty = true
Step 9 - 配置游戏地图
如果使用默认地图配置,可以略过此步骤。
$ vim ~/.klei/DoNotStarveTogether/Cluster_1/Master/worldgenoverride.lua
worldgenoverride.lua
return {
override_enabled = false | true,
overrides = {
world_size = "small" | "medium" | "large" | "huge", -- 地图大小
grass = "never" | "rare" | "default" | "often" | "always" -- 草资源数量
}
}
worldgenoverride.lua 示例
return {
override_enabled = true,
overrides = {
world_size = "huge",
grass = "often",
flowers = "often",
sapling = "often",
berrybush = "often",
carrot = "often",
flint = "often",
rock = "often",
sapling = "often"
}
}
Step 10 - 配置 Mod
如果无需安装 Mod,可以略过此步骤。
安装 Mod
$ vim ~/steamapps/DST/mods/dedicated_server_mods_setup.lua
edicated_server_mods_setup.lua 示例
ServerModSetup("378160973")
ServerModSetup("374550642")
Mod 可以在创意工坊中查看,Mod 对应的 id 可以在 URL 中找到。例如,Global Positions 的 URL 为 https://steamcommunity.com/sharedfiles/filedetails/?id=378160973
,那么对应的 id 就是 378160973
。
启用 Mod
$ vim ~/.klei/DoNotStarveTogether/Cluster_1/Master/modoverrides.lua
modoverrides.lua 示例
return {
["workshop-378160973"] = { enabled = true }, -- Global Positions
["workshop-374550642"] = { enabled = true }, -- Increased Stack size
}
Step 11 - 创建运行脚本
$ vim /home/steam/start.sh
start.sh
#!/bin/bash
cd /home/steam/steamapps/DST/bin
/usr/bin/screen -S "DST" bash -c 'LD_LIBRARY_PATH=~/dst_lib ./dontstarve_dedicated_server_nullrenderer -console'
给予脚本权限:
$ sudo chmod 700 start.sh
Step 12 - 创建更新脚本
$ vim vim /home/steam/update.sh
update.sh
#!/bin/sh
/home/steam/steamcmd/steamcmd.sh +@ShutdownOnFailedCommand 1 +@NoPromptForPassword 1 +login anonymous +force_install_dir /home/steam/steamapps/DST +app_update 343050 validate +quit
/home/steam/steamapps/DST/bin/dontstarve_dedicated_server_nullrenderer -only_update_server_mods
给予脚本权限:
$ sudo chmod +x update.sh
Step 13 - 再次运行
$ ~/.start.sh
注意
Cannot open your terminal '/dev/pts/0'
如果在使用 screen
命令时,出现 Cannot open your terminal '/dev/pts/0' - please check.
问题,可执行如下命令解决:
script /dev/null
查看游戏运行日志
查看现有会话:
screen -ls
Output
There is a screen on:
10786.DST (08/26/2018 08:43:12 PM) (Detached)
1 Socket in /var/run/screen/S-steam.
复制 <screen_pid>
,然后使用 screen -r <screen_pid>
命令进入会话。
screen -r 10786.DST
参考链接
Don't Starve Together Forums
Mod Workshop
Don't Starve Game Wiki