SA-MP Forums Archive
[Tutorial] Desbugar o derrubamento do servidor pelo comando [%s] - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Non-English (https://sampforum.blast.hk/forumdisplay.php?fid=9)
+--- Forum: Languages (https://sampforum.blast.hk/forumdisplay.php?fid=33)
+---- Forum: Português/Portuguese (https://sampforum.blast.hk/forumdisplay.php?fid=34)
+----- Forum: Lançamentos/Releases (https://sampforum.blast.hk/forumdisplay.php?fid=56)
+----- Thread: [Tutorial] Desbugar o derrubamento do servidor pelo comando [%s] (/showthread.php?tid=643534)



Desbugar o derrubamento do servidor pelo comando [%s] - yFrank - 22.10.2017

Primeiramente, vгo na sua callback

Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
Depois de terem ido na callback, adicionem o seguinte cуdigo:

Код:
	if(strlen(inputtext) > 128)return SendClientMessage(playerid, COLOR_GREY, " O link que vocк digitou estб muito grande !");
    if(strfind(inputtext,"%", true) != -1)return SendClientMessage(playerid, COLOR_GREY, "{FFFFFF}Vocк nгo pode usar esse tipo de caractere.");
Explicaзгo:

Код:
if(strlen(inputtext) > 128)return SendClientMessage(playerid, COLOR_GREY, " O link que vocк digitou estб muito grande !"); - Permite que o player possa digitar atй 128 digitos
Код:
if(strfind(inputtext,"%", true) != -1)return SendClientMessage(playerid, COLOR_GREY, "{FFFFFF}Vocк nгo pode usar esse tipo de caractere."); - O player nгo pode digitar nenhum cуdigo com ''%'' nas dialogs, que й o caso que ocorre o derrubamento do servidor!
O caso de derrubamento, (Nгo sei se ocorre em todos os servidores de SAMP), mas na maioria das GM's RPG acontecem.
Quando o player executa algum dialog e digita o comando %s crasha o servidor.


Re: Desbugar o derrubamento do servidor pelo comando [%s] - IlanZ - 22.10.2017

muitobom


Re: Desbugar o derrubamento do servidor pelo comando [%s] - Bruno13 - 22.10.2017

Soluзгo mais prбtica

PHP код:
strreplace(inputtext"%s""#", .maxlength 128);

strreplace(string[], const search[], const replacement[], bool:ignorecase falsepos 0limit = -1maxlength sizeof(string))
{
    
// No need to do anything if the limit is 0.
    
if (limit == 0)
        return 
0;
    
    new
        
sublen strlen(search),
        
replen strlen(replacement),
            
bool:packed ispacked(string),
        
maxlen maxlength,
        
len strlen(string),
        
count 0
    
;
    
    
    
// "maxlen" holds the max string length (not to be confused with "maxlength", which holds the max. array size).
    // Since packed strings hold 4 characters per array slot, we multiply "maxlen" by 4.
    
if (packed)
        
maxlen *= 4;
    
    
// If the length of the substring is 0, we have nothing to look for..
    
if (!sublen)
        return 
0;
    
    
// In this line we both assign the return value from "strfind" to "pos" then check if it's -1.
    
while (-!= (pos strfind(stringsearchignorecasepos))) {
        
// Delete the string we found
        
strdel(stringpospos sublen);
        
        
len -= sublen;
        
        
// If there's anything to put as replacement, insert it. Make sure there's enough room first.
        
if (replen && len replen maxlen) {
            
strins(stringreplacementposmaxlength);

            
pos += replen;
            
len += replen;
        }
        
        
// Is there a limit of number of replacements, if so, did we break it?
        
if (limit != -&& ++count >= limit)
            break;
    }
    
    return 
count;




Re: Desbugar o derrubamento do servidor pelo comando [%s] - ForT - 22.10.2017

Ao invйs de bloquear o dialog para um jogador, seria mais simples fazer desse jeito:
PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    
// Tamanho da mensagem
    
new len strlen(inputtext);
    
    while (
len--) {
        
// Verificar se possui % na mensagem
        
if (inputtext[len] == '%'inputtext[len] = '#';
    }
   
//... resto do cуdigo 



Re: Desbugar o derrubamento do servidor pelo comando [%s] - BrunoLuiz - 23.10.2017

https://sampforum.blast.hk/showthread.php?tid=641164


Re: Desbugar o derrubamento do servidor pelo comando [%s] - connork - 23.10.2017

O erro й na callback SendClientMessage, o dialog й um caminho pra enviar o caractere e causar o problema. Eu fiz da forma abaixo, pois no meu servidor haviam jogadores utilizando o caractere "%" nas senhas de suas contas.

pawn Код:
forward SendClientMessageEx(playerid, color, const message[]);
public SendClientMessageEx(playerid, color, const message[]) {
    new messagef[256];
    format(messagef, (256), "%s", message);
    if(strlen(message) > 0)
    {
        format(messagef, (256), "%s", \
        str_replace("%", "%%", messagef));
    }
    else format(messagef, (256), "%s", " ");
    return SendClientMessage(playerid, color, messagef);
}

#if defined _ALS_SendClientMessage
    #undef SendClientMessage
#else
    #define _ALS_SendClientMessage
#endif
#define SendClientMessage SendClientMessageEx



Re: Desbugar o derrubamento do servidor pelo comando [%s] - CaioTJF - 24.10.2017

Eu transformei % em # nas saнdas dos dialogs e nгo pensei nesse detalhe das senhas.

rep++ connork


Re: Desbugar o derrubamento do servidor pelo comando [%s] - SrDivuOfficial - 25.10.2017

Eu Nгo estou contra mas eu acho q vocк usou o do bruno_Street como base... ou nгo usou... apesar de ele te postado primeiro...