PDA

View Full Version : Restricting names


Sellize
28/04/2015, 12:08 PM
Is there a way I can make a file in scriptfiles, example:

John_Big
Wayne_Johnson
Oele_Piemel

and whenever a player connects it will check if the name is in the file, if it is, kick them?

Karan007
28/04/2015, 12:22 PM
That's not needed. Just add this code under the OnPlayerConnect callback.

new PlayerName[24];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
if(strcmp(PlayerName,"John_Big",true))
{
Kick(playerid);
}
if(strcmp(PlayerName,"Wayne_Johnson",true))
{
Kick(playerid);
}
if(strcmp(PlayerName,"Oele_piemel",true))
{
Kick(playerid);
}

Sellize
28/04/2015, 12:23 PM
That's not needed. Just add this code under the OnPlayerConnect callback.

new PlayerName[24];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
if(strcmp(PlayerName,"John_Big",true))
{
Kick(playerid);
}
if(strcmp(PlayerName,"Wayne_Johnson",true))
{
Kick(playerid);
}
if(strcmp(PlayerName,"Oele_piemel",true))
{
Kick(playerid);
}


Yes, I was aware this was possible but I just gave an example of names.
In reality I want to block ALOT of names and doing it that way will take alot of time

Karan007
28/04/2015, 12:25 PM
new PlayerName[24];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
if(strcmp(PlayerName,"John_Big" || "Name" || "Name",true)) // Use or ||
{
Kick(playerid);
}

Try this.

Sellize
28/04/2015, 12:26 PM
new PlayerName[24];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
if(strcmp(PlayerName,"John_Big" || "Name" || "Name",true)) // Use or ||
{
Kick(playerid);
}

Try this.

Do you even know what you are doing dude?

BleverCastard
28/04/2015, 12:43 PM
new PlayerName[24];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
if(strcmp(PlayerName,"John_Big" || "Name" || "Name",true)) // Use or ||
{
Kick(playerid);
}

Try this.

What are you doing?

Do you even know what you are doing dude?
That is possible, yes. Though why don't you just add a variable to their account?

Sellize
28/04/2015, 01:29 PM
What are you doing?


That is possible, yes. Though why don't you just add a variable to their account?

It's not like that.
I just want to ban people from using certain names that might influence their reputation on my server.

Vince
28/04/2015, 01:33 PM
You need a datasource. What that source is, is up to you. It can be a hard coded array, or a file, or a table in a database. In either case, you will need to find out if the name exists in the datasource. For arrays and fiiles the method is similar: loop through the entire list to find out if the name is in there. For databases, a regular select.

Threshold
28/04/2015, 01:36 PM
Okay, lets say you have a file called 'BlockedNames.txt' in your scriptfiles folder.

I'm going to assume you're using ZCMD and SSCANF just to make my life easier.

CMD:blockname(playerid, params[])
{
// if(!IsPlayerAdmin(playerid)) return 0; // Your admin variable here, blah blah
new targetname[MAX_PLAYER_NAME];
if(sscanf(params, "s", targetname)) return SendClientMessage(playerid, -1, "USAGE: /blockname [player name]");
new append[55];
format(append, sizeof(append), "%s\r\n", targetname);
new File:blockedlist = fopen("BlockedNames.txt", io_append);
if(!blockedlist) return SendClientMessage(playerid, -1, "Failed to open blocked names list.");
fwrite(blockedlist, append);
fclose(blockedlist);
format(append, sizeof(append), "Name '%s' successfully blocked.", targetname);
SendClientMessage(playerid, -1, append);
return 1;
}

public OnPlayerConnect(playerid)
{
CheckBlockedName(playerid);
return 1;
}

CheckBlockedName(playerid)
{
if(!fexist("BlockedNames.txt")) return 0;
new File:blockedlist = fopen("BlockedNames.txt", io_read);
new output[30], playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername, sizeof(playername));
while(fread(blockedlist, output))
{
if(!strcmp(playername, output, true))
{
// Player is using a blocked name, kick player?
break;
}
}
return 1;
}

References:
http://wiki.sa-mp.com/wiki/Fopen
http://wiki.sa-mp.com/wiki/Fwrite
http://wiki.sa-mp.com/wiki/Fread
http://wiki.sa-mp.com/wiki/Strcmp
http://wiki.sa-mp.com/wiki/GetPlayerName

EDIT: By the way, this is one of the 'data source' methods that Vince mentioned.

Gammix
28/04/2015, 01:42 PM
Pretty simple, using simple string and file functions:
#define MAX_NAMES 100//how many mximum names your file can have

new bad_names[MAX_NAMES][MAX_PLAYER_NAME + 7];
new total_bad_names_from_file = 0;

public OnGameModeInit()
{
new File:file = fopen("bad_names.txt", io_read);
new names[MAX_PLAYER_NAME + 7];//7 for extra characters
if(file)
{
while(fread(file, names))
{
for(new i, j = strlen(names); i < j; i++)
{
if(names[i] == '\n' || names[i] == '\r')
{
names[i] = '\0';
}
bad_names[total_bad_names_from_file] = names;
//add to total
total_bad_names_from_file += 1;
}
}
fclose(file);
}
return 1;
}

public OnPlayerConnect(playerid)
{
new username[MAX_PLAYER_NAME];
GetPlayerName(playerid, username, sizeof(username));
for(new i; i < total_bad_names_from_file; i++)
{
if(! strcmp(bad_names[i], username))
{
Kick(playerid);//kick the player
return 1;
}
}
return 1;
}

This will allow you kick all the players listed in Scriptfiles/bad_names.txt.

EDIT: i was late in replying though but this one works well.

Evocator
28/04/2015, 01:43 PM
Hi, you can do it using two ways:

1)
Using MYSQL (which is recommend), create a table with nicknames you need to forbid,
Call
SELECT LOCATE(`ForbiddenNames`, '%e') FROM `table` | PlayerName

Now once you get a response (thread your queries) and you found rows, then the nickname contains forbidden phrases, thus you kick the player.

2)
Create a .txt file, plainly add the forbidden nicks below one another
Bla
Fluk
Test
Shit
Nerd

Then, load the file, and split these phrases and save it using an array.

if ((file = fopen("ForbiddenNames.txt",io_read)))
{
while (fread(file, string))
{
for (new i = 0, j = strlen(string); i < j; i++)
{
if (string[i] == '\n' || string[i] == '\r')
string[i] = '\0'; //null it.
}

ForbiddenNames[sForbiddenNames] = string; //save it
sForbiddenNames++;
}
fclose(file);
}



And now once the guy connects, and has a nick, we can loop through the saved phrases and kick if detected.
for (new i = 0; i != sForbiddenNames; i++)
{
if (~strfind(Name, ForbiddenNames[i], true))
{
//Kick them
break;
}
}

Sellize
28/04/2015, 01:48 PM
Thank you all!

Threshold
29/04/2015, 06:35 AM
Urgh, I didn't even consider the \r and \n. My bad.