sdtd_server 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sdtd_server.rb +23 -7
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef1dd972029c53b8b591958f60265ccce586944e
4
- data.tar.gz: 8479ca01c3f3ee4a0cba6c3dfcad09bcd28885e4
3
+ metadata.gz: 525d890e97e4cfdc804886a29236c93ec4312417
4
+ data.tar.gz: b8144d718c6a66f41b32bcfc497a173b67e19cf6
5
5
  SHA512:
6
- metadata.gz: cd4727f4e94bdd2a6d2e5b461bbf90e7d4a0ac24ace9111925ce125c5dff6641d051afc9786115409975b95a0967cd3a1643e439d722f348481b5c11aac28be1
7
- data.tar.gz: 7dc30208cbd33197b68147e4ad290b625270b4174142fabdf122539c91e63c5d55aef1d7cc3bfef8784a5d421b87b844f9bd41afcbd833171c481aaff75984ab
6
+ metadata.gz: 081649d03cf533e9668c89af5c423b8c9161df763f1ed7cf7b6bab79c16eb32e926f714107ef02c16fca9cef062ea4c88c7f6cd9faf44a82ed52d0290521665e
7
+ data.tar.gz: 12342270ed6029f0bcb0ed0cb517a486290971b353a5650b49f7f6e3ef14c6d215837e80060e2dc7d8c7a38ae6ec9415ee10fdd19f3507cc8bc2b861629ba1b5
data/lib/sdtd_server.rb CHANGED
@@ -25,9 +25,21 @@ class SDTD_Server
25
25
  #
26
26
  #
27
27
  #
28
- #
29
- #
30
- #
28
+ def get_active_players
29
+ console_output = telnet_command 'listplayerids', /Total of/
30
+
31
+ players = Hash.new
32
+
33
+ console_output.scan( /\d+\.\s+id=(\d+),\s+(.+)/ ).each do |current_player|
34
+ puts current_player
35
+ user_id = current_player[0]
36
+ user_name = current_player[1]
37
+
38
+ players[user_id] = user_name
39
+ end
40
+
41
+ return players
42
+ end
31
43
  #
32
44
  def save_world
33
45
  telnet_command 'saveworld', /World saved/
@@ -39,18 +51,22 @@ class SDTD_Server
39
51
  end
40
52
  #
41
53
  private
42
- def telnet_command(string, match)
43
- return @connection.cmd('String' => string, 'Match' => match)
54
+ def get_game_prefrence(preference_name)
55
+ return telnet_command("getgamepref #{preference_name}", /\s+=/, /=\s*(.*)$/).first
56
+ end
57
+ #
58
+ def telnet_command(string, match, extract=nil)
59
+ command_results = @connection.cmd('String' => string, 'Match' => match)
60
+ return command_results unless extract
61
+ return command_results.match(extract).captures
44
62
  end
45
63
  #
46
- private
47
64
  def console_login
48
65
  login_response = telnet_command @password, /Logon successful.|Password incorrect/
49
66
  raise InvalidConsolePasswordError unless login_response.include? 'ogon successful.'
50
67
  @connected = true
51
68
  end
52
69
  #
53
- private
54
70
  def close_telnet_connection
55
71
  @connection.cmd('exit')
56
72
  @connection.close
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sdtd_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Ingalls
@@ -18,7 +18,7 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - lib/sdtd_server.rb
21
- homepage: https://rubygems.org/gems/sdtd_server
21
+ homepage: https://github.com/BrandonIngalls/sdtd_server-gem
22
22
  licenses:
23
23
  - MIT
24
24
  metadata: {}