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