347 字
2 分钟
TShock 泰拉瑞亚服务器部署

安装#

下载:https://github.com/Pryaxis/TShock/releases

解压后打开 cmd,运行安装程序等待完成,然后正常流程创建一个世界,最后 stop 关掉。

Terminal window
TShock.Server.exe -ip 0.0.0.0 -world Worlds/your-world.wld -lang zh_CN -worldpath ./Worlds

命令行参数参考:https://tshock.readme.io/docs/command-line-parameters

Docker 部署#

docker-compose.yml

services:
terraria:
build:
context: https://github.com/Pryaxis/TShock.git
args:
TARGETPLATFORM: linux/amd64
container_name: terraria
restart: on-failure
volumes:
- "./ServerPlugins/:/server/ServerPlugins"
- "./plugintshock/:/server/tshock"
- "./tshock/:/tshock"
- "./worlds:/worlds"
- "./logs:/tshock/logs"
- "/etc/localtime:/etc/localtime:ro"
ports:
- "7777:7777"
command: -world /worlds/your-world.wld -maxplayers 20 -autocreate 3 -pass <server-password> -worldevil crimson -difficulty 2

注意: ServerPlugins 才是放插件的地方,官方的 plugins 目录会出问题。挂载前要先通过 docker 把原有的 ServerPlugins 中的文件复制出来。

常用 docker 命令:

Terminal window
docker attach terraria
docker exec -it terraria bash

配套数据库#

services:
trdb:
image: mariadb:lts
container_name: trdb
restart: always
ports:
- "127.0.0.1:3306:3306"
volumes:
- ./mariadb-data:/var/lib/mysql
- ./mariadb-conf:/etc/mysql
- /run/mysqld:/run/mysqld
environment:
MARIADB_ROOT_PASSWORD: <db-root-password>

配置文件说明#

配置参考:https://github.com/Pryaxis/TShock/wiki/Configuration-file-setup

关键配置项(config.json):

{
"Settings": {
"ServerPassword": "<server-password>",
"ServerPort": 7777,
"MaxSlots": 8,
"ServerName": "My Server",
"UseServerName": true,
"LogPath": "/logs",
"DisableTombstones": true,
"ForceXmas": true,
"ForceHalloween": true,
"AllowAllowedGroupsToSpawnBannedItems": true,
"RespawnSeconds": 1,
"RespawnBossSeconds": 1,
"RequireLogin": true,
"AllowLoginAnyUsername": false,
"StorageType": "mysql",
"MySqlHost": "127.0.0.1:3306",
"MySqlDbName": "tshock",
"MySqlUsername": "root",
"MySqlPassword": "<db-password>"
}
}

创建 setup.lock 文件可禁止重新进入安装流程。

MOTD 配置#

motd.txt 示例:

欢迎来到 [c/ffff00:%map%] 服务器。
[c/FFFFFF:在线玩家 (%onlineplayers%/%serverslots%):] [c/FFFF00:%players%]
输入 [c/55D284:%specifier%]help 查看命令列表。
初次进入请输入 /register <密码> 进行注册
输入 /login <密码> 进行登入

服务端字符角色配置(SSC)#

sscconfig.json(开启并给初始礼物):

{
"Settings": {
"Enabled": true,
"ServerSideCharacterSave": 5,
"StartingInventory": [
{ "netID": 1869, "prefix": 0, "stack": 999 }
]
}
}
TShock 泰拉瑞亚服务器部署
https://iiii.fun/posts/terraria/tshock-deploy/
作者
慶靈
发布于
2025-01-13
许可协议
CC BY-NC-SA 4.0