Exemple #1
0
 public static void FriendInvite(ClientInfo _cInfo, Vector3 _position, string _destination)
 {
     try
     {
         int          x      = (int)_position.x;
         int          y      = (int)_position.y;
         int          z      = (int)_position.z;
         EntityPlayer player = PersistentOperations.GetEntityPlayer(_cInfo.entityId);
         if (player != null)
         {
             List <ClientInfo> clientList = PersistentOperations.ClientList();
             if (clientList != null)
             {
                 for (int i = 0; i < clientList.Count; i++)
                 {
                     ClientInfo   cInfo2  = clientList[i];
                     EntityPlayer player2 = PersistentOperations.GetEntityPlayer(cInfo2.entityId);
                     if (player2 != null)
                     {
                         if (player.IsFriendsWith(player2) && player.GetDistance(player2) <= 25)
                         {
                             Phrases.Dict.TryGetValue("Homes14", out string phrase);
                             phrase = phrase.Replace("{PlayerName}", _cInfo.playerName);
                             phrase = phrase.Replace("{Command_Prefix1}", ChatHook.Chat_Command_Prefix1);
                             phrase = phrase.Replace("{Command_go}", Command_go);
                             ChatHook.ChatMessage(cInfo2, Config.Chat_Response_Color + phrase + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
                             Phrases.Dict.TryGetValue("Homes15", out phrase);
                             phrase = phrase.Replace("{PlayerName}", cInfo2.playerName);
                             ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + phrase + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
                             if (Invite.ContainsKey(cInfo2.entityId))
                             {
                                 Invite.Remove(cInfo2.entityId);
                                 FriendPosition.Remove(cInfo2.entityId);
                             }
                             Invite.Add(cInfo2.entityId, DateTime.Now);
                             FriendPosition.Add(cInfo2.entityId, _destination);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in Homes.FriendInvite: {0}", e.Message));
     }
 }
Exemple #2
0
 public static bool ProcessEntityDamage(EntityAlive __instance, DamageResponse _dmResponse)
 {
     try
     {
         if (__instance != null && _dmResponse.Source != null && _dmResponse.Strength > 1)
         {
             if (__instance is EntityPlayer player)
             {
                 EntityPlayer _player1  = player;
                 int          _sourceId = _dmResponse.Source.getEntityId();
                 if (_sourceId > 0 && _player1.entityId != _sourceId)
                 {
                     ClientInfo _cInfo2 = PersistentOperations.GetClientInfoFromEntityId(_sourceId);
                     if (_cInfo2 != null)
                     {
                         EntityPlayer _player2 = PersistentOperations.GetEntityPlayer(_cInfo2.playerId);
                         if (_player2 != null)
                         {
                             if (IsEnabled)
                             {
                                 ItemValue _itemValue = ItemClass.GetItem(_player2.inventory.holdingItem.Name, false);
                                 if (_itemValue != null)
                                 {
                                     int _distance = (int)_player2.GetDistance(__instance);
                                     using (StreamWriter sw = new StreamWriter(filepath, true, Encoding.UTF8))
                                     {
                                         sw.WriteLine(string.Format("{0}: {1} \"{2}\" hit \"{3}\" with entity id {4} using {5} for {6} damage @ {7}. Distance: {8}", DateTime.Now, _cInfo2.playerId, _cInfo2.playerName, __instance.EntityName, __instance.entityId, _itemValue.ItemClass.GetLocalizedItemName() ?? _itemValue.ItemClass.GetItemName(), _dmResponse.Strength, __instance.position, _distance));
                                         sw.WriteLine();
                                         sw.Flush();
                                         sw.Close();
                                     }
                                     if (_dmResponse.Strength >= Player_Damage_Limit && GameManager.Instance.adminTools.GetUserPermissionLevel(_cInfo2) > Admin_Level)
                                     {
                                         Phrases.Dict.TryGetValue(952, out string _phrase952);
                                         SdtdConsole.Instance.ExecuteSync(string.Format("ban add {0} 5 years \"{1} {2}\"", _cInfo2.playerId, _phrase952, _dmResponse.Strength), null);
                                         using (StreamWriter sw = new StreamWriter(detectionFilepath, true, Encoding.UTF8))
                                         {
                                             sw.WriteLine(string.Format("Detected \"{0}\" Steam Id {1}, exceeded damage limit @ {2}. Damage: {3}", _cInfo2.playerName, _cInfo2.playerId, __instance.position, _dmResponse.Strength));
                                             sw.WriteLine();
                                             sw.Flush();
                                             sw.Close();
                                         }
                                         Phrases.Dict.TryGetValue(951, out string _phrase951);
                                         _phrase951 = _phrase951.Replace("{PlayerName}", _cInfo2.playerName);
                                         ChatHook.ChatMessage(null, Config.Chat_Response_Color + _phrase951 + "[-]", -1, Config.Server_Response_Name, EChatType.Global, null);
                                         return(false);
                                     }
                                 }
                             }
                             if (Zones.IsEnabled && (Zones.ZonePvE.Contains(__instance.entityId) || Zones.ZonePvE.Contains(_cInfo2.entityId)))
                             {
                                 Phrases.Dict.TryGetValue(323, out string _phrase323);
                                 ChatHook.ChatMessage(_cInfo2, Config.Chat_Response_Color + _phrase323 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
                                 if (!_player1.IsFriendsWith(_player2))
                                 {
                                     if (PersistentOperations.PvEViolations.ContainsKey(_cInfo2.entityId))
                                     {
                                         PersistentOperations.PvEViolations.TryGetValue(_cInfo2.entityId, out int _violations);
                                         _violations++;
                                         PersistentOperations.PvEViolations[_cInfo2.entityId] = _violations;
                                         if (PersistentOperations.Jail_Violation > 0 && _violations == PersistentOperations.Jail_Violation)
                                         {
                                             Jail(_cInfo2, __instance);
                                         }
                                         if (PersistentOperations.Kill_Violation > 0 && _violations == PersistentOperations.Kill_Violation)
                                         {
                                             Kill(_cInfo2);
                                         }
                                         if (PersistentOperations.Kick_Violation > 0 && _violations == PersistentOperations.Kick_Violation)
                                         {
                                             Kick(_cInfo2);
                                         }
                                         if (PersistentOperations.Ban_Violation > 0 && _violations == PersistentOperations.Ban_Violation)
                                         {
                                             Ban(_cInfo2);
                                         }
                                     }
                                     else
                                     {
                                         PersistentOperations.PvEViolations.Add(_cInfo2.entityId, 1);
                                     }
                                 }
                                 return(false);
                             }
                             if ((Lobby.IsEnabled && Lobby.PvE && Lobby.LobbyPlayers.Contains(__instance.entityId)) || (Market.IsEnabled && Market.PvE && Market.MarketPlayers.Contains(__instance.entityId)))
                             {
                                 Phrases.Dict.TryGetValue(260, out string _phrase260);
                                 ChatHook.ChatMessage(_cInfo2, Config.Chat_Response_Color + _phrase260 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
                                 if (!_player1.IsFriendsWith(_player2))
                                 {
                                     if (PersistentOperations.PvEViolations.ContainsKey(_cInfo2.entityId))
                                     {
                                         PersistentOperations.PvEViolations.TryGetValue(_cInfo2.entityId, out int _violations);
                                         _violations++;
                                         PersistentOperations.PvEViolations[_cInfo2.entityId] = _violations;
                                         if (PersistentOperations.Jail_Violation > 0 && _violations == PersistentOperations.Jail_Violation)
                                         {
                                             Jail(_cInfo2, __instance);
                                         }
                                         if (PersistentOperations.Kill_Violation > 0 && _violations == PersistentOperations.Kill_Violation)
                                         {
                                             Kill(_cInfo2);
                                         }
                                         if (PersistentOperations.Kick_Violation > 0 && _violations == PersistentOperations.Kick_Violation)
                                         {
                                             Kick(_cInfo2);
                                         }
                                         else if (PersistentOperations.Ban_Violation > 0 && _violations == PersistentOperations.Ban_Violation)
                                         {
                                             Ban(_cInfo2);
                                         }
                                     }
                                     else
                                     {
                                         PersistentOperations.PvEViolations.Add(_cInfo2.entityId, 1);
                                     }
                                 }
                                 return(false);
                             }
                             if (KillNotice.IsEnabled && KillNotice.Show_Damage && KillNotice.PvP)
                             {
                                 if (KillNotice.Damage.ContainsKey(_player1.entityId))
                                 {
                                     KillNotice.Damage[_player1.entityId] = _dmResponse.Strength;
                                 }
                                 else
                                 {
                                     KillNotice.Damage.Add(_player1.entityId, _dmResponse.Strength);
                                 }
                             }
                         }
                     }
                 }
             }
             else if (IsEnabled && __instance is EntityZombie)
             {
                 int _sourceId = _dmResponse.Source.getEntityId();
                 if (_sourceId > 0)
                 {
                     ClientInfo _cInfo = PersistentOperations.GetClientInfoFromEntityId(_sourceId);
                     if (_cInfo != null)
                     {
                         EntityPlayer _player = PersistentOperations.GetEntityPlayer(_cInfo.playerId);
                         if (_player != null)
                         {
                             ItemValue _itemValue = ItemClass.GetItem(_player.inventory.holdingItem.Name, false);
                             if (_itemValue != null)
                             {
                                 int _distance = (int)_player.GetDistance(__instance);
                                 using (StreamWriter sw = new StreamWriter(filepath, true, Encoding.UTF8))
                                 {
                                     sw.WriteLine(string.Format("{0}: {1} \"{2}\" hit \"{3}\" with entity id {4} using {5} for {6} damage @ {7}. Distance: {8}", DateTime.Now, _cInfo.playerId, _cInfo.playerName, __instance.EntityName, __instance.entityId, _itemValue.ItemClass.GetLocalizedItemName() ?? _itemValue.ItemClass.GetItemName(), _dmResponse.Strength, __instance.position, _distance));
                                     sw.WriteLine();
                                     sw.Flush();
                                     sw.Close();
                                 }
                                 if (_dmResponse.Strength >= Entity_Damage_Limit && GameManager.Instance.adminTools.GetUserPermissionLevel(_cInfo) > Admin_Level)
                                 {
                                     Phrases.Dict.TryGetValue(952, out string _phrase952);
                                     SdtdConsole.Instance.ExecuteSync(string.Format("ban add {0} 5 years \"{1} {2}\"", _cInfo.playerId, _phrase952, _dmResponse.Strength), null);
                                     using (StreamWriter sw = new StreamWriter(detectionFilepath, true, Encoding.UTF8))
                                     {
                                         sw.WriteLine(string.Format("Detected \"{0}\" Steam Id {1}, exceeded damage limit @ {2}. Damage: {3}", _cInfo.playerName, _cInfo.playerId, __instance.position, _dmResponse.Strength));
                                         sw.WriteLine();
                                         sw.Flush();
                                         sw.Close();
                                     }
                                     Phrases.Dict.TryGetValue(951, out string _phrase951);
                                     _phrase951 = _phrase951.Replace("{PlayerName}", _cInfo.playerName);
                                     ChatHook.ChatMessage(null, Config.Chat_Response_Color + _phrase951 + "[-]", -1, Config.Server_Response_Name, EChatType.Global, null);
                                     return(false);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in ProcessDamage.ProcessEntityDamage: {0}", e.Message));
     }
     return(true);
 }
Exemple #3
0
 public static bool ProcessPlayerDamage(EntityAlive __instance, DamageResponse _dmResponse)
 {
     try
     {
         if (__instance != null && __instance is EntityPlayer && _dmResponse.Source != null)
         {
             int _sourceId = _dmResponse.Source.getEntityId();
             if (_sourceId > 0)
             {
                 ClientInfo _cInfo = PersistentOperations.GetClientInfoFromEntityId(_sourceId);
                 if (_cInfo != null)
                 {
                     EntityPlayer _player2 = PersistentOperations.GetEntityPlayer(_cInfo.playerId);
                     if (_player2 != null)
                     {
                         if (Damage_Detector)
                         {
                             ItemValue _itemValue = ItemClass.GetItem(_player2.inventory.holdingItem.Name, true);
                             if (_itemValue != null)
                             {
                                 int _distance = (int)_player2.GetDistance(__instance);
                                 using (StreamWriter sw = new StreamWriter(filepath, true))
                                 {
                                     sw.WriteLine(string.Format("{0}: {1} {2} hit {3} with entity id {4} using {5} for {6} damage @ {7}. Distance: {8}", DateTime.Now, _cInfo.playerId, _cInfo.playerName, __instance.EntityName, __instance.entityId, _itemValue.ItemClass.GetLocalizedItemName() ?? _itemValue.ItemClass.GetItemName(), _dmResponse.Strength, __instance.position, _distance));
                                     sw.WriteLine();
                                     sw.Flush();
                                     sw.Close();
                                 }
                                 if (_dmResponse.Strength >= Entity_Damage_Limit && GameManager.Instance.adminTools.GetUserPermissionLevel(_cInfo) > Admin_Level)
                                 {
                                     string _message = "[FF0000]{PlayerName} has been banned for using damage manipulation.";
                                     _message = _message.Replace("{PlayerName}", _cInfo.playerName);
                                     ChatHook.ChatMessage(null, LoadConfig.Chat_Response_Color + _message + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Global, null);
                                     SdtdConsole.Instance.ExecuteSync(string.Format("ban add {0} 5 years \"Auto detection has banned you for using damage manipulation. Damage recorded: {1}\"", _cInfo.playerId, _dmResponse.Strength), (ClientInfo)null);
                                     using (StreamWriter sw = new StreamWriter(_detectionFilepath, true))
                                     {
                                         sw.WriteLine(string.Format("Detected {0}, Steam Id {1}, using damage manipulation @ {2}. Damage recorded: {3}", _cInfo.playerName, _cInfo.playerId, __instance.position, _dmResponse.Strength));
                                         sw.WriteLine();
                                         sw.Flush();
                                         sw.Close();
                                     }
                                     return(false);
                                 }
                             }
                         }
                         if (Zones.IsEnabled)
                         {
                             if (Zones.ZonePvE.Contains(__instance.entityId) || Zones.ZonePvE.Contains(_cInfo.entityId))
                             {
                                 ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + "Do not attack players inside a pve zone or while standing in one!" + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
                                 EntityPlayer _player1 = (EntityPlayer)__instance;
                                 if (_player1 != null)
                                 {
                                     if (!_player1.IsFriendsWith(_player2))
                                     {
                                         if (PersistentOperations.PvEViolations.ContainsKey(_cInfo.entityId))
                                         {
                                             PersistentOperations.PvEViolations.TryGetValue(_cInfo.entityId, out int _flags);
                                             _flags++;
                                             if (PersistentOperations.Jail_Violation > 0 && _flags >= PersistentOperations.Jail_Violation)
                                             {
                                                 Jail(_cInfo, __instance);
                                             }
                                             if (PersistentOperations.Kill_Violation > 0 && _flags >= PersistentOperations.Kill_Violation)
                                             {
                                                 Kill(_cInfo);
                                             }
                                             if (PersistentOperations.Kick_Violation > 0 && _flags >= PersistentOperations.Kick_Violation)
                                             {
                                                 Kick(_cInfo);
                                             }
                                             if (PersistentOperations.Ban_Violation > 0 && _flags >= PersistentOperations.Ban_Violation)
                                             {
                                                 Ban(_cInfo);
                                             }
                                         }
                                         else
                                         {
                                             PersistentOperations.PvEViolations.Add(_cInfo.entityId, 1);
                                         }
                                     }
                                 }
                                 return(false);
                             }
                         }
                         if (Lobby.IsEnabled && Lobby.PvE && Lobby.LobbyPlayers.Contains(__instance.entityId) || Market.IsEnabled && Market.PvE && Market.MarketPlayers.Contains(__instance.entityId))
                         {
                             ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + "Do not attack players inside the lobby or market!" + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
                             EntityPlayer _player1 = (EntityPlayer)__instance;
                             if (_player1 != null)
                             {
                                 if (!_player1.IsFriendsWith(_player2))
                                 {
                                     if (PersistentOperations.PvEViolations.ContainsKey(_cInfo.entityId))
                                     {
                                         PersistentOperations.PvEViolations.TryGetValue(_cInfo.entityId, out int _violations);
                                         _violations++;
                                         if (PersistentOperations.Jail_Violation > 0 && _violations >= PersistentOperations.Jail_Violation)
                                         {
                                             Jail(_cInfo, __instance);
                                         }
                                         if (PersistentOperations.Kill_Violation > 0 && _violations >= PersistentOperations.Kill_Violation)
                                         {
                                             Kill(_cInfo);
                                         }
                                         if (PersistentOperations.Kick_Violation > 0 && _violations >= PersistentOperations.Kick_Violation)
                                         {
                                             Kick(_cInfo);
                                         }
                                         else if (PersistentOperations.Ban_Violation > 0 && _violations >= PersistentOperations.Ban_Violation)
                                         {
                                             Ban(_cInfo);
                                         }
                                     }
                                     else
                                     {
                                         PersistentOperations.PvEViolations.Add(_cInfo.entityId, 1);
                                     }
                                 }
                             }
                             return(false);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in ProcessDamage.ProcessPlayerDamage: {0}", e.Message));
     }
     return(true);
 }
Exemple #4
0
 public static void Exec()
 {
     try
     {
         if (GameManager.Instance.World != null && GameManager.Instance.World.Players.Count > 0 && GameManager.Instance.World.Players.dict.Count > 0)
         {
             List <ClientInfo> _cInfoList = PersistentOperations.ClientList();
             if (_cInfoList != null && _cInfoList.Count > 0)
             {
                 for (int i = 0; i < _cInfoList.Count; i++)
                 {
                     ClientInfo _cInfo = _cInfoList[i];
                     if (_cInfo != null && _cInfo.playerId != null)
                     {
                         EntityPlayer _player = PersistentOperations.GetEntityPlayer(_cInfo.playerId);
                         if (_player != null)
                         {
                             int _userPermissionLevel = GameManager.Instance.adminTools.GetUserPermissionLevel(_cInfo);
                             if (SpectatorEnabled && _userPermissionLevel > Spectator_Admin_Level)
                             {
                                 if (_player.IsSpectator)
                                 {
                                     Phrases.Dict.TryGetValue(962, out string _phrase962);
                                     SdtdConsole.Instance.ExecuteSync(string.Format("ban add {0} 5 years \"{1}\"", _cInfo.playerId, _phrase962), null);
                                     string _file     = string.Format("DetectionLog_{0}.txt", DateTime.Today.ToString("M-d-yyyy"));
                                     string _filepath = string.Format("{0}/Logs/DetectionLogs/{1}", API.ConfigPath, _file);
                                     using (StreamWriter sw = new StreamWriter(_filepath, true, Encoding.UTF8))
                                     {
                                         sw.WriteLine(string.Format("Detected \"{0}\", Steam id {1}, using spectator mode @ {2} {3} {4}.", _cInfo.playerName, _cInfo.playerId, (int)_player.position.x, (int)_player.position.y, (int)_player.position.z));
                                         sw.WriteLine();
                                         sw.Flush();
                                         sw.Close();
                                     }
                                     Log.Warning("[SERVERTOOLS] Detected {0}, Steam Id {1}, using spectator mode @ {2} {3} {4}.", _cInfo.playerName, _cInfo.playerId, (int)_player.position.x, (int)_player.position.y, (int)_player.position.z);
                                     Phrases.Dict.TryGetValue(961, out string _phrase961);
                                     _phrase961 = _phrase961.Replace("{PlayerName}", _cInfo.playerName);
                                     ChatHook.ChatMessage(null, Config.Chat_Response_Color + _phrase961 + "[-]", -1, Config.Server_Response_Name, EChatType.Global, null);
                                     continue;
                                 }
                             }
                             if (GodEnabled && _userPermissionLevel > Godmode_Admin_Level)
                             {
                                 if (_player.Buffs.HasBuff("god"))
                                 {
                                     Phrases.Dict.TryGetValue(972, out string _phrase972);
                                     SdtdConsole.Instance.ExecuteSync(string.Format("ban add {0} 5 years \"{1}\"", _cInfo.playerId, _phrase972), null);
                                     string _file     = string.Format("DetectionLog_{0}.txt", DateTime.Today.ToString("M-d-yyyy"));
                                     string _filepath = string.Format("{0}/Logs/DetectionLogs/{1}", API.ConfigPath, _file);
                                     using (StreamWriter sw = new StreamWriter(_filepath, true, Encoding.UTF8))
                                     {
                                         sw.WriteLine(string.Format("Detected {0}, Steam Id {1}, using godmode @ {2} {3} {4}.", _cInfo.playerName, _cInfo.playerId, (int)_player.position.x, (int)_player.position.y, (int)_player.position.z));
                                         sw.WriteLine();
                                         sw.Flush();
                                         sw.Close();
                                     }
                                     Log.Warning("[SERVERTOOLS] Detected \"{0}\", Steam id {1}, using godmode @ {2} {3} {4}.", _cInfo.playerName, _cInfo.playerId, (int)_player.position.x, (int)_player.position.y, (int)_player.position.z);
                                     Phrases.Dict.TryGetValue(971, out string _phrase971);
                                     _phrase971 = _phrase971.Replace("{PlayerName}", _cInfo.playerName);
                                     ChatHook.ChatMessage(null, Config.Chat_Response_Color + _phrase971 + "[-]", -1, Config.Server_Response_Name, EChatType.Global, null);
                                     continue;
                                 }
                             }
                             if (FlyEnabled && _userPermissionLevel > Flying_Admin_Level)
                             {
                                 if (_player.IsSpawned() && _player.IsAlive())
                                 {
                                     if (_player.isSwimming)
                                     {
                                         BlockValue _block = GameManager.Instance.World.GetBlock(new Vector3i(_player.position));
                                         if (_block.Block.blockMaterial.IsLiquid)
                                         {
                                             continue;
                                         }
                                     }
                                     if (_player.AttachedToEntity != null)
                                     {
                                         Entity _entity = GameManager.Instance.World.GetEntity(_player.AttachedToEntity.entityId);
                                         if (_entity != null)
                                         {
                                             float _distance = _player.GetDistance(_player.AttachedToEntity);
                                             if (_distance <= 5)
                                             {
                                                 continue;
                                             }
                                         }
                                     }
                                     if (Movement.ContainsKey(_cInfo.entityId))
                                     {
                                         Movement.TryGetValue(_cInfo.entityId, out Vector3i position);
                                         Movement[_cInfo.entityId] = new Vector3i(_player.position);
                                         if (position.y - _player.position.y >= 4)
                                         {
                                             if (Flag.ContainsKey(_cInfo.entityId))
                                             {
                                                 Flag.Remove(_cInfo.entityId);
                                             }
                                             continue;
                                         }
                                     }
                                     else
                                     {
                                         Movement.Add(_cInfo.entityId, new Vector3i(_player.position));
                                     }
                                     if (AirCheck(_player.position.x, _player.position.y, _player.position.z) || GroundCheck(_player.position.x, _player.position.y, _player.position.z))
                                     {
                                         List <EntityPlayer> _playerList = PersistentOperations.PlayerList();
                                         for (int j = 0; j < _playerList.Count; j++)
                                         {
                                             if (_playerList[j].entityId != _player.entityId)
                                             {
                                                 float _distance = _player.GetDistance(_playerList[j]);
                                                 if (_distance <= 2)
                                                 {
                                                     continue;
                                                 }
                                             }
                                         }
                                         if (Flag.ContainsKey(_cInfo.entityId))
                                         {
                                             Flag.TryGetValue(_cInfo.entityId, out int _flags);
                                             _flags++;
                                             if (_flags >= Flying_Flags)
                                             {
                                                 Flag.Remove(_cInfo.entityId);
                                                 Phrases.Dict.TryGetValue(982, out string _phrase982);
                                                 SdtdConsole.Instance.ExecuteSync(string.Format("ban add {0} 5 years \"{1}\"", _cInfo.playerId, _phrase982), null);
                                                 string _file     = string.Format("DetectionLog_{0}.txt", DateTime.Today.ToString("M-d-yyyy"));
                                                 string _filepath = string.Format("{0}/Logs/DetectionLogs/{1}", API.ConfigPath, _file);
                                                 using (StreamWriter sw = new StreamWriter(_filepath, true, Encoding.UTF8))
                                                 {
                                                     sw.WriteLine(string.Format("Detected {0}, Steam Id {1}, flying @ {2} {3} {4}.", _cInfo.playerName, _cInfo.playerId, (int)_player.position.x, (int)_player.position.y, (int)_player.position.z));
                                                     sw.WriteLine();
                                                     sw.Flush();
                                                     sw.Close();
                                                 }
                                                 Log.Warning("[SERVERTOOLS] Detected {0}, Steam Id {1}, flying @ {2} {3} {4}. Steam Id has been banned", _cInfo.playerName, _cInfo.playerId, (int)_player.position.x, (int)_player.position.y, (int)_player.position.z);
                                                 Phrases.Dict.TryGetValue(981, out string _phrase981);
                                                 _phrase981 = _phrase981.Replace("{PlayerName}", _cInfo.playerName);
                                                 ChatHook.ChatMessage(null, Config.Chat_Response_Color + _phrase981 + "[-]", -1, Config.Server_Response_Name, EChatType.Global, null);
                                                 continue;
                                             }
                                             else
                                             {
                                                 Flag[_cInfo.entityId] = _flags;
                                             }
                                         }
                                         else
                                         {
                                             Flag.Add(_cInfo.entityId, 1);
                                         }
                                     }
                                     else if (Flag.ContainsKey(_cInfo.entityId))
                                     {
                                         Flag.Remove(_cInfo.entityId);
                                     }
                                 }
                                 else
                                 {
                                     if (Movement.ContainsKey(_cInfo.entityId))
                                     {
                                         Movement.TryGetValue(_cInfo.entityId, out Vector3i position);
                                         if (position != new Vector3i(_player.position))
                                         {
                                             if (Flag.ContainsKey(_cInfo.entityId))
                                             {
                                                 Flag.TryGetValue(_cInfo.entityId, out int _flags);
                                                 _flags++;
                                                 if (_flags >= Flying_Flags)
                                                 {
                                                     Flag.Remove(_cInfo.entityId);
                                                     Phrases.Dict.TryGetValue(982, out string _phrase982);
                                                     SdtdConsole.Instance.ExecuteSync(string.Format("ban add {0} 5 years \"{1}\"", _cInfo.playerId, _phrase982), null);
                                                     string _file     = string.Format("DetectionLog_{0}.txt", DateTime.Today.ToString("M-d-yyyy"));
                                                     string _filepath = string.Format("{0}/Logs/DetectionLogs/{1}", API.ConfigPath, _file);
                                                     using (StreamWriter sw = new StreamWriter(_filepath, true, Encoding.UTF8))
                                                     {
                                                         sw.WriteLine(string.Format("Detected {0}, Steam Id {1}, flying @ {2} {3} {4}.", _cInfo.playerName, _cInfo.playerId, (int)_player.position.x, (int)_player.position.y, (int)_player.position.z));
                                                         sw.WriteLine();
                                                         sw.Flush();
                                                         sw.Close();
                                                     }
                                                     Log.Warning("[SERVERTOOLS] Detected {0}, Steam Id {1}, flying @ {2} {3} {4}. Steam Id has been banned", _cInfo.playerName, _cInfo.playerId, (int)_player.position.x, (int)_player.position.y, (int)_player.position.z);
                                                     Phrases.Dict.TryGetValue(981, out string _phrase981);
                                                     _phrase981 = _phrase981.Replace("{PlayerName}", _cInfo.playerName);
                                                     ChatHook.ChatMessage(null, Config.Chat_Response_Color + _phrase981 + "[-]", -1, Config.Server_Response_Name, EChatType.Global, null);
                                                     continue;
                                                 }
                                                 else
                                                 {
                                                     Flag[_cInfo.entityId] = _flags;
                                                 }
                                             }
                                             else
                                             {
                                                 Flag.Add(_cInfo.entityId, 1);
                                             }
                                         }
                                     }
                                     else if (Flag.ContainsKey(_cInfo.entityId))
                                     {
                                         Flag.Remove(_cInfo.entityId);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in PlayerChecks.Exec: {0}", e.Message));
     }
 }
Exemple #5
0
 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);
 }