User:Beporter/Server Rewrite

From Terraria Wiki
Jump to navigation Jump to search

The Terraria dedicated server can be used to host a world without having to have Steam installed or running the Terraria game itself. The server will continue to run and allow people to connect even if no one is currently in it.

Requirements

  • Windows operating system. (The dedicated server does not run under any other OS such as linux.)
  • Microsoft .NET Framework 4 Client Redistributable. (If the framework is not installed, you will see the error prompt to the right.)
    Error message when .NET 4 is not installed
  • The Microsoft XNA Framework Redistributable 4.0. (The dedicated server will crash on launch with the error below if this framework is not already installed.)

    Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Xna.Framework.Game, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553' or one of its dependencies. The system cannot find the file specified. at Terraria.ProgramServer.Main(String[] args)

Installation

  • If you have Terraria installed already, then you already have the dedicated server in the game folder. (Usually in %PROGRAMFILES%\Steam\steamapps\common\terraria, where %PROGRAMFILES% resolves to C:\Program Files\.)
  • If you want to host a server without running Steam on your computer, you can download the standalone dedicated server from the Terraria homepage.
  • Make sure you have installed the Microsoft .NET Framework 4 Client Redistributable and the Microsoft XNA Framework Redistributable 4.0 from above.
  • If you have a router or firewall, you must configure it to forward/allow traffic on port 7777/tcp (default) to your server.
    • Read more about port forwarding: here and here.

Configuration

To configure your server, you must edit the contents of the serverconfig.txt file with the appropriate settings. Use the Config File Options section for reference.


Running the Server

  • Use the included start-server.bat script to start the server.
  • If you don't have an existing world, a new one will be randomly generated and stored in the folder you specified with the worldpath setting in serverconfig.txt.
  • The default number of max players is 8.
  • You can set a password to protect your game server in the serverconfig.txt file.
  • Share your IP address, the port number, and your server's Terraria password with your friends!
  • Players can join your server from the "Multiplayer" menu in Terraria.
  • The server will auto-save the world now and then.
    • It will also save the world when you type exit.
    • You can explicitly force a save by typing save in the console window.


Auto-restart

If you use the start-server.bat script to launch your server, the script will attempt to restart the server any time TerreriaServer.exe quits or dies unexpectedly. This is usually a good thing since it means your server will come back up automatically, but can cause problems when you want to legitimately quit the server, such as when you type exit in the server's console. The only way to stop start-server.bat from re-launching your game server is to type save in the console to manually save your world, then click the red "X" in the corner of the console window.

To remedy this, it is possible to configure TerrariaServer.exe to run as a system Service in the background using the sc.exe / srvany.exe tools. The disadvantage to this is that you will lose access to the TerrariaServer console to monitor the game state and issue commands. There are commercial options like AlwaysUp, Mean Server Loader and FireDaemon that can help work around some of these issues though.

Backups

  • You should take care to back up your Worlds/ folder and your serverconfig.txt file periodically.
  • Unless you specify another path in serverconfig.txt, your worlds are stored in %USERPROFILE%\My Documents\My Games\Terraria\Worlds\
    • %USERPROFILE% usually resolves to C:\Documents and Settings\[username]\ in Windows XP or C:\Users\[username]\ in Windows Vista and 7.

Banning and Un-Banning

After banning a character using the ban <player> command, that player may be un-banned by navigating to the Terraria folder, and then editing banlist.txt using Notepad or another plain text editor. (Do not use Wordpad or Microsoft Word!) This document will contain a list of all banned players. To un-ban a player delete the player's name and IP address from the file and re-save it.

Reference

Below are sections taken from the default serverconfig.txt file for easy reference.

Config File Options

Taken from the default serverconfig.txt:

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

#Load a world and automatically start the server.
world=C:\Users\Defaults\My Documents\My Games\Terraria\Worlds\world1.wld

#Set the port number
port=7777

#Set the server password
password=p@55w0rD

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

#Sets the folder where world files will be stored
worldpath=C:\Users\Defaults\My Documents\My Games\Terraria\Worlds\

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

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

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

#Adds addition cheat protection.
secure=1


Command Line Options

The TerrariaServer.exe can take most of the same options as what is available in the config file, although it's usually easier to use the config file and only specify -config on the command line. Here is the complete list.

Taken from the default serverconfig.txt:

-config <config file>			Specifies the configuration file to use.
-port <port number>				Specifies the port to listen on.
-maxplayers <number>			Sets the max number of players.
-players <number>				Alias for -maxplayers.
-password <password>			Sets the server password.
-pass <password>				Alias for -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.


Console Commands

Once the game server is up and running, you can enter the following commands into it:

  • help - Displays a list of commands.
  • playing - Shows the list of players.
  • clear - Clear the console window.
  • exit - Shutdown the server and save.
  • exit-nosave - Shutdown the server without saving.
  • save - Save the game world.
  • kick <player> - Kicks a player from the server.
  • ban <player> - Bans a player from the server.
  • password - Show password.
  • password <pass> - Change password.
  • version - Print version number.
  • time - Display game time.
  • port - Print the listening port.
  • maxplayers - Print the max number of players.
  • say <words> - Send a message.
  • motd - Print MOTD.
  • motd <words> - Change MOTD.
  • dawn - Change time to dawn.
  • noon - Change time to noon.
  • dusk - Change time to dusk.
  • midnight - Change time to midnight.
  • settle - Settle all water.

Note that you do not have to do a /[command] to do the command, just type the command with no forward slash into the console window and press Enter.