private void SendNotifications() { if ((bool)Config["AutomaticNotificationsEnabled"]) { timer.Repeat(Convert.ToSingle(Config["NotificationIntervalInMinutes"]) * 60, 0, () => { foreach (var player in BasePlayer.activePlayerList) { BuildingPrivlidge priv = player.GetBuildingPrivilege(); if (!priv) { return; } if (!priv.IsAuthed(player) || !player.IsAdmin) { return; } float minutesLeft = priv.GetProtectedMinutes(); if (minutesLeft < Convert.ToSingle(Config["MinutesLeftNeededToSendNotification"]) && minutesLeft > 0f) { PrintToChat(player, String.Format(lang.GetMessage("PrimaryDecayNotification", this, player.UserIDString), minutesLeft)); } else if (minutesLeft == 0f) { PrintToChat(player, lang.GetMessage("FinalDecayNotification", this, player.UserIDString)); } } }); } }
// checks if the player is authorized to damage the entity bool CheckAuthDamage(BaseCombatEntity entity, BasePlayer player) { // check if the player is the owner of the entity if (player.userID == entity.OwnerID) { return(true); // player is the owner, allow damage } // assume no authorization by default bool authed = false; // check for cupboards which overlap the entity var hit = Physics.OverlapBox(entity.transform.position, entity.bounds.extents / 2f, entity.transform.rotation, triggerMask); // loop through cupboards foreach (var ent in hit) { // get cupboard BuildingPrivilidge BuildingPrivlidge privs = ent.GetComponentInParent <BuildingPrivlidge>(); // check if the player is authorized on the cupboard if (privs != null) { if (!privs.IsAuthed(player)) { return(false); // return false if not authorized on any single cupboard which overlaps this entity } else { authed = true; // set authed to true to indicate player is authorized on at least one cupboard } } } return(authed); }
void TcstatusCommand(BasePlayer player, string command, string[] args) { if (!permission.UserHasPermission(player.UserIDString, "decaynotifications.use")) { PrintToChat(player, lang.GetMessage("NoPermission", this, player.UserIDString)); return; } BuildingPrivlidge priviledge = player.GetBuildingPrivilege(); if (!priviledge) { PrintToChat(player, lang.GetMessage("NoPriviledge", this, player.UserIDString)); return; } if (!priviledge.IsAuthed(player) || !player.IsAdmin) { return; } float minutesLeft = priviledge.GetProtectedMinutes(); if (minutesLeft > 0f) { PrintToChat(player, String.Format(lang.GetMessage("PrimaryDecayNotification", this, player.UserIDString), minutesLeft)); } else if (minutesLeft == 0) { PrintToChat(player, lang.GetMessage("FinalDecayNotification", this, player.UserIDString)); } return; }
private bool RemoveFromWhiteList(BuildingPrivlidge cb, BasePlayer player) { if (!cb.IsAuthed(player)) { return(false); } int i = 0; foreach (var authedPlayer in cb.authorizedPlayers) { if (authedPlayer.userid == player.userID) { cb.authorizedPlayers.RemoveAt(i); cb.SendNetworkUpdate(); if (cb.CheckEntity(player)) { player.SetInsideBuildingPrivilege(cb, false); } return(true); } i++; } return(false); }
void OpenToolCupboard(BasePlayer player, string command, string[] args) { if (!permission.UserHasPermission(player.UserIDString, "tcmanager.openinv") && !player.IsAdmin) { player.ChatMessage(Lang("NoCommandPermission", player.UserIDString)); return; } BuildingPrivlidge privilege = player.GetBuildingPrivilege(); if (!privilege) { player.ChatMessage(Lang("NoBuildingPrivilege", player.UserIDString)); return; } if (!privilege.IsAuthed(player) && !player.IsAdmin) { player.ChatMessage(Lang("NoAuthorization", player.UserIDString)); return; } player.EndLooting(); timer.Once(0.1f, delegate() { LootContainer(player, privilege); }); }
void AuthorizePlayer(BasePlayer player, string command, string[] args) { if (!permission.UserHasPermission(player.UserIDString, "tcmanager.auth") && !player.IsAdmin) { player.ChatMessage(Lang("NoCommandPermission", player.UserIDString)); return; } BuildingPrivlidge privilege = player.GetBuildingPrivilege(); if (!privilege) { player.ChatMessage(Lang("NoBuildingPrivilege", player.UserIDString)); return; } if (!privilege.IsAuthed(player)) { player.ChatMessage(Lang("NoAuthorization", player.UserIDString)); return; } if (args.Length == 0) { player.ChatMessage(Lang("AuthUsage", player.UserIDString)); return; } List <BasePlayer> playerList = FindPlayer(args[0]); if (playerList.Count == 1) { BasePlayer newPlayer = playerList[0]; privilege.authorizedPlayers.Add(new ProtoBuf.PlayerNameID() { userid = newPlayer.userID, username = newPlayer.displayName }); privilege.SendNetworkUpdateImmediate(); player.ChatMessage(Lang("AuthorizePlayer", player.UserIDString, newPlayer.displayName)); if (MasterLock) { MasterLock.Call("AddAuthorization", privilege, newPlayer, player); } } else if (playerList.Count == 0) { player.ChatMessage(Lang("PlayerNotFound", player.UserIDString, args[0].ToString())); } else { String playerNames = String.Empty; foreach (BasePlayer bPlayer in playerList) { if (!String.IsNullOrEmpty(playerNames)) { playerNames += ", "; } playerNames += bPlayer.displayName; } player.ChatMessage(Lang("MultiplePlayers", player.UserIDString, playerNames)); } }
object CanBeTargeted(BasePlayer player, BaseCombatEntity entity) { if (permission.UserHasPermission(player.UserIDString, turretsIgnore)) { return(false); } else if (permission.UserHasPermission(player.UserIDString, turretsNeverIgnore)) { return(null); } if (entity is NPCAutoTurret && _config.NPCTurretsAffected) { BuildingPrivlidge priviledge = entity.GetBuildingPrivilege(); if (priviledge != null && !priviledge.IsAuthed(player) && player.IsBuildingBlocked() && player.IsVisible(new Vector3(entity.transform.position.x, entity.transform.position.y + 0.8f, entity.transform.position.z), new Vector3(player.transform.position.x, player.transform.position.y + 1.5f, player.transform.position.z))) { return(null); } else { return(false); } } if ((entity is AutoTurret && !(entity is NPCAutoTurret) && _config.autoturretsAffected)) { AutoTurret turret = entity as AutoTurret; BuildingPrivlidge priviledge = turret.GetBuildingPrivilege(); if (priviledge != null && !priviledge.IsAuthed(player) && player.IsBuildingBlocked() && player.IsVisible(new Vector3(turret.transform.position.x, turret.transform.position.y + 0.8f, turret.transform.position.z), new Vector3(player.transform.position.x, player.transform.position.y + 1.5f, player.transform.position.z))) { if (_config.autoturretsShootAuthed && turret.IsAuthed(player)) { turret.SetTarget(player); return(null); } else if (!turret.IsAuthed(player)) { return(null); } } return(false); } if ((entity is FlameTurret && _config.flameTrapsAffected) || (entity is GunTrap && _config.shotgunTrapsAffected) && !player.IsBuildingBlocked() || !player.IsVisible(entity.transform.position, player.transform.position, Mathf.Infinity)) { return(false); } return(null); }
private bool IsInPrivilege(BasePlayer player) { BuildingPrivlidge buildingPrivilege = player.GetBuildingPrivilege(player.WorldSpaceBounds()); if (buildingPrivilege == null) { return(false); } return(buildingPrivilege.IsAuthed(player)); }
private object OnHammerHit(BasePlayer player, HitInfo info) { BaseCombatEntity entity = info?.HitEntity as BaseCombatEntity; if (entity == null || entity.IsDestroyed) { return(null); } DecayEntity decay = entity as DecayEntity; if (decay != null && decay.buildingID == 0) { return(null); } if (!_storedData.RepairEnabled.ContainsKey(player.userID) && _pluginConfig.DefaultEnabled) { _storedData.RepairEnabled[player.userID] = true; } if (!_storedData.RepairEnabled[player.userID]) { return(null); } if (IsNoEscapeBlocked(player)) { Chat(player, Lang(LangKeys.NoEscape, player)); return(null); } if (_repairingPlayers.Contains(player.userID)) { Chat(player, Lang(LangKeys.RepairInProcess, player)); return(null); } BuildingPrivlidge priv = player.GetBuildingPrivilege(); if (priv == null || !priv.IsAuthed(player)) { return(null); } PlayerRepairStats stats = new PlayerRepairStats(); BuildingManager.Building building = priv.GetBuilding(); ServerMgr.Instance.StartCoroutine(DoBuildingRepair(player, building, stats)); return(true); }
bool EnsureCupboardCanBeUsedForClaim(User user, BuildingPrivlidge cupboard) { if (cupboard == null) { user.SendChatMessage(Messages.SelectingCupboardFailedInvalidTarget); return(false); } if (!cupboard.IsAuthed(user.Player)) { user.SendChatMessage(Messages.SelectingCupboardFailedNotAuthorized); return(false); } return(true); }
private bool HasPriv(BasePlayer player) { var hit = Physics.OverlapSphere(player.transform.position, 2f, triggerMask); foreach (var entity in hit) { BuildingPrivlidge privs = entity.GetComponentInParent <BuildingPrivlidge>(); if (privs != null) { if (privs.IsAuthed(player)) { return(true); } } } return(false); }
bool CheckAuthCupboard(BaseEntity entity, BasePlayer player) { BuildingPrivlidge bprev = player.GetBuildingPrivilege(new OBB(entity.transform.position, entity.transform.rotation, entity.bounds)); if (UseOnlyInCupboardRange && bprev == null) { return(true); } if (!UseOnlyInCupboardRange && bprev == null) { return(false); } if (UseCupboard && bprev.IsAuthed(player)) { return(true); } return(false); }
void ToggleMasterLock(BasePlayer player, string command, string[] args) { if (!permission.UserHasPermission(player.UserIDString, "masterlock.toggle") && !player.IsAdmin) { player.ChatMessage(Lang("NoCommandPermission", player.UserIDString)); return; } BuildingPrivlidge privilege = player.GetBuildingPrivilege(); if (!privilege) { player.ChatMessage(Lang("NoBuildingPrivilege", player.UserIDString)); return; } if (!privilege.IsAuthed(player)) { player.ChatMessage(Lang("NoAuthorization", player.UserIDString)); return; } if (data.buildings.ContainsKey(privilege.net.ID)) { if (data.buildings[privilege.net.ID]) { data.buildings[privilege.net.ID] = false; player.ChatMessage(Lang("Disabled", player.UserIDString)); } else { data.buildings[privilege.net.ID] = true; InitializeMasterLock(privilege); player.ChatMessage(Lang("Enabled", player.UserIDString)); } } else { data.buildings.Add(privilege.net.ID, true); InitializeMasterLock(privilege); player.ChatMessage(Lang("Enabled", player.UserIDString)); } SaveData(); }
private bool AddToWhiteList(BuildingPrivlidge cb, BasePlayer player) { if (cb.IsAuthed(player)) { return(false); } var protobufPlayer = new ProtoBuf.PlayerNameID(); protobufPlayer.userid = player.userID; protobufPlayer.username = player.name; cb.authorizedPlayers.Add(protobufPlayer); cb.SendNetworkUpdate(); if (cb.CheckEntity(player)) { player.SetInsideBuildingPrivilege(cb, true); } return(true); }
private string CanTeleportToPosition(BasePlayer player, Vector3 position) { List <Collider> colliders = Facepunch.Pool.GetList <Collider>(); Vis.Colliders(position, 0.1f, colliders, triggerLayer); foreach (Collider collider in colliders) { BuildingPrivlidge tc = collider.GetComponentInParent <BuildingPrivlidge>(); if (tc == null) { continue; } if (!tc.IsAuthed(player)) { Facepunch.Pool.FreeList(ref colliders); return("building blocked"); } } return(null); }
void GetTaxBracket(BasePlayer player, string command, string[] args) { if (!permission.UserHasPermission(player.UserIDString, "tcmanager.taxrate") && !player.IsAdmin) { player.ChatMessage(Lang("NoCommandPermission", player.UserIDString)); return; } BuildingPrivlidge privilege = player.GetBuildingPrivilege(); if (!privilege) { player.ChatMessage(Lang("NoBuildingPrivilege", player.UserIDString)); return; } if (!privilege.IsAuthed(player) && !player.IsAdmin) { player.ChatMessage(Lang("NoAuthorization", player.UserIDString)); return; } player.ChatMessage(Lang("TaxRate", player.UserIDString, CalculateTaxRate(privilege))); }
public override ValidationResult Validate() { ValidationResult validationResult = base.Validate(); if (validationResult != 0) { return(validationResult); } AppIOEntity appIOEntity = BaseNetworkable.serverEntities.Find(base.Request.entityId) as AppIOEntity; if (appIOEntity == null) { return(ValidationResult.NotFound); } BuildingPrivlidge buildingPrivilege = appIOEntity.GetBuildingPrivilege(); if (buildingPrivilege != null && !buildingPrivilege.IsAuthed(base.UserId)) { return(ValidationResult.NotFound); } Entity = appIOEntity; base.Client.Subscribe(new EntityTarget(base.Request.entityId)); return(ValidationResult.Success); }
public object CropsProtected(BasePlayer player, GrowableEntity growable) { if (player.IPlayer.HasPermission(protectionbypass) == true) { return(null); } if ((bool)Config["ToolCupboardArea"] == true) { BuildingPrivlidge TC = player.GetBuildingPrivilege(); if (TC?.IsAuthed(player) == false) { WarnPlayer(player); return(true); } } else if (growable.OwnerID != player.userID) { WarnPlayer(player); return(true); } return(null); }
void CloseConnectedDoors(BasePlayer player, string command, string[] args) { if (!permission.UserHasPermission(player.UserIDString, "masterlock.doorcontrol") && !player.IsAdmin) { player.ChatMessage(Lang("NoCommandPermission", player.UserIDString)); return; } BuildingPrivlidge privilege = player.GetBuildingPrivilege(); if (!privilege) { player.ChatMessage(Lang("NoBuildingPrivilege", player.UserIDString)); return; } if (!privilege.IsAuthed(player)) { player.ChatMessage(Lang("NoAuthorization", player.UserIDString)); return; } if (data.buildings.ContainsKey(privilege.net.ID)) { if (data.buildings[privilege.net.ID]) { CloseDoors(privilege, player); } else { player.ChatMessage(Lang("NotEnabled", player.UserIDString)); } } else { player.ChatMessage(Lang("NotEnabled", player.UserIDString)); } }
public static bool Check( BasePlayer player, Construction construction, Vector3 position, Quaternion rotation) { OBB obb; ((OBB) ref obb).\u002Ector(position, rotation, construction.bounds); float radius = ((Vector3) ref obb.extents).get_magnitude() + 2f; List <BuildingBlock> list = (List <BuildingBlock>)Pool.GetList <BuildingBlock>(); Vis.Entities <BuildingBlock>((Vector3)obb.position, radius, list, 2097152, (QueryTriggerInteraction)2); uint num = 0; for (int index = 0; index < list.Count; ++index) { BuildingBlock buildingBlock = list[index]; Construction construction1 = construction; Construction blockDefinition = buildingBlock.blockDefinition; Vector3 vector3_1 = position; Vector3 position1 = ((Component)buildingBlock).get_transform().get_position(); Quaternion quaternion = rotation; Quaternion rotation1 = ((Component)buildingBlock).get_transform().get_rotation(); BuildingProximity.ProximityInfo proximity1 = BuildingProximity.GetProximity(construction1, vector3_1, quaternion, blockDefinition, position1, rotation1); BuildingProximity.ProximityInfo proximity2 = BuildingProximity.GetProximity(blockDefinition, position1, rotation1, construction1, vector3_1, quaternion); BuildingProximity.ProximityInfo proximityInfo = new BuildingProximity.ProximityInfo(); proximityInfo.hit = proximity1.hit || proximity2.hit; proximityInfo.connection = proximity1.connection || proximity2.connection; if ((double)proximity1.sqrDist <= (double)proximity2.sqrDist) { proximityInfo.line = proximity1.line; proximityInfo.sqrDist = proximity1.sqrDist; } else { proximityInfo.line = proximity2.line; proximityInfo.sqrDist = proximity2.sqrDist; } if (proximityInfo.connection) { BuildingManager.Building building = buildingBlock.GetBuilding(); if (building != null) { BuildingPrivlidge buildingPrivilege = building.GetDominatingBuildingPrivilege(); if (Object.op_Inequality((Object)buildingPrivilege, (Object)null)) { if (!construction.canBypassBuildingPermission && !buildingPrivilege.IsAuthed(player)) { Construction.lastPlacementError = "Cannot attach to unauthorized building"; // ISSUE: cast to a reference type Pool.FreeList <BuildingBlock>((List <M0>&) ref list); return(true); } if (num == 0U) { num = building.ID; } else if ((int)num != (int)building.ID) { Construction.lastPlacementError = "Cannot connect two buildings with cupboards"; // ISSUE: cast to a reference type Pool.FreeList <BuildingBlock>((List <M0>&) ref list); return(true); } } } } if (proximityInfo.hit) { Vector3 vector3_2 = Vector3.op_Subtraction((Vector3)proximityInfo.line.point1, (Vector3)proximityInfo.line.point0); if ((double)Mathf.Abs((float)vector3_2.y) <= 1.49000000953674 && (double)Vector3Ex.Magnitude2D(vector3_2) <= 1.49000000953674) { Construction.lastPlacementError = "Not enough space"; // ISSUE: cast to a reference type Pool.FreeList <BuildingBlock>((List <M0>&) ref list); return(true); } } } // ISSUE: cast to a reference type Pool.FreeList <BuildingBlock>((List <M0>&) ref list); return(false); }
void CalculateUpkeepCost(BasePlayer player, string command, string[] args) { if (!permission.UserHasPermission(player.UserIDString, "tcmanager.upkeep") && !player.IsAdmin) { player.ChatMessage(Lang("NoCommandPermission", player.UserIDString)); return; } BuildingPrivlidge privilege = player.GetBuildingPrivilege(); if (!privilege) { player.ChatMessage(Lang("NoBuildingPrivilege", player.UserIDString)); return; } if (!privilege.IsAuthed(player) && !player.IsAdmin) { player.ChatMessage(Lang("NoAuthorization", player.UserIDString)); return; } if (args.Length == 0) // Default { List <ItemAmount> itemAmounts = Facepunch.Pool.GetList <ItemAmount>(); privilege.CalculateUpkeepCostAmounts(itemAmounts); player.ChatMessage(Lang("DefaultCostHeader", player.UserIDString)); player.ChatMessage(Lang("Line", player.UserIDString)); foreach (ItemAmount amount in itemAmounts) { player.ChatMessage(Lang("ItemCost", player.UserIDString, amount.itemDef.displayName.translated, Math.Ceiling(amount.amount))); } Facepunch.Pool.FreeList(ref itemAmounts); } else { BuildingGrade.Enum grade = BuildingGrade.Enum.None; switch (args[0].ToLower()) { case "0": grade = BuildingGrade.Enum.Twigs; break; case "1": grade = BuildingGrade.Enum.Wood; break; case "2": grade = BuildingGrade.Enum.Stone; break; case "3": grade = BuildingGrade.Enum.Metal; break; case "4": grade = BuildingGrade.Enum.TopTier; break; default: player.ChatMessage(Lang("UpkeepUsage", player.UserIDString)); return; } List <ItemAmount> itemAmounts = Facepunch.Pool.GetList <ItemAmount>(); BuildingManager.Building building = privilege.GetBuilding(); foreach (BuildingBlock block in building.buildingBlocks) { BuildingGrade.Enum original = block.grade; block.grade = grade; block.CalculateUpkeepCostAmounts(itemAmounts, privilege.CalculateUpkeepCostFraction()); block.grade = original; } player.ChatMessage(Lang("GradedCostHeader", player.UserIDString, grade)); player.ChatMessage(Lang("Line", player.UserIDString)); foreach (ItemAmount amount in itemAmounts) { player.ChatMessage(Lang("ItemCost", player.UserIDString, amount.itemDef.displayName.translated, Math.Ceiling(amount.amount))); } Facepunch.Pool.FreeList(ref itemAmounts); } }
object OnSamSiteTarget(SamSite samsite, MiniCopter target) { BasePlayer player = target.GetDriver(); BuildingPrivlidge priviledge = samsite.GetBuildingPrivilege(); if (player != null && permission.UserHasPermission(player.UserIDString, turretsIgnore) || (samsite.ShortPrefabName == "sam_site_turret_deployed" && _config.samSitesAffected || samsite.ShortPrefabName == "sam_static" && _config.staticSamSitesAffected) && (priviledge == null || priviledge != null && ((priviledge.IsAuthed(player) || (!priviledge.IsAuthed(player.userID) && !player.IsBuildingBlocked()))))) { return(false); } return(null); }
public static bool Check(BasePlayer player, Construction construction, Vector3 position, Quaternion rotation) { OBB oBB = new OBB(position, rotation, construction.bounds); float single = oBB.extents.magnitude + 2f; List <BuildingBlock> list = Pool.GetList <BuildingBlock>(); Vis.Entities <BuildingBlock>(oBB.position, single, list, 2097152, QueryTriggerInteraction.Collide); uint d = 0; for (int i = 0; i < list.Count; i++) { BuildingBlock item = list[i]; Construction construction1 = construction; Construction construction2 = item.blockDefinition; Vector3 vector3 = position; Vector3 vector31 = item.transform.position; Quaternion quaternion = rotation; Quaternion quaternion1 = item.transform.rotation; BuildingProximity.ProximityInfo proximity = BuildingProximity.GetProximity(construction1, vector3, quaternion, construction2, vector31, quaternion1); BuildingProximity.ProximityInfo proximityInfo = BuildingProximity.GetProximity(construction2, vector31, quaternion1, construction1, vector3, quaternion); BuildingProximity.ProximityInfo proximityInfo1 = new BuildingProximity.ProximityInfo() { hit = (proximity.hit ? true : proximityInfo.hit), connection = (proximity.connection ? true : proximityInfo.connection) }; if (proximity.sqrDist > proximityInfo.sqrDist) { proximityInfo1.line = proximityInfo.line; proximityInfo1.sqrDist = proximityInfo.sqrDist; } else { proximityInfo1.line = proximity.line; proximityInfo1.sqrDist = proximity.sqrDist; } if (proximityInfo1.connection) { BuildingManager.Building building = item.GetBuilding(); if (building != null) { BuildingPrivlidge dominatingBuildingPrivilege = building.GetDominatingBuildingPrivilege(); if (dominatingBuildingPrivilege != null) { if (!construction.canBypassBuildingPermission && !dominatingBuildingPrivilege.IsAuthed(player)) { Construction.lastPlacementError = "Cannot attach to unauthorized building"; Pool.FreeList <BuildingBlock>(ref list); return(true); } if (d == 0) { d = building.ID; } else if (d != building.ID) { Construction.lastPlacementError = "Cannot connect two buildings with cupboards"; Pool.FreeList <BuildingBlock>(ref list); return(true); } } } } if (proximityInfo1.hit) { Vector3 vector32 = proximityInfo1.line.point1 - proximityInfo1.line.point0; if (Mathf.Abs(vector32.y) <= 1.49f && vector32.Magnitude2D() <= 1.49f) { Construction.lastPlacementError = "Not enough space"; Pool.FreeList <BuildingBlock>(ref list); return(true); } } } Pool.FreeList <BuildingBlock>(ref list); return(false); }
public override bool IsAuthorized(BasePlayer player) { return(Cupboard.IsAuthed(player)); }