Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
server.sh: Fix laggy CSGO console by waking up the server on attach a…
Browse files Browse the repository at this point in the history
…nd hibernating it on detach

Signed-off-by: Timo Reichl <[email protected]>
  • Loading branch information
Timo Reichl committed Jul 26, 2022
1 parent 356ccef commit 1e8e42d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
5 changes: 5 additions & 0 deletions image/games/base/hlds/usr/local/bin/server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ _update_restart_needed() {
}


attach() {
_attach
}


update() {
_update

Expand Down
42 changes: 42 additions & 0 deletions image/games/base/srcds/usr/local/bin/server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,43 @@ EOF_TICKRATE_ENABLER_CFG
}


_setup_csgo_hibernation_hook_attached() {
${TMUX_CMD} set-hook -t ${STEAMCMD_SERVER_SESSION_NAME} -u client-attached
${TMUX_CMD} set-hook -t ${STEAMCMD_SERVER_SESSION_NAME} client-attached 'send-keys "sv_hibernate_when_empty 0" "Enter"'
}


_setup_csgo_hibernation_hook_detached() {
${TMUX_CMD} set-hook -t ${STEAMCMD_SERVER_SESSION_NAME} -u client-detached
${TMUX_CMD} set-hook -t ${STEAMCMD_SERVER_SESSION_NAME} client-detached 'send-keys "sv_hibernate_when_empty 1" "Enter"'
}


_setup_csgo_hibernation_hooks() {
if healthy; then
_setup_csgo_hibernation_hook_detached
_setup_csgo_hibernation_hook_attached
fi
}


_run_post_csgo() {
if _is_attached; then
_setup_csgo_hibernation_hook_detached
${TMUX_CMD} send-keys -t ${STEAMCMD_SERVER_SESSION_NAME} "sv_hibernate_when_empty 0" "Enter"
fi
}


attach() {
if [[ ${STEAMCMD_SERVER_GAME} == "csgo" ]]; then
_setup_csgo_hibernation_hooks
fi

_attach
}


update() {
_update
}
Expand Down Expand Up @@ -56,6 +93,11 @@ run() {
-nodev" "Enter"

_run_post

if [[ ${STEAMCMD_SERVER_GAME} == "csgo" ]]; then
_run_post_csgo
fi

return 0
}

Expand Down
7 changes: 6 additions & 1 deletion image/games/base/usr/local/lib/steamcmd/server-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ MESSAGE_STEAMCMD_SERVER_HEALTHY="${MESSAGE_PREFIX} Server is healthy! ${MESSAGE_


# Define common functions
_is_attached() {
return $(${TMUX_CMD} ls -F "#{session_name}: #{?session_attached,yes,no}" | grep -w "${STEAMCMD_SERVER_SESSION_NAME}: yes" > /dev/null)
}


_is_running() {
return $(ps cax | grep ${1} > /dev/null)
}
Expand All @@ -47,7 +52,7 @@ wait() {
}


attach() {
_attach() {
${TMUX_CMD} a -t ${STEAMCMD_SERVER_SESSION_NAME}
}

Expand Down

0 comments on commit 1e8e42d

Please sign in to comment.