game_sup.erl 1.5 KB

1234567891011121314151617181920212223242526272829
  1. -module(game_sup).
  2. -behaviour(supervisor).
  3. -export([start_link/0, stop/0]).
  4. -include_lib("server/include/conf.hrl").
  5. -export([init/1, start/0, start_game/3, stop_game/2]).
  6. -define(SERVER, ?MODULE).
  7. start() -> supervisor:start({local, ?SERVER}, ?MODULE, []).
  8. start_link() -> supervisor:start_link({local, ?SERVER}, ?MODULE, []).
  9. stop() -> exit(?SERVER, shutdown).
  10. start_game(Sup,Mod,Par) -> supervisor:start_child(Sup,[Mod,Par]).
  11. stop_game(Sup,Pid) -> supervisor:terminate_child(Sup,Pid).
  12. init([]) ->
  13. RestartStrategy = one_for_one,
  14. MaxRestarts = 100,
  15. MaxSecondsBetweenRestarts = 3600,
  16. SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts},
  17. Restart = permanent,
  18. Shutdown = 2000,
  19. IdGen = {id_generator, {id_generator, start_link, []}, Restart, Shutdown, worker, [id_generator]},
  20. AuthServer = {auth_server, {auth_server, start_link, []}, Restart, Shutdown, worker, [auth_server]},
  21. GameStats = {game_stats, {game_stats, start_link, []}, Restart, Shutdown, worker, [game_stats]},
  22. GameManager = {game_manager, {game_manager, start_link, []}, Restart, Shutdown, worker, [game_manager]},
  23. TavlaSup = {tavla_sup, {tavla_sup, start_link, []}, Restart, Shutdown, supervisor, [tavla_sup]},
  24. OkeySup = {okey_sup, {okey_sup, start_link, []}, Restart, Shutdown, supervisor, [okey_sup]},
  25. LuckySup = {lucky_sup, {lucky_sup, start_link, []}, Restart, Shutdown, supervisor, [lucky_sup]},
  26. {ok, {SupFlags, [IdGen,GameManager,LuckySup,AuthServer,GameStats,TavlaSup,OkeySup]}}.