Skip to content

Instantly share code, notes, and snippets.

@nosoop
Created September 19, 2019 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nosoop/04dcb8088ad8b5a1114f3bb5c7e900ad to your computer and use it in GitHub Desktop.
Save nosoop/04dcb8088ad8b5a1114f3bb5c7e900ad to your computer and use it in GitHub Desktop.
ctrl+c, ctrl+v srcds/cs:go but smol and largely untested
#!/usr/bin/python3
'''
gameinfo cloner for CS:GO
takes an existing CS:GO dedicated server installation and an empty directory and links / copies /
modifies files in the latter to create a runnable server
'''
import os
import pathlib
import platform
import re
import sys
import shutil
ENGINE_PATH = pathlib.Path('..', 'core')
GAME_PATH = ENGINE_PATH / 'csgo'
DEST_ENGINE_PATH = pathlib.Path('.')
DEST_GAME_PATH = DEST_ENGINE_PATH / 'csgo'
DEST_GAME_PATH.mkdir(exist_ok = True)
# support absolute paths on linux, windows must use relative paths
# might want to use relative for both, but linux generally avoids spaces in file paths anyways
if platform.system() == 'Linux':
ENGINE_PATH = ENGINE_PATH.resolve()
GAME_PATH = GAME_PATH.resolve()
DEST_ENGINE_PATH = DEST_ENGINE_PATH.resolve()
DEST_GAME_PATH = DEST_GAME_PATH.resolve()
# process gameinfo.txt file, insert a new hardcoded CS:GO path
with (GAME_PATH / 'gameinfo.txt').open('rt') as input, (DEST_GAME_PATH / 'gameinfo.txt').open('wt') as output:
for line in filter(lambda s: not (s.strip().startswith('//') or len(s.strip()) == 0), input):
line = re.sub('Game\\s+csgo$', r'Game\t\t\t\t{gamedir}\n\t\t\tGame\t\t\t\tcsgo'.format(gamedir = GAME_PATH.as_posix()), line)
output.write(line)
# list of required files / directories
ENGINE_LINKS = [ "bin" ]
GAME_LINKS = [ "steam.inf" ]
GAME_COPIES = [ ]
if platform.system() == 'Linux':
shutil.copy2(ENGINE_PATH / 'srcds_run', 'srcds_run')
ENGINE_LINKS.append("srcds_linux")
elif platform.system() == 'Windows':
shutil.copy2(ENGINE_PATH / 'srcds.exe', 'srcds.exe')
for link in filter(lambda l: not (DEST_ENGINE_PATH / l).exists(), ENGINE_LINKS):
os.symlink(ENGINE_PATH / link, DEST_ENGINE_PATH / link)
for link in filter(lambda l: not (DEST_GAME_PATH / l).exists(), GAME_LINKS):
# get a proper relative path on windows (os.symlink src is relative to target)
link_rel = pathlib.Path(os.path.relpath((GAME_PATH / link).resolve(), DEST_GAME_PATH))
os.symlink(link_rel, DEST_GAME_PATH / link)
for file in filter(lambda f: not (DEST_GAME_PATH / f).exists(), GAME_COPIES):
shutil.copytree(GAME_PATH / file, DEST_GAME_PATH / file)
#!/bin/bash
# script to set up a gameinfo-cloning CS:GO server on Linux
# cd into your base directory
mkdir -p core/steam
pushd core
# install steam and install game above
wget -qO- "https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz" | tar xzf - -C steam
steam/steamcmd.sh +login anonymous +force_install_dir ../ +app_update 740 +quit
popd
@nosoop
Copy link
Author

nosoop commented Sep 19, 2019

Installation instructions

  1. cd yourself into an empty directory where all the files will go (e.g., /home/me/csgo-servers)
  2. Run install-csgo-multi.sh, will install CS:GO game files and SteamCMD into core and core/steam
  3. mkdir and cd into a new "server instance" directory, run clone_gameinfo.py in the new directory to generate the rewritten gameinfo and symlink the necessary files — you'll need Python 3.6 or 3.7 because of pathlib use
  4. (Optional) Install MM:S, SM, etc., they should work as expected. Source.Python needs the server bin symlinked, so do that if you're installing it as well.
  5. Run srcds_run (or srcds_wrapper) as you normally would

For new server instances cd into the directory created in step 1 then start from step 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment