Пример #1
0
        private void SessionChanged(ITorchSession session, TorchSessionState state)
        {
            switch (state)
            {
            case TorchSessionState.Loading:
                Hangar.Config.RefreshModel();
                break;

            case TorchSessionState.Loaded:

                //MP = Torch.CurrentSession.Managers.GetManager<MultiplayerManagerBase>();
                //ChatManager = Torch.CurrentSession.Managers.GetManager<ChatManagerServer>();
                PluginManager Plugins = Torch.CurrentSession.Managers.GetManager <PluginManager>();
                PluginDependencies.InitPluginDependencies(Plugins);
                ServerRunning = true;
                AutoHangar.StartAutoHangar();
                Controller?.ServerStarted();
                break;


            case TorchSessionState.Unloading:
                ServerRunning = false;
                PluginDispose();
                break;
            }
        }
Пример #2
0
        public bool LoadGrid(int ID, out IEnumerable <MyObjectBuilder_CubeGrid> Grids, out GridStamp Stamp)
        {
            Grids = null;
            Stamp = null;
            if (ID - 1 >= SelectedPlayerFile.Grids.Count || ID < 1)
            {
                Chat?.Respond("Invalid Index! Grid doent exsist in that slot!");
                return(false);
            }


            Stamp = SelectedPlayerFile.GetGrid(ID);
            string GridPath = Path.Combine(PlayersFolderPath, Stamp.GridName + ".sbc");

            Log.Warn("Attempting to load grid @" + GridPath);
            if (!GridSerializer.LoadGrid(GridPath, out Grids))
            {
                return(false);
            }

            PluginDependencies.BackupGrid(Grids.ToList(), IdentityID);
            GridSerializer.TransferGridOwnership(Grids, IdentityID);

            return(true);
        }
Пример #3
0
        public void LoadGrid(int ID, bool LoadNearPlayer)
        {
            if (!PerformMainChecks(false))
            {
                return;
            }

            if (!PlayersHanger.LoadGrid(ID, out IEnumerable <MyObjectBuilder_CubeGrid> Grids, out GridStamp Stamp))
            {
                Log.Error($"Loading grid {ID} failed for {IdentityID}!");
                Chat.Respond("Loading grid failed! Report this to staff and check logs for more info!");
                return;
            }


            if (!PlayersHanger.CheckLimits(Stamp, Grids))
            {
                return;
            }

            if (!CheckEnemyDistance(Config.LoadType, Stamp.GridSavePosition))
            {
                return;
            }

            if (!RequireLoadCurrency(Stamp))
            {
                return;
            }

            PluginDependencies.BackupGrid(Grids.ToList(), IdentityID);
            Vector3D SpawnPos = DetermineSpawnPosition(Stamp.GridSavePosition, PlayerPosition, out bool KeepOriginalPosition, LoadNearPlayer);

            if (!CheckDistanceToLoadPoint(SpawnPos))
            {
                return;
            }


            ParallelSpawner Spawner = new ParallelSpawner(Grids, Chat, !KeepOriginalPosition, SpawnedGridsSuccessful);

            Log.Info("Attempting Grid Spawning @" + SpawnPos.ToString());
            if (Spawner.Start(KeepOriginalPosition, SpawnPos))
            {
                Chat?.Respond("Spawning Complete!");
                PlayersHanger.RemoveGridStamp(Stamp);
            }
            else
            {
                Chat?.Respond("An error occured while spawning the grid!");
            }
        }
Пример #4
0
        public bool LoadGrid(GridStamp Stamp, out IEnumerable <MyObjectBuilder_CubeGrid> Grids)
        {
            Grids = null;


            if (!Stamp.TryGetGrids(PlayersFolderPath, out Grids))
            {
                return(false);
            }


            PluginDependencies.BackupGrid(Grids.ToList(), Identity.IdentityId);
            GridSerializer.TransferGridOwnership(Grids, Identity.IdentityId, Stamp.TransferOwnerShipOnLoad);

            return(true);
        }
        public static bool SaveGridsAndClose(IEnumerable <MyCubeGrid> Grids, string Path, string GridName, long OwnerIdentity)
        {
            Log.Info(Grids.Count());
            Task <IEnumerable <MyObjectBuilder_CubeGrid> > GridTask = GameEvents.InvokeAsync <IEnumerable <MyCubeGrid>, IEnumerable <MyObjectBuilder_CubeGrid> >(GetObjectBuilders, Grids);

            if (!GridTask.Wait(5000))
            {
                Log.Info("Grid saving timed out!");
                return(false);
            }
            else
            {
                CloseAllGrids(Grids);
                //ClearAllAttachments(GridTask.Result);
                SaveGridToFile(Path, GridName, GridTask.Result);
                PluginDependencies.BackupGrid(GridTask.Result.ToList(), OwnerIdentity);
                return(true);
            }
        }
Пример #6
0
        public void SetPluginsDependencies()
        {
            PluginDependencies.Items.Clear();
            List <string> providedPlugins = new List <string>();

            System.Globalization.CultureInfo invariantCulture = System.Globalization.CultureInfo.InvariantCulture;
            foreach (FileItem file in UniqueFileList.Items)
            {
                if (file.DestinationFilename.StartsWith("%" + MediaPortal.Configuration.Config.Dir.Plugins + "%", true, invariantCulture) &&
                    file.DestinationFilename.EndsWith(".dll", true, invariantCulture))
                {
                    string asm          = file.LocalFileName;
                    string assemblyPath = asm;
                    if (!Path.IsPathRooted(asm))
                    {
                        assemblyPath = Path.Combine(Path.GetDirectoryName(ProjectSettings.ProjectFilename), assemblyPath);
                        assemblyPath = Path.GetFullPath(assemblyPath);
                    }
                    if (Util.IsPlugin(assemblyPath))
                    {
                        providedPlugins.Add(asm);
                    }
                }
            }
            foreach (string asm in providedPlugins)
            {
                PluginDependencyItem dep = new PluginDependencyItem();
                dep.AssemblyName = Path.GetFileName(asm);
                string assemblyPath = asm;
                if (!Path.IsPathRooted(asm))
                {
                    assemblyPath = Path.Combine(Path.GetDirectoryName(ProjectSettings.ProjectFilename), assemblyPath);
                    assemblyPath = Path.GetFullPath(assemblyPath);
                }
                if (dep.ScanVersionInfo(assemblyPath))
                {
                    PluginDependencies.Add(dep);
                }
            }
        }
Пример #7
0
        public static async Task <bool> SaveGridsAndClose(IEnumerable <MyCubeGrid> Grids, string Path, string GridName, long OwnerIdentity)
        {
            Thread CurrentThread = Thread.CurrentThread;

            if (CurrentThread == MyUtils.MainThread)
            {
                //Log.Warn("Running on game thread!");

                IEnumerable <MyObjectBuilder_CubeGrid> grids = GetObjectBuilders(Grids);
                Grids.Close();


                await Task.Run(() => {
                    SaveGridToFile(Path, GridName, grids);
                    PluginDependencies.BackupGrid(grids.ToList(), OwnerIdentity);
                });

                return(true);
            }
            else
            {
                //Log.Warn("Not running on game thread!");

                //Log.Info(Grids.Count());
                Task <IEnumerable <MyObjectBuilder_CubeGrid> > GridTask = GameEvents.InvokeAsync <IEnumerable <MyCubeGrid>, IEnumerable <MyObjectBuilder_CubeGrid> >(GetObjectBuilders, Grids);
                if (!GridTask.Wait(5000))
                {
                    Log.Info("Grid saving timed out!");
                    return(false);
                }
                else
                {
                    Grids.Close();
                    //ClearAllAttachments(GridTask.Result);
                    SaveGridToFile(Path, GridName, GridTask.Result);
                    PluginDependencies.BackupGrid(GridTask.Result.ToList(), OwnerIdentity);
                    return(true);
                }
            }
        }
Пример #8
0
        public void LoadGrid(string input, bool LoadNearPlayer)
        {
            if (!PerformMainChecks(false))
            {
                return;
            }


            if (!PlayersHanger.ParseInput(input, out int ID))
            {
                Chat.Respond($"Grid {input} could not be found!");
                return;
            }



            if (!PlayersHanger.TryGetGridStamp(ID, out GridStamp Stamp))
            {
                return;
            }



            //Check to see if the grid is for sale. We need to let the player know if it is
            if (!CheckGridForSale(Stamp, ID))
            {
                return;
            }



            if (!PlayersHanger.LoadGrid(Stamp, out IEnumerable <MyObjectBuilder_CubeGrid> Grids))
            {
                Log.Error($"Loading grid {ID} failed for {IdentityID}!");
                Chat.Respond("Loading grid failed! Report this to staff and check logs for more info!");
                return;
            }

            if (!PlayersHanger.CheckLimits(Stamp, Grids))
            {
                return;
            }

            if (!CheckEnemyDistance(Config.LoadType, Stamp.GridSavePosition) && !Config.AllowLoadNearEnemy)
            {
                return;
            }

            if (!RequireLoadCurrency(Stamp))
            {
                return;
            }

            PluginDependencies.BackupGrid(Grids.ToList(), IdentityID);
            Vector3D SpawnPos = DetermineSpawnPosition(Stamp.GridSavePosition, PlayerPosition, out bool KeepOriginalPosition, LoadNearPlayer);

            if (!CheckDistanceToLoadPoint(SpawnPos))
            {
                return;
            }

            if (PluginDependencies.NexusInstalled && Config.NexusAPI &&
                NexusSupport.RelayLoadIfNecessary(SpawnPos, ID, LoadNearPlayer, Chat, SteamID, IdentityID, PlayerPosition))
            {
                return;
            }

            ParallelSpawner Spawner = new ParallelSpawner(Grids, Chat, SpawnedGridsSuccessful);

            Log.Info("Attempting Grid Spawning @" + SpawnPos.ToString());
            if (Spawner.Start(SpawnPos, KeepOriginalPosition))
            {
                Chat?.Respond("Spawning Complete!");
                PlayersHanger.RemoveGridStamp(ID);
            }
            else
            {
                Chat?.Respond("An error occured while spawning the grid!");
            }
        }
Пример #9
0
        private bool BlockLimitChecker(IEnumerable <MyObjectBuilder_CubeGrid> shipblueprints)
        {
            int BiggestGrid   = 0;
            int blocksToBuild = 0;
            //failedBlockType = null;
            //Need dictionary for each player AND their blocks they own. (Players could own stuff on the same grid)
            Dictionary <long, Dictionary <string, int> > BlocksAndOwnerForLimits = new Dictionary <long, Dictionary <string, int> >();


            //Total PCU and Blocks
            int FinalBlocksCount = 0;
            int FinalBlocksPCU   = 0;


            Dictionary <string, int> BlockPairNames    = new Dictionary <string, int>();
            Dictionary <string, int> BlockSubTypeNames = new Dictionary <string, int>();


            //Go ahead and check if the block limits is enabled server side! If it isnt... continue!
            if (!Config.EnableBlackListBlocks)
            {
                return(true);
            }


            else
            {
                //If we are using built in server block limits..
                if (Config.SBlockLimits)
                {
                    //& the server blocklimits is not enabled... Return true
                    if (MySession.Static.BlockLimitsEnabled == MyBlockLimitsEnabledEnum.NONE)
                    {
                        return(true);
                    }


                    //Cycle each grid in the ship blueprints

                    foreach (var CubeGrid in shipblueprints)
                    {
                        //Main.Debug("CubeBlocks count: " + CubeGrid.GetType());
                        if (BiggestGrid < CubeGrid.CubeBlocks.Count())
                        {
                            BiggestGrid = CubeGrid.CubeBlocks.Count();
                        }
                        blocksToBuild = blocksToBuild + CubeGrid.CubeBlocks.Count();

                        foreach (MyObjectBuilder_CubeBlock block in CubeGrid.CubeBlocks)
                        {
                            MyDefinitionId defId = new MyDefinitionId(block.TypeId, block.SubtypeId);

                            if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(defId, out MyCubeBlockDefinition myCubeBlockDefinition))
                            {
                                //Check for BlockPair or SubType?
                                string BlockName = "";
                                if (Config.SBlockLimits)
                                {
                                    //Server Block Limits
                                    BlockName = myCubeBlockDefinition.BlockPairName;
                                }
                                else
                                {
                                    //Custom Block SubType Limits
                                    BlockName = myCubeBlockDefinition.Id.SubtypeName;
                                }

                                long blockowner2 = 0L;
                                blockowner2 = block.BuiltBy;

                                //If the player dictionary already has a Key, we need to retrieve it
                                if (BlocksAndOwnerForLimits.ContainsKey(blockowner2))
                                {
                                    //if the dictionary already contains the same block type
                                    Dictionary <string, int> dictforuser = BlocksAndOwnerForLimits[blockowner2];
                                    if (dictforuser.ContainsKey(BlockName))
                                    {
                                        dictforuser[BlockName]++;
                                    }
                                    else
                                    {
                                        dictforuser.Add(BlockName, 1);
                                    }
                                    BlocksAndOwnerForLimits[blockowner2] = dictforuser;
                                }
                                else
                                {
                                    BlocksAndOwnerForLimits.Add(blockowner2, new Dictionary <string, int>
                                    {
                                        {
                                            BlockName,
                                            1
                                        }
                                    });
                                }

                                FinalBlocksPCU += myCubeBlockDefinition.PCU;


                                //if()
                            }
                        }

                        FinalBlocksCount += CubeGrid.CubeBlocks.Count;
                    }



                    if (MySession.Static.MaxGridSize != 0 && BiggestGrid > MySession.Static.MaxGridSize)
                    {
                        Chat.Respond("Biggest grid is over Max grid size! ");
                        return(false);
                    }

                    //Need too loop player identities in dictionary. Do this via seperate function
                    if (PlayerIdentityLoop(BlocksAndOwnerForLimits, FinalBlocksCount) == true)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    //BlockLimiter
                    if (!PluginDependencies.BlockLimiterInstalled)
                    {
                        //BlockLimiter is null!
                        Chat.Respond("Blocklimiter Plugin not installed or Loaded!");
                        Log.Warn("BLimiter plugin not installed or loaded! May require a server restart!");
                        return(false);
                    }


                    List <MyObjectBuilder_CubeGrid> grids = new List <MyObjectBuilder_CubeGrid>();

                    foreach (var CubeGrid in shipblueprints)
                    {
                        grids.Add(CubeGrid);
                    }



                    bool ValueReturn = PluginDependencies.CheckGridLimits(grids, Identity.IdentityId);

                    //Convert to value return type
                    if (!ValueReturn)
                    {
                        //Main.Debug("Cannont load grid in due to BlockLimiter Configs!");
                        return(true);
                    }
                    else
                    {
                        Chat.Respond("Grid would be over Server-Blocklimiter limits!");
                        return(false);
                    }
                }
            }
        }
Пример #10
0
 public void PluginDispose()
 {
     Controller?.Close();
     AutoHangar.Dispose();
     PluginDependencies.Dispose();
 }