-
-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can we have option to stop the server if last player disconnected #32
Comments
Would be a great feature! |
I support this, it would also prevent the server to reach huge number in days xD I do think this might as well be implemented at the game level to have a feature to "freeze time" once the last player disconnects. |
You could use something via RCON to watch the status of |
That's indeed an excellent workaround in the meantime, I might try and have a stab at it (and open a PR!) if I find the free cycles :) Cheers ! |
I have no idea on how to implement this. Can you describe this a bot more? |
script.txt |
I'd use |
#!/bin/bash
# Function to check players and take action based on the response
check_players() {
players_output=$(docker exec -it palworld-server rcon-cli ShowPlayers)
# Check if the response contains the header followed by an empty line
if echo "$players_output" | grep -q "name,playeruid,steamid"$'\n'$'\n'; then
echo "No players found. Shutting down the server."
docker exec -it palworld-server rcon-cli Shutdown
else
echo "Players found. Server will continue running."
# You can add additional actions or commands here if needed
fi
}
check_players
this in a nice little loop with a delay et voilà to start the server i have something similar, unfortunately, the server has to be reached twice, as the game times out during first connection and server boot. #!/bin/bash
TARGET_PORT=8211
while true; do
# Use tcpdump to capture incoming traffic on the target port
capture_result=$(sudo tcpdump -n -c 1 -i any port $TARGET_PORT 2>/dev/null)
# Check if any packets were captured
if [ -n "$capture_result" ]; then
# Trigger your event here (replace with your desired action)
echo "Connection attempt detected on port $TARGET_PORT"
echo "starting server"
docker start palworld-server
# End the loop
break
fi
# Adjust the sleep duration based on your monitoring requirements
sleep 1
done
# Optionally, you can perform cleanup or additional actions after the loop
echo "Loop ended" |
Question is would this mean I need to manually start the server each time a new player wants to connect ? |
This is a Python script that dynamically pauses and restarts the server when it detects no players and when a player joins. First, install
This works well for me. Feel free to modify it to suit your needs. |
For users who do not ask for passwords when using the this
to
Therefore, I don't need part Sometimes If you modify the function as follows, it works fine. def check_players():
players_output = run_command(
f"docker exec -it {CONTAINER_NAME} rcon-cli ShowPlayers"
)
print(f"player: {players_output}")
return "," in players_output.replace("name,playeruid,steamid", "") P.S. I'm using a modified Dockerfile for use in ARM64, and I have also changed the rcon-cli to https://github.com/itzg/rcon-cli. That may be why this is happening. + After writing this, I checked that the ARM version of Dockerfile was created in this repository. With this, this error doesn't seem to occur. |
Any way to do this in the background and at boot of my home server? Works great if it's actively running in my terminal window, but when I try to make it a cron job, it doesn't seem to recognize that there's anyone on the server and reboots then pauses after 60s. It does correctly detect when someone joins and unpauses the container though (but then repeats the cycle after 60s). I've also just tried starting it in the background with My cron was |
i use it with tmux, so i can just detach the session and reattach, nohup caused issues for me as well i usually reboot by hand, so i start the script again |
That's perfect, thank you! |
Hi, I was able to test the script on my server. Thank you. |
I've played around with different ways to get this to work with a simple bash script. Also got inspired by @fremus89's example. I now have a script running locally on the server where I host the dedicated server for me and my friends. If anyone's interested, I put together a little Docker container that's ready to use in conjunction with this project's Docker container: https://github.com/dnwjn/palworld-server-watcher. |
Just wanted to give you a shoutout here as this is exactly what I was looking for. I really didn't want to have to install Python and set up jobs to monitor my server. Having another Docker container that can handle it all is perfect, and it's been working great |
Happy to hear it's useful to someone else as well! |
@dnwjn Would you mind if I add some documentation from your repo to my docs website? |
Not at all! 😄 |
Is your feature request related to a problem? Please describe.
Pets may die during the time where nobody is looking for them (some people have to work :D)
On other steamcmd servers it was possible to set a flag to stop the server after the last player disconnected, I believe it was satisfactory, but don't hurt me if I'm wrong.
Describe the solution you'd like
We need an ENV variable that do the feature for us.
Describe alternatives you've considered
n.a.
Additional context
all said, at least I hope so :D
The text was updated successfully, but these errors were encountered: