AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with compile... (https://forums.alliedmods.net/showthread.php?t=222954)

AtomicServers 08-08-2013 10:41

Help with compile...
 
Hello guys I need help to compile this plugin:
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <colorchat>

#define PLUGIN "Chat"
#define VERSION "1.3"
#define AUTHOR "Alka"

#define USE_COLORCHAT

#define MAX_WARNINGS 3
#define MAX_LOGS 50

#define BYPASS_FLAG ADMIN_RCON

#define IsValidBlock(%0) (0 <= str_to_num(%0) <= 255)

enum (<<=1) {
    
    
ADV_BLOCK 1,
    
ADV_WARN,
    
ADV_KICK,
    
ADV_LOG,
    
ADV_BYPASS
};

enum {
    
    
ADDR_VALID 1,
    
ADDR_NOT_FOUND = -1
};

new 
g_pCvarMode;

new 
Trie:g_tCharsTrie:g_tBlocks;
new Array:
g_aDomains, Array:g_aWhitelist;

new 
g_iWarnings[33];

new 
g_szLogsFile[64];

public 
plugin_init() {
    
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
register_clcmd("say""clcmd_HandleChat");
    
register_clcmd("say_team""clcmd_HandleChat");
    
    
g_pCvarMode register_cvar("amx_advblock""abd");
    
    
g_tChars TrieCreate();
    
g_tBlocks TrieCreate();
    
    
g_aDomains ArrayCreate(6);
    
g_aWhitelist ArrayCreate(32);
}

public 
plugin_cfg()
{
    
get_basedir(g_szLogsFilecharsmax(g_szLogsFile));
    
add(g_szLogsFilecharsmax(g_szLogsFile), "/logs/advblock_logs.log");
    
    if(
file_size(g_szLogsFile1) / MAX_LOGS)
        
fclose(fopen(g_szLogsFile"w"));
    else
        
fclose(fopen(g_szLogsFile"a"));
    
    
LoadConfigs();
}

public 
plugin_end()
{
    
TrieDestroy(g_tChars);
    
TrieDestroy(g_tBlocks);
    
ArrayDestroy(g_aDomains);
    
ArrayDestroy(g_aWhitelist);
}

public 
client_disconnect(id)
{
    if(
g_iWarnings[id] > 0)
        
g_iWarnings[id] = 0;
}

public 
clcmd_HandleChat(id)
{
    if((
GetModFlags() & ADV_BYPASS) && get_user_flags(id) & BYPASS_FLAG)
        return 
PLUGIN_CONTINUE;
    
    new 
szText[191];
    
read_args(szTextcharsmax(szText));
    
remove_quotes(szText);
    
    if(
strlen(szText) < 4)
        return 
PLUGIN_CONTINUE;
    
    
TrieClear(g_tBlocks);
    
    new 
szBlock[4], iLen;
    new 
iNumSeqiNumBlocksiDel;
    new 
iLastBlock;
    new 
bool:bDuplicate;
    
    for(new 
sizeof szText i++)
    {
        if(
isdigit(szText[i]) && (sizeof szText))
        {
            
iLen += formatex(szBlock[iLen], charsmax(szBlock) - iLen"%c"szText[i]);
            
            if(
isdigit(szText[1]))
                
iNumSeq++;
            else
            {
                if(
IsValidBlock(szBlock))
                {
                    if(!
TrieKeyExists(g_tBlocksszBlock))
                    {
                        
TrieSetCell(g_tBlocksszBlock1);
                        
                        new 
iTo strlen(szBlock) == : (strlen(szBlock) == i);
                        if(
FindDiffChars(szTextcharsmax(szText), iLastBlockiTo) < 8)
                            
iNumBlocks++;
                        
                        
iLastBlock i;
                    }
                    else if(
TrieKeyExists(g_tBlocksszBlock) && !bDuplicate)
                    {
                        new 
iTo strlen(szBlock) == : (strlen(szBlock) == i);
                        if(
FindDiffChars(szTextcharsmax(szText), iLastBlockiTo) < 8)
                            
iNumBlocks++;
                        
                        
iLastBlock i;
                        
bDuplicate true;
                    }
                }
                
iLen 0;
            }
        }
        else
        {
            if(
szText[i] != 0)
            {
                
iDel++;
            }
        }
    }
    
    if((
iNumSeq && iNumBlocks 3) || (iNumBlocks && iDel 5) || CheckAddr(szTextcharsmax(szText)) != ADDR_NOT_FOUND)
    {
        new 
iFlags GetModFlags();
        
        if(
iFlags ADV_WARN)
        {
            if(
iFlags ADV_KICK)
            {
                
g_iWarnings[id]++;
                
#if !defined USE_COLORCHAT
                    
client_print(idprint_chat"Warning!!! Possible IP / Website advertising! [%d/%d] - Kick"g_iWarnings[id], MAX_WARNINGS);
                
#else
                    
client_print_color(idRED"^3[^4ChatGuardian^3] ^1Detected ^4[^3IP^4] ^1or ^4[^3Website^4] ^1advertising! ^4[^3%d^4/^3%d^4]"g_iWarnings[id], MAX_WARNINGS);
                
#endif
                
                
if(g_iWarnings[id] == 3)
                {
                    
server_cmd("kick #%d ^"Advertising!^""get_user_userid(id));
                    
g_iWarnings[id] = 0;
                }
            }
            else
            {
                
#if !defined USE_COLORCHAT
                    
client_print(idprint_chat"Warning!!! Possible IP / Website advertising!");
                
#else
                    
client_print_color(idRED"^4[^3ChatGuardian^4] ^1Detected ^3[^4IP^3] ^1or ^3[^4Website^3] ^1advertising!");
                
#endif
            
}
        }
        if(
iFlags ADV_LOG)
        {
            new 
szName[32];
            
get_user_name(idszNamecharsmax(szName));
            
            new 
iFile fopen(g_szLogsFile"a");
            
fprintf(iFile"Name: %s ^nChat: %s^n---------------------------------------^n"szNameszText);
            
fclose(iFile);
        }
        if(
iFlags ADV_BLOCK)
            return 
PLUGIN_HANDLED;
        else
            return 
PLUGIN_CONTINUE;
    }
    return 
PLUGIN_CONTINUE;
}

stock FindDiffChars(szString[], iLeniFromiTo)
{
    
TrieClear(g_tChars);
    
    new 
iChars;
    for(new 
iLen i++)
    {
        if(
iFrom iTo)
        {
            new 
szChar[2];
            
formatex(szCharcharsmax(szChar), "%c"szString[i]);
            
            if(!
TrieKeyExists(g_tCharsszChar))
            {
                
TrieSetCell(g_tCharsszChar1);
                
iChars++;
            }
        }
    }
    return 
iChars;
}

stock CheckAddr(szString[], iLen)
{
    new 
szText[128], iLen2;
    new 
i;
    for(
iLen i++)
    {
        if(!
isalpha(szString[i]) && !ValidAddrSeparator(szString[i]))
            continue;
        
        
iLen2 += formatex(szText[iLen2], charsmax(szText) - iLen2"%c"szString[i]);
    }
    
    new 
szTemp[6], szTemp1[32];
    for(
ArraySize(g_aWhitelist) ; i++)
    {
        
ArrayGetString(g_aWhitelistiszTemp1charsmax(szTemp1));
        if(
containi(szTextszTemp1) != -1)
        {
            
replace(szTextcharsmax(szText), szTemp1"");
            
i--;
        }
    }
    for(
ArraySize(g_aDomains) ; i++)
    {
        
ArrayGetString(g_aDomainsiszTempcharsmax(szTemp));
        
        if(
containi(szTextszTemp) > 0)
            return 
ADDR_VALID;
    }    
    return 
ADDR_NOT_FOUND;
}

stock bool:ValidAddrSeparator(iChar)
{
    new 
iChars[] = { ':''/''.' };
    for(new 
sizeof iChars i++)
    {
        if(
iChar == iChars[i])
            return 
true;
    }
    return 
false;
}

stock GetModFlags()
{
    new 
szVal[6];
    
get_pcvar_string(g_pCvarModeszValcharsmax(szVal));
    
    return 
read_flags(szVal);
}

stock LoadConfigs()
{
    new 
szFile[64];
    
get_configsdir(szFilecharsmax(szFile));
    
add(szFilecharsmax(szFile), "/advblock_config.ini");
    
    new 
iFile fopen(szFile"r");
    if(!
iFile)
        
set_fail_state("Error loading configuration file!");
    
    new 
szBuffer[32];
    new 
iConfig;
    while(!
feof(iFile))
    {
        
fgets(iFileszBuffercharsmax(szBuffer));
        
trim(szBuffer);
        
        if(!
szBuffer[0] || szBuffer[0] == ';')
            continue;
        
        if(
equal(szBuffer"#domains"))
        {
            
iConfig 1;
            continue;
        }
        else if(
equal(szBuffer"#whitelist"))
        {
            
iConfig 2;
            continue;
        }
        else
        {
            if(
szBuffer[0] != '{' || szBuffer[0] != '}')
            {
                switch(
iConfig)
                {
                    case 
1ArrayPushString(g_aDomainsszBuffer);
                    case 
2ArrayPushString(g_aWhitelistszBuffer);
                }
            }
        }
    }
    
fclose(iFile);


Can someone compile it and give it to me please?

YamiKaitou 08-08-2013 10:42

Re: Help with compile...
 
Compiles fine for me, what errors are you getting?

AtomicServers 08-08-2013 10:47

Re: Help with compile...
 
I get this: Error: Cannot read from file: "colorchat" on line 3

DWIGHTpN 08-08-2013 10:52

Re: Help with compile...
 
Compilator can't fiind colorchat library.
If you compile plugin on you pc, download colorchat library from: http://forums.alliedmods.net/showthread.php?p=851160

AtomicServers 08-08-2013 10:57

Re: Help with compile...
 
Can you tell me which version to use (stock or module) and where to put it please? Because I'm new and...

YamiKaitou 08-08-2013 11:05

Re: Help with compile...
 
Use the one that the author told you to use. Wherever you found the plugin should have told you the requirements for it

AtomicServers 08-08-2013 11:14

Re: Help with compile...
 
I still don't get it. Can't someone just compile it and attach the .amx file here please?

Black Rose 08-08-2013 11:43

Re: Help with compile...
 
You want the chatcolor.inc, since that's the file it cannot find.
Open the folder that contains your compiler, open the "include" folder. Place the .inc file here. Compile.

Another problem is that you're using functions from chatcolor.inc but you included the colorchat.inc.
Change the third row to:
#include <chatcolor>

If this is too hard you can compile it here.

AtomicServers 08-08-2013 11:49

Re: Help with compile...
 
I did what you said and it still gave me the same error so I compiled it in the site you gave me. Thanks! :)

Edit: Another problem came out... Before the plugin worked now it doesnt want to work???

Black Rose 08-08-2013 16:23

Re: Help with compile...
 
Then you must have broken it. Does it work if you remove this line?
Code:
#define USE_COLORCHAT
If not, start by checking if it's running.
Add debug after it in plugins.ini, does it print any messages in server console?
Add debug messages in form of "server_print()" or "client_print()" to see if where it halts and to check data that might be wrong.

EDIT: Sorry, I see the error now. You are using the names from chatcolor.inc but the parameters are from colorchat.inc. Just change all "client_print_color" to "ColorChat" and it should be fine.


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

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