Raised This Month: $ Target: $400
 0% 

Problem reading files in linux


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Killer zm
Senior Member
Join Date: Jun 2011
Old 05-14-2013 , 14:18   Problem reading files in linux
Reply With Quote #1

In this plugin :

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <fakemeta>

#define MAPSETTINGS 0

new ConfigDirectory[] = "precacheControl"
new WeaponsDirectory[] = "weapons"

new ConfigPath[200]
new 
WeaponsPath[200]

const 
MaxFilenameLength 100

new Array:C4Entries

enum Cvar 
{
    
CvarC4,
    
CvarCZ,
    
CvarHL,
    
CvarWeapons
}

new 
CvarSuffixes[Cvar][] = 
{
    
"c4",
    
"cz",
    
"hl",
    
"weapons"
}

new 
CvarPrefix[] = "precache_"

new Cvars[Cvar]

new 
HamHook:SpawnBombsiteHook1
new HamHook:SpawnBombsiteHook2

new Trie:BlockedEntries

validPathOrDie
(path[])
{
    if(!
dir_exists(path))
    {
        
set_fail_state("Plugin installation problem. You don't have the configuration folders in place")
    }
}

Array:
getFileEntries(file[],bool:isWeapon=false)
{
    static 
path[200]
    
    
formatex(path,charsmax(path),"%s%s.ini",isWeapon WeaponsPath ConfigPath file)
    
    if(!
file_exists(path))
    {
        
set_fail_state("Plugin installation problem. You don't have the configuration files in place")
    }
    
    new 
file fopen(path,"r")
    
    if(
file)
    {
        new Array:array = 
ArrayCreate(MaxFilenameLength)
        
        new 
line[MaxFilenameLength+1]
        
        while(
fgets(file,line,charsmax(line)))
        {
            
trim(line)
            
            
ArrayPushString(array,line)
        }
        
        
fclose(file)
        
        return array
    }
    else
    {
        static 
msg[200]
        
formatex(msg,charsmax(msg),"Failed to open file [%s]",path)
        
set_fail_state(msg)
    }
    
    return Array:
0
}

blockEntries(Array:array)
{
    new 
entryData[MaxFilenameLength]
    
    for(new 
i=0;i<ArraySize(array);i++)
    {
        
ArrayGetString(array,i,entryData,charsmax(entryData))
        
        
TrieSetCell(BlockedEntries,entryData,true)
    }
}

handleFolders()
{
    
get_configsdir(ConfigPath,charsmax(ConfigPath))
    
format(ConfigPath,charsmax(ConfigPath),"%s/%s/",ConfigPath,ConfigDirectory)
    
    
validPathOrDie(ConfigPath)
    
    
formatex(WeaponsPath,charsmax(WeaponsPath),"%s%s/",ConfigPath,WeaponsDirectory)
    
    
validPathOrDie(WeaponsPath)
}

handleCvars()
{
    new 
FullCvar[charsmax(CvarPrefix) + 10]
    
    new 
at copy(FullCvar,charsmax(FullCvar),CvarPrefix)
    
    for(new 
Cvar:i=Cvar:0;i<Cvar;i++)
    {
        
formatex(FullCvar[at],charsmax(FullCvar) - at,CvarSuffixes[i])
        
        
Cvars[i] = !!get_pcvar_num(register_cvar(FullCvar,"0"))
    }
}

blockWeapons()
{
    new 
path[200]
    
    
get_configsdir(path,charsmax(path))
    
#if MAPSETTINGS
    
new mapname[32]
    
get_mapname(mapName,charsmax(mapName))
    
format(path,charsmax(path),"%s/weaprest_%s.ini",pathmapname)
#else
    
format(path,charsmax(path),"%s/weaprest.ini",path)
#endif

    
new file fopen(path,"r")
    
    if(
file)
    {
        new 
line[100]
        
        while(
fgets(file,line,charsmax(line)))
        {
            
trim(line)
            
            if(
line[0] && line[0] != ';')
            {
                new 
spaceIndex contain(line," ")
                
line[spaceIndex] = 0
                
                blockEntries
(getFileEntries(line,true))
            }
        }
        
        
fclose(file)
    }
}

public 
plugin_precache()
{
    
register_plugin("precacheControl","1.0","")
    
    
BlockedEntries TrieCreate()
    
    
handleFolders()    
    
handleCvars()    
    
    if(!
Cvars[CvarCZ])
    {
        
blockEntries(getFileEntries("cz"))
    }
    
    if(!
Cvars[CvarHL])
    {
        
blockEntries(getFileEntries("hl"))
    }
    
    if(!
Cvars[CvarC4])
    {
        
blockEntries(C4Entries getFileEntries("c4",true))
        
        
SpawnBombsiteHook1 RegisterHam(Ham_Spawn,"func_bomb_target","precacheBombsite")
        
SpawnBombsiteHook2 RegisterHam(Ham_Spawn,"info_bomb_target","precacheBombsite")
    }    
    
    if(!
Cvars[CvarWeapons])
    {
        
blockWeapons()
    }
    
    
register_forward(FM_PrecacheModel,"precache")
    
register_forward(FM_PrecacheSound,"precache")
}

public 
precacheBombsite()
{    
    new 
entryData[MaxFilenameLength]
    
    for(new 
i=0;i<ArraySize(C4Entries);i++)
    {
        
ArrayGetString(C4Entries,i,entryData,charsmax(entryData))
        
        new 
len strlen(entryData)
        
        new 
soundExtension[] = ".wav"
        
        
new extensionIndex len charsmax(soundExtension)
        
        if(
extensionIndex 0)
        {
            if(
equal(entryData[extensionIndex],soundExtension))
            {
                
engfunc(EngFunc_PrecacheSound,entryData)
            }
            else
            {
                
engfunc(EngFunc_PrecacheModel,entryData)
            }
            
            
server_print("Unblocking precache [%s]",entryData)
        }
    }
    
    
DisableHamForward(SpawnBombsiteHook1)
    
DisableHamForward(SpawnBombsiteHook2)
}

public 
precache(data[])
{
    if(
TrieKeyExists(BlockedEntries,data))
    {
        
server_print("Blocking precache [%s]",data)
        return 
FMRES_SUPERCEDE
    
}
    
    return 
FMRES_IGNORED

on windows is reading perfectly from a directory witch is in configs: precacheControl with some .ini files but in linux, the precacheControl director is reading but .ini files that are inside is not reading ...

the problem I think is here

Code:
formatex(path,charsmax(path),"%s%s.ini",isWeapon ? WeaponsPath : ConfigPath , file)
because i get
Code:
Plugin installation problem. You don't have the configuration files in place
can be this somehow converted for linux or ... ?? i dont know ?? ... some one give some help here .
Thank You !

Last edited by Killer zm; 05-14-2013 at 14:21.
Killer zm is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-14-2013 , 15:18   Re: Problem reading files in linux
Reply With Quote #2

You need configuration files. It seems plugin doesn't find it. Check and make you have uploaded all the provided config files.
__________________
Arkshine is offline
Killer zm
Senior Member
Join Date: Jun 2011
Old 05-15-2013 , 10:00   Re: Problem reading files in linux
Reply With Quote #3

is working with configuration files .. thank you
you can close this
Killer zm is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:37.


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