Skip to content

Commit

Permalink
Implement prevention for fake car entry
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellLVP committed Jul 9, 2020
1 parent 68f0647 commit 3c787d5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
3 changes: 2 additions & 1 deletion javascript/features/settings/pawn_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { Setting } from 'entities/setting.js';

// List of PawnConfig settings with their unique values and settings. Must be synced with Pawn. The
// settings can be in any category, of any type, as long as the identifier is a valid one.
// Next ID: 11
// Next ID: 12
const kSynchronizedSettings = new Map([
[ 'abuse/fake_car_entry_prevention_sec', { id: 11 } ],
[ 'abuse/ignore_sole_passenger_damage', { id: 5 } ],
[ 'abuse/kick_reason_public', { id: 6 } ],
[ 'abuse/kill_attribution_time_sec', { id: 7 } ],
Expand Down
1 change: 1 addition & 0 deletions javascript/features/settings/setting_list.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions pawn/Driver/Driver.pwn
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ new const kUnoccupiedSyncMarkTimeMs = 185000;
// The area that describes the insides of Las Venturas. Made available and managed by the streamer.
new STREAMER_TAG_AREA: g_areaLasVenturas;

// Time (in milliseconds) until when damage issued by a particular player should be disabled.
new g_damageDisabledExpirationTime[MAX_PLAYERS] = { 0, ... };

// Boolean that indicates whether a particular player is currently in Las Venturas.
new bool: g_inLasVenturas[MAX_PLAYERS] = { false, ... };

Expand Down Expand Up @@ -148,6 +151,11 @@ public OnPlayerConnect(playerid) {
return PlayerEvents(playerid)->onPlayerConnect();
}

public OnPlayerSpawn(playerid) {
g_damageDisabledExpirationTime[playerid] = 0;
return LVPPlayerSpawn(playerid);
}

public OnPlayerDisconnect(playerid, reason) {
g_isDisconnecting[playerid] = true;

Expand Down Expand Up @@ -453,6 +461,14 @@ public OnPlayerStateChange(playerid, newstate, oldstate) {
if (oldstate == PLAYER_STATE_DRIVER)
ProcessDriftLeaveVehicleForPlayer(playerid);

// When the player is leaving a vehicle, disable their damage for a predefined amount of time
// to avoid players from abusing vehicle bugs to give them an advantage in a fight.
if ((oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
&& g_abuseFakeCarEntryPreventionSec > 0) {
g_damageDisabledExpirationTime[playerid] =
GetTickCount() + g_abuseFakeCarEntryPreventionSec * 1000;
}

return LegacyPlayerStateChange(playerid, newstate, oldstate);
}

Expand Down Expand Up @@ -525,6 +541,15 @@ public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float: fX, Float:
#if Feature::EnableServerSideWeaponConfig == 0
DetectAbuseOnWeaponShot(playerid, hittype, hitid);

// If damage has been disabled for the |playerid|, discard the shots entirely. It will expire
// automatically when the time has passed.
if (g_damageDisabledExpirationTime[playerid] > 0) {
if (g_damageDisabledExpirationTime[playerid] < GetTickCount())
g_damageDisabledExpirationTime[playerid] = 0;
else
return 0;
}

// We might want to ignore damage done by players who are passengers as the sole occupant of a
// vehicle. They can only be damaged with a chainsaw, making this very unfair in fights.
if (g_abuseIgnoreSolePassengerDamage && hittype != BULLET_HIT_TYPE_NONE) {
Expand Down Expand Up @@ -621,6 +646,19 @@ public OnPlayerUpdate(playerid) {
if (g_driftingEnabled)
ProcessDriftUpdateForPlayer(playerid);

// Determines if the player is entering a vehicle through animation, and if so, marks the time
// until which their damage should be disabled based on the prevention setting.
if (g_abuseFakeCarEntryPreventionSec > 0) {
new const animationIndex = GetPlayerAnimationIndex(playerid);
switch (animationIndex) {
case 1043 /* CAR_OPEN_LHS */, 1044 /* CAR_OPEN_RHS */,
1026 /* CAR_GETIN_LHS */, 1027 /* CAR_GETIN_RHS */: {
g_damageDisabledExpirationTime[playerid] =
GetTickCount() + g_abuseFakeCarEntryPreventionSec * 1000;
}
}
}

return 1;
}
#endif
7 changes: 6 additions & 1 deletion pawn/Driver/PawnConfig.pwn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// //features/settings/pawn_config.js. Each option will be stored as a global Pawn variable.

// Section: abuse
new g_abuseFakeCarEntryPreventionSec = 3;
new bool: g_abuseIgnoreSolePassengerDamage = true;
new bool: g_abuseKickReasonsPublic = true;
new g_abuseKillAttributionTimeSec = 10;
Expand All @@ -23,8 +24,9 @@ new bool: g_vehicleKeysBlockedInLasVenturas = true;

// These are the unique Ids for each of the properties that can be updated. They must be identical
// between the Pawn and the JavaScript code.
// Next ID: 11
// Next ID: 12
enum PawnConfigProperty {
kAbuseFakeCarEntryPrevention = 11,
kAbuseIgnoreSolePassengerDamage = 5,
kAbuseKickReasonPublic = 6,
kAbuseKillAttributionTimeSec = 7,
Expand All @@ -44,6 +46,9 @@ public OnPawnConfigDataChange(PawnConfigProperty: property, Float: numberValue)
new const intValue = floatround(numberValue, floatround_tozero);

switch (property) {
case kAbuseFakeCarEntryPrevention:
g_abuseFakeCarEntryPreventionSec = intValue;

case kAbuseIgnoreSolePassengerDamage:
g_abuseIgnoreSolePassengerDamage = !!intValue;

Expand Down
2 changes: 1 addition & 1 deletion pawn/Features/Gameplay/SpawnManager.pwn
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public OnPlayerRequestSpawn(playerid) {
* @param playerid Id of the player who is spawning.
* @return integer False if the player should be returned to class selection after the next spawn.
*/
public OnPlayerSpawn(playerid) {
LVPPlayerSpawn(playerid) {
if (Player(playerid)->isConnected() == false)
return 0;

Expand Down

0 comments on commit 3c787d5

Please sign in to comment.