-module(main).

-behaviour(application).

-export([start/0, start/2, stop/1]).

start() ->
   AllApp = [kernel, stdlib, sasl, inets, crypto, asn1, public_key, ssl, main],
   [doStartApp(App) || App <- AllApp].

doStartApp(MFAOrApp) ->
   try
      case case is_function(MFAOrApp) of true -> MFAOrApp(); _ -> application:ensure_all_started(MFAOrApp) end of
         {error, AppErrReason} ->
            io:format("start the app:~p error:~p", [MFAOrApp, AppErrReason]),
            exit({error, AppErrReason});
         _ ->
            io:format("start app ~w", [MFAOrApp])
      end
   catch C:R:S ->
      io:format("start the app:~p CRS:~p", [MFAOrApp, {C, R, S}]),
      exit({error, {MFAOrApp, {C, R, S}}})
   end.

start(_StartType, _StartArgs) ->
   game_master_sup:start_link(["127.0.0.1", "9310"]).

stop(_State) ->
   ok.
