Class: GameMachine::GameSystems::RegionService
Constant Summary
Constants inherited
from Actor::Base
Actor::Base::ON_RECEIVE_HOOKS
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Commands
#commands
Methods inherited from Actor::Base
aspect, aspects, find, find_by_address, find_distributed, find_distributed_local, find_remote, hashring, local_path, model_filter, #onReceive, player_controller, #receive_message, #schedule_message, #sender, set_player_controller
Instance Attribute Details
#regions ⇒ Object
Returns the value of attribute regions.
7
8
9
|
# File 'lib/game_machine/game_systems/region_service.rb', line 7
def regions
@regions
end
|
Class Method Details
.address ⇒ Object
18
19
20
|
# File 'lib/game_machine/game_systems/region_service.rb', line 18
def self.address
@address
end
|
.address=(address) ⇒ Object
22
23
24
|
# File 'lib/game_machine/game_systems/region_service.rb', line 22
def self.address=(address)
@address = address
end
|
.region ⇒ Object
26
27
28
|
# File 'lib/game_machine/game_systems/region_service.rb', line 26
def self.region
@region
end
|
.region=(region) ⇒ Object
30
31
32
|
# File 'lib/game_machine/game_systems/region_service.rb', line 30
def self.region=(region)
@region = region
end
|
.regions ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/game_machine/game_systems/region_service.rb', line 10
def self.regions
if @regions
@regions
else
@regions = java.util.concurrent.ConcurrentHashMap.new
end
end
|
Instance Method Details
#load_from_config ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/game_machine/game_systems/region_service.rb', line 53
def load_from_config
Application.config.regions.each do |entry|
name = entry[0]
if region = Region.find!(name)
self.class.regions[name] = region
else
self.class.regions[name] = false
end
end
end
|
#on_receive(message) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/game_machine/game_systems/region_service.rb', line 76
def on_receive(message)
if message.is_a?(String)
if message == 'update_regions'
update_regions
end
elsif message.is_a?(MessageLib::Entity)
if message.id == 'regions'
regions_msg = MessageLib::Regions.new.set_regions(regions_string)
entity = MessageLib::Entity.new.set_id(message.player.id).set_regions(regions_msg)
commands.player.send_message(entity,message.player.id)
end
end
end
|
#post_init(*args) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/game_machine/game_systems/region_service.rb', line 34
def post_init(*args)
cluster = JavaLib::Cluster.get(getContext.system)
self.class.address = cluster.self_address.to_string
load_from_config
update_regions
schedule_message('update_regions',10,:seconds)
end
|
#regions_string ⇒ Object
70
71
72
73
74
|
# File 'lib/game_machine/game_systems/region_service.rb', line 70
def regions_string
self.class.regions.select{|name,region| region && !region.server.nil?}.map do |name,region|
"#{region.name}=#{server_hostname(region.server)}"
end.join('|')
end
|
#server_hostname(server) ⇒ Object
66
67
68
|
# File 'lib/game_machine/game_systems/region_service.rb', line 66
def server_hostname(server)
server.sub('akka.tcp://cluster@','').split(':').first
end
|
#update_regions ⇒ Object
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/game_machine/game_systems/region_service.rb', line 42
def update_regions
self.class.regions.keys.each do |name|
if region = Region.find!(name)
self.class.regions[name] = region
if region.server == self.class.address
self.class.region = name
end
end
end
end
|