Skip to content

Commit 86448ea

Browse files
NanoBobLpsd
andauthored
Added server side weapon related checks (#3272)
* 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]>
1 parent 11c04b7 commit 86448ea

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
- name: Create build artifacts
4646
run: utils\premake5 compose_files
4747

48-
- uses: actions/upload-artifact@master
48+
- uses: actions/upload-artifact@v3
4949
with:
5050
name: InstallFiles
5151
path: InstallFiles/

Server/mods/deathmatch/logic/CGame.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,6 +2443,10 @@ void CGame::Packet_Bulletsync(CBulletsyncPacket& Packet)
24432443
CPlayer* pPlayer = Packet.GetSourcePlayer();
24442444
if (pPlayer && pPlayer->IsJoined())
24452445
{
2446+
// Early return when the player attempts to fire a weapon they do not have
2447+
if (!pPlayer->HasWeaponType(Packet.m_WeaponType))
2448+
return;
2449+
24462450
// Relay to other players
24472451
RelayNearbyPacket(Packet);
24482452

Server/mods/deathmatch/logic/CPed.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,17 @@ void CPed::SetWeaponTotalAmmo(unsigned short usTotalAmmo, unsigned char ucSlot)
356356
}
357357
}
358358

359+
bool CPed::HasWeaponType(unsigned char ucWeaponType)
360+
{
361+
for (unsigned char slot = 0; slot < WEAPON_SLOTS; slot++)
362+
{
363+
if (GetWeaponType(slot) == ucWeaponType)
364+
return true;
365+
}
366+
367+
return false;
368+
}
369+
359370
float CPed::GetMaxHealth()
360371
{
361372
// TODO: Verify this formula

Server/mods/deathmatch/logic/CPed.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ class CPed : public CElement
168168
void SetWeaponAmmoInClip(unsigned short uscAmmoInClip, unsigned char ucSlot = 0xFF);
169169
unsigned short GetWeaponTotalAmmo(unsigned char ucSlot = 0xFF);
170170
void SetWeaponTotalAmmo(unsigned short usTotalAmmo, unsigned char ucSlot = 0xFF);
171+
bool HasWeaponType(unsigned char ucWeaponType);
171172

172173
float GetMaxHealth();
173174
float GetHealth() { return m_fHealth; }

Server/mods/deathmatch/logic/packets/CPlayerPuresyncPacket.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ bool CPlayerPuresyncPacket::Read(NetBitStreamInterface& BitStream)
175175
// Set weapon slot
176176
if (bWeaponCorrect)
177177
pSourcePlayer->SetWeaponSlot(uiSlot);
178+
else
179+
{
180+
// remove invalid weapon data to prevent this from being relayed to other players
181+
ucClientWeaponType = 0;
182+
slot.data.uiSlot = 0;
183+
}
178184

179185
if (CWeaponNames::DoesSlotHaveAmmo(uiSlot))
180186
{

0 commit comments

Comments
 (0)