Exemplo n.º 1
0
        private void SessionChanged(ITorchSession session, TorchSessionState state)
        {
            var mpMan = Torch.CurrentSession.Managers.GetManager <IMultiplayerManagerServer>();

            switch (state)
            {
            case TorchSessionState.Loaded:
                mpMan.PlayerJoined     += MotdOnce;
                mpMan.PlayerLeft       += ResetMotdOnce;
                MyEntities.OnEntityAdd += EntityAdded;
                if (Config.StopShipsOnStart)
                {
                    StopShips();
                }
                _control?.Dispatcher.Invoke(() =>
                {
                    _control.IsEnabled   = true;
                    _control.DataContext = Config;
                });
                AutoCommands.Instance.Start();
                InfoModule.Init();
                break;

            case TorchSessionState.Unloading:
                mpMan.PlayerLeft       -= ResetMotdOnce;
                mpMan.PlayerJoined     -= MotdOnce;
                MyEntities.OnEntityAdd -= EntityAdded;
                _bagTracker.Clear();
                _removalTracker.Clear();
                break;
            }
        }
Exemplo n.º 2
0
        private void SessionChanged(ITorchSession session, TorchSessionState state)
        {
            var mpMan  = Torch.CurrentSession.Managers.GetManager <IMultiplayerManagerServer>();
            var cmdMan = Torch.CurrentSession.Managers.GetManager <CommandManager>();

            switch (state)
            {
            case TorchSessionState.Loading:
                string homeData = File.ReadAllText(homeDataPath);
                if (!string.IsNullOrEmpty(homeData))
                {
                    PlayerAccountModule.PlayersAccounts = JsonConvert.DeserializeObject <List <PlayerAccountModule.PlayerAccountData> >(File.ReadAllText(homeDataPath));
                }

                string rankdata = File.ReadAllText(rankDataPath);
                if (!string.IsNullOrEmpty(rankdata))
                {
                    RanksAndPermissionsModule.Ranks = JsonConvert.DeserializeObject <List <RanksAndPermissionsModule.RankData> >(File.ReadAllText(rankDataPath));
                }

                break;

            case TorchSessionState.Loaded:
                mpMan.PlayerJoined += AccModule.GenerateAccount;
                mpMan.PlayerJoined += MotdOnce;
                if (Config.EnableRanks)
                {
                    RanksAndPermissions.GenerateRank(Config.DefaultRank);
                    mpMan.PlayerJoined += RanksAndPermissions.RegisterInheritedRanks;
                }
                mpMan.PlayerLeft          += ResetMotdOnce;
                cmdMan.OnCommandExecuting += RanksAndPermissions.HasCommandPermission;
                MyEntities.OnEntityAdd    += EntityAdded;
                if (Config.StopShipsOnStart)
                {
                    StopShips();
                }
                _control?.Dispatcher.Invoke(() =>
                {
                    _control.IsEnabled   = true;
                    _control.DataContext = Config;
                });
                AutoCommands.Instance.Start();
                InfoModule.Init();
                break;

            case TorchSessionState.Unloading:
                mpMan.PlayerLeft       -= ResetMotdOnce;
                mpMan.PlayerJoined     -= MotdOnce;
                MyEntities.OnEntityAdd -= EntityAdded;
                _bagTracker.Clear();
                _removalTracker.Clear();
                break;
            }
        }