2
头图

Prepare

  1. For docker installation, refer docker deployment of the open source interface management tool doclever , the ubuntu system of the environment wsl2 in this article.
  2. Terraria server file, download address Terraria server , if the link fails, you can find and download on Terraria official website

Construct

  1. Prepare a temporary folder. After decompressing the downloaded server file, you only need to copy the linux version to come in.

    $ mkdir temp
    # 给这个文件加上执行权限
    $ chmod +x linux/TerrariaServer.bin.x86_64
    $ cp linux temp/linux
  2. Create a Dockerfile, a directory at the same level as linux

    $ vim Dockerfile
  3. Edit Dockerfile

    # 声明基础镜像,我这里用的ubuntu,大概80m
    FROM ubuntu:latest AS base
    # 在COPY命令后,改变容器的默认路径,这里直接进入到游戏文件根目录
    WORKDIR /usr/local/tserver
    # 未来暴露7777端口,因为泰拉瑞亚服务端端口默认7777,没特殊必要不需要修改
    EXPOSE 7777
    # 将本地游戏文件复制到ubuntu的路径下
    COPY ./linux /usr/local/tserver 
    # 当容器运行后执行的开服命令
    # ./TerrariaServer.bin.x86_64   可执行文件
    # -config 指定游戏配置文件
    # serverconfig.txt 游戏服务器配置文件
    ENTRYPOINT ["./TerrariaServer.bin.x86_64","-config","serverconfig.txt"]
  4. Create a game server configuration file, in the linux directory, at the same level as the game file

    $ vim serverconfig.txt

The file is placed at the end of the article, and the configuration is modified as needed. What I configure here is:

  1. Specify the map name TerrariaMaster1423.wld
  2. Specify the map loading path ./Worlds/
  3. Port 7777
  4. Server password xxxx
  5. Maximum number of players: 8
  6. Master of Map Difficulty
  7. Small map size

    ...

  1. Everything is ready, the build begins

    # 不要忘记末尾有个句点,这是表示从当前目录寻找Dockerfile
    $ docker build -t 1423_master_smallworld:v1 . 

voice chat

  1. Test start

    $ docker run --rm -it 1423_master_smallworld:v1

image.png

  1. Officially launched

    # -it 启动后进入docker容器内部
    # --rm 当容器停止后删除容器
    # -p 端口映射到物理机
    # -v 卷映射,将游戏存档持久化到物理机硬盘上
    $ docker run -it --rm -p 7777:7777 -v /home/xsf/temp/Worlds:/usr/local/tserver/Worlds 1423_master_smallworld:v1 

As for why it must be -it instead of -d. As for background startup, because of the limitation of the game service, the terminal output must be front-end, otherwise the startup will fail.
If you need to start on a remote server, you need to use screen or tmux to start, because when you close the remote, the service will be automatically shut down (no daemon)

Game effect

Server:
image.png
Client:
image.png
image.png
play! !

postscript

  1. You can clone the source file if you need to modify the server configuration

    xiaoshangfei/TerrariaServer1423(github.com) , modify serverconfig.txt by yourself.

  2. If you don't want to be troublesome, just download the docker image and run it

    $ docker pull xiaoshangfei911213/1423_master_smallworld
  3. Game server configuration file (reference)
#this is an example config file for TerrariaServer.exe
#use the command 'TerrariaServer.exe -config serverconfig.txt' to use this configuration or run start-server.bat
#please report crashes by emailing crashlog.txt to support@terraria.org

#the following is a list of available command line parameters:

#-config <config file>                            Specifies the configuration file to use.
#-port <port number>                              Specifies the port to listen on.
#-players <number> / -maxplayers <number>    Sets the max number of players
#-pass <password> / -password <password>        Sets the server password
#-world <world file>                    Load a world and automatically start the server.
#-autocreate <#>                    Creates a world if none is found in the path specified by -world. World size is specified by: 1(small), 2(medium), and 3(large).
#-banlist <path>                    Specifies the location of the banlist. Defaults to "banlist.txt" in the working directory.
#-worldname <world name>                         Sets the name of the world when using -autocreate.
#-secure                        Adds addition cheat protection to the server.
#-noupnp                        Disables automatic port forwarding
#-steam                            Enables Steam Support
#-lobby <friends> or <private>                Allows friends to join the server or sets it to private if Steam is enabled
#-ip <ip address>                    Sets the IP address for the server to listen on
#-forcepriority <priority>                Sets the process priority for this task. If this is used the "priority" setting below will be ignored.
#-disableannouncementbox                Disables the text announcements Announcement Box makes when pulsed from wire.
#-announcementboxrange <number>                Sets the announcement box text messaging range in pixels, -1 for serverwide announcements.
#-seed <seed>                        Specifies the world seed when using -autocreate

#remove the # in front of commands to enable them.

#Load a world and automatically start the server.
world=./Worlds/TerrariaMaster1423.wld

#Creates a new world if none is found. World size is specified by: 1(small), 2(medium), and 3(large).
autocreate=1

#Sets the world seed when using autocreate
seed=AwesomeSeed

#Sets the name of the world when using autocreate
worldname=TerrariaMaster1423

#Sets the difficulty of the world when using autocreate 0(classic), 1(expert), 2(master), 3(journey)
difficulty=2

#Sets the max number of players allowed on a server.  Value must be between 1 and 255
maxplayers=8

#Set the port number
port=7777

#Set the server password
password=xxxx

#Set the message of the day
motd=Please don�t cut the purple trees!

#Sets the folder where world files will be stored
worldpath=./Worlds/

#Sets the number of rolling world backups to keep
worldrollbackstokeep=2

#The location of the banlist. Defaults to "banlist.txt" in the working directory.
#banlist=banlist.txt

#Adds addition cheat protection.
#secure=1

#Sets the server language from its language code. 
#English = en-US, German = de-DE, Italian = it-IT, French = fr-FR, Spanish = es-ES, Russian = ru-RU, Chinese = zh-Hans, Portuguese = pt-BR, Polish = pl-PL,
language=zh-Hans

#Automatically forward ports with uPNP
#upnp=1

#Reduces enemy skipping but increases bandwidth usage. The lower the number the less skipping will happen, but more data is sent. 0 is off.
#npcstream=60

#Default system priority 0:Realtime, 1:High, 2:AboveNormal, 3:Normal, 4:BelowNormal, 5:Idle
priority=1

#Reduces maximum liquids moving at the same time. If enabled may reduce lags but liquids may take longer to settle.
#slowliquids=1

#Journey mode power permissions for every individual power. 0: Locked for everyone, 1: Can only be changed by host, 2: Can be changed by everyone
#journeypermission_time_setfrozen=2
#journeypermission_time_setdawn=2
#journeypermission_time_setnoon=2
#journeypermission_time_setdusk=2
#journeypermission_time_setmidnight=2
#journeypermission_godmode=2
#journeypermission_wind_setstrength=2
#journeypermission_rain_setstrength=2
#journeypermission_time_setspeed=2
#journeypermission_rain_setfrozen=2
#journeypermission_wind_setfrozen=2
#journeypermission_increaseplacementrange=2
#journeypermission_setdifficulty=2
#journeypermission_biomespread_setfrozen=2
#journeypermission_setspawnrate=2

Rule
12 声望6 粉丝

感觉什么都不会