Class: Q3Servers::Server
- Inherits:
-
Object
- Object
- Q3Servers::Server
- Defined in:
- lib/q3_servers/server.rb
Constant Summary collapse
- STATUS =
i[request request_status response response_status destroyed].freeze
- GT =
{ '0' => 'FFA', '4' => 'TS', '7' => 'CTF', '9' => 'JMP' }.freeze
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#info ⇒ Object
Returns the value of attribute info.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #destroy_socket ⇒ Object
- #filter_info(filter) ⇒ Object
- #gametype ⇒ Object
- #get_info_connect ⇒ Object
- #info_status ⇒ Object
-
#initialize(ip, port, info) ⇒ Server
constructor
A new instance of Server.
- #name_c_sanitized ⇒ Object
- #read_info ⇒ Object
- #read_status ⇒ Object
- #request_and_get_status ⇒ Object
- #request_info ⇒ Object
- #request_status ⇒ Object
- #socket ⇒ Object
- #status_updated_at ⇒ Object
- #unique_index ⇒ Object
- #updated_at ⇒ Object
Constructor Details
#initialize(ip, port, info) ⇒ Server
Returns a new instance of Server.
10 11 12 13 |
# File 'lib/q3_servers/server.rb', line 10 def initialize(ip, port, info) @connection = ServerConnection.new(ip, port) @info = info || {} end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
5 6 7 |
# File 'lib/q3_servers/server.rb', line 5 def connection @connection end |
#info ⇒ Object
Returns the value of attribute info.
5 6 7 |
# File 'lib/q3_servers/server.rb', line 5 def info @info end |
#status ⇒ Object
Returns the value of attribute status.
5 6 7 |
# File 'lib/q3_servers/server.rb', line 5 def status @status end |
Instance Method Details
#destroy_socket ⇒ Object
77 78 79 80 |
# File 'lib/q3_servers/server.rb', line 77 def destroy_socket status = :destroyed connection.socket.close end |
#filter_info(filter) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/q3_servers/server.rb', line 23 def filter_info(filter) return false if info.empty? return true if filter.empty? info['hostname'] = name_c_sanitized if info.key?('hostname') f = filter.select { |k, v| info.key?(k.to_s) and (info[k.to_s].downcase =~ /#{v.to_s.downcase}/) } !f.empty? end |
#gametype ⇒ Object
19 20 21 |
# File 'lib/q3_servers/server.rb', line 19 def gametype GT.fetch(info['gametype'], '') end |
#get_info_connect ⇒ Object
32 33 34 35 |
# File 'lib/q3_servers/server.rb', line 32 def get_info_connect request_info read_info end |
#info_status ⇒ Object
90 91 92 |
# File 'lib/q3_servers/server.rb', line 90 def info_status info['sv_status'] || {} end |
#name_c_sanitized ⇒ Object
15 16 17 |
# File 'lib/q3_servers/server.rb', line 15 def name_c_sanitized info['hostname'].gsub(/(\^[0-9]{1})/, '') if info.key?('hostname') end |
#read_info ⇒ Object
49 50 51 52 53 54 |
# File 'lib/q3_servers/server.rb', line 49 def read_info self.status = :response self.info = connection.read_info_server touch! info end |
#read_status ⇒ Object
56 57 58 59 60 61 |
# File 'lib/q3_servers/server.rb', line 56 def read_status self.status = :response_status info['sv_status'] = connection.read_status_server status_touch! info['sv_status'] end |
#request_and_get_status ⇒ Object
63 64 65 66 67 |
# File 'lib/q3_servers/server.rb', line 63 def request_and_get_status info['sv_status'] = connection.request_and_get_server_status # step 2 more info from server status_touch! info['sv_status'] end |
#request_info ⇒ Object
37 38 39 40 41 |
# File 'lib/q3_servers/server.rb', line 37 def request_info self.status = :request puts "Requesting info to #{connection}" connection.request_info_server end |
#request_status ⇒ Object
43 44 45 46 47 |
# File 'lib/q3_servers/server.rb', line 43 def request_status self.status = :request_status puts "Requesting status to #{connection}" connection.request_status_server end |
#socket ⇒ Object
69 70 71 |
# File 'lib/q3_servers/server.rb', line 69 def socket connection.socket end |
#status_updated_at ⇒ Object
86 87 88 |
# File 'lib/q3_servers/server.rb', line 86 def status_updated_at info.dig('sv_status', 'updated_at') end |
#unique_index ⇒ Object
73 74 75 |
# File 'lib/q3_servers/server.rb', line 73 def unique_index connection.unique_index end |
#updated_at ⇒ Object
82 83 84 |
# File 'lib/q3_servers/server.rb', line 82 def updated_at info['updated_at'] end |