diff --git a/src/d_netcmd.c b/src/d_netcmd.c index b9d0386b1..f11959ebc 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -270,6 +270,10 @@ static void Command_Schedule_List(void); static void Command_Automate_Set(void); +static void Command_PlaySound(void); + +static void Got_PlaySound(UINT8 **cp, INT32 playernum); + // ========================================================================= // CLIENT VARIABLES // ========================================================================= @@ -1112,6 +1116,9 @@ void D_RegisterServerCommands(void) #endif CV_RegisterVar(&cv_debugmappatch); + + COM_AddCommand("playsound", Command_PlaySound); + RegisterNetXCmd(XD_PLAYSOUND, Got_PlaySound); } // ========================================================================= @@ -6582,6 +6589,27 @@ static void Got_Cheat(UINT8 **cp, INT32 playernum) } } +static void Got_PlaySound(UINT8 **cp, INT32 playernum) +{ + INT32 sound_id = READINT32(*cp); + + if (playernum != serverplayer && !IsPlayerAdmin(playernum)) // hacked client, or disasterous bug + { + CONS_Alert(CONS_WARNING, M_GetText("Illegal playsound received from %s (serverplayer is %s)\n"), player_names[playernum], player_names[serverplayer]); + if (server) + SendKick(playernum, KICK_MSG_CON_FAIL); + return; + } + + if (sound_id < 0 || sound_id >= NUMSFX) + { + // bad sound effect, ignore + return; + } + + S_StartSound(NULL, sound_id); +} + static const char *displayplayer_compose_col(int playernum) { return va("\x84(%d) \x83%s\x80", playernum, player_names[playernum]); @@ -7020,6 +7048,50 @@ static void Command_Automate_Set(void) SendNetXCmd(XD_AUTOMATE, buf, buf_p - buf); } +static void Command_PlaySound(void) +{ + const char *sound; + const size_t argc = COM_Argc(); + sfxenum_t sfx = NUMSFX; + UINT8 buf[4]; + UINT8 *buf_p = buf; + + if (argc < 2) + { + CONS_Printf("playsound : Plays a sound effect for the entire server.\n"); + return; + } + + if (client && !IsPlayerAdmin(consoleplayer)) + { + CONS_Printf("This can only be used by the server host.\n"); + return; + } + + sound = COM_Argv(1); + if (*sound >= '0' && *sound <= '9') + { + sfx = atoi(sound); + } + else + { + for (sfx = 0; sfx < sfxfree; sfx++) + { + if (S_sfx[sfx].name && fasticmp(sound, S_sfx[sfx].name)) + break; + } + } + + if (sfx < 0 || sfx >= NUMSFX) + { + CONS_Printf("Could not find sound effect named \"sfx_%s\".\n", sound); + return; + } + + WRITEINT32(buf_p, sfx); + SendNetXCmd(XD_PLAYSOUND, buf, buf_p - buf); +} + /** Makes a change to ::cv_forceskin take effect immediately. * * \sa Command_SetForcedSkin_f, cv_forceskin, forcedskin @@ -8464,6 +8536,8 @@ static void Schedule_OnChange(void) } } + + void Got_DiscordInfo(UINT8 **p, INT32 playernum) { if (playernum != serverplayer /*&& !IsPlayerAdmin(playernum)*/) diff --git a/src/s_sound.c b/src/s_sound.c index abb2ffea1..b7aa6066a 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -266,8 +266,6 @@ void S_RegisterSoundStuff(void) COM_AddCommand("tunes", Command_Tunes_f); COM_AddCommand("restartaudio", Command_RestartAudio_f); - COM_AddCommand("playsound", Command_PlaySound); - RegisterNetXCmd(XD_PLAYSOUND, Got_PlaySound); } static void SetChannelsNum(void) @@ -2820,71 +2818,6 @@ static void Command_RestartAudio_f(void) M_ChangeMenuMusic(); } -static void Command_PlaySound(void) -{ - const char *sound; - const size_t argc = COM_Argc(); - sfxenum_t sfx = NUMSFX; - UINT8 buf[4]; - UINT8 *buf_p = buf; - - if (argc < 2) - { - CONS_Printf("playsound : Plays a sound effect for the entire server.\n"); - return; - } - - if (client && !IsPlayerAdmin(consoleplayer)) - { - CONS_Printf("This can only be used by the server host.\n"); - return; - } - - sound = COM_Argv(1); - if (*sound >= '0' && *sound <= '9') - { - sfx = atoi(sound); - } - else - { - for (sfx = 0; sfx < sfxfree; sfx++) - { - if (S_sfx[sfx].name && fasticmp(sound, S_sfx[sfx].name)) - break; - } - } - - if (sfx < 0 || sfx >= NUMSFX) - { - CONS_Printf("Could not find sound effect named \"sfx_%s\".\n", sound); - return; - } - - WRITEINT32(buf_p, sfx); - SendNetXCmd(XD_PLAYSOUND, buf, buf_p - buf); -} - -static void Got_PlaySound(UINT8 **cp, INT32 playernum) -{ - INT32 sound_id = READINT32(*cp); - - if (playernum != serverplayer && !IsPlayerAdmin(playernum)) // hacked client, or disasterous bug - { - CONS_Alert(CONS_WARNING, M_GetText("Illegal playsound received from %s (serverplayer is %s)\n"), player_names[playernum], player_names[serverplayer]); - if (server) - SendKick(playernum, KICK_MSG_CON_FAIL); - return; - } - - if (sound_id < 0 || sound_id >= NUMSFX) - { - // bad sound effect, ignore - return; - } - - S_StartSound(NULL, sound_id); -} - void GameSounds_OnChange(void) { if (M_CheckParm("-nosound") || M_CheckParm("-noaudio"))