Exemplo n.º 1
0
        public void View()
        {
            var xorg = new Ogre
            {
                Key           = new PersistonKey("Ogre", DatonKey.NEWPK, false),
                Name          = "Xorg",
                Money         = 4,
                PaymentMethod = new List <Ogre.PaymentMethodRow>
                {
                    new Ogre.PaymentMethodRow {
                        Method = "credit", Notes = "usually declined"
                    }
                }
            };

            //bill can't view money
            var bill = new User();

            bill.Roles = new[]
            {
                new RetroRole
                {
                    BaseLevel      = PermissionLevel.View,
                    TableOverrides = new List <TablePermission>
                    {
                        new TablePermission
                        {
                            TableName       = "Ogre",
                            BaseLevel       = PermissionLevel.View | PermissionLevel.Modify,
                            ColumnOverrides = new List <ColumnPermission>
                            {
                                new ColumnPermission {
                                    ColumnName = "Money", BaseLevel = PermissionLevel.None
                                }
                            }
                        },
                        new TablePermission
                        {
                            TableName = "PaymentMethod",
                            Level     = (usr, daton, tabname) => PermissionLevel.None
                        }
                    }
                }
            };

            var ddict = new DataDictionary();

            ddict.AddDatonUsingClassAnnotation(typeof(Ogre));
            var guard = new SecurityGuard(ddict, bill);

            guard.HidePrivateParts(xorg);

            Assert.IsNotNull(xorg.Name);
            Assert.IsNull(xorg.Money);
            Assert.AreEqual(1, xorg.PaymentMethod.Count);
            Assert.IsNull(xorg.PaymentMethod[0].Method);
            Assert.IsNull(xorg.PaymentMethod[0].Notes);
        }
Exemplo n.º 2
0
    void SpawnEnemies(float timeLimit, ref float time)
    {
        if (time >= timeLimit)
        {
            SecurityGuard e1 = Instantiate(sg, doorsToUse[0].transform.position, Quaternion.identity, enemyParent);
            e1.distancePlayerInRange = 1000;
            e1.fsm.SendEvent((int)SecurityGuard.EventosGuardia.EnRangoDeAtaque);

            SecurityGuard e2 = Instantiate(sg, doorsToUse[1].transform.position, Quaternion.identity, enemyParent);
            e1.distancePlayerInRange = 1000;
            e1.fsm.SendEvent((int)SecurityGuard.EventosGuardia.EnRangoDeAtaque);
            timer = 0;
        }
    }
Exemplo n.º 3
0
        public ActionResult addSecurityGuard(SecurityGuard guard)
        {
            using (BlogDbContext db = new BlogDbContext())
            {
                var isSameUser = db.accounts.Where(a => a.AccountUsername == guard.GuardUsername).FirstOrDefault();
                if (isSameUser == null)
                {
                    // Username not the same
                    // Generate ID
                    StringBuilder strBuilder = new StringBuilder();
                    Enumerable
                    .Range(65, 26)
                    .Select(e => ((char)e).ToString())
                    .Concat(Enumerable.Range(97, 26).Select(e => ((char)e).ToString()))
                    .Concat(Enumerable.Range(0, 10).Select(e => e.ToString()))
                    .OrderBy(e => Guid.NewGuid())
                    .Take(11)
                    .ToList().ForEach(e => strBuilder.Append(e));
                    string id = strBuilder.ToString();

                    guard.GuardId       = id;
                    guard.GuardPassword = Crypto.Hash(guard.GuardPassword);
                    db.securityGuards.Add(guard);
                    db.SaveChanges();

                    var isAdded = addGuardAccount(guard.GuardUsername);
                    if (isAdded)
                    {
                        return(new JsonResult {
                            Data = new { status = true, name = guard.GuardName, lastname = guard.GuardLastname, statusCode = 0 }, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                        });
                    }
                    else
                    {
                        return(new JsonResult {
                            Data = new { status = false, statusCode = 99 }, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                        });
                    }
                }
                else
                {
                    // same
                    return(new JsonResult {
                        Data = new { status = false, statusCode = 1 }, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    });
                }
            }
        }
        public NeedSecurityGuardAttribute(SecurityGuard sg = SecurityGuard.None, string extnames = ".ico|.jpg|.gif|.png|.doc|.docx|.xls|.xlsx|.ppt|.ppts|.pps|.txt|.zip|.rar")

        {
            _sg       = sg;
            _extnames = extnames;
        }
Exemplo n.º 5
0
 public void ChangeSecurityGuard(SecurityGuard securityGuard)
 {
     SecurityGuard = securityGuard ?? throw new ArgumentNullException(nameof(securityGuard));
 }
Exemplo n.º 6
0
        public void Update()
        {
            var xorg = new Ogre
            {
                Key           = new PersistonKey("Ogre", DatonKey.NEWPK, false),
                Name          = "Xorg",
                Money         = 4,
                PaymentMethod = new List <Ogre.PaymentMethodRow>
                {
                    new Ogre.PaymentMethodRow {
                        Method = "credit", Notes = "usually declined"
                    }
                }
            };

            //bill can't update money
            var bill = new User();

            bill.Roles = new[]
            {
                new RetroRole
                {
                    BaseLevel      = PermissionLevel.All,
                    TableOverrides = new List <TablePermission>
                    {
                        new TablePermission
                        {
                            TableName       = "Ogre",
                            BaseLevel       = PermissionLevel.View | PermissionLevel.Modify,
                            ColumnOverrides = new List <ColumnPermission>
                            {
                                new ColumnPermission {
                                    ColumnName = "Money", BaseLevel = PermissionLevel.None
                                }
                            }
                        },
                        new TablePermission
                        {
                            TableName = "PaymentMethod",
                            Level     = (usr, daton, tabname) => PermissionLevel.None
                        }
                    }
                }
            };

            var ddict = new DataDictionary();

            ddict.AddDatonUsingClassAnnotation(typeof(Ogre));
            var ogredef    = ddict.DatonDefs["Ogre"];
            var paymentdef = ogredef.MainTableDef.Children[0];

            var diff = new PersistonDiff(ogredef, xorg.Key, xorg.Version)
            {
                MainTable = new List <PersistonDiff.DiffRow>
                {
                    new PersistonDiff.DiffRow
                    {
                        Kind    = DiffKind.Other,
                        Columns = new Dictionary <string, object>
                        {
                            { "Name", "Priscilla" }, //allowed
                            { "Money", (decimal)5.49 } //disallowed
                        },
                        ChildTables = new Dictionary <TableDef, List <PersistonDiff.DiffRow> >
                        {
                            {
                                paymentdef,
                                new List <PersistonDiff.DiffRow>
                                {
                                    new PersistonDiff.DiffRow
                                    {
                                        Kind    = DiffKind.Other,
                                        Columns = new Dictionary <string, object>
                                        {
                                            { "Method", "cash" }, //disallowed by function
                                            { "Notes", "cash is best" }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            var guard  = new SecurityGuard(ddict, bill);
            var errors = guard.GetDisallowedWrites(xorg, ogredef, diff).ToArray();

            Assert.AreEqual(3, errors.Length);
            Assert.IsTrue(errors[0].Contains("Ogre.Money"));
            Assert.IsTrue(errors[1].Contains("PaymentMethod.Method"));
            Assert.IsTrue(errors[2].Contains("PaymentMethod.Notes"));
        }
Exemplo n.º 7
0
        public void Create()
        {
            var xorg = new Ogre
            {
                Key           = new PersistonKey("Ogre", DatonKey.NEWPK, false),
                Name          = "Xorg",
                Money         = 4,
                PaymentMethod = new List <Ogre.PaymentMethodRow>
                {
                    new Ogre.PaymentMethodRow {
                        Method = "credit", Notes = "usually declined"
                    }
                }
            };

            //nancy can only create new payment rows, not update existing
            var nancy = new User();

            nancy.Roles = new[]
            {
                new RetroRole
                {
                    BaseLevel      = PermissionLevel.None,
                    TableOverrides = new List <TablePermission>
                    {
                        new TablePermission
                        {
                            TableName = "PaymentMethod",
                            BaseLevel = PermissionLevel.Create
                        }
                    }
                }
            };

            var ddict = new DataDictionary();

            ddict.AddDatonUsingClassAnnotation(typeof(Ogre));
            var ogredef    = ddict.DatonDefs["Ogre"];
            var paymentdef = ogredef.MainTableDef.Children[0];

            var diff = new PersistonDiff(ogredef, xorg.Key, xorg.Version)
            {
                MainTable = new List <PersistonDiff.DiffRow>
                {
                    new PersistonDiff.DiffRow
                    {
                        Kind    = DiffKind.Other,
                        Columns = new Dictionary <string, object>
                        {
                            { "Name", "Priscilla" } //disallowed
                        },
                        ChildTables = new Dictionary <TableDef, List <PersistonDiff.DiffRow> >
                        {
                            {
                                paymentdef,
                                new List <PersistonDiff.DiffRow>
                                {
                                    new PersistonDiff.DiffRow
                                    {
                                        Kind    = DiffKind.Other,
                                        Columns = new Dictionary <string, object>
                                        {
                                            { "Notes", "disallowed" } //disallowed update
                                        }
                                    },
                                    new PersistonDiff.DiffRow
                                    {
                                        Kind    = DiffKind.NewRow,
                                        Columns = new Dictionary <string, object>
                                        {
                                            { "Method", "barter" } //allowed create row
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            var guard  = new SecurityGuard(ddict, nancy);
            var errors = guard.GetDisallowedWrites(xorg, ogredef, diff).ToArray();

            Assert.AreEqual(2, errors.Length);
            Assert.IsTrue(errors[0].Contains("Ogre.Name"));
            Assert.IsTrue(errors[1].Contains("PaymentMethod.Notes"));
        }
Exemplo n.º 8
0
        public static void Prefix(ExileController __instance, [HarmonyArgument(0)] ref GameData.PlayerInfo exiled, [HarmonyArgument(1)] bool tie)
        {
            lastExiled = exiled;

            // Medic shield
            if (Medic.medic != null && AmongUsClient.Instance.AmHost && Medic.futureShielded != null && !Medic.medic.Data.IsDead)   // We need to send the RPC from the host here, to make sure that the order of shifting and setting the shield is correct(for that reason the futureShifted and futureShielded are being synced)
            {
                MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.MedicSetShielded, Hazel.SendOption.Reliable, -1);
                writer.Write(Medic.futureShielded.PlayerId);
                AmongUsClient.Instance.FinishRpcImmediately(writer);
                RPCProcedure.medicSetShielded(Medic.futureShielded.PlayerId);
            }

            // Madmate exiled
            if (AmongUsClient.Instance.AmHost &&
                exiled != null &&
                ((CreatedMadmate.exileCrewmate &&
                  exiled.Object.hasModifier(ModifierType.CreatedMadmate)) ||
                 (Madmate.exileCrewmate &&
                  exiled.Object.hasModifier(ModifierType.Madmate))))
            {
                // pick random crewmate
                PlayerControl target = pickRandomCrewmate(exiled.PlayerId);
                if (target != null)
                {
                    // exile the picked crewmate
                    MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
                                                                                      (byte)CustomRPC.UncheckedExilePlayer,
                                                                                      Hazel.SendOption.Reliable,
                                                                                      -1);
                    writer.Write(target.PlayerId);
                    AmongUsClient.Instance.FinishRpcImmediately(writer);
                    RPCProcedure.uncheckedExilePlayer(target.PlayerId);
                }
            }

            // Shifter shift
            if (Shifter.shifter != null && AmongUsClient.Instance.AmHost && Shifter.futureShift != null)   // We need to send the RPC from the host here, to make sure that the order of shifting and erasing is correct (for that reason the futureShifted and futureErased are being synced)
            {
                MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.ShifterShift, Hazel.SendOption.Reliable, -1);
                writer.Write(Shifter.futureShift.PlayerId);
                AmongUsClient.Instance.FinishRpcImmediately(writer);
                RPCProcedure.shifterShift(Shifter.futureShift.PlayerId);
            }
            Shifter.futureShift = null;

            // Eraser erase
            if (Eraser.eraser != null && AmongUsClient.Instance.AmHost && Eraser.futureErased != null)    // We need to send the RPC from the host here, to make sure that the order of shifting and erasing is correct (for that reason the futureShifted and futureErased are being synced)
            {
                foreach (PlayerControl target in Eraser.futureErased)
                {
                    if (target != null && target.canBeErased())
                    {
                        MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.ErasePlayerRoles, Hazel.SendOption.Reliable, -1);
                        writer.Write(target.PlayerId);
                        AmongUsClient.Instance.FinishRpcImmediately(writer);
                        RPCProcedure.erasePlayerRoles(target.PlayerId);
                    }
                }
            }
            Eraser.futureErased = new List <PlayerControl>();

            // Trickster boxes
            if (Trickster.trickster != null && JackInTheBox.hasJackInTheBoxLimitReached())
            {
                JackInTheBox.convertToVents();
            }

            // Witch execute casted spells
            if (Witch.witch != null && Witch.futureSpelled != null && AmongUsClient.Instance.AmHost)
            {
                bool exiledIsWitch            = exiled != null && exiled.PlayerId == Witch.witch.PlayerId;
                bool witchDiesWithExiledLover = exiled != null && Lovers.bothDie && exiled.Object.isLovers() && exiled.Object.getPartner() == Witch.witch;

                if ((witchDiesWithExiledLover || exiledIsWitch) && Witch.witchVoteSavesTargets)
                {
                    Witch.futureSpelled = new List <PlayerControl>();
                }
                foreach (PlayerControl target in Witch.futureSpelled)
                {
                    if (target != null && !target.Data.IsDead && Helpers.checkMuderAttempt(Witch.witch, target, true) == MurderAttemptResult.PerformKill)
                    {
                        MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.WitchSpellCast, Hazel.SendOption.Reliable, -1);
                        writer.Write(target.PlayerId);
                        AmongUsClient.Instance.FinishRpcImmediately(writer);
                        RPCProcedure.witchSpellCast(target.PlayerId);
                    }
                }
            }
            Witch.futureSpelled = new List <PlayerControl>();

            // SecurityGuard vents and cameras
            var allCameras = ShipStatus.Instance.AllCameras.ToList();

            MapOptions.camerasToAdd.ForEach(camera => {
                camera.gameObject.SetActive(true);
                camera.gameObject.GetComponent <SpriteRenderer>().color = Color.white;
                allCameras.Add(camera);
            });
            ShipStatus.Instance.AllCameras = allCameras.ToArray();
            MapOptions.camerasToAdd        = new List <SurvCamera>();

            foreach (Vent vent in MapOptions.ventsToSeal)
            {
                PowerTools.SpriteAnim animator = vent.GetComponent <PowerTools.SpriteAnim>();
                animator?.Stop();
                vent.EnterVentAnim = vent.ExitVentAnim = null;
                vent.myRend.sprite = animator == null?SecurityGuard.getStaticVentSealedSprite() : SecurityGuard.getAnimatedVentSealedSprite();

                if (SubmergedCompatibility.isSubmerged() && vent.Id == 0)
                {
                    vent.myRend.sprite = SecurityGuard.getSubmergedCentralUpperSealedSprite();
                }
                if (SubmergedCompatibility.isSubmerged() && vent.Id == 14)
                {
                    vent.myRend.sprite = SecurityGuard.getSubmergedCentralLowerSealedSprite();
                }
                vent.myRend.color = Color.white;
                vent.name         = "SealedVent_" + vent.name;
            }
            MapOptions.ventsToSeal = new List <Vent>();

            // 1 = reset per turn
            if (MapOptions.restrictDevices == 1)
            {
                MapOptions.resetDeviceTimes();
            }
        }
        public User Create(
            string login,
            string password,
            Role role,
            string email     = null,
            bool needNotify  = false,
            int?entranceId   = null,
            int?departmentId = null)
        {
            if (string.IsNullOrWhiteSpace(login))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(login));
            }
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(password));
            }

            if (_userRepository.AllActive().Any(x => x.Login.Equals(login, StringComparison.InvariantCultureIgnoreCase)))
            {
                throw new UserAlreadyExistsException("Пользователь с таким логином уже существует");
            }

            User user;

            switch (role)
            {
            case Role.Administrator:
                user = new Administrator(login, password, email, needNotify);
                break;

            case Role.Manager:
            {
                if (!departmentId.HasValue)
                {
                    throw new InvalidOperationException("Department not chosen.");
                }

                var department = _departmentService.GetById(departmentId.Value);

                user = new Manager(login, password, department, email);
                break;
            }

            case Role.SecurityGuard:
            {
                if (!entranceId.HasValue)
                {
                    throw new InvalidOperationException("Entrance not chosen.");
                }

                var entrance = _entranceService.GetById(entranceId.Value);

                user = new SecurityGuard(login, password, entrance);

                entrance.ChangeSecurityGuard((SecurityGuard)user);

                break;
            }

            default: throw new ArgumentOutOfRangeException(nameof(role));
            }

            _userRepository.Add(user);

            return(GetByLogin(login));
        }
Exemplo n.º 10
0
 public ActionResult Manage([Bind(Include = "SecurityGuardID,AttendanceSystemID,Name,Address,Mobile")] SecurityGuard security)
 {
     return(base.BaseSave <SecurityGuard>(security, security.SecurityGuardID > 0));
 }