An optional array parameter (LIKE TEH TASKS ONE) can be now passed to cvar query handlers

This commit is contained in:
Pavol Marko 2005-09-06 10:12:02 +00:00
parent 2f27b7da8d
commit 6bebf37f1a
4 changed files with 133 additions and 83 deletions

View File

@ -48,7 +48,7 @@ void CPlayer::Init( edict_t* e , int i )
aiming = 0; aiming = 0;
menu = 0; menu = 0;
keys = 0; keys = 0;
death_weapon.clear(); death_weapon.clear();
name.clear(); name.clear();
ip.clear(); ip.clear();
@ -56,43 +56,45 @@ void CPlayer::Init( edict_t* e , int i )
} }
void CPlayer::Disconnect() { void CPlayer::Disconnect() {
ingame = false; ingame = false;
initialized = false; initialized = false;
authorized = false; authorized = false;
while (!cvarQueryQueue.empty()) while (!cvarQueryQueue.empty())
{ {
ClientCvarQuery_Info *pQuery = cvarQueryQueue.front(); ClientCvarQuery_Info *pQuery = cvarQueryQueue.front();
unregisterSPForward(pQuery->resultFwd); unregisterSPForward(pQuery->resultFwd);
delete pQuery; if (pQuery->params)
cvarQueryQueue.pop(); delete [] pQuery->params;
} delete pQuery;
cvarQueryQueue.pop();
}
bot = 0; bot = 0;
} }
void CPlayer::PutInServer() { void CPlayer::PutInServer() {
playtime = gpGlobals->time; playtime = gpGlobals->time;
ingame = true; ingame = true;
} }
bool CPlayer::Connect(const char* connectname,const char* ipaddress) { bool CPlayer::Connect(const char* connectname,const char* ipaddress) {
name.assign(connectname); name.assign(connectname);
ip.assign(ipaddress); ip.assign(ipaddress);
time = gpGlobals->time; time = gpGlobals->time;
bot = IsBot(); bot = IsBot();
death_killer = 0; death_killer = 0;
memset(flags,0,sizeof(flags)); memset(flags,0,sizeof(flags));
memset(weapons,0,sizeof(weapons)); memset(weapons,0,sizeof(weapons));
initialized = true; initialized = true;
authorized = false; authorized = false;
const char* authid = GETPLAYERAUTHID( pEdict ); const char* authid = GETPLAYERAUTHID( pEdict );
if ( (authid == 0) || (*authid == 0) if ( (authid == 0) || (*authid == 0)
|| (strcmp( authid , "STEAM_ID_PENDING") == 0) ) || (strcmp( authid , "STEAM_ID_PENDING") == 0) )
return true; return true;
return false; return false;
} }
@ -102,48 +104,48 @@ bool CPlayer::Connect(const char* connectname,const char* ipaddress) {
// ***************************************************** // *****************************************************
void Grenades::put( edict_t* grenade, float time, int type, CPlayer* player ) void Grenades::put( edict_t* grenade, float time, int type, CPlayer* player )
{ {
Obj* a = new Obj; Obj* a = new Obj;
if ( a == 0 ) return; if ( a == 0 ) return;
a->player = player; a->player = player;
a->grenade = grenade; a->grenade = grenade;
a->time = gpGlobals->time + time; a->time = gpGlobals->time + time;
a->type = type; a->type = type;
a->next = head; a->next = head;
head = a; head = a;
} }
bool Grenades::find( edict_t* enemy, CPlayer** p, int& type ) bool Grenades::find( edict_t* enemy, CPlayer** p, int& type )
{ {
bool found = false; bool found = false;
Obj** a = &head; Obj** a = &head;
while ( *a ){ while ( *a ){
if ( (*a)->time > gpGlobals->time ) { if ( (*a)->time > gpGlobals->time ) {
if ( (*a)->grenade == enemy ) { if ( (*a)->grenade == enemy ) {
found = true; found = true;
(*p) = (*a)->player; (*p) = (*a)->player;
type = (*a)->type; type = (*a)->type;
} }
} }
else { else {
Obj* b = (*a)->next; Obj* b = (*a)->next;
delete *a; delete *a;
*a = b; *a = b;
continue; continue;
} }
a = &(*a)->next; a = &(*a)->next;
} }
return found; return found;
} }
void Grenades::clear() void Grenades::clear()
{ {
while(head){ while(head){
Obj* a = head->next; Obj* a = head->next;
delete head; delete head;
head = a; head = a;
} }
} }
// ***************************************************** // *****************************************************
@ -158,17 +160,17 @@ void XVars::clear() {
int XVars::put( AMX* p, cell* v ) int XVars::put( AMX* p, cell* v )
{ {
for(int a = 0; a < num; ++a) { for(int a = 0; a < num; ++a) {
if ( (head[a].amx == p) && (head[a].value == v) ) if ( (head[a].amx == p) && (head[a].value == v) )
return a; return a;
} }
if ( (num >= size) && realloc_array( size ? (size * 2) : 8 ) ) if ( (num >= size) && realloc_array( size ? (size * 2) : 8 ) )
return -1; return -1;
head[num].value = v; head[num].value = v;
head[num].amx = p; head[num].amx = p;
return num++; return num++;
} }
int XVars::realloc_array( int nsize ) int XVars::realloc_array( int nsize )
@ -190,17 +192,17 @@ int XVars::realloc_array( int nsize )
// ***************************************************** // *****************************************************
TeamIds::TeamIds() { head = 0; newTeam = 0; } TeamIds::TeamIds() { head = 0; newTeam = 0; }
TeamIds::~TeamIds() { TeamIds::~TeamIds() {
while( head ) { while( head ) {
TeamEle* a = head->next; TeamEle* a = head->next;
delete head; delete head;
head = a; head = a;
} }
} }
void TeamIds::registerTeam( const char* n ,int s ) void TeamIds::registerTeam( const char* n ,int s )
{ {
TeamEle** a = &head; TeamEle** a = &head;
while( *a ){ while( *a ){
if ( strcmp((*a)->name.c_str(),n) == 0 ){ if ( strcmp((*a)->name.c_str(),n) == 0 ){
if (s != -1){ if (s != -1){
(*a)->id = s; (*a)->id = s;
@ -209,31 +211,31 @@ void TeamIds::registerTeam( const char* n ,int s )
return; return;
} }
a = &(*a)->next; a = &(*a)->next;
} }
*a = new TeamEle( n , s ); *a = new TeamEle( n , s );
if ( *a == 0 ) return; if ( *a == 0 ) return;
newTeam |= (1<<(*a)->tid); newTeam |= (1<<(*a)->tid);
} }
int TeamIds::findTeamId( const char* n ) int TeamIds::findTeamId( const char* n )
{ {
TeamEle* a = head; TeamEle* a = head;
while( a ){ while( a ){
if ( !stricmp(a->name.c_str(),n) ) if ( !stricmp(a->name.c_str(),n) )
return a->id; return a->id;
a = a->next; a = a->next;
} }
return -1; return -1;
} }
int TeamIds::findTeamIdCase( const char* n) int TeamIds::findTeamIdCase( const char* n)
{ {
TeamEle* a = head; TeamEle* a = head;
while( a ){ while( a ){
if ( !strcmp(a->name.c_str(), n) ) if ( !strcmp(a->name.c_str(), n) )
return a->id; return a->id;
a = a->next; a = a->next;
} }
return -1; return -1;
} }

View File

@ -67,6 +67,9 @@ struct ClientCvarQuery_Info
bool querying; // Are we actually waiting for a response at the moment? bool querying; // Are we actually waiting for a response at the moment?
String cvarName; String cvarName;
int resultFwd; int resultFwd;
int paramLen;
cell *params;
}; };
class CPlayer class CPlayer

View File

@ -2928,6 +2928,13 @@ static cell AMX_NATIVE_CALL int3(AMX *amx, cell *params)
// native query_client_cvar(id, const cvar[], const resultfunc[]) // native query_client_cvar(id, const cvar[], const resultfunc[])
static cell AMX_NATIVE_CALL query_client_cvar(AMX *amx, cell *params) static cell AMX_NATIVE_CALL query_client_cvar(AMX *amx, cell *params)
{ {
int numParams = params[0] / sizeof(cell);
if (numParams != 3 && numParams != 5)
{
LogError(amx, AMX_ERR_NATIVE, "Invalid number of parameters passed!");
return 0;
}
if (!g_NewDLL_Available) if (!g_NewDLL_Available)
{ {
LogError(amx, AMX_ERR_NATIVE, "NewDLL functions are not available. Blame (your) metamod (version)"); LogError(amx, AMX_ERR_NATIVE, "NewDLL functions are not available. Blame (your) metamod (version)");
@ -2953,8 +2960,13 @@ static cell AMX_NATIVE_CALL query_client_cvar(AMX *amx, cell *params)
const char *cvarname = get_amxstring(amx, params[2], 0, dummy); const char *cvarname = get_amxstring(amx, params[2], 0, dummy);
const char *resultfuncname = get_amxstring(amx, params[3], 1, dummy); const char *resultfuncname = get_amxstring(amx, params[3], 1, dummy);
// public clientcvarquery_result(id, const cvar[], const result[]) // public clientcvarquery_result(id, const cvar[], const result[], [const param[]])
int iFunc = registerSPForwardByName(amx, resultfuncname, FP_CELL, FP_STRING, FP_STRING, FP_DONE); int iFunc;
if (numParams == 5 && params[4] != 0)
iFunc = registerSPForwardByName(amx, resultfuncname, FP_CELL, FP_STRING, FP_STRING, FP_ARRAY, FP_DONE);
else
iFunc = registerSPForwardByName(amx, resultfuncname, FP_CELL, FP_STRING, FP_STRING, FP_DONE);
if (iFunc == -1) if (iFunc == -1)
{ {
LogError(amx, AMX_ERR_NATIVE, "Function \"%s\" is not present", resultfuncname); LogError(amx, AMX_ERR_NATIVE, "Function \"%s\" is not present", resultfuncname);
@ -2966,6 +2978,29 @@ static cell AMX_NATIVE_CALL query_client_cvar(AMX *amx, cell *params)
queryObject->cvarName.assign(cvarname); queryObject->cvarName.assign(cvarname);
queryObject->resultFwd = iFunc; queryObject->resultFwd = iFunc;
if (numParams == 5 && params[4] != 0)
{
queryObject->paramLen = params[4] + 1;
queryObject->params = new cell[ queryObject->paramLen ];
if (!queryObject->params)
{
delete queryObject;
unregisterSPForward(iFunc);
LogError(amx, AMX_ERR_MEMORY, "Hmm. Out of memory?");
return 0;
}
memcpy(reinterpret_cast<void*>(queryObject->params),
reinterpret_cast<const void *>(get_amxaddr(amx, params[5])),
queryObject->paramLen * sizeof(cell));
queryObject->params[queryObject->paramLen - 1] = 0;
}
else
{
queryObject->params = NULL;
queryObject->paramLen = 0;
}
pPlayer->cvarQueryQueue.push(queryObject); pPlayer->cvarQueryQueue.push(queryObject);
return 1; return 1;

View File

@ -1031,8 +1031,18 @@ void C_CvarValue(const edict_t *pEdict, const char *value)
if (pPlayer->cvarQueryQueue.front()->querying) if (pPlayer->cvarQueryQueue.front()->querying)
{ {
executeForwards(pQuery->resultFwd, ENTINDEX(pEdict), pQuery->cvarName.c_str(), value); if (pQuery->paramLen)
{
cell arr = prepareCellArray(pQuery->params, pQuery->paramLen);
executeForwards(pQuery->resultFwd, ENTINDEX(pEdict), pQuery->cvarName.c_str(), value, arr);
}
else
executeForwards(pQuery->resultFwd, ENTINDEX(pEdict), pQuery->cvarName.c_str(), value);
unregisterSPForward(pQuery->resultFwd); unregisterSPForward(pQuery->resultFwd);
if (pQuery->params)
delete [] pQuery->params;
delete pQuery; delete pQuery;
pPlayer->cvarQueryQueue.pop(); pPlayer->cvarQueryQueue.pop();
RETURN_META(MRES_HANDLED); RETURN_META(MRES_HANDLED);