From a552ddc008b5795266564f036eb23815da8301fc Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 29 Sep 2020 22:37:51 -0700 Subject: [PATCH] Add warning if sound index is unknown instead of panic --- bot/ingame.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bot/ingame.go b/bot/ingame.go index 5ceca71..7742318 100644 --- a/bot/ingame.go +++ b/bot/ingame.go @@ -322,10 +322,14 @@ func handleSoundEffect(c *Client, p pk.Packet) error { } if c.Events.SoundPlay != nil { - return c.Events.SoundPlay( - data.SoundNames[s.Sound], int(s.Category), - float64(s.X)/8, float64(s.Y)/8, float64(s.Z)/8, - float32(s.Volume), float32(s.Pitch)) + if int(s.Sound) < len(data.SoundNames) { + return c.Events.SoundPlay( + data.SoundNames[s.Sound], int(s.Category), + float64(s.X)/8, float64(s.Y)/8, float64(s.Z)/8, + float32(s.Volume), float32(s.Pitch)) + } else { + fmt.Fprintf(os.Stderr, "WARN: Unknown sound name. is data.SoundNames out of date?\n") + } } return nil