diff --git a/cl_dll/hud.cpp b/cl_dll/hud.cpp index a1d60508..8b8046d8 100644 --- a/cl_dll/hud.cpp +++ b/cl_dll/hud.cpp @@ -100,6 +100,23 @@ void __CmdFunc_ToggleServerBrowser( void ) { } +int __MsgFunc_PlayMP3( const char *pszName, int iSize, void *pbuf ) +{ + char cmd[64]; + + BEGIN_READ( pbuf, iSize ); + + sprintf( cmd, "sound/mp3/%s", READ_STRING() ); + gEngfuncs.pfnPrimeMusicStream( cmd, 1 ); + + return 1; +} + +void __CmdFunc_StopMP3( void ) +{ + gEngfuncs.pfnPrimeMusicStream( 0, 0 ); +} + // TFFree Command Menu Message Handlers int __MsgFunc_ValClass( const char *pszName, int iSize, void *pbuf ) { @@ -183,6 +200,9 @@ void CHud::Init( void ) // VGUI Menus HOOK_MESSAGE( VGUIMenu ); + HOOK_MESSAGE( PlayMP3 ); + HOOK_COMMAND( "stopmp3", StopMP3 ); + CVAR_CREATE( "hud_classautokill", "1", FCVAR_ARCHIVE | FCVAR_USERINFO ); // controls whether or not to suicide immediately on TF class switch CVAR_CREATE( "hud_takesshots", "0", FCVAR_ARCHIVE ); // controls whether or not to automatically take screenshots at the end of a round hud_textmode = CVAR_CREATE ( "hud_textmode", "0", FCVAR_ARCHIVE ); diff --git a/dlls/TheGate/command.cpp b/dlls/TheGate/command.cpp index d7761729..c30d6474 100644 --- a/dlls/TheGate/command.cpp +++ b/dlls/TheGate/command.cpp @@ -23,16 +23,13 @@ class CTriggerCommand : public CPointEntity { public: - void Spawn(void); - void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value); - -private: - void PlayMP3(CBaseEntity* pClient, const char* song); + void Spawn(); + void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); }; -LINK_ENTITY_TO_CLASS(trigger_command, CTriggerCommand); +LINK_ENTITY_TO_CLASS( trigger_command, CTriggerCommand ) -void CTriggerCommand::Spawn(void) +void CTriggerCommand::Spawn() { pev->solid = SOLID_NOT; pev->movetype = MOVETYPE_NONE; @@ -40,61 +37,18 @@ void CTriggerCommand::Spawn(void) pev->frame = 0; } -void CTriggerCommand::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) +void CTriggerCommand::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) { - if (!pActivator || !pActivator->IsNetClient()) - return; + char cmd[64]; - const char* command = STRING(pev->netname); - - if (!command || !*command) + if( !pActivator || !pActivator->IsPlayer() ) return; - // ALERT(at_console, "%s with command \"%s\"\n", STRING(pev->classname), command); - - char* str = NULL; - - if ((str = (char*)strstr(command, "playmp3")) != NULL) - { - int pchlen = 0; - int extlen = 3; // "mp3" excluding NULL terminator. - int ideallen = 0; - - char* pch = NULL, *lastpch = NULL; - char* song = NULL; - - pch = strtok(str, " ."); - - while (pch) - { - pchlen = strlen(pch); - ideallen = (pchlen <= extlen) ? pchlen : extlen; - - if (strncmp(pch, "mp3", sizeof(char) * ideallen) == 0) - { - pch = NULL; - } - else - { - lastpch = pch; - pch = strtok(NULL, " ."); - } - } - - song = lastpch; - - PlayMP3(pActivator, song); - } - - UTIL_Remove(this); -} - -void CTriggerCommand::PlayMP3(CBaseEntity* pClient, const char* song) -{ - ASSERT(pClient != NULL); + if( !pev->netname ) + return; - char cmd[128]; - sprintf(cmd, "play sound/mp3/%s.mp3\n", song); + sprintf( cmd, "%s\n", STRING( pev->netname ) ); + CLIENT_COMMAND( ENT( pActivator->pev ), cmd ); - CLIENT_COMMAND(ENT(pClient->pev),cmd); + UTIL_Remove( this ); } diff --git a/dlls/client.cpp b/dlls/client.cpp index 578534e3..d5d13a85 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -49,6 +49,7 @@ extern void CopyToBodyQue( entvars_t* pev ); extern int giPrecacheGrunt; extern int gmsgSayText; extern int gmsgBhopcap; +extern int gmsgPlayMP3; extern cvar_t allow_spectators; @@ -487,6 +488,12 @@ void ClientCommand( edict_t *pEntity ) { GetClassPtr( (CBasePlayer *)pev )->ForceClientDllUpdate(); } + else if( FStrEq(pcmd, "playmp3" ) ) + { + MESSAGE_BEGIN( MSG_ONE, gmsgPlayMP3, NULL, ENT( pev ) ); + WRITE_STRING( (char *)CMD_ARGV( 1 ) ); + MESSAGE_END(); + } else if( FStrEq(pcmd, "give" ) ) { if( g_flWeaponCheat != 0.0 ) diff --git a/dlls/player.cpp b/dlls/player.cpp index 0c4fd3f2..b2530694 100644 --- a/dlls/player.cpp +++ b/dlls/player.cpp @@ -190,6 +190,7 @@ int gmsgStatusText = 0; int gmsgStatusValue = 0; int gmsgScope = 0; +int gmsgPlayMP3 = 0; void LinkUserMessages( void ) { @@ -233,12 +234,12 @@ void LinkUserMessages( void ) gmsgFade = REG_USER_MSG( "ScreenFade", sizeof(ScreenFade) ); gmsgAmmoX = REG_USER_MSG( "AmmoX", 2 ); gmsgTeamNames = REG_USER_MSG( "TeamNames", -1 ); + gmsgPlayMP3 = REG_USER_MSG( "PlayMP3", -1 ); + gmsgScope = REG_USER_MSG( "Scope", 1 ); gmsgBhopcap = REG_USER_MSG( "Bhopcap", 1 ); gmsgStatusText = REG_USER_MSG( "StatusText", -1 ); gmsgStatusValue = REG_USER_MSG( "StatusValue", 3 ); - - gmsgScope = REG_USER_MSG( "Scope", 1 ); } LINK_ENTITY_TO_CLASS( player, CBasePlayer )