Example #1
0
        public override void Start()
        {
            base.Start();

            Console.AddCommandByMethod(() => ReloadConfig());

            Container.Register(config);

            Container.TryResolve(out IGlobalSession globalSession);

            Debug.Log("Remote config loading...");
            AppConfig.LoadByUrlAsync().ContinueWith((json) =>
            {
                var loadedConfig = OnConfigLoaded(json);

                var globalPort = CommandLine.GetArg("--port");
                if (globalPort != null)
                {
                    loadedConfig.Main.ServerPort = ushort.Parse(globalPort);
                }

                var gameId = CommandLine.GetArg("--gameid");
                if (globalSession?.Game != null) //TODO: Have separate logic(client\serv\editor)
                {
                    LoadGameData(globalSession.Game.id)
                    .ContinueWith(data =>
                    {
                        var(game, characters) = data;
                        Container.Resolve <IGlobalSession>().Game             = game;
                        Container.Resolve <IGlobalSession>().CharactersInGame = characters;

                        //InitWorlds(Container.Resolve<IGlobalSession>().Game);
                        InitWorlds(loadedConfig.Main.ServerPort);
                    });
                }
                else if (gameId != null)
                {
                    LoadGameData(gameId)
                    .ContinueWith(data =>
                    {
                        var(game, characters) = data;
                        var newSession        = new GlobalSession
                        {
                            Game             = game,
                            CharactersInGame = characters
                        };
                        MainContainer.Container.Register <IGlobalSession>(newSession);
                        InitWorlds(loadedConfig.Main.ServerPort);
                    });
                }
                else
                {
                    InitWorlds(loadedConfig.Main.ServerPort);
                }
            });
        }