Class: GameOverseer::ChannelManager
- Inherits:
-
Object
- Object
- GameOverseer::ChannelManager
- Defined in:
- lib/gameoverseer/channels/channel_manager.rb
Overview
Handles routing packets to the services that subscribe to channels
Constant Summary collapse
- CHAT =
0
- WORLD =
1
- HANDSHAKE =
2
- FAULT =
3
Class Method Summary collapse
-
.instance ⇒ ChannelManager
Returns instance of active ChannelManager.
-
.instance=(_instance) ⇒ Object
Sets instance of ChannelManager that is used through out the system.
Instance Method Summary collapse
-
#initialize ⇒ ChannelManager
constructor
A new instance of ChannelManager.
-
#register_channel(channel, service) ⇒ Object
Enables a service to subscribe to a channel.
-
#send_to_service(client_id, data) ⇒ Object
Routes packet to Service.
Constructor Details
#initialize ⇒ ChannelManager
Returns a new instance of ChannelManager.
10 11 12 13 |
# File 'lib/gameoverseer/channels/channel_manager.rb', line 10 def initialize @channels = {} ChannelManager.instance = self end |
Class Method Details
.instance ⇒ ChannelManager
Returns instance of active GameOverseer::ChannelManager
38 39 40 |
# File 'lib/gameoverseer/channels/channel_manager.rb', line 38 def self.instance @instance end |
.instance=(_instance) ⇒ Object
Sets instance of GameOverseer::ChannelManager that is used through out the system
44 45 46 |
# File 'lib/gameoverseer/channels/channel_manager.rb', line 44 def self.instance=_instance @instance = _instance end |
Instance Method Details
#register_channel(channel, service) ⇒ Object
Enables a service to subscribe to a channel
18 19 20 21 22 23 24 25 26 |
# File 'lib/gameoverseer/channels/channel_manager.rb', line 18 def register_channel(channel, service) _channel = channel.downcase unless @channels[_channel] @channels[_channel] = service GameOverseer::Console.log("ChannelManager> mapped '#{_channel}' to '#{service.class}'.") else raise "Could not map channel '#{_channel}' because '#{@channels[data[_channel]].class}' is already using it." end end |
#send_to_service(client_id, data) ⇒ Object
Routes packet to Service
31 32 33 34 |
# File 'lib/gameoverseer/channels/channel_manager.rb', line 31 def send_to_service(client_id, data) @channels[data['channel']].client_id = client_id @channels[data['channel']].process(data) end |