Portal SAMP
[Ajuda] Sistema whitelist - Versão de Impressão

+- Portal SAMP (https://portalsamp.com)
+-- Fórum: SA-MP (https://portalsamp.com/forumdisplay.php?fid=5)
+--- Fórum: Área de suporte (https://portalsamp.com/forumdisplay.php?fid=6)
+--- Tópico: [Ajuda] Sistema whitelist (/showthread.php?tid=2790)

Páginas: 1 2


Sistema whitelist - fear - 12/09/2022

boa noite. eu peguei esse sistema no discord do pawn coders ele é de whitelist

o problema dele e que uso o comando /wl nick do player e ele escreve no whitelist.txt ao invez do nick escreve dentro do whitelist.txt a palavra whitelist.txt kkk alguém sabe o pq? mudei pra "s" e add playerid ao invez de um pib que estava no sscanf.

codigo:

Código PHP:
CMD:wl(playerid,params[])
{
    if(
IsPlayerAdmin(playerid))
    {
        if(
sscanf(params,"u",playerid)) return SendClientMessage(playerid,-1,"Use /wl [Nome_Sobrenome]");
        
AddPlayerToWhitelist(playerid);
    }
    return 
1;
}
CMD:deletarwl(playerid,params[])
{
    if(
IsPlayerAdmin(playerid))
    {
        if(
sscanf(params,"u",playerid)) return SendClientMessage(playerid,-1,"Use /deletar wl [playerid / name]");
        
RemovePlayerFromWhitelist(playerid);
    }
    return 
1;
}

stock AddPlayerToWhitelist(playerid)
{
    new 
name[32];
    if(!
fexist(Whitelist)) {new File:fhandle fopen(Whitelist,io_write); fclose(fhandle);}
    
GetPlayerName(playeridname32);
    new 
File:hfile fopen(Whitelistio_append);
    new 
str[128];
    
format(str128"Whitelist.txt\%s\r\n"name);
    
fwrite(hfilestr);
    
fclose(hfile);
}

stock RemovePlayerFromWhitelist(playerid)
{
    new 
name[32], string[256], line=0;
    
GetPlayerName(playeridname32);
    if(!
fexist(Whitelist)) {new File:fhandle fopen(Whitelist,io_write); fclose(fhandle);}
    new 
File:hfile fopen(Whitelistio_read);
    while(
fread(hfilestring))
    {
        if(!
strcmp(stringnamefalse) && strlen(string))
        {
            
fdeleteline(Whitelistline);
        }
        
line++;
    }
    
fclose(hfile);




RE: Sistema whitelist - MarcosBrazz - 12/09/2022

Possivelmente o problema está nessa parte:
Código:
format(str, 128, "Whitelist.txt\%s\r\n", name);
fwrite(hfile, str);
Acredito que só retirar o "Whitelist.txt\"
Código:
format(str, 128, "%s\r\n", name);
fwrite(hfile, str);



RE: Sistema whitelist - fear - 12/09/2022

(12/09/2022 19:54)MarcosBrazz Escreveu: Possivelmente o problema está nessa parte:
Código:
format(str, 128, "Whitelist.txt\%s\r\n", name);
fwrite(hfile, str);
Acredito que só retirar o "Whitelist.txt\"
Código:
format(str, 128, "%s\r\n", name);
fwrite(hfile, str);

Não escreve nada no whitelist.txt agora so se eu coloco manualmente pra funcionar pelo comando ele não escreveu o nick no txt não


RE: Sistema whitelist - MarcosBrazz - 12/09/2022

Fiz umas modificações, testa ai
Código:
//~~~~~~~~~~~~~~~~~~
CMD:wl(playerid,params[])
{
    new name[24+1];
    if(IsPlayerAdmin(playerid))
    {
        if(sscanf(params,"s[24]",name)) return SendClientMessage(playerid,-1,"Use /wl [Nome_Sobrenome]");
        AddPlayerToWhitelist(name);
    }
    return 1;
}
CMD:deletarwl(playerid,params[])
{
    new name[24+1];
    if(IsPlayerAdmin(playerid))
    {
        if(sscanf(params,"s[24]",name)) return SendClientMessage(playerid,-1,"Use /deletar wl [playerid / name]");
        RemovePlayerFromWhitelist(name);
    }
    return 1;
}

stock AddPlayerToWhitelist(name[])
{
    if(!fexist(Whitelist)) {new File:fhandle = fopen(Whitelist,io_write); fclose(fhandle);}
    new File:hfile = fopen(Whitelist, io_append);
    new str[128];
    format(str, 128, "%s\r\n", name);
    fwrite(hfile, str);
    fclose(hfile);
}

stock RemovePlayerFromWhitelist(name[])
{
    new string[256], line=0;
    if(!fexist(Whitelist)) {new File:fhandle = fopen(Whitelist,io_write); fclose(fhandle);}
    new File:hfile = fopen(Whitelist, io_read);
    while(fread(hfile, string))
    {
        if(!strcmp(string, name, false) && strlen(string))
        {
            fdeleteline(Whitelist, line);
        }
        line++;
    }
    fclose(hfile);
}
//~~~~~~~~~~~~~~~~



RE: Sistema whitelist - fear - 12/09/2022

(12/09/2022 20:41)MarcosBrazz Escreveu: Fiz umas modificações, testa ai
Código:
//~~~~~~~~~~~~~~~~~~
CMD:wl(playerid,params[])
{
    new name[24+1];
    if(IsPlayerAdmin(playerid))
    {
        if(sscanf(params,"s[24]",name)) return SendClientMessage(playerid,-1,"Use /wl [Nome_Sobrenome]");
        AddPlayerToWhitelist(name);
    }
    return 1;
}
CMD:deletarwl(playerid,params[])
{
    new name[24+1];
    if(IsPlayerAdmin(playerid))
    {
        if(sscanf(params,"s[24]",name)) return SendClientMessage(playerid,-1,"Use /deletar wl [playerid / name]");
        RemovePlayerFromWhitelist(name);
    }
    return 1;
}

stock AddPlayerToWhitelist(name[])
{
    if(!fexist(Whitelist)) {new File:fhandle = fopen(Whitelist,io_write); fclose(fhandle);}
    new File:hfile = fopen(Whitelist, io_append);
    new str[128];
    format(str, 128, "%s\r\n", name);
    fwrite(hfile, str);
    fclose(hfile);
}

stock RemovePlayerFromWhitelist(name[])
{
    new string[256], line=0;
    if(!fexist(Whitelist)) {new File:fhandle = fopen(Whitelist,io_write); fclose(fhandle);}
    new File:hfile = fopen(Whitelist, io_read);
    while(fread(hfile, string))
    {
        if(!strcmp(string, name, false) && strlen(string))
        {
            fdeleteline(Whitelist, line);
        }
        line++;
    }
    fclose(hfile);
}
//~~~~~~~~~~~~~~~~
Agora ele escreveu o nick porém ele não escreveu abaixo do nick que coloquei manualmente pra poder testar.. assim ele ficou como no print abaixo. não libero o nick pra logar o nick é "teste"


RE: Sistema whitelist - MarcosBrazz - 12/09/2022

Ele não ficou abaixo pois como você colocou manualmente, ele não foi com "\r\n" para ir para a proxima linha, mas é só apagar tudo que tiver no arquivo e utilizar o comando novamente


RE: Sistema whitelist - fear - 13/09/2022

(12/09/2022 22:10)MarcosBrazz Escreveu: Ele não ficou abaixo pois como você colocou manualmente, ele não foi com "\r\n" para ir para a proxima linha, mas é só apagar tudo que tiver no arquivo e utilizar o comando novamente


Depois de add mais de um nick ele ficou desse jeito e mesmo assim não autorizo nenhum dos nicks abaixo ai.

nicks: reck, novonick e antonio

eu tenho que add o nick fear manualmente para poder logar no sv.. talvez seja isso? mas como vou burlar? autorizando admin logar sem precisar do whitelist eu pensei...

Depois de usar o /wl o nick fear que add manualmente tb não consegue mais logar.. não sei oque estou fazendo de errado kkkk

codigo do onplayerconnect:

Código PHP:
    if(!IsWhitelisted(playerid))
    {
    
        new 
WL[2000];
        
strins(WL,"{FF0000}FACA A WHITELIST NO CANAL LIBERAR-WL EM NOSSO DISCORD\n",strlen(WL));
        
strins(WL,"\n",strlen(WL));
        
strins(WL,"{FF0000}DISCORD: \n",strlen(WL));
        
strins(WL,"\n",strlen(WL));
        
strins(WL,"{FFFFFF}DUVIDAS? CHAME UM STAFF NO PRIVADO DO DISCORD\n",strlen(WL));
        
ShowPlayerDialog(playerid,WLZPDIALOG_STYLE_MSGBOX"{6495ED}# {FFFFFF}WHITELIST ZP",WL"Sair""");
        
Kick(playerid);
        return 
1;
    } 

PRINT:


RE: Sistema whitelist - MarcosBrazz - 13/09/2022

Nos mande a função "IsWhitelisted"


RE: Sistema whitelist - fear - 13/09/2022

(13/09/2022 10:03)MarcosBrazz Escreveu: Nos mande a função "IsWhitelisted"
Código PHP:
stock IsWhitelisted(playerid)
{
    new 
string[256], name[32];
    
GetPlayerName(playeridname32);
    if(!
fexist(Whitelist)) {new File:fhandle fopen(Whitelist,io_write); fclose(fhandle);}
    new 
File:hfile fopen("Whitelist.txt"io_read);
    while(
fread(hfilestring))
    {
        if(!
strcmp(stringnamefalse) && strlen(string))
        {
            return 
true;
         }
    }
    
fclose(hfile);
    return 
false;




RE: Sistema whitelist - MarcosBrazz - 13/09/2022

Substitui por isso
Código:
stock IsWhitelisted(playerid)
{
    new string[256], name[24];
    GetPlayerName(playerid, name, 32);
    if(!fexist(Whitelist)) {new File:fhandle = fopen(Whitelist,io_write); fclose(fhandle);}
    new File:hfile = fopen("Whitelist.txt", io_read);
    while(fread(hfile, string))
    {
        if(strfind(string, name, true) != -1 && strlen(string))
        {
            return 1;
        }
    }
    fclose(hfile);
    return 0;
}