User:Beporter/Server Rewrite

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.) Terraria_Server_No_DotNET4.png
 * 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, where   resolves to  .)
 * 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  (default) to your server.
 * Read more about port forwarding: here and here.

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

Running the Server

 * Use the included  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  setting in.
 * 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.
 * You can explicitly force a save by typing  in the console window.

Auto-restart
If you use the  script to launch your server, the script will attempt to restart the server any time   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  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  folder and your   file periodically.
 * Unless you specify another path in, your worlds are stored in
 * %USERPROFILE% usually resolves to  in Windows XP or   in Windows Vista and 7.

Banning and Un-Banning
After banning a character using the  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 :

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

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

port=7777
 * 1) Set the port number

password=p@55w0rD
 * 1) Set the server password

motd=Please dont cut the purple trees!
 * 1) Set the message of the day

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

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

worldname=World
 * 1) Sets the name of the world when using autocreate

banlist=banlist.txt
 * 1) The location of the banlist. Defaults to "banlist.txt" in the working directory.

secure=1
 * 1) Adds addition cheat protection.

Command Line Options
The  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   on the command line. Here is the complete list.

Taken from the default :

-config 			Specifies the configuration file to use. -port 				Specifies the port to listen on. -maxplayers 			Sets the max number of players. -players 				Alias for -maxplayers. -password 			Sets the server password. -pass 				Alias for -password. -world 				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 					Specifies the location of the banlist. Defaults to "banlist.txt" in the working directory. -worldname 			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 - Kicks a player from the server.
 * ban - Bans a player from the server.
 * password - Show password.
 * password - Change password.
 * version - Print version number.
 * time - Display game time.
 * port - Print the listening port.
 * maxplayers - Print the max number of players.
 * say - Send a message.
 * motd - Print MOTD.
 * motd - 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.