diff --git a/dlls/client.cpp b/dlls/client.cpp index 82b8e7e762..823867c226 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -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 optional: . 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 ); @@ -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 ) @@ -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 ) ) ); } } } @@ -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 @@ -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 ) ) ); @@ -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 } @@ -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 ) ); } } diff --git a/dlls/game.cpp b/dlls/game.cpp index eb4ae16b2e..4c401bf733 100644 --- a/dlls/game.cpp +++ b/dlls/game.cpp @@ -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; @@ -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 @@ -501,6 +521,7 @@ void GameDLLInit( void ) CVAR_REGISTER( &mp_chattime ); + CVAR_REGISTER( &mp_disable_longjump ); // REGISTER CVARS FOR SKILL LEVEL STUFF // Agrunt @@ -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" ); diff --git a/dlls/game.h b/dlls/game.h index 3119351aaf..21cf4aa97d 100644 --- a/dlls/game.h +++ b/dlls/game.h @@ -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; diff --git a/dlls/gamerules.cpp b/dlls/gamerules.cpp index bfbbf59ec7..79221ca631 100644 --- a/dlls/gamerules.cpp +++ b/dlls/gamerules.cpp @@ -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 @@ -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 \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 \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" ); + } + +} \ No newline at end of file diff --git a/dlls/gamerules.h b/dlls/gamerules.h index 781ef447fc..6f999a3092 100644 --- a/dlls/gamerules.h +++ b/dlls/gamerules.h @@ -165,6 +165,8 @@ class CGameRules }; extern CGameRules *InstallGameRules( void ); +extern void SV_PromotePlayer_f ( void ); +extern void SV_DemotePlayer_f ( void ); //========================================================= diff --git a/dlls/items.cpp b/dlls/items.cpp index 08a13711b4..3c86099678 100644 --- a/dlls/items.cpp +++ b/dlls/items.cpp @@ -30,6 +30,7 @@ #include "gamerules.h" extern int gmsgItemPickup; +extern cvar_t mp_disable_longjump; class CWorldItem : public CBaseEntity { @@ -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; } diff --git a/dlls/multiplay_gamerules.cpp b/dlls/multiplay_gamerules.cpp index da199271d4..f77610836a 100644 --- a/dlls/multiplay_gamerules.cpp +++ b/dlls/multiplay_gamerules.cpp @@ -140,47 +140,47 @@ void CHalfLifeMultiplay::RefreshSkillData( void ) // override some values for multiplay. // suitcharger - gSkillData.suitchargerCapacity = 30; + gSkillData.suitchargerCapacity = CVAR_GET_FLOAT( "sk_mp_suitcharger" ); // Crowbar whack - gSkillData.plrDmgCrowbar = 25; + gSkillData.plrDmgCrowbar = CVAR_GET_FLOAT( "sk_mp_plr_crowbar" ); // Glock Round - gSkillData.plrDmg9MM = 12; + gSkillData.plrDmg9MM = CVAR_GET_FLOAT( "sk_mp_plr_9mm_bullet" ); // 357 Round - gSkillData.plrDmg357 = 40; + gSkillData.plrDmg357 = CVAR_GET_FLOAT( "sk_mp_plr_357_bullet" ); // MP5 Round - gSkillData.plrDmgMP5 = 12; + gSkillData.plrDmgMP5 = CVAR_GET_FLOAT( "sk_mp_plr_9mmAR_bullet" ); // M203 grenade - gSkillData.plrDmgM203Grenade = 100; + gSkillData.plrDmgM203Grenade = CVAR_GET_FLOAT( "sk_mp_plr_9mmAR_grenade" ); // Shotgun buckshot - gSkillData.plrDmgBuckshot = 20;// fewer pellets in deathmatch + gSkillData.plrDmgBuckshot = CVAR_GET_FLOAT( "sk_mp_plr_buckshot" ); // Crossbow - gSkillData.plrDmgCrossbowClient = 20; + gSkillData.plrDmgCrossbowClient = CVAR_GET_FLOAT( "sk_mp_plr_xbow_bolt_client" ); // RPG - gSkillData.plrDmgRPG = 120; + gSkillData.plrDmgRPG = CVAR_GET_FLOAT( "sk_mp_plr_rpg" ); // Egon - gSkillData.plrDmgEgonWide = 20; - gSkillData.plrDmgEgonNarrow = 10; + gSkillData.plrDmgEgonWide = CVAR_GET_FLOAT( "sk_mp_plr_egon_wide" ); + gSkillData.plrDmgEgonNarrow = CVAR_GET_FLOAT( "sk_mp_plr_egon_narrow" ); // Hand Grendade - gSkillData.plrDmgHandGrenade = 100; + gSkillData.plrDmgHandGrenade = CVAR_GET_FLOAT( "sk_mp_plr_hand_grenade" ); // Satchel Charge - gSkillData.plrDmgSatchel = 120; + gSkillData.plrDmgSatchel = CVAR_GET_FLOAT( "sk_mp_plr_satchel" ); // Tripmine - gSkillData.plrDmgTripmine = 150; + gSkillData.plrDmgTripmine = CVAR_GET_FLOAT( "sk_mp_plr_tripmine" ); // hornet - gSkillData.plrDmgHornet = 10; + gSkillData.plrDmgHornet = CVAR_GET_FLOAT( "sk_mp_plr_hornet" ); } // longest the intermission can last, in seconds diff --git a/dlls/player.cpp b/dlls/player.cpp index cce57d02e3..e66e4a43b7 100644 --- a/dlls/player.cpp +++ b/dlls/player.cpp @@ -3270,6 +3270,12 @@ void CBasePlayer::GiveNamedItem( const char *pszName ) DispatchTouch( pent, ENT( pev ) ); } +void CBasePlayer::CreateNamedItem ( const char *pEntName, int units_ahead ) +{ + UTIL_MakeVectors( Vector( 0, pev->v_angle.y, 0 ) ); + Create( pEntName, pev->origin + gpGlobals->v_forward * units_ahead, pev->v_angle ); +} + CBaseEntity *FindEntityForward( CBaseEntity *pMe ) { TraceResult tr; @@ -3434,12 +3440,13 @@ void CBasePlayer::ImpulseCommands() void CBasePlayer::CheatImpulseCommands( int iImpulse ) { #if !HLDEMO_BUILD - if( g_enable_cheats->value == 0 ) + if( g_enable_cheats->value == 0 && m_privilege_elevated == FALSE ) { return; } CBaseEntity *pEntity; + TraceResult tr; switch( iImpulse ) diff --git a/dlls/player.h b/dlls/player.h index d2f5d94587..0e3c087ea2 100644 --- a/dlls/player.h +++ b/dlls/player.h @@ -273,6 +273,7 @@ class CBasePlayer : public CBaseMonster void ItemPreFrame( void ); void ItemPostFrame( void ); void GiveNamedItem( const char *szName ); + void CreateNamedItem( const char *szName , int units_ahead ); void EnableControl(BOOL fControl); int GiveAmmo( int iAmount, const char *szName, int iMax ); @@ -330,6 +331,8 @@ class CBasePlayer : public CBaseMonster Vector m_vecLastViewAngles; bool m_bSentBhopcap; // If false, the player just joined and needs a bhopcap message. + + BOOL m_privilege_elevated = false; // When set to true, the player can use cheats when sv_cheats is 2+. }; #define AUTOAIM_2DEGREES 0.0348994967025 diff --git a/dlls/util.cpp b/dlls/util.cpp index a7ab3ca4db..169516ccc0 100644 --- a/dlls/util.cpp +++ b/dlls/util.cpp @@ -579,6 +579,27 @@ CBaseEntity *UTIL_PlayerByIndex( int playerIndex ) return pPlayer; } +CBasePlayer* UTIL_FindPlayerByName (const char *p_search_name) +{ + for(int i=1; i<= gpGlobals->maxClients; i++) + { + edict_t *pEdict = g_engfuncs.pfnPEntityOfEntIndex(i); + if(pEdict) + { + CBaseEntity *pEnt = CBaseEntity::Instance( pEdict ); + if(pEnt && pEnt->IsPlayer()) + { + const char *p_net_name = STRING(pEnt->pev->netname); + if( strcmp(p_net_name, p_search_name) == 0 ) + { + return (CBasePlayer*)pEnt; + } + } + } + } + return NULL; +} + void UTIL_MakeVectors( const Vector &vecAngles ) { MAKE_VECTORS( vecAngles ); diff --git a/dlls/util.h b/dlls/util.h index 6e3b2cca1b..5a80bb89c1 100644 --- a/dlls/util.h +++ b/dlls/util.h @@ -223,6 +223,7 @@ inline BOOL FClassnameIs(entvars_t* pev, const char* szClassname) } class CBaseEntity; +class CBasePlayer; // Misc. Prototypes extern void UTIL_SetSize (entvars_t* pev, const Vector &vecMin, const Vector &vecMax); @@ -241,6 +242,7 @@ extern CBaseEntity *UTIL_FindEntityGeneric(const char *szName, Vector &vecSrc, f // otherwise returns NULL // Index is 1 based extern CBaseEntity *UTIL_PlayerByIndex( int playerIndex ); +extern CBasePlayer *UTIL_FindPlayerByName ( const char *p_search_name ); #define UTIL_EntitiesInPVS(pent) (*g_engfuncs.pfnEntitiesInPVS)(pent) extern void UTIL_MakeVectors (const Vector &vecAngles);