diff --git a/SDK/include/utils.hpp b/SDK/include/utils.hpp index 1891faf9b..3107984a5 100644 --- a/SDK/include/utils.hpp +++ b/SDK/include/utils.hpp @@ -1,4 +1,5 @@ #pragma once +#include "player.hpp" #define STRINGIFY(s) _STRINGIFY(s) #define _STRINGIFY(s) #s @@ -14,3 +15,16 @@ inline StringView trim(StringView view) const size_t end = view.find_last_not_of(whitespace); return view.substr(start, end - start + 1); } + +inline bool IsWeaponForTakenDamageValid(int weapon) +{ + auto slot = WeaponSlotData(weapon).slot(); + if (slot == INVALID_WEAPON_SLOT) + { + if (weapon < 49 || weapon > 54) + { + return false; + } + } + return true; +} diff --git a/Server/Components/Actors/actors_main.cpp b/Server/Components/Actors/actors_main.cpp index abf0b8b9e..474d75f90 100644 --- a/Server/Components/Actors/actors_main.cpp +++ b/Server/Components/Actors/actors_main.cpp @@ -8,6 +8,7 @@ #include "actor.hpp" #include +#include class ActorsComponent final : public IActorsComponent, public PlayerConnectEventHandler, public PlayerUpdateEventHandler, public PoolEventHandler { @@ -41,6 +42,11 @@ class ActorsComponent final : public IActorsComponent, public PlayerConnectEvent return false; } + if (!IsWeaponForTakenDamageValid(onPlayerDamageActorRPC.WeaponID)) + { + return false; + } + if (onPlayerDamageActorRPC.Bodypart < BodyPart_Torso || onPlayerDamageActorRPC.Bodypart > BodyPart_Head) { return false; diff --git a/Server/Source/player_pool.hpp b/Server/Source/player_pool.hpp index 2cecaf5a0..7f5b32445 100644 --- a/Server/Source/player_pool.hpp +++ b/Server/Source/player_pool.hpp @@ -10,6 +10,7 @@ #include "player_impl.hpp" #include +#include struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public PlayerUpdateEventHandler, public CoreEventHandler { @@ -213,7 +214,13 @@ struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public { return false; } - if (!from->areWeaponsAllowed() && 0 < onPlayerGiveTakeDamageRPC.WeaponID && onPlayerGiveTakeDamageRPC.WeaponID <= 47) + + if (!IsWeaponForTakenDamageValid(onPlayerGiveTakeDamageRPC.WeaponID)) + { + return false; + } + + if (!from->areWeaponsAllowed() && 0 < onPlayerGiveTakeDamageRPC.WeaponID && onPlayerGiveTakeDamageRPC.WeaponID <= 54) { // They were shooting and shouldn't be. return false; @@ -247,7 +254,14 @@ struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public { return false; } - if (!peer.areWeaponsAllowed() && 0 < onPlayerGiveTakeDamageRPC.WeaponID && onPlayerGiveTakeDamageRPC.WeaponID <= 47) + + auto slot = WeaponSlotData(onPlayerGiveTakeDamageRPC.WeaponID).slot(); + if (slot == INVALID_WEAPON_SLOT) + { + return false; + } + + if (!peer.areWeaponsAllowed() && (0 < onPlayerGiveTakeDamageRPC.WeaponID && onPlayerGiveTakeDamageRPC.WeaponID <= 46)) { // They were shooting and shouldn't be. return false; @@ -657,6 +671,12 @@ struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public Player& player = static_cast(peer); + uint8_t slot = WeaponSlotData(footSync.Weapon).slot(); + if (slot == INVALID_WEAPON_SLOT) + { + return false; + } + footSync.PlayerID = player.poolID; footSync.Rotation *= player.rotTransform_; @@ -1091,6 +1111,13 @@ struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public { return false; } + + uint8_t slot = WeaponSlotData(vehicleSync.WeaponID).slot(); + if (slot == INVALID_WEAPON_SLOT) + { + return false; + } + IVehicle& vehicle = *vehiclePtr; Player& player = static_cast(peer); player.pos_ = vehicleSync.Position; @@ -1335,9 +1362,16 @@ struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public { return false; } - IVehicle& vehicle = *vehiclePtr; + uint8_t slot = WeaponSlotData(passengerSync.WeaponID).slot(); + if (slot == INVALID_WEAPON_SLOT) + { + return false; + } + + IVehicle& vehicle = *vehiclePtr; Player& player = static_cast(peer); + if (vehicle.isRespawning()) return false;