Class: GameMachine::Application

Inherits:
Object
  • Object
show all
Defined in:
server/lib/game_machine/application.rb

Class Method Summary collapse

Class Method Details

.akkaObject


20
21
22
# File 'server/lib/game_machine/application.rb', line 20

def akka
  Akka.instance
end

.configObject


24
25
26
# File 'server/lib/game_machine/application.rb', line 24

def config
  AppConfig.instance.config
end

.data_storeObject


12
13
14
15
16
17
18
# File 'server/lib/game_machine/application.rb', line 12

def data_store
  store = DbLib::Store.get_instance
  store.connect(
    config.datastore.store,
    config.datastore.serialization
  )
end

.initialize!Object


6
7
8
9
10
# File 'server/lib/game_machine/application.rb', line 6

def initialize!
  AppConfig.instance.load_config
  JavaLib::GameMachineLoader.preStart
  akka.initialize!
end

.load_pluginsObject


89
90
91
92
93
# File 'server/lib/game_machine/application.rb', line 89

def load_plugins
  require_relative '../../java/server/src/user/java/plugins/plugins.rb'

  JavaLib::GameMachineLoader.start_java_game_actors
end

.orm_connectObject


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'server/lib/game_machine/application.rb', line 69

def orm_connect
  if config.orm
    pool = GameMachine::JavaLib::DbConnectionPool.getInstance
    unless pool.connect(
      'game_machine_orm',
      config.jdbc.hostname,
      config.jdbc.port,
      config.jdbc.database,
      config.jdbc.ds,
      config.jdbc.username,
      config.jdbc.password || '',
      config.jdbc.driver,
      config.jdbc.url
    )
      GameMachine.logger.error "Unable to establish database connection, exiting"
      System.exit 1
    end
  end
end

.register(system_class) ⇒ Object


32
33
34
35
# File 'server/lib/game_machine/application.rb', line 32

def register(system_class)
  registered << system_class
  GameMachine.logger.debug "#{system_class} registered"
end

.registeredObject


28
29
30
# File 'server/lib/game_machine/application.rb', line 28

def registered
  @@registered ||= Set.new
end

.startObject


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'server/lib/game_machine/application.rb', line 50

def start
  orm_connect

  start_actor_system
  data_store
  
  start_endpoints
  start_core_systems
  start_handlers

  start_game_systems
  load_plugins
 
  start_http

  GameMachine.logger.info("Game Machine start successful")
  
end

.start_actor_systemObject


37
38
39
# File 'server/lib/game_machine/application.rb', line 37

def start_actor_system
  akka.start
end

.start_core_systemsObject

TODO configurize router sizes


122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'server/lib/game_machine/application.rb', line 122

def start_core_systems
  Actor::Builder.new(ClusterMonitor).start
  Actor::Builder.new(ObjectDb).distributed(1).start
  JavaLib::GameMachineLoader.startObjectDb(config.routers.objectdb)
  Actor::Builder.new(MessageQueue).start

  ClientManager.get_map('preload')
  Actor::Builder.new(ClientManager).with_router(JavaLib::RoundRobinRouter,config.routers.game_handler * 2).start
  Actor::Builder.new(ClientManagerUpdater).start
  
  # Client manager especially needs to be running now, so other actors can
  # register to it to receive events
  unless GameMachine.env == 'test'
    GameMachine.logger.info("Waiting 2 seconds for core actors to start")
    sleep 2
  end

end

.start_endpointsObject


101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'server/lib/game_machine/application.rb', line 101

def start_endpoints
  if config.tcp.enabled
    NetLib::TcpServer.start(config.tcp.host, config.tcp.port);
    GameMachine.logger.info(
      "Tcp starting on #{config.tcp.host}:#{config.tcp.port}"
    )
  end

  if config.udp.enabled
    NetLib::UdpServer.start("netty",config.udp.host,config.udp.port)
  end

  JavaLib::GameMachineLoader.start_incoming(config.routers.incoming)
end

.start_game_systemsObject


141
142
143
144
145
146
147
148
149
150
151
152
# File 'server/lib/game_machine/application.rb', line 141

def start_game_systems
  Actor::Builder.new(GameSystems::Devnull).start
  JavaLib::GameMachineLoader.StartEntityTracking
  Actor::Builder.new(GameSystems::LocalEcho).with_router(JavaLib::RoundRobinRouter,1).start
  Actor::Builder.new(GameSystems::LocalEcho).with_name('DistributedLocalEcho').distributed(2).start
  Actor::Builder.new(GameSystems::StressTest).with_router(JavaLib::RoundRobinRouter,1).start
  Actor::Builder.new(GameSystems::ChatManager).start

  # Make sure shared hashmaps are initialized
  #team_handler = Application.config.handlers.team.constantize.new
  #Actor::Builder.new(GameSystems::TeamManager).with_router(JavaLib::RoundRobinRouter,config.routers.game_handler).start
end

.start_handlersObject


116
117
118
# File 'server/lib/game_machine/application.rb', line 116

def start_handlers
  JavaLib::GameMachineLoader.start_request_handler(config.routers.request_handler)
end

.start_httpObject


95
96
97
98
# File 'server/lib/game_machine/application.rb', line 95

def start_http
  http = NetLib::HttpServer.new(config.http.host,config.http.port,config.http.ssl,'message_gateway')
  http.start
end

.stopObject


45
46
47
48
# File 'server/lib/game_machine/application.rb', line 45

def stop
  stop_actor_system
  DbLib::Store.get_instance.shutdown
end

.stop_actor_systemObject


41
42
43
# File 'server/lib/game_machine/application.rb', line 41

def stop_actor_system
  akka.stop
end