Skip to content

Commit 4e891f7

Browse files
committed
Add an account setting to require SAMPCAC for certain players
1 parent cd9226b commit 4e891f7

File tree

6 files changed

+65
-7
lines changed

6 files changed

+65
-7
lines changed

javascript/features/account/account_database.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ export class AccountDatabase {
639639
money_spawn: { table: 'users_mutable', type: AccountDatabase.kTypeNumber },
640640
online_time: { table: 'users_mutable', type: AccountDatabase.kTypeNumber },
641641
preferred_radio_channel: { table: 'users_mutable', type: AccountDatabase.kTypeString },
642+
require_sampcac: { table: 'users_mutable', type: AccountDatabase.kTypeNumber },
642643
skin_id: { table: 'users_mutable', type: AccountDatabase.kTypeNumber },
643644
stats_carbombs: { table: 'users_mutable', type: AccountDatabase.kTypeNumber },
644645
stats_drivebys: { table: 'users_mutable', type: AccountDatabase.kTypeNumber },

pawn/Features/Account.pwn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ enum PasswordRequestType {
111111
#include "Features/Account/EnterPasswordDialog.pwn"
112112
#include "Features/Account/ForcedGuestDialog.pwn"
113113
#include "Features/Account/MultipleSessionDialog.pwn"
114+
#include "Features/Account/RequireSampcacDialog.pwn"
114115

115116
#include "Features/Account/Bans/BanManager.pwn"
116117
#include "Features/Account/Bans/BanCommands.pwn"

pawn/Features/Account/Account.pwn

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ class Account <playerId (MAX_PLAYERS)> {
5959
* @param registered Is the user a registered player on Las Venturas Playground?
6060
* @param userId Id of the user as they are registered in the database.
6161
* @param skinId Optional default skin as has been chosen by the registered user.
62-
* @param enableAutomaticIdentification Should this user be identified automatically?
62+
* @param requireSampcac Whether SAMPCAC is required for this player account.
6363
*/
64-
public onRegisteredRequestComplete(bool: registered, userId, skinId, bool: enableAutomaticIdentification = false) {
64+
public onRegisteredRequestComplete(bool: registered, userId, skinId, bool: requireSampcac) {
6565
BanManager->verifyPlayerAllowedToPlay(playerId, userId);
6666

6767
// Let JavaScript know about the player being registered or not.
@@ -72,17 +72,21 @@ class Account <playerId (MAX_PLAYERS)> {
7272

7373
Player(playerId)->setIsRegistered(true);
7474
Player(playerId)->setIsLoggedIn(false);
75+
7576
m_loginAttemptCount = 0;
7677
m_userId = userId;
7778

7879
SpawnManager(playerId)->setSkinId(skinId);
7980
Annotation::ExpandList<OnPlayerAccountAvailable>(playerId);
8081

81-
// Proceed to loading their data immediately if automatic identification is enabled.
82-
if (enableAutomaticIdentification == true) {
83-
this->identifyPlayerForUserId(userId);
82+
#if Feature::EnableSAMPCAC == 1
83+
// If use of SAMPCAC is required for this player, but they haven't enabled it, show them a
84+
// dialog with this notice and prohibit them from continuing to play on the server.
85+
if (requireSampcac && !CAC_GetStatus(playerId)) {
86+
RequireSampcacDialog(playerId)->show();
8487
return;
8588
}
89+
#endif
8690

8791
// Otherwise create a login dialog asking them to enter their password.
8892
this->displayPasswordDialog();
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2006-2020 Las Venturas Playground. All rights reserved.
2+
// Use of this source code is governed by the GPLv2 license, a copy of which can
3+
// be found in the LICENSE file.
4+
5+
/**
6+
* Dialog telling the player that their account has been locked to require use of SAMPCAC, and they
7+
* have to enable it before being able to play on the server.
8+
*
9+
* @author Russell Krupke <russell@sa-mp.nl>
10+
*/
11+
class RequireSampcacDialog <playerId (MAX_PLAYERS)> {
12+
// What is the dialog Id that will be used for this dialog?
13+
public const DialogId = @counter(OnDialogResponse);
14+
15+
/**
16+
* Show the dialog which informs the user that they have to enable SAMPCAC in order to be able
17+
* to play. This cannot be dismissed - acknowledging the dialog will disconnect them.
18+
*/
19+
public show() {
20+
new message[256];
21+
format(message, sizeof(message),
22+
"Your account requires use of SAMPCAC in order to play on Las Venturas\n" ...
23+
"Playground. Please enable the anticheat and reconnect to the server.");
24+
25+
ShowPlayerDialog(playerId,
26+
RequireSampcacDialog::DialogId,
27+
DIALOG_STYLE_MSGBOX,
28+
"You must enable SAMPCAC to play here!",
29+
message, "Disconnect", "");
30+
}
31+
32+
/**
33+
* Disconnects the player from the server as they have dismissed the dialog.
34+
*
35+
* @param button The button which was clicked, see the DialogButton enumeration.
36+
* @param listItem Index of the selected item in the list, which starts at zero.
37+
* @param inputText The text which was inserted, if any.
38+
* @return integer Were we able to correctly handle this callback?
39+
*/
40+
@switch(OnDialogResponse, RequireSampcacDialog::DialogId)
41+
public onResponse(DialogButton: button, listItem, inputText[]) {
42+
Kick(playerId);
43+
44+
#pragma unused button, listItem, inputText
45+
return 1;
46+
}
47+
};

pawn/Interface/Data/PlayerRegisteredRequest.pwn

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class PlayerRegisteredRequest {
3131
public __construct() {
3232
if (!QueryBuilder->create("SELECT " ...
3333
" users.user_id, " ...
34-
" users_mutable.skin_id " ...
34+
" users_mutable.skin_id, " ...
35+
" users_mutable.require_sampcac " ...
3536
"FROM " ...
3637
" users_nickname " ...
3738
"LEFT JOIN " ...
@@ -69,13 +70,16 @@ class PlayerRegisteredRequest {
6970
*/
7071
public onReceivedResult(playerId, resultId) {
7172
new bool: registered = DatabaseResult(resultId)->count() > 0 && DatabaseResult(resultId)->next();
73+
7274
new userId = 0, skinId = 0;
75+
new bool: requireSampcac = false;
7376

7477
if (registered == true) {
7578
userId = DatabaseResult(resultId)->readInteger("user_id");
7679
skinId = DatabaseResult(resultId)->readInteger("skin_id");
80+
requireSampcac = DatabaseResult(resultId)->readInteger("require_sampcac") != 0;
7781
}
7882

79-
Account(playerId)->onRegisteredRequestComplete(registered, userId, skinId);
83+
Account(playerId)->onRegisteredRequestComplete(registered, userId, skinId, requireSampcac);
8084
}
8185
};

pawn/lvp.ppr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@
342342
<DiskObject>\Resources\Minigames\Derby\Derby7.pwn</DiskObject>
343343
<DiskObject>\Resources\Minigames\Derby\Derby8.pwn</DiskObject>
344344
<DiskObject>\Resources\Minigames\Derby\Derby9.pwn</DiskObject>
345+
<DiskObject>\Features\Account\RequireSampcacDialog.pwn</DiskObject>
345346
</FileList>
346347
<Settings>
347348
<Setting name="name">Las Venturas Playground</Setting>

0 commit comments

Comments
 (0)