public void Cleanup() { Hacker.ClearAllHitsAsync(); Hacker.ClearBlacklistsAsync(); }
public HackerTests() { hacker = new Hacker(); }
public static void class4() { Character hacker = new Hacker("Acid Wash", "I'm a vert smart and capable hack person"); Debug.Log(hacker.Greet()); }
public void BeforeEachTest() { hacker = new Hacker(); }
public void solved(Hacker hacker) { }
public static async Task <Hacker.Result> DefendURL(HttpContext context) { Hacker.Result result = Hacker.Result.Allowed; Stopwatch watch = new Stopwatch(); watch.Start(); if (!Initialized) { lock (lockObject) { if (!Initialized) { Hacker.Logger = new TraceLogger(); Hacker.Logger.LogInformation(ClassName + ' ' + "Initialize"); Hacker.Store = new RedisDefenceStore(HackerSprayConfig.Settings.Redis, HackerSprayConfig.Settings.Prefix, Hacker.Config); Hacker.Logger.LogInformation(ClassName + ' ' + " Initialized"); Initialized = true; } } } // This handles load balancers passing the original client IP // through this header. // WARNING: If your load balancer is not passing original client IP // through this header, then you will be blocking your load balancer, // causing a total outage. Also ensure this Header cannot be spoofed. // Your load balancer should be configured in a way that it does not accept // this header from the request, instead it always sets it itself. var originIP = context.Request.GetClientIp(); foreach (var path in HackerSprayConfig.Settings.Paths) { if ((path.Post && context.Request.HttpMethod == "POST") || (!path.Post && context.Request.HttpMethod == "GET") && path.Name == context.Request.Path) { Hacker.Logger.LogDebug(ClassName + ' ' + "Path matched: " + context.Request.Path); if (path.Mode == "key") { result = await Hacker.DefendAsync(context.Request.Path, originIP, path.Interval, path.MaxAttempts, TimeSpan.MaxValue, long.MaxValue, TimeSpan.MaxValue, long.MaxValue); if (result == Hacker.Result.TooManyHitsOnKey) { Hacker.Logger.LogInformation(ClassName + ' ' + "TooManyHitsOnKey Blacklist Path: " + context.Request.Path); await Hacker.BlacklistKeyAsync(path.Name, path.Interval); } } else if (path.Mode == "origin") { result = await Hacker.DefendAsync(context.Request.Path, originIP, TimeSpan.MaxValue, long.MaxValue, path.Interval, path.MaxAttempts, TimeSpan.MaxValue, long.MaxValue); if (result == Hacker.Result.TooManyHitsFromOrigin) { Hacker.Logger.LogInformation(ClassName + ' ' + "TooManyHitsFromOrigin Blacklist origin: " + originIP); await Hacker.BlacklistOriginAsync(originIP, path.Interval); } } else //(path.Mode == "key+origin") { result = await Hacker.DefendAsync(context.Request.Path, originIP, TimeSpan.MaxValue, long.MaxValue, TimeSpan.MaxValue, long.MaxValue, path.Interval, path.MaxAttempts); } break; } } watch.Stop(); Hacker.Logger.LogDebug(ClassName + ' ' + "DefendURL: " + context.Request.Path + " " + watch.ElapsedMilliseconds); return(result); }
public bool PutHacker(int id, [FromBody] Hacker hacker) { return(this.HackerService.UpdateHacker(id, hacker)); }
public void Cleanup() { Hacker.ClearAllHitsAsync().Run(); Hacker.ClearBlacklistsAsync().Run(); Hacker.Store.Dispose(); }
public void TestAllowed() { var result = Hacker.DefendAsync("TestAllowed" + GetRandomKey(), GetRandomIP()).Run(); Assert.AreEqual(Hacker.Result.Allowed, result); }
/// <summary> /// <para>Scripts that use UpdateManager and run on a server shall be added here.</para> /// </summary> private void RegisterScripts_Server() { #region Autopilot //RadarEquipment.Definition apRadar = new RadarEquipment.Definition() //{ // Radar = true, // LineOfSight = false, // MaxTargets_Tracking = 3, // MaxPowerLevel = 1000 //}; Action <IMyCubeBlock> construct = block => { if (ShipAutopilot.IsAutopilotBlock(block)) { var sca = new ShipAutopilot(block); RegisterForUpdates(ShipAutopilot.UpdateFrequency, sca.Update, block); RegisterForUpdates(100, sca.m_block.NetworkNode.Update100, block); //RadarEquipment r = new RadarEquipment(block, apRadar, block); //RegisterForUpdates(100, r.Update100, block); } }; RegisterForBlock(typeof(MyObjectBuilder_Cockpit), construct); if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bUseRemoteControl)) { RegisterForBlock(typeof(MyObjectBuilder_RemoteControl), construct); } #endregion #region Weapons if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowHacker)) { RegisterForBlock(typeof(MyObjectBuilder_LandingGear), block => { if (Hacker.IsHacker(block)) { Hacker h = new Hacker(block); RegisterForUpdates(10, h.Update10, block); } }); } else { Log.DebugLog("Hacker is disabled in settings"); } #endregion #region Solar { SunProperties sun = new SunProperties(); RegisterForUpdates(10, sun.Update10); } RegisterForBlock(typeof(MyObjectBuilder_OxygenFarm), (block) => { Solar s = new Solar(block); RegisterForUpdates(100, s.Update100, block); }); RegisterForBlock(typeof(MyObjectBuilder_SolarPanel), (block) => { Solar s = new Solar(block); RegisterForUpdates(100, s.Update100, block); }); #endregion RegisterForBlock(typeof(MyObjectBuilder_OreDetector), block => { var od = new OreDetector(block); RegisterForUpdates(1000, od.Update, block); }); }
public void TestOriginRangeBlocking() { Hacker.ClearBlacklistsAsync().Run(); Hacker.ClearAllHitsAsync().Run(); var ipsInRange = new[] { IPAddress.Parse("10.10.10.10"), IPAddress.Parse("10.10.10.11"), IPAddress.Parse("10.10.254.254"), IPAddress.Parse("10.11.10.9"), IPAddress.Parse("10.11.10.10"), IPAddress.Parse("9.1.1.1"), IPAddress.Parse("9.1.1.10"), IPAddress.Parse("9.10.10.9"), IPAddress.Parse("10.11.10.12"), IPAddress.Parse("127.254.254.254"), IPAddress.Parse("100.100.100.100"), IPAddress.Parse("128.10.10.12"), IPAddress.Parse("128.10.10.254"), IPAddress.Parse("128.10.10.128"), }; var ipsOutofRange = new[] { IPAddress.Parse("10.10.10.9"), IPAddress.Parse("9.10.10.10"), IPAddress.Parse("10.11.10.11"), IPAddress.Parse("128.10.10.11"), IPAddress.Parse("200.200.200.200"), IPAddress.Parse("1.1.1.1"), IPAddress.Parse("10.0.0.0") }; Hacker.BlacklistOriginAsync(IPAddress.Parse("10.10.10.10"), IPAddress.Parse("10.11.10.10")).Run(); Hacker.BlacklistOriginAsync(IPAddress.Parse("9.1.1.1"), IPAddress.Parse("9.10.10.9")).Run(); Hacker.BlacklistOriginAsync(IPAddress.Parse("10.11.10.12"), IPAddress.Parse("127.254.254.254")).Run(); Hacker.BlacklistOriginAsync(IPAddress.Parse("128.10.10.12"), IPAddress.Parse("128.10.10.254")).Run(); Array.ForEach(ipsInRange, ip => Assert.AreEqual(Hacker.Result.OriginBlocked, Hacker.DefendAsync("TestOriginRangeBlocking", ip).Run(), ip.ToString() + " must be blocked.")); Hacker.ClearAllHitsAsync().Run(); Array.ForEach(ipsOutofRange, ip => Assert.AreEqual(Hacker.Result.Allowed, Hacker.DefendAsync("TestOriginRangeBlocking", ip).Run(), ip.ToString() + " must be allowed")); Hacker.WhitelistOriginAsync(IPAddress.Parse("9.1.1.1"), IPAddress.Parse("9.10.10.9")).Run(); Array.ForEach(new[] { IPAddress.Parse("9.1.1.1"), IPAddress.Parse("9.1.1.10"), IPAddress.Parse("9.10.10.9") }, ip => Assert.AreEqual(Hacker.Result.Allowed, Hacker.DefendAsync("TestOriginRangeBlocking", ip).Run(), ip.ToString() + " must be allowed")); Hacker.ClearBlacklistsAsync().Run(); Hacker.ClearAllHitsAsync().Run(); Array.ForEach(ipsInRange, ip => Assert.AreEqual(Hacker.Result.Allowed, Hacker.DefendAsync("TestOriginRangeBlocking", ip).Run(), ip.ToString() + " must be allowed when there's no blacklisting.")); Hacker.ClearAllHitsAsync().Run(); Array.ForEach(ipsOutofRange, ip => Assert.AreEqual(Hacker.Result.Allowed, Hacker.DefendAsync("TestOriginRangeBlocking", ip).Run(), ip.ToString() + " must be allowed when there's no blacklisting")); }
/// <summary> /// Scripts that use UpdateManager and run on clients as well as on server shall be added here. /// </summary> private void RegisterScripts_ClientAndServer() { #region Attached RegisterForBlock(new MyObjectBuilderType[] { typeof(MyObjectBuilder_MotorStator), typeof(MyObjectBuilder_MotorAdvancedStator), typeof(MyObjectBuilder_MotorSuspension) }, block => RegisterForUpdates(100, (new StatorRotor.Stator(block)).Update, block)); RegisterForBlock(typeof(MyObjectBuilder_ExtendedPistonBase), (block) => { Piston.PistonBase pistonBase = new Piston.PistonBase(block); RegisterForUpdates(100, pistonBase.Update, block); }); RegisterForBlock(typeof(MyObjectBuilder_ShipConnector), (block) => { Connector conn = new Connector(block); RegisterForUpdates(10, conn.Update, block); }); RegisterForBlock(typeof(MyObjectBuilder_LandingGear), (block) => { if (!Hacker.IsHacker(block)) { new LandingGear(block); } }); #endregion #region Antenna Communication Action <IMyCubeBlock> nodeConstruct = block => { RelayNode node = new RelayNode(block); RegisterForUpdates(100, node.Update100, block); }; RegisterForBlock(typeof(MyObjectBuilder_Beacon), nodeConstruct); RegisterForBlock(typeof(MyObjectBuilder_LaserAntenna), nodeConstruct); RegisterForBlock(typeof(MyObjectBuilder_RadioAntenna), nodeConstruct); RegisterForCharacter(character => { if (character.IsPlayer) { RelayNode node = new RelayNode(character); RegisterForUpdates(100, node.Update100, (IMyEntity)character); } }); RegisterForBlock(typeof(MyObjectBuilder_MyProgrammableBlock), block => { ProgrammableBlock pb = new ProgrammableBlock(block); if (MyAPIGateway.Multiplayer.IsServer) { RegisterForUpdates(100, pb.Update100, block); } }); RegisterForBlock(typeof(MyObjectBuilder_TextPanel), block => { TextPanel tp = new TextPanel(block); if (MyAPIGateway.Multiplayer.IsServer) { RegisterForUpdates(100, tp.Update100, block); } }); RegisterForBlock(typeof(MyObjectBuilder_Projector), block => { Projector p = new Projector(block); if (MyAPIGateway.Session.Player != null) { RegisterForUpdates(100, p.Update100, block); RegisterForUpdates(1, p.Update1, block); } }); if (MyAPIGateway.Session.Player != null) { new Player(); } #endregion #region Autopilot if (!MyAPIGateway.Multiplayer.IsServer) { //RadarEquipment.Definition apRadar = new RadarEquipment.Definition() //{ // Radar = true, // LineOfSight = false, // MaxTargets_Tracking = 3, // MaxPowerLevel = 1000 //}; Action <IMyCubeBlock> apConstruct = (block) => { if (ShipAutopilot.IsAutopilotBlock(block)) { nodeConstruct(block); new AutopilotTerminal(block); //RadarEquipment r = new RadarEquipment(block, apRadar, block); //RegisterForUpdates(100, r.Update100, block); } }; if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bUseRemoteControl)) { RegisterForBlock(typeof(MyObjectBuilder_RemoteControl), apConstruct); } RegisterForBlock(typeof(MyObjectBuilder_Cockpit), apConstruct); } if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAirResistanceBeta)) { RegisterForGrid(grid => { AeroEffects aero = new AeroEffects(grid); RegisterForUpdates(1, aero.Update1, grid); if (MyAPIGateway.Multiplayer.IsServer) { RegisterForUpdates(100, aero.Update100, grid); } }); RegisterForBlock(typeof(MyObjectBuilder_Cockpit), block => RegisterForUpdates(1, (new CockpitTerminal(block)).Update1, block)); } #endregion #region Radar if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowRadar)) { RegisterForBlock(typeof(MyObjectBuilder_Beacon), (block) => { if (RadarEquipment.IsDefinedRadarEquipment(block)) { new RadarEquipment(block); } }); RegisterForBlock(typeof(MyObjectBuilder_RadioAntenna), (block) => { if (RadarEquipment.IsDefinedRadarEquipment(block)) { new RadarEquipment(block); } }); RegisterForUpdates(100, RadarEquipment.UpdateAll); } #endregion #region Terminal Control RegisterForBlock(new MyObjectBuilderType[] { typeof(MyObjectBuilder_RadioAntenna), typeof(MyObjectBuilder_LaserAntenna) }, block => new ManualMessage(block)); #endregion Terminal Control #region Weapon Control if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowWeaponControl)) { #region Turrets Action <IMyCubeBlock> constructor; if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowGuidedMissile)) { constructor = block => { if (!WeaponTargeting.ValidWeaponBlock(block)) { return; } Turret t = new Turret(block); RegisterForUpdates(1, t.Update_Targeting, block); if (GuidedMissileLauncher.IsGuidedMissileLauncher(block)) { GuidedMissileLauncher gml = new GuidedMissileLauncher(t); RegisterForUpdates(1, gml.Update1, block); } } } ; else { constructor = block => { if (!WeaponTargeting.ValidWeaponBlock(block)) { return; } Turret t = new Turret(block); RegisterForUpdates(1, t.Update_Targeting, block); } }; RegisterForBlock(typeof(MyObjectBuilder_LargeGatlingTurret), constructor); RegisterForBlock(typeof(MyObjectBuilder_LargeMissileTurret), constructor); RegisterForBlock(typeof(MyObjectBuilder_InteriorTurret), constructor); #endregion #region Fixed if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowGuidedMissile)) { constructor = block => { if (!WeaponTargeting.ValidWeaponBlock(block)) { return; } FixedWeapon w = new FixedWeapon(block); RegisterForUpdates(1, w.Update_Targeting, block); if (GuidedMissileLauncher.IsGuidedMissileLauncher(block)) { GuidedMissileLauncher gml = new GuidedMissileLauncher(w); RegisterForUpdates(1, gml.Update1, block); } }; } else { constructor = block => { if (!WeaponTargeting.ValidWeaponBlock(block)) { return; } FixedWeapon w = new FixedWeapon(block); RegisterForUpdates(1, w.Update_Targeting, block); } }; RegisterForBlock(typeof(MyObjectBuilder_SmallGatlingGun), constructor); RegisterForBlock(typeof(MyObjectBuilder_SmallMissileLauncher), constructor); RegisterForBlock(typeof(MyObjectBuilder_SmallMissileLauncherReload), constructor); #endregion // apparently missiles do not have their positions synced RegisterForUpdates(1, GuidedMissile.Update1); RegisterForUpdates(10, GuidedMissile.Update10); RegisterForUpdates(100, GuidedMissile.Update100); } else { Log.DebugLog("Weapon Control is disabled", Logger.severity.INFO); } #endregion #region Solar if (!MyAPIGateway.Multiplayer.IsServer) { RegisterForBlock(typeof(MyObjectBuilder_OxygenFarm), (block) => new Solar(block)); RegisterForBlock(typeof(MyObjectBuilder_SolarPanel), (block) => new Solar(block)); } #endregion new ChatHandler(); Globals.Update100(); RegisterForUpdates(100, Globals.Update100); Action <IMyCubeBlock> act = (block) => MainCockpitFix.AddController((IMyShipController)block); RegisterForBlock(typeof(MyObjectBuilder_Cockpit), act); RegisterForBlock(typeof(MyObjectBuilder_RemoteControl), act); }
public void Setup() { Game = new(); Agent = (Hacker)Game.Agents[nameof(Hacker)]; }
static void Main(string[] args) { //------------OBSERVER-------------------------------- Console.WriteLine("-------OBSERVER EXAMPLE------------- \n"); Application shazam = new Application("Shazam", "2.3.1"); List <IClient> clients = new List <IClient> { new Client("Aurel", shazam), new Client("Nicu", shazam), new VipClient("Dima", shazam), new Client("Vlad", shazam) }; shazam.Notify(); //---------------STRATEGY------------------------------ Console.WriteLine("\n-------STRATEGY EXAMPLE------------- \n"); PC pc = new PC("Acer", new HDD()); pc.Read(); pc.ChangeTypepRead(new SSD()); pc.Read(); //-------------TEMPLATE--------------------------------- Console.WriteLine("\n--------Template Example------------ \n"); Reparation personal = new PersonalReparation(); Reparation serviceCenter = new ServiceCenter(); Console.WriteLine("My reparation:"); personal.Repair(); Console.WriteLine("\nService Center Reparation:"); serviceCenter.Repair(); //------------VISITOR------------------------------------ Console.WriteLine("\n----------Visitor Example-------------"); MyDataBase myDB = new MyDataBase("Facebook"); Files files = new Files(); Developer developer = new Developer("George"); User user = new User("Aurel"); Hacker hacker = new Hacker(); files.Accept(developer); files.Accept(hacker); myDB.Accept(developer); myDB.Accept(user); Console.WriteLine("\n OR: "); Administrator admin = new Administrator(); admin.AddElement(myDB); admin.AddElement(files); admin.Accept(developer); admin.Accept(user); admin.RemoveElement(files); Console.WriteLine("Remove operations with files."); admin.Accept(developer); admin.Accept(user); Console.ReadKey(); }
private Card RandomCard(Vector2 position, bool front, int playerID) { Card c = null; if (Globals.r.Next(4) == 0) { int cardsCount = 31; int rn = Globals.r.Next(cardsCount); switch (rn) { case 0: c = new Actor(position, front, playerID); break; case 1: c = new Artist(position, front, playerID); break; case 2: c = new Astrophysicist(position, front, playerID); break; case 3: c = new Babysitter(position, front, playerID); break; case 4: c = new BabysitterU(position, front, playerID); break; case 5: c = new BusDriver(position, front, playerID); break; case 6: c = new Conman(position, front, playerID); break; case 7: c = new DeliveryPerson(position, front, playerID); break; case 8: c = new DrugDealer(position, front, playerID); break; case 9: c = new FastFoodEmployee(position, front, playerID); break; case 10: c = new Hacker(position, front, playerID); break; case 11: c = new Hitman(position, front, playerID); break; case 12: c = new HumanTrafficker(position, front, playerID); break; case 13: c = new IndieGameDev(position, front, playerID); break; case 14: c = new Influencer(position, front, playerID); break; case 15: c = new InstaModel(position, front, playerID); break; case 16: c = new InternDev(position, front, playerID); break; case 17: c = new JuniorDev(position, front, playerID); break; case 18: c = new Musician(position, front, playerID); break; case 19: c = new OnlyFans(position, front, playerID); break; case 20: c = new Referee(position, front, playerID); break; case 21: c = new RiceFarmer(position, front, playerID); break; case 22: c = new Santa(position, front, playerID); break; case 23: c = new Shelfstacker(position, front, playerID); break; case 24: c = new Shoplifter(position, front, playerID); break; case 25: c = new Sporter(position, front, playerID); break; case 27: c = new Streamer(position, front, playerID); break; case 28: c = new SugarDaddy(position, front, playerID); break; case 29: c = new TaxiDriver(position, front, playerID); break; case 30: c = new Writer(position, front, playerID); break; case 26: c = new YogaInstructor(position, front, playerID); break; } } else { int cardsCount = 12; int rn = Globals.r.Next(cardsCount); switch (rn) { case 0: c = new Alcohol(position, front, playerID); break; case 1: c = new Drugs(position, front, playerID); break; case 2: c = new EatingOut(position, front, playerID); break; case 3: c = new FastFood(position, front, playerID); break; case 4: c = new Gambling(position, front, playerID); break; case 5: c = new Gaming(position, front, playerID); break; case 6: c = new Joint(position, front, playerID); break; case 7: c = new PomXML(position, front, playerID); break; case 8: c = new Shopping(position, front, playerID); break; case 9: c = new Smoking(position, front, playerID); break; case 10: c = new SocialMedia(position, front, playerID); break; case 11: c = new Streaming(position, front, playerID); break; } } return(c); }
public void StringIsNull() { var hacker = new Hacker(); hacker.Pangram(null); }
private void Awake() { Instance = this; }
public async Task Invoke(HttpContext context) { var path = context.Request.Path; Stopwatch watch = new Stopwatch(); watch.Start(); if (path.HasValue) { Debug("Defend Begin: " + path); // This handles load balancers passing the original client IP // through this header. // WARNING: If your load balancer is not passing original client IP // through this header, then you will be blocking your load balancer, // causing a total outage. Also ensure this Header cannot be spoofed. // Your load balancer should be configured in a way that it does not accept // this header from the request, instead it always sets it itself. var originIP = context.Connection.RemoteIpAddress; //if (context.Request.Headers.ContainsKey(XForwardedForHeader)) // originIP = IPAddress.Parse(context.Request.Headers[XForwardedForHeader]).MapToIPv4(); var result = Hacker.Result.Allowed; foreach (var key in _keys) { if (key.Method == context.Request.Method && key.Key == path) { Debug("Defend: " + path); if (key.Mode == HackerSprayOptionKey.HitCountMode.PerKey) { result = await Hacker.DefendAsync(path, originIP, key.Interval, key.MaxAttempts, TimeSpan.MaxValue, long.MaxValue, TimeSpan.MaxValue, long.MaxValue); if (result == Hacker.Result.TooManyHitsOnKey) { await Hacker.BlacklistKeyAsync(path, key.Interval); } } else if (key.Mode == HackerSprayOptionKey.HitCountMode.PerOrigin) { result = await Hacker.DefendAsync(path, originIP, TimeSpan.MaxValue, long.MaxValue, key.Interval, key.MaxAttempts, TimeSpan.MaxValue, long.MaxValue); if (result == Hacker.Result.TooManyHitsFromOrigin) { await Hacker.BlacklistOriginAsync(originIP, key.Interval); } } else //(key.Item5 == Mode.PerKeyOrigin) { result = await Hacker.DefendAsync(path, originIP, TimeSpan.MaxValue, long.MaxValue, TimeSpan.MaxValue, long.MaxValue, key.Interval, key.MaxAttempts); } Debug("Defend Result: " + Enum.GetName(typeof(Hacker.Result), result)); break; } } watch.Stop(); Debug("Defend End: " + path + " " + watch.ElapsedMilliseconds); if (result == Hacker.Result.Allowed) { await _next.Invoke(context); } else { Info("Blocked: " + path); context.Response.StatusCode = (int)HttpStatusCode.NotAcceptable; await context.Response.WriteAsync(Enum.GetName(typeof(Hacker.Result), result)); } //watch.Stop(); //Debug("Finished: " + path + " " + watch.ElapsedMilliseconds); } else { await _next.Invoke(context); } }
public void Update(Hacker hacker) { //bool updateTargetFlag = false; if (!infoGot) { //获取当前角色序号 index = hacker.GetIndex(); //获取地图尺寸 mapSize = hacker.GetMapInfo(); // 20 2 22 //获取地图 foreach (int x in Range(mapSize[0])) { List <List <int?> > nextX = new List <List <int?> >(); foreach (int y in Range(1, mapSize[1] + 1)) { List <int?> nextY = new List <int?>(); foreach (int z in Range(mapSize[2])) { nextY.Add(hacker.GetMapType(x, y, z)); } nextX.Add(nextY); } map.Add(nextX); } //获取钥匙位置 int[] temp = { 0, 0, 0 }; keysPosition.Add(temp); foreach (int i in Range(1, 4)) { string sOut = "Key" + i + " "; keysPosition.Add(hacker.GetKeysPosition(i)); sOut += keysPosition[i][0] + " " + keysPosition[i][1] + " " + keysPosition[i][2]; //logger.info(sOut); } //获取出口位置 foreach (int i in Range(4)) { string sOut = "Exit" + i + " "; exitPosition.Add(hacker.GetExitPosition(i)); sOut += exitPosition[i][0] + " " + exitPosition[i][1] + " " + exitPosition[i][2]; //logger.info(sOut); } //获取电梯位置 foreach (int i in Range(1, 3)) { string sOut = "Elevator" + i + " "; List <int[]> elevatorTemp = new List <int[]>(); int[] ele = hacker.GetElevatorPosition(i); int[] eleF1 = { ele[0], 1, ele[1] }; int[] eleF2 = { ele[0], 2, ele[1] }; elevatorTemp.Add(eleF1); elevatorTemp.Add(eleF2); elevatorPosition.Add(elevatorTemp); sOut += elevatorPosition[i - 1][0][0] + " " + elevatorPosition[i - 1][0][1] + " " + elevatorPosition[i - 1][0][2] + "\n"; sOut += elevatorPosition[i - 1][1][0] + " " + elevatorPosition[i - 1][1][1] + " " + elevatorPosition[i - 1][1][2] + "\n"; //logger.info(sOut); } //获取逃跑者位置 foreach (int i in Range(1, 4)) { hackerPosition.Add(hacker.HackerPosition(i)); } //估计抓捕者位置 policePosition = exitPosition[0]; //updateTargetFlag = true; selfPosition = hacker.GetPosition(); target = ChooseTargetV2(); infoGot = true; //LOG /* * logger.info("index " + index); * logger.info("mapSize " + mapSize[0] + " " + mapSize[1] + " " + mapSize[2] + " "); * * for (int z = mapSize[2] - 1; z >= 0; z--) * { * string sOut = "[1]"; * for (int x = 0; x < mapSize[0]; x++) * { * sOut += map[x][0][z].ToString() + ","; * } * logger.info(sOut); * } * logger.info(" "); * * for (int z = mapSize[2] - 1; z >= 0; z--) * { * string sOut = "[2]"; * for (int x = 0; x < mapSize[0]; x++) * { * sOut += map[x][1][z].ToString() + ","; * } * logger.info(sOut); * } * logger.info(" "); */ //初始化 selfPosition = hacker.GetPosition(); string log2 = "POINTLIST "; pointList = SearchShortest(); foreach (int[] point in pointList) { log2 += "(" + point[0] + ", " + point[1] + ", " + point[2] + ") "; } //logger.info(log2); } //实时更新逃跑者位置与抓捕者(可能的)位置 foreach (int i in Range(1, 4)) { int[] tempPosition = hacker.HackerPosition(i); if ((tempPosition == null) && (hackerPosition[i - 1] != null)) { bool someoneIsArrestedTemp = true; foreach (int j in Range(4)) { if (FindWayWholeMap(hackerPosition[i - 1], exitPosition[j]).Count <= 1) { someoneIsArrestedTemp = false; } //logger.info("DISTANCE[" + j + "]: " + FindWayWholeMap(hackerPosition[i - 1], exitPosition[j]).Count); } if (someoneIsArrestedTemp) { policePosition = hackerPosition[i - 1]; someoneIsArrested = true; //updateTargetFlag = true; if (myKey != 0) { target = ChooseTargetV2(); } //logger.info("Hacker " + i + " is arrested! PolicePosition: (" + policePosition[0] + ", " + policePosition[1] + ", " + policePosition[2] + "), " + "policePositionUpdateSteps: " + policePositionUpdateSteps); } } hackerPosition[i - 1] = hacker.HackerPosition(i); } if (hacker.Warning()) { int[] policeNewPosition = hacker.GetPolicePosition(); if (!(policeNewPosition[0] == policePosition[0] && policeNewPosition[1] == policePosition[1] && policeNewPosition[2] == policePosition[2])) { target = ChooseTargetV2(); } policePosition = hacker.GetPolicePosition(); //updateTargetFlag = true; //target = ChooseTargetV2(); policePositionUpdateSteps = 0; //logger.info("Warning! PolicePosition: (" + policePosition[0] + ", " + policePosition[1] + ", " + policePosition[2] + ")" + ", SelfPosition: (" + selfPosition[0] + ", " + selfPosition[1] + ", " + selfPosition[2] + "), " + "policePositionUpdateSteps: " + policePositionUpdateSteps); } //实时更新自己拥有的钥匙 int newMyKey = hacker.haveKey(); if ((myKey == 0) && (newMyKey != 0)) { //logger.info("GET KEY " + newMyKey + "!"); //updateTargetFlag = true; myKey = newMyKey; target = ChooseTargetV2(); } myKey = newMyKey; if (!hacker.isMoving())//不在移动 { selfPosition = hacker.GetPosition(); if (FindWaySafe(selfPosition, target).Count == 0) { target = ChooseTargetV2(); } //int[] target = ChooseTarget(); /* * if (updateTargetFlag == true) * { * target = ChooseTargetV2(); * } */ track = FindWaySafe(selfPosition, target); if (track.Count > 0) { switch (track[0].direction) { case "U": hacker.MoveNorth(); break; case "D": hacker.MoveSouth(); break; case "L": hacker.MoveWest(); break; case "R": hacker.MoveEast(); break; } track.Remove(track[0]); } int timeRest = hacker.GetGameTime(); //logger.info("timeRest: " + timeRest); if (!hacker.Warning()) { policePositionUpdateSteps += 1; } } }
public bool PostHacker([FromBody] Hacker hacker) { return(this.HackerService.AddHacker(hacker)); }