AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Check log for specific words (https://forums.alliedmods.net/showthread.php?t=100959)

BeasT 08-19-2009 13:34

Check log for specific words
 
I need to check my log file that is placed in amxmodx/logs for specific words (actualy I need to check if the map, that is being currently played, name is written in the log). And if the log contains the map name than do nothing, and if doesn't contain - do something. And one more thing: the code should 'understand' the diffrence between de_dust and de_dust2 (these two are 'diffrent words').

Arkshine 08-19-2009 13:47

Re: Check log for specific words
 
You need :

- open_dir() : To open the directory wanted.
- next_file() : To read the next file in the directory handle.
- fopen() / fgets() / fclose() : To open the file, reading each line, and closing the file.

And while reading each line, you would need to use something like contain().
But depending what you need to find, you may want to try regex.

BeasT 08-19-2009 15:01

Re: Check log for specific words
 
I don't understand, need example :?

Alka 08-19-2009 15:57

Re: Check log for specific words
 
Here ->
PHP Code:

stock CheckForString(const szDir[16], const szFile[16], const szString[])
{
    new 
szLocalDir[32];
    
get_localinfo("amx_basedir"szLocalDircharsmax(szLocalDir));
    new 
szPath[64];
    
formatex(szPathcharsmax(szPath), "%s/%s/%s"szLocalDirszDirszFile);
    
    new 
iFile fopen(szPath);
    if(!
iFile)
        return 
0;
    
    new 
szBuffer[128];
    while(!
feof(iFile))
    {
        
fgets(iFileszBuffercharsmax(szBuffer));
        if(!
szBuffer[0])
            continue;
        
        if(
containi(szBufferszString) != -1)
        {
            
fclose(iFile);
            return 
1;
        }
    }
    
fclose(iFile);
    return 
0;


Just use CheckForString("logs", "somefile.log", "searched_string") , returns 0 if file not exists or string wasn't found else returns 1

Arkshine 08-19-2009 16:21

Re: Check log for specific words
 
Damn I've read too fastly. I've confused with another plugin which read files in a specific directory. http://workshop.mixedberry.net/Smile...on/th_045_.gif

Alka 08-19-2009 17:00

Re: Check log for specific words
 
Hey onion!

BeasT 08-19-2009 17:41

Re: Check log for specific words
 
Thx Alka!


All times are GMT -4. The time now is 15:12.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.