mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2024-12-25 14:25:38 +03:00
latest cleaned files for today (i cant read more :o )
This commit is contained in:
parent
16ad8739e7
commit
52b1d67ca2
@ -35,7 +35,9 @@
|
||||
// *****************************************************
|
||||
// class CmdMngr
|
||||
// *****************************************************
|
||||
CmdMngr::CmdMngr() {
|
||||
|
||||
CmdMngr::CmdMngr()
|
||||
{
|
||||
memset(sortedlists, 0, sizeof(sortedlists));
|
||||
srvcmdlist = 0;
|
||||
clcmdlist = 0;
|
||||
@ -49,10 +51,9 @@ CmdMngr::CmdMngr() {
|
||||
|
||||
}
|
||||
|
||||
CmdMngr::Command::Command( CPluginMngr::CPlugin* pplugin,const char* pcmd,
|
||||
const char* pinfo , int pflags , int pfunc,
|
||||
bool pviewable, CmdMngr* pparent ) : commandline(pcmd) , info(pinfo) {
|
||||
|
||||
CmdMngr::Command::Command(CPluginMngr::CPlugin* pplugin, const char* pcmd, const char* pinfo, int pflags,
|
||||
int pfunc, bool pviewable, CmdMngr* pparent) : commandline(pcmd), info(pinfo)
|
||||
{
|
||||
char szCmd[64], szArg[64];
|
||||
*szCmd = 0; *szArg = 0;
|
||||
sscanf(pcmd, "%s %s", szCmd, szArg);
|
||||
@ -78,17 +79,21 @@ CmdMngr::Command* CmdMngr::registerCommand( CPluginMngr::CPlugin* plugin , int
|
||||
Command* b = new Command(plugin, cmd, info, level, func, listable, this);
|
||||
if (b == 0) return 0;
|
||||
setCmdLink(&sortedlists[0], b);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
CmdMngr::Command* CmdMngr::getCmd(long int id, int type, int access)
|
||||
{
|
||||
//if (id >= 1024 || id < 0) return (Command*)id;
|
||||
if ( id < 0 ){
|
||||
for (CmdMngr::iterator a = begin( type ); a ; ++a){
|
||||
if (id < 0)
|
||||
{
|
||||
for (CmdMngr::iterator a = begin(type); a ; ++a)
|
||||
{
|
||||
if ((*a).id == id)
|
||||
return &(*a);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -98,9 +103,7 @@ CmdMngr::Command* CmdMngr::getCmd( long int id ,int type, int access )
|
||||
buf_cmdaccess = access;
|
||||
buf_cmdtype = type;
|
||||
buf_cmdid = id;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
int a = id;
|
||||
id -= buf_cmdid;
|
||||
buf_cmdid = a;
|
||||
@ -108,17 +111,12 @@ CmdMngr::Command* CmdMngr::getCmd( long int id ,int type, int access )
|
||||
|
||||
while (buf_cmdptr)
|
||||
{
|
||||
|
||||
if ( (*buf_cmdptr).gotAccess( access ) &&
|
||||
(*buf_cmdptr).getPlugin()->isExecutable( (*buf_cmdptr).getFunction() )
|
||||
if ((*buf_cmdptr).gotAccess(access) && (*buf_cmdptr).getPlugin()->isExecutable((*buf_cmdptr).getFunction())
|
||||
&& (*buf_cmdptr).isViewable())
|
||||
{
|
||||
|
||||
if (id-- == 0)
|
||||
return &(*buf_cmdptr);
|
||||
|
||||
}
|
||||
|
||||
++buf_cmdptr;
|
||||
}
|
||||
|
||||
@ -138,10 +136,7 @@ int CmdMngr::getCmdNum( int type, int access )
|
||||
|
||||
while (a)
|
||||
{
|
||||
|
||||
if ( (*a).gotAccess( access ) &&
|
||||
(*a).getPlugin()->isExecutable( (*a).getFunction() )
|
||||
&& (*a).isViewable() )
|
||||
if ((*a).gotAccess(access) && (*a).getPlugin()->isExecutable((*a).getFunction()) && (*a).isViewable())
|
||||
++buf_num;
|
||||
++a;
|
||||
}
|
||||
@ -169,20 +164,18 @@ void CmdMngr::setCmdLink( CmdLink** a , Command* c, bool sorted )
|
||||
|
||||
np->next = *a;
|
||||
*a = np;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
while (*a) a = &(*a)->next;
|
||||
*a = np;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void CmdMngr::clearCmdLink(CmdLink** phead, bool pclear)
|
||||
{
|
||||
while( *phead ){
|
||||
while (*phead)
|
||||
{
|
||||
CmdLink* pp = (*phead)->next;
|
||||
|
||||
if (pclear) delete (*phead)->cmd;
|
||||
delete *phead;
|
||||
*phead = pp;
|
||||
@ -191,39 +184,50 @@ void CmdMngr::clearCmdLink( CmdLink** phead, bool pclear )
|
||||
|
||||
void CmdMngr::Command::setCmdType(int a)
|
||||
{
|
||||
switch(a){
|
||||
switch(a)
|
||||
{
|
||||
case CMD_ConsoleCommand: cmdtype |= 3; break;
|
||||
case CMD_ClientCommand: cmdtype |= 1; break;
|
||||
case CMD_ServerCommand: cmdtype |= 2; break;
|
||||
}
|
||||
if ( cmdtype & 1 ) { // ClientCommand
|
||||
|
||||
if (cmdtype & 1) // ClientCommand
|
||||
{
|
||||
parent->setCmdLink(&parent->sortedlists[1], this);
|
||||
if (!parent->registerCmdPrefix(this))
|
||||
parent->setCmdLink(&parent->clcmdlist, this, false);
|
||||
}
|
||||
if ( cmdtype & 2 ) { // ServerCommand
|
||||
|
||||
if (cmdtype & 2) // ServerCommand
|
||||
{
|
||||
parent->setCmdLink(&parent->sortedlists[2], this);
|
||||
parent->setCmdLink(&parent->srvcmdlist, this, false);
|
||||
}
|
||||
}
|
||||
|
||||
const char* CmdMngr::Command::getCmdType() const {
|
||||
switch( cmdtype ){
|
||||
const char* CmdMngr::Command::getCmdType() const
|
||||
{
|
||||
switch(cmdtype)
|
||||
{
|
||||
case 1: return "client";
|
||||
case 2: return "server";
|
||||
case 3: return "console";
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
bool CmdMngr::registerCmdPrefix(Command* cc)
|
||||
{
|
||||
CmdPrefix** b = findPrefix(cc->getCommand());
|
||||
if (*b){
|
||||
|
||||
if (*b)
|
||||
{
|
||||
setCmdLink(&(*b)->list, cc, false);
|
||||
cc->prefix = (*b)->name.size();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -231,22 +235,29 @@ void CmdMngr::registerPrefix( const char* nn )
|
||||
{
|
||||
if (*nn == 0) return;
|
||||
CmdPrefix** b = findPrefix(nn);
|
||||
|
||||
if (*b) return;
|
||||
*b = new CmdPrefix(nn, this);
|
||||
}
|
||||
|
||||
CmdMngr::CmdPrefix** CmdMngr::findPrefix( const char* nn ){
|
||||
CmdMngr::CmdPrefix** CmdMngr::findPrefix(const char* nn)
|
||||
{
|
||||
CmdPrefix** aa = &prefixHead;
|
||||
while(*aa){
|
||||
|
||||
while (*aa)
|
||||
{
|
||||
if (!strncmp((*aa)->name.c_str(), nn, (*aa)->name.size()))
|
||||
break;
|
||||
aa = &(*aa)->next;
|
||||
}
|
||||
|
||||
return aa;
|
||||
}
|
||||
|
||||
void CmdMngr::clearPrefix(){
|
||||
while(prefixHead){
|
||||
void CmdMngr::clearPrefix()
|
||||
{
|
||||
while (prefixHead)
|
||||
{
|
||||
CmdPrefix* a = prefixHead->next;
|
||||
delete prefixHead;
|
||||
prefixHead = a;
|
||||
@ -264,7 +275,8 @@ void CmdMngr::clear()
|
||||
clearBufforedInfo();
|
||||
}
|
||||
|
||||
void CmdMngr::clearBufforedInfo() {
|
||||
void CmdMngr::clearBufforedInfo()
|
||||
{
|
||||
buf_type = -1;
|
||||
buf_access = 0;
|
||||
buf_id = -1;
|
||||
@ -274,4 +286,3 @@ void CmdMngr::clearBufforedInfo() {
|
||||
}
|
||||
|
||||
int CmdMngr::Command::uniqueid = 0;
|
||||
|
||||
|
@ -48,6 +48,7 @@ EventsMngr::ClEvent::ClEvent(CPluginMngr::CPlugin* plugin, int func, int flags)
|
||||
m_FlagWorld = (flags & 1) ? true : false; // flag a
|
||||
m_FlagPlayer = (flags & 2) ? true : false; // flag b
|
||||
m_FlagOnce = (flags & 4) ? true : false; // flag c
|
||||
|
||||
if (flags & 24)
|
||||
{
|
||||
m_FlagAlive = (flags & 16) ? true : false; // flag e
|
||||
@ -64,12 +65,14 @@ EventsMngr::ClEvent::~ClEvent()
|
||||
{
|
||||
cond_t *tmp1 = m_Conditions;
|
||||
cond_t *tmp2 = NULL;
|
||||
|
||||
while (tmp1)
|
||||
{
|
||||
tmp2 = tmp1->next;
|
||||
delete tmp1;
|
||||
tmp1 = tmp2;
|
||||
}
|
||||
|
||||
m_Conditions = NULL;
|
||||
}
|
||||
|
||||
@ -82,14 +85,17 @@ void EventsMngr::NextParam()
|
||||
|
||||
MsgDataEntry *tmp = NULL;
|
||||
int tmpSize = 0;
|
||||
|
||||
if (m_ParseVault)
|
||||
{
|
||||
// copy to tmp
|
||||
tmp = new MsgDataEntry[m_ParseVaultSize];
|
||||
|
||||
if (!tmp)
|
||||
{
|
||||
return; // :TODO: Error report !!
|
||||
}
|
||||
|
||||
memcpy(tmp, m_ParseVault, m_ParseVaultSize * sizeof(MsgDataEntry));
|
||||
tmpSize = m_ParseVaultSize;
|
||||
delete [] m_ParseVault;
|
||||
@ -102,6 +108,7 @@ void EventsMngr::NextParam()
|
||||
m_ParseVaultSize = INITIAL_PARSEVAULT_SIZE;
|
||||
|
||||
m_ParseVault = new MsgDataEntry[m_ParseVaultSize];
|
||||
|
||||
if (tmp)
|
||||
{
|
||||
memcpy(m_ParseVault, tmp, tmpSize * sizeof(MsgDataEntry));
|
||||
@ -178,10 +185,11 @@ void EventsMngr::ClEvent::registerFilter(char *filter)
|
||||
if (m_Conditions)
|
||||
{
|
||||
cond_t *tmp = m_Conditions;
|
||||
|
||||
while (tmp->next)
|
||||
tmp = tmp->next;
|
||||
tmp->next = tmpCond;
|
||||
|
||||
tmp->next = tmpCond;
|
||||
}
|
||||
else
|
||||
m_Conditions = tmpCond;
|
||||
@ -194,6 +202,7 @@ EventsMngr::ClEvent* EventsMngr::registerEvent(CPluginMngr::CPlugin* plugin, int
|
||||
return NULL;
|
||||
|
||||
ClEvent *event = new ClEvent(plugin, func, flags);
|
||||
|
||||
if (!event)
|
||||
return NULL;
|
||||
|
||||
@ -221,7 +230,6 @@ void EventsMngr::parserInit(int msg_type, float* timer, CPlayer* pPlayer, int in
|
||||
if ((*iter).m_Done)
|
||||
continue;
|
||||
|
||||
|
||||
if (!(*iter).m_Plugin->isExecutable((*iter).m_Func))
|
||||
{
|
||||
(*iter).m_Done = true;
|
||||
@ -247,6 +255,7 @@ void EventsMngr::parserInit(int msg_type, float* timer, CPlayer* pPlayer, int in
|
||||
(*iter).m_Done = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
m_ParseNotDone = true;
|
||||
}
|
||||
|
||||
@ -257,6 +266,7 @@ void EventsMngr::parserInit(int msg_type, float* timer, CPlayer* pPlayer, int in
|
||||
m_ParseVault[0].type = MSG_INTEGER;
|
||||
m_ParseVault[0].iValue = index;
|
||||
}
|
||||
|
||||
m_ParseFun = &m_Events[msg_type];
|
||||
}
|
||||
|
||||
@ -266,7 +276,6 @@ void EventsMngr::parseValue(int iValue)
|
||||
if (!m_ParseNotDone || !m_ParseFun)
|
||||
return;
|
||||
|
||||
|
||||
// grow if needed
|
||||
++m_ParsePos;
|
||||
NextParam();
|
||||
@ -284,6 +293,7 @@ void EventsMngr::parseValue(int iValue)
|
||||
// loop through conditions
|
||||
bool execute = false;
|
||||
bool anyConditions = false;
|
||||
|
||||
for (ClEvent::cond_t *condIter = (*iter).m_Conditions; condIter; condIter = condIter->next)
|
||||
{
|
||||
if (condIter->paramId == m_ParsePos)
|
||||
@ -312,7 +322,6 @@ void EventsMngr::parseValue(float fValue)
|
||||
if (!m_ParseNotDone || !m_ParseFun)
|
||||
return;
|
||||
|
||||
|
||||
// grow if needed
|
||||
++m_ParsePos;
|
||||
NextParam();
|
||||
@ -330,6 +339,7 @@ void EventsMngr::parseValue(float fValue)
|
||||
// loop through conditions
|
||||
bool execute = false;
|
||||
bool anyConditions = false;
|
||||
|
||||
for (ClEvent::cond_t *condIter = (*iter).m_Conditions; condIter; condIter = condIter->next)
|
||||
{
|
||||
if (condIter->paramId == m_ParsePos)
|
||||
@ -374,6 +384,7 @@ void EventsMngr::parseValue(const char *sz)
|
||||
// loop through conditions
|
||||
bool execute = false;
|
||||
bool anyConditions = false;
|
||||
|
||||
for (ClEvent::cond_t *condIter = (*iter).m_Conditions; condIter; condIter = condIter->next)
|
||||
{
|
||||
if (condIter->paramId == m_ParsePos)
|
||||
@ -408,6 +419,7 @@ void EventsMngr::executeEvents()
|
||||
(*iter).m_Done = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
(*iter).m_Stamp = (float)*m_Timer;
|
||||
executeForwards((*iter).m_Func, m_ParseVault ? m_ParseVault[0].iValue : 0);
|
||||
}
|
||||
@ -479,6 +491,7 @@ void EventsMngr::clearEvents(void)
|
||||
{
|
||||
m_Events[i].clear();
|
||||
}
|
||||
|
||||
// delete parsevault
|
||||
if (m_ParseVault)
|
||||
{
|
||||
@ -506,6 +519,7 @@ int EventsMngr::getEventId(const char* msg)
|
||||
|
||||
// if msg is a number, return it
|
||||
int pos = atoi(msg);
|
||||
|
||||
if (pos != 0)
|
||||
return pos;
|
||||
|
||||
|
@ -36,6 +36,7 @@
|
||||
// *****************************************************
|
||||
// class File
|
||||
// *****************************************************
|
||||
|
||||
File::File(const char* n, const char* m)
|
||||
{
|
||||
fp = fopen(n, m);
|
||||
@ -70,7 +71,6 @@ File& operator<<( File& f, int n )
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
File& operator<<(File& f, const char& c)
|
||||
{
|
||||
if (f) fputc(c, f.fp);
|
||||
@ -96,6 +96,7 @@ int File::getline( char* buf, int sz )
|
||||
{
|
||||
int a = sz;
|
||||
char *origBuf = buf;
|
||||
|
||||
if (*this)
|
||||
{
|
||||
int c;
|
||||
@ -123,4 +124,3 @@ File& File::skipWs( )
|
||||
ungetc(c, fp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -184,6 +184,7 @@ size_t CLangMngr::strip(char *str, char *newstr, bool makelower)
|
||||
}
|
||||
|
||||
newstr[pos] = 0;
|
||||
|
||||
return ptr - str + 1;
|
||||
}
|
||||
|
||||
@ -305,6 +306,7 @@ void CLangMngr::CLang::Clear()
|
||||
if (m_LookUpTable[i])
|
||||
delete m_LookUpTable[i];
|
||||
}
|
||||
|
||||
m_LookUpTable.clear();
|
||||
}
|
||||
|
||||
@ -332,11 +334,13 @@ void CLangMngr::CLang::MergeDefinitions(CQueue<sKeyDef*> &vec)
|
||||
{
|
||||
const char *def = 0;
|
||||
int key = -1;
|
||||
|
||||
while (!vec.empty())
|
||||
{
|
||||
key = vec.front()->key;
|
||||
def = vec.front()->def->c_str();
|
||||
LangEntry *entry = GetEntry(key);
|
||||
|
||||
if (entry->GetDefHash() != MakeHash(def))
|
||||
{
|
||||
if (entry->GetCache())
|
||||
@ -348,6 +352,7 @@ void CLangMngr::CLang::MergeDefinitions(CQueue<sKeyDef*> &vec)
|
||||
//AMXXLOG_Log("[AMXX] Language key %s[%s] defined twice", m_LMan->GetKey(key), m_LanguageName);
|
||||
}
|
||||
}
|
||||
|
||||
delete vec.front();
|
||||
vec.pop();
|
||||
}
|
||||
@ -357,20 +362,22 @@ const char * CLangMngr::CLang::GetDef(const char *key)
|
||||
{
|
||||
static char nfind[1024] = "ML_NOTFOUND(KEY)";
|
||||
int ikey = m_LMan->GetKeyEntry(key);
|
||||
|
||||
if (ikey == -1)
|
||||
{
|
||||
sprintf(nfind, "ML_NOTFOUND: %s", key);
|
||||
return nfind;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < m_LookUpTable.size(); i++)
|
||||
{
|
||||
if (m_LookUpTable[i]->GetKey() == ikey)
|
||||
return m_LookUpTable[i]->GetDef();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
struct OffsetPair
|
||||
{
|
||||
uint32_t defOffset;
|
||||
@ -381,6 +388,7 @@ struct OffsetPair
|
||||
bool CLangMngr::CLang::SaveDefinitions(FILE *fp, uint32_t &curOffset)
|
||||
{
|
||||
unsigned short defLen = 0;
|
||||
|
||||
for (unsigned int i = 0; i < m_LookUpTable.size(); i++)
|
||||
{
|
||||
defLen = m_LookUpTable[i]->GetDefLength();
|
||||
@ -423,7 +431,6 @@ bool CLangMngr::CLang::Save(FILE *fp, int &defOffset, uint32_t &curOffset)
|
||||
// assumes fp is set to the right position
|
||||
bool CLangMngr::CLang::Load(FILE *fp)
|
||||
{
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -464,6 +471,7 @@ int CLangMngr::GetKeyEntry(const char *key)
|
||||
for (i = 0; i < KeyList.size(); i++)
|
||||
{
|
||||
cmpKey = KeyList[i]->hash;
|
||||
|
||||
if (hKey == cmpKey)
|
||||
{
|
||||
return i;
|
||||
@ -521,6 +529,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
||||
{
|
||||
// number of parameters ( for NEXT_PARAM macro )
|
||||
int paramCount = *params / sizeof(cell);
|
||||
|
||||
// the output buffer
|
||||
static char outbuf[4096];
|
||||
char *outptr = outbuf;
|
||||
@ -538,6 +547,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
||||
cell *pAmxLangName = get_amxaddr(amx, params[parm++]); // other cases
|
||||
const char *cpLangName=NULL;
|
||||
// Handle player ids (1-32) and server language
|
||||
|
||||
if (*pAmxLangName == LANG_PLAYER) // LANG_PLAYER
|
||||
{
|
||||
if ((int)CVAR_GET_FLOAT("amx_client_languages") == 0)
|
||||
@ -546,9 +556,11 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
||||
} else {
|
||||
cpLangName = ENTITY_KEYVALUE(GET_PLAYER_POINTER_I(m_CurGlobId)->pEdict, "lang");
|
||||
}
|
||||
} else if (*pAmxLangName == LANG_SERVER) { // LANG_SERVER
|
||||
} else if (*pAmxLangName == LANG_SERVER) // LANG_SERVER
|
||||
{
|
||||
cpLangName = g_vault.get("server_language");
|
||||
} else if (*pAmxLangName >= 1 && *pAmxLangName <= 32) { // Direct Client Id
|
||||
} else if (*pAmxLangName >= 1 && *pAmxLangName <= 32) // Direct Client Id
|
||||
{
|
||||
if ((int)CVAR_GET_FLOAT("amx_client_languages") == 0)
|
||||
{
|
||||
cpLangName = g_vault.get("server_language");
|
||||
@ -559,12 +571,15 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
||||
int tmplen = 0;
|
||||
cpLangName = get_amxstring(amx, langName, 2, tmplen);
|
||||
}
|
||||
|
||||
if (!cpLangName || strlen(cpLangName) < 1)
|
||||
cpLangName = "en";
|
||||
|
||||
int tmplen = 0;
|
||||
NEXT_PARAM();
|
||||
char *key = get_amxstring(amx, params[parm++], 1, tmplen);
|
||||
const char *def = GetDef(cpLangName, key);
|
||||
|
||||
if (def == NULL)
|
||||
{
|
||||
if (*pAmxLangName != LANG_SERVER)
|
||||
@ -583,6 +598,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
||||
def = buf;
|
||||
}
|
||||
}
|
||||
|
||||
while (*def)
|
||||
{
|
||||
if (*def == '%')
|
||||
@ -592,9 +608,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
||||
{
|
||||
*outptr++ = '%';
|
||||
++def;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
static char format[32];
|
||||
format[0] = '%';
|
||||
char *ptr = format+1;
|
||||
@ -604,6 +618,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
||||
ZEROTERM(format);
|
||||
|
||||
*ptr = 0;
|
||||
|
||||
switch (*(ptr - 1))
|
||||
{
|
||||
case 's':
|
||||
@ -644,12 +659,14 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
outptr += strlen(outptr);
|
||||
}
|
||||
}
|
||||
else if (*def == '^')
|
||||
{
|
||||
++def;
|
||||
|
||||
switch (*def)
|
||||
{
|
||||
case 'n':
|
||||
@ -670,22 +687,20 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
||||
*outptr++ = *def;
|
||||
break;
|
||||
}
|
||||
|
||||
++def;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
CHECK_OUTPTR(1);
|
||||
*outptr++ = *def++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
static char tmpString[4096];
|
||||
char *tmpPtr = tmpString;
|
||||
int tmpLen = 0;
|
||||
static char format[32] = {'%'};
|
||||
char *ptr = format+1;
|
||||
|
||||
if (*src != '%')
|
||||
{
|
||||
while (*src != 0 && ptr-format<sizeof(format) && !isalpha(*ptr++ = static_cast<char>(*src++)))
|
||||
@ -693,6 +708,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
||||
*ptr = 0;
|
||||
ZEROTERM(format);
|
||||
--src;
|
||||
|
||||
switch (*(ptr - 1))
|
||||
{
|
||||
case 's':
|
||||
@ -728,23 +744,24 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
outptr += strlen(outptr);
|
||||
} else {
|
||||
CHECK_OUTPTR(1);
|
||||
*outptr++ = '%';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
CHECK_OUTPTR(1);
|
||||
*outptr++ = static_cast<char>(*src);
|
||||
}
|
||||
++src;
|
||||
}
|
||||
|
||||
len = outptr - outbuf;
|
||||
CHECK_OUTPTR(1);
|
||||
*outptr++ = 0;
|
||||
|
||||
return outbuf;
|
||||
}
|
||||
|
||||
@ -754,6 +771,7 @@ const char *CLangMngr::Format(const char *fmt, ...)
|
||||
va_start(ap, fmt);
|
||||
const char *retVal = FormatString(fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@ -788,6 +806,7 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
|
||||
const char *pAmxLangName = va_arg(ap, const char*);
|
||||
const char *cpLangName=NULL;
|
||||
// Handle player ids (1-32) and server language
|
||||
|
||||
if (pAmxLangName == (const char *)LANG_PLAYER) // LANG_PLAYER
|
||||
{
|
||||
if ((int)CVAR_GET_FLOAT("amx_client_languages"))
|
||||
@ -796,9 +815,11 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
|
||||
} else {
|
||||
cpLangName = ENTITY_KEYVALUE(GET_PLAYER_POINTER_I(m_CurGlobId)->pEdict, "lang");
|
||||
}
|
||||
} else if (pAmxLangName == (const char *)LANG_SERVER) { // LANG_SERVER
|
||||
} else if (pAmxLangName == (const char *)LANG_SERVER) // LANG_SERVER
|
||||
{
|
||||
cpLangName = g_vault.get("server_language");
|
||||
} else if (pAmxLangName >= (const char *)1 && pAmxLangName <= (const char *)32) { // Direct Client Id
|
||||
} else if (pAmxLangName >= (const char *)1 && pAmxLangName <= (const char *)32) // Direct Client Id
|
||||
{
|
||||
if ((int)CVAR_GET_FLOAT("amx_client_languages"))
|
||||
{
|
||||
cpLangName = g_vault.get("server_language");
|
||||
@ -809,11 +830,14 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
|
||||
int tmplen = 0;
|
||||
cpLangName = pAmxLangName;
|
||||
}
|
||||
|
||||
if (!cpLangName || strlen(cpLangName) < 1)
|
||||
cpLangName = "en";
|
||||
|
||||
int tmplen = 0;
|
||||
const char *key = va_arg(ap, const char *);
|
||||
const char *def = GetDef(cpLangName, key);
|
||||
|
||||
if (def == NULL)
|
||||
{
|
||||
if (pAmxLangName != LANG_SERVER)
|
||||
@ -832,6 +856,7 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
|
||||
def = buf;
|
||||
}
|
||||
}
|
||||
|
||||
while (*def)
|
||||
{
|
||||
if (*def == '%')
|
||||
@ -847,6 +872,7 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
|
||||
*ptr = 0;
|
||||
vsprintf(outptr, format, ap);
|
||||
// vsprintf doesnt alter the ap, increment here
|
||||
|
||||
switch (*(ptr - 1))
|
||||
{
|
||||
case 'f':
|
||||
@ -862,11 +888,13 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
|
||||
va_arg(ap, int);
|
||||
break;
|
||||
}
|
||||
|
||||
outptr += strlen(outptr);
|
||||
}
|
||||
else if (*def == '^')
|
||||
{
|
||||
++def;
|
||||
|
||||
switch (*def)
|
||||
{
|
||||
case 'n':
|
||||
@ -887,19 +915,17 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
|
||||
*outptr++ = *def;
|
||||
break;
|
||||
}
|
||||
|
||||
++def;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
CHECK_OUTPTR(1);
|
||||
*outptr++ = *def++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
static char format[32] = {'%'};
|
||||
char *ptr = format+1;
|
||||
|
||||
if (*src != '%')
|
||||
{
|
||||
while (*src != 0 && ptr-format < sizeof(format) && !isalpha(*ptr++ = *src++))
|
||||
@ -909,6 +935,7 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
|
||||
--src;
|
||||
vsprintf(outptr, format, ap);
|
||||
// vsprintf doesnt alter the ap, increment here
|
||||
|
||||
switch (*(ptr - 1))
|
||||
{
|
||||
case 'f':
|
||||
@ -924,22 +951,23 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
|
||||
va_arg(ap, int);
|
||||
break;
|
||||
}
|
||||
|
||||
outptr += strlen(outptr);
|
||||
} else {
|
||||
CHECK_OUTPTR(1);
|
||||
*outptr++ = '%';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
CHECK_OUTPTR(1);
|
||||
*outptr++ = *src;
|
||||
}
|
||||
++src;
|
||||
}
|
||||
|
||||
CHECK_OUTPTR(1);
|
||||
*outptr++ = 0;
|
||||
|
||||
return outbuf;
|
||||
}
|
||||
void CLangMngr::MergeDefinitions(const char *lang, CQueue<sKeyDef*> &tmpVec)
|
||||
@ -969,6 +997,7 @@ int CLangMngr::MergeDefinitionFile(const char *file)
|
||||
AMXXLOG_Log("[AMXX] Failed to open dictionary file: %s", file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
MD5 md5;
|
||||
md5.update(fp); // closes for us
|
||||
md5.finalize();
|
||||
@ -1022,6 +1051,7 @@ int CLangMngr::MergeDefinitionFile(const char *file)
|
||||
buf.trim();
|
||||
if (buf[0] == 0)
|
||||
continue;
|
||||
|
||||
if (buf[0] == '[' && buf.size() >= 3)
|
||||
{
|
||||
if (multiline)
|
||||
@ -1031,10 +1061,12 @@ int CLangMngr::MergeDefinitionFile(const char *file)
|
||||
delete tmpEntry;
|
||||
tmpEntry = 0;
|
||||
}
|
||||
|
||||
if (!Defq.empty())
|
||||
{
|
||||
MergeDefinitions(language, Defq);
|
||||
}
|
||||
|
||||
language[0] = buf[1];
|
||||
language[1] = buf[2];
|
||||
language[2] = 0;
|
||||
@ -1042,6 +1074,7 @@ int CLangMngr::MergeDefinitionFile(const char *file)
|
||||
if (!multiline)
|
||||
{
|
||||
pos = buf.find('=');
|
||||
|
||||
if (pos > String::npos)
|
||||
{
|
||||
tmpEntry = new sKeyDef;
|
||||
@ -1062,6 +1095,7 @@ int CLangMngr::MergeDefinitionFile(const char *file)
|
||||
tmpEntry = 0;
|
||||
} else {
|
||||
pos = buf.find(':');
|
||||
|
||||
if (pos > String::npos)
|
||||
{
|
||||
tmpEntry = new sKeyDef;
|
||||
@ -1264,7 +1298,6 @@ bool CLangMngr::LoadCache(const char *filename)
|
||||
fread((void*)&dictCount, sizeof(short), 1, fp);
|
||||
md5Pair *p = 0;
|
||||
|
||||
|
||||
for (int i = 1; i <= dictCount; i++)
|
||||
{
|
||||
fread((void*)&len, sizeof(char), 1, fp);
|
||||
@ -1311,6 +1344,7 @@ bool CLangMngr::Load(const char *filename)
|
||||
|
||||
uint32_t *LangOffsets = new uint32_t[langCount];
|
||||
char langname[3];
|
||||
|
||||
for (unsigned int i = 0; i < langCount; i++)
|
||||
{
|
||||
fread(langname, sizeof(char), 2, fp);
|
||||
@ -1324,6 +1358,7 @@ bool CLangMngr::Load(const char *filename)
|
||||
keyEntry *e = 0;
|
||||
unsigned char keylen;
|
||||
uint32_t keyoffset, save;
|
||||
|
||||
for (unsigned i = 0; i < keycount; i++)
|
||||
{
|
||||
e = new keyEntry;
|
||||
@ -1347,9 +1382,11 @@ bool CLangMngr::Load(const char *filename)
|
||||
uint32_t defhash;
|
||||
uint32_t defoffset;
|
||||
unsigned short deflen;
|
||||
|
||||
for (unsigned int i = 0; i < langCount; i++)
|
||||
{
|
||||
fread((void*)&numentries, sizeof(uint32_t), 1, fp);
|
||||
|
||||
for (unsigned int j = 0; j < numentries; j++)
|
||||
{
|
||||
fread((void *)&keynum, sizeof(uint32_t), 1, fp);
|
||||
@ -1383,6 +1420,7 @@ CLangMngr::~CLangMngr()
|
||||
void CLangMngr::Clear()
|
||||
{
|
||||
unsigned int i = 0;
|
||||
|
||||
for (i = 0; i < m_Languages.size(); i++)
|
||||
{
|
||||
if (m_Languages[i])
|
||||
@ -1415,6 +1453,7 @@ const char *CLangMngr::GetLangName(int langId)
|
||||
{
|
||||
int i = 0;
|
||||
LangVecIter iter;
|
||||
|
||||
for (iter = m_Languages.begin(); iter != m_Languages.end(); ++iter)
|
||||
{
|
||||
if (i == langId)
|
||||
@ -1423,6 +1462,7 @@ const char *CLangMngr::GetLangName(int langId)
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
@ -1430,6 +1470,7 @@ bool CLangMngr::LangExists(const char *langName)
|
||||
{
|
||||
char buf[3] = {0};
|
||||
int i = 0;
|
||||
|
||||
while (buf[i] = tolower(*langName++))
|
||||
{
|
||||
if (++i == 2)
|
||||
@ -1437,11 +1478,13 @@ bool CLangMngr::LangExists(const char *langName)
|
||||
}
|
||||
|
||||
LangVecIter iter;
|
||||
|
||||
for (iter = m_Languages.begin(); iter != m_Languages.end(); ++iter)
|
||||
{
|
||||
if (strcmp((*iter)->GetName(), buf) == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -35,102 +35,136 @@
|
||||
// *****************************************************
|
||||
// class LogEventsMngr
|
||||
// *****************************************************
|
||||
LogEventsMngr::LogEventsMngr() {
|
||||
|
||||
LogEventsMngr::LogEventsMngr()
|
||||
{
|
||||
logCurrent = logCounter = 0;
|
||||
logcmplist = 0;
|
||||
arelogevents = false;
|
||||
memset(logevents, 0, sizeof(logevents));
|
||||
}
|
||||
|
||||
LogEventsMngr::~LogEventsMngr() {
|
||||
LogEventsMngr::~LogEventsMngr()
|
||||
{
|
||||
clearLogEvents();
|
||||
}
|
||||
|
||||
int LogEventsMngr::CLogCmp::compareCondition(const char* string){
|
||||
int LogEventsMngr::CLogCmp::compareCondition(const char* string)
|
||||
{
|
||||
if (logid == parent->logCounter)
|
||||
return result;
|
||||
|
||||
logid = parent->logCounter;
|
||||
if (in) return result = strstr(string, text.c_str()) ? 0 : 1;
|
||||
|
||||
return result = strcmp(string,text.c_str());
|
||||
}
|
||||
|
||||
LogEventsMngr::CLogCmp* LogEventsMngr::registerCondition(char* filter){
|
||||
LogEventsMngr::CLogCmp* LogEventsMngr::registerCondition(char* filter)
|
||||
{
|
||||
char* temp = filter;
|
||||
// expand "1=message"
|
||||
|
||||
while (isdigit(*filter))
|
||||
++filter;
|
||||
|
||||
bool in = (*filter=='&');
|
||||
*filter++ = 0;
|
||||
int pos = atoi(temp);
|
||||
if (pos < 0 || pos >= MAX_LOGARGS) pos = 0;
|
||||
CLogCmp* c = logcmplist;
|
||||
while( c ) {
|
||||
|
||||
while (c)
|
||||
{
|
||||
if ((c->pos == pos) && (c->in == in) && !strcmp(c->text.c_str(), filter))
|
||||
return c;
|
||||
c = c->next;
|
||||
}
|
||||
|
||||
return logcmplist = new CLogCmp(filter, in, pos, logcmplist, this);
|
||||
}
|
||||
|
||||
void LogEventsMngr::CLogEvent::registerFilter( char* filter ){
|
||||
void LogEventsMngr::CLogEvent::registerFilter(char* filter)
|
||||
{
|
||||
CLogCmp *cmp = parent->registerCondition(filter);
|
||||
if (cmp == 0) return;
|
||||
for(LogCond* c = filters; c ; c = c->next){
|
||||
if ( c->argnum == cmp->pos ){
|
||||
|
||||
for (LogCond* c = filters; c; c = c->next)
|
||||
{
|
||||
if (c->argnum == cmp->pos)
|
||||
{
|
||||
c->list = new LogCondEle(cmp, c->list);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LogCondEle* aa = new LogCondEle(cmp, 0);
|
||||
if (aa == 0) return;
|
||||
filters = new LogCond(cmp->pos, aa, filters);
|
||||
}
|
||||
|
||||
void LogEventsMngr::setLogString( char* frmt, va_list& vaptr ) {
|
||||
void LogEventsMngr::setLogString(char* frmt, va_list& vaptr)
|
||||
{
|
||||
++logCounter;
|
||||
int len = vsnprintf(logString, 255, frmt, vaptr);
|
||||
if ( len == - 1) {
|
||||
|
||||
if (len == - 1)
|
||||
{
|
||||
len = 255;
|
||||
logString[len] = 0;
|
||||
}
|
||||
|
||||
if (len) logString[--len] = 0;
|
||||
logArgc = 0;
|
||||
}
|
||||
|
||||
void LogEventsMngr::setLogString( char* frmt, ... ) {
|
||||
void LogEventsMngr::setLogString(char* frmt, ...)
|
||||
{
|
||||
++logCounter;
|
||||
va_list logArgPtr;
|
||||
va_start(logArgPtr, frmt);
|
||||
int len = vsnprintf(logString, 255, frmt, logArgPtr);
|
||||
if ( len == - 1) {
|
||||
|
||||
if (len == - 1)
|
||||
{
|
||||
len = 255;
|
||||
logString[len] = 0;
|
||||
}
|
||||
|
||||
va_end(logArgPtr);
|
||||
if (len) logString[--len] = 0;
|
||||
logArgc = 0;
|
||||
}
|
||||
|
||||
void LogEventsMngr::parseLogString( ) {
|
||||
void LogEventsMngr::parseLogString()
|
||||
{
|
||||
register const char* b = logString;
|
||||
register int a;
|
||||
while( *b && logArgc < MAX_LOGARGS ){
|
||||
|
||||
while (*b && logArgc < MAX_LOGARGS)
|
||||
{
|
||||
a = 0;
|
||||
if ( *b == '"' ) {
|
||||
|
||||
if (*b == '"')
|
||||
{
|
||||
++b;
|
||||
|
||||
while (*b && *b != '"' && a < 127)
|
||||
logArgs[logArgc][a++] = *b++;
|
||||
|
||||
logArgs[logArgc++][a] = 0;
|
||||
if (*b) b+=2; // thanks to double terminator
|
||||
}
|
||||
else if ( *b == '(' ) {
|
||||
else if (*b == '(')
|
||||
{
|
||||
++b;
|
||||
|
||||
while (*b && *b != ')' && a < 127)
|
||||
logArgs[logArgc][a++] = *b++;
|
||||
|
||||
logArgs[logArgc++][a] = 0;
|
||||
if (*b) b+=2;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
while (*b && *b != '(' && *b != '"' && a < 127)
|
||||
logArgs[logArgc][a++] = *b++;
|
||||
if (*b) --a;
|
||||
@ -143,27 +177,35 @@ LogEventsMngr::CLogEvent* LogEventsMngr::registerLogEvent( CPluginMngr::CPlugin*
|
||||
{
|
||||
if (pos < 1 || pos > MAX_LOGARGS)
|
||||
return 0;
|
||||
|
||||
arelogevents = true;
|
||||
CLogEvent** d = &logevents[pos];
|
||||
while (*d) d = &(*d)->next;
|
||||
|
||||
return *d = new CLogEvent(plugin, func, this);
|
||||
}
|
||||
|
||||
void LogEventsMngr::executeLogEvents()
|
||||
{
|
||||
bool valid;
|
||||
|
||||
for (CLogEvent* a = logevents[logArgc]; a; a = a->next)
|
||||
{
|
||||
valid = true;
|
||||
|
||||
for (CLogEvent::LogCond* b = a->filters; b; b = b->next)
|
||||
{
|
||||
valid = false;
|
||||
for( CLogEvent::LogCondEle* c = b->list; c ; c = c->next) {
|
||||
if ( c->cmp->compareCondition( logArgs[b->argnum] ) == 0 ){
|
||||
|
||||
for (CLogEvent::LogCondEle* c = b->list; c; c = c->next)
|
||||
{
|
||||
if (c->cmp->compareCondition(logArgs[b->argnum]) == 0)
|
||||
{
|
||||
valid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid)
|
||||
break;
|
||||
}
|
||||
@ -175,38 +217,49 @@ void LogEventsMngr::executeLogEvents()
|
||||
}
|
||||
}
|
||||
|
||||
void LogEventsMngr::clearLogEvents(){
|
||||
void LogEventsMngr::clearLogEvents()
|
||||
{
|
||||
logCurrent = logCounter = 0;
|
||||
arelogevents = false;
|
||||
for(int i = 0; i < MAX_LOGARGS + 1; ++i){
|
||||
|
||||
for (int i = 0; i < MAX_LOGARGS + 1; ++i)
|
||||
{
|
||||
CLogEvent **a = &logevents[i];
|
||||
while(*a){
|
||||
while (*a)
|
||||
{
|
||||
CLogEvent* bb = (*a)->next;
|
||||
delete *a;
|
||||
*a = bb;
|
||||
}
|
||||
}
|
||||
|
||||
clearConditions();
|
||||
}
|
||||
|
||||
void LogEventsMngr::clearConditions() {
|
||||
while (logcmplist){
|
||||
void LogEventsMngr::clearConditions()
|
||||
{
|
||||
while (logcmplist)
|
||||
{
|
||||
CLogCmp* a = logcmplist->next;
|
||||
delete logcmplist;
|
||||
logcmplist = a;
|
||||
}
|
||||
}
|
||||
|
||||
LogEventsMngr::CLogEvent::LogCond::~LogCond() {
|
||||
while( list ) {
|
||||
LogEventsMngr::CLogEvent::LogCond::~LogCond()
|
||||
{
|
||||
while (list)
|
||||
{
|
||||
LogCondEle* cc = list->next;
|
||||
delete list;
|
||||
list = cc;
|
||||
}
|
||||
}
|
||||
|
||||
LogEventsMngr::CLogEvent::~CLogEvent() {
|
||||
while( filters ) {
|
||||
LogEventsMngr::CLogEvent::~CLogEvent()
|
||||
{
|
||||
while (filters)
|
||||
{
|
||||
LogCond* cc = filters->next;
|
||||
delete filters;
|
||||
filters = cc;
|
||||
@ -216,23 +269,35 @@ LogEventsMngr::CLogEvent::~CLogEvent() {
|
||||
LogEventsMngr::CLogEvent *LogEventsMngr::getValidLogEvent(CLogEvent * a)
|
||||
{
|
||||
bool valid;
|
||||
while(a){
|
||||
|
||||
while (a)
|
||||
{
|
||||
valid = true;
|
||||
for( CLogEvent::LogCond* b = a->filters; b ; b = b->next){
|
||||
|
||||
for (CLogEvent::LogCond* b = a->filters; b; b = b->next)
|
||||
{
|
||||
valid = false;
|
||||
for( CLogEvent::LogCondEle* c = b->list; c ; c = c->next) {
|
||||
if ( c->cmp->compareCondition( logArgs[b->argnum] ) == 0 ){
|
||||
|
||||
for (CLogEvent::LogCondEle* c = b->list; c; c = c->next)
|
||||
{
|
||||
if (c->cmp->compareCondition(logArgs[b->argnum]) == 0)
|
||||
{
|
||||
valid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid) break;
|
||||
}
|
||||
if (!valid){
|
||||
|
||||
if (!valid)
|
||||
{
|
||||
a = a->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user