Class: GameOverseer::ClientManager
- Inherits:
-
Object
- Object
- GameOverseer::ClientManager
- Defined in:
- lib/gameoverseer/clients/client_manager.rb
Overview
Stores client data
Instance Attribute Summary collapse
-
#clients ⇒ Object
Returns the value of attribute clients.
Class Method Summary collapse
Instance Method Summary collapse
-
#add(client_id, ip_address) ⇒ Object
Add client to clients list.
-
#get(client_id) ⇒ Hash
Gets client data.
-
#initialize ⇒ ClientManager
constructor
A new instance of ClientManager.
-
#remove(client_id) ⇒ Object
Removes client data and disconnects client.
-
#update(client_id, key, value) ⇒ Object
Store client specific data in a Hash.
Constructor Details
#initialize ⇒ ClientManager
Returns a new instance of ClientManager.
7 8 9 10 |
# File 'lib/gameoverseer/clients/client_manager.rb', line 7 def initialize ClientManager.instance = self @clients = [] end |
Instance Attribute Details
#clients ⇒ Object
Returns the value of attribute clients.
5 6 7 |
# File 'lib/gameoverseer/clients/client_manager.rb', line 5 def clients @clients end |
Class Method Details
.instance ⇒ ClientManager
57 58 59 |
# File 'lib/gameoverseer/clients/client_manager.rb', line 57 def self.instance @instance end |
.instance=(_instance) ⇒ Object
62 63 64 |
# File 'lib/gameoverseer/clients/client_manager.rb', line 62 def self.instance=_instance @instance = _instance end |
Instance Method Details
#add(client_id, ip_address) ⇒ Object
Add client to clients list
15 16 17 18 |
# File 'lib/gameoverseer/clients/client_manager.rb', line 15 def add(client_id, ip_address) @clients << {client_id: client_id, ip_address: ip_address} GameOverseer::Services.client_connected(client_id, ip_address) end |
#get(client_id) ⇒ Hash
Gets client data
35 36 37 38 39 40 41 42 43 |
# File 'lib/gameoverseer/clients/client_manager.rb', line 35 def get(client_id) _hash = @clients.detect do |hash| if hash[:client_id] == client_id true end end return _hash end |
#remove(client_id) ⇒ Object
Removes client data and disconnects client
47 48 49 50 51 52 53 54 |
# File 'lib/gameoverseer/clients/client_manager.rb', line 47 def remove(client_id) @clients.each do |hash| if hash[:client_id] == client_id @clients.delete(hash) GameOverseer::Services.client_disconnected(client_id) end end end |
#update(client_id, key, value) ⇒ Object
Store client specific data in a Hash
24 25 26 27 28 29 30 |
# File 'lib/gameoverseer/clients/client_manager.rb', line 24 def update(client_id, key, value) @clients.each do |hash| if hash[:client_id] == client_id hash[key] = value end end end |