Thread: [Solved] Contain in .ini dont work
View Single Post
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-29-2021 , 16:46   Re: Contain in .ini dont work
Reply With Quote #4

Quote:
Originally Posted by The overrated maniac View Post
Thanks all of it worked. When I put szFileData[50000] server crashed, I did it with 9000 and works, what is the max lenght?
The theoretical max is not really relevant here since it's much larger than you actually need. You should only use a value that make sense for the use case. For example, an IP address can only be 15 characters, at most. So, it depends on what you're storing in this file and how it's formatted. If you are storing IP addresses, you could get away with a size of 18 (to account for the newline and carriage return and the null character) but I would recommend doubling this value.


Quote:
Originally Posted by The overrated maniac View Post
Edit: testing more I became with a bigger problem.. now I dont have a output, it dosnt put anything in say.

PHP Code:
new Path[256];
        
get_configsdir(Pathcharsmax(Path));
        
formatex(Pathcharsmax(Path),"%s/%s"PathgFileName);
    
        if(!
file_exists(Path)){
            return 
PLUGIN_HANDLED;
        }
    
        new 
fopen(Path"rt");
    
        new 
szFileData[2000];
    
        while(
fgets(fszFileDatacharsmax(szFileData))){
        
            
trim(szFileData);
            
            if(
contain(szFileDatag_szUserIP) != 1){
                
client_print(0print_chat"CONTAIN IP");
                return 
PLUGIN_HANDLED;
            }
            else{
                
client_print(0print_chat"NO CONTAIN");
                return 
PLUGIN_HANDLED;
            }
        }
        
fclose(f); 
Even another message that isnt in the function dont work but I have a client_cmd in this function and it works.. its like the output stop working
Don't return in the middle of reading a file because you are creating a memory leak by not properly closing the file every time this code is called.

Also, you are using a value of 1 with contain() which is wrong, you need to use -1.

If you still can't fix it, it will make it much easier to help you if you attach your .sma file.
__________________
fysiks is offline