Skip to content

Commit

Permalink
#22 Refactoring done, #21 Bug fixed, #18 Added rcon capability and ex…
Browse files Browse the repository at this point in the history
…ample from the community to run easy RCON commands, #14 Added mechanic to handle signals better, #10 Added compability
  • Loading branch information
jammsen committed Jan 22, 2024
1 parent e385958 commit ee23b88
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea/
game
docker-compose.yml
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ ENV TIMEZONE=Europe/Berlin \
MAX_PLAYERS=32 \
MULTITHREAD_ENABLED=true \
COMMUNITY_SERVER=true \
RCON_ENABLED=true \
RCON_PORT=25575 \
PUBLIC_IP=10.0.0.1 \
PUBLIC_PORT=8211 \
SERVER_NAME=jammsen-docker-generated-###RANDOM### \
SERVER_DESCRIPTION="Palworld-Dedicated-Server running in Docker by jammsen" \
SERVER_PASSWORD=serverPasswordHere \
ADMIN_PASSWORD=adminPasswordHere
ADMIN_PASSWORD=adminPasswordHere


VOLUME [ "/palworld" ]

EXPOSE 8211/udp
EXPOSE 25575/tcp

ADD --chmod=777 servermanager.sh /servermanager.sh

Expand Down
111 changes: 107 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ This includes a Palworld Dedicated Server based on Linux and Docker.

## Getting started

1. Create `game` sub-directories on your Dockernode in your game-server-directory (`/srv/palworld`) and give it with `chmod 777 game` full permissions or use `chown -R 1000:1000 game/`.
2. Setup Port-Forwarding or NAT for the ports in the Docker-Compose file
3. (Build if needed )Start via `docker-compose up -d` - See docker-compose.yml and next section for more infos
4. After first start, stop the server, setup your config at `game/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini` and start it again
1. Choose a Docker-Compose examples from below
2. Create `game` sub-directories on your Dockernode in your game-server-directory (Example: `/srv/palworld`) and give it with `chmod 777 game` full permissions or use `chown -R 1000:1000 game/`.
3. Setup Port-Forwarding or NAT for the ports in the Docker-Compose file
4. (Build the image if you need) Start via `docker-compose up -d` - See docker-compose.yml and next section for more infos
5. After first start, stop the server, setup your config at `game/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini` and start it again

## Environment-Variables
| Variable | Describe | Default Value | Allowed Value |
Expand All @@ -38,6 +39,8 @@ This includes a Palworld Dedicated Server based on Linux and Docker.
| MAX_PLAYERS | Maximum amout of players | 32 | 1-32 |
| MULTITHREAD_ENABLED | Sets options for "Improved multi-threaded CPU performance" | true | false/true |
| COMMUNITY_SERVER | Sets the server to a "Community-Server". If true, the server will appear in the Community-Serverlist. Needs PUBLIC_IP and PUBLIC_PORT | true | false/true |
| RCON_ENABLED | RCON function - use ADMIN_PASSWORD to login after enabling it | true | false/true |
| RCON_PORT | RCON port to connect to | 25575 | 1024-65535 |
| PUBLIC_IP | Public ip, auto-detect if not specified, see COMMUNITY_SERVER | 10.0.0.1 | ip address |
| PUBLIC_PORT | Public port, auto-detect if not specified, see COMMUNITY_SERVER | 8211 | 1024-65535 |
| SERVER_NAME | Name of the server | jammsen-docker-generated-###RANDOM### | string |
Expand All @@ -47,6 +50,106 @@ This includes a Palworld Dedicated Server based on Linux and Docker.

Look at https://tech.palworldgame.com/optimize-game-balance for more information and config-settings in `game/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini`

## Docker-Compose examples

### Standalone gameserver
```yml
version: '3.9'
services:
palworld-dedicated-server:
build: .
container_name: palworld-dedicated-server
image: jammsen/palworld-dedicated-server:latest
restart: always
network_mode: bridge
ports:
- target: 8211 # gamerserver port inside of the container
published: 8211 # gamerserver port on your host
protocol: udp
mode: host
- target: 25575 # rcon port inside of the container
published: 25575 # rcon port on your host
protocol: tcp
mode: host
environment:
- ALWAYS_UPDATE_ON_START=true
- MAX_PLAYERS=32
- MULTITHREAD_ENABLED=true
- COMMUNITY_SERVER=true
- RCON_ENABLED=true
- RCON_PORT=25575
- PUBLIC_IP=10.0.0.5
- PUBLIC_PORT=8211
- SERVER_NAME=jammsen-docker-generated-###RANDOM###
- SERVER_DESCRIPTION=Palworld-Dedicated-Server running in Docker by jammsen
- SERVER_PASSWORD=serverPasswordHere
- ADMIN_PASSWORD=adminPasswordHere
volumes:
- ./game:/palworld
```
### Gameserver with RCON
```yml
version: '3.9'
services:
palworld-dedicated-server:
build: .
container_name: palworld-dedicated-server
image: jammsen/palworld-dedicated-server:latest
restart: always
network_mode: bridge
ports:
- target: 8211 # gamerserver port inside of the container
published: 8211 # gamerserver port on your host
protocol: udp
mode: host
- target: 25575 # rcon port inside of the container
published: 25575 # rcon port on your host
protocol: tcp
mode: host
environment:
- ALWAYS_UPDATE_ON_START=true
- MAX_PLAYERS=32
- MULTITHREAD_ENABLED=true
- COMMUNITY_SERVER=true
- RCON_ENABLED=true
- RCON_PORT=25575
- PUBLIC_IP=10.0.0.5
- PUBLIC_PORT=8211
- SERVER_NAME=jammsen-docker-generated-###RANDOM###
- SERVER_DESCRIPTION=Palworld-Dedicated-Server running in Docker by jammsen
- SERVER_PASSWORD=serverPasswordHere
- ADMIN_PASSWORD=adminPasswordHere
volumes:
- ./game:/palworld

rcon:
image: outdead/rcon:latest
entrypoint: ['/rcon', '-a', '10.0.0.5:25575', '-p', 'adminPasswordHere']
profiles: ['rcon']
```
The profiles defintion, prevents the container from starting with the server and in your console you can run now RCON commands via
#### RCON
In your shell you can now run commands against the gameserver via RCON
```shell
$ docker compose run --rm rcon ShowPlayers
name,playeruid,steamid
$ docker compose run --rm rcon info
Welcome to Pal Server[v0.1.2.0] jammsen-docker-generated-20384
$ docker compose run --rm rcon save
Complete Save
```
**Imporant:**
- Keep the `--rm` in the command line, or you will have many exited containers in your list.
- All RCON-Commands can be research here: https://tech.palworldgame.com/server-commands

## FAQ

### How can i look into the config of my Palworld container?
You can run this `docker exec -ti palworld-dedicated-server cat /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini` and it will show you the config inside the container.

### Im seeing S_API errors in my logs when i start the container
Errors like `[S_API FAIL] Tried to access Steam interface SteamUser021 before SteamAPI_Init succeeded.` are safe to ignore.

## Planned features in the future

- Feel free to suggest something
Expand Down
18 changes: 16 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,31 @@ services:
restart: always
network_mode: bridge
ports:
- "8211:8211/udp"
- target: 8211 # gamerserver port inside of the container
published: 8211 # gamerserver port on your host
protocol: udp
mode: host
- target: 25575 # rcon port inside of the container
published: 25575 # rcon port on your host
protocol: tcp
mode: host
environment:
- ALWAYS_UPDATE_ON_START=true
- MAX_PLAYERS=32
- MULTITHREAD_ENABLED=true
- COMMUNITY_SERVER=true
- PUBLIC_IP=10.0.0.1
- RCON_ENABLED=true
- RCON_PORT=25575
- PUBLIC_IP=10.0.0.5
- PUBLIC_PORT=8211
- SERVER_NAME=jammsen-docker-generated-###RANDOM###
- SERVER_DESCRIPTION=Palworld-Dedicated-Server running in Docker by jammsen
- SERVER_PASSWORD=serverPasswordHere
- ADMIN_PASSWORD=adminPasswordHere
volumes:
- ./game:/palworld

rcon:
image: outdead/rcon:latest
entrypoint: ['/rcon', '-a', '10.0.0.5:25575', '-p', 'adminPasswordHere']
profiles: ['rcon']
42 changes: 34 additions & 8 deletions servermanager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ function updateServer() {
}

function startServer() {
# IF Bash extendion usaged:
# https://stackoverflow.com/a/13864829
# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02

echo ">>> Starting the gameserver"
cd $GAME_PATH

Expand All @@ -28,15 +32,23 @@ function startServer() {
cp ${GAME_PATH}/DefaultPalWorldSettings.ini ${GAME_PATH}/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini
fi

if [[ -n $PUBLIC_IP ]]; then
if [[ ! -z ${RCON_ENABLED+x} ]]; then
echo "Setting rcon-enabled to $RCON_ENABLED"
sed -i "s/RCONEnabled=[a-zA-Z]*/RCONEnabled=$RCON_ENABLED/" ${GAME_PATH}/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini
fi
if [[ ! -z ${RCON_PORT+x} ]]; then
echo "Setting rcon-port to $RCON_PORT"
sed -i "s/RCONPort=[0-9]*/RCONPort=$RCON_PORT/" ${GAME_PATH}/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini
fi
if [[ ! -z ${PUBLIC_IP+x} ]]; then
echo "Setting public ip to $PUBLIC_IP"
sed -i "s/PublicIP=\"[^\"]*\"/PublicIP=\"$PUBLIC_IP\"/" ${GAME_PATH}/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini
fi
if [[ -n $PUBLIC_PORT ]]; then
if [[ ! -z ${PUBLIC_PORT+x} ]]; then
echo "Setting public port to $PUBLIC_PORT"
sed -i "s/PublicPort=[0-9]*/PublicPort=$PUBLIC_PORT/" ${GAME_PATH}/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini
fi
if [[ -n $SERVER_NAME ]]; then
if [[ ! -z ${SERVER_NAME+x} ]]; then
echo "Setting server name to $SERVER_NAME"
sed -i "s/ServerName=\"[^\"]*\"/ServerName=\"$SERVER_NAME\"/" ${GAME_PATH}/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini
if [[ "$SERVER_NAME" == *"###RANDOM###"* ]]; then
Expand All @@ -46,19 +58,19 @@ function startServer() {
echo "Server name is now jammsen-docker-generated-$RAND_VALUE"
fi
fi
if [[ -n $SERVER_DESCRIPTION ]]; then
if [[ ! -z ${SERVER_DESCRIPTION+x} ]]; then
echo "Setting server description to $SERVER_DESCRIPTION"
sed -i "s/ServerDescription=\"[^\"]*\"/ServerDescription=\"$SERVER_DESCRIPTION\"/" ${GAME_PATH}/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini
fi
if [[ -n $SERVER_PASSWORD ]]; then
if [[ ! -z ${SERVER_PASSWORD+x} ]]; then
echo "Setting server password to $SERVER_PASSWORD"
sed -i "s/ServerPassword=\"[^\"]*\"/ServerPassword=\"$SERVER_PASSWORD\"/" ${GAME_PATH}/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini
fi
if [[ -n $ADMIN_PASSWORD ]]; then
if [[ ! -z ${ADMIN_PASSWORD+x} ]]; then
echo "Setting server admin password to $ADMIN_PASSWORD"
sed -i "s/AdminPassword=\"[^\"]*\"/AdminPassword=\"$ADMIN_PASSWORD\"/" ${GAME_PATH}/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini
fi
if [[ -n $MAX_PLAYERS ]]; then
if [[ ! -z ${MAX_PLAYERS+x} ]]; then
echo "Setting max-players to $MAX_PLAYERS"
sed -i "s/ServerPlayerMaxNum=[0-9]*/ServerPlayerMaxNum=$MAX_PLAYERS/" ${GAME_PATH}/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini
fi
Expand All @@ -84,4 +96,18 @@ function startMain() {
startServer
}

startMain
term_handler() {
kill -SIGTERM $(pidof PalServer-Linux-Test)
tail --pid=$(pidof PalServer-Linux-Test) -f 2>/dev/null
exit 143;
}

trap 'kill ${!}; term_handler' SIGTERM

startMain &
killpid="$!"
while true
do
wait $killpid
exit 0;
done

0 comments on commit ee23b88

Please sign in to comment.