Skip to content
Permalink
Browse files
Add an account setting to require SAMPCAC for certain players
  • Loading branch information
RussellLVP committed Jul 22, 2020
1 parent cd9226b commit 4e891f7b6293323e04ee61adc34b64c6c9661400
Showing 6 changed files with 65 additions and 7 deletions.
@@ -639,6 +639,7 @@ export class AccountDatabase {
money_spawn: { table: 'users_mutable', type: AccountDatabase.kTypeNumber },
online_time: { table: 'users_mutable', type: AccountDatabase.kTypeNumber },
preferred_radio_channel: { table: 'users_mutable', type: AccountDatabase.kTypeString },
require_sampcac: { table: 'users_mutable', type: AccountDatabase.kTypeNumber },
skin_id: { table: 'users_mutable', type: AccountDatabase.kTypeNumber },
stats_carbombs: { table: 'users_mutable', type: AccountDatabase.kTypeNumber },
stats_drivebys: { table: 'users_mutable', type: AccountDatabase.kTypeNumber },
@@ -111,6 +111,7 @@ enum PasswordRequestType {
#include "Features/Account/EnterPasswordDialog.pwn"
#include "Features/Account/ForcedGuestDialog.pwn"
#include "Features/Account/MultipleSessionDialog.pwn"
#include "Features/Account/RequireSampcacDialog.pwn"

#include "Features/Account/Bans/BanManager.pwn"
#include "Features/Account/Bans/BanCommands.pwn"
@@ -59,9 +59,9 @@ class Account <playerId (MAX_PLAYERS)> {
* @param registered Is the user a registered player on Las Venturas Playground?
* @param userId Id of the user as they are registered in the database.
* @param skinId Optional default skin as has been chosen by the registered user.
* @param enableAutomaticIdentification Should this user be identified automatically?
* @param requireSampcac Whether SAMPCAC is required for this player account.
*/
public onRegisteredRequestComplete(bool: registered, userId, skinId, bool: enableAutomaticIdentification = false) {
public onRegisteredRequestComplete(bool: registered, userId, skinId, bool: requireSampcac) {
BanManager->verifyPlayerAllowedToPlay(playerId, userId);

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

Player(playerId)->setIsRegistered(true);
Player(playerId)->setIsLoggedIn(false);

m_loginAttemptCount = 0;
m_userId = userId;

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

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

// Otherwise create a login dialog asking them to enter their password.
this->displayPasswordDialog();
@@ -0,0 +1,47 @@
// Copyright 2006-2020 Las Venturas Playground. All rights reserved.
// Use of this source code is governed by the GPLv2 license, a copy of which can
// be found in the LICENSE file.

/**
* Dialog telling the player that their account has been locked to require use of SAMPCAC, and they
* have to enable it before being able to play on the server.
*
* @author Russell Krupke <russell@sa-mp.nl>
*/
class RequireSampcacDialog <playerId (MAX_PLAYERS)> {
// What is the dialog Id that will be used for this dialog?
public const DialogId = @counter(OnDialogResponse);

/**
* Show the dialog which informs the user that they have to enable SAMPCAC in order to be able
* to play. This cannot be dismissed - acknowledging the dialog will disconnect them.
*/
public show() {
new message[256];
format(message, sizeof(message),
"Your account requires use of SAMPCAC in order to play on Las Venturas\n" ...
"Playground. Please enable the anticheat and reconnect to the server.");

ShowPlayerDialog(playerId,
RequireSampcacDialog::DialogId,
DIALOG_STYLE_MSGBOX,
"You must enable SAMPCAC to play here!",
message, "Disconnect", "");
}

/**
* Disconnects the player from the server as they have dismissed the dialog.
*
* @param button The button which was clicked, see the DialogButton enumeration.
* @param listItem Index of the selected item in the list, which starts at zero.
* @param inputText The text which was inserted, if any.
* @return integer Were we able to correctly handle this callback?
*/
@switch(OnDialogResponse, RequireSampcacDialog::DialogId)
public onResponse(DialogButton: button, listItem, inputText[]) {
Kick(playerId);

#pragma unused button, listItem, inputText
return 1;
}
};
@@ -31,7 +31,8 @@ class PlayerRegisteredRequest {
public __construct() {
if (!QueryBuilder->create("SELECT " ...
" users.user_id, " ...
" users_mutable.skin_id " ...
" users_mutable.skin_id, " ...
" users_mutable.require_sampcac " ...
"FROM " ...
" users_nickname " ...
"LEFT JOIN " ...
@@ -69,13 +70,16 @@ class PlayerRegisteredRequest {
*/
public onReceivedResult(playerId, resultId) {
new bool: registered = DatabaseResult(resultId)->count() > 0 && DatabaseResult(resultId)->next();

new userId = 0, skinId = 0;
new bool: requireSampcac = false;

if (registered == true) {
userId = DatabaseResult(resultId)->readInteger("user_id");
skinId = DatabaseResult(resultId)->readInteger("skin_id");
requireSampcac = DatabaseResult(resultId)->readInteger("require_sampcac") != 0;
}

Account(playerId)->onRegisteredRequestComplete(registered, userId, skinId);
Account(playerId)->onRegisteredRequestComplete(registered, userId, skinId, requireSampcac);
}
};
@@ -342,6 +342,7 @@
<DiskObject>\Resources\Minigames\Derby\Derby7.pwn</DiskObject>
<DiskObject>\Resources\Minigames\Derby\Derby8.pwn</DiskObject>
<DiskObject>\Resources\Minigames\Derby\Derby9.pwn</DiskObject>
<DiskObject>\Features\Account\RequireSampcacDialog.pwn</DiskObject>
</FileList>
<Settings>
<Setting name="name">Las Venturas Playground</Setting>

0 comments on commit 4e891f7

Please sign in to comment.