Help with forbidden characters [+1]
#1

For more reason i want to make a 'forbidden character' on character '@' for example.

I have this command.
Код:
CMD:changeemail(playerid, params[])
{
	new string[128];
	if(sscanf(params, "s[64]", params)) return SendClientMessage(playerid, COLOR_ORANGE, "{F97804}USAGE:{B4B5B7}{FFFFFF} /changeemail [new email]");

	new playername2[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playername2, sizeof(playername2));

            new string3[128];
			new playername3[MAX_PLAYER_NAME];
			GetPlayerName(playerid, playername3, sizeof(playername3));
			format(string3, sizeof(string3), "users/%s.ini", playername3);
            new File: hFile = fopen(string3, io_write);
			if (hFile)
			{
			    strmid(PlayerInfo[playerid][pEmail], params, 0, strlen(params), 255);
			    new var[32];
				format(var, 32, "Email=%s\n", PlayerInfo[playerid][pEmail]);fwrite(hFile, var);
			}
			fclose(hFile);

	format(string, sizeof(string), "You have changed your Email Adrees to: {FF6347}%s.", params);
	SendClientMessage(playerid, COLOR_WHITE, string);
	SavePlayerData(playerid);
	return 1;
}
So, i want to make when character '@' is not in text [/changeemail <text>] show you a message just like this "Sorry invalid email adress"

Someone can help me ? I gave +rep who help me to solve this problem, thanks.

(sorry for my bad english)
Reply
#2

You can use strfind to check for the character.
Reply
#3

Quote:
Originally Posted by PrawkC
Посмотреть сообщение
You can use strfind to check for the character.
I tried to make with strfind but doesn't work

Can you give me an example please ? Or to make me for '@' ?
Reply
#4

Quote:
Originally Posted by CaRa
Посмотреть сообщение
I tried to make with strfind but doesn't work

Can you give me an example please ? Or to make me for '@' ?
You probably didn't use it correctly, look it up on the wiki.. it shows you an example and it WILL work for what you're doing.
Reply
#5

strfind returns -1 when the needle is not found in the haystack.

An example of this would be:
pawn Код:
if(strfind(params, "@", true) == -1)
{
    // No @-sign!
}
Reply
#6

Quote:
Originally Posted by PrawkC
Посмотреть сообщение
You probably didn't use it correctly, look it up on the wiki.. it shows you an example and it WILL work for what you're doing.
Quote:
Originally Posted by AndreT
Посмотреть сообщение
strfind returns -1 when the needle is not found in the haystack.

An example of this would be:
pawn Код:
if(strfind(params, "@", true) == -1)
{
    // No @-sign!
}
Thanks a lot. My mistake was that i put 'playerid' instead of 'params'.
Reply
#7

Oy, I have another few things to say here...

1) Your command does not require sscanf parsing. It has one parameter only!
pawn Код:
CMD:changeemail(playerid, params[])
{
    if(isnull(params))
    {
        // Output the message about how the usage of the command really is!
    }

    // ...
    return true;
}
2) Your "var" array is a bit too small to contain larger e-mail addresses as their size, by rfcs, is allowed to up to 64 characters I believe.
pawn Код:
new var[64+1];
3) You don't actually need multiple arrays to store these strings, you don't use any of them at the same time. So don't waste memory! And don't get the same player's name TWICE.
pawn Код:
new string[128], playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername, sizeof(playername));
format(string, sizeof(string), "users/%s.ini", playername);
// new hFile = ...;
Reply
#8

Quote:
Originally Posted by AndreT
Посмотреть сообщение
Oy, I have another few things to say here...

1) Your command does not require sscanf parsing. It has one parameter only!
pawn Код:
CMD:changeemail(playerid, params[])
{
    if(isnull(params))
    {
        // Output the message about how the usage of the command really is!
    }

    // ...
    return true;
}
Ok, i didn't know that, thanks.

2) Your "var" array is a bit too small to contain larger e-mail addresses as their size, by rfcs, is allowed to up to 64 characters I believe.
pawn Код:
new var[64+1];
I get it.

3) You don't actually need multiple arrays to store these strings, you don't use any of them at the same time. So don't waste memory! And don't get the same player's name TWICE.
pawn Код:
new string[128], playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername, sizeof(playername));
format(string, sizeof(string), "users/%s.ini", playername);
// new hFile = ...;
I forgot to remove playername2 ... Can you delete the array that waste my memory ?

Код:
 new string3[128];
			new playername3[MAX_PLAYER_NAME];
			GetPlayerName(playerid, playername3, sizeof(playername3));
			format(string3, sizeof(string3), "users/%s.ini", playername3);
            new File: hFile = fopen(string3, io_write);
			if (hFile)
			{
			    strmid(PlayerInfo[playerid][pEmail], params, 0, strlen(params), 255);
			    new var[64+1];
				format(var, 32, "Email=%s\n", PlayerInfo[playerid][pEmail]);fwrite(hFile, var);
			}
			fclose(hFile);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)