Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server Variable Features #195

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 75 additions & 25 deletions dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,42 +471,95 @@ called each time a player uses a "cmd" command
extern cvar_t *g_enable_cheats;

// Use CMD_ARGV, CMD_ARGV, and CMD_ARGC to get pointers the character string command.
void ClientCommand( edict_t *pEntity )
void ClientCommand( edict_t *pEdict )
{
const char *pcmd = CMD_ARGV( 0 );
const char *pstr;

// Is the client spawned yet?
if( !pEntity->pvPrivateData )
if( !pEdict->pvPrivateData )
return;

entvars_t *pev = &pEntity->v;
entvars_t *pev = &pEdict->v;
CBasePlayer *pPlayer = GetClassPtr( (CBasePlayer *)pev );
const bool p_can_cheat = g_enable_cheats->value == 1 || pPlayer->m_privilege_elevated;

if( FStrEq( pcmd, "say" ) )
{
Host_Say( pEntity, 0 );
Host_Say( pEdict, 0 );
}
else if( FStrEq( pcmd, "say_team" ) )
{
Host_Say( pEntity, 1 );
Host_Say( pEdict, 1 );
}
else if( FStrEq( pcmd, "fullupdate" ) )
{
GetClassPtr( (CBasePlayer *)pev )->ForceClientDllUpdate();
pPlayer->ForceClientDllUpdate();
}
else if( FStrEq(pcmd, "give" ) )
{
if( g_enable_cheats->value != 0 )
if( p_can_cheat )
{
if( CMD_ARGC() == 2 || CMD_ARGC() == 3)
{
int iszItem = ALLOC_STRING( CMD_ARGV( 1 ) );
int units_ahead = 0;
if( CMD_ARGC() == 3 )
units_ahead = atoi( CMD_ARGV ( 2 ) );

if( units_ahead == 0 )
{
pPlayer->GiveNamedItem( STRING( iszItem ) );
return;
} else if (units_ahead > 0)
{
pPlayer->CreateNamedItem( STRING( iszItem ) , units_ahead );
return;
}
}
ClientPrint(&pEdict->v, HUD_PRINTCONSOLE, "Usage: give <entity_name> optional: <units_ahead>. <units_ahead> must be > 0.\n");
}
}
else if( FStrEq( pcmd, "fly" ) )
{
if( pPlayer->m_privilege_elevated == FALSE ) return;

if( pPlayer->pev->movetype != MOVETYPE_NOCLIP )
{
int iszItem = ALLOC_STRING( CMD_ARGV( 1 ) ); // Make a copy of the classname
GetClassPtr( (CBasePlayer *)pev )->GiveNamedItem( STRING( iszItem ) );
ClientPrint(&pEdict->v, HUD_PRINTCONSOLE, "FLY ON.\n");
pPlayer->pev->movetype = MOVETYPE_NOCLIP;
}
else
{
ClientPrint(&pEdict->v, HUD_PRINTCONSOLE, "FLY OFF.\n");
pPlayer->pev->movetype = MOVETYPE_WALK;
}
return;
}
else if( FStrEq( pcmd, "nodamage" ) )
{
if( pPlayer->m_privilege_elevated == FALSE ) return;

pPlayer->pev->flags = pPlayer->pev->flags ^ FL_GODMODE;

if( !FBitSet( pPlayer->pev->flags, FL_GODMODE ) )
ClientPrint(&pEdict->v, HUD_PRINTCONSOLE, "NO DAMAGE OFF.\n");
else ClientPrint(&pEdict->v, HUD_PRINTCONSOLE, "NO DAMAGE ON.\n");
}
else if( FStrEq( pcmd, "noattack" ) )
{
if( pPlayer->m_privilege_elevated == FALSE ) return;
pPlayer->pev->flags = pPlayer->pev->flags ^ FL_NOTARGET;

if( !FBitSet( pPlayer->pev->flags, FL_NOTARGET ) )
ClientPrint(&pEdict->v, HUD_PRINTCONSOLE, "NO ATTACK OFF.\n");
else ClientPrint(&pEdict->v, HUD_PRINTCONSOLE, "NO ATTACK ON.\n");
}
else if( FStrEq( pcmd, "fire" ) )
{
if( g_enable_cheats->value != 0 )
if( p_can_cheat )
{
CBaseEntity *pPlayer = CBaseEntity::Instance( pEntity );
CBaseEntity *pPlayer = CBaseEntity::Instance( pEdict );
if( CMD_ARGC() > 1 )
{
FireTargets( CMD_ARGV( 1 ), pPlayer, pPlayer, USE_TOGGLE, 0 );
Expand All @@ -518,7 +571,7 @@ void ClientCommand( edict_t *pEntity )
UTIL_TraceLine(
pev->origin + pev->view_ofs,
pev->origin + pev->view_ofs + gpGlobals->v_forward * 1000,
dont_ignore_monsters, pEntity, &tr
dont_ignore_monsters, pEdict, &tr
);

if( tr.pHit )
Expand All @@ -527,7 +580,7 @@ void ClientCommand( edict_t *pEntity )
if( pHitEnt )
{
pHitEnt->Use( pPlayer, pPlayer, USE_TOGGLE, 0 );
ClientPrint( &pEntity->v, HUD_PRINTCONSOLE, UTIL_VarArgs( "Fired %s \"%s\"\n", STRING( pHitEnt->pev->classname ), STRING( pHitEnt->pev->targetname ) ) );
ClientPrint( &pEdict->v, HUD_PRINTCONSOLE, UTIL_VarArgs( "Fired %s \"%s\"\n", STRING( pHitEnt->pev->classname ), STRING( pHitEnt->pev->targetname ) ) );
}
}
}
Expand All @@ -536,34 +589,33 @@ void ClientCommand( edict_t *pEntity )
else if( FStrEq( pcmd, "drop" ) )
{
// player is dropping an item.
GetClassPtr( (CBasePlayer *)pev )->DropPlayerItem( (char *)CMD_ARGV( 1 ) );
pPlayer->DropPlayerItem( (char *)CMD_ARGV( 1 ) );
}
else if( FStrEq( pcmd, "fov" ) )
{
if( g_enable_cheats->value != 0 && CMD_ARGC() > 1 )
if( p_can_cheat && CMD_ARGC() > 1 )
{
GetClassPtr( (CBasePlayer *)pev )->m_iFOV = atoi( CMD_ARGV( 1 ) );
pPlayer->m_iFOV = atoi( CMD_ARGV( 1 ) );
}
else
{
CLIENT_PRINTF( pEntity, print_console, UTIL_VarArgs( "\"fov\" is \"%d\"\n", (int)GetClassPtr( (CBasePlayer *)pev )->m_iFOV ) );
CLIENT_PRINTF( pEdict, print_console, UTIL_VarArgs( "\"fov\" is \"%d\"\n", (int)pPlayer->m_iFOV ) );
}
}
else if( FStrEq( pcmd, "use" ) )
{
GetClassPtr( (CBasePlayer *)pev )->SelectItem( (char *)CMD_ARGV( 1 ) );
pPlayer->SelectItem( (char *)CMD_ARGV( 1 ) );
}
else if( ( ( pstr = strstr( pcmd, "weapon_" ) ) != NULL ) && ( pstr == pcmd ) )
{
GetClassPtr( (CBasePlayer *)pev )->SelectItem( pcmd );
pPlayer->SelectItem( pcmd );
}
else if( FStrEq( pcmd, "lastinv" ) )
{
GetClassPtr( (CBasePlayer *)pev )->SelectLastItem();
pPlayer->SelectLastItem();
}
else if( FStrEq( pcmd, "spectate" ) ) // clients wants to become a spectator
{
CBasePlayer *pPlayer = GetClassPtr( (CBasePlayer *)pev );
if( !pPlayer->IsObserver() )
{
// always allow proxies to become a spectator
Expand All @@ -590,7 +642,6 @@ void ClientCommand( edict_t *pEntity )
}
else if( FStrEq( pcmd, "specmode" ) ) // new spectator mode
{
CBasePlayer *pPlayer = GetClassPtr( (CBasePlayer *)pev );

if( pPlayer->IsObserver() )
pPlayer->Observer_SetMode( atoi( CMD_ARGV( 1 ) ) );
Expand All @@ -601,12 +652,11 @@ void ClientCommand( edict_t *pEntity )
}
else if( FStrEq( pcmd, "follownext" ) ) // follow next player
{
CBasePlayer *pPlayer = GetClassPtr( (CBasePlayer *)pev );

if( pPlayer->IsObserver() )
pPlayer->Observer_FindNextPlayer( atoi( CMD_ARGV( 1 ) ) ? true : false );
}
else if( g_pGameRules->ClientCommand( GetClassPtr( (CBasePlayer *)pev ), pcmd ) )
else if( g_pGameRules->ClientCommand( pPlayer, pcmd ) )
{
// MenuSelect returns true only if the command is properly handled, so don't print a warning
}
Expand All @@ -626,7 +676,7 @@ void ClientCommand( edict_t *pEntity )
command[127] = '\0';

// tell the user they entered an unknown command
ClientPrint( &pEntity->v, HUD_PRINTCONSOLE, UTIL_VarArgs( "Unknown command: %s\n", command ) );
ClientPrint( &pEdict->v, HUD_PRINTCONSOLE, UTIL_VarArgs( "Unknown command: %s\n", command ) );
}
}

Expand Down
41 changes: 41 additions & 0 deletions dlls/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ cvar_t multibyte_only = { "mp_multibyte_only", "0", FCVAR_SERVER };

cvar_t mp_chattime = { "mp_chattime","10", FCVAR_SERVER };

cvar_t mp_disable_longjump = {"mp_disable_longjump", "0", FCVAR_SERVER};

// Engine Cvars
cvar_t *g_psv_gravity = NULL;
cvar_t *g_psv_aim = NULL;
Expand Down Expand Up @@ -452,6 +454,24 @@ cvar_t sk_player_leg1 = { "sk_player_leg1","1" };
cvar_t sk_player_leg2 = { "sk_player_leg2","1" };
cvar_t sk_player_leg3 = { "sk_player_leg3","1" };

// multiplayer override overrides.
// The default values are Valve's original overrides.
cvar_t sk_mp_suitcharger = {"sk_mp_suitcharger","30"};
cvar_t sk_mp_plr_crowbar = {"sk_mp_plr_crowbar","25"};
cvar_t sk_mp_plr_9mm_bullet = {"sk_mp_plr_9mm_bullet","12"};
cvar_t sk_mp_plr_357_bullet = {"sk_mp_plr_357_bullet","40"};
cvar_t sk_mp_plr_9mmAR_bullet = {"sk_mp_plr_9mmAR_bullet","12"};
cvar_t sk_mp_plr_9mmAR_grenade = {"sk_mp_plr_9mmAR_grenade","100"};
cvar_t sk_mp_plr_buckshot = {"sk_mp_plr_buckshot","20"}; // fewer pellets in deathmatch
cvar_t sk_mp_plr_xbow_bolt_client = {"sk_mp_plr_xbow_bolt_client","20"};
cvar_t sk_mp_plr_rpg = {"sk_mp_plr_rpg","120"};
cvar_t sk_mp_plr_egon_wide = {"sk_mp_plr_egon_wide","20"};
cvar_t sk_mp_plr_egon_narrow = {"sk_mp_plr_egon_narrow","10"};
cvar_t sk_mp_plr_hand_grenade = {"sk_mp_plr_hand_grenade","100"};
cvar_t sk_mp_plr_satchel = {"sk_mp_plr_satchel","120"};
cvar_t sk_mp_plr_tripmine = {"sk_mp_plr_tripmine","150"};
cvar_t sk_mp_plr_hornet = {"sk_mp_plr_hornet","10"};

// END Cvars for Skill Level settings

// Register your console variables here
Expand Down Expand Up @@ -501,6 +521,7 @@ void GameDLLInit( void )
CVAR_REGISTER( &mp_chattime );


CVAR_REGISTER( &mp_disable_longjump );

// REGISTER CVARS FOR SKILL LEVEL STUFF
// Agrunt
Expand Down Expand Up @@ -875,6 +896,26 @@ void GameDLLInit( void )
CVAR_REGISTER( &sk_player_leg1 );
CVAR_REGISTER( &sk_player_leg2 );
CVAR_REGISTER( &sk_player_leg3 );


// multiplayer override overrides

CVAR_REGISTER( &sk_mp_suitcharger );
CVAR_REGISTER( &sk_mp_plr_crowbar );
CVAR_REGISTER( &sk_mp_plr_9mm_bullet );
CVAR_REGISTER( &sk_mp_plr_357_bullet );
CVAR_REGISTER( &sk_mp_plr_9mmAR_bullet );
CVAR_REGISTER( &sk_mp_plr_9mmAR_grenade );
CVAR_REGISTER( &sk_mp_plr_buckshot );
CVAR_REGISTER( &sk_mp_plr_xbow_bolt_client );
CVAR_REGISTER( &sk_mp_plr_rpg );
CVAR_REGISTER( &sk_mp_plr_egon_wide );
CVAR_REGISTER( &sk_mp_plr_egon_narrow );
CVAR_REGISTER( &sk_mp_plr_hand_grenade );
CVAR_REGISTER( &sk_mp_plr_satchel );
CVAR_REGISTER( &sk_mp_plr_tripmine );
CVAR_REGISTER( &sk_mp_plr_hornet );

// END REGISTER CVARS FOR SKILL LEVEL STUFF

SERVER_COMMAND( "exec skill.cfg\n" );
Expand Down
1 change: 1 addition & 0 deletions dlls/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extern cvar_t chargerfix;
extern cvar_t satchelfix;
extern cvar_t monsteryawspeedfix;
extern cvar_t forcerespawn;
extern cvar_t mp_disable_longjump;
extern cvar_t flashlight;
extern cvar_t aimcrosshair;
extern cvar_t decalfrequency;
Expand Down
66 changes: 66 additions & 0 deletions dlls/gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ CGameRules *InstallGameRules( void )
}
else
{
// Add new Deathmatch Commands
g_engfuncs.pfnAddServerCommand( "promote", SV_PromotePlayer_f );
g_engfuncs.pfnAddServerCommand( "demote", SV_DemotePlayer_f );


if( teamplay.value > 0 )
{
// teamplay
Expand All @@ -345,3 +350,64 @@ CGameRules *InstallGameRules( void )
}
}
}


//=========================================================
// New Server Commands
//=========================================================

void SV_PromotePlayer_f ( void )
{
if( g_engfuncs.pfnCmd_Argc() != 2 )
{
g_engfuncs.pfnServerPrint("Usage: promote <name>\n" );
return;
}

const char* p_user_search = g_engfuncs.pfnCmd_Argv( 1 );

CBasePlayer* p_plyr = UTIL_FindPlayerByName(p_user_search);

if(p_plyr != NULL)
{
UTIL_LogPrintf("Promote: \"%s<%i><%s>\"\n"
, STRING(p_plyr->pev->netname)
, GETPLAYERUSERID( p_plyr->edict() )
, GETPLAYERAUTHID( p_plyr->edict() ));

p_plyr->m_privilege_elevated = TRUE;
}
else
{
g_engfuncs.pfnServerPrint("Player not found!\n" );
}

}

void SV_DemotePlayer_f ( void )
{
if( g_engfuncs.pfnCmd_Argc() != 2 )
{
g_engfuncs.pfnServerPrint("Usage: demote <name>\n" );
return;
}

const char* p_user_search = g_engfuncs.pfnCmd_Argv( 1 );

CBasePlayer* p_plyr = UTIL_FindPlayerByName(p_user_search);

if(p_plyr != NULL)
{
UTIL_LogPrintf("Demote: \"%s<%i><%s>\"\n"
, STRING(p_plyr->pev->netname)
, GETPLAYERUSERID( p_plyr->edict() )
, GETPLAYERAUTHID( p_plyr->edict() ));

p_plyr->m_privilege_elevated = FALSE;
}
else
{
g_engfuncs.pfnServerPrint("Player not found!\n" );
}

}
2 changes: 2 additions & 0 deletions dlls/gamerules.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ class CGameRules
};

extern CGameRules *InstallGameRules( void );
extern void SV_PromotePlayer_f ( void );
extern void SV_DemotePlayer_f ( void );


//=========================================================
Expand Down
3 changes: 2 additions & 1 deletion dlls/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "gamerules.h"

extern int gmsgItemPickup;
extern cvar_t mp_disable_longjump;

class CWorldItem : public CBaseEntity
{
Expand Down Expand Up @@ -312,7 +313,7 @@ class CItemLongJump : public CItem
}
BOOL MyTouch( CBasePlayer *pPlayer )
{
if( pPlayer->m_fLongJump )
if( pPlayer->m_fLongJump || (g_pGameRules->IsMultiplayer() && mp_disable_longjump.value > 0) )
{
return FALSE;
}
Expand Down
Loading