Skip to content

Commit

Permalink
Added server side weapon related checks (#3272)
Browse files Browse the repository at this point in the history
* Added checks to make sure players are able to fire guns they're firing, and don't send potentially incorrect weapon data

* Re-run pipeline

* Specify artifact upload version to hopefully fix build issue

---------

Co-authored-by: Lpsd <[email protected]>
  • Loading branch information
NanoBob and Lpsd authored Dec 17, 2023
1 parent 11c04b7 commit 86448ea
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- name: Create build artifacts
run: utils\premake5 compose_files

- uses: actions/upload-artifact@master
- uses: actions/upload-artifact@v3
with:
name: InstallFiles
path: InstallFiles/
Expand Down
4 changes: 4 additions & 0 deletions Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2443,6 +2443,10 @@ void CGame::Packet_Bulletsync(CBulletsyncPacket& Packet)
CPlayer* pPlayer = Packet.GetSourcePlayer();
if (pPlayer && pPlayer->IsJoined())
{
// Early return when the player attempts to fire a weapon they do not have
if (!pPlayer->HasWeaponType(Packet.m_WeaponType))
return;

// Relay to other players
RelayNearbyPacket(Packet);

Expand Down
11 changes: 11 additions & 0 deletions Server/mods/deathmatch/logic/CPed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,17 @@ void CPed::SetWeaponTotalAmmo(unsigned short usTotalAmmo, unsigned char ucSlot)
}
}

bool CPed::HasWeaponType(unsigned char ucWeaponType)
{
for (unsigned char slot = 0; slot < WEAPON_SLOTS; slot++)
{
if (GetWeaponType(slot) == ucWeaponType)
return true;
}

return false;
}

float CPed::GetMaxHealth()
{
// TODO: Verify this formula
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CPed.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class CPed : public CElement
void SetWeaponAmmoInClip(unsigned short uscAmmoInClip, unsigned char ucSlot = 0xFF);
unsigned short GetWeaponTotalAmmo(unsigned char ucSlot = 0xFF);
void SetWeaponTotalAmmo(unsigned short usTotalAmmo, unsigned char ucSlot = 0xFF);
bool HasWeaponType(unsigned char ucWeaponType);

float GetMaxHealth();
float GetHealth() { return m_fHealth; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ bool CPlayerPuresyncPacket::Read(NetBitStreamInterface& BitStream)
// Set weapon slot
if (bWeaponCorrect)
pSourcePlayer->SetWeaponSlot(uiSlot);
else
{
// remove invalid weapon data to prevent this from being relayed to other players
ucClientWeaponType = 0;
slot.data.uiSlot = 0;
}

if (CWeaponNames::DoesSlotHaveAmmo(uiSlot))
{
Expand Down

0 comments on commit 86448ea

Please sign in to comment.