void EventsMngr::parserInit(int msg_type, float* timer, CPlayer* pPlayer, int index) { if (msg_type < 0 || msg_type > MAX_AMX_REG_MSG) return; m_ParseNotDone = false; // don't parse if nothing to do if (!m_Events[msg_type].size()) return; m_ParseMsgType = msg_type; m_Timer = timer; for (ClEventVecIter iter = m_Events[msg_type].begin(); iter; ++iter) { if ((*iter).m_Done) continue; if (!(*iter).m_Plugin->isExecutable((*iter).m_Func)) { (*iter).m_Done = true; continue; } if (pPlayer) { if (!(*iter).m_FlagClient || (pPlayer->IsBot() ? !(*iter).m_FlagBot : !(*iter).m_FlagPlayer) || (pPlayer->IsAlive() ? !(*iter).m_FlagAlive : !(*iter).m_FlagDead)) { (*iter).m_Done = true; continue; } } else if (!(*iter).m_FlagWorld) { (*iter).m_Done = true; continue; } if ((*iter).m_FlagOnce && (*iter).m_Stamp == (float)(*timer)) { (*iter).m_Done = true; continue; } m_ParseNotDone = true; } if (m_ParseNotDone) { m_ParsePos = 0; NextParam(); m_ParseVault[0].type = MSG_INTEGER; m_ParseVault[0].iValue = index; } m_ParseFun = &m_Events[msg_type]; }
/* read an RX document stream and augment the given list of arguments */ int RxReadParams(char *stream, char **argn_ret[], char **argv_ret[], int *argc_ret) { char **argv, **argn; int argc, n; NString param; char *name, *value; int status; status = 0; argc = n = 0; argn = argv = NULL; if (stream != NULL) { do { stream = NextParam(stream, ¶m); if (param.length != 0 && ParseParam(¶m, &name, &value) == 0) { argc++; if (n == 0) { /* alloc first block */ n = PARAMSINC; argn = (char **)Malloc(sizeof(char *) * n); if (!argn) return 1; argv = (char **)Malloc(sizeof(char *) * n); if (!argv) { Free(argn); return 1; } } if (argc % PARAMSINC == 0) { /* we need to add a block */ n += PARAMSINC; argn = (char **) Realloc(argn, sizeof(char *) * argc, sizeof(char *) * n); argv = (char **) Realloc(argv, sizeof(char *) * argc, sizeof(char *) * n); if (!argn || !argv) { argc--; status = 1; break; } } argn[argc - 1] = name; argv[argc - 1] = value; } } while (*stream); } *argn_ret = argn; *argv_ret = argv; *argc_ret = argc; return status; }
void EventsMngr::parseValue(float fValue) { // not parsing if (!m_ParseNotDone || !m_ParseFun) return; // grow if needed ++m_ParsePos; NextParam(); m_ParseVault[m_ParsePos].type = MSG_FLOAT; m_ParseVault[m_ParsePos].fValue = fValue; // loop through the registered funcs, and decide whether they have to be called or not // if they shouldnt, their m_Done is set to true for (ClEventVecIter iter = m_ParseFun->begin(); iter; ++iter) { if ((*iter).m_Done) continue; // already skipped; don't bother with parsing // 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) { anyConditions = true; switch (condIter->type) { 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; } if (execute) break; } } if (anyConditions && !execute) (*iter).m_Done = true; // don't execute } }
// Sort une chaîne formattée à l'écran avec les params dans une chaîne. // %u : unsigned int. // %i : int. // %U? : unsigned int. ? = Le nombre de zero. // %I? : int. ? = Le nombre de zero. // %s : ptrString. // %h : hexa. // %b? : binaire. ? = 1 pour un octets, 2 pour deux octets etc. Max = 4. // %c : char. // *params est la liste des paramètres %?. void OutT_Format(unsigned char *str, void *params) { #define NextParam(ParamsPtr) (((void*) ParamsPtr) += 4, *((int*) (ParamsPtr-4))) while (*str != 0) { if (*str == '%') { switch(str[1]) { char *string; case 'u' : OutT_uInt(NextParam(params),0); break; case 'i' : OutT_Int(NextParam(params),0); break; case 'U' : OutT_uInt(NextParam(params),str[2]-48); str++; break; case 'I' : OutT_Int(NextParam(params),str[2]-48); str++; break; case 's' : string = (char*) NextParam(params); while (*string != 0) OutT_PutChar(*string++); break; case 'h' : OutT_Hexa(NextParam(params)); break; case 'b' : OutT_Bin(NextParam(params),str[2]-48); str++; break; case 'c' : OutT_PutChar(NextParam(params)); break; default : { OutT_PutChar(*str); str--; } } str++; } else OutT_PutChar(*str); str++; } }
int CConsole::ParseArgs(CResult *pResult, const char *pFormat) { char Command = *pFormat; char *pStr; int Optional = 0; int Error = 0; pStr = pResult->m_pArgsStart; while(1) { if(!Command) break; if(Command == '?') Optional = 1; else { pStr = str_skip_whitespaces(pStr); if(!(*pStr)) // error, non optional command needs value { if(!Optional) { Error = 1; break; } while(Command) { Command = NextParam(pFormat); } break; } // add token if(*pStr == '"') { char *pDst; pStr++; pResult->AddArgument(pStr); pDst = pStr; // we might have to process escape data while(1) { if(pStr[0] == '"') break; else if(pStr[0] == '\\') { if(pStr[1] == '\\') pStr++; // skip due to escape else if(pStr[1] == '"') pStr++; // skip due to escape } else if(pStr[0] == 0) return 1; // return error *pDst = *pStr; pDst++; pStr++; } // write null termination *pDst = 0; pStr++; } else { pResult->AddArgument(pStr); if(Command == 'r') // rest of the string break; else if(Command == 'i') // validate int pStr = str_skip_to_whitespace(pStr); else if(Command == 'f') // validate float pStr = str_skip_to_whitespace(pStr); else if(Command == 's') // validate string pStr = str_skip_to_whitespace(pStr); if(pStr[0] != 0) // check for end of string { pStr[0] = 0; pStr++; } } } Command = NextParam(pFormat); } return Error; }