2016-07-26 15:18:32 +03:00
|
|
|
// vi: set ts=4 sw=4 :
|
|
|
|
// vim: set tw=75 :
|
|
|
|
|
|
|
|
// mplayer.cpp - methods of individual player (class MPlayer) and
|
|
|
|
// list of players (class MPlayerList).
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2005 Will Day <willday@hpgx.net>
|
|
|
|
*
|
|
|
|
* This file is part of Metamod.
|
|
|
|
*
|
|
|
|
* Metamod is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* Metamod is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Metamod; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the author gives permission to
|
|
|
|
* link the code of this program with the Half-Life Game g_engine ("HL
|
|
|
|
* g_engine") and Modified Game Libraries ("MODs") developed by Valve,
|
|
|
|
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
|
|
|
* respects for all of the code used other than the HL g_engine and MODs
|
|
|
|
* from Valve. If you modify this file, you may extend this exception
|
|
|
|
* to your version of the file, but you are not obligated to do so. If
|
|
|
|
* you do not wish to do so, delete this exception statement from your
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-07-26 03:22:47 +03:00
|
|
|
#include "precompiled.h"
|
2016-07-04 09:07:29 +03:00
|
|
|
|
|
|
|
// Constructor
|
2016-07-26 15:18:32 +03:00
|
|
|
MPlayer::MPlayer() : isQueried(mFALSE)
|
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 15:18:32 +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 15:18:32 +03:00
|
|
|
if (!cvar) {
|
2016-07-04 09:07:29 +03:00
|
|
|
meta_errno = ME_ARGUMENT;
|
|
|
|
return;
|
|
|
|
}
|
2016-07-26 15:18:32 +03:00
|
|
|
|
2016-07-04 09:07:29 +03:00
|
|
|
isQueried = mTRUE;
|
2016-07-26 15:18:32 +03:00
|
|
|
strncpy(cvarName, cvar, sizeof cvarName - 1);
|
|
|
|
cvarName[sizeof cvarName - 1] = '\0';
|
2016-07-04 09:07:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 15:18:32 +03:00
|
|
|
cvarName[0] = '\0';
|
2016-07-04 09:07:29 +03:00
|
|
|
}
|
|
|
|
|
2016-07-26 15:18:32 +03:00
|
|
|
|
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 15:18:32 +03:00
|
|
|
const char* MPlayer::is_querying_cvar(void) const
|
2016-07-04 09:07:29 +03:00
|
|
|
{
|
2016-07-26 15:18:32 +03:00
|
|
|
if (isQueried) {
|
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
|
|
|
|
2016-07-26 15:18:32 +03:00
|
|
|
return NULL;
|
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 15:18:32 +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 15:18:32 +03:00
|
|
|
int indx = ENTINDEX(pEntity);
|
2016-07-26 03:22:47 +03:00
|
|
|
|
2016-07-26 15:18:32 +03:00
|
|
|
if (indx >= 1 && indx <= maxplayers)
|
|
|
|
players[indx].set_cvar_query(cvar);
|
2016-07-04 09:07:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unmark player as querying a client cvar
|
2016-07-26 15:18:32 +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 15:18:32 +03:00
|
|
|
int indx = ENTINDEX(pEntity);
|
2016-07-26 03:22:47 +03:00
|
|
|
|
2016-07-26 15:18:32 +03:00
|
|
|
if (indx >= 1 && indx <= maxplayers)
|
|
|
|
players[indx].clear_cvar_query(cvar);
|
2016-07-04 09:07:29 +03:00
|
|
|
}
|
|
|
|
|
2016-07-26 15:18:32 +03:00
|
|
|
void MPlayerList::clear_all_cvar_queries(void)
|
2016-07-04 09:07:29 +03:00
|
|
|
{
|
2016-07-26 15:18:32 +03:00
|
|
|
for (int indx = 1; indx <= maxplayers; indx++) {
|
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 15:18:32 +03:00
|
|
|
const char* MPlayerList::is_querying_cvar(const edict_t* pEntity) const
|
2016-07-04 09:07:29 +03:00
|
|
|
{
|
2016-07-26 15:18:32 +03:00
|
|
|
int indx = ENTINDEX(pEntity);
|
|
|
|
|
|
|
|
if (indx >= 1 && indx <= maxplayers)
|
|
|
|
return players[indx].is_querying_cvar();
|
2016-07-26 03:22:47 +03:00
|
|
|
|
2016-07-26 15:18:32 +03:00
|
|
|
RETURN_ERRNO(NULL, ME_NOTFOUND);
|
2016-07-04 09:07:29 +03:00
|
|
|
}
|