Ejemplo n.º 1
0
        public override void Initialize(ModGameAPI dediAPI)
        {
            GameAPI  = dediAPI;
            LogLevel = EmpyrionNetAPIDefinitions.LogLevel.Debug;

            PlayerManager = Program.GetManager <PlayerManager>();

            TaskTools.Intervall(2000, () => SysteminfoHub?.Clients.All.SendAsync("UPC", JsonConvert.SerializeObject(new {
                o    = CurrentSysteminfo.online,
                ap   = CurrentSysteminfo.activePlayers,
                apf  = CurrentSysteminfo.activePlayfields,
                c    = CurrentSysteminfo.cpuTotalLoad,
                r    = CurrentSysteminfo.ramAvailableMB,
                tpf  = CurrentSysteminfo.totalPlayfieldserver,
                tpfm = CurrentSysteminfo.totalPlayfieldserverRamMB,
            })).Wait(1000));
            TaskTools.Intervall(30000, () => SysteminfoHub?.Clients.All.SendAsync("Update", JsonConvert.SerializeObject(CurrentSysteminfo)).Wait(1000));
            TaskTools.Intervall(5000, UpdateEmpyrionInfos);
            TaskTools.Intervall(5000, UpdateComputerInfos);
            TaskTools.Intervall(2000, UpdatePerformanceInfos);

            CpuTotalLoad = new PerformanceCounter
            {
                CategoryName = "Processor",
                CounterName  = "% Processor Time",
                InstanceName = "_Total"
            };

            RamAvailable = new PerformanceCounter("Memory", "Available MBytes");
        }
Ejemplo n.º 2
0
        public override void Initialize(ModGameAPI dediAPI)
        {
            GameAPI  = dediAPI;
            LogLevel = EmpyrionNetAPIDefinitions.LogLevel.Debug;

            TaskTools.Intervall(60, CheckTimetable);
        }
Ejemplo n.º 3
0
        public override void Initialize(ModGameAPI dediAPI)
        {
            GameAPI = dediAPI;

            try
            {
                Log($"**EmpyrionGalaxyNavigator loaded: {string.Join(" ", Environment.GetCommandLineArgs())}", LogLevel.Message);

                LoadConfiguration();
                LogLevel = Configuration.Current.LogLevel;
                ChatCommandManager.CommandPrefix = Configuration.Current.ChatCommandPrefix;

                GalaxyMap = new GalaxyMap {
                    GalaxyAutoUpdateMinutes = Configuration.Current.GalaxyAutoUpdateMinutes
                };
                GalaxyMap.ReadDbData(Path.Combine(EmpyrionConfiguration.SaveGamePath, "global.db"));

                ChatCommands.Add(new ChatCommand(@"nav help", (I, A) => DisplayHelp(I.playerId), "display help"));
                ChatCommands.Add(new ChatCommand(@"nav stop", (I, A) => StopNavigation(I.playerId), "stops navigation"));
                ChatCommands.Add(new ChatCommand(@"nav updategalaxy", (I, A) => UpdateGalayMap(I.playerId), "force update the galaxy db"));
                ChatCommands.Add(new ChatCommand(@"nav setwarp (?<LY>.*)", (I, A) => SetWarpDistance(I.playerId, A), "set the warp distance for navigation to (LY)"));
                ChatCommands.Add(new ChatCommand(@"nav (?<target>.*)", (I, A) => StartNavigation(I.playerId, A), "start a navigation to (target)"));

                Event_Player_ChangedPlayfield += Navigator_Event_Player_ChangedPlayfield;

                TaskTools.Intervall(Configuration.Current.MessageLoopMS, () => { try { CheckPlayerNavMessages().Wait(); } catch { } });
            }
            catch (Exception Error)
            {
                Log($"**EmpyrionGalaxyNavigator Error: {Error} {string.Join(" ", Environment.GetCommandLineArgs())}", LogLevel.Error);
            }
        }
Ejemplo n.º 4
0
        public bool ModsStarted()
        {
            if (!CheckModHostStatusStarted)
            {
                CheckModHostStatusStarted = true;
                TaskTools.Intervall(1000, CheckModHostStatus);
            }

            Process EGSProcess = null;

            try {
                if (SysteminfoManager.Value.ProcessInformation == null)
                {
                    return(false);
                }
                EGSProcess = Process.GetProcessById(SysteminfoManager.Value.ProcessInformation.Id);

                var AllChilds = EGSProcess?.GetChildProcesses().ToList();

                // Fallback falls die Processinfos nicht existieren
                if (AllChilds == null || AllChilds.Count == 0)
                {
                    return(!File.Exists(StopFileName));
                }

                var ESGChildProcesses = AllChilds.Where(P => P.ProcessName.StartsWith("EmpyrionModHost", StringComparison.InvariantCultureIgnoreCase)).ToArray();

                return(ESGChildProcesses?.FirstOrDefault() != null);
            }
            catch
            {
                // Fallback falls die Processinfos nicht existieren
                return(!File.Exists(StopFileName));
            }
        }
Ejemplo n.º 5
0
        public override void Initialize(ModGameAPI dediAPI)
        {
            GameAPI = dediAPI;

            API_Exit += () => { try { System.IO.File.Delete(CurrentEBPFile); } catch { } };

            TaskTools.Intervall(Math.Max(1, Program.AppSettings.GlobalStructureUpdateInSeconds) * 1000, () => GlobalStructureList());
        }
Ejemplo n.º 6
0
        public override void Initialize(ModGameAPI dediAPI)
        {
            GameAPI  = dediAPI;
            LogLevel = EmpyrionNetAPIDefinitions.LogLevel.Debug;

            TaskTools.Intervall(Math.Max(1, Program.AppSettings.StructureDataUpdateCheckInSeconds) * 1000, () => BackupStructureData());

            Event_Playfield_Loaded   += P => ActivePlayfields.TryAdd(P.playfield, P.playfield);
            Event_Playfield_Unloaded += P => ActivePlayfields.TryRemove(P.playfield, out _);
        }
        private void StartScriptIntervall(int intervall, Action action, string name)
        {
            if (intervall <= 0)
            {
                return;
            }

            var exec = TaskTools.Intervall(intervall, action, name);

            StopScriptsEvent += (S, E) => exec.Set();
        }
Ejemplo n.º 8
0
        public override void Initialize(ModGameAPI dediAPI)
        {
            DediAPI  = dediAPI;
            LogLevel = LogLevel.Message;

            Log($"**EmpyrionForbiddenPlayfields: loaded");

            LoadConfiuration();
            LogLevel = Configuration.Current.LogLevel;

            TaskTools.Intervall(30000, () => UpdateFactionData().Wait());
            TaskTools.Intervall(1000, () => TestNextPlayer());
        }
Ejemplo n.º 9
0
        public PlayerManager(
            ILogger <PlayerManager> aLogger,
            IRoleHubContext <PlayerHub> aPlayerHub,
            IProvider <IUserService> aUserService)
        {
            Logger            = aLogger;
            PlayerHub         = aPlayerHub;
            UserService       = aUserService;
            SysteminfoManager = new Lazy <SysteminfoManager>(() => Program.GetManager <SysteminfoManager>());
            ChatManager       = new Lazy <ChatManager>(() => Program.GetManager <ChatManager>());
            UserManager       = new Lazy <UserManager>(() => Program.GetManager <UserManager>());

            TaskTools.Intervall(10000, SendPlayerUpdates);
        }
        public override void Initialize(ModGameAPI dediAPI)
        {
            DediAPI  = dediAPI;
            LogLevel = LogLevel.Message;

            Log($"**EmpyrionBackpackExtender: loaded");

            LoadConfiuration();
            LogLevel = Configuration.Current.LogLevel;
            ChatCommandManager.CommandPrefix = Configuration.Current.ChatCommandPrefix;

            TaskTools.Intervall(60000, () => CurrentFactions = Request_Get_Factions(0.ToId()).Result);

            AddCommandsFor(Configuration.Current.PersonalBackpack, "personal", P => P.steamId);
            AddCommandsFor(Configuration.Current.FactionBackpack, "faction", P => P.factionId.ToString());
            AddCommandsFor(Configuration.Current.OriginBackpack, "origin", P => P.origin.ToString());
            AddCommandsFor(Configuration.Current.GlobalBackpack, "global", P => "global");
        }
Ejemplo n.º 11
0
        public void EGSStop(int aWaitMinutes)
        {
            try
            {
                Logger.Log(Microsoft.Extensions.Logging.LogLevel.Information, "EGSStop");
                EGSRunState(true);
                Program.Host.ExposeShutdownHost();

                var stoptime = DateTime.Now.AddMinutes(aWaitMinutes);
                var exit     = aWaitMinutes == 0 ? null : TaskTools.Intervall(10000, () => {
                    Request_InGameMessage_AllPlayers(Timeouts.NoResponse, $"Server shutdown in {(stoptime - DateTime.Now).ToString(@"mm\:ss")}".ToIdMsgPrio(0, MessagePriorityType.Alarm));
                });

                try
                {
                    Process EGSProcess = null;
                    try { EGSProcess = ProcessInformation == null ? null : Process.GetProcessById(ProcessInformation.Id); } catch { }

                    Logger.Log(Microsoft.Extensions.Logging.LogLevel.Information, "EGSStop: saveandexit:" + aWaitMinutes);
                    Request_ConsoleCommand(new PString("saveandexit " + aWaitMinutes)).Wait(10000);
                    Thread.Sleep(10000);
                    if (EGSProcess != null && !EGSProcess.HasExited)
                    {
                        Logger.Log(Microsoft.Extensions.Logging.LogLevel.Information, "EGSStop: Wait:" + aWaitMinutes);
                        EGSProcess?.WaitForExit((aWaitMinutes + 1) * 60000);
                    }
                    exit?.Set();

                    CurrentSysteminfo.online = SetState(CurrentSysteminfo.online, "o", false);
                }
                catch (Exception Error)
                {
                    exit?.Set();
                    Logger.LogError(Error, "EGSStop: WaitForExit");
                    Thread.Sleep(10000);
                }

                UpdateClient();
            }
            catch (Exception Error)
            {
                Logger.LogError(Error, "EGSStop");
            }
        }
Ejemplo n.º 12
0
        private void UpdateOnlinePlayers()
        {
            TaskTools.Intervall(10000, () =>
            {
                var onlinePlayers = Request_Player_List().Result;
                if (onlinePlayers == null)
                {
                    return;
                }

                if (onlinePlayers.list == null)
                {
                    UpdatePlayer(DB => DB.Players.Where(P => P.Online), PlayerDisconnect);
                }
                else
                {
                    UpdatePlayer(DB => DB.Players.Where(P => onlinePlayers.list.Contains(P.EntityId) && !P.Online), PlayerConnect);
                    UpdatePlayer(DB => DB.Players.Where(P => !onlinePlayers.list.Contains(P.EntityId) && P.Online), PlayerDisconnect);
                }

                onlinePlayers.list?.AsParallel().ForEach(I => Request_Player_Info(new Id(I)));
            });
        }
Ejemplo n.º 13
0
        public override void Initialize(ModGameAPI dediAPI)
        {
            DediAPI = dediAPI;

            try
            {
                Log($"**EmpyrionPoiRestore loaded: {string.Join(" ", Environment.GetCommandLineArgs())}", LogLevel.Message);

                LoadConfiguration();
                LogLevel = Configuration.Current.LogLevel;
                ChatCommandManager.CommandPrefix = Configuration.Current.ChatCommandPrefix;

                ChatCommands.Add(new ChatCommand(@"poipos help", (I, A) => DisplayHelp(I.playerId, null), "display help"));
                ChatCommands.Add(new ChatCommand(@"poipos add (?<Name>.+)", (I, A) => StorePoiPosAndRot(I.playerId, A), "store POI pos and rot", PermissionType.Admin));

                TaskTools.Intervall(Configuration.Current.CheckPoiPositionsEveryNSeconds * 1000, async() => await CheckPlayfields());
                Event_Playfield_Loaded += P => TaskTools.Delay(Configuration.Current.CheckPoiPositionsNSecondsAfterPlayfieldLoaded, async() => await CheckPlayfields());
            }
            catch (Exception Error)
            {
                Log($"**EmpyrionPoiRestore Error: {Error} {string.Join(" ", Environment.GetCommandLineArgs())}", LogLevel.Error);
            }
        }
        public override void Initialize(ModGameAPI dediAPI)
        {
            GameAPI = dediAPI;

            TaskTools.Intervall(30000, HistoryLog);
        }
Ejemplo n.º 15
0
        private bool CheckForForbiddenPlayfield(PlayerInfo player)
        {
            if (player.permission >= (int)Configuration.Current.FreeTravelPermision)
            {
                return(true);
            }

            var checkplayfield = Configuration.Current.ForbiddenPlayfields.FirstOrDefault(P => P.Name == player.playfield);

            if (checkplayfield == null)
            {
                return(true);
            }

            var faction = FactionData?.factions?.FirstOrDefault(F => F.factionId == player.factionId);

            if (faction.HasValue &&
                checkplayfield.FactionInfo != null &&
                checkplayfield.FactionInfo.Any(F => string.Compare(F.Abbr, faction.Value.abbrev?.Trim(), StringComparison.InvariantCultureIgnoreCase) == 0))
            {
                return(true);
            }

            var checkplayer = checkplayfield.PlayerInfo?.FirstOrDefault(P => P.SteamId == player.steamId);

            if (checkplayer != null)
            {
                if (string.IsNullOrEmpty(checkplayer.Name))
                {
                    checkplayer.Name = player.playerName;
                    Configuration.Save();
                }
                return(true);
            }

            checkplayer = checkplayfield.PlayerInfo?.FirstOrDefault(P => string.Compare(P.Name, player.playerName.Trim(), StringComparison.InvariantCultureIgnoreCase) == 0);
            if (checkplayer != null)
            {
                if (string.IsNullOrEmpty(checkplayer.SteamId))
                {
                    checkplayer.SteamId = player.steamId;
                    Configuration.Save();
                }
                return(true);
            }

            if (string.IsNullOrEmpty(checkplayfield.WarpBackTo))
            {
                if (!PlayerAlerts.TryGetValue(player.steamId, out _))
                {
                    PlayerAlerts.TryAdd(player.steamId,
                                        TaskTools.Intervall(10000, () =>
                    {
                        Request_InGameMessage_SinglePlayer(Timeouts.NoResponse,
                                                           (string.IsNullOrEmpty(checkplayfield.CustomMessage) ? $"Please leave this playfield '{player.playfield}', it is reserved!" : checkplayfield.CustomMessage)
                                                           .ToIdMsgPrio(player.entityId,
                                                                        checkplayfield.MessageType ?? Configuration.Current.MessageType,
                                                                        checkplayfield.RepeatSeconds ?? Configuration.Current.RepeatSeconds));
                        CheckPlayerLocation(player.entityId).Wait();
                    })
                                        );
                }

                return(false);
            }

            return(false);
        }