dialog bugs
#1

I'm making a AdminProtection system, they need to enter a code first before they can use admin commands.
But when I enter my code, it goes to the "Wrong Code" not the Accept Code.
My code is 12345 and all codes have to be numbers so.

pawn Код:
case DIALOG_ADMINCODE:
            {
                if(isnull(inputtext))
                    return SPD(playerid, DIALOG_ADMINCODE2);
               
                new count = 0;
                if(count == 2)
                {
                    new query[500], string[128];
                    format(query, sizeof(query), "INSERT INTO `bans` (`Username`, `AdminName`, `Reason`, `Ipaddress`, `BannedTS`, `UnbannedTS`) VALUES('%s', '%s', '%s', '%s', %d, %d)", GetName(playerid), "Server", "2 times Wrong Admin Code.", PlayerIP[playerid], gettime()+7200, -1);
                    mysql_function_query(connectionHandle, query, false, "DefaultCallback", "");

                    format(string, sizeof(string), "{FFCC00}.:: {FFFFFF}Banned [%s] {FFCC00}::.", date(gettime()+7200, 1));
                    SendClientMessage(playerid, WHITE, string);
                    format(string, sizeof(string), "| Reason for ban: 2 times Wrong Admin Code.");
                    SendClientMessage(playerid, SERVERCOLOR, string);
                    format(string, sizeof(string), "| Banned by: Server");
                    SendClientMessage(playerid, SERVERCOLOR, string);
                    format(string, sizeof(string), "| Type of Ban: Permanent");
                    SendClientMessage(playerid, SERVERCOLOR, string);
                    format(string, sizeof(string), "| If you want to contradict your ban, please make a screenshot (F8) of this screen");
                    SendClientMessage(playerid, SERVERCOLOR, string);
                    format(string, sizeof(string), "| And post a Unban-Appeal on our forums with this screenshot.");
                    SendClientMessage(playerid, SERVERCOLOR, string);
                    KickWithMessage(playerid, SPECIALORANGE, "**************************************************");
                    TextDrawShowForPlayer(playerid, Text:AdminCodeFailed);
                   
                }
                else if(!strcmp(inputtext, Player[playerid][AdminCode], false))
                {
                    AdminLoggedIn[playerid] = 1;
                    TextDrawShowForPlayer(playerid, Text:AdminCodeSuccess);
                    SetTimerEx("RemoveAdminCodeSuccess", 3500, false, "d", playerid);
                }
                else
                {
                    count++;
                    SPD(playerid, DIALOG_ADMINCODE3);
                }
            }
pawn Код:
command(enteradmincode, playerid, params[])
{
    if(Player[playerid][Adminlevel] >= 1)
    {
        SPD(playerid, DIALOG_ADMINCODE);
    }
    else
    {
        TextDrawShowForPlayer(playerid, Text:CantCommand);
        SetTimerEx("RemoveCantCommand", 3500, false, "d", playerid);
    }
    return 1;
}
pawn Код:
stock SPD(playerid, dialogid) // a shortened custom function for ShowPlayerDialog; you don't have to handle all of the ShowPlayerDialog lines, just know the playerid and the dialogid you want to show
{
    new string[600];
    switch(dialogid)
    {
        case DIALOG_REGISTER:
        {
            format(string, sizeof(string), "{FFFFFF}Welcome to {0086EF}<changeme>\n\n{FFFFFF}Username:  {0086EF}%s\n\n{FFFFFF}Please enter your password below", RPName(playerid));
            ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, ""#COL_EMB_WHITE"Account Registration", string, "Register", "Cancel");
        }
        case DIALOG_AUTHENTICATION:
        {
            format(string, sizeof(string), "{FFFFFF}Welcome back to {0086EF}<changeme>\n\n{FFFFFF}Username:  {0086EF}%s\n\n{FFFFFF}Please enter your password below", RPName(playerid));
            ShowPlayerDialog(playerid, DIALOG_AUTHENTICATION, DIALOG_STYLE_PASSWORD, ""#COL_EMB_WHITE"Account Authentication", string, "Login", "Cancel");
        }
        case DIALOG_ADMINCODE:
        {
            format(string, sizeof(string), "{FFFFFF}Please enter your admin code below.");
            ShowPlayerDialog(playerid, DIALOG_ADMINCODE, DIALOG_STYLE_PASSWORD, ""#COL_EMB_WHITE"Admin Identification", string, "Login", "Cancel");
        }
        case DIALOG_ADMINCODE2:
        {
            format(string, sizeof(string), "{FFFFFF}Please enter your admin code below.\n\n{FF0000}You need to enter a code.");
            ShowPlayerDialog(playerid, DIALOG_ADMINCODE, DIALOG_STYLE_PASSWORD, ""#COL_EMB_WHITE"Admin Identification", string, "Login", "Cancel");
        }
        case DIALOG_ADMINCODE3:
        {
            format(string, sizeof(string), "{FFFFFF}Please enter your admin code below.\n\n{FF0000}Wrong Code.");
            ShowPlayerDialog(playerid, DIALOG_ADMINCODE, DIALOG_STYLE_PASSWORD, ""#COL_EMB_WHITE"Admin Identification", string, "Login", "Cancel");
        }
    }
    return -1;
}
Reply
#2

Is Player[playerid][AdminCode] a string or an integer?
Reply
#3

Integer
The code is in numbers no letters includ, like:12345 or 123321
Reply
#4

YOu cant compare an interger as a string.. use

if(strval(inputtext) == admincode)....
Reply
#5

Quote:
Originally Posted by IceCube!
Посмотреть сообщение
YOu cant compare an interger as a string.. use

if(strval(inputtext) == admincode)....
I will try that tomorrow im on my tablet right now. I will post a update when I've tested it.
Reply
#6

Okay I'm almost certain thats the error though, as strcmp was looking for a "", which writing or numbers contained within, by using strval your dropping the string to numbers... if the string was "123565", it would change it to 123565 as an interger, therefore then comparable with the one you have saved.

ALTERNATIVELY, your could to Valstr... this suprisingly converts and Interger to a string HOWEVER I dont reccomendit as comparing intergers is quicker than checking a string.
Reply
#7

The identification thing works now, it logs me in.
But I also made something that when someone entered their code wrongly 2 times they will get banned, to prevent maybe a hacked admin account. But that is not working. It keeps saying "Wrong Code".

Can you help me fixing that aswel?
Reply
#8

The variable "Count" is destroyed once the response of the dialog has ran its course, make it a global variable that doesn't get destroyed....

pawn Код:
new AdminLoginAttempts[MAX_PLAYERS];
That should fix your problem as the memory isn't destroyed.
Reply
#9

Fixed Thank you
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)