Beispiel #1
0
        public void ResetPlanet(string planetName)
        {
            var maps = new List <MyPlanet>(2);

            foreach (MyPlanet map in MyEntities.GetEntities().OfType <MyPlanet>())
            {
                if (map.StorageName.Contains(planetName, StringComparison.CurrentCultureIgnoreCase))
                {
                    maps.Add(map);
                }
            }

            switch (maps.Count)
            {
            case 0:
                Context.Respond($"Couldn't find planet with name {planetName}");
                return;

            case 1:
                var map = maps[0];
                map.Storage.Reset(MyStorageDataTypeFlags.All);
                ModCommunication.SendMessageToClients(new VoxelResetMessage(new long[] { map.EntityId }));
                Context.Respond($"Reset planet {map.Name}");
                return;

            default:
                Context.Respond($"Found {maps.Count} planets matching '{planetName}'. Please select from list:");
                Context.Respond(string.Join("\r\n", maps.Select(m => m.StorageName)));
                return;
            }
        }
Beispiel #2
0
        public void ResetAll()
        {
            var voxelMaps = MyEntities.GetEntities().OfType <MyVoxelBase>();

            var resetIds = new List <long>();

            //Parallel.ForEach(voxelMaps, map =>
            foreach (var map in voxelMaps)
            {
                try
                {
                    if (map.StorageName == null || map.Storage.DataProvider == null)
                    {
                        return;
                    }

                    map.Storage.Reset(MyStorageDataTypeFlags.All);
                    lock (resetIds)
                        resetIds.Add(map.EntityId);
                }
                catch (Exception e)
                {
                    _log.Error($"{e.Message}\n{e.StackTrace}");
                }
            }                            //, blocking:true);
            ModCommunication.SendMessageToClients(new VoxelResetMessage(resetIds.ToArray()));

            Context.Respond($"Reset {resetIds.Count} voxel maps.");
        }
Beispiel #3
0
        public void ResetPlanets()
        {
            var voxelMaps = MyEntities.GetEntities().OfType <MyPlanet>();

            var resetIds = new List <long>();

            foreach (var map in voxelMaps)
            {
                try
                {
                    if (map.StorageName == null || map.Storage.DataProvider == null)
                    {
                        continue;
                    }

                    map.Storage.Reset(MyStorageDataTypeFlags.All);
                    resetIds.Add(map.EntityId);
                }
                catch (Exception e)
                {
                    _log.Error($"{e.Message}\n{e.StackTrace}");
                }
            }

            ModCommunication.SendMessageToClients(new VoxelResetMessage(resetIds.ToArray()));

            Context.Respond($"Reset {resetIds.Count} voxel maps.");
        }
Beispiel #4
0
        public static bool PrefixPhysics()
        {
            if (!HkBaseSystem.IsOutOfMemory)
            {
                return(true);
            }

            if (NotifiedFailure)
            {
                return(false);
            }

            NotifiedFailure = true;
            ModCommunication.SendMessageToClients(new NotificationMessage("Havok has run out of memory. Server will restart in 30 seconds!", 60000, MyFontEnum.Red));
            //save the session NOW before anything moves due to weird physics.
            MySession.Static.Save();
            //pause the game, for funsies
            MySandboxGame.IsPaused = true;

            //nasty hack
            Task.Run(() =>
            {
                Thread.Sleep(TimeSpan.FromSeconds(30));
                TorchBase.Instance.Restart();
            });

            return(false);
        }
Beispiel #5
0
        public void CleanupAsteroids(bool deleteStorage = false)
        {
            var voxelMaps = MyEntities.GetEntities().OfType <MyVoxelMap>();

            var resetIds = new List <long>();

            //Parallel.ForEach(voxelMaps, map =>
            foreach (var map in voxelMaps)
            {
                try
                {
                    if (map.StorageName == null || map.Storage.DataProvider == null)
                    {
                        continue;
                    }

                    var s            = map.PositionComp.WorldVolume;
                    var nearEntities = new List <MyEntity>();

                    MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref s, nearEntities);

                    if (nearEntities.Any(e => e is MyCubeGrid || e is MyCharacter))
                    {
                        continue;
                    }

                    long id = map.EntityId;

                    if (deleteStorage)
                    {
                        map.Close();
                    }
                    else
                    {
                        map.Storage.Reset(MyStorageDataTypeFlags.All);
                    }

                    if (!deleteStorage)
                    {
                        lock (resetIds)
                            resetIds.Add(id);
                    }
                }
                catch (Exception e)
                {
                    _log.Error($"{e.Message}\n{e.StackTrace}");
                }
            }                            //);

            ModCommunication.SendMessageToClients(new VoxelResetMessage(resetIds.ToArray()));

            Context.Respond($"Reset {resetIds.Count} voxel maps.");
        }
Beispiel #6
0
        public void CleanupAsteroidsDistant(double distance = 1000, bool deleteStorage = false)
        {
            var voxelMaps = MyEntities.GetEntities().OfType <MyVoxelMap>();

            var resetIds = new List <long>();
            int count    = 0;

            foreach (var map in voxelMaps)
            {
                try
                {
                    if (map.StorageName == null || map.Storage.DataProvider == null)
                    {
                        continue;
                    }

                    var s            = new BoundingSphereD(map.PositionComp.GetPosition(), distance);
                    var nearEntities = new List <MyEntity>();

                    MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref s, nearEntities);

                    if (nearEntities.Any(e => e is MyCubeGrid || e is MyCharacter))
                    {
                        continue;
                    }

                    count++;

                    long id = map.EntityId;

                    if (deleteStorage)
                    {
                        using (PinDelete())
                            map.Close();
                    }
                    else
                    {
                        map.Storage.Reset(MyStorageDataTypeFlags.All);
                        resetIds.Add(id);
                    }
                }
                catch (Exception e)
                {
                    _log.Error($"{e.Message}\n{e.StackTrace}");
                }
            }

            ModCommunication.SendMessageToClients(new VoxelResetMessage(resetIds.ToArray()));

            Context.Respond($"Reset {count} voxel maps.");
        }
Beispiel #7
0
        public void ResetAll(bool deleteStorage = false)
        {
            var voxelMaps = MyEntities.GetEntities().OfType <MyVoxelBase>();

            var resetIds = new List <long>();
            int count    = 0;

            foreach (var map in voxelMaps)
            {
                try
                {
                    if (map.StorageName == null || map.Storage.DataProvider == null)
                    {
                        continue;
                    }

                    count++;

                    long id = map.EntityId;

                    if (deleteStorage && map is MyVoxelMap)
                    {
                        using (PinDelete())
                            map.Close();
                    }
                    else
                    {
                        map.Storage.Reset(MyStorageDataTypeFlags.All);
                        resetIds.Add(id);
                    }
                }
                catch (Exception e)
                {
                    _log.Error($"{e.Message}\n{e.StackTrace}");
                }
            }

            ModCommunication.SendMessageToClients(new VoxelResetMessage(resetIds.ToArray()));

            Context.Respond($"Reset {count} voxel maps.");
        }
Beispiel #8
0
 public void Notify(string message, int disappearTimeMs = 2000, string font = "White")
 {
     ModCommunication.SendMessageToClients(new NotificationMessage(message, disappearTimeMs, font));
 }
Beispiel #9
0
        public void Vote(string name)
        {
            if (Context.Player == null)
            {
                return;
            }

            if (VoteStatus == Status.voteInProgress)
            {
                Context.Respond(
                    $"vote for {voteInProgress} is currently active. Use !yes to vote and !no to retract vote");
                return;
            }

            _command = EssentialsPlugin.Instance.Config.AutoCommands.FirstOrDefault(c => c.Name.Equals(name));

            if (_command == null || _command.CommandTrigger != Trigger.Vote)
            {
                Context.Respond($"Couldn't find any votable command with the name {name}");
                _command = null;
                return;
            }


            // Rexxar's spam blocker. Timing is random as f**k and unique to each player.
            var steamid = Context.Player.SteamUserId;

            if (_voteCooldown.TryGetValue(steamid, out var activeCooldown))
            {
                var difference = activeCooldown - DateTime.Now;
                if (difference.TotalSeconds > 0)
                {
                    Context.Respond(
                        $"Cooldown active. You can use this command again in {difference.Minutes:N0} minutes : {difference.Seconds:N0} seconds");
                    return;
                }

                _voteCooldown[steamid] = DateTime.Now.AddMinutes(_cooldown);
            }

            else
            {
                _voteCooldown.Add(steamid, DateTime.Now.AddMinutes(_cooldown));
            }

            var _voteDuration = TimeSpan.Parse(_command.Interval);

            // voting status
            voteInProgress = name;
            VoteStatus     = Status.voteInProgress;
            VoteYes();
            var sb = new StringBuilder();

            sb.AppendLine($"Voting started for {name} by {Context.Player.DisplayName}.");
            sb.AppendLine("Use !yes to vote and !no to retract your vote");
            ModCommunication.SendMessageToClients(new NotificationMessage(sb.ToString(), 15000, "Blue"));
            //vote countdown
            Task.Run(() =>
            {
                var countdown = VoteCountdown(_voteDuration).GetEnumerator();
                while (countdown.MoveNext())
                {
                    Thread.Sleep(1000);
                }
            });

            lastVoteName = voteInProgress;
        }
Beispiel #10
0
        public async Task PlayerTransfer(string type, ulong steamid)
        {
            string ip             = "";
            string name           = "";
            string port           = "";
            string existanceCheck = "";

            int i = 0;
            IEnumerable <string> channelIds = Plugin.Config.Servers;

            foreach (string chId in channelIds)
            {
                ip   = chId.Split(':')[1];
                name = chId.Split(':')[0];
                port = chId.Split(':')[2];
                i++;
            }

            if (i == 1)
            {
                string target = ip + ":" + port;
                ip += ":" + port;
                string slotinfo = await Plugin.CheckSlotsAsync(target);

                existanceCheck = slotinfo.Split(';').Last();
                bool paired = await Plugin.CheckKeyAsync(target);

                if (ip == null || name == null || port == null)
                {
                    utils.Respond("Invalid Configuration!", "Server", steamid);
                    return;
                }

                if (target.Length < 1)
                {
                    utils.Respond("Unknown Server. Please use '!switch list' to see a list of valid servers!", "Server", steamid);
                    return;
                }

                if (existanceCheck != "1")
                {
                    utils.Respond("Cannot communicate with target, please make sure SwitchMe is installed there!", "Server", steamid);
                    return;
                }

                if (paired != true)
                {
                    utils.Respond("Unauthorised Switch! Please make sure the servers have the same Bind Key!", "Server", steamid);
                    return;
                }

                ///   Slot checking
                Log.Warn("Checking " + target);
                int    currentRemotePlayers = int.Parse(slotinfo.Substring(0, slotinfo.IndexOf(":")));
                string max = slotinfo.Substring(slotinfo.IndexOf(':') + 1, slotinfo.IndexOf(';') - slotinfo.IndexOf(':') - 1);
                Log.Warn("MAX: " + max);
                int currentLocalPlayers = int.Parse(MySession.Static.Players.GetOnlinePlayers().Count.ToString());
                if (type == "single")
                {
                    currentLocalPlayers = 1;
                }
                int maxi     = int.Parse(max);
                int maxcheck = currentLocalPlayers + currentRemotePlayers;
                utils.Respond("Slot Checking...", "Server", steamid);
                Log.Warn(maxcheck + " Player Count Prediction|Player Count Threshold " + max);
                if (maxcheck > maxi && Context.Player.PromoteLevel != MyPromoteLevel.Admin)
                {
                    return;
                }


                /// Connection phase
                try {
                    utils.Respond("Connecting client(s) to " + Context.RawArgs + " @ " + ip, "Server", steamid);
                    Log.Warn("Connected clients to " + Context.RawArgs + " @ " + ip);
                    if (type == "single")
                    {
                        ModCommunication.SendMessageTo(new JoinServerMessage(ip), steamid);
                        return;
                    }
                    if (type == "all")
                    {
                        ModCommunication.SendMessageToClients(new JoinServerMessage(ip));
                        return;
                    }
                }
                catch {
                    Context.Respond("Failure");
                }
                /// Move onto Specific connection
            }

            else
            {
                channelIds = Plugin.Config.Servers.Where(c => c.Split(':')[0].Equals(Context.RawArgs));

                foreach (string chId in channelIds)
                {
                    ip   = chId.Split(':')[1];
                    name = chId.Split(':')[0];
                    port = chId.Split(':')[2];
                }

                string target = ip + ":" + port;
                ip += ":" + port;
                string slotinfo = await Plugin.CheckSlotsAsync(target);

                existanceCheck = slotinfo.Split(';').Last();
                bool paired = await Plugin.CheckKeyAsync(target);

                if (ip == null || name == null || port == null)
                {
                    Context.Respond("Invalid Configuration!");
                    return;
                }

                if (target.Length < 1)
                {
                    Context.Respond("Unknown Server. Please use '!switch list' to see a list of valid servers!");
                    return;
                }

                if (existanceCheck != "1")
                {
                    Context.Respond("Cannot communicate with target, please make sure SwitchMe is installed there!");
                    return;
                }

                if (paired != true)
                {
                    Context.Respond("Unauthorised Switch! Please make sure the servers have the same Bind Key!");
                    return;
                }

                ///     Slot checking
                Log.Warn("Checking " + target);
                int    currentRemotePlayers = int.Parse(slotinfo.Substring(0, slotinfo.IndexOf(":")));
                string max = slotinfo.Substring(slotinfo.IndexOf(':') + 1, slotinfo.IndexOf(';') - slotinfo.IndexOf(':') - 1);
                Log.Warn("MAX: " + max);
                int currentLocalPlayers = int.Parse(MySession.Static.Players.GetOnlinePlayers().Count.ToString());
                int maxi     = int.Parse(max);
                int maxcheck = currentLocalPlayers + currentRemotePlayers;
                Context.Respond("Slot Checking...");
                Log.Warn(maxcheck + " Player Count Prediction|Player Count Threshold " + max);
                if (maxcheck > maxi)
                {
                    Context.Respond("Cannot switch, not enough slots available");
                    return;
                }
                Context.Respond("Slot checking passed!");

                ///     Connection phase
                try {
                    if (type == "single")
                    {
                        ModCommunication.SendMessageTo(new JoinServerMessage(ip), Context.Player.SteamUserId);
                        return;
                    }
                    ModCommunication.SendMessageToClients(new JoinServerMessage(ip));
                    return;
                }
                catch {
                    Context.Respond("Failure");
                }
            }
        }
 private static void SendNotification(string message, int disappearTimeMs = 10000)
 {
     ModCommunication.SendMessageToClients(new NotificationMessage(message, disappearTimeMs, "Red"));
 }