public static bool ProcessBlockChange(GameManager __instance, PlatformUserIdentifierAbs _persistentPlayerId, List <BlockChangeInfo> _blocksToChange) { try { if (__instance != null && _persistentPlayerId != null && _blocksToChange != null) { ClientInfo cInfo = PersistentOperations.GetClientInfoFromUId(_persistentPlayerId); if (cInfo != null) { EntityPlayer player = PersistentOperations.GetEntityPlayer(cInfo.entityId); if (player != null) { World world = __instance.World; for (int i = 0; i < _blocksToChange.Count; i++) { BlockChangeInfo newBlockInfo = _blocksToChange[i]; //new block info BlockValue oldBlockValue = world.GetBlock(newBlockInfo.pos); //old block value Block oldBlock = oldBlockValue.Block; if (newBlockInfo != null && oldBlock != null && newBlockInfo.bChangeBlockValue) //has new block value { Block newBlock = newBlockInfo.blockValue.Block; if (newBlock != null) { if (newBlock is BlockSleepingBag)//placed a sleeping bag { if (POIProtection.IsEnabled && POIProtection.Bed && world.IsPositionWithinPOI(newBlockInfo.pos.ToVector3(), 8)) { GameManager.Instance.World.SetBlockRPC(newBlockInfo.pos, BlockValue.Air); PersistentOperations.ReturnBlock(cInfo, newBlock.GetBlockName(), 1); Phrases.Dict.TryGetValue("POI1", out string phrase); ChatHook.ChatMessage(cInfo, Config.Chat_Response_Color + phrase + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); return(false); } } else if (newBlock is BlockLandClaim)//placed a land claim { if (POIProtection.IsEnabled && POIProtection.Claim && world.IsPositionWithinPOI(newBlockInfo.pos.ToVector3(), 5)) { GameManager.Instance.World.SetBlockRPC(newBlockInfo.pos, BlockValue.Air); PersistentOperations.ReturnBlock(cInfo, newBlock.GetBlockName(), 1); Phrases.Dict.TryGetValue("POI2", out string _phrase); ChatHook.ChatMessage(cInfo, Config.Chat_Response_Color + _phrase + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); return(false); } } if (BlockLogger.IsEnabled && !_blocksToChange[i].blockValue.Equals(BlockValue.Air)) { BlockLogger.PlacedBlock(cInfo, newBlock, newBlockInfo.pos); } } if (oldBlockValue.Block is BlockTrapDoor) { return(true); } else if (newBlockInfo.blockValue.Equals(BlockValue.Air.type))//new block is air { if (oldBlockValue.Block is BlockLandClaim) { if (PersistentOperations.ClaimedByWho(_persistentPlayerId, newBlockInfo.pos) == EnumLandClaimOwner.None) { if (DamageDetector.IsEnabled) { int total = oldBlock.MaxDamage - oldBlockValue.damage; if (total >= DamageDetector.Block_Damage_Limit && (GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.PlatformId) > Admin_Level && GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.CrossplatformId) > Admin_Level)) { Penalty(total, player, cInfo); return(false); } } if (BlockLogger.IsEnabled) { BlockLogger.BrokeBlock(cInfo, oldBlock, newBlockInfo.pos); } int slot = player.inventory.holdingItemIdx; ItemValue itemValue = cInfo.latestPlayerData.inventory[slot].itemValue; if (itemValue != null && InfiniteAmmo.IsEnabled && itemValue.ItemClass.IsGun() && InfiniteAmmo.Exec(cInfo, player, slot, itemValue)) { return(false); } } else if (BlockLogger.IsEnabled) { BlockLogger.RemovedBlock(cInfo, oldBlock, newBlockInfo.pos); } } else if (!oldBlock.CanPickup)//old block can not be picked up { if (PersistentOperations.ClaimedByWho(_persistentPlayerId, newBlockInfo.pos) == EnumLandClaimOwner.None) { if (DamageDetector.IsEnabled) { int total = oldBlock.MaxDamage - oldBlockValue.damage; if (total >= DamageDetector.Block_Damage_Limit && (GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.PlatformId) > Admin_Level && GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.CrossplatformId) > Admin_Level)) { Penalty(total, player, cInfo); return(false); } } } if (BlockLogger.IsEnabled) { BlockLogger.RemovedBlock(cInfo, oldBlock, newBlockInfo.pos); } } } else if (oldBlock.blockID == newBlock.blockID) //block is the same { if (newBlockInfo.bChangeDamage) //block took damage { if (DamageDetector.IsEnabled) { int total = newBlockInfo.blockValue.damage - oldBlockValue.damage; if (total >= DamageDetector.Block_Damage_Limit && (GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.PlatformId) > Admin_Level && GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.CrossplatformId) > Admin_Level)) { Penalty(total, player, cInfo); return(false); } } int slot = player.inventory.holdingItemIdx; ItemValue itemValue = cInfo.latestPlayerData.inventory[slot].itemValue; if (itemValue != null && InfiniteAmmo.IsEnabled && itemValue.ItemClass.IsGun() && InfiniteAmmo.Exec(cInfo, player, slot, itemValue)) { return(false); } } } else if (oldBlock.DowngradeBlock.Block.blockID == newBlock.blockID)//downgraded { if (oldBlockValue.damage == newBlockInfo.blockValue.damage || newBlockInfo.blockValue.damage == 0) { if (BlockLogger.IsEnabled) { BlockLogger.DowngradedBlock(cInfo, oldBlock, newBlock, newBlockInfo.pos); } return(true); } if (DamageDetector.IsEnabled) { int total = oldBlock.MaxDamage - oldBlockValue.damage + newBlockInfo.blockValue.damage; if (total >= DamageDetector.Block_Damage_Limit && (GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.PlatformId) > Admin_Level && GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.CrossplatformId) > Admin_Level)) { Penalty(total, player, cInfo); return(false); } } int slot = player.inventory.holdingItemIdx; ItemValue itemValue = cInfo.latestPlayerData.inventory[slot].itemValue; if (itemValue != null && InfiniteAmmo.IsEnabled && itemValue.ItemClass.IsGun() && InfiniteAmmo.Exec(cInfo, player, slot, itemValue)) { return(false); } } } } } } } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in BlockChange.ProcessBlockChange: {0}", e.Message)); } return(true); }
public static bool Exec(NetPackageDamageEntity __instance) { try { Entity victim = PersistentOperations.GetEntity(entityId(__instance)); if (victim != null) { Entity attacker = PersistentOperations.GetEntity(attackerEntityId(__instance)); if (attacker != null) { if (victim is EntityPlayer) { ClientInfo cInfoVictim = PersistentOperations.GetClientInfoFromEntityId(victim.entityId); if (cInfoVictim != null) { EntityPlayer victimPlayer = victim as EntityPlayer; if (attacker is EntityPlayer) { ClientInfo cInfoAttacker = PersistentOperations.GetClientInfoFromEntityId(attacker.entityId); if (cInfoAttacker != null) { EntityPlayer attackingPlayer = attacker as EntityPlayer; if (attackingItem(__instance) != null) { if (DamageDetector.IsEnabled && !DamageDetector.IsValidPvP(victim as EntityPlayer, cInfoAttacker, strength(__instance), attackingItem(__instance))) { return(true); } if (InfiniteAmmo.IsEnabled && attackingItem(__instance).ItemClass.IsGun()) { int slot = attackingPlayer.inventory.holdingItemIdx; if (InfiniteAmmo.Exec(cInfoAttacker, attackingPlayer, slot, attackingItem(__instance))) { return(true); } } } else { return(true); } if (NewPlayerProtection.IsEnabled) { if (NewPlayerProtection.IsProtected(victimPlayer)) { Phrases.Dict.TryGetValue("NewPlayerProtection2", out string phrase); ChatHook.ChatMessage(cInfoAttacker, Config.Chat_Response_Color + phrase + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); return(true); } else if (NewPlayerProtection.IsProtected(attackingPlayer)) { Phrases.Dict.TryGetValue("NewPlayerProtection1", out string phrase); ChatHook.ChatMessage(cInfoVictim, Config.Chat_Response_Color + phrase + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); return(true); } } //if (Zones.IsEnabled && !Zones.IsValid(cInfoVictim, cInfoAttacker)) //{ // return true; //} if (Lobby.IsEnabled && Lobby.PvE && (Lobby.LobbyPlayers.Contains(victimPlayer.entityId) || Lobby.LobbyPlayers.Contains(attackingPlayer.entityId))) { Lobby.PvEViolation(cInfoAttacker); return(true); } if (Market.IsEnabled && Market.PvE && (Market.MarketPlayers.Contains(victimPlayer.entityId) || Market.MarketPlayers.Contains(attackingPlayer.entityId))) { Market.PvEViolation(cInfoAttacker); return(true); } float distance = attackingPlayer.GetDistance(victimPlayer); using (StreamWriter sw = new StreamWriter(Filepath, true, Encoding.UTF8)) { sw.WriteLine(string.Format("{0}: '{1}' '{2}' named '{3}' @ '{4}' hit '{5}' '{6}' named '{7}' @ '{8}' using '{9}' for '{10}' damage. Distance '{11}'", DateTime.Now, cInfoAttacker.PlatformId.CombinedString, cInfoAttacker.CrossplatformId.CombinedString, cInfoAttacker.playerName, cInfoAttacker.latestPlayerData.ecd.pos, cInfoVictim.PlatformId.CombinedString, cInfoVictim.CrossplatformId.CombinedString, cInfoVictim.playerName, cInfoVictim.latestPlayerData.ecd.pos, attackingItem(__instance).ItemClass.GetLocalizedItemName() ?? attackingItem(__instance).ItemClass.GetItemName(), strength(__instance), distance)); sw.WriteLine(); sw.Flush(); sw.Close(); } if (bFatal(__instance) && victimPlayer.IsAlive() && lastEntityKilled != victimPlayer.entityId) { lastEntityKilled = victimPlayer.entityId; if (KillNotice.IsEnabled && KillNotice.PvP) { KillNotice.PlayerKilledPlayer(cInfoVictim, victimPlayer, cInfoAttacker, attackingPlayer, attackingItem(__instance), strength(__instance)); } if (Bounties.IsEnabled) { Bounties.PlayerKilled(victimPlayer, attackingPlayer, cInfoVictim, cInfoAttacker); } if (Wallet.IsEnabled && Wallet.PVP && Wallet.Player_Kill > 0) { Wallet.AddCurrency(cInfoAttacker.CrossplatformId.CombinedString, Wallet.Player_Kill); } if (MagicBullet.IsEnabled && !MagicBullet.Kill.Contains(cInfoAttacker.entityId)) { MagicBullet.Kill.Add(cInfoAttacker.entityId); } } } } else if (attacker is EntityZombie) { if (NewPlayerProtection.IsEnabled && NewPlayerProtection.IsProtected(victimPlayer)) { return(true); } if (KillNotice.IsEnabled && KillNotice.Zombie_Kills) { int[] attack = new int[] { attacker.entityId, strength(__instance) }; if (KillNotice.Damage.ContainsKey(victim.entityId)) { KillNotice.Damage[victim.entityId] = attack; } else { KillNotice.Damage.Add(victim.entityId, attack); } } } else if (attacker is EntityAnimal) { if (NewPlayerProtection.IsEnabled && NewPlayerProtection.IsProtected(victimPlayer)) { return(true); } if (KillNotice.IsEnabled && KillNotice.Animal_Kills) { int[] attack = new int[] { attacker.entityId, strength(__instance) }; if (KillNotice.Damage.ContainsKey(victim.entityId)) { KillNotice.Damage[victim.entityId] = attack; } else { KillNotice.Damage.Add(victim.entityId, attack); } } } } } else if (victim is EntityZombie && attacker is EntityPlayer) { ClientInfo cInfoAttacker = PersistentOperations.GetClientInfoFromEntityId(attacker.entityId); if (cInfoAttacker != null) { EntityPlayer attackingPlayer = attacker as EntityPlayer; if (attackingItem(__instance) != null) { if (DamageDetector.IsEnabled && !DamageDetector.IsValidEntityDamage(attackingPlayer, cInfoAttacker, strength(__instance), attackingItem(__instance))) { return(true); } if (InfiniteAmmo.IsEnabled && attackingItem(__instance).ItemClass.IsGun()) { int slot = attackingPlayer.inventory.holdingItemIdx; if (InfiniteAmmo.Exec(cInfoAttacker, attackingPlayer, slot, attackingItem(__instance))) { return(true); } } if (bFatal(__instance) && victim.IsAlive() && lastEntityKilled != victim.entityId) { lastEntityKilled = victim.entityId; if (Wallet.IsEnabled && Wallet.Zombie_Kill > 0) { Wallet.AddCurrency(cInfoAttacker.CrossplatformId.CombinedString, Wallet.Zombie_Kill); } if (BloodmoonWarrior.IsEnabled && BloodmoonWarrior.BloodmoonStarted && BloodmoonWarrior.WarriorList.Contains(cInfoAttacker.entityId)) { if (BloodmoonWarrior.KilledZombies.TryGetValue(cInfoAttacker.entityId, out int killedZ)) { BloodmoonWarrior.KilledZombies[cInfoAttacker.entityId] += 1; } else { BloodmoonWarrior.KilledZombies.Add(cInfoAttacker.entityId, 1); } } } } else { return(true); } if (PersistentOperations.IsBloodmoon() && Market.IsEnabled && Market.MarketPlayers.Contains(cInfoAttacker.entityId)) { Phrases.Dict.TryGetValue("Market12", out string phrase); ChatHook.ChatMessage(cInfoAttacker, Config.Chat_Response_Color + phrase + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); return(true); } if (PersistentOperations.IsBloodmoon() && Lobby.IsEnabled && Lobby.LobbyPlayers.Contains(cInfoAttacker.entityId)) { Phrases.Dict.TryGetValue("Lobby12", out string phrase); ChatHook.ChatMessage(cInfoAttacker, Config.Chat_Response_Color + phrase + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); return(true); } int distance = (int)attackingPlayer.GetDistance(victim); using (StreamWriter sw = new StreamWriter(Filepath, true, Encoding.UTF8)) { sw.WriteLine(string.Format("{0}: '{1}' '{2}' named '{3}' @ '{4}' hit '{5}' named '{6}' @ '{7}' using '{8}' for '{9}' damage. Distance '{10}'", DateTime.Now, cInfoAttacker.PlatformId.CombinedString, cInfoAttacker.CrossplatformId.CombinedString, cInfoAttacker.playerName, cInfoAttacker.latestPlayerData.ecd.pos, victim.entityId, victim.EntityClass.entityClassName, victim.position, attackingItem(__instance).ItemClass.GetLocalizedItemName() ?? attackingItem(__instance).ItemClass.GetItemName(), strength(__instance), distance)); sw.WriteLine(); sw.Flush(); sw.Close(); } } } else if (victim is EntityAnimal && attacker is EntityPlayer) { ClientInfo cInfoAttacker = PersistentOperations.GetClientInfoFromEntityId(attacker.entityId); if (cInfoAttacker != null) { EntityPlayer attackingPlayer = attacker as EntityPlayer; if (attackingItem(__instance) != null) { if (DamageDetector.IsEnabled && !DamageDetector.IsValidEntityDamage(attackingPlayer, cInfoAttacker, strength(__instance), attackingItem(__instance))) { return(true); } if (InfiniteAmmo.IsEnabled && attackingItem(__instance).ItemClass.IsGun()) { int slot = attackingPlayer.inventory.holdingItemIdx; if (InfiniteAmmo.Exec(cInfoAttacker, attackingPlayer, slot, attackingItem(__instance))) { return(true); } } } } } } } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in ProcessDamage.Exec: {0}", e.Message)); } return(false); }