arkrb 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44676ce6403228c660cd6ebdd5041720a3e0a5623d255f4155f2439a4090455c
4
- data.tar.gz: a20847149c5e0279fabd19303a5c4edc6c8a3ea04f20f2d814100e8935fddb55
3
+ metadata.gz: 30aec9fd508dde5c37a44eede01670a91f57d220624c53e5c8d1a5f57939c377
4
+ data.tar.gz: e3a7b74dfd865cb2528bb5f827dba21bb6f59507aedb87f30029b82b662d17ce
5
5
  SHA512:
6
- metadata.gz: 23b63025cb6f29a51d9204189428eb724ad7a0c3367baf969689fbd6bf2578d989dffa152c192f47271b7875c50cb568d8744860326850ae7cd847e8ba7a9067
7
- data.tar.gz: 4e3f12f9cc7d98d1c6013d5bf1617244444b972a2cbf49188944ac2028dc629a642ace82b5922e949023254d9d05e0d27150d77ddddf280e201bdd76b3682bfe
6
+ metadata.gz: f7484aa720ceeaf083a9580d59b7e07a92392ec2b828da29184c90d2d69fbd6676c60d26f4bdbd71075cbab09be958fe24af2ffbc8640654fe8386654ef282b1
7
+ data.tar.gz: 99073581202e48e51abe25e6905f3cae0f0e23d34261790477be2310fe93b4fd7935decbf2f5b58349a1cc396d46fca11c6bd831b8cf285516f11d74ddd6a676
data/.gitignore CHANGED
@@ -6,7 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
-
9
+ *.log
10
10
 
11
11
 
12
12
  # Created by https://www.gitignore.io/api/ruby,linux,rubymine+all
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- arkrb (0.1.0)
5
- colorize
6
- oga
4
+ arkrb (0.2.0)
5
+ colorize (~> 0.8.1)
6
+ oga (~> 2.14)
7
7
  thor (~> 0.20.0)
8
8
  yard (~> 0.9.12)
9
9
 
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.require_paths = ['lib']
31
31
 
32
32
  spec.add_dependency 'yard', '~> 0.9.12'
33
- spec.add_dependency 'oga', '~> 1.3', '>= 1.3.1'
33
+ spec.add_dependency 'oga', '~> 2.14'
34
34
  spec.add_runtime_dependency 'thor', '~> 0.20.0'
35
35
  spec.add_runtime_dependency 'colorize', '~> 0.8.1'
36
36
 
@@ -28,12 +28,9 @@ module Arkrb
28
28
 
29
29
  Arkrb::ErrorParsing.new.sanitize!(command, errors) unless errors.strip.empty?
30
30
 
31
- # todo: Remove the sanatize equals true line below.
32
- sanitize = true
33
-
34
31
  if sanitize
35
32
  output_parsing = Arkrb::OutputParsing.new
36
- pp output_parsing.sanitize!(command, output)
33
+ output_parsing.sanitize!(command, output)
37
34
  else
38
35
  puts output
39
36
  puts errors
@@ -46,6 +46,12 @@ module Arkrb
46
46
  class ModAlreadyExists < CustomError
47
47
  end
48
48
 
49
+ class PlayerNotFound < CustomError
50
+ end
51
+
52
+ class PlayerAlreadyExists < CustomError
53
+ end
54
+
49
55
  end
50
56
 
51
57
  end
@@ -50,8 +50,7 @@ module Arkrb
50
50
 
51
51
  # @return [True, Exception]
52
52
  def restart(output)
53
- if output =~ /#{'server has been stopped'}/im &&
54
- output =~ /#{'the server is now running'}/im
53
+ if output =~ /#{'the server is now running'}/im
55
54
  true
56
55
  else
57
56
  raise_unknown_error(__method__.to_sym, output)
@@ -60,16 +59,24 @@ module Arkrb
60
59
 
61
60
  def status(output)
62
61
  status_items = {}
62
+ defaults = {
63
+ running: nil, pid: nil, listening: nil, name: nil,
64
+ players: nil, active_players: nil, online: nil,
65
+ arkservers_link: nil, build_id: nil, version: nil
66
+ }
67
+
63
68
  status = output.gsub(/\e\[([;\d]+)?m/, '')
64
69
  if status =~ /Server running/im
65
- status = status.split("\n").map {|s| s.strip }
70
+ status = status.split("\n").map {|s| s.strip}
66
71
  status.shift
67
72
  status.each do |item|
68
73
  item_info = item.split(':', 2)
69
- status_items[item_info.first.gsub('Server', '').strip.downcase.tr(' ', '_').to_sym] = item_info[1].strip
74
+ status_items[item_info.first.gsub('Server ', '').strip.downcase.tr(' ', '_').to_sym] = item_info[1].strip
70
75
  end
71
- status_items[:arkservers_link] = status_items.delete(:arks_link)
72
- status_items
76
+ status_items[:running] = (status_items.fetch(:running, 'no') =~ /yes/im) ? true : false
77
+ status_items[:listening] = (status_items.fetch(:listening, 'no') =~ /yes/im) ? true : false
78
+ status_items[:online] = (status_items.fetch(:online, 'no') =~ /yes/im) ? true : false
79
+ defaults.merge(status_items)
73
80
  else
74
81
  raise_unknown_error(__method__.to_sym, output)
75
82
  end
@@ -163,9 +170,9 @@ module Arkrb
163
170
  end
164
171
 
165
172
  # @return [Object]
166
- # def rcon_cmd(output)
167
- # arkmanager_exec(:rcon, command)
168
- # end
173
+ def rconcmd(output)
174
+ output
175
+ end
169
176
 
170
177
  # @return [Boolean]
171
178
  # def update_available?(output)
@@ -4,6 +4,7 @@ require 'open-uri'
4
4
  require 'arkrb'
5
5
  require 'arkrb/error'
6
6
  require 'arkrb/server/mods'
7
+ require 'arkrb/server/player'
7
8
  module Arkrb
8
9
  class Server
9
10
 
@@ -85,7 +86,34 @@ module Arkrb
85
86
 
86
87
  # @return [Object]
87
88
  def rcon_cmd(command)
88
- arkmanager_exec(:rcon, command)
89
+ arkmanager_exec(:rconcmd, command.to_s)
90
+ end
91
+
92
+ def get_player_list
93
+ sanitize_filter = @sanitize_output
94
+ @sanitize_output = true
95
+ users = []
96
+ player_list = rcon_cmd('ListPlayers')
97
+ .split("\n")
98
+ .map {|m| m.delete('\\"').strip}
99
+ .reject(&:empty?)
100
+ player_list.delete_if {|x| x =~ /Running command/im}
101
+ if player_list.count == 1 && player_list.first =~ /no/im
102
+ users << Player.new(player_list.first, player_list.first, player_list.first)
103
+ else
104
+ player_list.map! {|p| %i(name steam_id).zip(p.gsub!(/^[0-9]+. /im, '').split(', ')).to_h}
105
+ player_list.each do |u|
106
+ player_id = rcon_cmd("GetPlayerIDForSteamID #{u[:steam_id].to_i}")
107
+ .split("\n")
108
+ .delete_if {|x| x =~ /Running command/im}
109
+ .map! {|x| x.delete('\\"').strip}
110
+ .reject(&:empty?)
111
+ .first.split('PlayerID: ').last
112
+ users << Player.new(u[:name], u[:steam_id], player_id)
113
+ end
114
+ end
115
+ @sanitize_output = sanitize_filter
116
+ users
89
117
  end
90
118
 
91
119
  # @return [Boolean]
@@ -99,7 +127,7 @@ module Arkrb
99
127
  end
100
128
 
101
129
  def mod_list
102
- @mod_list ||= Arkrb::Mods.new
130
+ @mod_list ||= Arkrb::Mods.new
103
131
  end
104
132
 
105
133
  private
@@ -109,25 +137,4 @@ module Arkrb
109
137
  end
110
138
 
111
139
  end
112
- end
113
-
114
- # server = Arkrb::Server.new('main')
115
- # server.mod_list.add(731604991)
116
- #
117
- # pp server
118
- #
119
- # pp server.mod_list.to_h
120
- #
121
- #
122
- #
123
- # mod_list = Arkrb::Mods.new
124
- #
125
- # pp mod_list
126
- # mod_a = 731604991
127
- # mod_b = 812655342
128
- #
129
- # mod_list.add(731604991)
130
- # mod_list.add(812655342)
131
- # pp mod_list.to_h
132
- # # mod_list.add(731604991)
133
- # # pp mod_list.find_by_id(mod_a).to_h
140
+ end
@@ -0,0 +1,20 @@
1
+ class Player
2
+ def initialize(name, steam_id, player_id)
3
+ @name = name
4
+ @steam_id = steam_id
5
+ @player_id = player_id
6
+ end
7
+
8
+ attr :name, :steam_id, :player_id
9
+
10
+ def to_h
11
+ {
12
+ name: name,
13
+ steam_id: steam_id,
14
+ player_id: player_id
15
+ }
16
+ end
17
+
18
+ alias_method :to_hash, :to_h
19
+
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Arkrb
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arkrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bruno
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-13 00:00:00.000000000 Z
11
+ date: 2018-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -30,20 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.3'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 1.3.1
33
+ version: '2.14'
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
38
  - - "~>"
42
39
  - !ruby/object:Gem::Version
43
- version: '1.3'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 1.3.1
40
+ version: '2.14'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: thor
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -173,6 +167,7 @@ files:
173
167
  - lib/arkrb/server.rb
174
168
  - lib/arkrb/server/mod.rb
175
169
  - lib/arkrb/server/mods.rb
170
+ - lib/arkrb/server/player.rb
176
171
  - lib/arkrb/version.rb
177
172
  homepage: https://github.com/mbround18/ark_rb
178
173
  licenses: