SA-MP Forums Archive
file help please =D - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: file help please =D (/showthread.php?tid=71774)



file help please =D - Flo_White - 03.04.2009

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


Re: file help please =D - Jefff - 03.04.2009

Код:
	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


Re: file help please =D - Flo_White - 03.04.2009

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


Re: file help please =D - Donny_k - 03.04.2009

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'.


Re: file help please =D - Flo_White - 04.04.2009

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


Re: file help please =D - Jefff - 04.04.2009

Код:
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


Re: file help please =D - Flo_White - 04.04.2009

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


Re: file help please =D - Donny_k - 04.04.2009

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'.



Re: file help please =D - Flo_White - 04.04.2009

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


Re: file help please =D - phoenix0120 - 04.04.2009

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