Exemple #1
0
 private void TorchOnGameStateChanged(MySandboxGame game, TorchGameState newstate)
 {
     if (newstate == TorchGameState.Loading && MySandboxGame.ConfigDedicated.RemoteApiEnabled && !string.IsNullOrEmpty(MySandboxGame.ConfigDedicated.RemoteSecurityKey))
     {
         var myRemoteServer = new MyRemoteServer(MySandboxGame.ConfigDedicated.RemoteApiPort, MySandboxGame.ConfigDedicated.RemoteSecurityKey);
         LogManager.GetCurrentClassLogger().Info($"Remote API started on port {myRemoteServer.Port}");
     }
 }
 void GameStateChanged(MySandboxGame game, TorchGameState state)
 {
     if (state != TorchGameState.Created)
     {
         return;
     }
     // not necessary after 1.196
     // API.Register();
 }
Exemple #3
0
        private void GameStateChanged(Sandbox.MySandboxGame game, TorchGameState newState)
        {
            if (newState == TorchGameState.Loaded)
            {
            }

            if (newState == TorchGameState.Unloading)
            {
            }
        }
 private void OnGameStateChanged(MySandboxGame game, TorchGameState newState)
 {
     if ((newState & TorchGameState.Loaded) == TorchGameState.Loaded)
     {
         Torch.Managers.GetManager(typeof(PBProfilerManager)).Attach();
     }
     else if ((newState & TorchGameState.Unloading) != 0)
     {
         Torch.Managers.GetManager(typeof(PBProfilerManager)).Detach();
     }
 }
Exemple #5
0
        private void OnGameStateChanged(MySandboxGame game, TorchGameState newstate)
        {
            switch (newstate)
            {
            case TorchGameState.Creating:
                var instanceManager = Torch
                                      .Managers
                                      .GetManager(typeof(InstanceManager)) as InstanceManager;

                instanceManager?.DedicatedConfig.Mods
                .Add(new ModItemInfo(new MyObjectBuilder_Checkpoint.ModItem(1772298664)));
                break;
            }
        }
Exemple #6
0
        private void Torch_GameStateChanged(MySandboxGame game, TorchGameState newState)
        {
            if (MySandboxGame.ConfigDedicated.RemoteApiEnabled)
            {
                LogManager.GetCurrentClassLogger().Error($"Remote API is enabled, disable it!");
                return;
            }

            if (newState == TorchGameState.Creating)
            {
                LogManager.GetCurrentClassLogger().Info($"WebServer started on port {MySandboxGame.ConfigDedicated.RemoteApiPort}");
                ws = new WebServer(SendHttpResponseResponse, $"http://*:{MySandboxGame.ConfigDedicated.RemoteApiPort}/");
                ws.Run();
            }
            else if (newState == TorchGameState.Unloaded)
            {
                ws.Stop();
                ws = null;
            }
            else if (newState == TorchGameState.Loaded)
            {
                List <ulong> modIds        = MySession.Static.Mods.Select((x) => x.PublishedFileId).ToList();
                List <ulong> modAddedIds   = modIds.Except(_config.Data.LastModIds).ToList();
                List <ulong> modRemovedIds = _config.Data.LastModIds.Except(modIds).ToList();

                if (modAddedIds.Count > 0 || modRemovedIds.Count > 0)
                {
                    List <string> tags = new List <string>();
                    tags.Add("mods");
                    if (modAddedIds.Count > 0)
                    {
                        tags.Add("added");
                    }
                    if (modRemovedIds.Count > 0)
                    {
                        tags.Add("removed");
                    }

                    List <string> text = new List <string>();
                    foreach (ulong modId in modAddedIds)
                    {
                        text.Add($"Added {modId} ({MySession.Static.Mods.Find((x) => x.PublishedFileId == modId).Name})");
                    }
                    foreach (ulong modId in modRemovedIds)
                    {
                        text.Add($"Removed {modId} ({MySession.Static.Mods.Find((x) => x.PublishedFileId == modId).Name})");
                    }

                    events.EnqueueFront(new Event
                    {
                        Type     = "config",
                        Text     = string.Join("\n", text),
                        Tags     = tags.ToArray(),
                        Occurred = DateTime.Now,
                    });

                    _config.Data.LastModIds = modIds;
                    _config.Save();
                }

                GC.Collect();
            }
        }