Linux 上搭建饥荒联机版 Don't Starve Together 服务器

1.配置服务器 Linux 环境
2.安装 STEAMCMD 命令行平台及游戏包
3.配置 Don't Starve Together
3.1.生成默认配置文件
3.2设置 Token
3.3设置服务器全局配置
3.4设置局部配置
4.增加 Mod(可选)
5.启动服务器

配置服务器 Linux 环境

这里用的是 Ubuntu 16.04 LTS,根据不同环境安装不同的依赖库
Ubuntu 64 位环境:

sudo apt-get install libstdc++6:i386 libgcc1:i386 libcurl4-gnutls-dev:i386  

Ubuntu 32 位环境:

sudo apt-get install libstdc++6 libgcc1 libcurl4-gnutls-dev  

安装 STEAMCMD 命令行平台及游戏包

下载 SteamCMD:

mkdir ~/steamcmd  
cd ~/steamcmd  
wget http://media.steampowered.com/installer/steamcmd_linux.tar.gz  

你也可以使用饥荒官网提供的精简版 SteamCMD:

wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz  

接着解压并运行安装:

tar -xvzf steamcmd_linux.tar.gz  
./steamcmd.sh

在steam>模式下,登录及安装游戏包

login anonymous  
force_install_dir ../dstserver  
app_update 343050 validate  
quit  

上面的命令中,第一行以匿名方式登录,当然你也可以登录你自己的 SteamID,然后第三行的343050是 Don't Starve Together 在 Steam 平台中的 ID。

等待更新结束后,平台和游戏包就安装好了,已经完成了一半的工作,接下来是配置了。

配置Don't Starve Together

生成默认配置文件

cd ~/dstserver/bin  
./dontstarve_dedicated_server_nullrenderer

当看到以下提示

[200] Account Failed (6): "E_INVALID_TOKEN"
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!! Your Server Will Not Start !!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

按Ctrl+C中断,然后完善生成的默认配置

设置Token 这里由于搭建的Steam平台的正版服务器,需要在游戏中获取一个Token,正常进入Don't Starve Together游戏,然后选择我的资料,在弹出的页下方可以生成token,复制到cluster_token.txt中

cd ~/.klei/DoNotStarveTogether/Cluster_1  
vi cluster_token.txt  

粘贴后保存该文件

设置服务器全局配置

cd ~/.klei/DoNotStarveTogether/Cluster_1  
vi cluster.ini  

填入以下内容:

[GAMEPLAY]
game_mode = survival  
max_players = 6  
pvp = false  
pause_when_empty = true

[NETWORK]
cluster_description = INSTART Server  
cluster_name = INSTART Server  
cluster_intention = cooperative  
cluster_password = 

[STEAM] 
steam_group_admins = true  
steam_group_id =  
steam_group_only = false

[MISC]
console_enabled = true

[SHARD]
shard_enabled = true  
bind_ip = 127.0.0.1  
master_ip = 127.0.0.1  
master_port = 10889  
cluster_key = supersecretkey  

注意上面的clustername是服务器房间名,clusterpassword是服务器房间密码,可以自行修改.

配置文件说明如下:

[MISC]
max_snapshots = 6                  # 最大快照数,决定了可回滚的天数  
console_enabled = true             # 是否开启控制台

[SHARD]
shard_enabled = true               # 服务器共享,要开启洞穴服务器的必须启用  
bind_ip = 127.0.0.1                # 服务器监听的地址,当所有实例都运行在同一台机器时,可填写 127.0.0.1,会被 server .ini 覆盖  
master_ip = 127.0.0.1              # master 服务器的 IP,针对非 master 服务器,若与 master 服务器运行在同一台机器时,可填写 127.0.0.1,会被 server.ini 覆盖  
master_port = 10888                # 监听 master 服务器的 UDP 端口,所有连接至 master 服务器的非 master 服务器必须相同  
cluster_key = dst                  # 连接密码,每台服务器必须相同,会被 server.ini 覆盖

[STEAM]
steam_group_only = false           # 只允许某 Steam 组的成员加入  
steam_group_id = 0                 # 指定某个 Steam 组,填写组 ID  
steam_group_admins = false         # 开启后,Steam 组的管理员拥有服务器的管理权限

[NETWORK]
offline_server = false             # 离线服务器,只有局域网用户能加入,并且所有依赖于 Steam 的任何功能都无效,比如说饰品掉落  
tick_rate = 15                     # 每秒通信次数,越高游戏体验越好,但是会加大服务器负担  
whitelist_slots = 0                # 为白名单用户保留的游戏位  
cluster_password =                 # 游戏密码,不设置表示无密码  
cluster_name = ttionya test        # 游戏房间名称  
cluster_description = description  # 游戏房间描述  
lan_only_cluster = false           # 局域网游戏  
cluster_intention = madness        # 游戏偏好,可选 cooperative, competitive, social, or madness,随便设置,没卵用

[GAMEPLAY]
max_players = 16                   # 最大游戏人数  
pvp = true                         # 能不能攻击其他玩家,能不能给其他玩家喂屎  
game_mode = survival               # 游戏模式,可选 survival, endless or wilderness,与玩家死亡后的负面影响有关  
pause_when_empty = false           # 没人服务器暂停,刷天数必备  
vote_kick_enabled = false          # 投票踢人

设置局部配置

cd ~/.klei/DoNotStarveTogether/Cluster_1/Master  
vi server.ini  

填入

[NETWORK]
server_port = 11000

[SHARD]
is_master = true

[STEAM]
master_server_port = 27018  
authentication_port = 8768  

接着在改洞穴部分

cd ~/.klei/DoNotStarveTogether/Cluster_1/Caves  
vi server.ini  

填入

[NETWORK]
server_port = 11001

[SHARD]
is_master = false  
name = Caves

[STEAM]
master_server_port = 27019  
authentication_port = 8769  

配置说明文件如下:

[SHARD]
is_master = true /false      # 是否是 master 服务器,只能存在一个 true,其他全是 false  
name = caves                 # 针对非 master 服务器的名称  
id = ???                     # 随机生成,不用加入该属性

[STEAM]
authentication_port = 8766   # Steam 用的端口,确保每个实例都不相同  
master_server_port = 27016   # Steam 用的端口,确保每个实例都不相同

[NETWORK]
server_port = 10999          # 监听的 UDP 端口,只能介于 10998 - 11018 之间,确保每个实例都不相同

增加Mod(可选) 这里只加载了一个全局地图定位的Mod,加载其它可以根据Steam社区中Mod地址URL中的ID替换 第一次运行之后,把游戏mod上传到/root/dontstarvetogether_dedicated_server/mods文件夹下面。

创建下载Mod的脚本

cd ~/.klei/DoNotStarveTogether/Cluster_1  
vi dedicated_server_mods_setup.lua  

填入

ServerModSetup("378160973")  
--ServerModCollectionSetup("id")

创建Mod配置文件

cd ~/.klei/DoNotStarveTogether/Cluster_1/Master  
vi modoverrides.lua  

填入

return {  
["workshop-378160973"] = { enabled = true }
}

同样创建洞穴部分的

cd ~/.klei/DoNotStarveTogether/Cluster_1/Caves  
vi modoverrides.lua  

填入

return {  
["workshop-378160973"] = { enabled = true }
}

设定管理员

首先,你要得到你想要设为管理员的玩家的用户 id。

有两种方法:

1、让该玩家加入游戏,再查看日志,你会在日志中找到 KU_ 开头的一串用户 id

2、让该玩家点击游戏主页面的 Account 按钮(和获得 token 一样),在页面中会有用户 id

之后,把用户 id 一行放一个,保存在 adminlist.txt 文件中。下面是栗子:

cd ~/.klei/DoNotStarveTogether/Cluster_1  
vi adminlist.txt  
KU_SIyU7lzH  

Ban 用户(可选)

岂可休,有个奇怪的人进来就烧家

玛戈急,有个绅士给我喂屎

日了狗,对面的妹纸从裤裆中掏出了我想掏出的东西(喂

但是这种人踢了又进来,简直丧(gan)心(de)病(piao)狂(liang),不想再让他进来?Ban 了他!

从日志中找到他的 SteamID64,添加到 blocklist.txt 中,一行一个。

白名单席位(可选)

哇,服务器太火爆了,管理员都进不来了。怎么?想占着茅坑不拉屎?可以!

还记得 cluster.ini 里有一个 whitelist_slots 配置吗?这就是白名单席位。

白名单席位占用最大游戏人数,比如说,服务器一共开了 16 个位置,设置了 6 个白名单席位,此时,最多只能加入 10 个普通玩家。

与 blocklist.txt 对应,这个文件是 whitelist.txt,但是里面的内容是以 KU_ 开头的用户 id。

启动服务器

创建启动服务器脚本

cd ~/  
vi rundst.sh  

填入

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

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"

./steamcmd.sh +force_install_dir "$install_dir" +login anonymous +app_update 343050 validate +quit

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: /'

给脚本赋予执行权限

chmod u+x ~/rundst.sh  

接着进入screen,执行脚本,开启服务器

screen  
./rundst.sh

这样就大功告成了,enjoy!

Linux 系统 SteamCMD 搭建文件结构

/home/dst/.klei/DoNotStarveTogether\Cluster_1
|
|   adminlist.txt(/adminlist.txt)
|   blocklist.txt(/blocklist.txt)
|   cluster.ini(/cluster.ini)
|   cluster_token.txt(/cluster_token.txt)
|   whitelist.txt(/whitelist.txt)
|
|---Master
|   |   modoverrides.lua(/Master/modoverrides.lua)
|   |   server.ini(/Master/server.ini)
|   |   worldgenoverride.lua(/Master/worldgenoverride.lua)
|   |   其他文件
|   |
|   |---其他文件夹
|
|---Caves
    |   modoverrides.lua(/Caves/modoverrides.lua)
    |   server.ini(/Caves/server.ini)
    |   worldgenoverride.lua(/Caves/worldgenoverride.lua)
    |   其他文件
    |
    |---其他文件夹

/home/dst/dst/mods
|
|   dedicated_server_mods_setup.lua(/dedicated_server_mods_setup.lua)

世界地图配置文件

地上部分
地上部分,将文件保存为 worldgenoverride.lua,并放进 Master 文件夹中:

return {  
    override_enabled = true,
    preset = "SURVIVAL_TOGETHER",       -- "SURVIVAL_TOGETHER", "MOD_MISSING", "SURVIVAL_TOGETHER_CLASSIC", "SURVIVAL_DEFAULT_PLUS", "COMPLETE_DARKNESS", "DST_CAVE", "DST_CAVE_PLUS"
    overrides = {
        -- default is "never", "rare", "default", "often", "always"

        -- MISC
        task_set = "default",           -- "classic", "default", "cave_default"
        start_location = "default",     -- "caves", "default", "plus", "darkness"
        world_size = "default",         -- "small", "medium", "default", "huge"
        branching = "default",          -- "never", "least", "default", "most"
        loop = "default",               -- "never", "default", "always"
        autumn = "default",             -- "noseason", "veryshortseason", "shortseason", "default", "longseason", "verylongseason", "random"
        winter = "default",             -- "noseason", "veryshortseason", "shortseason", "default", "longseason", "verylongseason", "random"
        spring = "default",             -- "noseason", "veryshortseason", "shortseason", "default", "longseason", "verylongseason", "random"
        summer = "default",             -- "noseason", "veryshortseason", "shortseason", "default", "longseason", "verylongseason", "random"
        season_start = "default",       -- "default", "winter", "spring", "summer", "autumnorspring", "winterorsummer", "random"
        day = "default",                -- "default", "longday", "longdusk", "longnight", "noday", "nodusk", "nonight", "onlyday", "onlydusk", "onlynight"
        weather = "default",
        earthquakes = "default",
        lightning = "default",
        frograin = "default",
        wildfires = "default",
        touchstone = "default",
        regrowth = "default",           -- "veryslow", "slow", "default", "fast", "veryfast"
        cavelight = "default",          -- "veryslow", "slow", "default", "fast", "veryfast"
        boons = "default",
        prefabswaps_start = "default",  -- "classic", "default", "highly random"
        prefabswaps = "default",        -- "none", "few", "default", "many", "max"

        -- RESOURCES
        flowers = "default",
        grass = "default",
        sapling = "default",
        marshbush = "default",
        tumbleweed = "default",
        reeds = "default",
        trees = "default",
        flint = "default",
        rock = "default",
        rock_ice = "default",
        meteorspawner = "default",
        meteorshowers = "default",
        mushtree = "default",
        fern = "default",
        flower_cave = "default",
        wormlights = "default",

        -- UNPREPARED
        berrybush = "default",
        carrot = "default",
        mushroom = "default",
        cactus = "default",
        banana = "default",
        lichen = "default",

        -- ANIMALS
        rabbits = "default",
        moles = "default",
        butterfly = "default",
        birds = "default",
        buzzard = "default",
        catcoon = "default",
        perd = "default",
        pigs = "default",
        lightninggoat = "default",
        beefalo = "default",
        beefaloheat = "default",
        hunt = "default",
        alternatehunt = "default",
        penguins = "default",
        cave_ponds = "default",
        ponds = "default",
        bees = "default",
        angrybees = "default",
        tallbirds = "default",
        slurper = "default",
        bunnymen = "default",
        slurtles = "default",
        rocky = "default",
        monkey = "default",

        -- MONSTERS
        spiders = "default",
        cave_spiders = "default",
        hounds = "default",
        houndmound = "default",
        merm = "default",
        tentacles = "default",
        chess = "default",
        lureplants = "default",
        walrus = "default",
        liefs = "default",
        deciduousmonster = "default",
        krampus = "default",
        bearger = "default",
        deerclops = "default",
        goosemoose = "default",
        dragonfly = "default",
        bats = "default",
        fissure = "default",
        worms = "default",
    },
}

洞穴部分
洞穴部分,将文件保存为 worldgenoverride.lua,并放进 Caves 文件夹中:

    override_enabled = true,
    preset = "DST_CAVE",                 -- "SURVIVAL_TOGETHER", "MOD_MISSING", "SURVIVAL_TOGETHER_CLASSIC", "SURVIVAL_DEFAULT_PLUS", "COMPLETE_DARKNESS", "DST_CAVE", "DST_CAVE_PLUS"
    overrides = {
        -- defalut is "never", "rare", "default", "often", "always"

        -- MISC
        task_set = "cave_default",       -- "classic", "default", "cave_default"
        start_location = "default",      -- "caves", "default", "plus", "darkness"
        world_size = "default",          -- "small", "medium", "default", "huge"
        branching = "default",           -- "never", "least", "default", "most"
        loop = "default",                -- "never", "default", "always"
        autumn = "default",              -- "noseason", "veryshortseason", "shortseason", "default", "longseason", "verylongseason", "random"
        winter = "default",              -- "noseason", "veryshortseason", "shortseason", "default", "longseason", "verylongseason", "random"
        spring = "default",              -- "noseason", "veryshortseason", "shortseason", "default", "longseason", "verylongseason", "random"
        summer = "default",              -- "noseason", "veryshortseason", "shortseason", "default", "longseason", "verylongseason", "random"
        season_start = "default",        -- "default", "winter", "spring", "summer", "autumnorspring", "winterorsummer", "random"
        day = "default",                 -- "default", "longday", "longdusk", "longnight", "noday", "nodusk", "nonight", "onlyday", "onlydusk", "onlynight"
        weather = "default",
        earthquakes = "default",
        lightning = "default",
        frograin = "default",
        wildfires = "default",
        touchstone = "default",
        regrowth = "default",            -- "veryslow", "slow", "default", "fast", "veryfast"
        cavelight = "default",           -- "veryslow", "slow", "default", "fast", "veryfast"
        boons = "default",
        prefabswaps_start = "default",   -- "classic", "default", "highly random"
        prefabswaps = "default",         -- "none", "few", "default", "many", "max"

        -- RESOURCES
        flowers = "default",
        grass = "default",
        sapling = "default",
        marshbush = "default",
        tumbleweed = "default",
        reeds = "default",
        trees = "default",
        flint = "default",
        rock = "default",
        rock_ice = "default",
        meteorspawner = "default",
        meteorshowers = "default",
        mushtree = "default",
        fern = "default",
        flower_cave = "default",
        wormlights = "default",

        -- UNPREPARED
        berrybush = "default",
        carrot = "default",
        mushroom = "default",
        cactus = "default",
        banana = "default",
        lichen = "default",

        -- ANIMALS
        rabbits = "default",
        moles = "default",
        butterfly = "default",
        birds = "default",
        buzzard = "default",
        catcoon = "default",
        perd = "default",
        pigs = "default",
        lightninggoat = "default",
        beefalo = "default",
        beefaloheat = "default",
        hunt = "default",
        alternatehunt = "default",
        penguins = "default",
        cave_ponds = "default",
        ponds = "default",
        bees = "default",
        angrybees = "default",
        tallbirds = "default",
        slurper = "default",
        bunnymen = "default",
        slurtles = "default",
        rocky = "default",
        monkey = "default",

        -- MONSTERS
        spiders = "default",
        cave_spiders = "default",
        hounds = "default",
        houndmound = "default",
        merm = "default",
        tentacles = "default",
        chess = "default",
        lureplants = "default",
        walrus = "default",
        liefs = "default",
        deciduousmonster = "default",
        krampus = "default",
        bearger = "default",
        deerclops = "default",
        goosemoose = "default",
        dragonfly = "default",
        bats = "default",
        fissure = "default",
        worms = "default",
    },
}

游戏命令:

TheNet:Kick(userid)  
--踢出用户ID为“userid”的玩家
TheNet:Ban(userid)  
--禁止用户ID为“userid”的玩家加入
c_announce("大家记好房间名,回一下档")  
--公告
c_sethealth(percent)  
--设置血量,括号里填百分比,0.9=90%
c_setsanity(percent)  
--设置san值,括号里填百分比,0.9=90%
c_sethunger(percent)  
--设置饱食度,括号里填百分比,0.9=90%
c_godmode()  
--上帝模式
c_speedmult(multiplier)  
--设置移动速度,一般1.2足够
c_reset()  
--在不保存世界的情况下重载,会导致掉线
c_regenerateworld()  
--删除当前世界并生成新世界
c_save()  
--手动保存
c_shutdown(true | false)  
c_shutdown(true)或c_shutdown()  
--保存游戏并关闭服务器,
c_shutdown(false)  
--不保存游戏直接关闭服务器
c_rollback(count)  
--回档,count从1开始计算,回到之前保存的状态

c_give("meat_dried",90)  
--90个大肉干
c_give("krampus_sack")  
--坎普斯背包
c_give("walrushat")  
--海象帽
c_give("cane")  
--行走法杖
c_give("tentaclespike")  
--(狼牙棒)
c_give("telestaff")  
--(传送魔杖)
c_give("panflute")  
--(排箫)
c_give("staff_tornado")  
--(龙卷风魔杖)
c_give("featherfan")  
--(羽毛扇)
c_give("healingsalve",50)  
--(治疗药膏)
c_give("unagi",50)  
--(鳗鱼料理)

c_reset(true)  
---重载世界
c_regenerateworld()  
---生成新世界
c_announce("1")  
---发信息
c_rollback(1)  
---回档(count=1-5)
c_shutdown(true)  
---关闭世界
c_skip(1)  
---跳过天数
c_save(true)