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

# Description: Resolves various issues with csgo.

# Fixed server not always creating steam_appid.txt file.
fn_csgoappfix(){
if [ ! -f "${filesdir}/steam_appid.txt" ]; then
	fn_printdots "Applying 730 steam_appid.txt Fix."
	sleep 1
	fn_printinfo "Applying 730 steam_appid.txt Fix."
	fn_scriptlog "Applying 730 steam_appid.txt Fix"
	sleep 1
	echo -en "\n"
	echo -n "730" >> "${filesdir}/steam_appid.txt"
fi
}

fn_csgofixes(){
# Fixes the following error:
# Error parsing BotProfile.db - unknown attribute 'Rank".
if ! grep -q "//Rank" "${systemdir}/botprofile.db" ; then
	echo "botprofile.db fix removes the following error from appearing on the console:"
	echo "	Error parsing BotProfile.db - unknown attribute 'Rank"
	sleep 1
	fn_printdots "Applying botprofile.db fix."
	sleep 1
	fn_printinfo "Applying botprofile.db fix."
	sleep 1
	sed -i 's/\tRank/\t\/\/Rank/g' "${systemdir}/botprofile.db"
	echo -en "\n"
	echo ""
fi

# Fixes errors simular to the following:
# Unknown command "cl_bobamt_vert".
if ! grep -q "//exec default" "${servercfgdir}/valve.rc" || ! grep -q "//exec joystick" "${servercfgdir}/valve.rc"; then
	echo "valve.rc fix removes the following error from appearing on the console:"
	echo "	Unknown command \"cl_bobamt_vert\""
	sleep 1
	fn_printdots "Applying valve.rc fix."
	sleep 1
	fn_printinfo "Applying valve.rc fix."
	sleep 1
	sed -i 's/exec default.cfg/\/\/exec default.cfg/g' "${servercfgdir}/valve.rc"
	sed -i 's/exec joystick.cfg/\/\/exec joystick.cfg/g' "${servercfgdir}/valve.rc"
	echo -en "\n"
	echo ""
fi

# Fixes errors simular to the following:
# http://forums.steampowered.com/forums/showthread.php?t=3170366.
if [ -f "${systemdir}/subscribed_collection_ids.txt" ]||[ -f "${systemdir}/subscribed_file_ids.txt" ]||[ -f "${systemdir}/ugc_collection_cache.txt" ]; then
	echo "workshopmapfix fixes the following error:"
	echo "	http://forums.steampowered.com/forums/showthread.php?t=3170366"
	sleep 1
	fn_printdots "Applying workshopmap fix."
	sleep 1
	fn_printinfo "Applying workshopmap fix."
	sleep 1
	rm -f "${systemdir}/subscribed_collection_ids.txt"
	rm -f "${systemdir}/subscribed_file_ids.txt"
	rm -f "${systemdir}/ugc_collection_cache.txt"
	echo -en "\n"
	echo ""
fi
}

if [ ! -z "${startfix}" ]; then
	fn_csgoappfix
else
	fn_csgofixes
fi