Class: GameMachine::AppConfig

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
server/lib/game_machine/app_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAppConfig

Returns a new instance of AppConfig


9
10
11
12
# File 'server/lib/game_machine/app_config.rb', line 9

def initialize
  @loaded = false
  @config = OpenStruct.new
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config


7
8
9
# File 'server/lib/game_machine/app_config.rb', line 7

def config
  @config
end

#loadedObject (readonly)

Returns the value of attribute loaded


7
8
9
# File 'server/lib/game_machine/app_config.rb', line 7

def loaded
  @loaded
end

Instance Method Details

#load_configObject


14
15
16
17
18
19
20
# File 'server/lib/game_machine/app_config.rb', line 14

def load_config
  @config = HoconConfig.config
  set_config_from_env

  set_java_config
  @loaded = true
end

#set_config_from_envObject


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'server/lib/game_machine/app_config.rb', line 65

def set_config_from_env
  GameMachine.logger.info "Setting config from ENV"

  if ENV['NODE_HOST']
    config.http.host = ENV['NODE_HOST']
    config.tcp.host = ENV['NODE_HOST']
    config.udp.host = ENV['NODE_HOST']
    config.akka.host = ENV['NODE_HOST']
  end

  if ENV['WWW_PORT']
    config.http.port = ENV['WWW_PORT'].to_i
  end

  if ENV['TCP_PORT']
    config.tcp.port = ENV['TCP_PORT'].to_i
  end

  if ENV['UDP_PORT']
    config.udp.port = ENV['UDP_PORT'].to_i
  end

  if ENV['AKKA_PORT']
    config.akka.port = ENV['AKKA_PORT'].to_i
  end

  if ENV['CLOUD_HOST'] && ENV['CLOUD_USER'] && ENV['API_KEY']
    GameMachine.logger.info "Found gamecloud config in ENV"
    config.gamecloud.host = ENV['CLOUD_HOST']
    config.gamecloud.user = ENV['CLOUD_USER']
    config.gamecloud.api_key = ENV['API_KEY']
  end

  if ENV['DB_HOST'] && ENV['DB_PORT']  && ENV['DB_NAME'] && ENV['DB_USER'] && ENV['DB_PASS']
    GameMachine.logger.info "Found database config in ENV"
    config.jdbc.hostname =  ENV['DB_HOST']
    config.jdbc.port =      ENV['DB_PORT'].to_i
    config.jdbc.database =  ENV['DB_NAME']
    config.jdbc.username =  ENV['DB_USER']
    config.jdbc.password =  ENV['DB_PASS']
  end

  if ENV['AKKA_SEED_HOST'] && ENV['AKKA_SEED_PORT']
    GameMachine.logger.info "Found Seed in ENV"
    Application.config.seeds << "#{ENV['AKKA_SEED_HOST']}:#{ENV['AKKA_SEED_PORT']}"
  end

end

#set_java_configObject


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'server/lib/game_machine/app_config.rb', line 22

def set_java_config
  JavaLib::AppConfig.set_env_root(ENV['APP_ROOT'])
  JavaLib::AppConfig.set_config_name(GameMachine.env)
  JavaLib::AppConfig.set_env(config.environment)
  JavaLib::AppConfig.set_agent_secret(config.agent_secret)
  JavaLib::AppConfig.set_default_game_id(config.default_game_id)
  JavaLib::AppConfig.setWorldOffset(config.world_offset)
  JavaLib::AppConfig.setGridExpiration(config.grid_expiration)
  JavaLib::AppConfig.set_orm(config.orm)
  JavaLib::AppConfig.set_plugins(config.plugins)
  JavaLib::AppConfig::Handlers.setAuth(config.handlers.auth)
  JavaLib::AppConfig::Gamecloud.set_host(config.gamecloud.host)
  JavaLib::AppConfig::Gamecloud.set_user(config.gamecloud.user)
  JavaLib::AppConfig::Gamecloud.set_api_key(config.gamecloud.api_key)

  JavaLib::AppConfig::Jdbc.set_hostname(config.jdbc.hostname)
  JavaLib::AppConfig::Jdbc.set_port(config.jdbc.port)
  JavaLib::AppConfig::Jdbc.set_database(config.jdbc.database)
  JavaLib::AppConfig::Jdbc.set_username(config.jdbc.username)
  JavaLib::AppConfig::Jdbc.set_password(config.jdbc.password)
  JavaLib::AppConfig::Jdbc.set_ds(config.jdbc.ds)
  JavaLib::AppConfig::Jdbc.set_driver(config.jdbc.driver)
  JavaLib::AppConfig::Jdbc.set_url(config.jdbc.url)
  
  JavaLib::AppConfig::Couchbase.set_bucket(config.couchbase.bucket)
  JavaLib::AppConfig::Couchbase.set_password(config.couchbase.password)
  JavaLib::AppConfig::Couchbase.set_servers(config.couchbase.servers)
  JavaLib::AppConfig::Datastore.set_store(config.datastore.store)
  JavaLib::AppConfig::Datastore.set_serialization(config.datastore.serialization)
  JavaLib::AppConfig::Datastore.set_cache_write_interval(config.datastore.cache_write_interval)
  JavaLib::AppConfig::Datastore.set_cache_writes_per_second(config.datastore.cache_writes_per_second)
  JavaLib::AppConfig::Datastore.set_mapdb_path(config.datastore.mapdb_path)

  JavaLib::GridConfigs::set_grid_configs(config.grids)
        
  JavaLib::AppConfig::Client.setIdleTimeout(config.client.idle_timeout)
  JavaLib::AppConfig::Client.setProtocol(config.client.protocol)
  JavaLib::AppConfig::Client.setTcpHost(config.tcp.host)
  JavaLib::AppConfig::Client.setTcpPort(config.tcp.port)
  JavaLib::AppConfig::Client.setUdpHost(config.udp.host)
  JavaLib::AppConfig::Client.setUdpPort(config.udp.port)
end