2016-07-26 03:22:47 +03:00
|
|
|
#include "precompiled.h"
|
2016-07-04 09:07:29 +03:00
|
|
|
|
|
|
|
// Constructor
|
|
|
|
MPlayer::MPlayer()
|
|
|
|
: isQueried(mFALSE),
|
2016-07-26 03:22:47 +03:00
|
|
|
cvarName(nullptr)
|
2016-07-04 09:07:29 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
MPlayer::~MPlayer()
|
|
|
|
{
|
2016-07-26 03:22:47 +03:00
|
|
|
if (cvarName) {
|
2016-07-04 09:07:29 +03:00
|
|
|
free(cvarName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy constructor
|
|
|
|
MPlayer::MPlayer(const MPlayer& rhs)
|
|
|
|
: isQueried(rhs.isQueried),
|
2016-07-26 03:22:47 +03:00
|
|
|
cvarName(nullptr)
|
2016-07-04 09:07:29 +03:00
|
|
|
{
|
2016-07-26 03:22:47 +03:00
|
|
|
if (rhs.cvarName) {
|
2016-07-04 09:07:29 +03:00
|
|
|
cvarName = strdup(rhs.cvarName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assignment operator
|
2016-07-26 03:22:47 +03:00
|
|
|
MPlayer& MPlayer::operator=(const MPlayer& rhs)
|
2016-07-04 09:07:29 +03:00
|
|
|
{
|
|
|
|
isQueried = rhs.isQueried;
|
|
|
|
|
2016-07-26 03:22:47 +03:00
|
|
|
if (cvarName) {
|
2016-07-04 09:07:29 +03:00
|
|
|
free(cvarName);
|
|
|
|
}
|
2016-07-26 03:22:47 +03:00
|
|
|
cvarName = nullptr;
|
|
|
|
if (rhs.cvarName) {
|
2016-07-04 09:07:29 +03:00
|
|
|
cvarName = strdup(rhs.cvarName);
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark a player as querying a client cvar and stores the cvar name
|
|
|
|
// meta_errno values:
|
|
|
|
// - ME_ARGUMENT cvar is NULL
|
2016-07-26 03:22:47 +03:00
|
|
|
void MPlayer::set_cvar_query(const char *cvar)
|
2016-07-04 09:07:29 +03:00
|
|
|
{
|
|
|
|
// Do not allow NULL as queried cvar since we use this as
|
|
|
|
// return value in is_querying_cvar as indication if a
|
|
|
|
// client cvar is queried.
|
2016-07-26 03:22:47 +03:00
|
|
|
if (!cvar)
|
2016-07-04 10:11:20 +03:00
|
|
|
{
|
2016-07-04 09:07:29 +03:00
|
|
|
meta_errno = ME_ARGUMENT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isQueried = mTRUE;
|
2016-07-26 03:22:47 +03:00
|
|
|
if (cvarName) {
|
2016-07-04 09:07:29 +03:00
|
|
|
free(cvarName);
|
|
|
|
}
|
|
|
|
cvarName = strdup(cvar);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Unmark player as querying a client cvar
|
2016-07-26 03:22:47 +03:00
|
|
|
void MPlayer::clear_cvar_query(const char* /*cvar*/)
|
2016-07-04 09:07:29 +03:00
|
|
|
{
|
|
|
|
isQueried = mFALSE;
|
2016-07-26 03:22:47 +03:00
|
|
|
if (cvarName)
|
2016-07-04 10:11:20 +03:00
|
|
|
{
|
2016-07-04 09:07:29 +03:00
|
|
|
free(cvarName);
|
2016-07-26 03:22:47 +03:00
|
|
|
cvarName = nullptr;
|
2016-07-04 09:07:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if a client cvar is queried for this player
|
|
|
|
// Returns NULL if not
|
|
|
|
// or the name of the cvar.
|
2016-07-26 03:22:47 +03:00
|
|
|
const char *MPlayer::is_querying_cvar()
|
2016-07-04 09:07:29 +03:00
|
|
|
{
|
2016-07-26 03:22:47 +03:00
|
|
|
if (isQueried)
|
2016-07-04 10:11:20 +03:00
|
|
|
{
|
2016-07-26 03:22:47 +03:00
|
|
|
return cvarName;
|
2016-07-04 09:07:29 +03:00
|
|
|
}
|
2016-07-26 03:22:47 +03:00
|
|
|
|
|
|
|
return nullptr;
|
2016-07-04 09:07:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mark a player as querying a client cvar and stores the cvar name
|
|
|
|
// meta_errno values:
|
|
|
|
// - ME_ARGUMENT cvar is NULL
|
2016-07-26 03:22:47 +03:00
|
|
|
void MPlayerList::set_player_cvar_query(const edict_t *pEntity, const char *cvar)
|
2016-07-04 09:07:29 +03:00
|
|
|
{
|
2016-07-26 03:22:47 +03:00
|
|
|
int indx = ENTINDEX(const_cast<edict_t *>(pEntity));
|
|
|
|
if (indx < 1 || indx > gpGlobals->maxClients)
|
2016-07-04 09:07:29 +03:00
|
|
|
return; //maybe output a message?
|
2016-07-26 03:22:47 +03:00
|
|
|
|
2016-07-04 09:07:29 +03:00
|
|
|
players[indx].set_cvar_query(cvar);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmark player as querying a client cvar
|
2016-07-26 03:22:47 +03:00
|
|
|
void MPlayerList::clear_player_cvar_query(const edict_t *pEntity, const char *cvar)
|
2016-07-04 09:07:29 +03:00
|
|
|
{
|
2016-07-26 03:22:47 +03:00
|
|
|
int indx = ENTINDEX(const_cast<edict_t *>(pEntity));
|
|
|
|
if (indx < 1 || indx > gpGlobals->maxClients)
|
2016-07-04 09:07:29 +03:00
|
|
|
return; //maybe output a message?
|
2016-07-26 03:22:47 +03:00
|
|
|
|
2016-07-04 09:07:29 +03:00
|
|
|
players[indx].clear_cvar_query(cvar);
|
|
|
|
}
|
|
|
|
|
2016-07-26 03:22:47 +03:00
|
|
|
void MPlayerList::clear_all_cvar_queries()
|
2016-07-04 09:07:29 +03:00
|
|
|
{
|
2016-07-26 03:22:47 +03:00
|
|
|
for (int indx = 1; indx < gpGlobals->maxClients; ++indx)
|
2016-07-04 10:11:20 +03:00
|
|
|
{
|
2016-07-04 09:07:29 +03:00
|
|
|
players[indx].clear_cvar_query();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if a client cvar is queried for this player
|
|
|
|
// Returns NULL if not
|
|
|
|
// or the name of the cvar.
|
|
|
|
// meta_errno values:
|
|
|
|
// - ME_NOTFOUND invalid entity
|
2016-07-26 03:22:47 +03:00
|
|
|
const char *MPlayerList::is_querying_cvar(const edict_t *pEntity)
|
2016-07-04 09:07:29 +03:00
|
|
|
{
|
2016-07-26 03:22:47 +03:00
|
|
|
int indx = ENTINDEX(const_cast<edict_t *>(pEntity));
|
|
|
|
if (indx < 1 || indx > gpGlobals->maxClients)
|
2016-07-04 10:11:20 +03:00
|
|
|
{
|
2016-07-26 03:22:47 +03:00
|
|
|
RETURN_ERRNO(nullptr, ME_NOTFOUND);
|
2016-07-04 09:07:29 +03:00
|
|
|
}
|
2016-07-26 03:22:47 +03:00
|
|
|
|
|
|
|
return players[indx].is_querying_cvar();
|
2016-07-04 09:07:29 +03:00
|
|
|
}
|