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
195
amxmodx/CCmd.cpp
195
amxmodx/CCmd.cpp
@ -35,8 +35,10 @@
|
|||||||
// *****************************************************
|
// *****************************************************
|
||||||
// class CmdMngr
|
// class CmdMngr
|
||||||
// *****************************************************
|
// *****************************************************
|
||||||
CmdMngr::CmdMngr() {
|
|
||||||
memset(sortedlists,0,sizeof(sortedlists));
|
CmdMngr::CmdMngr()
|
||||||
|
{
|
||||||
|
memset(sortedlists, 0, sizeof(sortedlists));
|
||||||
srvcmdlist = 0;
|
srvcmdlist = 0;
|
||||||
clcmdlist = 0;
|
clcmdlist = 0;
|
||||||
prefixHead = 0;
|
prefixHead = 0;
|
||||||
@ -49,13 +51,12 @@ CmdMngr::CmdMngr() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CmdMngr::Command::Command( CPluginMngr::CPlugin* pplugin,const char* pcmd,
|
CmdMngr::Command::Command(CPluginMngr::CPlugin* pplugin, const char* pcmd, const char* pinfo, int pflags,
|
||||||
const char* pinfo , int pflags , int pfunc,
|
int pfunc, bool pviewable, CmdMngr* pparent) : commandline(pcmd), info(pinfo)
|
||||||
bool pviewable, CmdMngr* pparent ) : commandline(pcmd) , info(pinfo) {
|
{
|
||||||
|
|
||||||
char szCmd[64], szArg[64];
|
char szCmd[64], szArg[64];
|
||||||
*szCmd = 0; *szArg=0;
|
*szCmd = 0; *szArg = 0;
|
||||||
sscanf(pcmd,"%s %s",szCmd,szArg);
|
sscanf(pcmd, "%s %s", szCmd, szArg);
|
||||||
command.assign(szCmd);
|
command.assign(szCmd);
|
||||||
argument.assign(szArg);
|
argument.assign(szArg);
|
||||||
plugin = pplugin;
|
plugin = pplugin;
|
||||||
@ -73,180 +74,190 @@ CmdMngr::Command::~Command()
|
|||||||
++uniqueid;
|
++uniqueid;
|
||||||
}
|
}
|
||||||
|
|
||||||
CmdMngr::Command* CmdMngr::registerCommand( CPluginMngr::CPlugin* plugin , int func , char* cmd , char* info , int level , bool listable )
|
CmdMngr::Command* CmdMngr::registerCommand(CPluginMngr::CPlugin* plugin, int func, char* cmd, char* info, int level, bool listable)
|
||||||
{
|
{
|
||||||
Command* b = new Command( plugin , cmd , info , level , func , listable, this );
|
Command* b = new Command(plugin, cmd, info, level, func, listable, this);
|
||||||
if ( b == 0 ) return 0;
|
if (b == 0) return 0;
|
||||||
setCmdLink( &sortedlists[0] , b );
|
setCmdLink(&sortedlists[0], b);
|
||||||
return b;
|
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
CmdMngr::Command* CmdMngr::getCmd( long int id ,int type, int access )
|
CmdMngr::Command* CmdMngr::getCmd(long int id, int type, int access)
|
||||||
{
|
{
|
||||||
//if ( id >= 1024 || id < 0 ) return (Command*)id;
|
//if (id >= 1024 || id < 0) return (Command*)id;
|
||||||
if ( id < 0 ){
|
if (id < 0)
|
||||||
for (CmdMngr::iterator a = begin( type ); a ; ++a){
|
{
|
||||||
if ( (*a).id == id )
|
for (CmdMngr::iterator a = begin(type); a ; ++a)
|
||||||
|
{
|
||||||
|
if ((*a).id == id)
|
||||||
return &(*a);
|
return &(*a);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (id < buf_cmdid) || (access != buf_cmdaccess) || (type != buf_cmdtype) )
|
if ((id < buf_cmdid) || (access != buf_cmdaccess) || (type != buf_cmdtype))
|
||||||
{
|
{
|
||||||
buf_cmdptr = begin( type );
|
buf_cmdptr = begin(type);
|
||||||
buf_cmdaccess = access;
|
buf_cmdaccess = access;
|
||||||
buf_cmdtype = type;
|
buf_cmdtype = type;
|
||||||
buf_cmdid = id;
|
buf_cmdid = id;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
int a = id;
|
int a = id;
|
||||||
id -= buf_cmdid;
|
id -= buf_cmdid;
|
||||||
buf_cmdid = a;
|
buf_cmdid = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ( buf_cmdptr )
|
while (buf_cmdptr)
|
||||||
{
|
{
|
||||||
|
if ((*buf_cmdptr).gotAccess(access) && (*buf_cmdptr).getPlugin()->isExecutable((*buf_cmdptr).getFunction())
|
||||||
if ( (*buf_cmdptr).gotAccess( access ) &&
|
&& (*buf_cmdptr).isViewable())
|
||||||
(*buf_cmdptr).getPlugin()->isExecutable( (*buf_cmdptr).getFunction() )
|
|
||||||
&& (*buf_cmdptr).isViewable() )
|
|
||||||
{
|
{
|
||||||
|
if (id-- == 0)
|
||||||
if ( id-- == 0 )
|
|
||||||
return &(*buf_cmdptr);
|
return &(*buf_cmdptr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
++buf_cmdptr;
|
++buf_cmdptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdMngr::getCmdNum( int type, int access )
|
int CmdMngr::getCmdNum(int type, int access)
|
||||||
{
|
{
|
||||||
if ( (access == buf_access) && (type == buf_type) )
|
if ((access == buf_access) && (type == buf_type))
|
||||||
return buf_num; // once calculated don't have to be done again
|
return buf_num; // once calculated don't have to be done again
|
||||||
|
|
||||||
buf_access = access;
|
buf_access = access;
|
||||||
buf_type = type;
|
buf_type = type;
|
||||||
buf_num = 0;
|
buf_num = 0;
|
||||||
|
|
||||||
CmdMngr::iterator a = begin( type );
|
CmdMngr::iterator a = begin(type);
|
||||||
|
|
||||||
while ( a )
|
while (a)
|
||||||
{
|
{
|
||||||
|
if ((*a).gotAccess(access) && (*a).getPlugin()->isExecutable((*a).getFunction()) && (*a).isViewable())
|
||||||
if ( (*a).gotAccess( access ) &&
|
++buf_num;
|
||||||
(*a).getPlugin()->isExecutable( (*a).getFunction() )
|
|
||||||
&& (*a).isViewable() )
|
|
||||||
++buf_num;
|
|
||||||
++a;
|
++a;
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf_num;
|
return buf_num;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CmdMngr::setCmdLink( CmdLink** a , Command* c, bool sorted )
|
void CmdMngr::setCmdLink(CmdLink** a, Command* c, bool sorted)
|
||||||
{
|
{
|
||||||
CmdLink* np = new CmdLink( c );
|
CmdLink* np = new CmdLink(c);
|
||||||
|
|
||||||
if ( np == 0 ) return;
|
if (np == 0) return;
|
||||||
|
|
||||||
if ( sorted )
|
if (sorted)
|
||||||
{
|
{
|
||||||
while( *a )
|
while (*a)
|
||||||
{
|
{
|
||||||
int i = strcmp(c->getCommand(),(*a)->cmd->getCommand() );
|
int i = strcmp(c->getCommand(),(*a)->cmd->getCommand());
|
||||||
|
|
||||||
if ( (i<0) || (i==0) && ( strcmp( c->getArgument() , (*a)->cmd->getArgument() ) < 0 ) )
|
if ((i < 0) || (i == 0) && (strcmp(c->getArgument(), (*a)->cmd->getArgument()) < 0))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
a = &(*a)->next;
|
a = &(*a)->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
np->next = *a;
|
np->next = *a;
|
||||||
*a = np;
|
*a = np;
|
||||||
}
|
} else {
|
||||||
else
|
while (*a) a = &(*a)->next;
|
||||||
{
|
|
||||||
while ( *a ) a = &(*a)->next;
|
|
||||||
*a = np;
|
*a = np;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CmdMngr::clearCmdLink( CmdLink** phead, bool pclear )
|
void CmdMngr::clearCmdLink(CmdLink** phead, bool pclear)
|
||||||
{
|
{
|
||||||
while( *phead ){
|
while (*phead)
|
||||||
|
{
|
||||||
CmdLink* pp = (*phead)->next;
|
CmdLink* pp = (*phead)->next;
|
||||||
if ( pclear ) delete (*phead)->cmd;
|
|
||||||
|
if (pclear) delete (*phead)->cmd;
|
||||||
delete *phead;
|
delete *phead;
|
||||||
*phead = pp;
|
*phead = pp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CmdMngr::Command::setCmdType( int a )
|
void CmdMngr::Command::setCmdType(int a)
|
||||||
{
|
{
|
||||||
switch(a){
|
switch(a)
|
||||||
case CMD_ConsoleCommand: cmdtype |= 3; break;
|
{
|
||||||
case CMD_ClientCommand: cmdtype |= 1; break;
|
case CMD_ConsoleCommand: cmdtype |= 3; break;
|
||||||
case CMD_ServerCommand: cmdtype |= 2; break;
|
case CMD_ClientCommand: cmdtype |= 1; break;
|
||||||
|
case CMD_ServerCommand: cmdtype |= 2; break;
|
||||||
}
|
}
|
||||||
if ( cmdtype & 1 ) { // ClientCommand
|
|
||||||
parent->setCmdLink( &parent->sortedlists[1] , this );
|
if (cmdtype & 1) // ClientCommand
|
||||||
if ( !parent->registerCmdPrefix( this ) )
|
{
|
||||||
parent->setCmdLink( &parent->clcmdlist , this , false );
|
parent->setCmdLink(&parent->sortedlists[1], this);
|
||||||
|
if (!parent->registerCmdPrefix(this))
|
||||||
|
parent->setCmdLink(&parent->clcmdlist, this, false);
|
||||||
}
|
}
|
||||||
if ( cmdtype & 2 ) { // ServerCommand
|
|
||||||
parent->setCmdLink( &parent->sortedlists[2] , this );
|
if (cmdtype & 2) // ServerCommand
|
||||||
parent->setCmdLink( &parent->srvcmdlist , this , false );
|
{
|
||||||
|
parent->setCmdLink(&parent->sortedlists[2], this);
|
||||||
|
parent->setCmdLink(&parent->srvcmdlist, this, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* CmdMngr::Command::getCmdType() const {
|
const char* CmdMngr::Command::getCmdType() const
|
||||||
switch( cmdtype ){
|
{
|
||||||
case 1: return"client";
|
switch(cmdtype)
|
||||||
case 2: return "server";
|
{
|
||||||
case 3: return "console";
|
case 1: return "client";
|
||||||
|
case 2: return "server";
|
||||||
|
case 3: return "console";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CmdMngr::registerCmdPrefix( Command* cc )
|
bool CmdMngr::registerCmdPrefix(Command* cc)
|
||||||
{
|
{
|
||||||
CmdPrefix** b = findPrefix( cc->getCommand() );
|
CmdPrefix** b = findPrefix(cc->getCommand());
|
||||||
if (*b){
|
|
||||||
setCmdLink( &(*b)->list , cc , false );
|
if (*b)
|
||||||
|
{
|
||||||
|
setCmdLink(&(*b)->list, cc, false);
|
||||||
cc->prefix = (*b)->name.size();
|
cc->prefix = (*b)->name.size();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CmdMngr::registerPrefix( const char* nn )
|
void CmdMngr::registerPrefix(const char* nn)
|
||||||
{
|
{
|
||||||
if ( *nn == 0 ) return;
|
if (*nn == 0) return;
|
||||||
CmdPrefix** b = findPrefix( nn );
|
CmdPrefix** b = findPrefix(nn);
|
||||||
|
|
||||||
if (*b) return;
|
if (*b) return;
|
||||||
*b = new CmdPrefix( nn , this );
|
*b = new CmdPrefix(nn, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
CmdMngr::CmdPrefix** CmdMngr::findPrefix( const char* nn ){
|
CmdMngr::CmdPrefix** CmdMngr::findPrefix(const char* nn)
|
||||||
|
{
|
||||||
CmdPrefix** aa = &prefixHead;
|
CmdPrefix** aa = &prefixHead;
|
||||||
while(*aa){
|
|
||||||
if ( !strncmp( (*aa)->name.c_str(), nn, (*aa)->name.size() ) )
|
while (*aa)
|
||||||
|
{
|
||||||
|
if (!strncmp((*aa)->name.c_str(), nn, (*aa)->name.size()))
|
||||||
break;
|
break;
|
||||||
aa=&(*aa)->next;
|
aa = &(*aa)->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
return aa;
|
return aa;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CmdMngr::clearPrefix(){
|
void CmdMngr::clearPrefix()
|
||||||
while(prefixHead){
|
{
|
||||||
|
while (prefixHead)
|
||||||
|
{
|
||||||
CmdPrefix* a = prefixHead->next;
|
CmdPrefix* a = prefixHead->next;
|
||||||
delete prefixHead;
|
delete prefixHead;
|
||||||
prefixHead = a;
|
prefixHead = a;
|
||||||
@ -264,7 +275,8 @@ void CmdMngr::clear()
|
|||||||
clearBufforedInfo();
|
clearBufforedInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CmdMngr::clearBufforedInfo() {
|
void CmdMngr::clearBufforedInfo()
|
||||||
|
{
|
||||||
buf_type = -1;
|
buf_type = -1;
|
||||||
buf_access = 0;
|
buf_access = 0;
|
||||||
buf_id = -1;
|
buf_id = -1;
|
||||||
@ -274,4 +286,3 @@ void CmdMngr::clearBufforedInfo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int CmdMngr::Command::uniqueid = 0;
|
int CmdMngr::Command::uniqueid = 0;
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
// class ClEvent
|
// class ClEvent
|
||||||
// *****************************************************
|
// *****************************************************
|
||||||
|
|
||||||
EventsMngr::ClEvent::ClEvent(CPluginMngr::CPlugin* plugin, int func, int flags)
|
EventsMngr::ClEvent::ClEvent(CPluginMngr::CPlugin* plugin, int func, int flags)
|
||||||
{
|
{
|
||||||
m_Plugin = plugin;
|
m_Plugin = plugin;
|
||||||
m_Func = func;
|
m_Func = func;
|
||||||
@ -45,13 +45,14 @@ EventsMngr::ClEvent::ClEvent(CPluginMngr::CPlugin* plugin, int func, int flags)
|
|||||||
m_FlagAlive = true;
|
m_FlagAlive = true;
|
||||||
m_FlagDead = true;
|
m_FlagDead = true;
|
||||||
|
|
||||||
m_FlagWorld = (flags & 1) ? true : false; // flag a
|
m_FlagWorld = (flags & 1) ? true : false; // flag a
|
||||||
m_FlagPlayer = (flags & 2) ? true : false; // flag b
|
m_FlagPlayer = (flags & 2) ? true : false; // flag b
|
||||||
m_FlagOnce = (flags & 4) ? true : false; // flag c
|
m_FlagOnce = (flags & 4) ? true : false; // flag c
|
||||||
|
|
||||||
if (flags & 24)
|
if (flags & 24)
|
||||||
{
|
{
|
||||||
m_FlagAlive = (flags & 16) ? true : false; // flag e
|
m_FlagAlive = (flags & 16) ? true : false; // flag e
|
||||||
m_FlagDead = (flags & 8) ? true : false; // flag d
|
m_FlagDead = (flags & 8) ? true : false; // flag d
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Stamp = 0.0f;
|
m_Stamp = 0.0f;
|
||||||
@ -64,12 +65,14 @@ EventsMngr::ClEvent::~ClEvent()
|
|||||||
{
|
{
|
||||||
cond_t *tmp1 = m_Conditions;
|
cond_t *tmp1 = m_Conditions;
|
||||||
cond_t *tmp2 = NULL;
|
cond_t *tmp2 = NULL;
|
||||||
|
|
||||||
while (tmp1)
|
while (tmp1)
|
||||||
{
|
{
|
||||||
tmp2 = tmp1->next;
|
tmp2 = tmp1->next;
|
||||||
delete tmp1;
|
delete tmp1;
|
||||||
tmp1 = tmp2;
|
tmp1 = tmp2;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Conditions = NULL;
|
m_Conditions = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,14 +85,17 @@ void EventsMngr::NextParam()
|
|||||||
|
|
||||||
MsgDataEntry *tmp = NULL;
|
MsgDataEntry *tmp = NULL;
|
||||||
int tmpSize = 0;
|
int tmpSize = 0;
|
||||||
|
|
||||||
if (m_ParseVault)
|
if (m_ParseVault)
|
||||||
{
|
{
|
||||||
// copy to tmp
|
// copy to tmp
|
||||||
tmp = new MsgDataEntry[m_ParseVaultSize];
|
tmp = new MsgDataEntry[m_ParseVaultSize];
|
||||||
|
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
{
|
{
|
||||||
return; // :TODO: Error report !!
|
return; // :TODO: Error report !!
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(tmp, m_ParseVault, m_ParseVaultSize * sizeof(MsgDataEntry));
|
memcpy(tmp, m_ParseVault, m_ParseVaultSize * sizeof(MsgDataEntry));
|
||||||
tmpSize = m_ParseVaultSize;
|
tmpSize = m_ParseVaultSize;
|
||||||
delete [] m_ParseVault;
|
delete [] m_ParseVault;
|
||||||
@ -102,6 +108,7 @@ void EventsMngr::NextParam()
|
|||||||
m_ParseVaultSize = INITIAL_PARSEVAULT_SIZE;
|
m_ParseVaultSize = INITIAL_PARSEVAULT_SIZE;
|
||||||
|
|
||||||
m_ParseVault = new MsgDataEntry[m_ParseVaultSize];
|
m_ParseVault = new MsgDataEntry[m_ParseVaultSize];
|
||||||
|
|
||||||
if (tmp)
|
if (tmp)
|
||||||
{
|
{
|
||||||
memcpy(m_ParseVault, tmp, tmpSize * sizeof(MsgDataEntry));
|
memcpy(m_ParseVault, tmp, tmpSize * sizeof(MsgDataEntry));
|
||||||
@ -178,10 +185,11 @@ void EventsMngr::ClEvent::registerFilter(char *filter)
|
|||||||
if (m_Conditions)
|
if (m_Conditions)
|
||||||
{
|
{
|
||||||
cond_t *tmp = m_Conditions;
|
cond_t *tmp = m_Conditions;
|
||||||
|
|
||||||
while (tmp->next)
|
while (tmp->next)
|
||||||
tmp = tmp->next;
|
tmp = tmp->next;
|
||||||
|
|
||||||
tmp->next = tmpCond;
|
tmp->next = tmpCond;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_Conditions = tmpCond;
|
m_Conditions = tmpCond;
|
||||||
@ -194,6 +202,7 @@ EventsMngr::ClEvent* EventsMngr::registerEvent(CPluginMngr::CPlugin* plugin, int
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ClEvent *event = new ClEvent(plugin, func, flags);
|
ClEvent *event = new ClEvent(plugin, func, flags);
|
||||||
|
|
||||||
if (!event)
|
if (!event)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -216,12 +225,11 @@ void EventsMngr::parserInit(int msg_type, float* timer, CPlayer* pPlayer, int in
|
|||||||
if (!m_Events[msg_type].size())
|
if (!m_Events[msg_type].size())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for(ClEventVecIter iter = m_Events[msg_type].begin(); iter; ++iter)
|
for (ClEventVecIter iter = m_Events[msg_type].begin(); iter; ++iter)
|
||||||
{
|
{
|
||||||
if ((*iter).m_Done)
|
if ((*iter).m_Done)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
||||||
if (!(*iter).m_Plugin->isExecutable((*iter).m_Func))
|
if (!(*iter).m_Plugin->isExecutable((*iter).m_Func))
|
||||||
{
|
{
|
||||||
(*iter).m_Done = true;
|
(*iter).m_Done = true;
|
||||||
@ -230,7 +238,7 @@ void EventsMngr::parserInit(int msg_type, float* timer, CPlayer* pPlayer, int in
|
|||||||
|
|
||||||
if (pPlayer)
|
if (pPlayer)
|
||||||
{
|
{
|
||||||
if (!(*iter).m_FlagPlayer || (pPlayer->IsAlive() ? !(*iter).m_FlagAlive : !(*iter).m_FlagDead ) )
|
if (!(*iter).m_FlagPlayer || (pPlayer->IsAlive() ? !(*iter).m_FlagAlive : !(*iter).m_FlagDead))
|
||||||
{
|
{
|
||||||
(*iter).m_Done = true;
|
(*iter).m_Done = true;
|
||||||
continue;
|
continue;
|
||||||
@ -247,6 +255,7 @@ void EventsMngr::parserInit(int msg_type, float* timer, CPlayer* pPlayer, int in
|
|||||||
(*iter).m_Done = true;
|
(*iter).m_Done = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ParseNotDone = true;
|
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].type = MSG_INTEGER;
|
||||||
m_ParseVault[0].iValue = index;
|
m_ParseVault[0].iValue = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ParseFun = &m_Events[msg_type];
|
m_ParseFun = &m_Events[msg_type];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,7 +276,6 @@ void EventsMngr::parseValue(int iValue)
|
|||||||
if (!m_ParseNotDone || !m_ParseFun)
|
if (!m_ParseNotDone || !m_ParseFun)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
// grow if needed
|
// grow if needed
|
||||||
++m_ParsePos;
|
++m_ParsePos;
|
||||||
NextParam();
|
NextParam();
|
||||||
@ -284,6 +293,7 @@ void EventsMngr::parseValue(int iValue)
|
|||||||
// loop through conditions
|
// loop through conditions
|
||||||
bool execute = false;
|
bool execute = false;
|
||||||
bool anyConditions = false;
|
bool anyConditions = false;
|
||||||
|
|
||||||
for (ClEvent::cond_t *condIter = (*iter).m_Conditions; condIter; condIter = condIter->next)
|
for (ClEvent::cond_t *condIter = (*iter).m_Conditions; condIter; condIter = condIter->next)
|
||||||
{
|
{
|
||||||
if (condIter->paramId == m_ParsePos)
|
if (condIter->paramId == m_ParsePos)
|
||||||
@ -291,11 +301,11 @@ void EventsMngr::parseValue(int iValue)
|
|||||||
anyConditions = true;
|
anyConditions = true;
|
||||||
switch(condIter->type)
|
switch(condIter->type)
|
||||||
{
|
{
|
||||||
case '=': if (condIter->iValue == iValue) execute=true; break;
|
case '=': if (condIter->iValue == iValue) execute = true; break;
|
||||||
case '!': if (condIter->iValue != iValue) execute=true; break;
|
case '!': if (condIter->iValue != iValue) execute = true; break;
|
||||||
case '&': if (iValue & condIter->iValue) execute=true; break;
|
case '&': if (iValue & condIter->iValue) execute = true; break;
|
||||||
case '<': if (iValue < condIter->iValue) execute=true; break;
|
case '<': if (iValue < condIter->iValue) execute = true; break;
|
||||||
case '>': if (iValue > condIter->iValue) execute=true; break;
|
case '>': if (iValue > condIter->iValue) execute = true; break;
|
||||||
}
|
}
|
||||||
if (execute)
|
if (execute)
|
||||||
break;
|
break;
|
||||||
@ -312,7 +322,6 @@ void EventsMngr::parseValue(float fValue)
|
|||||||
if (!m_ParseNotDone || !m_ParseFun)
|
if (!m_ParseNotDone || !m_ParseFun)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
// grow if needed
|
// grow if needed
|
||||||
++m_ParsePos;
|
++m_ParsePos;
|
||||||
NextParam();
|
NextParam();
|
||||||
@ -330,6 +339,7 @@ void EventsMngr::parseValue(float fValue)
|
|||||||
// loop through conditions
|
// loop through conditions
|
||||||
bool execute = false;
|
bool execute = false;
|
||||||
bool anyConditions = false;
|
bool anyConditions = false;
|
||||||
|
|
||||||
for (ClEvent::cond_t *condIter = (*iter).m_Conditions; condIter; condIter = condIter->next)
|
for (ClEvent::cond_t *condIter = (*iter).m_Conditions; condIter; condIter = condIter->next)
|
||||||
{
|
{
|
||||||
if (condIter->paramId == m_ParsePos)
|
if (condIter->paramId == m_ParsePos)
|
||||||
@ -337,10 +347,10 @@ void EventsMngr::parseValue(float fValue)
|
|||||||
anyConditions = true;
|
anyConditions = true;
|
||||||
switch(condIter->type)
|
switch(condIter->type)
|
||||||
{
|
{
|
||||||
case '=': if (condIter->fValue == fValue) execute=true; break;
|
case '=': if (condIter->fValue == fValue) execute = true; break;
|
||||||
case '!': if (condIter->fValue != fValue) execute=true; break;
|
case '!': if (condIter->fValue != fValue) execute = true; break;
|
||||||
case '<': if (fValue < condIter->fValue) execute=true; break;
|
case '<': if (fValue < condIter->fValue) execute = true; break;
|
||||||
case '>': if (fValue > condIter->fValue) execute=true; break;
|
case '>': if (fValue > condIter->fValue) execute = true; break;
|
||||||
}
|
}
|
||||||
if (execute)
|
if (execute)
|
||||||
break;
|
break;
|
||||||
@ -374,6 +384,7 @@ void EventsMngr::parseValue(const char *sz)
|
|||||||
// loop through conditions
|
// loop through conditions
|
||||||
bool execute = false;
|
bool execute = false;
|
||||||
bool anyConditions = false;
|
bool anyConditions = false;
|
||||||
|
|
||||||
for (ClEvent::cond_t *condIter = (*iter).m_Conditions; condIter; condIter = condIter->next)
|
for (ClEvent::cond_t *condIter = (*iter).m_Conditions; condIter; condIter = condIter->next)
|
||||||
{
|
{
|
||||||
if (condIter->paramId == m_ParsePos)
|
if (condIter->paramId == m_ParsePos)
|
||||||
@ -381,9 +392,9 @@ void EventsMngr::parseValue(const char *sz)
|
|||||||
anyConditions = true;
|
anyConditions = true;
|
||||||
switch(condIter->type)
|
switch(condIter->type)
|
||||||
{
|
{
|
||||||
case '=': if (!strcmp(sz, condIter->sValue.c_str())) execute=true; break;
|
case '=': if (!strcmp(sz, condIter->sValue.c_str())) execute = true; break;
|
||||||
case '!': if (strcmp(sz, condIter->sValue.c_str())) execute=true; break;
|
case '!': if (strcmp(sz, condIter->sValue.c_str())) execute = true; break;
|
||||||
case '&': if (strstr(sz, condIter->sValue.c_str())) execute=true; break;
|
case '&': if (strstr(sz, condIter->sValue.c_str())) execute = true; break;
|
||||||
}
|
}
|
||||||
if (execute)
|
if (execute)
|
||||||
break;
|
break;
|
||||||
@ -403,11 +414,12 @@ void EventsMngr::executeEvents()
|
|||||||
|
|
||||||
for (ClEventVecIter iter = m_ParseFun->begin(); iter; ++iter)
|
for (ClEventVecIter iter = m_ParseFun->begin(); iter; ++iter)
|
||||||
{
|
{
|
||||||
if ( (*iter).m_Done )
|
if ((*iter).m_Done)
|
||||||
{
|
{
|
||||||
(*iter).m_Done = false;
|
(*iter).m_Done = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*iter).m_Stamp = (float)*m_Timer;
|
(*iter).m_Stamp = (float)*m_Timer;
|
||||||
executeForwards((*iter).m_Func, m_ParseVault ? m_ParseVault[0].iValue : 0);
|
executeForwards((*iter).m_Func, m_ParseVault ? m_ParseVault[0].iValue : 0);
|
||||||
}
|
}
|
||||||
@ -423,53 +435,53 @@ int EventsMngr::getArgNum() const
|
|||||||
|
|
||||||
const char* EventsMngr::getArgString(int a) const
|
const char* EventsMngr::getArgString(int a) const
|
||||||
{
|
{
|
||||||
if ( a < 0 || a > m_ParsePos )
|
if (a < 0 || a > m_ParsePos)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
static char var[32];
|
static char var[32];
|
||||||
|
|
||||||
switch(m_ParseVault[a].type)
|
switch(m_ParseVault[a].type)
|
||||||
{
|
{
|
||||||
case MSG_INTEGER:
|
case MSG_INTEGER:
|
||||||
sprintf( var, "%d", m_ParseVault[a].iValue );
|
sprintf(var, "%d", m_ParseVault[a].iValue);
|
||||||
return var;
|
return var;
|
||||||
case MSG_STRING:
|
case MSG_STRING:
|
||||||
return m_ParseVault[a].sValue;
|
return m_ParseVault[a].sValue;
|
||||||
default:
|
default:
|
||||||
sprintf( var, "%g", m_ParseVault[a].fValue );
|
sprintf(var, "%g", m_ParseVault[a].fValue);
|
||||||
return var;
|
return var;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int EventsMngr::getArgInteger(int a) const
|
int EventsMngr::getArgInteger(int a) const
|
||||||
{
|
{
|
||||||
if ( a < 0 || a > m_ParsePos )
|
if (a < 0 || a > m_ParsePos)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
switch(m_ParseVault[a].type)
|
switch(m_ParseVault[a].type)
|
||||||
{
|
{
|
||||||
case MSG_INTEGER:
|
case MSG_INTEGER:
|
||||||
return m_ParseVault[a].iValue;
|
return m_ParseVault[a].iValue;
|
||||||
case MSG_STRING:
|
case MSG_STRING:
|
||||||
return atoi(m_ParseVault[a].sValue);
|
return atoi(m_ParseVault[a].sValue);
|
||||||
default:
|
default:
|
||||||
return (int)m_ParseVault[a].fValue;
|
return (int)m_ParseVault[a].fValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float EventsMngr::getArgFloat(int a) const
|
float EventsMngr::getArgFloat(int a) const
|
||||||
{
|
{
|
||||||
if ( a < 0 || a > m_ParsePos )
|
if (a < 0 || a > m_ParsePos)
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
|
|
||||||
switch(m_ParseVault[a].type)
|
switch(m_ParseVault[a].type)
|
||||||
{
|
{
|
||||||
case MSG_INTEGER:
|
case MSG_INTEGER:
|
||||||
return static_cast<float>(m_ParseVault[a].iValue);
|
return static_cast<float>(m_ParseVault[a].iValue);
|
||||||
case MSG_STRING:
|
case MSG_STRING:
|
||||||
return static_cast<float>(atof(m_ParseVault[a].sValue));
|
return static_cast<float>(atof(m_ParseVault[a].sValue));
|
||||||
default:
|
default:
|
||||||
return m_ParseVault[a].fValue;
|
return m_ParseVault[a].fValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -479,6 +491,7 @@ void EventsMngr::clearEvents(void)
|
|||||||
{
|
{
|
||||||
m_Events[i].clear();
|
m_Events[i].clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete parsevault
|
// delete parsevault
|
||||||
if (m_ParseVault)
|
if (m_ParseVault)
|
||||||
{
|
{
|
||||||
@ -497,25 +510,26 @@ int EventsMngr::getEventId(const char* msg)
|
|||||||
CS_EventsIds id;
|
CS_EventsIds id;
|
||||||
} table[] =
|
} table[] =
|
||||||
{
|
{
|
||||||
{ "CS_DeathMsg" , CS_DeathMsg },
|
{"CS_DeathMsg", CS_DeathMsg},
|
||||||
// { "CS_RoundEnd" , CS_RoundEnd },
|
// {"CS_RoundEnd", CS_RoundEnd},
|
||||||
// { "CS_RoundStart" , CS_RoundStart },
|
// {"CS_RoundStart", CS_RoundStart},
|
||||||
// { "CS_Restart" , CS_Restart },
|
// {"CS_Restart", CS_Restart},
|
||||||
{ "" , CS_Null }
|
{"", CS_Null}
|
||||||
};
|
};
|
||||||
|
|
||||||
// if msg is a number, return it
|
// if msg is a number, return it
|
||||||
int pos = atoi(msg);
|
int pos = atoi(msg);
|
||||||
|
|
||||||
if (pos != 0)
|
if (pos != 0)
|
||||||
return pos;
|
return pos;
|
||||||
|
|
||||||
// try to find in table first
|
// try to find in table first
|
||||||
for (pos = 0; table[ pos ].id != CS_Null; ++pos )
|
for (pos = 0; table[pos].id != CS_Null; ++pos)
|
||||||
if ( !strcmp( table[ pos ].name , msg ) )
|
if (!strcmp(table[pos].name, msg))
|
||||||
return table[ pos ].id;
|
return table[pos].id;
|
||||||
|
|
||||||
// find the id of the message
|
// find the id of the message
|
||||||
return pos = GET_USER_MSG_ID(PLID, msg , 0 );
|
return pos = GET_USER_MSG_ID(PLID, msg, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int EventsMngr::getCurrentMsgType()
|
int EventsMngr::getCurrentMsgType()
|
||||||
|
@ -36,91 +36,91 @@
|
|||||||
// *****************************************************
|
// *****************************************************
|
||||||
// class File
|
// class File
|
||||||
// *****************************************************
|
// *****************************************************
|
||||||
File::File( const char* n, const char* m )
|
|
||||||
|
File::File(const char* n, const char* m)
|
||||||
{
|
{
|
||||||
fp = fopen( n , m );
|
fp = fopen(n, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
File::~File( )
|
File::~File()
|
||||||
{
|
{
|
||||||
if ( fp )
|
if (fp)
|
||||||
fclose( fp );
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
File::operator bool ( ) const
|
File::operator bool () const
|
||||||
{
|
{
|
||||||
return fp && !feof(fp);
|
return fp && !feof(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
File& operator<<( File& f, const String& n )
|
File& operator<<(File& f, const String& n)
|
||||||
{
|
{
|
||||||
if ( f ) fputs( n.c_str() , f.fp ) ;
|
if (f) fputs(n.c_str(), f.fp);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
File& operator<<( File& f, const char* n )
|
File& operator<<(File& f, const char* n)
|
||||||
{
|
{
|
||||||
if ( f ) fputs( n , f.fp ) ;
|
if (f) fputs(n, f.fp);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
File& operator<<( File& f, int n )
|
File& operator<<(File& f, int n)
|
||||||
{
|
{
|
||||||
if ( f ) fprintf( f.fp , "%d" , n ) ;
|
if (f) fprintf(f.fp, "%d", n);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File& operator<<(File& f, const char& c)
|
||||||
File& operator<<( File& f, const char& c )
|
|
||||||
{
|
{
|
||||||
if ( f ) fputc( c , f.fp ) ;
|
if (f) fputc(c, f.fp);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
File& operator>>( File& f, String& n )
|
File& operator>>(File& f, String& n)
|
||||||
{
|
{
|
||||||
if ( !f ) return f;
|
if (!f) return f;
|
||||||
char temp[1024];
|
char temp[1024];
|
||||||
fscanf( f.fp , "%s", temp );
|
fscanf(f.fp, "%s", temp);
|
||||||
n.assign(temp);
|
n.assign(temp);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
File& operator>>( File& f, char* n )
|
File& operator>>(File& f, char* n)
|
||||||
{
|
{
|
||||||
if ( f ) fscanf( f.fp , "%s", n );
|
if (f) fscanf(f.fp, "%s", n);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
int File::getline( char* buf, int sz )
|
int File::getline(char* buf, int sz)
|
||||||
{
|
{
|
||||||
int a = sz;
|
int a = sz;
|
||||||
char *origBuf = buf;
|
char *origBuf = buf;
|
||||||
if ( *this )
|
|
||||||
{
|
if (*this)
|
||||||
int c;
|
{
|
||||||
while ( sz-- && (c = getc( (*this).fp)) && c != EOF && c != '\n' )
|
int c;
|
||||||
*buf++ = c;
|
while (sz-- && (c = getc((*this).fp)) && c != EOF && c != '\n')
|
||||||
*buf = 0;
|
*buf++ = c;
|
||||||
}
|
|
||||||
|
|
||||||
// trim 0x0a and 0x0d characters at the end
|
|
||||||
while (buf != origBuf)
|
|
||||||
{
|
|
||||||
if (*buf == 0x0a || *buf == 0x0d)
|
|
||||||
*buf = 0;
|
*buf = 0;
|
||||||
--buf;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return a - sz;
|
// trim 0x0a and 0x0d characters at the end
|
||||||
|
while (buf != origBuf)
|
||||||
|
{
|
||||||
|
if (*buf == 0x0a || *buf == 0x0d)
|
||||||
|
*buf = 0;
|
||||||
|
--buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
return a - sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
File& File::skipWs( )
|
File& File::skipWs()
|
||||||
{
|
{
|
||||||
if ( !*this ) return *this;
|
if (!*this) return *this;
|
||||||
int c;
|
int c;
|
||||||
while( isspace( c = getc( fp ) ) ){};
|
while (isspace(c = getc(fp))) {};
|
||||||
ungetc( c , fp );
|
ungetc(c, fp);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ size_t CLangMngr::strip(char *str, char *newstr, bool makelower)
|
|||||||
int flag = 0;
|
int flag = 0;
|
||||||
size_t strln = strlen(str);
|
size_t strln = strlen(str);
|
||||||
|
|
||||||
for (i=strln-1; i>=0; i--)
|
for (i = strln - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
if (str[i] == '\n' || str[i] == ' ' || str[i] == '\t')
|
if (str[i] == '\n' || str[i] == ' ' || str[i] == '\t')
|
||||||
{
|
{
|
||||||
@ -184,6 +184,7 @@ size_t CLangMngr::strip(char *str, char *newstr, bool makelower)
|
|||||||
}
|
}
|
||||||
|
|
||||||
newstr[pos] = 0;
|
newstr[pos] = 0;
|
||||||
|
|
||||||
return ptr - str + 1;
|
return ptr - str + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,11 +301,12 @@ CLangMngr::CLang::~CLang()
|
|||||||
|
|
||||||
void CLangMngr::CLang::Clear()
|
void CLangMngr::CLang::Clear()
|
||||||
{
|
{
|
||||||
for (unsigned int i=0; i<m_LookUpTable.size(); i++)
|
for (unsigned int i = 0; i < m_LookUpTable.size(); i++)
|
||||||
{
|
{
|
||||||
if (m_LookUpTable[i])
|
if (m_LookUpTable[i])
|
||||||
delete m_LookUpTable[i];
|
delete m_LookUpTable[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
m_LookUpTable.clear();
|
m_LookUpTable.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,7 +314,7 @@ CLangMngr::CLang::LangEntry * CLangMngr::CLang::GetEntry(int pkey)
|
|||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i=0; i<m_LookUpTable.size(); i++)
|
for (i = 0; i < m_LookUpTable.size(); i++)
|
||||||
{
|
{
|
||||||
if (m_LookUpTable[i]->GetKey() == pkey)
|
if (m_LookUpTable[i]->GetKey() == pkey)
|
||||||
{
|
{
|
||||||
@ -332,11 +334,13 @@ void CLangMngr::CLang::MergeDefinitions(CQueue<sKeyDef*> &vec)
|
|||||||
{
|
{
|
||||||
const char *def = 0;
|
const char *def = 0;
|
||||||
int key = -1;
|
int key = -1;
|
||||||
|
|
||||||
while (!vec.empty())
|
while (!vec.empty())
|
||||||
{
|
{
|
||||||
key = vec.front()->key;
|
key = vec.front()->key;
|
||||||
def = vec.front()->def->c_str();
|
def = vec.front()->def->c_str();
|
||||||
LangEntry *entry = GetEntry(key);
|
LangEntry *entry = GetEntry(key);
|
||||||
|
|
||||||
if (entry->GetDefHash() != MakeHash(def))
|
if (entry->GetDefHash() != MakeHash(def))
|
||||||
{
|
{
|
||||||
if (entry->GetCache())
|
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);
|
//AMXXLOG_Log("[AMXX] Language key %s[%s] defined twice", m_LMan->GetKey(key), m_LanguageName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete vec.front();
|
delete vec.front();
|
||||||
vec.pop();
|
vec.pop();
|
||||||
}
|
}
|
||||||
@ -357,20 +362,22 @@ const char * CLangMngr::CLang::GetDef(const char *key)
|
|||||||
{
|
{
|
||||||
static char nfind[1024] = "ML_NOTFOUND(KEY)";
|
static char nfind[1024] = "ML_NOTFOUND(KEY)";
|
||||||
int ikey = m_LMan->GetKeyEntry(key);
|
int ikey = m_LMan->GetKeyEntry(key);
|
||||||
|
|
||||||
if (ikey == -1)
|
if (ikey == -1)
|
||||||
{
|
{
|
||||||
sprintf(nfind, "ML_NOTFOUND: %s", key);
|
sprintf(nfind, "ML_NOTFOUND: %s", key);
|
||||||
return nfind;
|
return nfind;
|
||||||
}
|
}
|
||||||
for (unsigned int i = 0; i<m_LookUpTable.size(); i++)
|
|
||||||
|
for (unsigned int i = 0; i < m_LookUpTable.size(); i++)
|
||||||
{
|
{
|
||||||
if (m_LookUpTable[i]->GetKey() == ikey)
|
if (m_LookUpTable[i]->GetKey() == ikey)
|
||||||
return m_LookUpTable[i]->GetDef();
|
return m_LookUpTable[i]->GetDef();
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct OffsetPair
|
struct OffsetPair
|
||||||
{
|
{
|
||||||
uint32_t defOffset;
|
uint32_t defOffset;
|
||||||
@ -381,7 +388,8 @@ struct OffsetPair
|
|||||||
bool CLangMngr::CLang::SaveDefinitions(FILE *fp, uint32_t &curOffset)
|
bool CLangMngr::CLang::SaveDefinitions(FILE *fp, uint32_t &curOffset)
|
||||||
{
|
{
|
||||||
unsigned short defLen = 0;
|
unsigned short defLen = 0;
|
||||||
for (unsigned int i = 0; i<m_LookUpTable.size(); i++)
|
|
||||||
|
for (unsigned int i = 0; i < m_LookUpTable.size(); i++)
|
||||||
{
|
{
|
||||||
defLen = m_LookUpTable[i]->GetDefLength();
|
defLen = m_LookUpTable[i]->GetDefLength();
|
||||||
fwrite((void *)&defLen, sizeof(unsigned short), 1, fp);
|
fwrite((void *)&defLen, sizeof(unsigned short), 1, fp);
|
||||||
@ -403,7 +411,7 @@ bool CLangMngr::CLang::Save(FILE *fp, int &defOffset, uint32_t &curOffset)
|
|||||||
fwrite((void*)&size, sizeof(uint32_t), 1, fp);
|
fwrite((void*)&size, sizeof(uint32_t), 1, fp);
|
||||||
curOffset += sizeof(uint32_t);
|
curOffset += sizeof(uint32_t);
|
||||||
|
|
||||||
for (unsigned int i = 0; i<m_LookUpTable.size(); i++)
|
for (unsigned int i = 0; i < m_LookUpTable.size(); i++)
|
||||||
{
|
{
|
||||||
keynum = m_LookUpTable[i]->GetKey();
|
keynum = m_LookUpTable[i]->GetKey();
|
||||||
defhash = m_LookUpTable[i]->GetDefHash();
|
defhash = m_LookUpTable[i]->GetDefHash();
|
||||||
@ -423,7 +431,6 @@ bool CLangMngr::CLang::Save(FILE *fp, int &defOffset, uint32_t &curOffset)
|
|||||||
// assumes fp is set to the right position
|
// assumes fp is set to the right position
|
||||||
bool CLangMngr::CLang::Load(FILE *fp)
|
bool CLangMngr::CLang::Load(FILE *fp)
|
||||||
{
|
{
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -461,9 +468,10 @@ int CLangMngr::GetKeyEntry(const char *key)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i<KeyList.size(); i++)
|
for (i = 0; i < KeyList.size(); i++)
|
||||||
{
|
{
|
||||||
cmpKey = KeyList[i]->hash;
|
cmpKey = KeyList[i]->hash;
|
||||||
|
|
||||||
if (hKey == cmpKey)
|
if (hKey == cmpKey)
|
||||||
{
|
{
|
||||||
return i;
|
return i;
|
||||||
@ -490,7 +498,7 @@ int CLangMngr::GetKeyEntry(String &key)
|
|||||||
uint32_t hKey = MakeHash(key.c_str(), true);
|
uint32_t hKey = MakeHash(key.c_str(), true);
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
|
|
||||||
for (i = 0; i<KeyList.size(); i++)
|
for (i = 0; i < KeyList.size(); i++)
|
||||||
{
|
{
|
||||||
if (hKey == KeyList[i]->hash)
|
if (hKey == KeyList[i]->hash)
|
||||||
{
|
{
|
||||||
@ -521,6 +529,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
|||||||
{
|
{
|
||||||
// number of parameters ( for NEXT_PARAM macro )
|
// number of parameters ( for NEXT_PARAM macro )
|
||||||
int paramCount = *params / sizeof(cell);
|
int paramCount = *params / sizeof(cell);
|
||||||
|
|
||||||
// the output buffer
|
// the output buffer
|
||||||
static char outbuf[4096];
|
static char outbuf[4096];
|
||||||
char *outptr = outbuf;
|
char *outptr = outbuf;
|
||||||
@ -531,13 +540,14 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
|||||||
if (*src == '%')
|
if (*src == '%')
|
||||||
{
|
{
|
||||||
++src;
|
++src;
|
||||||
if (*src=='L')
|
if (*src == 'L')
|
||||||
{
|
{
|
||||||
cell langName = params[parm]; // "en" case (langName contains the address to the string)
|
cell langName = params[parm]; // "en" case (langName contains the address to the string)
|
||||||
NEXT_PARAM();
|
NEXT_PARAM();
|
||||||
cell *pAmxLangName = get_amxaddr(amx, params[parm++]); // other cases
|
cell *pAmxLangName = get_amxaddr(amx, params[parm++]); // other cases
|
||||||
const char *cpLangName=NULL;
|
const char *cpLangName=NULL;
|
||||||
// Handle player ids (1-32) and server language
|
// Handle player ids (1-32) and server language
|
||||||
|
|
||||||
if (*pAmxLangName == LANG_PLAYER) // LANG_PLAYER
|
if (*pAmxLangName == LANG_PLAYER) // LANG_PLAYER
|
||||||
{
|
{
|
||||||
if ((int)CVAR_GET_FLOAT("amx_client_languages") == 0)
|
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 {
|
} else {
|
||||||
cpLangName = ENTITY_KEYVALUE(GET_PLAYER_POINTER_I(m_CurGlobId)->pEdict, "lang");
|
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");
|
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)
|
if ((int)CVAR_GET_FLOAT("amx_client_languages") == 0)
|
||||||
{
|
{
|
||||||
cpLangName = g_vault.get("server_language");
|
cpLangName = g_vault.get("server_language");
|
||||||
@ -559,12 +571,15 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
|||||||
int tmplen = 0;
|
int tmplen = 0;
|
||||||
cpLangName = get_amxstring(amx, langName, 2, tmplen);
|
cpLangName = get_amxstring(amx, langName, 2, tmplen);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cpLangName || strlen(cpLangName) < 1)
|
if (!cpLangName || strlen(cpLangName) < 1)
|
||||||
cpLangName = "en";
|
cpLangName = "en";
|
||||||
|
|
||||||
int tmplen = 0;
|
int tmplen = 0;
|
||||||
NEXT_PARAM();
|
NEXT_PARAM();
|
||||||
char *key = get_amxstring(amx, params[parm++], 1, tmplen);
|
char *key = get_amxstring(amx, params[parm++], 1, tmplen);
|
||||||
const char *def = GetDef(cpLangName, key);
|
const char *def = GetDef(cpLangName, key);
|
||||||
|
|
||||||
if (def == NULL)
|
if (def == NULL)
|
||||||
{
|
{
|
||||||
if (*pAmxLangName != LANG_SERVER)
|
if (*pAmxLangName != LANG_SERVER)
|
||||||
@ -583,6 +598,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
|||||||
def = buf;
|
def = buf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*def)
|
while (*def)
|
||||||
{
|
{
|
||||||
if (*def == '%')
|
if (*def == '%')
|
||||||
@ -592,9 +608,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
|||||||
{
|
{
|
||||||
*outptr++ = '%';
|
*outptr++ = '%';
|
||||||
++def;
|
++def;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
static char format[32];
|
static char format[32];
|
||||||
format[0] = '%';
|
format[0] = '%';
|
||||||
char *ptr = format+1;
|
char *ptr = format+1;
|
||||||
@ -604,88 +618,89 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
|||||||
ZEROTERM(format);
|
ZEROTERM(format);
|
||||||
|
|
||||||
*ptr = 0;
|
*ptr = 0;
|
||||||
switch ( *(ptr-1) )
|
|
||||||
|
switch (*(ptr - 1))
|
||||||
{
|
{
|
||||||
case 's':
|
case 's':
|
||||||
{
|
{
|
||||||
static char tmpString[4096];
|
static char tmpString[4096];
|
||||||
char *tmpPtr = tmpString;
|
char *tmpPtr = tmpString;
|
||||||
NEXT_PARAM();
|
NEXT_PARAM();
|
||||||
cell *tmpCell = get_amxaddr(amx, params[parm++]);
|
cell *tmpCell = get_amxaddr(amx, params[parm++]);
|
||||||
while (tmpPtr-tmpString < sizeof(tmpString) && *tmpCell)
|
while (tmpPtr-tmpString < sizeof(tmpString) && *tmpCell)
|
||||||
*tmpPtr++ = static_cast<char>(*tmpCell++);
|
*tmpPtr++ = static_cast<char>(*tmpCell++);
|
||||||
|
|
||||||
*tmpPtr = 0;
|
*tmpPtr = 0;
|
||||||
_snprintf(outptr, sizeof(outbuf)-(outptr-outbuf)-1, format, tmpString);
|
_snprintf(outptr, sizeof(outbuf)-(outptr-outbuf)-1, format, tmpString);
|
||||||
ZEROTERM(outbuf);
|
ZEROTERM(outbuf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'g':
|
case 'g':
|
||||||
case 'f':
|
case 'f':
|
||||||
{
|
{
|
||||||
NEXT_PARAM();
|
NEXT_PARAM();
|
||||||
_snprintf(outptr, sizeof(outbuf)-(outptr-outbuf)-1, format, *(REAL*)get_amxaddr(amx, params[parm++]));
|
_snprintf(outptr, sizeof(outbuf)-(outptr-outbuf)-1, format, *(REAL*)get_amxaddr(amx, params[parm++]));
|
||||||
ZEROTERM(outbuf);
|
ZEROTERM(outbuf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'i':
|
case 'i':
|
||||||
case 'd':
|
case 'd':
|
||||||
case 'c':
|
case 'c':
|
||||||
{
|
{
|
||||||
NEXT_PARAM();
|
NEXT_PARAM();
|
||||||
_snprintf(outptr, sizeof(outbuf)-(outptr-outbuf)-1, format, (int)*get_amxaddr(amx, params[parm++]));
|
_snprintf(outptr, sizeof(outbuf)-(outptr-outbuf)-1, format, (int)*get_amxaddr(amx, params[parm++]));
|
||||||
ZEROTERM(outbuf);
|
ZEROTERM(outbuf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
CHECK_OUTPTR(strlen(format)+1);
|
CHECK_OUTPTR(strlen(format)+1);
|
||||||
strcpy(outptr, format);
|
strcpy(outptr, format);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
outptr += strlen(outptr);
|
outptr += strlen(outptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (*def == '^')
|
else if (*def == '^')
|
||||||
{
|
{
|
||||||
++def;
|
++def;
|
||||||
|
|
||||||
switch (*def)
|
switch (*def)
|
||||||
{
|
{
|
||||||
case 'n':
|
case 'n':
|
||||||
CHECK_OUTPTR(1);
|
CHECK_OUTPTR(1);
|
||||||
*outptr++ = '\n';
|
*outptr++ = '\n';
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
CHECK_OUTPTR(1);
|
CHECK_OUTPTR(1);
|
||||||
*outptr++ = '\t';
|
*outptr++ = '\t';
|
||||||
break;
|
break;
|
||||||
case '^':
|
case '^':
|
||||||
CHECK_OUTPTR(1);
|
CHECK_OUTPTR(1);
|
||||||
*outptr++ = '^';
|
*outptr++ = '^';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
CHECK_OUTPTR(2);
|
CHECK_OUTPTR(2);
|
||||||
*outptr++ = '^';
|
*outptr++ = '^';
|
||||||
*outptr++ = *def;
|
*outptr++ = *def;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
++def;
|
++def;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
CHECK_OUTPTR(1);
|
CHECK_OUTPTR(1);
|
||||||
*outptr++ = *def++;
|
*outptr++ = *def++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
static char tmpString[4096];
|
static char tmpString[4096];
|
||||||
char *tmpPtr = tmpString;
|
char *tmpPtr = tmpString;
|
||||||
int tmpLen = 0;
|
int tmpLen = 0;
|
||||||
static char format[32] = {'%'};
|
static char format[32] = {'%'};
|
||||||
char *ptr = format+1;
|
char *ptr = format+1;
|
||||||
|
|
||||||
if (*src != '%')
|
if (*src != '%')
|
||||||
{
|
{
|
||||||
while (*src != 0 && ptr-format<sizeof(format) && !isalpha(*ptr++ = static_cast<char>(*src++)))
|
while (*src != 0 && ptr-format<sizeof(format) && !isalpha(*ptr++ = static_cast<char>(*src++)))
|
||||||
@ -693,9 +708,10 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
|||||||
*ptr = 0;
|
*ptr = 0;
|
||||||
ZEROTERM(format);
|
ZEROTERM(format);
|
||||||
--src;
|
--src;
|
||||||
switch ( *(ptr-1) )
|
|
||||||
|
switch (*(ptr - 1))
|
||||||
{
|
{
|
||||||
case 's':
|
case 's':
|
||||||
{
|
{
|
||||||
NEXT_PARAM();
|
NEXT_PARAM();
|
||||||
cell *tmpCell = get_amxaddr(amx, params[parm++]);
|
cell *tmpCell = get_amxaddr(amx, params[parm++]);
|
||||||
@ -706,45 +722,46 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
|||||||
ZEROTERM(outbuf);
|
ZEROTERM(outbuf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'g':
|
case 'g':
|
||||||
case 'f':
|
case 'f':
|
||||||
{
|
{
|
||||||
NEXT_PARAM();
|
NEXT_PARAM();
|
||||||
_snprintf(outptr, sizeof(outbuf)-(outptr-outbuf)-1, format, *(REAL*)get_amxaddr(amx, params[parm++]));
|
_snprintf(outptr, sizeof(outbuf)-(outptr-outbuf)-1, format, *(REAL*)get_amxaddr(amx, params[parm++]));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'i':
|
case 'i':
|
||||||
case 'd':
|
case 'd':
|
||||||
case 'c':
|
case 'c':
|
||||||
{
|
{
|
||||||
NEXT_PARAM();
|
NEXT_PARAM();
|
||||||
_snprintf(outptr, sizeof(outbuf)-(outptr-outbuf)-1, format, (int)*get_amxaddr(amx, params[parm++]));
|
_snprintf(outptr, sizeof(outbuf)-(outptr-outbuf)-1, format, (int)*get_amxaddr(amx, params[parm++]));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
CHECK_OUTPTR(strlen(format)+1);
|
CHECK_OUTPTR(strlen(format)+1);
|
||||||
strcpy(outptr, format);
|
strcpy(outptr, format);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
outptr += strlen(outptr);
|
outptr += strlen(outptr);
|
||||||
} else {
|
} else {
|
||||||
CHECK_OUTPTR(1);
|
CHECK_OUTPTR(1);
|
||||||
*outptr++ = '%';
|
*outptr++ = '%';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
CHECK_OUTPTR(1);
|
CHECK_OUTPTR(1);
|
||||||
*outptr++ = static_cast<char>(*src);
|
*outptr++ = static_cast<char>(*src);
|
||||||
}
|
}
|
||||||
++src;
|
++src;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = outptr - outbuf;
|
len = outptr - outbuf;
|
||||||
CHECK_OUTPTR(1);
|
CHECK_OUTPTR(1);
|
||||||
*outptr++ = 0;
|
*outptr++ = 0;
|
||||||
|
|
||||||
return outbuf;
|
return outbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -754,6 +771,7 @@ const char *CLangMngr::Format(const char *fmt, ...)
|
|||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
const char *retVal = FormatString(fmt, ap);
|
const char *retVal = FormatString(fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -782,12 +800,13 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
|
|||||||
if (*src == '%')
|
if (*src == '%')
|
||||||
{
|
{
|
||||||
++src;
|
++src;
|
||||||
if (*src=='L')
|
if (*src == 'L')
|
||||||
{
|
{
|
||||||
NEXT_PARAM();
|
NEXT_PARAM();
|
||||||
const char *pAmxLangName = va_arg(ap, const char*);
|
const char *pAmxLangName = va_arg(ap, const char*);
|
||||||
const char *cpLangName=NULL;
|
const char *cpLangName=NULL;
|
||||||
// Handle player ids (1-32) and server language
|
// Handle player ids (1-32) and server language
|
||||||
|
|
||||||
if (pAmxLangName == (const char *)LANG_PLAYER) // LANG_PLAYER
|
if (pAmxLangName == (const char *)LANG_PLAYER) // LANG_PLAYER
|
||||||
{
|
{
|
||||||
if ((int)CVAR_GET_FLOAT("amx_client_languages"))
|
if ((int)CVAR_GET_FLOAT("amx_client_languages"))
|
||||||
@ -796,9 +815,11 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
|
|||||||
} else {
|
} else {
|
||||||
cpLangName = ENTITY_KEYVALUE(GET_PLAYER_POINTER_I(m_CurGlobId)->pEdict, "lang");
|
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");
|
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"))
|
if ((int)CVAR_GET_FLOAT("amx_client_languages"))
|
||||||
{
|
{
|
||||||
cpLangName = g_vault.get("server_language");
|
cpLangName = g_vault.get("server_language");
|
||||||
@ -809,11 +830,14 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
|
|||||||
int tmplen = 0;
|
int tmplen = 0;
|
||||||
cpLangName = pAmxLangName;
|
cpLangName = pAmxLangName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cpLangName || strlen(cpLangName) < 1)
|
if (!cpLangName || strlen(cpLangName) < 1)
|
||||||
cpLangName = "en";
|
cpLangName = "en";
|
||||||
|
|
||||||
int tmplen = 0;
|
int tmplen = 0;
|
||||||
const char *key = va_arg(ap, const char *);
|
const char *key = va_arg(ap, const char *);
|
||||||
const char *def = GetDef(cpLangName, key);
|
const char *def = GetDef(cpLangName, key);
|
||||||
|
|
||||||
if (def == NULL)
|
if (def == NULL)
|
||||||
{
|
{
|
||||||
if (pAmxLangName != LANG_SERVER)
|
if (pAmxLangName != LANG_SERVER)
|
||||||
@ -832,6 +856,7 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
|
|||||||
def = buf;
|
def = buf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*def)
|
while (*def)
|
||||||
{
|
{
|
||||||
if (*def == '%')
|
if (*def == '%')
|
||||||
@ -847,8 +872,72 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
|
|||||||
*ptr = 0;
|
*ptr = 0;
|
||||||
vsprintf(outptr, format, ap);
|
vsprintf(outptr, format, ap);
|
||||||
// vsprintf doesnt alter the ap, increment here
|
// vsprintf doesnt alter the ap, increment here
|
||||||
switch (*(ptr-1))
|
|
||||||
|
switch (*(ptr - 1))
|
||||||
{
|
{
|
||||||
|
case 'f':
|
||||||
|
va_arg(ap, double);
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
va_arg(ap, char *);
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
case 'd':
|
||||||
|
case 'i':
|
||||||
|
default: // default: assume int-like parameter
|
||||||
|
va_arg(ap, int);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
outptr += strlen(outptr);
|
||||||
|
}
|
||||||
|
else if (*def == '^')
|
||||||
|
{
|
||||||
|
++def;
|
||||||
|
|
||||||
|
switch (*def)
|
||||||
|
{
|
||||||
|
case 'n':
|
||||||
|
CHECK_OUTPTR(1);
|
||||||
|
*outptr++ = '\n';
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
CHECK_OUTPTR(1);
|
||||||
|
*outptr++ = '\t';
|
||||||
|
break;
|
||||||
|
case '^':
|
||||||
|
CHECK_OUTPTR(1);
|
||||||
|
*outptr++ = '^';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
CHECK_OUTPTR(2);
|
||||||
|
*outptr++ = '^';
|
||||||
|
*outptr++ = *def;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
++def;
|
||||||
|
} else {
|
||||||
|
CHECK_OUTPTR(1);
|
||||||
|
*outptr++ = *def++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
static char format[32] = {'%'};
|
||||||
|
char *ptr = format+1;
|
||||||
|
|
||||||
|
if (*src != '%')
|
||||||
|
{
|
||||||
|
while (*src != 0 && ptr-format < sizeof(format) && !isalpha(*ptr++ = *src++))
|
||||||
|
/*nothing*/;
|
||||||
|
*ptr = 0;
|
||||||
|
ZEROTERM(format);
|
||||||
|
--src;
|
||||||
|
vsprintf(outptr, format, ap);
|
||||||
|
// vsprintf doesnt alter the ap, increment here
|
||||||
|
|
||||||
|
switch (*(ptr - 1))
|
||||||
|
{
|
||||||
case 'f':
|
case 'f':
|
||||||
va_arg(ap, double);
|
va_arg(ap, double);
|
||||||
break;
|
break;
|
||||||
@ -861,85 +950,24 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
|
|||||||
default: // default: assume int-like parameter
|
default: // default: assume int-like parameter
|
||||||
va_arg(ap, int);
|
va_arg(ap, int);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
outptr += strlen(outptr);
|
|
||||||
}
|
|
||||||
else if (*def == '^')
|
|
||||||
{
|
|
||||||
++def;
|
|
||||||
switch (*def)
|
|
||||||
{
|
|
||||||
case 'n':
|
|
||||||
CHECK_OUTPTR(1);
|
|
||||||
*outptr++ = '\n';
|
|
||||||
break;
|
|
||||||
case 't':
|
|
||||||
CHECK_OUTPTR(1);
|
|
||||||
*outptr++ = '\t';
|
|
||||||
break;
|
|
||||||
case '^':
|
|
||||||
CHECK_OUTPTR(1);
|
|
||||||
*outptr++ = '^';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
CHECK_OUTPTR(2);
|
|
||||||
*outptr++ = '^';
|
|
||||||
*outptr++ = *def;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
++def;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CHECK_OUTPTR(1);
|
|
||||||
*outptr++ = *def++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
static char format[32] = {'%'};
|
|
||||||
char *ptr = format+1;
|
|
||||||
if (*src != '%')
|
|
||||||
{
|
|
||||||
while (*src != 0 && ptr-format<sizeof(format) && !isalpha(*ptr++ = *src++))
|
|
||||||
/*nothing*/;
|
|
||||||
*ptr = 0;
|
|
||||||
ZEROTERM(format);
|
|
||||||
--src;
|
|
||||||
vsprintf(outptr, format, ap);
|
|
||||||
// vsprintf doesnt alter the ap, increment here
|
|
||||||
switch (*(ptr-1))
|
|
||||||
{
|
|
||||||
case 'f':
|
|
||||||
va_arg(ap, double);
|
|
||||||
break;
|
|
||||||
case 's':
|
|
||||||
va_arg(ap, char *);
|
|
||||||
break;
|
|
||||||
case 'c':
|
|
||||||
case 'd':
|
|
||||||
case 'i':
|
|
||||||
default: // default: assume int-like parameter
|
|
||||||
va_arg(ap, int);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
outptr += strlen(outptr);
|
outptr += strlen(outptr);
|
||||||
} else {
|
} else {
|
||||||
CHECK_OUTPTR(1);
|
CHECK_OUTPTR(1);
|
||||||
*outptr++ = '%';
|
*outptr++ = '%';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
CHECK_OUTPTR(1);
|
CHECK_OUTPTR(1);
|
||||||
*outptr++ = *src;
|
*outptr++ = *src;
|
||||||
}
|
}
|
||||||
++src;
|
++src;
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK_OUTPTR(1);
|
CHECK_OUTPTR(1);
|
||||||
*outptr++ = 0;
|
*outptr++ = 0;
|
||||||
|
|
||||||
return outbuf;
|
return outbuf;
|
||||||
}
|
}
|
||||||
void CLangMngr::MergeDefinitions(const char *lang, CQueue<sKeyDef*> &tmpVec)
|
void CLangMngr::MergeDefinitions(const char *lang, CQueue<sKeyDef*> &tmpVec)
|
||||||
@ -957,9 +985,9 @@ int CLangMngr::MergeDefinitionFile(const char *file)
|
|||||||
if (!fp)
|
if (!fp)
|
||||||
{
|
{
|
||||||
CVector<md5Pair *>::iterator iter;
|
CVector<md5Pair *>::iterator iter;
|
||||||
for (iter=FileList.begin(); iter!=FileList.end(); ++iter)
|
for (iter = FileList.begin(); iter != FileList.end(); ++iter)
|
||||||
{
|
{
|
||||||
if ( (*iter)->file.compare(file) == 0 )
|
if ((*iter)->file.compare(file) == 0)
|
||||||
{
|
{
|
||||||
char buf[33] = {0};
|
char buf[33] = {0};
|
||||||
(*iter)->val.assign(buf);
|
(*iter)->val.assign(buf);
|
||||||
@ -969,19 +997,20 @@ int CLangMngr::MergeDefinitionFile(const char *file)
|
|||||||
AMXXLOG_Log("[AMXX] Failed to open dictionary file: %s", file);
|
AMXXLOG_Log("[AMXX] Failed to open dictionary file: %s", file);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MD5 md5;
|
MD5 md5;
|
||||||
md5.update(fp); // closes for us
|
md5.update(fp); // closes for us
|
||||||
md5.finalize();
|
md5.finalize();
|
||||||
char md5buffer[33];
|
char md5buffer[33];
|
||||||
md5.hex_digest(md5buffer);
|
md5.hex_digest(md5buffer);
|
||||||
bool foundFlag = false;
|
bool foundFlag = false;
|
||||||
|
|
||||||
CVector<md5Pair *>::iterator iter;
|
CVector<md5Pair *>::iterator iter;
|
||||||
for (iter=FileList.begin(); iter!=FileList.end(); ++iter)
|
for (iter = FileList.begin(); iter != FileList.end(); ++iter)
|
||||||
{
|
{
|
||||||
if ( (*iter)->file.compare(file) == 0 )
|
if ((*iter)->file.compare(file) == 0)
|
||||||
{
|
{
|
||||||
if ( (*iter)->val.compare(md5buffer) == 0 )
|
if ((*iter)->val.compare(md5buffer) == 0)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
@ -1022,6 +1051,7 @@ int CLangMngr::MergeDefinitionFile(const char *file)
|
|||||||
buf.trim();
|
buf.trim();
|
||||||
if (buf[0] == 0)
|
if (buf[0] == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (buf[0] == '[' && buf.size() >= 3)
|
if (buf[0] == '[' && buf.size() >= 3)
|
||||||
{
|
{
|
||||||
if (multiline)
|
if (multiline)
|
||||||
@ -1031,10 +1061,12 @@ int CLangMngr::MergeDefinitionFile(const char *file)
|
|||||||
delete tmpEntry;
|
delete tmpEntry;
|
||||||
tmpEntry = 0;
|
tmpEntry = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Defq.empty())
|
if (!Defq.empty())
|
||||||
{
|
{
|
||||||
MergeDefinitions(language, Defq);
|
MergeDefinitions(language, Defq);
|
||||||
}
|
}
|
||||||
|
|
||||||
language[0] = buf[1];
|
language[0] = buf[1];
|
||||||
language[1] = buf[2];
|
language[1] = buf[2];
|
||||||
language[2] = 0;
|
language[2] = 0;
|
||||||
@ -1042,6 +1074,7 @@ int CLangMngr::MergeDefinitionFile(const char *file)
|
|||||||
if (!multiline)
|
if (!multiline)
|
||||||
{
|
{
|
||||||
pos = buf.find('=');
|
pos = buf.find('=');
|
||||||
|
|
||||||
if (pos > String::npos)
|
if (pos > String::npos)
|
||||||
{
|
{
|
||||||
tmpEntry = new sKeyDef;
|
tmpEntry = new sKeyDef;
|
||||||
@ -1062,6 +1095,7 @@ int CLangMngr::MergeDefinitionFile(const char *file)
|
|||||||
tmpEntry = 0;
|
tmpEntry = 0;
|
||||||
} else {
|
} else {
|
||||||
pos = buf.find(':');
|
pos = buf.find(':');
|
||||||
|
|
||||||
if (pos > String::npos)
|
if (pos > String::npos)
|
||||||
{
|
{
|
||||||
tmpEntry = new sKeyDef;
|
tmpEntry = new sKeyDef;
|
||||||
@ -1105,9 +1139,9 @@ int CLangMngr::MergeDefinitionFile(const char *file)
|
|||||||
CLangMngr::CLang * CLangMngr::GetLang(const char *name)
|
CLangMngr::CLang * CLangMngr::GetLang(const char *name)
|
||||||
{
|
{
|
||||||
LangVecIter iter;
|
LangVecIter iter;
|
||||||
for (iter=m_Languages.begin(); iter!=m_Languages.end(); ++iter)
|
for (iter = m_Languages.begin(); iter != m_Languages.end(); ++iter)
|
||||||
{
|
{
|
||||||
if ( strcmp((*iter)->GetName(), name)==0 )
|
if (strcmp((*iter)->GetName(), name) == 0)
|
||||||
return (*iter);
|
return (*iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1122,9 +1156,9 @@ CLangMngr::CLang * CLangMngr::GetLang(const char *name)
|
|||||||
CLangMngr::CLang * CLangMngr::GetLangR(const char *name)
|
CLangMngr::CLang * CLangMngr::GetLangR(const char *name)
|
||||||
{
|
{
|
||||||
LangVecIter iter;
|
LangVecIter iter;
|
||||||
for (iter=m_Languages.begin(); iter!=m_Languages.end(); ++iter)
|
for (iter = m_Languages.begin(); iter != m_Languages.end(); ++iter)
|
||||||
{
|
{
|
||||||
if ( strcmp((*iter)->GetName(), name)==0 )
|
if (strcmp((*iter)->GetName(), name) == 0)
|
||||||
return (*iter);
|
return (*iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1166,7 +1200,7 @@ bool CLangMngr::Save(const char *filename)
|
|||||||
curOffset += sizeof(uint32_t);
|
curOffset += sizeof(uint32_t);
|
||||||
|
|
||||||
uint32_t langOffset = curOffset + ktbSize + ltbSize;
|
uint32_t langOffset = curOffset + ktbSize + ltbSize;
|
||||||
for (unsigned int i = 0; i<m_Languages.size(); i++)
|
for (unsigned int i = 0; i < m_Languages.size(); i++)
|
||||||
{
|
{
|
||||||
langName = m_Languages[i]->GetName();
|
langName = m_Languages[i]->GetName();
|
||||||
fwrite(langName, sizeof(char), 2, fp);
|
fwrite(langName, sizeof(char), 2, fp);
|
||||||
@ -1179,7 +1213,7 @@ bool CLangMngr::Save(const char *filename)
|
|||||||
//Note - langOffset now points to the start of key lookup table
|
//Note - langOffset now points to the start of key lookup table
|
||||||
uint32_t keyHash = 0;
|
uint32_t keyHash = 0;
|
||||||
uint32_t keyOffset = langOffset;
|
uint32_t keyOffset = langOffset;
|
||||||
for (unsigned int i = 0; i<KeyList.size(); i++)
|
for (unsigned int i = 0; i < KeyList.size(); i++)
|
||||||
{
|
{
|
||||||
keyHash = KeyList[i]->hash;
|
keyHash = KeyList[i]->hash;
|
||||||
fwrite((void*)&keyHash, sizeof(uint32_t), 1, fp);
|
fwrite((void*)&keyHash, sizeof(uint32_t), 1, fp);
|
||||||
@ -1192,7 +1226,7 @@ bool CLangMngr::Save(const char *filename)
|
|||||||
|
|
||||||
//Note - now keyOffset points toward the start of the def table
|
//Note - now keyOffset points toward the start of the def table
|
||||||
int defOffset = keyOffset;
|
int defOffset = keyOffset;
|
||||||
for (unsigned int i = 0; i<m_Languages.size(); i++)
|
for (unsigned int i = 0; i < m_Languages.size(); i++)
|
||||||
{
|
{
|
||||||
m_Languages[i]->Save(fp, defOffset, curOffset);
|
m_Languages[i]->Save(fp, defOffset, curOffset);
|
||||||
}
|
}
|
||||||
@ -1200,7 +1234,7 @@ bool CLangMngr::Save(const char *filename)
|
|||||||
//Now, defOffset points toward the END of the file
|
//Now, defOffset points toward the END of the file
|
||||||
//curoffset should point toward the key table, so...
|
//curoffset should point toward the key table, so...
|
||||||
unsigned char keyLen = 0;
|
unsigned char keyLen = 0;
|
||||||
for (unsigned int i = 0; i<KeyList.size(); i++)
|
for (unsigned int i = 0; i < KeyList.size(); i++)
|
||||||
{
|
{
|
||||||
keyLen = KeyList[i]->key.size();
|
keyLen = KeyList[i]->key.size();
|
||||||
fwrite((void*)&keyLen, sizeof(unsigned char), 1, fp);
|
fwrite((void*)&keyLen, sizeof(unsigned char), 1, fp);
|
||||||
@ -1211,7 +1245,7 @@ bool CLangMngr::Save(const char *filename)
|
|||||||
|
|
||||||
//Finally, write the def table
|
//Finally, write the def table
|
||||||
// It's assumed no orders changed...
|
// It's assumed no orders changed...
|
||||||
for (unsigned int i = 0; i<m_Languages.size(); i++)
|
for (unsigned int i = 0; i < m_Languages.size(); i++)
|
||||||
{
|
{
|
||||||
m_Languages[i]->SaveDefinitions(fp, curOffset);
|
m_Languages[i]->SaveDefinitions(fp, curOffset);
|
||||||
}
|
}
|
||||||
@ -1236,7 +1270,7 @@ bool CLangMngr::SaveCache(const char *filename)
|
|||||||
|
|
||||||
fwrite((void *)&dictCount, sizeof(short), 1, fp);
|
fwrite((void *)&dictCount, sizeof(short), 1, fp);
|
||||||
|
|
||||||
for (i=FileList.begin(); i!=FileList.end(); i++)
|
for (i = FileList.begin(); i != FileList.end(); i++)
|
||||||
{
|
{
|
||||||
len = (*i)->file.size();
|
len = (*i)->file.size();
|
||||||
fwrite((void *)&len, sizeof(char), 1, fp);
|
fwrite((void *)&len, sizeof(char), 1, fp);
|
||||||
@ -1264,8 +1298,7 @@ bool CLangMngr::LoadCache(const char *filename)
|
|||||||
fread((void*)&dictCount, sizeof(short), 1, fp);
|
fread((void*)&dictCount, sizeof(short), 1, fp);
|
||||||
md5Pair *p = 0;
|
md5Pair *p = 0;
|
||||||
|
|
||||||
|
for (int i = 1; i <= dictCount; i++)
|
||||||
for (int i=1; i<=dictCount; i++)
|
|
||||||
{
|
{
|
||||||
fread((void*)&len, sizeof(char), 1, fp);
|
fread((void*)&len, sizeof(char), 1, fp);
|
||||||
fread(buf, sizeof(char), len, fp);
|
fread(buf, sizeof(char), len, fp);
|
||||||
@ -1311,7 +1344,8 @@ bool CLangMngr::Load(const char *filename)
|
|||||||
|
|
||||||
uint32_t *LangOffsets = new uint32_t[langCount];
|
uint32_t *LangOffsets = new uint32_t[langCount];
|
||||||
char langname[3];
|
char langname[3];
|
||||||
for (unsigned int i=0; i<langCount; i++)
|
|
||||||
|
for (unsigned int i = 0; i < langCount; i++)
|
||||||
{
|
{
|
||||||
fread(langname, sizeof(char), 2, fp);
|
fread(langname, sizeof(char), 2, fp);
|
||||||
langname[2] = 0;
|
langname[2] = 0;
|
||||||
@ -1324,7 +1358,8 @@ bool CLangMngr::Load(const char *filename)
|
|||||||
keyEntry *e = 0;
|
keyEntry *e = 0;
|
||||||
unsigned char keylen;
|
unsigned char keylen;
|
||||||
uint32_t keyoffset, save;
|
uint32_t keyoffset, save;
|
||||||
for (unsigned i=0; i<keycount; i++)
|
|
||||||
|
for (unsigned i = 0; i < keycount; i++)
|
||||||
{
|
{
|
||||||
e = new keyEntry;
|
e = new keyEntry;
|
||||||
fread((void*)&(e->hash), sizeof(uint32_t), 1, fp);
|
fread((void*)&(e->hash), sizeof(uint32_t), 1, fp);
|
||||||
@ -1347,10 +1382,12 @@ bool CLangMngr::Load(const char *filename)
|
|||||||
uint32_t defhash;
|
uint32_t defhash;
|
||||||
uint32_t defoffset;
|
uint32_t defoffset;
|
||||||
unsigned short deflen;
|
unsigned short deflen;
|
||||||
for (unsigned int i=0; i<langCount; i++)
|
|
||||||
|
for (unsigned int i = 0; i < langCount; i++)
|
||||||
{
|
{
|
||||||
fread((void*)&numentries, sizeof(uint32_t), 1, fp);
|
fread((void*)&numentries, sizeof(uint32_t), 1, fp);
|
||||||
for (unsigned int j=0; j<numentries; j++)
|
|
||||||
|
for (unsigned int j = 0; j < numentries; j++)
|
||||||
{
|
{
|
||||||
fread((void *)&keynum, sizeof(uint32_t), 1, fp);
|
fread((void *)&keynum, sizeof(uint32_t), 1, fp);
|
||||||
fread((void *)&defhash, sizeof(uint32_t), 1, fp);
|
fread((void *)&defhash, sizeof(uint32_t), 1, fp);
|
||||||
@ -1383,19 +1420,20 @@ CLangMngr::~CLangMngr()
|
|||||||
void CLangMngr::Clear()
|
void CLangMngr::Clear()
|
||||||
{
|
{
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
for (i=0; i<m_Languages.size(); i++)
|
|
||||||
|
for (i = 0; i < m_Languages.size(); i++)
|
||||||
{
|
{
|
||||||
if (m_Languages[i])
|
if (m_Languages[i])
|
||||||
delete m_Languages[i];
|
delete m_Languages[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<FileList.size(); i++)
|
for (i = 0; i < FileList.size(); i++)
|
||||||
{
|
{
|
||||||
if (FileList[i])
|
if (FileList[i])
|
||||||
delete FileList[i];
|
delete FileList[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<KeyList.size(); i++)
|
for (i = 0; i < KeyList.size(); i++)
|
||||||
{
|
{
|
||||||
if (KeyList[i])
|
if (KeyList[i])
|
||||||
delete KeyList[i];
|
delete KeyList[i];
|
||||||
@ -1415,7 +1453,8 @@ const char *CLangMngr::GetLangName(int langId)
|
|||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
LangVecIter iter;
|
LangVecIter iter;
|
||||||
for (iter=m_Languages.begin(); iter!=m_Languages.end(); ++iter)
|
|
||||||
|
for (iter = m_Languages.begin(); iter != m_Languages.end(); ++iter)
|
||||||
{
|
{
|
||||||
if (i == langId)
|
if (i == langId)
|
||||||
{
|
{
|
||||||
@ -1423,13 +1462,15 @@ const char *CLangMngr::GetLangName(int langId)
|
|||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CLangMngr::LangExists(const char *langName)
|
bool CLangMngr::LangExists(const char *langName)
|
||||||
{
|
{
|
||||||
char buf[3] = { 0 };
|
char buf[3] = {0};
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while (buf[i] = tolower(*langName++))
|
while (buf[i] = tolower(*langName++))
|
||||||
{
|
{
|
||||||
if (++i == 2)
|
if (++i == 2)
|
||||||
@ -1437,11 +1478,13 @@ bool CLangMngr::LangExists(const char *langName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
LangVecIter iter;
|
LangVecIter iter;
|
||||||
for (iter=m_Languages.begin(); iter!=m_Languages.end(); ++iter)
|
|
||||||
|
for (iter = m_Languages.begin(); iter != m_Languages.end(); ++iter)
|
||||||
{
|
{
|
||||||
if ( strcmp((*iter)->GetName(), buf)==0 )
|
if (strcmp((*iter)->GetName(), buf) == 0)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,135 +35,177 @@
|
|||||||
// *****************************************************
|
// *****************************************************
|
||||||
// class LogEventsMngr
|
// class LogEventsMngr
|
||||||
// *****************************************************
|
// *****************************************************
|
||||||
LogEventsMngr::LogEventsMngr() {
|
|
||||||
logCurrent = logCounter = 0;
|
LogEventsMngr::LogEventsMngr()
|
||||||
logcmplist = 0;
|
{
|
||||||
arelogevents = false;
|
logCurrent = logCounter = 0;
|
||||||
memset( logevents, 0, sizeof(logevents) );
|
logcmplist = 0;
|
||||||
|
arelogevents = false;
|
||||||
|
memset(logevents, 0, sizeof(logevents));
|
||||||
}
|
}
|
||||||
|
|
||||||
LogEventsMngr::~LogEventsMngr() {
|
LogEventsMngr::~LogEventsMngr()
|
||||||
|
{
|
||||||
clearLogEvents();
|
clearLogEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
int LogEventsMngr::CLogCmp::compareCondition(const char* string){
|
int LogEventsMngr::CLogCmp::compareCondition(const char* string)
|
||||||
if ( logid == parent->logCounter )
|
{
|
||||||
return result;
|
if (logid == parent->logCounter)
|
||||||
logid = parent->logCounter;
|
return result;
|
||||||
if ( in ) return result = strstr( string , text.c_str() ) ? 0 : 1;
|
|
||||||
return result = strcmp(string,text.c_str());
|
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;
|
char* temp = filter;
|
||||||
// expand "1=message"
|
// expand "1=message"
|
||||||
while ( isdigit(*filter) )
|
|
||||||
|
while (isdigit(*filter))
|
||||||
++filter;
|
++filter;
|
||||||
bool in = (*filter=='&');
|
|
||||||
|
bool in = (*filter=='&');
|
||||||
*filter++ = 0;
|
*filter++ = 0;
|
||||||
int pos = atoi(temp);
|
int pos = atoi(temp);
|
||||||
if ( pos < 0 || pos >= MAX_LOGARGS) pos = 0;
|
if (pos < 0 || pos >= MAX_LOGARGS) pos = 0;
|
||||||
CLogCmp* c = logcmplist;
|
CLogCmp* c = logcmplist;
|
||||||
while( c ) {
|
|
||||||
if ( (c->pos==pos) && (c->in==in) && !strcmp(c->text.c_str(), filter))
|
while (c)
|
||||||
|
{
|
||||||
|
if ((c->pos == pos) && (c->in == in) && !strcmp(c->text.c_str(), filter))
|
||||||
return c;
|
return c;
|
||||||
c = c->next;
|
c = c->next;
|
||||||
}
|
}
|
||||||
return logcmplist = new CLogCmp( filter , in , pos , logcmplist,this );
|
|
||||||
|
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;
|
CLogCmp *cmp = parent->registerCondition(filter);
|
||||||
for(LogCond* c = filters; c ; c = c->next){
|
if (cmp == 0) return;
|
||||||
if ( c->argnum == cmp->pos ){
|
|
||||||
c->list = new LogCondEle( cmp , c->list );
|
for (LogCond* c = filters; c; c = c->next)
|
||||||
|
{
|
||||||
|
if (c->argnum == cmp->pos)
|
||||||
|
{
|
||||||
|
c->list = new LogCondEle(cmp, c->list);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LogCondEle* aa = new LogCondEle( cmp , 0 );
|
|
||||||
if ( aa == 0 ) return;
|
LogCondEle* aa = new LogCondEle(cmp, 0);
|
||||||
filters = new LogCond( cmp->pos , aa , filters );
|
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;
|
++logCounter;
|
||||||
int len = vsnprintf (logString, 255 , frmt, vaptr );
|
int len = vsnprintf(logString, 255, frmt, vaptr);
|
||||||
if ( len == - 1) {
|
|
||||||
|
if (len == - 1)
|
||||||
|
{
|
||||||
len = 255;
|
len = 255;
|
||||||
logString[len] = 0;
|
logString[len] = 0;
|
||||||
}
|
}
|
||||||
if ( len ) logString[--len] = 0;
|
|
||||||
|
if (len) logString[--len] = 0;
|
||||||
logArgc = 0;
|
logArgc = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogEventsMngr::setLogString( char* frmt, ... ) {
|
void LogEventsMngr::setLogString(char* frmt, ...)
|
||||||
|
{
|
||||||
++logCounter;
|
++logCounter;
|
||||||
va_list logArgPtr;
|
va_list logArgPtr;
|
||||||
va_start ( logArgPtr , frmt );
|
va_start(logArgPtr, frmt);
|
||||||
int len = vsnprintf(logString, 255 , frmt, logArgPtr );
|
int len = vsnprintf(logString, 255, frmt, logArgPtr);
|
||||||
if ( len == - 1) {
|
|
||||||
|
if (len == - 1)
|
||||||
|
{
|
||||||
len = 255;
|
len = 255;
|
||||||
logString[len] = 0;
|
logString[len] = 0;
|
||||||
}
|
}
|
||||||
va_end ( logArgPtr );
|
|
||||||
if ( len ) logString[--len] = 0;
|
va_end(logArgPtr);
|
||||||
|
if (len) logString[--len] = 0;
|
||||||
logArgc = 0;
|
logArgc = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogEventsMngr::parseLogString( ) {
|
void LogEventsMngr::parseLogString()
|
||||||
register const char* b = logString;
|
{
|
||||||
register int a;
|
register const char* b = logString;
|
||||||
while( *b && logArgc < MAX_LOGARGS ){
|
register int a;
|
||||||
a = 0;
|
|
||||||
if ( *b == '"' ) {
|
while (*b && logArgc < MAX_LOGARGS)
|
||||||
++b;
|
{
|
||||||
while ( *b && *b != '"' && a < 127 )
|
a = 0;
|
||||||
logArgs[logArgc][a++] = *b++;
|
|
||||||
logArgs[logArgc++][a] = 0;
|
if (*b == '"')
|
||||||
if ( *b) b+=2; // thanks to double terminator
|
{
|
||||||
}
|
++b;
|
||||||
else if ( *b == '(' ) {
|
|
||||||
++b;
|
while (*b && *b != '"' && a < 127)
|
||||||
while ( *b && *b != ')' && a < 127 )
|
logArgs[logArgc][a++] = *b++;
|
||||||
logArgs[logArgc][a++] = *b++;
|
|
||||||
logArgs[logArgc++][a] = 0;
|
logArgs[logArgc++][a] = 0;
|
||||||
if ( *b) b+=2;
|
if (*b) b+=2; // thanks to double terminator
|
||||||
}
|
}
|
||||||
else {
|
else if (*b == '(')
|
||||||
while ( *b && *b != '(' && *b != '"' && a < 127 )
|
{
|
||||||
logArgs[logArgc][a++] = *b++;
|
++b;
|
||||||
if ( *b ) --a;
|
|
||||||
logArgs[logArgc++][a] = 0;
|
while (*b && *b != ')' && a < 127)
|
||||||
}
|
logArgs[logArgc][a++] = *b++;
|
||||||
}
|
|
||||||
|
logArgs[logArgc++][a] = 0;
|
||||||
|
if (*b) b+=2;
|
||||||
|
} else {
|
||||||
|
while (*b && *b != '(' && *b != '"' && a < 127)
|
||||||
|
logArgs[logArgc][a++] = *b++;
|
||||||
|
if (*b) --a;
|
||||||
|
logArgs[logArgc++][a] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LogEventsMngr::CLogEvent* LogEventsMngr::registerLogEvent( CPluginMngr::CPlugin* plugin, int func, int pos )
|
LogEventsMngr::CLogEvent* LogEventsMngr::registerLogEvent(CPluginMngr::CPlugin* plugin, int func, int pos)
|
||||||
{
|
{
|
||||||
if ( pos < 1 || pos > MAX_LOGARGS)
|
if (pos < 1 || pos > MAX_LOGARGS)
|
||||||
return 0;
|
return 0;
|
||||||
arelogevents = true;
|
|
||||||
CLogEvent** d = &logevents[pos];
|
arelogevents = true;
|
||||||
while(*d) d = &(*d)->next;
|
CLogEvent** d = &logevents[pos];
|
||||||
return *d = new CLogEvent( plugin , func, this );
|
while (*d) d = &(*d)->next;
|
||||||
|
|
||||||
|
return *d = new CLogEvent(plugin, func, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogEventsMngr::executeLogEvents()
|
void LogEventsMngr::executeLogEvents()
|
||||||
{
|
{
|
||||||
bool valid;
|
bool valid;
|
||||||
for(CLogEvent* a = logevents[ logArgc ]; a ; a = a->next)
|
|
||||||
|
for (CLogEvent* a = logevents[logArgc]; a; a = a->next)
|
||||||
{
|
{
|
||||||
valid = true;
|
valid = true;
|
||||||
for( CLogEvent::LogCond* b = a->filters; b ; b = b->next)
|
|
||||||
|
for (CLogEvent::LogCond* b = a->filters; b; b = b->next)
|
||||||
{
|
{
|
||||||
valid = false;
|
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;
|
valid = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!valid)
|
if (!valid)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -175,64 +217,87 @@ void LogEventsMngr::executeLogEvents()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogEventsMngr::clearLogEvents(){
|
void LogEventsMngr::clearLogEvents()
|
||||||
logCurrent = logCounter = 0;
|
{
|
||||||
arelogevents = false;
|
logCurrent = logCounter = 0;
|
||||||
for(int i = 0; i < MAX_LOGARGS + 1; ++i){
|
arelogevents = false;
|
||||||
CLogEvent **a = &logevents[i];
|
|
||||||
while(*a){
|
for (int i = 0; i < MAX_LOGARGS + 1; ++i)
|
||||||
CLogEvent* bb = (*a)->next;
|
{
|
||||||
delete *a;
|
CLogEvent **a = &logevents[i];
|
||||||
*a = bb;
|
while (*a)
|
||||||
}
|
{
|
||||||
}
|
CLogEvent* bb = (*a)->next;
|
||||||
clearConditions();
|
delete *a;
|
||||||
|
*a = bb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clearConditions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogEventsMngr::clearConditions() {
|
void LogEventsMngr::clearConditions()
|
||||||
while (logcmplist){
|
{
|
||||||
CLogCmp* a = logcmplist->next;
|
while (logcmplist)
|
||||||
delete logcmplist;
|
{
|
||||||
logcmplist = a;
|
CLogCmp* a = logcmplist->next;
|
||||||
}
|
delete logcmplist;
|
||||||
|
logcmplist = a;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LogEventsMngr::CLogEvent::LogCond::~LogCond() {
|
LogEventsMngr::CLogEvent::LogCond::~LogCond()
|
||||||
while( list ) {
|
{
|
||||||
|
while (list)
|
||||||
|
{
|
||||||
LogCondEle* cc = list->next;
|
LogCondEle* cc = list->next;
|
||||||
delete list;
|
delete list;
|
||||||
list = cc;
|
list = cc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LogEventsMngr::CLogEvent::~CLogEvent() {
|
LogEventsMngr::CLogEvent::~CLogEvent()
|
||||||
while( filters ) {
|
{
|
||||||
|
while (filters)
|
||||||
|
{
|
||||||
LogCond* cc = filters->next;
|
LogCond* cc = filters->next;
|
||||||
delete filters;
|
delete filters;
|
||||||
filters = cc;
|
filters = cc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LogEventsMngr::CLogEvent *LogEventsMngr::getValidLogEvent( CLogEvent * a )
|
LogEventsMngr::CLogEvent *LogEventsMngr::getValidLogEvent(CLogEvent * a)
|
||||||
{
|
{
|
||||||
bool valid;
|
bool valid;
|
||||||
while(a){
|
|
||||||
|
while (a)
|
||||||
|
{
|
||||||
valid = true;
|
valid = true;
|
||||||
for( CLogEvent::LogCond* b = a->filters; b ; b = b->next){
|
|
||||||
|
for (CLogEvent::LogCond* b = a->filters; b; b = b->next)
|
||||||
|
{
|
||||||
valid = false;
|
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;
|
valid = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!valid) break;
|
if (!valid) break;
|
||||||
}
|
}
|
||||||
if (!valid){
|
|
||||||
|
if (!valid)
|
||||||
|
{
|
||||||
a = a->next;
|
a = a->next;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user