/
pawn_config.js
61 lines (54 loc) · 2.78 KB
/
pawn_config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2020 Las Venturas Playground. All rights reserved.
// Use of this source code is governed by the MIT license, a copy of which can
// be found in the LICENSE file.
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: 19
const kSynchronizedSettings = new Map([
[ 'abuse/disable_out_of_range_damage', { id: 14 } ],
[ 'abuse/fake_car_entry_prevention_enter_ms', { id: 11 } ],
[ 'abuse/fake_car_entry_prevention_exit_ms', { id: 12 } ],
[ 'abuse/highfps_damage_ignored_sec', { id: 15 } ],
[ 'abuse/highfps_damage_sample_sec', { id: 16 } ],
[ 'abuse/highfps_damage_threshold', { id: 17 } ],
[ 'abuse/ignore_sole_passenger_damage', { id: 5 } ],
[ '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 } ],
[ 'vehicles/drifting_min_angle', { id: 3 } ],
[ 'vehicles/drifting_min_speed', { id: 4 } ],
[ 'vehicles/drifting_point_divider', { id: 9 } ],
[ 'vehicles/keys_blocked_in_las_venturas', { id: 10 } ],
]);
// Analogous to the PawnConfig class in Pawn, but on the sending side. Observes settings in the
// |kSynchronizedSettings| map, and synchronizes them with Pawn when they change value.
export class PawnConfig {
// Called when a setting has changed value. Will ignore anything that's not explicitly been
// added to the |kSynchronizedSettings| map, keyed by setting identifier.
onSettingUpdated(setting, value) {
const configuration = kSynchronizedSettings.get(setting.identifier);
if (!configuration)
return; // the |setting| should not be synchronized
switch (setting.type) {
case Setting.TYPE_BOOLEAN:
this.pawnConfigDataChange(configuration.id, { numberValue: !!value ? 1 : 0 });
break;
case Setting.TYPE_NUMBER:
this.pawnConfigDataChange(configuration.id, { numberValue: value });
break;
}
}
// Calls through to the OnPawnConfigDataChange event in Pawn to update the value, with the
// given parameters. Will run it after a slight delay to avoid re-entrancy issues.
pawnConfigDataChange(property, { numberValue = 0 } = {}) {
if (server.isTest())
return; // do not propagate changes in tests
wait(0).then(() =>
pawnInvoke('OnPawnConfigDataChange', 'if', property, numberValue));
}
}