@@ -351,10 +351,12 @@ may_update
351
351
# SERVER STATUS MONITORING
352
352
# ===============================================================================
353
353
354
- # Function to monitor server status and display when online
354
+ # Function to monitor server status and display when online or player count changes
355
355
monitor_server_status () {
356
356
local check_interval=15 # Check every 15 seconds
357
357
local server_online=false
358
+ local last_player_count=" "
359
+ local initial_status_shown=false
358
360
359
361
# Wait for initial startup
360
362
sleep ${check_interval}
@@ -365,23 +367,80 @@ monitor_server_status() {
365
367
status_output=$( ./arkmanager status 2> /dev/null || echo " Status check failed" )
366
368
367
369
# Check if server is online
370
+ local server_is_online=false
368
371
if echo " ${status_output} " | grep -q " Server online:.*Yes" ; then
369
- if [[ " ${server_online} " == " false" ]]; then
370
- # Force a newline before status output to separate from prompt
371
- echo " "
372
+ server_is_online=true
373
+ fi
374
+
375
+ # Extract current player count
376
+ local current_player_count=" "
377
+ if echo " ${status_output} " | grep -q " Active Steam Players:" ; then
378
+ current_player_count=$( echo " ${status_output} " | grep " Active Steam Players:" | sed ' s/.*Active Steam Players: *//' )
379
+ fi
380
+
381
+ # Determine if we should show status update
382
+ local show_update=false
383
+ local update_reason=" "
384
+
385
+ # Show if server just came online
386
+ if [[ " ${server_is_online} " == " true" && " ${server_online} " == " false" ]]; then
387
+ show_update=true
388
+ update_reason=" Server came online"
389
+ fi
390
+
391
+ # Show if player count changed (only after initial status has been shown)
392
+ if [[ " ${server_is_online} " == " true" && " ${initial_status_shown} " == " true" ]]; then
393
+ if [[ -n " ${current_player_count} " && " ${current_player_count} " != " ${last_player_count} " ]]; then
394
+ show_update=true
395
+ if [[ -z " ${update_reason} " ]]; then
396
+ update_reason=" Player count changed: ${last_player_count} → ${current_player_count} "
397
+ fi
398
+ fi
399
+ fi
400
+
401
+ # Display status update if needed
402
+ if [[ " ${show_update} " == " true" ]]; then
403
+ # Force a newline before status output to separate from prompt
404
+ echo " "
405
+ if [[ " ${update_reason} " == " Server came online" ]]; then
372
406
log_success " === SERVER STATUS UPDATE ==="
373
- # Display each line of status output with proper formatting
374
- while IFS= read -r line; do
375
- [[ -n " $line " ]] && log_info " $line "
376
- done <<< " ${status_output}"
407
+ else
408
+ log_success " === PLAYER COUNT UPDATE ==="
409
+ log_info " ${update_reason} "
410
+ log_success " =========================="
411
+ fi
412
+
413
+ # Display each line of status output with proper formatting
414
+ while IFS= read -r line; do
415
+ [[ -n " $line " ]] && log_info " $line "
416
+ done <<< " ${status_output}"
417
+
418
+ if [[ " ${update_reason} " == " === Server came online ===" ]]; then
377
419
log_success " ============================"
378
- echo " " # Add blank line after status
379
- server_online=true
380
- # Exit monitoring after showing status once
381
- break
382
420
fi
383
- else
421
+ echo " " # Add blank line after status
422
+
423
+ initial_status_shown=true
424
+ fi
425
+
426
+ # Update tracking variables
427
+ server_online=" ${server_is_online} "
428
+ if [[ -n " ${current_player_count} " ]]; then
429
+ last_player_count=" ${current_player_count} "
430
+ fi
431
+
432
+ # If server goes offline, reset tracking
433
+ if [[ " ${server_is_online} " == " false" ]]; then
434
+ if [[ " ${server_online} " == " true" ]]; then
435
+ echo " "
436
+ log_warning " === SERVER OFFLINE ==="
437
+ log_warning " Server has gone offline"
438
+ log_warning " ======================"
439
+ echo " "
440
+ fi
384
441
server_online=false
442
+ last_player_count=" "
443
+ initial_status_shown=false
385
444
fi
386
445
387
446
sleep ${check_interval}
0 commit comments