Skip to content

Commit

Permalink
Make the maximum number of connections per IP address configurable in…
Browse files Browse the repository at this point in the history
… /lvp settings
  • Loading branch information
RussellLVP committed Jul 22, 2020
1 parent 4e891f7 commit fcdbd8a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 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,7 +6,7 @@ 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: 18
// Next ID: 19
const kSynchronizedSettings = new Map([
[ 'abuse/disable_out_of_range_damage', { id: 14 } ],
[ 'abuse/fake_car_entry_prevention_enter_ms', { id: 11 } ],
Expand All @@ -18,6 +18,7 @@ const kSynchronizedSettings = new Map([
[ 'abuse/kick_reason_public', { id: 6 } ],
[ 'abuse/kill_attribution_time_sec', { id: 7 } ],
[ 'abuse/manual_sawnoff_damage', { id: 13 } ],
[ 'abuse/maximum_connections_per_ip', { id: 18 } ],
[ 'vehicles/drifting_enabled', { id: 1 } ],
[ 'vehicles/drifting_max_angle', { id: 2 } ],
[ 'vehicles/drifting_max_distance', { id: 8 } ],
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.

7 changes: 6 additions & 1 deletion pawn/Driver/PawnConfig.pwn
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ new bool: g_abuseIgnoreSolePassengerDamage = true;
new bool: g_abuseKickReasonsPublic = true;
new g_abuseKillAttributionTimeSec = 10;
new bool: g_abuseManualSawnoffDamage = false;
new g_maximumConnectionsPerIP = 3;

// Section: drifting
new bool: g_driftingEnabled = false;
Expand All @@ -30,7 +31,7 @@ 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: 18
// Next ID: 19
enum PawnConfigProperty {
kAbuseDisableOutOfRangeDamage = 14,
kAbuseFakeCarEntryPreventionEnterMs = 11,
Expand All @@ -42,6 +43,7 @@ enum PawnConfigProperty {
kAbuseKickReasonPublic = 6,
kAbuseKillAttributionTimeSec = 7,
kAbuseManualSawnoffDamage = 13,
kAbuseMaximumConnectionsPerIP = 18,
kVehiclesDriftingEnabled = 1,
kVehiclesDriftingMaxAngle = 2,
kVehiclesDriftingMaxDistance = 8,
Expand Down Expand Up @@ -116,3 +118,6 @@ public OnPawnConfigDataChange(PawnConfigProperty: property, Float: numberValue)

// Functions to allow legacy parts of the gamemode to access the values. Only when needed.
AreKickReasonsPublic() { return g_abuseKickReasonsPublic ? 1 : 0; }

// Returns the maximum number of allowable connections per IP address.
GetMaximumConnectionsPerIP() { return g_maximumConnectionsPerIP; }
5 changes: 1 addition & 4 deletions pawn/Entities/Players/PlayerEvents.pwn
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
* @author Russell Krupke <russell@sa-mp.nl>
*/
class PlayerEvents <playerId (MAX_PLAYERS)> {
// Maximum number of connections allowed from a single IP address.
const MaxConnectionsPerIp = 3;

// Time in milliseconds between two timestamps of connections originating from the same IP address.
const DefaultDelayConnection = 500;

Expand Down Expand Up @@ -52,7 +49,7 @@ class PlayerEvents <playerId (MAX_PLAYERS)> {
}

// Check if the maximum number of players ingame from the same IP has been reached.
if (matchedPlayers >= MaxConnectionsPerIp) {
if (matchedPlayers >= GetMaximumConnectionsPerIP()) {
printf("Player [%d] shares IP with %d ingame players.", playerId, matchedPlayers);
Kick(playerId); // deny player entry
}
Expand Down

0 comments on commit fcdbd8a

Please sign in to comment.