Unreachable code, fatal error etc.
#1

Hello,

I've have tried so much to fix this, but it seems impossible


Код:
(425) : warning 225: unreachable code
(425) : error 029: invalid expression, assumed zero
(432) : error 014: invalid statement; not in switch
(432) : warning 215: expression has no effect
(432) : error 001: expected token: ";", but found ":"
(432) : error 029: invalid expression, assumed zero
(432) : fatal error 107: too many error messages on one line
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DialogRegister:
        {
            if(!response) return Kick(playerid);
            {
                new EncryptedPass[130], query[256];
                WP_Hash(EncryptedPass, sizeof(EncryptedPass), inputtext);
                {
                    new string[128];
                    SendClientMessage(playerid, COLOR_RED, "[ERROR]: Your password must be 6 to 129 characters long!");
                    format(string, sizeof(string), "This server requires you to register an account before playing\n\nUsername: %s\n\nEnter your desired password below then click ok.",PlayerName(playerid));
                    ShowPlayerDialog(playerid,DialogRegister,DIALOG_STYLE_INPUT,"{EDDC57}Registration required",string,"Register","Cancel");
                    return 1;
                   
                    }else { // 425
                    mysql_format(MySQLCon, query, sizeof(query), "INSERT INTO `players` (`user`, `pass`, `IP`) VALUES ('%e', '%s', '%s')", PlayerName(playerid), EncryptedPass, PlayerIP(playerid));
                    mysql_tquery(MySQLCon, query, "OnPlayerRegister", "i", playerid);
                }
            }
        }
    }
    case DialogLogin: // line 432
    {
        if(!response) return Kick(playerid);
        {
            new Lquery[256];
            mysql_format(MySQLCon, Lquery, sizeof(query), "SELECT * FROM `players` WHERE `user` = '%e' LIMIT 1", PlayerName(playerid));
            mysql_tquery(MySQLCon, Lquery, "OnPlayerLogin", "i", playerid);
            } else {
            LoginAttempt[playerid]++; new string[128];
            if(LoginAttempt[playerid] == 1)
            {
                format(string, sizeof(string), "Before playing you must login\n\nUsername: %s\n\nEnter your password below and click login",PlayerName(playerid));
                ShowPlayerDialog(playerid,DialogLogin,DIALOG_STYLE_PASSWORD,"{EDDC57}Login required",string,"Login","Cancel");
                SendClientMessage(playerid, -1,"{B30000}[ERROR]: {FFFFFF}You have entered an incorrect password. [1/3]");
            } else if(LoginAttempt[playerid] == 2)
            {
                format(string, sizeof(string), "Before playing you must login\n\nUsername: %s\n\nEnter your password below and click login",PlayerName(playerid));
                ShowPlayerDialog(playerid,DialogLogin,DIALOG_STYLE_PASSWORD,"{EDDC57}Login required",string,"Login","Cancel");
                SendClientMessage(playerid, -1,"{B30000}[ERROR] {FFFFFF}You have entered an incorrect password. [2/3]");
            } else if(LoginAttempt[playerid] == 3)
            {
                SendClientMessage(playerid, -1,"{B30000}[ERROR] {FFFFFF}You have entered an incorrect password. [3/3]");
                format(string,sizeof(string),"{208DD6}[SERVER] {FFFFFF}%s[%d] has been kicked from the server. (Max password attempts)",PlayerName(playerid),playerid);
                SendClientMessageToAll(COLOR_WHITE,string);
                Kick(playerid);
            }
        }
    }
    return 1;
}
Reply
#2

Код:
(425) : warning 225: unreachable code
(425) : error 029: invalid expression, assumed zero
Why would you "else" a nothing?

Код:
(432) : error 014: invalid statement; not in switch
(432) : warning 215: expression has no effect
(432) : error 001: expected token: ";", but found ":"
(432) : error 029: invalid expression, assumed zero
(432) : fatal error 107: too many error messages on one line
You went off the switch statement, and straight after you are trying to use a case again.
Reply
#3

Never mind
Reply
#4

I have no idea how you even managed to come up with this code.

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DialogRegister:
        {
            if(!response) return Kick(playerid);
            {
                new EncryptedPass[130], query[256];
                WP_Hash(EncryptedPass, sizeof(EncryptedPass), inputtext);
//There should be a check here to see if the password is between 6 and 129 characters
                {
                    new string[128];
                    SendClientMessage(playerid, COLOR_RED, "[ERROR]: Your password must be 6 to 129 characters long!");
                    format(string, sizeof(string), "This server requires you to register an account before playing\n\nUsername: %s\n\nEnter your desired password below then click ok.",PlayerName(playerid));
                    ShowPlayerDialog(playerid,DialogRegister,DIALOG_STYLE_INPUT,"{EDDC57}Registration required",string,"Register","Cancel");
                    return 1;
                   
                    }else { // 425
                    mysql_format(MySQLCon, query, sizeof(query), "INSERT INTO `players` (`user`, `pass`, `IP`) VALUES ('%e', '%s', '%s')", PlayerName(playerid), EncryptedPass, PlayerIP(playerid));
                    mysql_tquery(MySQLCon, query, "OnPlayerRegister", "i", playerid);
                }
            }
        }
//Everything from case DialogLogin until the line before return 1 should be here
    }
    case DialogLogin: // line 432
    {
        if(!response) return Kick(playerid);
        {
            new Lquery[256];
            mysql_format(MySQLCon, Lquery, sizeof(query), "SELECT * FROM `players` WHERE `user` = '%e' LIMIT 1", PlayerName(playerid));
            mysql_tquery(MySQLCon, Lquery, "OnPlayerLogin", "i", playerid);
            } else {
            LoginAttempt[playerid]++; new string[128];
            if(LoginAttempt[playerid] == 1)
            {
                format(string, sizeof(string), "Before playing you must login\n\nUsername: %s\n\nEnter your password below and click login",PlayerName(playerid));
                ShowPlayerDialog(playerid,DialogLogin,DIALOG_STYLE_PASSWORD,"{EDDC57}Login required",string,"Login","Cancel");
                SendClientMessage(playerid, -1,"{B30000}[ERROR]: {FFFFFF}You have entered an incorrect password. [1/3]");
            } else if(LoginAttempt[playerid] == 2)
            {
                format(string, sizeof(string), "Before playing you must login\n\nUsername: %s\n\nEnter your password below and click login",PlayerName(playerid));
                ShowPlayerDialog(playerid,DialogLogin,DIALOG_STYLE_PASSWORD,"{EDDC57}Login required",string,"Login","Cancel");
                SendClientMessage(playerid, -1,"{B30000}[ERROR] {FFFFFF}You have entered an incorrect password. [2/3]");
            } else if(LoginAttempt[playerid] == 3)
            {
                SendClientMessage(playerid, -1,"{B30000}[ERROR] {FFFFFF}You have entered an incorrect password. [3/3]");
                format(string,sizeof(string),"{208DD6}[SERVER] {FFFFFF}%s[%d] has been kicked from the server. (Max password attempts)",PlayerName(playerid),playerid);
                SendClientMessageToAll(COLOR_WHITE,string);
                Kick(playerid);
            }
        }
    }
    return 1;
}
I added comments that'll explain you how to fix the problems.
Reply
#5

Quote:
Originally Posted by FUNExtreme
Посмотреть сообщение
I have no idea how you even managed to come up with this code.

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DialogRegister:
        {
            if(!response) return Kick(playerid);
            {
                new EncryptedPass[130], query[256];
                WP_Hash(EncryptedPass, sizeof(EncryptedPass), inputtext);
//There should be a check here to see if the password is between 6 and 129 characters
                {
                    new string[128];
                    SendClientMessage(playerid, COLOR_RED, "[ERROR]: Your password must be 6 to 129 characters long!");
                    format(string, sizeof(string), "This server requires you to register an account before playing\n\nUsername: %s\n\nEnter your desired password below then click ok.",PlayerName(playerid));
                    ShowPlayerDialog(playerid,DialogRegister,DIALOG_STYLE_INPUT,"{EDDC57}Registration required",string,"Register","Cancel");
                    return 1;
                   
                    }else { // 425
                    mysql_format(MySQLCon, query, sizeof(query), "INSERT INTO `players` (`user`, `pass`, `IP`) VALUES ('%e', '%s', '%s')", PlayerName(playerid), EncryptedPass, PlayerIP(playerid));
                    mysql_tquery(MySQLCon, query, "OnPlayerRegister", "i", playerid);
                }
            }
        }
//Everything from case DialogLogin until the line before return 1 should be here
    }
    case DialogLogin: // line 432
    {
        if(!response) return Kick(playerid);
        {
            new Lquery[256];
            mysql_format(MySQLCon, Lquery, sizeof(query), "SELECT * FROM `players` WHERE `user` = '%e' LIMIT 1", PlayerName(playerid));
            mysql_tquery(MySQLCon, Lquery, "OnPlayerLogin", "i", playerid);
            } else {
            LoginAttempt[playerid]++; new string[128];
            if(LoginAttempt[playerid] == 1)
            {
                format(string, sizeof(string), "Before playing you must login\n\nUsername: %s\n\nEnter your password below and click login",PlayerName(playerid));
                ShowPlayerDialog(playerid,DialogLogin,DIALOG_STYLE_PASSWORD,"{EDDC57}Login required",string,"Login","Cancel");
                SendClientMessage(playerid, -1,"{B30000}[ERROR]: {FFFFFF}You have entered an incorrect password. [1/3]");
            } else if(LoginAttempt[playerid] == 2)
            {
                format(string, sizeof(string), "Before playing you must login\n\nUsername: %s\n\nEnter your password below and click login",PlayerName(playerid));
                ShowPlayerDialog(playerid,DialogLogin,DIALOG_STYLE_PASSWORD,"{EDDC57}Login required",string,"Login","Cancel");
                SendClientMessage(playerid, -1,"{B30000}[ERROR] {FFFFFF}You have entered an incorrect password. [2/3]");
            } else if(LoginAttempt[playerid] == 3)
            {
                SendClientMessage(playerid, -1,"{B30000}[ERROR] {FFFFFF}You have entered an incorrect password. [3/3]");
                format(string,sizeof(string),"{208DD6}[SERVER] {FFFFFF}%s[%d] has been kicked from the server. (Max password attempts)",PlayerName(playerid),playerid);
                SendClientMessageToAll(COLOR_WHITE,string);
                Kick(playerid);
            }
        }
    }
    return 1;
}
I added comments that'll explain you how to fix the problems.
For example
pawn Код:
if(strlen(inputtext) < 6 || strlen(inputtext) > 129)
?
Reply
#6

Quote:
Originally Posted by Interscope
Посмотреть сообщение
For example
pawn Код:
if(strlen(inputtext) < 6 || strlen(inputtext) > 129)
?
Like that, yes.
Reply
#7

Код:
  warning 219: local variable "query" shadows a variable at a preceding level
(220) : warning 219: local variable "query" shadows a variable at a preceding level
(237) : warning 219: local variable "query" shadows a variable at a preceding level
(366) : warning 219: local variable "query" shadows a variable at a preceding level
(381) : warning 219: local variable "query" shadows a variable at a preceding level
(416) : warning 219: local variable "query" shadows a variable at a preceding level
(430) : error 002: only a single statement (or expression) can follow each "case"
(430) : warning 215: expression has no effect
(431) : warning 209: function "OnDialogResponse" should return a value
(432) : error 010: invalid function or declaration
(434) : error 010: invalid function or declaration
(437) : error 021: symbol already defined: "mysql_format"
(439) : error 010: invalid function or declaration
(441) : error 010: invalid function or declaration
(446) : error 010: invalid function or declaration
(451) : error 010: invalid function or declaration
(460) : error 010: invalid function or declaration
(686) : warning 203: symbol is never used: "LoginAttempt"
(686) : warning 203: symbol is never used: "query"
I'm really close to flipping here.

Thanks for the answer though, I give up
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)