private static void StaticOnClientJoined(ulong obj) { if (obj == 0) { return; } if (BlockLimiterConfig.Instance.PlayerTimes.Any(x => x.Player == obj) == false) { Instance.Log.Warn($"{obj} logged to player time {DateTime.Now}"); var playerTime = new PlayerTime { Player = obj, Time = DateTime.Now }; BlockLimiterConfig.Instance.PlayerTimes.Add(playerTime); } if (!BlockLimiterConfig.Instance.EnableLimits) { return; } var identityId = Utilities.GetPlayerIdFromSteamId(obj); if (identityId == 0) { return; } var playerFaction = MySession.Static.Factions.GetPlayerFaction(identityId); UpdateLimits.PlayerLimit(identityId); if (playerFaction != null) { UpdateLimits.PlayerLimit(playerFaction.FactionId); } }
private void FactionsOnFactionCreated(long id) { if (!BlockLimiterConfig.Instance.EnableLimits) { return; } UpdateLimits.FactionLimit(id); }
private static void StaticOnClientJoined(ulong obj, string playerName) { if (obj == 0) { return; } if (!BlockLimiterConfig.Instance.EnableLimits) { return; } var identityId = Utilities.GetPlayerIdFromSteamId(obj); if (identityId == 0) { return; } var playerFaction = MySession.Static.Factions.GetPlayerFaction(identityId); UpdateLimits.PlayerLimit(identityId); if (playerFaction != null) { UpdateLimits.PlayerLimit(playerFaction.FactionId); } }
public static void ResetLimits(bool updateGrids = true, bool updatePlayers = true, bool updateFactions = true) { if (!BlockLimiterConfig.Instance.EnableLimits) { foreach (var limit in BlockLimiterConfig.Instance.AllLimits) { limit.FoundEntities.Clear(); } return; } if (updateGrids) { var grids = new HashSet <MyCubeGrid>(); GridCache.GetGrids(grids); Task.Run(() => { Parallel.ForEach(grids, grid => { if (grid == null) { return; } UpdateLimits.GridLimit(grid); }); }); } if (updatePlayers) { var players = MySession.Static.Players.GetAllPlayers(); if (players.Count > 0) { Task.Run(() => { Parallel.ForEach(players, player => { if (player.SteamId == 0) { return; } var identity = Utilities.GetPlayerIdFromSteamId(player.SteamId); if (identity == 0) { return; } UpdateLimits.PlayerLimit(identity); }); }); } } if (updateFactions) { Task.Run(() => { Parallel.ForEach(MySession.Static.Factions, factionInfo => { var(id, faction) = factionInfo; if (faction.IsEveryoneNpc() || id == 0) { return; } UpdateLimits.FactionLimit(id); }); }); } }
/// <summary> /// Updates limits on grid split /// </summary> /// <param name="originalGrid"></param> private static void OnCreateSplit(ref MyCubeGrid from, ref MyCubeGrid to) { if (!BlockLimiterConfig.Instance.EnableLimits) { return; } var toBlocks = new HashSet <MySlimBlock>(to.CubeBlocks); if (toBlocks.Count == 0) { Log.Error("Not updated breakage"); return; } foreach (var block in toBlocks) { if (block.BuiltBy == block.OwnerId) { Block.DecreaseCount(block.BlockDefinition, block.BuiltBy, 1, from.EntityId); } else { Block.DecreaseCount(block.BlockDefinition, block.BuiltBy, 1, from.EntityId); Block.DecreaseCount(block.BlockDefinition, block.OwnerId); } } var grid = from; if (grid == null) { return; } var removeSmallestGrid = false; var owners = GridCache.GetOwners(from); if (owners == null || owners.Count == 0) { return; } foreach (var owner in owners) { if (!Grid.CountViolation(grid, owner)) { continue; } removeSmallestGrid = true; break; } if (!removeSmallestGrid) { return; } var grid1 = from; var grid2 = to; BlockLimiter.Instance.Torch.InvokeAsync(() => { Thread.Sleep(100); if (grid1.BlocksCount > grid2.BlocksCount) { grid2.SendGridCloseRequest(); UpdateLimits.GridLimit(grid1); } else { grid1.SendGridCloseRequest(); UpdateLimits.GridLimit(grid2); } }); }