Dedicated server: Difference between revisions

From PZwiki
m (added/moved links)
 
(107 intermediate revisions by 29 users not shown)
Line 1: Line 1:
{{languages}}
{{Header|Project Zomboid|Multiplayer}}
{{header|Community|Multiplayer|version=Version 40|incver=43}}
{{Page version|41.78.16}}
Hosting a Project Zomboid dedicated server can be done in Windows and Linux.
Hosting a Project Zomboid dedicated server can be done in Windows or Linux.


==Steam Server==
==Downloading the server files==
===Through the Steam Client===
===Through Steam===
# Go to your Library and then Tools.
#Navigate to your Steam library and filter for tools
# Scroll until you see "Project Zomboid Dedicated Server" and download/install it.
#Locate 'Project Zomboid Dedicated Server' and download/install it
# Once downloaded, run the program.


That's it. Now connect to the server through the game (if hosting it on the same computer being played on, connect to it via its LAN IP, or alternatively 127.0.0.1 or "localhost" without the quotes)
{{Note|content='''Do not''' launch the server via Steam. If accidentally done, verify the integrity of the files.}}
 
===Through SteamCMD===
SteamCMD is the command line version of Steam. The Valve Developer wiki has [https://developer.valvesoftware.com/wiki/SteamCMD instructions] on how to download and configure SteamCMD.


====Windows====
====Windows====
Now go to the folder that the files have just been downloaded to, in this example to C:\PZserver and run the startServer64.bat for a 64bit server or StartServer32.bat for the 32bit version:
Once you have downloaded and extracted SteamCMD to the folder of your choosing, run it by executing <code>steamcmd.exe</code> from a command line.
 
You can now set up the installation directory where the dedicated server files will be stored.


[[File:mp_win_folders.png|350px|link={{filepath:mp_win_folders.png}}]]
The following is an example of setting the download directory to its own separate folder on the <code>C:</code> drive. You can choose wherever you would like to store the server files.
<syntaxhighlight lang="bash">
force_install_dir C:\PZServer
</syntaxhighlight>


''Note: While the exes may work, sometimes it'll result in a dedicated server that cannot be connected to locally.''
For Linux users, the server will install to <code>/home/<MYOURUSERNAME>/.steam/steam/steamapps/common/Project Zomboid Dedicated Server/</code> unless specified otherwise.
 
Once you have set the install directory to your preference, login anonymously to Steam:
<syntaxhighlight lang="bash">
login anonymous
</syntaxhighlight>
 
Next, download the Project Zomboid dedicated server files:
<syntaxhighlight lang="bash">
app_update 380870 validate
</syntaxhighlight>
 
Once you see the message ''"Success! App '380870' fully installed"'', close SteamCMD:
<syntaxhighlight lang="bash">
quit
</syntaxhighlight>


====Linux====
====Linux====
The default installation folder is in /home/YOURUSERNAME/.steam/steam/steamapps/common/Project Zomboid Dedicated Server
For Debian and Ubuntu, first install ''steamcmd'':
<syntaxhighlight lang="bash">
sudo add-apt-repository multiverse; sudo dpkg --add-architecture i386; sudo apt update
sudo apt install steamcmd
</syntaxhighlight>
 
You might need to enable ''non-free'' repository:
<syntaxhighlight lang="bash">
sudo apt-get install software-properties-common -y
sudo apt-add-repository non-free
</syntaxhighlight>
 
Proceed to Install ''steamcmd'':
<syntaxhighlight lang="bash">
sudo dpkg --add-architecture i386
sudo apt-get update -y
sudo apt-get install steamcmd -y
</syntaxhighlight>
 
Don't run the server as root. Add an user as '''pzuser''':
<syntaxhighlight lang="bash">
sudo adduser pzuser
</syntaxhighlight>
 
We will install Zomboid Server in <code>/opt/pzserver</code>:
<syntaxhighlight lang="bash">
sudo mkdir /opt/pzserver
sudo chown pzuser:pzuser /opt/pzserver
</syntaxhighlight>
 
Log in as '''pzuser''':
<syntaxhighlight lang="bash">
sudo -u pzuser -i
</syntaxhighlight>
 
Create the configuration file <code>/home/pzuser/update_zomboid.txt</code> that will manage steamcmd:
<syntaxhighlight lang="bash">
cat >$HOME/update_zomboid.txt <<'EOL'
// update_zomboid.txt
//
@ShutdownOnFailedCommand 1 //set to 0 if updating multiple servers at once
@NoPromptForPassword 1
force_install_dir /opt/pzserver/
//for servers which don't need a login
login anonymous
app_update 380870 validate
quit
EOL
</syntaxhighlight>
 
Now install Project Zomboid Server. You will use this same command every time you want to update the server to the latest version.
<syntaxhighlight lang="bash">
export PATH=$PATH:/usr/games
steamcmd +runscript $HOME/update_zomboid.txt
</syntaxhighlight>
 
==Forwarding required ports==
Project Zomboid dedicated servers require the following open ports to successfully connect to clients:
*16261 UDP
*16262 UDP - Direct Connection Port
 
===Linux===
A common firewall used to open ports on Linux is UFW (Uncomplicated Firewall). To open the required ports on the firewall you can run:
<syntaxhighlight lang="bash">
# Open the ports
sudo ufw allow 16261/udp
sudo ufw allow 16262/udp
# Reload the firewall to make the added rules go into effect
sudo ufw reload
</syntaxhighlight>
 
==Running multiple servers from a single box==
The ports above are default for the first server in the <code>SERVERNAME.ini</code> file. If you're running multiple instances of PZ on a single Linux Box, you'll need to follow these steps:
#Create 2 separate accounts in Linux from the home directory
#Run steamcmd in under both users to create two instances of steamcmd.
#Run the <syntaxhighlight lang="bash" inline>login anonymous</syntaxhighlight> & <syntaxhighlight lang="bash" inline>app_update 380870 validate</syntaxhighlight> commands under both users (via scripts if preferred - you'll need to duplicate the scripts above under each user and edit directories accordingly if so)
#Before running the 2nd server instance, be sure to open further UDP ports on your Server (e.g. 16274 + 16275).
#Edit the <code>SERVERNAME.ini</code> file in the 2nd Steam Instance to reflect these ports under the UDP Port settings).
 
Each instance will require 2 clear UDP ports.
 
===Ports used before version 41.77===
*16261 UDP
*8766, 8767 UDP
 
==Running the server==
===Windows===
Navigate to the download folder you specified (<code>C:\pzserver</code> if you followed the above steps) and locate the three ''StartServer'' batch files.
 
The default download directory if you used Steam to install the server is <code>C:\Program Files (x86)\Steam\steamapps\common\Project Zomboid Dedicated Server</code>
 
[[File:Server folder.png|frame|center|''StartServer32'' starts the Steam compatible 32-bit dedicated server.<br>
''StartServer64'' starts the Steam compatible 64-bit dedicated server.<br>
''StartServer64_nosteam'' starts the non-Steam 64-bit dedicated server.]]
 
Run the batch file that corresponds with your operating system. For most use cases this will be 64-bit unless you are intentionally running 32-bit or running the non-Steam version.
 
{{Note|type=warn|content=By default the StartServer64 batch file specifies 16GB of starting memory for the server. You '''must''' edit the StartServer64 file and change the <code>-Xms</code> and <code>-Xmx</code> files to the values you want to use for server memory, or the server will fail to start with memory errors.}}
 
An example with 6 GB used for the amount of memory (note the <code>-Xms</code> and <code>-Xmx</code> values):
<syntaxhighlight lang="bash">
".\jre64\bin\java.exe" -Djava.awt.headless=true -Dzomboid.steam=1 -Dzomboid.znetlog=1 -XX:+UseZGC -XX:-CreateCoredumpOnCrash -XX:-OmitStackTraceInFastThrow -Xms6g -Xmx6g -Djava.library.path=natives/;natives/win64/;. -cp %PZ_CLASSPATH% zombie.network.GameServer -statistic 0
</syntaxhighlight>


From here start the start-server.sh file.
For reference, this is equivalent to the "Server Memory" option when using "Host" from the main menu to host a local multiplayer server.


If you don't know how, navigate to the installation folder via terminal. The following example uses the default folder:
[[File:Server started.png|thumb|A message indicating the server started successfully.]]
<pre>cd ~/.steam/steam/steamapps/common/Project\ Zomboid\ Dedicated\ Server\/</pre>


Then simply start the start-server.sh by typing
Launching a server will open a command console window that begins executing the server on your machine. On the first run, it will prompt you to set a password for the admin account it will create. After the server finishes setting up with default game settings, a message will output indicating success or failure.
<pre>bash start-server.sh</pre>
[[File:mp_lin_terminal.png|350px|link={{filepath:mp_lin_terminal.png}}]]


===Linux===
First, start tmux. Using tmux will prevent your server from being shut down if you accidentally close your terminal window or your ssh connection gets disconnected. You can run <syntaxhighlight lang="bash" inline>tmux a</syntaxhighlight> to bring the PZ server console back up if that happens. If you get a "command not found" message when you try to run tmux, then run <syntaxhighlight lang="bash" inline>apt-get install tmux</syntaxhighlight> to install it.
<syntaxhighlight lang="bash">
tmux
</syntaxhighlight>


If this is the first time creating the server, you will be asked for an admin password after the userdatabase was created. This automatically creates an account with the name "admin" and the password you're setting.<br>
[[File:mp lin terminal.png|thumb]]
If you read "*** SERVER STARTED ***" after setting up the password, the server is successfully launched.


[[File:mp_win_console.png|350px|link={{filepath:mp_win_console.png}}]]
Navigate to your installation folder (default: <code>/home/YOURUSERNAME/.steam/steam/steamapps/common/Project Zomboid Dedicated Server</code>) and start the <code>start-server.sh</code> file. The following example uses the default folder:
<syntaxhighlight lang="bash">
cd ~/.steam/steam/steamapps/common/Project\ Zomboid\ Dedicated\ Server\/
</syntaxhighlight>


====Starting the Server====
However, if you followed the instructions in this page to [[Dedicated_Server#Linux|install Project Zomboid Server via steamcmd in Linux]], navigate to the folder that was specified in that install script:
As stated in the cmd window, the ports 8766 and 16261 have to be port forwarded in order to allow people to successfully connect to it.
<syntaxhighlight lang="bash">
cd /opt/pzserver/
</syntaxhighlight>


''When using the Steam version of the game (starting the game through Steam), connecting to the LAN/WAN server requires both the local IP and the internet IP of the server (there are two fields for this purpose). The host (assuming they're playing on the same computer as the server is running on) can use 0.0.0.0 or 127.0.0.1 as the local IP.''
Then start the <code>start-server.sh</code>
<syntaxhighlight lang="bash">
bash start-server.sh
</syntaxhighlight>


In case the test of the TCP port fails on the LAN server, enter the LAN IP in the optional field as well as the public IP address in the intended field.
Optionally, you can change the name of the server, this will change which .ini file is used and it will create a new save folder by this new server name:
A started steam server shows you the public IP address in the cmd window.


''Note for Hamachi users: You will have to use the Hamachi IP as the "public" IP ("IP" field in the MP server list menu) in order to connect to your own server.
<syntaxhighlight lang="bash">
Example:''
bash start-server.sh -servername SERVERNAME
</syntaxhighlight>


[[File:mp_server_ip.png|350px|link={{filepath:mp_server_ip.png}}]]
Launching a server will open a command console window that begins executing the server on your machine. On the first run, it will prompt you to set a password for the admin account it will create. After the server finishes setting up with default game settings, a message will output indicating success or failure.


==Downloading the Steam server files==
[[File:mp win console.png|thumb|A message indicating the server started successfully.]]
First of all, in order to host a Steam server you will need to download the server files.


There are two ways to go about this
====Systemd====
===Through the Steam Client (THE EASIEST WAY)===
{{Note|type=warn|content=The Zomboid Devs explicitly [https://theindiestone.com/forums/index.php?/topic/63563-4178-multiplayer-zomboid-dedicated-server-does-not-handle-sigterm/#comment-376957 discourage] this method, the safeties currently in place should insure a proper saving sequence on server shutdown, but there are no guarantees.}}
Go to your Library and then select "Tools".<br>Scroll until you see "Project Zomboid Dedicated Server" and download/install it like you would with a game.<br>Once downloaded, you start it.  


That's it.
An option is to configure the server to run under system.d.


===Through SteamCMD===
Before you do this:
See Valve's developer wiki for how to download and install SteamCMD:<br>
#manually start the server (as described above) at least once because the first time you are asked to input an admin password.
https://developer.valvesoftware.com/wiki/SteamCMD
#make sure you are no longer logged in as pzuser (type <syntaxhighlight lang="bash" inline>exit</syntaxhighlight> if you are) - the system.d commands are to be run as root.
 
First, configure the system.d unit:
<syntaxhighlight lang="bash">
cat >/etc/systemd/system/zomboid.service <<'EOL'
[Unit]
Description=Project Zomboid Server
After=network.target
 
[Service]
PrivateTmp=true
Type=simple
User=pzuser
WorkingDirectory=/opt/pzserver/
ExecStart=/bin/sh -c "exec /opt/pzserver/start-server.sh </opt/pzserver/zomboid.control"
ExecStop=/bin/sh -c "echo save > /opt/pzserver/zomboid.control; sleep 15; echo quit > /opt/pzserver/zomboid.control"
Sockets=zomboid.socket
KillSignal=SIGCONT
 
[Install]
WantedBy=multi-user.target
EOL
</syntaxhighlight>
Second, add a "zomboid.socket FIFO service", this will allow us to issue commands to the server, and guarantee a safe shutdown.
<syntaxhighlight lang="bash">
cat >/etc/systemd/system/zomboid.socket <<'EOL'
[Unit]
BindsTo=zomboid.service
 
[Socket]
ListenFIFO=/opt/pzserver/zomboid.control
FileDescriptorName=control
RemoveOnStop=true
SocketMode=0660
SocketUser=pzuser
 
EOL
</syntaxhighlight>
 
Once you have done that, you have the following commands available:
<syntaxhighlight lang="bash">
# start a server
systemctl start zomboid.socket
 
# stop a server
systemctl stop zomboid
 
# restart a server
systemctl restart zomboid
 
# check server status (ctrl-c to exit)
systemctl status zomboid
</syntaxhighlight>
 
The logs are now managed by journalctl. To access to the logs of the server, execute the following command:
<syntaxhighlight lang="bash">
journalctl -u zomboid -f
</syntaxhighlight>
 
To send commands to the server, use the following command:
<syntaxhighlight lang="bash">
echo "command" > /opt/pzserver/zomboid.control
</syntaxhighlight>
 
If you use sudo to elevate permissions on your system, you should use:
<syntaxhighlight lang="bash">
echo "command" | sudo tee /opt/pzserver/zomboid.control
</syntaxhighlight>
 
To see if your command worked, check journalctl, a good command to test with is <syntaxhighlight lang="bash" inline>help</syntaxhighlight>.
 
==Connecting to the server==
[[File:Mp server1.jpg|thumb|The add server panel.]]
 
#Launch Project Zomboid
#Click the ''Join'' menu option
#Click the ''Favorites'' tab
#Add [http://www.whatismyip.com your public IPv4 address]
#Enter port (default: 16261)
#Input your account details (anything desired)
#Click ''Save'', select the added server and join
 
{{Note|content=I: Hosting a non-Steam dedicated server requires players connect through the non-Steam version of the game client. For Steam game owners, this can be achieved by adding <code>-nosteam</code> to the launch options of Project Zomboid under its properties menu.}}
{{Note|content=II: If hosting a server for LAN or VPN clients, the local IPv4 address or VPN defined address needs to be used.}}
{{Note|content=III: As of game version 41.65, players who host and play on the same machine can solely use the public IPv4 address to connect to their server. If connection issues are encountered, consider adding your local IPv4 address to the ''Local IP'' field on the server screen. This address can be determined by clicking ''Start'' on the desktop, typing ''cmd'', hitting enter, typing <syntaxhighlight lang="bash" inline>ipconfig</syntaxhighlight> in the opened command prompt and hitting enter.}}
 
==Administrating the server==
There are a myriad of tools available for server administrators to customize and manage their servers.
 
===Configuring the server game settings===
====Windows====
=====Server data save locations=====
By default the server will look for game settings and world data named ''servertest'' inside <code>C:\Users\YourUsername\Zomboid</code>. If this data does not exist, the server will generate it automatically using default game settings. Use the following table for reference.
 
*<code>servertest.ini</code> in <code>C:\Users\YourUsername\Zomboid\Server</code>
*:This file contains the server configuration settings. Editable with notepad.
*<code>servertest_SandboxVars.lua</code> in <code>C:\Users\YourUsername\Zomboid\Server</code>
*:This file contains the server sandbox configuration settings. Editable with notepad.
*<code>servertest_spawnpoints.lua</code> in <code>C:\Users\YourUsername\Zomboid\Server</code>
*:This file contains the spawnpoints available in your server. Setting custom spawn points is possible. Editable with notepad.
*<code>servertest_spawnregions.lua</code> in <code>C:\Users\YourUsername\Zomboid\Server</code>
*:This file contains the regions available for spawning (i.e. Muldraugh, Rosewood, etc). Editable with notepad.
*<code>servertest</code> folder in <code>C:\Users\YourUsername\Zomboid\Saves\Multiplayer</code>
*:This folder contains the generated/saved world data of the server.
 
=====Customizing settings=====
Customizing server settings can be accomplished in two ways.
#Through the game client
#Editing the relevant files in notepad
 
To customize settings using the game client, launch Project Zomboid and select the ''Host'' menu option followed by the ''Manage Settings'' menu option.
 
[[File:20211221145754 1.jpg|thumb|Added Steam Workshop-subscribed mods to the server will be downloaded automatically on connecting client machines.]]
 
'''If the server was successfully run at least once:'''
#Select ''servertest'' from the the list of saved server settings
#Click ''Edit Settings''
#Edit desired settings and save
 
'''If the server was not run at least once:'''
#Click ''Create New Settings''
#Name these settings ''servertest''
#Edit desired settings and save
 
The next time the server successfully starts it will use the defined <code>servertest.ini</code> and lua files. The settings can be verified by using the admin command <code>showoptions</code> or opening <code>servertest.ini</code>, <code>servertest_SandboxVars.lua</code>, <code>servertest_spawnpoints.lua</code>, and <code>servertest_spawnregions.lua</code> in notepad.
 
{{Note|content=Changes can be saved to <code>servertest.ini</code> while the server is running. After <code>servertest.ini</code> is saved, use admin command <code>reloadoptions</code> to make the changes live.}}
 
=====Customizing server name=====
You may customize your server's name to something other than ''servertest'' in order to either have worlds you can quickly read and identify, or to be able to switch to a new world without having to move a bunch of files on both server and client side to preserve that world.
 
First and foremost, be aware that player map data is stored locally client side under your IP address and port. If you don't want map information bleedover, you may need to change the port in your server settings.


If you are trying to save an existing server, you have two choices ahead of you:
#Never use port 16261 for any other PZ servers.
#Have anyone who has previously joined look for a file named something like <code>123.45.0.12_16261_a589371111b0ccerf81acc30e918f8c9</code> [server ip address _ server port _ something] located at <code>C:\Users\YourUsername\Zomboid\Saves</code> and have them put it somewhere safe or edit the folder name.


Once installed, run SteamCMD (by running the steamcmd.exe in the installation folder of SteamCMD).
Then make a copy of whichever one you used to launch servertest normally by selecting it, right clicking, select copy, right click somewhere in empty space, paste.


In the open SteamCMD window, type in the following:
Rename the new file (or don't).
[[File:Server folder.png|frame|center|The server folder.]]


<pre>login anonymous</pre>
Open the file in some text editor (such as notepad) and insert:
<syntaxhighlight lang="bash">
-servername YOURSERVERNAME behind -cp %PZ_CLASSPATH% zombie.network.GameServer
</syntaxhighlight>
<!--- not sure if specific positioning actually matters --->
Example with server name of "pizza":
<syntaxhighlight lang="bash">
@setlocal enableextensions
@cd /d "%~dp0"
SET PZ_CLASSPATH=java/istack-commons-runtime.jar;java/jassimp.jar;java/javacord-2.0.17-shaded.jar;java/javax.activation-api.jar;java/jaxb-api.jar;java/jaxb-runtime.jar;java/lwjgl.jar;java/lwjgl-natives-windows.jar;java/lwjgl-glfw.jar;java/lwjgl-glfw-natives-windows.jar;java/lwjgl-jemalloc.jar;java/lwjgl-jemalloc-natives-windows.jar;java/lwjgl-opengl.jar;java/lwjgl-opengl-natives-windows.jar;java/lwjgl_util.jar;java/sqlite-jdbc-3.27.2.1.jar;java/trove-3.0.3.jar;java/uncommons-maths-1.2.3.jar;java/
".\jre64\bin\java.exe" -Djava.awt.headless=true -Dzomboid.steam=1 -Dzomboid.znetlog=1 -XX:+UseZGC -XX:-CreateCoredumpOnCrash -XX:-OmitStackTraceInFastThrow -Xms4g -Xmx4g -Djava.library.path=natives/;natives/win64/;. -cp %PZ_CLASSPATH% zombie.network.GameServer -servername pizza -statistic 0
PAUSE
</syntaxhighlight>


This will log you in anonymously, so you won't even need a Steam account in order to host a Steam server.
Just running this will create a world with all the requisite files with the default settings, which you can edit later.


If you want, you can now set up the installation directory. Linux users can skip this; the server will then install to /home/YOURUSERNAME/.steam/steam/steamapps/common/Project Zomboid Dedicated Server/.
If you've already created a server with a name you want to use with all the settings set the way you want, use the same name as the file at <code>C:\Users\%your username%\Zomboid\db</code>.
The following is an example (for Windows), installing the server on your C: drive in a folder called "PZServer":
<pre>force_install_dir C:\PZServer</pre>


Once done, we will download the server files to the specified folder by typing in:
====Linux====
<pre>app_update 380870 validate</pre>
=====Server data save locations=====
By default the server will look for game settings and world data named ''servertest'' inside <code>~/Zomboid</code> (assuming you followed the instructions above that would be <code>/home/pzuser/Zomboid</code>). If this data does not exist, the server will generate it automatically using default game settings. Use the following file list for reference.
*<code>servertest.ini</code> in <code>~/Zomboid/Server</code>
*:This file contains the server configuration settings. Editable with notepad.
*<code>servertest_SandboxVars.lua</code> in <code>~/Zomboid/Server</code>
*:This file contains the server sandbox configuration settings. Editable with notepad.
*<code>servertest_spawnpoints.lua</code> in <code>~/Zomboid/Server</code>
*:This file contains the spawnpoints available in your server. Setting custom spawn points is possible. Editable with notepad.
*<code>servertest_spawnregions.lua</code> in <code>~/Zomboid/Server</code>
*:This file contains the regions available for spawning (i.e., Muldraugh, Rosewood, etc.). Editable with notepad.
*<code>servertest</code> folder in <code>~/Zomboid/Saves/Multiplayer</code>
*:This folder contains the generated/saved world data of the server.


When the download is done and you see the success message, you can close Steam CMD by typing in
===Admin commands===
<pre>quit</pre>
{{Main|Admin commands}}


==Non-Steam Server==
The admin commands can be executed either on the server console window or in-game (preceded by a forward slash when used in-game) provided the user has admin status. For a list of commands, see [[admin commands]].
To host a non-Steam-server, navigate to your game installation folder (the default location is Steam\SteamApps\common\ProjectZomboid) and find the batch-file called ProjectZomboidServer.bat.<br>Start it by double clicking it.


A command prompt window will pop up. Upon first startup, it will create a userdatabase and create an admin account while asking you to set up a password for it.<br>After setting up the password, it will finish creating and starting up the server and say "***SERVER STARTED****".
<code>/help</code> command can be used to show all available commands.


(Note: If you are getting an error, saying "The system cannot find the path specified" while trying to create the spawnregions or user database, let it go through and once the server started without those, close the cmd window and start up the server again by executing the ProjectZomboidServer.bat.)
===Installing mods===
#Save all mods to a steam workshop collection
#Paste collection url into [https://pzidgrabber.com PZ ID Grabber]
#Open your <code>SERVERNAME.ini</code> file
#In <code>Mods=</code> section paste the mods into the file
#In <code>WorkshopItems=</code> section paste the workshop Items Ids


To allow people to connect to your server you will need to forward the necessary ports.<br>The necessary standard ports to forward are 16261 (UDP) which serves as a handshake port for communicating with the server.<br>For each possible player slot on your server, you need to forward additional TCP ports, which are used to stream the world to the player clients.<br>If you want a server with 10 slots, you would have to forward<br>16261 UDP<br>16262 - 16272 TCP
==Troubleshooting==
===Can't connect to own server, stuck in the loading screen (steam client version)===
#Verify that the saved profile for your server in the server 'favorites' tab is using your actual public IPv4 address ([https://www.whatismyip.com/ WhatismyIP]) and that the 16261 UDP port is forwarded in your router.
#Close the server using the "quit" command, verify integrity of server files, relaunch the server '''using only the "StartServer32.bat" or "StartServer64.bat" executable''' found where the server is installed. DO NOT use the Steam client to launch the server, and if you do, verify the server files again.
#Connect to the server.


A quick and easy way to test if your ports are forwarded properly are:
===Character stuck in void after joining===
*http://www.canyouseeme.org/
This might happen if you are using a pre-existing profile to connect to a server which was previously hosted using the in-game "Host" function. To solve:
*http://www.yougetsignal.com/tools/open-ports/


Good guides on how to forward ports are found all over the internet. Portforward.com has good guides on hand and covers a lot of routers. Port Forwarding sounds harder in theory that it actually is and mostly just involves getting into the menu of your router.<br>If you have no access to your router, please consult whoever is in charge of your network (parents, room mates, admins, etc).
#Disconnect from the server.
#Create a new profile by changing your account name in the "add server panel", e.g., "player" becomes "player_1". Remember to "SAVE" so the client remembers your new profile.
#Connect to the server. Your new character should be placed at one of the ordinary spawn positions.


==External links==
==External links==
*[https://www.whatismyip.com/ WhatIsMyIP?]
*[https://steamcommunity.com/sharedfiles/filedetails/?id=514493377 How to create a (Steam) server]
*[https://steamcommunity.com/sharedfiles/filedetails/?id=514493377 How to create a (Steam) server]
*[https://developer.valvesoftware.com/wiki/SteamCMD SteamCMD Valve developer wiki]
*[https://developer.valvesoftware.com/wiki/SteamCMD SteamCMD Valve developer wiki]
*[https://canyouseeme.org/ CanYouSeeMe.org]
*[https://canyouseeme.org/ CanYouSeeMe.org]
*[https://www.yougetsignal.com/tools/open-ports/ Open Port Check Tool]
*[https://www.yougetsignal.com/tools/open-ports/ Open Port Check Tool]
*[https://github.com/patrix87/SteamCMDServerManager Powershell SteamCMD Server Manager]


[[Category:Guides]]
[[Category:Guides]]

Latest revision as of 22:54, 26 March 2024

Project ZomboidMultiplayerDedicated server
UI Tick.png
This page has been revised for the current stable version (41.78.16).
Help by adding any missing content. [edit]

Hosting a Project Zomboid dedicated server can be done in Windows or Linux.

Downloading the server files

Through Steam

  1. Navigate to your Steam library and filter for tools
  2. Locate 'Project Zomboid Dedicated Server' and download/install it
LightBulbBlue.png
Do not launch the server via Steam. If accidentally done, verify the integrity of the files.

Through SteamCMD

SteamCMD is the command line version of Steam. The Valve Developer wiki has instructions on how to download and configure SteamCMD.

Windows

Once you have downloaded and extracted SteamCMD to the folder of your choosing, run it by executing steamcmd.exe from a command line.

You can now set up the installation directory where the dedicated server files will be stored.

The following is an example of setting the download directory to its own separate folder on the C: drive. You can choose wherever you would like to store the server files.

force_install_dir C:\PZServer

For Linux users, the server will install to /home/<MYOURUSERNAME>/.steam/steam/steamapps/common/Project Zomboid Dedicated Server/ unless specified otherwise.

Once you have set the install directory to your preference, login anonymously to Steam:

login anonymous

Next, download the Project Zomboid dedicated server files:

app_update 380870 validate

Once you see the message "Success! App '380870' fully installed", close SteamCMD:

quit

Linux

For Debian and Ubuntu, first install steamcmd:

sudo add-apt-repository multiverse; sudo dpkg --add-architecture i386; sudo apt update
sudo apt install steamcmd

You might need to enable non-free repository:

sudo apt-get install software-properties-common -y
sudo apt-add-repository non-free

Proceed to Install steamcmd:

sudo dpkg --add-architecture i386
sudo apt-get update -y
sudo apt-get install steamcmd -y

Don't run the server as root. Add an user as pzuser:

sudo adduser pzuser

We will install Zomboid Server in /opt/pzserver:

sudo mkdir /opt/pzserver
sudo chown pzuser:pzuser /opt/pzserver

Log in as pzuser:

sudo -u pzuser -i

Create the configuration file /home/pzuser/update_zomboid.txt that will manage steamcmd:

cat >$HOME/update_zomboid.txt <<'EOL'
// update_zomboid.txt
//
@ShutdownOnFailedCommand 1 //set to 0 if updating multiple servers at once
@NoPromptForPassword 1
force_install_dir /opt/pzserver/
//for servers which don't need a login
login anonymous
app_update 380870 validate
quit
EOL

Now install Project Zomboid Server. You will use this same command every time you want to update the server to the latest version.

export PATH=$PATH:/usr/games
steamcmd +runscript $HOME/update_zomboid.txt

Forwarding required ports

Project Zomboid dedicated servers require the following open ports to successfully connect to clients:

  • 16261 UDP
  • 16262 UDP - Direct Connection Port

Linux

A common firewall used to open ports on Linux is UFW (Uncomplicated Firewall). To open the required ports on the firewall you can run:

# Open the ports
sudo ufw allow 16261/udp
sudo ufw allow 16262/udp
# Reload the firewall to make the added rules go into effect
sudo ufw reload

Running multiple servers from a single box

The ports above are default for the first server in the SERVERNAME.ini file. If you're running multiple instances of PZ on a single Linux Box, you'll need to follow these steps:

  1. Create 2 separate accounts in Linux from the home directory
  2. Run steamcmd in under both users to create two instances of steamcmd.
  3. Run the login anonymous & app_update 380870 validate commands under both users (via scripts if preferred - you'll need to duplicate the scripts above under each user and edit directories accordingly if so)
  4. Before running the 2nd server instance, be sure to open further UDP ports on your Server (e.g. 16274 + 16275).
  5. Edit the SERVERNAME.ini file in the 2nd Steam Instance to reflect these ports under the UDP Port settings).

Each instance will require 2 clear UDP ports.

Ports used before version 41.77

  • 16261 UDP
  • 8766, 8767 UDP

Running the server

Windows

Navigate to the download folder you specified (C:\pzserver if you followed the above steps) and locate the three StartServer batch files.

The default download directory if you used Steam to install the server is C:\Program Files (x86)\Steam\steamapps\common\Project Zomboid Dedicated Server

StartServer32 starts the Steam compatible 32-bit dedicated server.
StartServer64 starts the Steam compatible 64-bit dedicated server.
StartServer64_nosteam starts the non-Steam 64-bit dedicated server.

Run the batch file that corresponds with your operating system. For most use cases this will be 64-bit unless you are intentionally running 32-bit or running the non-Steam version.

LightBulbYellow.png
By default the StartServer64 batch file specifies 16GB of starting memory for the server. You must edit the StartServer64 file and change the -Xms and -Xmx files to the values you want to use for server memory, or the server will fail to start with memory errors.

An example with 6 GB used for the amount of memory (note the -Xms and -Xmx values):

".\jre64\bin\java.exe" -Djava.awt.headless=true -Dzomboid.steam=1 -Dzomboid.znetlog=1 -XX:+UseZGC -XX:-CreateCoredumpOnCrash -XX:-OmitStackTraceInFastThrow -Xms6g -Xmx6g -Djava.library.path=natives/;natives/win64/;. -cp %PZ_CLASSPATH% zombie.network.GameServer -statistic 0

For reference, this is equivalent to the "Server Memory" option when using "Host" from the main menu to host a local multiplayer server.

A message indicating the server started successfully.

Launching a server will open a command console window that begins executing the server on your machine. On the first run, it will prompt you to set a password for the admin account it will create. After the server finishes setting up with default game settings, a message will output indicating success or failure.

Linux

First, start tmux. Using tmux will prevent your server from being shut down if you accidentally close your terminal window or your ssh connection gets disconnected. You can run tmux a to bring the PZ server console back up if that happens. If you get a "command not found" message when you try to run tmux, then run apt-get install tmux to install it.

tmux
Mp lin terminal.png

Navigate to your installation folder (default: /home/YOURUSERNAME/.steam/steam/steamapps/common/Project Zomboid Dedicated Server) and start the start-server.sh file. The following example uses the default folder:

cd ~/.steam/steam/steamapps/common/Project\ Zomboid\ Dedicated\ Server\/

However, if you followed the instructions in this page to install Project Zomboid Server via steamcmd in Linux, navigate to the folder that was specified in that install script:

cd /opt/pzserver/

Then start the start-server.sh

bash start-server.sh

Optionally, you can change the name of the server, this will change which .ini file is used and it will create a new save folder by this new server name:

bash start-server.sh -servername SERVERNAME

Launching a server will open a command console window that begins executing the server on your machine. On the first run, it will prompt you to set a password for the admin account it will create. After the server finishes setting up with default game settings, a message will output indicating success or failure.

A message indicating the server started successfully.

Systemd

LightBulbYellow.png
The Zomboid Devs explicitly discourage this method, the safeties currently in place should insure a proper saving sequence on server shutdown, but there are no guarantees.

An option is to configure the server to run under system.d.

Before you do this:

  1. manually start the server (as described above) at least once because the first time you are asked to input an admin password.
  2. make sure you are no longer logged in as pzuser (type exit if you are) - the system.d commands are to be run as root.

First, configure the system.d unit:

cat >/etc/systemd/system/zomboid.service <<'EOL'
[Unit]
Description=Project Zomboid Server
After=network.target

[Service]
PrivateTmp=true
Type=simple
User=pzuser
WorkingDirectory=/opt/pzserver/
ExecStart=/bin/sh -c "exec /opt/pzserver/start-server.sh </opt/pzserver/zomboid.control"
ExecStop=/bin/sh -c "echo save > /opt/pzserver/zomboid.control; sleep 15; echo quit > /opt/pzserver/zomboid.control"
Sockets=zomboid.socket
KillSignal=SIGCONT

[Install]
WantedBy=multi-user.target
EOL

Second, add a "zomboid.socket FIFO service", this will allow us to issue commands to the server, and guarantee a safe shutdown.

cat >/etc/systemd/system/zomboid.socket <<'EOL'
[Unit]
BindsTo=zomboid.service

[Socket]
ListenFIFO=/opt/pzserver/zomboid.control
FileDescriptorName=control
RemoveOnStop=true
SocketMode=0660
SocketUser=pzuser

EOL

Once you have done that, you have the following commands available:

# start a server
systemctl start zomboid.socket

# stop a server
systemctl stop zomboid

# restart a server
systemctl restart zomboid

# check server status (ctrl-c to exit)
systemctl status zomboid

The logs are now managed by journalctl. To access to the logs of the server, execute the following command:

journalctl -u zomboid -f

To send commands to the server, use the following command:

echo "command" > /opt/pzserver/zomboid.control

If you use sudo to elevate permissions on your system, you should use:

echo "command" | sudo tee /opt/pzserver/zomboid.control

To see if your command worked, check journalctl, a good command to test with is help.

Connecting to the server

The add server panel.
  1. Launch Project Zomboid
  2. Click the Join menu option
  3. Click the Favorites tab
  4. Add your public IPv4 address
  5. Enter port (default: 16261)
  6. Input your account details (anything desired)
  7. Click Save, select the added server and join
LightBulbBlue.png
I: Hosting a non-Steam dedicated server requires players connect through the non-Steam version of the game client. For Steam game owners, this can be achieved by adding -nosteam to the launch options of Project Zomboid under its properties menu.
LightBulbBlue.png
II: If hosting a server for LAN or VPN clients, the local IPv4 address or VPN defined address needs to be used.
LightBulbBlue.png
III: As of game version 41.65, players who host and play on the same machine can solely use the public IPv4 address to connect to their server. If connection issues are encountered, consider adding your local IPv4 address to the Local IP field on the server screen. This address can be determined by clicking Start on the desktop, typing cmd, hitting enter, typing ipconfig in the opened command prompt and hitting enter.

Administrating the server

There are a myriad of tools available for server administrators to customize and manage their servers.

Configuring the server game settings

Windows

Server data save locations

By default the server will look for game settings and world data named servertest inside C:\Users\YourUsername\Zomboid. If this data does not exist, the server will generate it automatically using default game settings. Use the following table for reference.

  • servertest.ini in C:\Users\YourUsername\Zomboid\Server
    This file contains the server configuration settings. Editable with notepad.
  • servertest_SandboxVars.lua in C:\Users\YourUsername\Zomboid\Server
    This file contains the server sandbox configuration settings. Editable with notepad.
  • servertest_spawnpoints.lua in C:\Users\YourUsername\Zomboid\Server
    This file contains the spawnpoints available in your server. Setting custom spawn points is possible. Editable with notepad.
  • servertest_spawnregions.lua in C:\Users\YourUsername\Zomboid\Server
    This file contains the regions available for spawning (i.e. Muldraugh, Rosewood, etc). Editable with notepad.
  • servertest folder in C:\Users\YourUsername\Zomboid\Saves\Multiplayer
    This folder contains the generated/saved world data of the server.
Customizing settings

Customizing server settings can be accomplished in two ways.

  1. Through the game client
  2. Editing the relevant files in notepad

To customize settings using the game client, launch Project Zomboid and select the Host menu option followed by the Manage Settings menu option.

Added Steam Workshop-subscribed mods to the server will be downloaded automatically on connecting client machines.

If the server was successfully run at least once:

  1. Select servertest from the the list of saved server settings
  2. Click Edit Settings
  3. Edit desired settings and save

If the server was not run at least once:

  1. Click Create New Settings
  2. Name these settings servertest
  3. Edit desired settings and save

The next time the server successfully starts it will use the defined servertest.ini and lua files. The settings can be verified by using the admin command showoptions or opening servertest.ini, servertest_SandboxVars.lua, servertest_spawnpoints.lua, and servertest_spawnregions.lua in notepad.

LightBulbBlue.png
Changes can be saved to servertest.ini while the server is running. After servertest.ini is saved, use admin command reloadoptions to make the changes live.
Customizing server name

You may customize your server's name to something other than servertest in order to either have worlds you can quickly read and identify, or to be able to switch to a new world without having to move a bunch of files on both server and client side to preserve that world.

First and foremost, be aware that player map data is stored locally client side under your IP address and port. If you don't want map information bleedover, you may need to change the port in your server settings.

If you are trying to save an existing server, you have two choices ahead of you:

  1. Never use port 16261 for any other PZ servers.
  2. Have anyone who has previously joined look for a file named something like 123.45.0.12_16261_a589371111b0ccerf81acc30e918f8c9 [server ip address _ server port _ something] located at C:\Users\YourUsername\Zomboid\Saves and have them put it somewhere safe or edit the folder name.

Then make a copy of whichever one you used to launch servertest normally by selecting it, right clicking, select copy, right click somewhere in empty space, paste.

Rename the new file (or don't).

The server folder.

Open the file in some text editor (such as notepad) and insert:

-servername YOURSERVERNAME behind -cp %PZ_CLASSPATH% zombie.network.GameServer

Example with server name of "pizza":

@setlocal enableextensions
@cd /d "%~dp0"
SET PZ_CLASSPATH=java/istack-commons-runtime.jar;java/jassimp.jar;java/javacord-2.0.17-shaded.jar;java/javax.activation-api.jar;java/jaxb-api.jar;java/jaxb-runtime.jar;java/lwjgl.jar;java/lwjgl-natives-windows.jar;java/lwjgl-glfw.jar;java/lwjgl-glfw-natives-windows.jar;java/lwjgl-jemalloc.jar;java/lwjgl-jemalloc-natives-windows.jar;java/lwjgl-opengl.jar;java/lwjgl-opengl-natives-windows.jar;java/lwjgl_util.jar;java/sqlite-jdbc-3.27.2.1.jar;java/trove-3.0.3.jar;java/uncommons-maths-1.2.3.jar;java/
".\jre64\bin\java.exe" -Djava.awt.headless=true -Dzomboid.steam=1 -Dzomboid.znetlog=1 -XX:+UseZGC -XX:-CreateCoredumpOnCrash -XX:-OmitStackTraceInFastThrow -Xms4g -Xmx4g -Djava.library.path=natives/;natives/win64/;. -cp %PZ_CLASSPATH% zombie.network.GameServer -servername pizza -statistic 0
PAUSE

Just running this will create a world with all the requisite files with the default settings, which you can edit later.

If you've already created a server with a name you want to use with all the settings set the way you want, use the same name as the file at C:\Users\%your username%\Zomboid\db.

Linux

Server data save locations

By default the server will look for game settings and world data named servertest inside ~/Zomboid (assuming you followed the instructions above that would be /home/pzuser/Zomboid). If this data does not exist, the server will generate it automatically using default game settings. Use the following file list for reference.

  • servertest.ini in ~/Zomboid/Server
    This file contains the server configuration settings. Editable with notepad.
  • servertest_SandboxVars.lua in ~/Zomboid/Server
    This file contains the server sandbox configuration settings. Editable with notepad.
  • servertest_spawnpoints.lua in ~/Zomboid/Server
    This file contains the spawnpoints available in your server. Setting custom spawn points is possible. Editable with notepad.
  • servertest_spawnregions.lua in ~/Zomboid/Server
    This file contains the regions available for spawning (i.e., Muldraugh, Rosewood, etc.). Editable with notepad.
  • servertest folder in ~/Zomboid/Saves/Multiplayer
    This folder contains the generated/saved world data of the server.

Admin commands

Main article: Admin commands

The admin commands can be executed either on the server console window or in-game (preceded by a forward slash when used in-game) provided the user has admin status. For a list of commands, see admin commands.

/help command can be used to show all available commands.

Installing mods

  1. Save all mods to a steam workshop collection
  2. Paste collection url into PZ ID Grabber
  3. Open your SERVERNAME.ini file
  4. In Mods= section paste the mods into the file
  5. In WorkshopItems= section paste the workshop Items Ids

Troubleshooting

Can't connect to own server, stuck in the loading screen (steam client version)

  1. Verify that the saved profile for your server in the server 'favorites' tab is using your actual public IPv4 address (WhatismyIP) and that the 16261 UDP port is forwarded in your router.
  2. Close the server using the "quit" command, verify integrity of server files, relaunch the server using only the "StartServer32.bat" or "StartServer64.bat" executable found where the server is installed. DO NOT use the Steam client to launch the server, and if you do, verify the server files again.
  3. Connect to the server.

Character stuck in void after joining

This might happen if you are using a pre-existing profile to connect to a server which was previously hosted using the in-game "Host" function. To solve:

  1. Disconnect from the server.
  2. Create a new profile by changing your account name in the "add server panel", e.g., "player" becomes "player_1". Remember to "SAVE" so the client remembers your new profile.
  3. Connect to the server. Your new character should be placed at one of the ordinary spawn positions.

External links