object CanUseLockedEntity(BasePlayer player, CodeLock codeLock) { if (codeLock.IsLocked() == false) { return(null); } var building = (codeLock.GetParentEntity() as DecayEntity)?.GetBuilding(); if (building == null) { Puts($"Couldn't find building for {codeLock.GetParentEntity()?.PrefabName}!"); return(null); } if (building.buildingPrivileges.Count == 0) { return(null); } var tcLock = building.buildingPrivileges[0].GetSlot(BaseEntity.Slot.Lock) as CodeLock; if (tcLock == null) { return(null); } if (tcLock.code != codeLock.code) { return(null); } if (tcLock.whitelistPlayers.Contains(player.userID)) { return(true); } return(null); }
// Handle the case where the code lock is removed but the car and cockpit remain private void OnEntityKill(CodeLock codeLock) { if (codeLock == null) { return; } var seatingModule = codeLock.GetParentEntity() as VehicleModuleSeating; if (seatingModule == null) { return; } var car = seatingModule.Vehicle as ModularCar; NextTick(() => { if (car == null) { return; } UIManager.UpdateCarUI(car); }); }
void OnCodeEntered(CodeLock codeLock, BasePlayer player, string code) { if (!(codeLock.GetParentEntity() is BuildingPrivlidge)) { return; } if (codeLock.code == code) { PrintToChat(player, $"<color=#FF7F00>LockSync:</color> {lang.GetMessage("AutoAuthInfo", this, player.UserIDString)}"); } }
/// <summary> /// Update the code on all locks following the master lock /// </summary> /// <param name="codeLock"></param> /// <param name="player"></param> /// <param name="newCode"></param> /// <param name="isGuestCode"></param> void CanChangeCode(CodeLock codeLock, BasePlayer player, string newCode, bool isGuestCode) { if (codeLock.GetParentEntity() is BuildingPrivlidge) { BuildingPrivlidge privilege = codeLock.GetParentEntity() as BuildingPrivlidge; if (data.buildings.ContainsKey(privilege.net.ID)) { if (data.buildings[privilege.net.ID] && !isGuestCode) { uint count = UpdateCode(privilege, newCode); player.ChatMessage(Lang("CodeUpdate", player.UserIDString, count)); } else if (!data.buildings[privilege.net.ID] && !isGuestCode && (bool)Config["Display Tooltips"]) { ShowGameTip(BasePlayer.FindByID(privilege.OwnerID), Lang("UseCommand", player.UserIDString)); } } else if ((bool)Config["Display Tooltips"]) { ShowGameTip(BasePlayer.FindByID(privilege.OwnerID), Lang("UseCommand", player.UserIDString)); } } }
/// <summary> /// Can use door hook - called when someone tries to use a door with a codelock /// </summary> /// <param name="player">the player who tried to use the door</param> /// <param name="door">the door in question</param> /// <returns>can we open the door</returns> bool CanUseDoor(BasePlayer player, CodeLock lck) { // reflect to get the private code var codeField = typeof(CodeLock).GetField("code", BindingFlags.NonPublic | BindingFlags.Instance); var codeValue = (string)codeField.GetValue(lck); // if it's not locked or the code isn't all 0s there's nothing for us to do if (!lck.IsLocked() || codeValue != "0000") { return(true); } var door = (Door)lck.GetParentEntity(); var doorId = GetDoorId(door); var doorOwnerId = Convert.ToString(door.OwnerID); var playerId = Convert.ToString(player.userID); if (!acl.ContainsKey(doorId)) { acl[doorId] = new List <string>(); } if (acl[doorId].IndexOf(doorOwnerId) > -1) { return(true); } else { if (pending2FA.IndexOf(doorId + playerId) == -1) { pending2FA.Add(doorId + playerId); GetRequest(doorOwnerId, doorId, playerId); } return(false); } }
private object OnCodeEntered(CodeLock codeLock, BasePlayer player, string code) { if (player.IPlayer.HasPermission(PermissionIgnore)) { return(null); } var isCodeAdmin = codeLock.code == code; var isCodeGuest = codeLock.guestCode == code; if (!isCodeAdmin && !isCodeGuest) { return(null); } var limit = Configuration.Limit.Find(codeLock.ShortPrefabName); if (limit == null) { return(null); } var total = codeLock.guestPlayers.Count + codeLock.whitelistPlayers.Count; if (total < limit.MaxAuthorized) { return(null); } var entity = codeLock.GetParentEntity(); if (entity == null || !entity.IsValid()) { return(null); } if (limit.NoDecaying && IsDecaying(entity.GetBuildingPrivilege())) { return(null); } if (limit.Deauthorize) { if (isCodeAdmin && codeLock.whitelistPlayers.Count > 0) { if (limit.DeauthorizeAll) { codeLock.whitelistPlayers.Clear(); } else { codeLock.whitelistPlayers.RemoveAt(0); } codeLock.SendNetworkUpdate(); } if (isCodeGuest && codeLock.guestPlayers.Count > 0) { if (limit.DeauthorizeAll) { codeLock.guestPlayers.Clear(); } else { codeLock.guestPlayers.RemoveAt(0); } codeLock.SendNetworkUpdate(); } NotifyDeauthorize(limit, entity, player); } else { NotifyAuthorize(limit, entity, player); } if (limit.Enforce) { return(true); } return(null); }