Class: Arkrb::Server

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance_name, sanitize_output = true) ⇒ Server

Returns a new instance of Server.



11
12
13
14
15
# File 'lib/arkrb/server.rb', line 11

def initialize(instance_name, sanitize_output = true)
  @instance_name = instance_name
  @sanitize_output = sanitize_output
  mod_list
end

Instance Attribute Details

#instance_nameObject (readonly)

Returns the value of attribute instance_name.



17
18
19
# File 'lib/arkrb/server.rb', line 17

def instance_name
  @instance_name
end

#mod_listObject (readonly)

Returns the value of attribute mod_list.



17
18
19
# File 'lib/arkrb/server.rb', line 17

def mod_list
  @mod_list
end

Instance Method Details

#backup!True, Exception

Returns:

  • (True, Exception)


52
53
54
# File 'lib/arkrb/server.rb', line 52

def backup!
  arkmanager_exec :backup
end

#broadcast(message) ⇒ True, Exception

Returns:

  • (True, Exception)


87
88
89
# File 'lib/arkrb/server.rb', line 87

def broadcast(message)
  arkmanager_exec(:broadcast, message)
end

#disable_mod(mod_id) ⇒ True, Exception

Returns:

  • (True, Exception)


67
68
69
# File 'lib/arkrb/server.rb', line 67

def disable_mod(mod_id)
  arkmanager_exec(:disable_mod, mod_id)
end

#enable_mod(mod_id) ⇒ True, Exception

Returns:

  • (True, Exception)


62
63
64
# File 'lib/arkrb/server.rb', line 62

def enable_mod(mod_id)
  arkmanager_exec(:enable_mod, mod_id)
end

#get_player_listObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/arkrb/server.rb', line 96

def get_player_list
  sanitize_filter = @sanitize_output
  @sanitize_output = true
  users = []
  player_list = rcon_cmd('ListPlayers')
                    .split("\n")
                    .map {|m| m.delete('\\"').strip}
                    .reject(&:empty?)
  player_list.delete_if {|x| x =~ /Running command/im}
  if player_list.count == 1 && player_list.first =~ /no/im
    users << Player.new(player_list.first, player_list.first, player_list.first)
  else
    player_list.map! {|p| %i(name steam_id).zip(p.gsub!(/^[0-9]+. /im, '').split(', ')).to_h}
    player_list.each do |u|
      player_id = rcon_cmd("GetPlayerIDForSteamID #{u[:steam_id].to_i}")
                      .split("\n")
                      .delete_if {|x| x =~ /Running command/im}
                      .map! {|x| x.delete('\\"').strip}
                      .reject(&:empty?)
                      .first.split('PlayerID: ').last
      users << Player.new(u[:name], u[:steam_id], player_id)
    end
  end
  @sanitize_output = sanitize_filter
  users
end

#installObject



19
20
21
# File 'lib/arkrb/server.rb', line 19

def install
  arkmanager_exec :install
end

#install_mod(mod_id) ⇒ True, Exception

Returns:

  • (True, Exception)


72
73
74
# File 'lib/arkrb/server.rb', line 72

def install_mod(mod_id)
  arkmanager_exec(:install_mod, mod_id)
end

#mod_updates_available?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/arkrb/server.rb', line 129

def mod_updates_available?
  arkmanager_exec :check_mod_update
end

#rcon_cmd(command) ⇒ Object

Returns:

  • (Object)


92
93
94
# File 'lib/arkrb/server.rb', line 92

def rcon_cmd(command)
  arkmanager_exec(:rconcmd, command.to_s)
end

#reinstall_mod(mod_id) ⇒ True, Exception

Returns:

  • (True, Exception)


82
83
84
# File 'lib/arkrb/server.rb', line 82

def reinstall_mod(mod_id)
  arkmanager_exec(:reinstall_mod, mod_id)
end

#restart!True, Exception

Returns:

  • (True, Exception)


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

def restart!
  arkmanager_exec :restart
end

#save_world!True, Exception

Returns:

  • (True, Exception)


57
58
59
# File 'lib/arkrb/server.rb', line 57

def save_world!
  arkmanager_exec :save_world
end

#start!(verbose = false) ⇒ True, Exception

Returns:

  • (True, Exception)


24
25
26
# File 'lib/arkrb/server.rb', line 24

def start!(verbose = false)
  arkmanager_exec :start
end

#status!Object



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

def status!
  arkmanager_exec :status
end

#stop!True, Exception

Returns:

  • (True, Exception)


29
30
31
# File 'lib/arkrb/server.rb', line 29

def stop!
  arkmanager_exec :stop
end

#uninstall_mod(mod_id) ⇒ True, Exception

Returns:

  • (True, Exception)


77
78
79
# File 'lib/arkrb/server.rb', line 77

def uninstall_mod(mod_id)
  arkmanager_exec(:uninstall_mod, mod_id)
end

#update!(update_mods = false) ⇒ True, Exception

Returns:

  • (True, Exception)


43
44
45
46
47
48
49
# File 'lib/arkrb/server.rb', line 43

def update!(update_mods = false)
  if update_mods
    arkmanager_exec :update, '--update-mods'
  else
    arkmanager_exec :update
  end
end

#update_available?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/arkrb/server.rb', line 124

def update_available?
  arkmanager_exec :check_update
end