Skip to content

Added server side weapon related checks #3272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this intentional?

- 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to add a comment explaining what could cause this (Cheaters, etc).

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to add a comment explaining what could cause this (Cheaters, etc).

ucClientWeaponType = 0;
slot.data.uiSlot = 0;
}

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