class GameTemplate

Public Class Methods

new(game, remote = "") click to toggle source
# File lib/game_template.rb, line 7
def initialize(game, remote = "")
  @game = game
  @remote = remote
end

Public Instance Methods

install(install_path, steam_login) click to toggle source
# File lib/game_template.rb, line 16
def install(install_path, steam_login)
  if @game.app_id.nil?
    @game.install_server(install_path)
  else
    install_steam_server(install_path, steam_login)
  end
  @game.post_install(install_path) if defined? @game.post_install
  create_unit_file(install_path)
end
run(install_path) click to toggle source
# File lib/game_template.rb, line 12
def run(install_path)
  exec(@game.launch(install_path))
end

Private Instance Methods

create_unit_file(install_path) click to toggle source
# File lib/game_template.rb, line 34
def create_unit_file(install_path)
  file_path = "/tmp/#{@game.name}.service"
  `touch #{file_path}`
  `echo "#{unit_file_contents(install_path)}" >> #{file_path}`
  system("mv -f #{"/tmp/#{@game.name}.service"} /etc/systemd/system/#{@game.name}.service")
end
install_steam_server(install_path, steam_login) click to toggle source
# File lib/game_template.rb, line 28
def install_steam_server(install_path, steam_login)
  abort("STEAMCMD does not appear to be installed! Aborting...".red) if `which steamcmd`.empty?
  system("$(which steamcmd) #{steam_login} +quit")
  system("$(which steamcmd) #{steam_login} +force_install_dir #{install_path} +app_update #{@game.app_id} validate +quit")
end
unit_file_contents(install_path) click to toggle source
# File lib/game_template.rb, line 41
def unit_file_contents(install_path)
  "[Unit]
  After=network.target
  Description=Daemon for #{@game.name} dedicated server
  [Install]
  WantedBy=default.target
  [Service]
  Type=simple
  ExecStart=#{`which gsd-cli`.strip()} run #{@game.name} --path #{install_path}"
end