Class: GameTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/game_template.rb

Overview

Create a Rust server

Instance Method Summary collapse

Constructor Details

#initialize(game, remote, path = nil) ⇒ GameTemplate

Returns a new instance of GameTemplate.



8
9
10
11
12
13
# File 'lib/game_template.rb', line 8

def initialize(game, remote, path = nil)
  @game = game
  @install_path = get_install_path(path)
  @file_path = "/tmp/#{@game.name}.service"
  @remote = remote
end

Instance Method Details

#disableObject



42
43
44
# File 'lib/game_template.rb', line 42

def disable
  system("sudo -p 'sudo password: ' systemctl disable #{@game.name}")
end

#enableObject



38
39
40
# File 'lib/game_template.rb', line 38

def enable
  system("sudo -p 'sudo password: ' systemctl enable #{@game.name}")
end

#install(steamuser, steampassword, dev_mode) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/game_template.rb', line 50

def install(steamuser, steampassword, dev_mode)
  puts "Beginning installation process. This may take a while..."
  ensure_delete_unit_file()
  if @game.app_id.nil?
    @game.install_server(@install_path)
  else
    install_steam_server(steamuser, steampassword)
  end
  binary_path = if dev_mode.nil?
                  `which gsd-cli`.strip()
                else
                  puts "Dev mode enabled - running from source"
                  "#{Dir.pwd}/bin/gsd-cli"
                end
  create_unit_file(binary_path)
  system("sudo -p 'sudo password: ' cp -f #{@file_path} /etc/systemd/system/#{@game.name}.service")
  puts "Server installation & deployment complete!".green
end

#restartObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/game_template.rb', line 19

def restart
  command = "systemctl restart #{@game.name}"
  if @remote.nil?
    system("sudo -p 'sudo password: ' #{command}")
  else
    puts @remote
    puts command
    Helpers.remote_cmd(@remote, command)
  end
end

#runObject



46
47
48
# File 'lib/game_template.rb', line 46

def run
  exec(@game.launch(@install_path))
end

#startObject



15
16
17
# File 'lib/game_template.rb', line 15

def start
  system("sudo -p 'sudo password: ' systemctl start #{@game.name}")
end

#statusObject



30
31
32
# File 'lib/game_template.rb', line 30

def status
  system("sudo -p 'sudo password: ' systemctl status #{@game.name}")
end

#stopObject



34
35
36
# File 'lib/game_template.rb', line 34

def stop
  system("sudo -p 'sudo password: ' systemctl stop #{@game.name}")
end

#updateObject



69
70
71
72
73
74
75
# File 'lib/game_template.rb', line 69

def update
  if @game.app_id.nil?
    puts "Non-Steam games not supported."
  else
    install_steam_server()
  end
end