fixed a small bug where loading under dlsym crashed
fixed line endings in vim
This commit is contained in:
parent
4dc4616933
commit
e6120fdcd6
|
@ -1,254 +1,254 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "sh_list.h"
|
#include "sh_list.h"
|
||||||
#include "CString.h"
|
#include "CString.h"
|
||||||
|
|
||||||
#include "amxmodx.h"
|
#include "amxmodx.h"
|
||||||
|
|
||||||
#include "CFlagManager.h"
|
#include "CFlagManager.h"
|
||||||
|
|
||||||
void CFlagManager::SetFile(const char *Filename)
|
void CFlagManager::SetFile(const char *Filename)
|
||||||
{
|
{
|
||||||
|
|
||||||
m_strConfigFile.assign(g_mod_name.c_str());
|
m_strConfigFile.assign(g_mod_name.c_str());
|
||||||
m_strConfigFile.append("/");
|
m_strConfigFile.append("/");
|
||||||
m_strConfigFile.append(get_localinfo("amxx_configsdir","addons/amxmodx/configs"));
|
m_strConfigFile.append(get_localinfo("amxx_configsdir","addons/amxmodx/configs"));
|
||||||
m_strConfigFile.append("/");
|
m_strConfigFile.append("/");
|
||||||
m_strConfigFile.append(Filename);
|
m_strConfigFile.append(Filename);
|
||||||
|
|
||||||
|
|
||||||
CreateIfNotExist();
|
CreateIfNotExist();
|
||||||
}
|
}
|
||||||
|
|
||||||
const int CFlagManager::LoadFile(const int force)
|
const int CFlagManager::LoadFile(const int force)
|
||||||
{
|
{
|
||||||
CheckIfDisabled();
|
CheckIfDisabled();
|
||||||
// If we're disabled get the hell out. now.
|
// If we're disabled get the hell out. now.
|
||||||
if (m_iDisabled)
|
if (m_iDisabled)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// if we're not forcing this, and NeedToLoad says we dont have to
|
// if we're not forcing this, and NeedToLoad says we dont have to
|
||||||
// then just stop
|
// then just stop
|
||||||
if (!force && !NeedToLoad())
|
if (!force && !NeedToLoad())
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
this->Clear();
|
this->Clear();
|
||||||
|
|
||||||
|
|
||||||
// We need to load the file
|
// We need to load the file
|
||||||
|
|
||||||
FILE *File;
|
FILE *File;
|
||||||
|
|
||||||
File=fopen(m_strConfigFile.c_str(),"r");
|
File=fopen(m_strConfigFile.c_str(),"r");
|
||||||
|
|
||||||
if (!File)
|
if (!File)
|
||||||
{
|
{
|
||||||
AMXXLOG_Log("[AMXX] FlagManager: Cannot open file \"%s\" (FILE pointer null!)",m_strConfigFile.c_str());
|
AMXXLOG_Log("[AMXX] FlagManager: Cannot open file \"%s\" (FILE pointer null!)",m_strConfigFile.c_str());
|
||||||
return -1;
|
return -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Trying to copy this almost exactly as other configs are read...
|
// Trying to copy this almost exactly as other configs are read...
|
||||||
String Line;
|
String Line;
|
||||||
|
|
||||||
char Command[256];
|
char Command[256];
|
||||||
char Flags[256];
|
char Flags[256];
|
||||||
|
|
||||||
String TempLine;
|
String TempLine;
|
||||||
while (!feof(File))
|
while (!feof(File))
|
||||||
{
|
{
|
||||||
|
|
||||||
Line._fread(File);
|
Line._fread(File);
|
||||||
|
|
||||||
char *nonconst=const_cast<char *>(Line.c_str());
|
char *nonconst=const_cast<char *>(Line.c_str());
|
||||||
|
|
||||||
|
|
||||||
// Strip out comments
|
// Strip out comments
|
||||||
while (*nonconst)
|
while (*nonconst)
|
||||||
{
|
{
|
||||||
if (*nonconst==';') // End the line at comments
|
if (*nonconst==';') // End the line at comments
|
||||||
{
|
{
|
||||||
*nonconst='\0';
|
*nonconst='\0';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
nonconst++;
|
nonconst++;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Command[0]='\0';
|
Command[0]='\0';
|
||||||
Flags[0]='\0';
|
Flags[0]='\0';
|
||||||
|
|
||||||
// Extract the command
|
// Extract the command
|
||||||
TempLine.assign(Line.c_str());
|
TempLine.assign(Line.c_str());
|
||||||
|
|
||||||
nonconst=const_cast<char *>(TempLine.c_str());
|
nonconst=const_cast<char *>(TempLine.c_str());
|
||||||
|
|
||||||
char *start=NULL;
|
char *start=NULL;
|
||||||
char *end=NULL;
|
char *end=NULL;
|
||||||
|
|
||||||
// move up line until the first ", mark this down as the start
|
// move up line until the first ", mark this down as the start
|
||||||
// then find the second " and mark it down as the end
|
// then find the second " and mark it down as the end
|
||||||
while (*nonconst!='\0')
|
while (*nonconst!='\0')
|
||||||
{
|
{
|
||||||
if (*nonconst=='"')
|
if (*nonconst=='"')
|
||||||
{
|
{
|
||||||
if (start==NULL)
|
if (start==NULL)
|
||||||
{
|
{
|
||||||
start=nonconst+1;
|
start=nonconst+1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
end=nonconst;
|
end=nonconst;
|
||||||
goto done_with_command;
|
goto done_with_command;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nonconst++;
|
nonconst++;
|
||||||
}
|
}
|
||||||
done_with_command:
|
done_with_command:
|
||||||
|
|
||||||
// invalid line?
|
// invalid line?
|
||||||
if (start==NULL || end==NULL)
|
if (start==NULL || end==NULL)
|
||||||
{
|
{
|
||||||
// TODO: maybe warn for an invalid non-commented line?
|
// TODO: maybe warn for an invalid non-commented line?
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
*end='\0';
|
*end='\0';
|
||||||
|
|
||||||
strncpy(Command,start,sizeof(Command)-1);
|
strncpy(Command,start,sizeof(Command)-1);
|
||||||
|
|
||||||
|
|
||||||
// Now do the same thing for the flags
|
// Now do the same thing for the flags
|
||||||
nonconst=++end;
|
nonconst=++end;
|
||||||
|
|
||||||
start=NULL;
|
start=NULL;
|
||||||
end=NULL;
|
end=NULL;
|
||||||
|
|
||||||
// move up line until the first ", mark this down as the start
|
// move up line until the first ", mark this down as the start
|
||||||
// then find the second " and mark it down as the end
|
// then find the second " and mark it down as the end
|
||||||
while (*nonconst!='\0')
|
while (*nonconst!='\0')
|
||||||
{
|
{
|
||||||
if (*nonconst=='"')
|
if (*nonconst=='"')
|
||||||
{
|
{
|
||||||
if (start==NULL)
|
if (start==NULL)
|
||||||
{
|
{
|
||||||
start=nonconst+1;
|
start=nonconst+1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
end=nonconst;
|
end=nonconst;
|
||||||
goto done_with_flags;
|
goto done_with_flags;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nonconst++;
|
nonconst++;
|
||||||
}
|
}
|
||||||
done_with_flags:
|
done_with_flags:
|
||||||
// invalid line?
|
// invalid line?
|
||||||
if (start==NULL || end==NULL)
|
if (start==NULL || end==NULL)
|
||||||
{
|
{
|
||||||
// TODO: maybe warn for an invalid non-commented line?
|
// TODO: maybe warn for an invalid non-commented line?
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
*end='\0';
|
*end='\0';
|
||||||
|
|
||||||
strncpy(Flags,start,sizeof(Flags)-1);
|
strncpy(Flags,start,sizeof(Flags)-1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!isalnum(*Command))
|
if (!isalnum(*Command))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Done sucking the command and flags out of the line
|
// Done sucking the command and flags out of the line
|
||||||
// now insert this command into the linked list
|
// now insert this command into the linked list
|
||||||
|
|
||||||
AddFromFile(const_cast<const char*>(&Command[0]),&Flags[0]);
|
AddFromFile(const_cast<const char*>(&Command[0]),&Flags[0]);
|
||||||
|
|
||||||
nonconst=const_cast<char *>(Line.c_str());
|
nonconst=const_cast<char *>(Line.c_str());
|
||||||
*nonconst='\0';
|
*nonconst='\0';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
fclose(File);
|
fclose(File);
|
||||||
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This gets called from LoadFile
|
* This gets called from LoadFile
|
||||||
* Do NOT flag the entries as NeedToWrite
|
* Do NOT flag the entries as NeedToWrite
|
||||||
* No comment is passed from the file because
|
* No comment is passed from the file because
|
||||||
* this should never get written
|
* this should never get written
|
||||||
*/
|
*/
|
||||||
void CFlagManager::AddFromFile(const char *Command, const char *Flags)
|
void CFlagManager::AddFromFile(const char *Command, const char *Flags)
|
||||||
{
|
{
|
||||||
|
|
||||||
CFlagEntry *Entry=new CFlagEntry;
|
CFlagEntry *Entry=new CFlagEntry;
|
||||||
|
|
||||||
Entry->SetName(Command);
|
Entry->SetName(Command);
|
||||||
Entry->SetFlags(Flags);
|
Entry->SetFlags(Flags);
|
||||||
|
|
||||||
// Link it
|
// Link it
|
||||||
m_FlagList.push_back(Entry);
|
m_FlagList.push_back(Entry);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void CFlagManager::LookupOrAdd(const char *Command, int &Flags, AMX *Plugin)
|
void CFlagManager::LookupOrAdd(const char *Command, int &Flags, AMX *Plugin)
|
||||||
{
|
{
|
||||||
if (m_iDisabled) // if disabled in core.ini stop
|
if (m_iDisabled) // if disabled in core.ini stop
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TempFlags=Flags;
|
int TempFlags=Flags;
|
||||||
if (TempFlags==-1)
|
if (TempFlags==-1)
|
||||||
{
|
{
|
||||||
TempFlags=0;
|
TempFlags=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<CFlagEntry *>::iterator iter;
|
List<CFlagEntry *>::iterator iter;
|
||||||
List<CFlagEntry *>::iterator end;
|
List<CFlagEntry *>::iterator end;
|
||||||
|
|
||||||
iter=m_FlagList.begin();
|
iter=m_FlagList.begin();
|
||||||
end=m_FlagList.end();
|
end=m_FlagList.end();
|
||||||
|
|
||||||
while (iter!=end)
|
while (iter!=end)
|
||||||
{
|
{
|
||||||
if (strcmp((*iter)->GetName()->c_str(),Command)==0)
|
if (strcmp((*iter)->GetName()->c_str(),Command)==0)
|
||||||
{
|
{
|
||||||
CFlagEntry *Entry=(*iter);
|
CFlagEntry *Entry=(*iter);
|
||||||
|
|
||||||
if (Entry->IsHidden()) // "!" flag, exclude this function
|
if (Entry->IsHidden()) // "!" flag, exclude this function
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Found, byref the new flags
|
// Found, byref the new flags
|
||||||
Flags=Entry->Flags();
|
Flags=Entry->Flags();
|
||||||
|
|
||||||
// Move it to the back of the list for faster lookup for the rest
|
// Move it to the back of the list for faster lookup for the rest
|
||||||
m_FlagList.erase(iter);
|
m_FlagList.erase(iter);
|
||||||
|
|
||||||
m_FlagList.push_back(Entry);
|
m_FlagList.push_back(Entry);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
iter++;
|
iter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// was not found, add it
|
// was not found, add it
|
||||||
|
|
||||||
CFlagEntry *Entry=new CFlagEntry;
|
CFlagEntry *Entry=new CFlagEntry;
|
||||||
|
|
||||||
Entry->SetName(Command);
|
Entry->SetName(Command);
|
||||||
Entry->SetFlags(TempFlags);
|
Entry->SetFlags(TempFlags);
|
||||||
|
|
||||||
if (Plugin)
|
if (Plugin)
|
||||||
{
|
{
|
||||||
|
@ -267,143 +267,143 @@ void CFlagManager::LookupOrAdd(const char *Command, int &Flags, AMX *Plugin)
|
||||||
// Link it
|
// Link it
|
||||||
m_FlagList.push_back(Entry);
|
m_FlagList.push_back(Entry);
|
||||||
|
|
||||||
}
|
}
|
||||||
void CFlagManager::WriteCommands(void)
|
void CFlagManager::WriteCommands(void)
|
||||||
{
|
{
|
||||||
List<CFlagEntry *>::iterator iter;
|
List<CFlagEntry *>::iterator iter;
|
||||||
List<CFlagEntry *>::iterator end;
|
List<CFlagEntry *>::iterator end;
|
||||||
FILE *File;
|
FILE *File;
|
||||||
int NeedToRead=0;
|
int NeedToRead=0;
|
||||||
|
|
||||||
// First off check the modified time of this file
|
// First off check the modified time of this file
|
||||||
// if it matches the stored modified time, then update
|
// if it matches the stored modified time, then update
|
||||||
// after we write so we do not re-read next map
|
// after we write so we do not re-read next map
|
||||||
struct stat TempStat;
|
struct stat TempStat;
|
||||||
|
|
||||||
stat(m_strConfigFile.c_str(),&TempStat);
|
stat(m_strConfigFile.c_str(),&TempStat);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (TempStat.st_mtime != m_Stat.st_mtime)
|
if (TempStat.st_mtime != m_Stat.st_mtime)
|
||||||
{
|
{
|
||||||
NeedToRead=1;
|
NeedToRead=1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
File=fopen(m_strConfigFile.c_str(),"a");
|
File=fopen(m_strConfigFile.c_str(),"a");
|
||||||
|
|
||||||
iter=m_FlagList.begin();
|
iter=m_FlagList.begin();
|
||||||
end=m_FlagList.end();
|
end=m_FlagList.end();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while (iter!=end)
|
while (iter!=end)
|
||||||
{
|
{
|
||||||
if ((*iter)->NeedWritten())
|
if ((*iter)->NeedWritten())
|
||||||
{
|
{
|
||||||
if ((*iter)->GetComment()->size())
|
if ((*iter)->GetComment()->size())
|
||||||
{
|
{
|
||||||
fprintf(File,"\"%s\" \t\"%s\" ; %s\n",(*iter)->GetName()->c_str(),(*iter)->GetFlags()->c_str(),(*iter)->GetComment()->c_str());
|
fprintf(File,"\"%s\" \t\"%s\" ; %s\n",(*iter)->GetName()->c_str(),(*iter)->GetFlags()->c_str(),(*iter)->GetComment()->c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(File,"\"%s\" \t\"%s\"\n",(*iter)->GetName()->c_str(),(*iter)->GetFlags()->c_str());
|
fprintf(File,"\"%s\" \t\"%s\"\n",(*iter)->GetName()->c_str(),(*iter)->GetFlags()->c_str());
|
||||||
}
|
}
|
||||||
(*iter)->SetNeedWritten(0);
|
(*iter)->SetNeedWritten(0);
|
||||||
}
|
}
|
||||||
++iter;
|
++iter;
|
||||||
};
|
};
|
||||||
|
|
||||||
fclose(File);
|
fclose(File);
|
||||||
|
|
||||||
|
|
||||||
// If NeedToRead was 0, then update the timestamp
|
// If NeedToRead was 0, then update the timestamp
|
||||||
// that was saved so we do not re-read this file
|
// that was saved so we do not re-read this file
|
||||||
// next map
|
// next map
|
||||||
if (!NeedToRead)
|
if (!NeedToRead)
|
||||||
{
|
{
|
||||||
stat(m_strConfigFile.c_str(),&TempStat);
|
stat(m_strConfigFile.c_str(),&TempStat);
|
||||||
|
|
||||||
m_Stat.st_mtime=TempStat.st_mtime;
|
m_Stat.st_mtime=TempStat.st_mtime;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CFlagManager::ShouldIAddThisCommand(const AMX *amx, const cell *params, const char *cmdname) const
|
int CFlagManager::ShouldIAddThisCommand(const AMX *amx, const cell *params, const char *cmdname) const
|
||||||
{
|
{
|
||||||
|
|
||||||
// If flagmanager is disabled then ignore this
|
// If flagmanager is disabled then ignore this
|
||||||
if (m_iDisabled)
|
if (m_iDisabled)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If 5th param exists it was compiled after this change was made
|
// If 5th param exists it was compiled after this change was made
|
||||||
// if it does not exist, try our logic at the end of this function
|
// if it does not exist, try our logic at the end of this function
|
||||||
// 5th param being > 0 means explicit yes
|
// 5th param being > 0 means explicit yes
|
||||||
// < 0 means auto detect (default is -1), treat it like there was no 5th param
|
// < 0 means auto detect (default is -1), treat it like there was no 5th param
|
||||||
// 0 means explicit no
|
// 0 means explicit no
|
||||||
|
|
||||||
if ((params[0] / sizeof(cell)) >= 5)
|
if ((params[0] / sizeof(cell)) >= 5)
|
||||||
{
|
{
|
||||||
if (params[5]>0) // This command was explicitly told to be included
|
if (params[5]>0) // This command was explicitly told to be included
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (params[5]==0) // this command was explicitly told to NOT be used
|
else if (params[5]==0) // this command was explicitly told to NOT be used
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// auto detect if we should use this command
|
// auto detect if we should use this command
|
||||||
|
|
||||||
// if command access is -1 (default, not set to ADMIN_ALL or any other access), then no
|
// if command access is -1 (default, not set to ADMIN_ALL or any other access), then no
|
||||||
if (params[3]==-1)
|
if (params[3]==-1)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// if command is (or starts with) "say", then no
|
// if command is (or starts with) "say", then no
|
||||||
if (strncmp(cmdname,"say",3)==0)
|
if (strncmp(cmdname,"say",3)==0)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// else use it
|
// else use it
|
||||||
return 1;
|
return 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void CFlagManager::Clear(void)
|
void CFlagManager::Clear(void)
|
||||||
{
|
{
|
||||||
List<CFlagEntry *>::iterator iter;
|
List<CFlagEntry *>::iterator iter;
|
||||||
List<CFlagEntry *>::iterator end;
|
List<CFlagEntry *>::iterator end;
|
||||||
|
|
||||||
iter=m_FlagList.begin();
|
iter=m_FlagList.begin();
|
||||||
end=m_FlagList.end();
|
end=m_FlagList.end();
|
||||||
|
|
||||||
while (iter!=end)
|
while (iter!=end)
|
||||||
{
|
{
|
||||||
delete (*iter);
|
delete (*iter);
|
||||||
|
|
||||||
++iter;
|
++iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_FlagList.clear();
|
m_FlagList.clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
void CFlagManager::CheckIfDisabled(void)
|
void CFlagManager::CheckIfDisabled(void)
|
||||||
{
|
{
|
||||||
if (atoi(get_localinfo("disableflagman","0"))==0)
|
if (atoi(get_localinfo("disableflagman","0"))==0)
|
||||||
{
|
{
|
||||||
m_iDisabled=0;
|
m_iDisabled=0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_iDisabled=1;
|
m_iDisabled=1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,219 +1,218 @@
|
||||||
#ifndef CFLAGMANAGER_H
|
#ifndef CFLAGMANAGER_H
|
||||||
#define CFLAGMANAGER_H
|
#define CFLAGMANAGER_H
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "sh_list.h"
|
#include "sh_list.h"
|
||||||
#include "CString.h"
|
#include "CString.h"
|
||||||
|
|
||||||
#include "amxmodx.h"
|
#include "amxmodx.h"
|
||||||
|
|
||||||
class CFlagEntry
|
class CFlagEntry
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
String m_strName; // command name ("amx_slap")
|
String m_strName; // command name ("amx_slap")
|
||||||
String m_strFlags; // string flags ("a","b")
|
String m_strFlags; // string flags ("a","b")
|
||||||
String m_strComment; // comment to write ("; admincmd.amxx")
|
String m_strComment; // comment to write ("; admincmd.amxx")
|
||||||
int m_iFlags; // bitmask flags
|
int m_iFlags; // bitmask flags
|
||||||
int m_iNeedWritten; // write this command on map change?
|
int m_iNeedWritten; // write this command on map change?
|
||||||
int m_iHidden; // set to 1 when the command is set to "!" access in
|
int m_iHidden; // set to 1 when the command is set to "!" access in
|
||||||
// the .ini file: this means do not process this command
|
// the .ini file: this means do not process this command
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CFlagEntry()
|
CFlagEntry()
|
||||||
{
|
{
|
||||||
m_iNeedWritten=0;
|
m_iNeedWritten=0;
|
||||||
m_iFlags=0;
|
m_iFlags=0;
|
||||||
m_iHidden=0;
|
m_iHidden=0;
|
||||||
};
|
};
|
||||||
const int NeedWritten(void) const
|
const int NeedWritten(void) const
|
||||||
{
|
{
|
||||||
return m_iNeedWritten;
|
return m_iNeedWritten;
|
||||||
};
|
};
|
||||||
|
|
||||||
void SetNeedWritten(const int i=1)
|
void SetNeedWritten(const int i=1)
|
||||||
{
|
{
|
||||||
m_iNeedWritten=i;
|
m_iNeedWritten=i;
|
||||||
};
|
};
|
||||||
|
|
||||||
const String *GetName(void) const
|
const String *GetName(void) const
|
||||||
{
|
{
|
||||||
return &m_strName;
|
return &m_strName;
|
||||||
};
|
};
|
||||||
|
|
||||||
const String *GetFlags(void) const
|
const String *GetFlags(void) const
|
||||||
{
|
{
|
||||||
return &m_strFlags;
|
return &m_strFlags;
|
||||||
};
|
};
|
||||||
const String *GetComment(void) const
|
const String *GetComment(void) const
|
||||||
{
|
{
|
||||||
return &m_strComment;
|
return &m_strComment;
|
||||||
};
|
};
|
||||||
|
|
||||||
const int Flags(void) const
|
const int Flags(void) const
|
||||||
{
|
{
|
||||||
return m_iFlags;
|
return m_iFlags;
|
||||||
};
|
};
|
||||||
|
|
||||||
void SetName(const char *data)
|
void SetName(const char *data)
|
||||||
{
|
{
|
||||||
m_strName.assign(data);
|
m_strName.assign(data);
|
||||||
};
|
};
|
||||||
void SetFlags(const char *flags)
|
void SetFlags(const char *flags)
|
||||||
{
|
{
|
||||||
// If this is a "!" entry then stop
|
// If this is a "!" entry then stop
|
||||||
if (flags && flags[0]=='!')
|
if (flags && flags[0]=='!')
|
||||||
{
|
{
|
||||||
SetHidden(1);
|
SetHidden(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_strFlags.assign(flags);
|
m_strFlags.assign(flags);
|
||||||
m_iFlags=UTIL_ReadFlags(flags);
|
m_iFlags=UTIL_ReadFlags(flags);
|
||||||
};
|
};
|
||||||
void SetFlags(const int flags)
|
void SetFlags(const int flags)
|
||||||
{
|
{
|
||||||
m_iFlags=flags;
|
m_iFlags=flags;
|
||||||
|
|
||||||
char FlagsString[32];
|
char FlagsString[32];
|
||||||
UTIL_GetFlags(FlagsString, flags);
|
UTIL_GetFlags(FlagsString, flags);
|
||||||
|
|
||||||
m_strFlags.assign(FlagsString);
|
m_strFlags.assign(FlagsString);
|
||||||
};
|
};
|
||||||
void SetComment(const char *comment)
|
void SetComment(const char *comment)
|
||||||
{
|
{
|
||||||
m_strComment.assign(comment);
|
m_strComment.assign(comment);
|
||||||
};
|
};
|
||||||
void SetHidden(int i=1)
|
void SetHidden(int i=1)
|
||||||
{
|
{
|
||||||
m_iHidden=i;
|
m_iHidden=i;
|
||||||
};
|
};
|
||||||
int IsHidden(void) const
|
int IsHidden(void) const
|
||||||
{
|
{
|
||||||
return m_iHidden;
|
return m_iHidden;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
class CFlagManager
|
class CFlagManager
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
List<CFlagEntry *> m_FlagList;
|
List<CFlagEntry *> m_FlagList;
|
||||||
String m_strConfigFile;
|
String m_strConfigFile;
|
||||||
struct stat m_Stat;
|
struct stat m_Stat;
|
||||||
int m_iForceRead;
|
int m_iForceRead;
|
||||||
int m_iDisabled;
|
int m_iDisabled;
|
||||||
|
|
||||||
|
|
||||||
void CreateIfNotExist(void) const
|
void CreateIfNotExist(void) const
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
fp=fopen(m_strConfigFile.c_str(),"r");
|
fp=fopen(m_strConfigFile.c_str(),"r");
|
||||||
|
|
||||||
if (!fp)
|
if (!fp)
|
||||||
{
|
{
|
||||||
// File does not exist, create the header
|
// File does not exist, create the header
|
||||||
fp=fopen(m_strConfigFile.c_str(),"a");
|
fp=fopen(m_strConfigFile.c_str(),"a");
|
||||||
|
|
||||||
if (fp)
|
if (fp)
|
||||||
{
|
{
|
||||||
fprintf(fp,"; This file will store the commands used by plugins, and their access level\n");
|
fprintf(fp,"; This file will store the commands used by plugins, and their access level\n");
|
||||||
fprintf(fp,"; To change the access of a command, edit the flags beside it and then\n");
|
fprintf(fp,"; To change the access of a command, edit the flags beside it and then\n");
|
||||||
fprintf(fp,"; change the server's map.\n;\n");
|
fprintf(fp,"; change the server's map.\n;\n");
|
||||||
fprintf(fp,"; Example: If I wanted to change the amx_slap access to require\n");
|
fprintf(fp,"; Example: If I wanted to change the amx_slap access to require\n");
|
||||||
fprintf(fp,"; RCON access (flag \"l\") I would change this:\n");
|
fprintf(fp,"; RCON access (flag \"l\") I would change this:\n");
|
||||||
fprintf(fp,"; \"amx_slap\" \"e\" ; admincmd.amxx\n");
|
fprintf(fp,"; \"amx_slap\" \"e\" ; admincmd.amxx\n");
|
||||||
fprintf(fp,"; To this:\n");
|
fprintf(fp,"; To this:\n");
|
||||||
fprintf(fp,"; \"amx_slap\" \"l\" ; admincmd.amxx\n;\n");
|
fprintf(fp,"; \"amx_slap\" \"l\" ; admincmd.amxx\n;\n");
|
||||||
fprintf(fp,"; To disable a specific command from being used with the command manager\n");
|
fprintf(fp,"; To disable a specific command from being used with the command manager\n");
|
||||||
fprintf(fp,"; and to only use the plugin-specified access set the flag to \"!\"\n;\n");
|
fprintf(fp,"; and to only use the plugin-specified access set the flag to \"!\"\n;\n");
|
||||||
fprintf(fp,"; NOTE: The plugin name at the end is just for reference to what plugin\n");
|
fprintf(fp,"; NOTE: The plugin name at the end is just for reference to what plugin\n");
|
||||||
fprintf(fp,"; uses what commands. It is ignored.\n\n");
|
fprintf(fp,"; uses what commands. It is ignored.\n\n");
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* Returns 1 if the timestamp for the file is different than the one we have loaded
|
* Returns 1 if the timestamp for the file is different than the one we have loaded
|
||||||
* 0 otherwise
|
* 0 otherwise
|
||||||
*/
|
*/
|
||||||
inline int NeedToLoad(void)
|
inline int NeedToLoad(void)
|
||||||
{
|
{
|
||||||
struct stat TempStat;
|
struct stat TempStat;
|
||||||
|
|
||||||
stat(m_strConfigFile.c_str(),&TempStat);
|
stat(m_strConfigFile.c_str(),&TempStat);
|
||||||
|
|
||||||
// If the modified timestamp does not match the stored
|
// If the modified timestamp does not match the stored
|
||||||
// timestamp than we need to re-read this file.
|
// timestamp than we need to re-read this file.
|
||||||
// Otherwise, ignore the file.
|
// Otherwise, ignore the file.
|
||||||
if (TempStat.st_mtime != m_Stat.st_mtime)
|
if (TempStat.st_mtime != m_Stat.st_mtime)
|
||||||
{
|
{
|
||||||
// Save down the modified timestamp
|
// Save down the modified timestamp
|
||||||
m_Stat.st_mtime=TempStat.st_mtime;
|
m_Stat.st_mtime=TempStat.st_mtime;
|
||||||
return 1;
|
return 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CFlagManager()
|
CFlagManager()
|
||||||
{
|
{
|
||||||
memset(&m_Stat,0x0,sizeof(struct stat));
|
memset(&m_Stat,0x0,sizeof(struct stat));
|
||||||
m_iDisabled=0;
|
m_iDisabled=0;
|
||||||
m_iForceRead=0;
|
m_iForceRead=0;
|
||||||
};
|
};
|
||||||
~CFlagManager()
|
~CFlagManager()
|
||||||
{
|
{
|
||||||
WriteCommands();
|
};
|
||||||
};
|
|
||||||
|
/**
|
||||||
/**
|
* Sets the filename in relation to amxmodx/configs
|
||||||
* Sets the filename in relation to amxmodx/configs
|
*/
|
||||||
*/
|
void SetFile(const char *Filename="cmdaccess.ini");
|
||||||
void SetFile(const char *Filename="cmdaccess.ini");
|
|
||||||
|
const char *GetFile(void) const { return m_strConfigFile.c_str(); };
|
||||||
const char *GetFile(void) const { return m_strConfigFile.c_str(); };
|
|
||||||
|
/**
|
||||||
/**
|
* Parse the file, and load all entries
|
||||||
* Parse the file, and load all entries
|
* Returns 1 on success, 0 on refusal (no need to), and -1 on error
|
||||||
* Returns 1 on success, 0 on refusal (no need to), and -1 on error
|
*/
|
||||||
*/
|
const int LoadFile(const int force=0);
|
||||||
const int LoadFile(const int force=0);
|
|
||||||
|
/**
|
||||||
/**
|
* Checks if the command exists in the list
|
||||||
* Checks if the command exists in the list
|
* If it does, it byrefs the flags for it
|
||||||
* If it does, it byrefs the flags for it
|
* If it does not, it adds it to the list
|
||||||
* If it does not, it adds it to the list
|
* These are added from register_*cmd calls
|
||||||
* These are added from register_*cmd calls
|
*/
|
||||||
*/
|
void LookupOrAdd(const char *Command, int &Flags, AMX *Plugin);
|
||||||
void LookupOrAdd(const char *Command, int &Flags, AMX *Plugin);
|
|
||||||
|
|
||||||
|
/**
|
||||||
/**
|
* Write the commands back to the file
|
||||||
* Write the commands back to the file
|
*/
|
||||||
*/
|
void WriteCommands(void);
|
||||||
void WriteCommands(void);
|
|
||||||
|
/**
|
||||||
/**
|
* Add this straight from the cmdaccess.ini file
|
||||||
* Add this straight from the cmdaccess.ini file
|
*/
|
||||||
*/
|
void AddFromFile(const char *Command, const char *Flags);
|
||||||
void AddFromFile(const char *Command, const char *Flags);
|
|
||||||
|
/**
|
||||||
/**
|
* Checks if this command should be added to flagman or not
|
||||||
* Checks if this command should be added to flagman or not
|
* This is only checked when adding commands from the register_* natives
|
||||||
* This is only checked when adding commands from the register_* natives
|
* If an admin manually adds a command to cmdaccess.ini it will be used
|
||||||
* If an admin manually adds a command to cmdaccess.ini it will be used
|
* regardless of whatever this function would say should be done with it
|
||||||
* regardless of whatever this function would say should be done with it
|
*/
|
||||||
*/
|
int ShouldIAddThisCommand(const AMX *amx, const cell *params, const char *cmdname) const;
|
||||||
int ShouldIAddThisCommand(const AMX *amx, const cell *params, const char *cmdname) const;
|
|
||||||
|
void Clear(void);
|
||||||
void Clear(void);
|
|
||||||
|
void CheckIfDisabled(void);
|
||||||
void CheckIfDisabled(void);
|
};
|
||||||
};
|
|
||||||
|
#endif // CFLAGMANAGER_H
|
||||||
#endif // CFLAGMANAGER_H
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user