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
59 60 61 |
# File 'lib/gameoverseer/clients/client_manager.rb', line 59 def self.instance @instance end |
.instance=(_instance) ⇒ Object
64 65 66 |
# File 'lib/gameoverseer/clients/client_manager.rb', line 64 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 19 |
# 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) GameOverseer::Console.log("ClientManager> client with id '#{client_id}' connected") end |
#get(client_id) ⇒ Hash
Gets client data
36 37 38 39 40 41 42 43 44 |
# File 'lib/gameoverseer/clients/client_manager.rb', line 36 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
48 49 50 51 52 53 54 55 56 |
# File 'lib/gameoverseer/clients/client_manager.rb', line 48 def remove(client_id) @clients.each do |hash| if hash[:client_id] == client_id @clients.delete(hash) GameOverseer::Services.client_disconnected(client_id) GameOverseer::Console.log("ClientManager> client with id '#{client_id}' disconnected") end end end |
#update(client_id, key, value) ⇒ Object
Store client specific data in a Hash
25 26 27 28 29 30 31 |
# File 'lib/gameoverseer/clients/client_manager.rb', line 25 def update(client_id, key, value) @clients.each do |hash| if hash[:client_id] == client_id hash[key] = value end end end |