discord verification system
# support-forum
w
Hello just want to ask how can i prevent the user from using the same code that is already used by another player?
i
Use a variable with the MAX_PLAYERS, simply generate a verification code each time a user is going to verify and set it in his id, then a conditional that only the user with the code in the variable of his id can use
w
but it seems playerid cannot be used in discord connector
it can but it will generate weird bug also
i
I have a system like this, and it doesn't give any errors
w
Copy code
c
if (discordCode == g_DCUser[E_ACCOUNT_CODE]) {
            DCC_GetUserId(user, userId, sizeof(userId));
            DCC_GetUserName(user, userName, sizeof(userName));
            DCC_GetUserDiscriminator(user, userDiscriminator, sizeof(userDiscriminator));
            g_DCUser[E_DISCORD_NAME] = userName;
            g_DCUser[E_DISCORD_TAG] = userDiscriminator;

            mysql_format(g_Handle, query, sizeof(query), "SELECT `username` FROM `players` WHERE `discord_code` = %i", discordCode);
            mysql_tquery(g_Handle, query, "VerifyAccount");
        } else {
            DCC_SendChannelMessage(channel, "This code is already used by another player.");
        }
do you mean like this?
i
Wait a minute, are you doing the verification system from discord to samp?
I have a system but it sends a verification code to the discord, when registering in the samp
w
yeah
mine have getcode command inside the server and it generates 4 digits code
i
Mine does that

https://cdn.discordapp.com/attachments/1104225054109212723/1104239932077244468/image.png

w
do bot pm the user for the verification code?
i
Yes, to confirm registration
w
Copy code
c
CMD:getcode(playerid, params[])
{
    new randomNumber = RandomMinMax(1000, 9999), query[300];
    g_DCUser[E_ACCOUNT_CODE] = randomNumber;
    mysql_format(g_Handle, query, sizeof(query), "UPDATE `players` SET `discord_code` = '%i' WHERE `id` = '%i'", g_DCUser[E_ACCOUNT_CODE], g_Player[playerid][E_PLAYER_ID]);
    mysql_query(g_Handle, query);
    SendClientMessage(playerid, COLOR_SUCCESS, "Your code is %i", randomNumber);
    return 1;
}
i stored the random digits to the variable and database
i
To check it by Database id?
Much better
w
how?
@icy-laptop-33903 sorry for bothering you but can i ask how this code works?
Copy code
c
mysql_format(g_Handle, query, sizeof(query), "SELECT `username` FROM `players` WHERE `discord_code` = %i", discordCode);
        mysql_tquery(g_Handle, query, "VerifyAccount");
Copy code
c
forward VerifyAccount(playerid);
public VerifyAccount(playerid)
{
    if (cache_num_rows()) {
        new str[128];
        format(str, sizeof(str), "The code you've been submitting is either invalid or used to an account that is now verified.");
        new DCC_Embed:embed = DCC_CreateEmbed("Invalid Code!", str);
        DCC_SetEmbedColor(embed, 0xFF0000);
        DCC_SendChannelEmbedMessage(g_VerificationChannel, embed);
    } else {
        DCC_SendChannelMessage(g_VerificationChannel, "Verified");
    }
    return 1;
}
this is the callback used in thread query
b
@witty-helicopter-92812 are you saving the player code?
w
yea @best-father-39200
b
hmmm
better check it in the database
i
Yesterday I left sorry, why did you save it in the database? @witty-helicopter-92812
w
To prevent the user from linking another discord account to their server account