file help please =D
#1

my script is this:
Код:
new File:badname=fopen("fAdmin/Config/badnames.cfg",io_read);
  format(string,sizeof(string),"%s",PlayerName(playerid));
  while(fread(badname, string))
  {
    if(!strcmp(string,PlayerName(playerid),true))
    {
      new blacklist[128];
      SendClientMessage(playerid,COLOR_YELLOW,"[Server] Your Name is blacklisted!");
      format(blacklist,sizeof(blacklist),"[Server] %s has been kicked by the Server [Reason: Forbidden Name]",PlayerName(playerid));
      SendClientMessageToAll(COLOR_RED,blacklist);
      KickLog(blacklist);
      Kick(playerid);
      return 1;
    }
  }
but when my name is in that file and i connect i don't get kicked
please help me

greetings
Reply
#2

Код:
	new File:badname=fopen("fAdmin/Config/badnames.cfg",io_read);
	new string[128];
	while(fread(badname, string))
	{
		if(!strcmp(string,PlayerName(playerid),true))
		{
			new blacklist[128];
			SendClientMessage(playerid,COLOR_YELLOW,"[Server] Your Name is blacklisted!");
			format(blacklist,sizeof(blacklist),"[Server] %s has been kicked by the Server [Reason: Forbidden Name]",PlayerName(playerid));
			SendClientMessageToAll(COLOR_RED,blacklist);
			KickLog(blacklist);
			Kick(playerid);
			return 1;
		}
	}
and u need
Код:
fclose(badname);
:P
Reply
#3

where do i need to put
Код:
fclose(badname);
to?
under
Код:
Kick(playerid);
?
Reply
#4

You would add the close after the while loop as it's still being used until the loop finishes or is stopped (break) and the name will need it's '/n' stripping off it before comparing so take a look around for 'StripNewLine'.
Reply
#5

that's it:
Код:
new File:badname=fopen("fAdmin/Config/badnames.cfg",io_read);
  while(fread(badname, string))
  {
    if(!strcmp(string,PlayerName(playerid),true))
    {
      new blacklist[128];
      SendClientMessage(playerid,COLOR_YELLOW,"[Server] Your Name is blacklisted!");
      format(blacklist,sizeof(blacklist),"[Server] %s has been kicked by the Server [Reason: Forbidden Name]",PlayerName(playerid));
      SendClientMessageToAll(COLOR_RED,blacklist);
      KickLog(blacklist);
      Kick(playerid);
      return 1;
    }
  }
  fclose(badname);
but it still doesn't work
Reply
#6

Код:
public OnPlayerConnect(playerid)
{
	if(fexist("fAdmin/Config/badnames.cfg"))
	{
	new File:badname=fopen("fAdmin/Config/badnames.cfg",io_read);
	while(fread(badname, string))
	{
		for(new i = 0; i < strlen(string); i++) if(string[i] == '\n' || string[i] == '\r') string[i] = '\0';
		if(!strcmp(PlayerName(playerid),string,true))
		{
			new blacklist[128];
			SendClientMessage(playerid,COLOR_YELLOW,"[Server] Your Name is blacklisted!");
			format(blacklist,sizeof(blacklist),"[Server] %s has been kicked by the Server [Reason: Forbidden Name]",PlayerName(playerid));
			SendClientMessageToAll(COLOR_RED,blacklist);
			KickLog(blacklist);
			Kick(playerid);
		}
	}
	fclose(badname);
	}
	return 1;
}
:P
Reply
#7

my Forbid-Command:

Код:
dcmd_forbidname(playerid,params[])
{
	if(PlayerData[playerid][Level] >= 2)
	{
	  new name,string[128],bname[128],File:badname;
	  if(sscanf(params,"c",name)) return SendClientMessage(playerid, COLOR_SYSTEM, "Usage: /forbidname [name]");
		badname=fopen("fAdmin/Config/badnames.cfg",io_append);
		format(bname,sizeof(bname),"%s\r\n",params);
		fwrite(badname,bname);
		fclose(badname);
	  format(string,sizeof(string),"[Server] Administrator %s has forbidden the Name %s",PlayerName(playerid),params);
	  SendClientMessageToAll(COLOR_RED,string);
	  return 1;
	}
	else return SendClientMessage(playerid,COLOR_RED,"Admins only!");
}
Код:
if(fexist("fAdmin/Config/badnames.cfg"))
	{
	new File:badname=fopen("fAdmin/Config/badnames.cfg",io_read);
	while(fread(badname, string))
	{
		for(new i = 0; i < strlen(string); i++) if(string[i] == '\n' || string[i] == '\r') string[i] = '\0';
		if(!strcmp(PlayerName(playerid),string,true))
		{
			new blacklist[128];
			SendClientMessage(playerid,COLOR_YELLOW,"[Server] Your Name is blacklisted!");
			format(blacklist,sizeof(blacklist),"[Server] %s has been kicked by the Server [Reason: Forbidden Name]",PlayerName(playerid));
			SendClientMessageToAll(COLOR_RED,blacklist);
			KickLog(blacklist);
			Kick(playerid);
		}
	}
	fclose(badname);
	}
	return 1;
it still doesn't work. The name is inthe File but i can still connect with that name
Reply
#8

Quote:
Originally Posted by Donny
You would add the close after the while loop as it's still being used until the loop finishes or is stopped (break) and the name will need it's '/n' stripping off it before comparing so take a look around for 'StripNewLine'.
Reply
#9

and how would it look like then? i tried but i failed and it doesn't work D:
Reply
#10

new File:badname=fopen("fAdmin\\Config\\badnames.cfg", io_read);
if(!badname) { return 1; }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)