예제 #1
0
 public void InitializeScenario()
 {
     if (scenario != null)
     {
         return;
     }
     if (ScenarioRunner.Instance == null)
     {
         return;
     }
     if (Client.realtimeSinceStartup > (lastInitCheck + 10))
     {
         lastInitCheck = Client.realtimeSinceStartup;
         foreach (ScenarioModule sm in ScenarioRunner.GetLoadedModules())
         {
             if (scenario == null && sm is ScenarioDiscoverableObjects)
             {
                 scenario = (ScenarioDiscoverableObjects)sm;
             }
         }
         if (scenario != null)
         {
             DarkLog.Debug("Scenario module found, we can spawn asteroids!");
             scenario.spawnInterval    = float.MaxValue;
             scenario.spawnOddsAgainst = 1;
             // Disable the new Sentinel mechanic in KSP 1.3.0
             SentinelUtilities.SpawnChance = 0f;
         }
     }
 }
예제 #2
0
 /// <summary>
 /// Check if the scenario has changed and sends it to the server
 /// </summary>
 public void SendScenarioModules()
 {
     if (Enabled)
     {
         var modules = (ScenarioModule[])ScenarioRunner.GetLoadedModules().ToArray().Clone();
         TaskFactory.StartNew(() => ParseAndSendModules(modules));
     }
 }
예제 #3
0
 /// <summary>
 /// Check if the scenario has changed and sends it to the server
 /// </summary>
 public void SendScenarioModules()
 {
     if (Enabled)
     {
         var modules = ScenarioRunner.GetLoadedModules();
         ParseModulesToConfigNodes(modules);
         TaskFactory.StartNew(SendModulesConfigNodes);
     }
 }
예제 #4
0
        public void SendScenarioModules(bool highPriority)
        {
            List <string> scenarioName = new List <string>();
            List <byte[]> scenarioData = new List <byte[]>();

            foreach (ScenarioModule sm in ScenarioRunner.GetLoadedModules())
            {
                string scenarioType = sm.GetType().Name;
                if (!IsScenarioModuleAllowed(scenarioType))
                {
                    continue;
                }
                ConfigNode scenarioNode = new ConfigNode();
                sm.Save(scenarioNode);

                if (scenarioType == "ContractSystem")
                {
                    SpawnStrandedKerbalsForRescueMissions(scenarioNode);
                }

                byte[] scenarioBytes = ConfigNodeSerializer.fetch.Serialize(scenarioNode);
                string scenarioHash  = Common.CalculateSHA256Hash(scenarioBytes);
                if (scenarioBytes.Length == 0)
                {
                    DarkLog.Debug("Error writing scenario data for " + scenarioType);
                    continue;
                }
                if (checkData.ContainsKey(scenarioType) ? (checkData[scenarioType] == scenarioHash) : false)
                {
                    //Data is the same since last time - Skip it.
                    continue;
                }
                else
                {
                    checkData[scenarioType] = scenarioHash;
                }
                if (scenarioBytes != null)
                {
                    scenarioName.Add(scenarioType);
                    scenarioData.Add(scenarioBytes);
                }
            }

            if (scenarioName.Count > 0)
            {
                if (highPriority)
                {
                    NetworkWorker.fetch.SendScenarioModuleDataHighPriority(scenarioName.ToArray(), scenarioData.ToArray());
                }
                else
                {
                    NetworkWorker.fetch.SendScenarioModuleData(scenarioName.ToArray(), scenarioData.ToArray());
                }
            }
        }
예제 #5
0
    private MinmusComposition getMinmusCompositionScenarioModule()
    {
        foreach (ScenarioModule s in ScenarioRunner.GetLoadedModules())
        {
            if (s.GetType().Equals(typeof(MinmusComposition)))
            {
                return((MinmusComposition)s);
            }
        }

        return(null);
    }
    private NeutrinosScenario getNeutrinosScenarioModule()
    {
        foreach (ScenarioModule s in ScenarioRunner.GetLoadedModules())
        {
            if (s.GetType().Equals(typeof(NeutrinosScenario)))
            {
                return((NeutrinosScenario)s);
            }
        }

        return(null);
    }
예제 #7
0
        /// <summary>
        /// Check if the scenario has changed and sends it to the server
        /// This method is not optimized and take several ms to run
        /// </summary>
        public void SendScenarioModules()
        {
            if (!Enabled || !SystemsContainer.Get <MainSystem>().GameRunning)
            {
                return;
            }

            var modules = ScenarioRunner.GetLoadedModules().ToArray();

            //I tried to do this method in another thread as it takes a lot of time to run
            //but appear several empty lines in the log... Perhaps we cannot do it :(
            var scenarioName = new List <string>();
            var scenarioData = new List <byte[]>();

            foreach (var scenarioModule in modules)
            {
                var scenarioType = scenarioModule.GetType().Name;

                if (!IsScenarioModuleAllowed(scenarioType))
                {
                    continue;
                }

                var scenarioNode = new ConfigNode();
                scenarioModule.Save(scenarioNode);

                var scenarioBytes = ConfigNodeSerializer.Serialize(scenarioNode);
                var scenarioHash  = Common.CalculateSha256Hash(scenarioBytes);

                if (scenarioBytes.Length == 0)
                {
                    LunaLog.Log($"[LMP]: Error writing scenario data for {scenarioType}");
                    continue;
                }

                //Data is the same since last time - Skip it.
                if (CheckData.ContainsKey(scenarioType) && CheckData[scenarioType] == scenarioHash)
                {
                    continue;
                }

                CheckData[scenarioType] = scenarioHash;

                scenarioName.Add(scenarioType);
                scenarioData.Add(scenarioBytes);
            }

            if (scenarioName.Any())
            {
                MessageSender.SendScenarioModuleData(scenarioName.ToArray(), scenarioData.ToArray());
            }
        }
예제 #8
0
 /// <summary>
 /// Check if the scenario has changed and sends it to the server
 /// </summary>
 public void SendScenarioModules()
 {
     if (Enabled)
     {
         try
         {
             var modules = ScenarioRunner.GetLoadedModules();
             ParseModulesToConfigNodes(modules);
             TaskFactory.StartNew(SendModulesConfigNodes);
         }
         catch (Exception e)
         {
             LunaLog.LogError($"Error while trying to send the scenario modules!. Details {e}");
         }
     }
 }
예제 #9
0
 private bool TestForActiveSCANsat()
 {
     if (satFound)
     {
         return(true);
     }
     foreach (ScenarioModule thatScenario in ScenarioRunner.GetLoadedModules())
     {
         if (thatScenario.ClassName == "SCANcontroller")
         {
             satFound = true;
             return(true);
         }
     }
     return(false);
 }
예제 #10
0
            public static ExternalInterface Get()
            {
                List <ScenarioModule> modules;

                try {
                    modules = ScenarioRunner.GetLoadedModules();
                } catch {
                    return(null);
                }
                foreach (var module in modules)
                {
                    if (module is PrincipiaPluginAdapter)
                    {
                        return(new ExternalInterface((PrincipiaPluginAdapter)module));
                    }
                }
                return(null);
            }
예제 #11
0
        /// <summary>
        /// Check if the scenario has changed and sends it to the server
        /// </summary>
        public void SendScenarioModules()
        {
            var scenarioName = new List <string>();
            var scenarioData = new List <byte[]>();

            foreach (var scenarioModule in ScenarioRunner.GetLoadedModules())
            {
                var scenarioType = scenarioModule.GetType().Name;

                if (!IsScenarioModuleAllowed(scenarioType))
                {
                    continue;
                }

                var scenarioNode = new ConfigNode();
                scenarioModule.Save(scenarioNode);

                var scenarioBytes = ConfigNodeSerializer.Singleton.Serialize(scenarioNode);
                var scenarioHash  = Common.CalculateSha256Hash(scenarioBytes);

                if (scenarioBytes.Length == 0)
                {
                    Debug.Log($"[LMP]: Error writing scenario data for {scenarioType}");
                    continue;
                }

                //Data is the same since last time - Skip it.
                if (CheckData.ContainsKey(scenarioType) && (CheckData[scenarioType] == scenarioHash))
                {
                    continue;
                }

                CheckData[scenarioType] = scenarioHash;

                scenarioName.Add(scenarioType);
                scenarioData.Add(scenarioBytes);
            }

            if (scenarioName.Any())
            {
                MessageSender.SendScenarioModuleData(scenarioName.ToArray(), scenarioData.ToArray());
            }
        }
        private void SendScenarioModules()
        {
            List <string> scenarioName = new List <string>();
            List <byte[]> scenarioData = new List <byte[]>();

            foreach (ScenarioModule sm in ScenarioRunner.GetLoadedModules())
            {
                string scenarioType = sm.GetType().Name;
                if (!IsScenarioModuleAllowed(scenarioType))
                {
                    continue;
                }
                ConfigNode scenarioNode = new ConfigNode();
                sm.Save(scenarioNode);
                byte[] scenarioBytes = ConfigNodeSerializer.fetch.Serialize(scenarioNode);
                string scenarioHash  = Common.CalculateSHA256Hash(scenarioBytes);
                if (checkData.ContainsKey(scenarioType) ? (checkData[scenarioType] == scenarioHash) : false)
                {
                    //Data is the same since last time - Skip it.
                    continue;
                }
                else
                {
                    checkData[scenarioType] = scenarioHash;
                }
                if (scenarioBytes != null)
                {
                    scenarioName.Add(scenarioType);
                    scenarioData.Add(scenarioBytes);
                }
            }

            if (scenarioName.Count > 0)
            {
                NetworkWorker.fetch.SendScenarioModuleData(scenarioName.ToArray(), scenarioData.ToArray());
            }
        }
예제 #13
0
        public void SendScenarioModules(bool highPriority)
        {
            lastScenarioSendTime = Client.realtimeSinceStartup;
            List <string>    scenarioName = new List <string>();
            List <ByteArray> scenarioData = new List <ByteArray>();

            foreach (ScenarioModule sm in ScenarioRunner.GetLoadedModules())
            {
                string scenarioType = sm.GetType().Name;
                if (!IsScenarioModuleAllowed(scenarioType))
                {
                    continue;
                }
                try
                {
                    ConfigNode scenarioNode = new ConfigNode();
                    sm.Save(scenarioNode);

                    ByteArray scenarioBytes = configNodeSerializer.Serialize(scenarioNode);
                    string    scenarioHash  = Common.CalculateSHA256Hash(scenarioBytes);
                    if (scenarioBytes.Length == 0)
                    {
                        DarkLog.Debug("Error writing scenario data for " + scenarioType);
                        ByteRecycler.ReleaseObject(scenarioBytes);
                        continue;
                    }
                    if (checkData.ContainsKey(scenarioType) ? (checkData[scenarioType] == scenarioHash) : false)
                    {
                        //Data is the same since last time - Skip it.
                        ByteRecycler.ReleaseObject(scenarioBytes);
                        continue;
                    }
                    else
                    {
                        checkData[scenarioType] = scenarioHash;
                    }
                    scenarioName.Add(scenarioType);
                    scenarioData.Add(scenarioBytes);
                }
                catch (Exception e)
                {
                    string fullName = sm.GetType().FullName;
                    if (!warnedModules.Contains(fullName))
                    {
                        DarkLog.Debug("Unable to save module data from " + fullName + ", skipping upload of this module. Exception: " + e);
                        warnedModules.Add(fullName);
                        if (!fullName.Contains("Expansions.Serenity.DeployedScience"))
                        {
                            ScreenMessages.PostScreenMessage("DMP was unable to save " + fullName + ", this module data will be lost.", 30f, ScreenMessageStyle.UPPER_CENTER);
                        }
                    }
                }
            }

            if (scenarioName.Count > 0)
            {
                if (highPriority)
                {
                    networkWorker.SendScenarioModuleDataHighPriority(scenarioName.ToArray(), scenarioData.ToArray());
                }
                else
                {
                    networkWorker.SendScenarioModuleData(scenarioName.ToArray(), scenarioData.ToArray());
                }
            }
        }
 public static IEnumerable <T> GetScenarioModules <T>()
     where T : ScenarioModule
 {
     return(ScenarioRunner.GetLoadedModules().OfType <T>());
 }