Class: Q3Servers::List
- Inherits:
-
Object
- Object
- Q3Servers::List
- Defined in:
- lib/q3_servers/list.rb
Constant Summary collapse
- PROTOCOL =
68- MAX_LENGTH =
65_536
Instance Attribute Summary collapse
-
#cache ⇒ Object
(also: #cache?)
Returns the value of attribute cache.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#favorites ⇒ Object
readonly
Returns the value of attribute favorites.
-
#info_cache_secs ⇒ Object
Returns the value of attribute info_cache_secs.
-
#master_address ⇒ Object
Returns the value of attribute master_address.
-
#master_cache_secs ⇒ Object
Returns the value of attribute master_cache_secs.
-
#master_port ⇒ Object
Returns the value of attribute master_port.
-
#master_socket ⇒ Object
readonly
Returns the value of attribute master_socket.
-
#master_updated_at ⇒ Object
Returns the value of attribute master_updated_at.
-
#only_favorites ⇒ Object
(also: #only_favorites?)
Returns the value of attribute only_favorites.
-
#servers ⇒ Object
readonly
Returns the value of attribute servers.
-
#threads ⇒ Object
readonly
Returns the value of attribute threads.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #add_favorite(ip, port) ⇒ Object
- #add_server(server) ⇒ Object
- #cached_info?(server) ⇒ Boolean
- #cached_status?(server) ⇒ Boolean
- #favorite?(server) ⇒ Boolean
- #fetch_servers(filter = {}, use_threads: false) ⇒ Object
-
#initialize ⇒ List
constructor
A new instance of List.
- #request_server_info(server, filter, use_threads) ⇒ Object
Constructor Details
#initialize ⇒ List
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/q3_servers/list.rb', line 17 def initialize @master_socket = UDPSocket.new @servers = [] @cache = true @timeout = 1 @master_updated_at = nil @debug = false @master_cache_secs = 600 @info_cache_secs = 60 @favorites = [] @master_port = 27_900 @master_address = 'master.urbanterror.info' # 51.75.224.242 @threads = [] end |
Instance Attribute Details
#cache ⇒ Object Also known as: cache?
Returns the value of attribute cache.
12 13 14 |
# File 'lib/q3_servers/list.rb', line 12 def cache @cache end |
#debug ⇒ Object
Returns the value of attribute debug.
12 13 14 |
# File 'lib/q3_servers/list.rb', line 12 def debug @debug end |
#favorites ⇒ Object (readonly)
Returns the value of attribute favorites.
11 12 13 |
# File 'lib/q3_servers/list.rb', line 11 def favorites @favorites end |
#info_cache_secs ⇒ Object
Returns the value of attribute info_cache_secs.
12 13 14 |
# File 'lib/q3_servers/list.rb', line 12 def info_cache_secs @info_cache_secs end |
#master_address ⇒ Object
Returns the value of attribute master_address.
12 13 14 |
# File 'lib/q3_servers/list.rb', line 12 def master_address @master_address end |
#master_cache_secs ⇒ Object
Returns the value of attribute master_cache_secs.
12 13 14 |
# File 'lib/q3_servers/list.rb', line 12 def master_cache_secs @master_cache_secs end |
#master_port ⇒ Object
Returns the value of attribute master_port.
12 13 14 |
# File 'lib/q3_servers/list.rb', line 12 def master_port @master_port end |
#master_socket ⇒ Object (readonly)
Returns the value of attribute master_socket.
11 12 13 |
# File 'lib/q3_servers/list.rb', line 11 def master_socket @master_socket end |
#master_updated_at ⇒ Object
Returns the value of attribute master_updated_at.
12 13 14 |
# File 'lib/q3_servers/list.rb', line 12 def master_updated_at @master_updated_at end |
#only_favorites ⇒ Object Also known as: only_favorites?
Returns the value of attribute only_favorites.
12 13 14 |
# File 'lib/q3_servers/list.rb', line 12 def only_favorites @only_favorites end |
#servers ⇒ Object (readonly)
Returns the value of attribute servers.
11 12 13 |
# File 'lib/q3_servers/list.rb', line 11 def servers @servers end |
#threads ⇒ Object (readonly)
Returns the value of attribute threads.
11 12 13 |
# File 'lib/q3_servers/list.rb', line 11 def threads @threads end |
#timeout ⇒ Object
Returns the value of attribute timeout.
12 13 14 |
# File 'lib/q3_servers/list.rb', line 12 def timeout @timeout end |
Instance Method Details
#add_favorite(ip, port) ⇒ Object
58 59 60 61 |
# File 'lib/q3_servers/list.rb', line 58 def add_favorite(ip, port) favorites << new_favorite = Server.new(ip, port, {}) add_server(new_favorite) end |
#add_server(server) ⇒ Object
54 55 56 |
# File 'lib/q3_servers/list.rb', line 54 def add_server(server) servers << server end |
#cached_info?(server) ⇒ Boolean
46 47 48 |
# File 'lib/q3_servers/list.rb', line 46 def cached_info?(server) cache? && server_info?(server) && !server_info_outdated?(server) end |
#cached_status?(server) ⇒ Boolean
50 51 52 |
# File 'lib/q3_servers/list.rb', line 50 def cached_status?(server) cache? && server_status?(server) && !server_status_outdated?(server) end |
#favorite?(server) ⇒ Boolean
63 64 65 |
# File 'lib/q3_servers/list.rb', line 63 def favorite?(server) favorites.any? { |fav| server.unique_index == fav.unique_index } end |
#fetch_servers(filter = {}, use_threads: false) ⇒ Object
32 33 34 35 |
# File 'lib/q3_servers/list.rb', line 32 def fetch_servers(filter = {}, use_threads: false) servers_list_from_master if master_server_outdated? && !only_favorites? fetch_info_servers(filter, use_threads) end |
#request_server_info(server, filter, use_threads) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/q3_servers/list.rb', line 37 def request_server_info(server, filter, use_threads) print_debug("INFO Server: Connecting to Server id => #{server.unique_index}") if use_threads thread_server_info(server, filter) else server.request_info end end |