Nimdy / Dedicated_Valheim_Server_Script

Valheim Server Manager . Supports: ValheimPlus, Bepinex, Multi-world, Multi-Lang, Update, Backup, Restore and more: Built for Linux
GNU Affero General Public License v3.0
697 stars 120 forks source link

[FEATURE] See active players in njordmenu #295

Closed apertureless closed 1 year ago

apertureless commented 1 year ago

Is your feature request related to a problem? Please describe. I am managing a valheim server and would find it very useful to see if there are any active players on the server before I shutdown for backup.

Describe the solution you'd like Showing if / how many active players are on the server currently

Describe alternatives you've considered Alternatives would either be to login to valheim to check or add the server to steam favorite servers, where you see how many players are connected.

landemou commented 1 year ago

Hello, I host a valheim server at home. I decided to be able to start/stop it from a webpage so that it doesn't get started all the time. From this page I display the number of people connected, the uptime, etc ... It also allows me to launch backups only when there is no player connected. I'm sharing a piece of code where you'll see the program I use SteamServerQuery to query the server for the number of players connected.

################## Variables ####################
DIR=SteamServerQueries
DEST=/var/www/html/valheim/log/nb_user.txt
##############################################

world=$(systemctl --type=service --state=running | grep valheim | cut -d"_" -f2 | cut -d"." -f1) # What world is started

STATUS=$(systemctl is-active valheimserver_$world.service >/dev/null 2>&1 && echo yes || echo no) # Count players if world started
if [ $STATUS == "yes" ]; then
    OUTPUT=$(./$DIR/a2sInfoPlayer.py < $DIR/serverlist/valheim)
    PLAYERS=$(echo $OUTPUT  | cut -d' ' -f11)
    echo $PLAYERS > $DEST
fi

If you do self-hosting like me, in SteamServerQueries/serverlist/valheim you must have 127.0.0.1:2457 The script is executed every 5 minutes with a crontab. The result is sent in a text file. I hope this example will help you.

apertureless commented 1 year ago

Thanks! I will look into it. I was trying to get the connected players via netstat but it was not very reliable.

Nimdy commented 1 year ago

Is your feature request related to a problem? Please describe. I am managing a valheim server and would find it very useful to see if there are any active players on the server before I shutdown for backup.

Describe the solution you'd like Showing if / how many active players are on the server currently

Describe alternatives you've considered Alternatives would either be to login to valheim to check or add the server to steam favorite servers, where you see how many players are connected.

image

Nimdy commented 1 year ago

Added this. Thank you