#!/bin/bash
# LGSM fn_validate function
# Author: Daniel Gibbs
# Website: http://gameservermanagers.com
# Version: 190515

# Description: Runs a server validation.

local modulename="Validate"

fn_validation(){
fn_printwarn "Validating may overwrite some customised files."
sleep 1
echo -en "\n"
echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate"
sleep 5
echo -en "\n"
fn_printdots "Checking server files"
sleep 1
fn_printok "Checking server files"
fn_scriptlog "Checking server files"
sleep 1
cd "${rootdir}"
cd "steamcmd"
fn_check_steamcmd
fn_check_steamuser

if [ $(command -v unbuffer) ]; then
	unbuffer=unbuffer
fi

${unbuffer} ./steamcmd.sh +login "${steamuser}" "${steampass}" +force_install_dir "${filesdir}" +app_update "${appid}" validate +quit|tee -a "${scriptlog}"
fn_scriptlog "Checking complete"
}

fn_check_root
fn_check_systemdir
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
if [ "${tmuxwc}" -eq 1 ]; then
    fn_stop
    fn_validation
    fn_start
else
    fn_validation
fi