PAC3-Server / notagain

Custom Servercontent for the official PAC3 Server.
GNU General Public License v3.0
13 stars 22 forks source link

Prevent SH spam from causing errors #153

Closed MeteorTheLizard closed 4 years ago

MeteorTheLizard commented 4 years ago

[ERROR] notagain/goluwa/libraries/client/common_audio.lua:18: bad argument #1 to 'ipairs' (table expected, got nil)

Happened whenever someone spammed "sh" in chat or through saysound, should be fixed with this.

Myaats commented 4 years ago

Wouldn't it be smarter to find out what is calling it without a table instead of adding a check that should be unnecessary?

MeteorTheLizard commented 4 years ago

Wouldn't it be smarter to find out what is calling it without a table instead of adding a check that should be unnecessary?

Yes, it would be smarter. I've done some debugging and code digging to understand how exactly all of this works and what it is supposed to do and came to the conclusion that the webaudio.CreateStream() function sometimes does not return anything. If I have to guess, since you can spam chatsounds, it creates to many requests which may cause the request to get blocked. I have to note here though that I'm not capable of coding Javascript and can therefor not guarantee that this is actually the issue. Anyway, it seems like this is the best solution for this problem.

Myaats commented 4 years ago

Wouldn't it be smarter to find out what is calling it without a table instead of adding a check that should be unnecessary?

Yes, it would be smarter. I've done some debugging and code digging to understand how exactly all of this works and what it is supposed to do and came to the conclusion that the webaudio.CreateStream() function sometimes does not return anything. If I have to guess, since you can spam chatsounds, it creates to many requests which may cause the request to get blocked. I have to note here though that I'm not capable of coding Javascript and can therefor not guarantee that this is actually the issue. Anyway, it seems like this is the best solution for this problem.

The best solution is never to add more workarounds for an issue that should be easily fixable, imagine if you have to do nil checks for all arguments in al ofl your functions because other functions might call it without it's arguments.

Do you check if te arguments is present and if not return, or do you fix the rest of the code?

CapsAdmin commented 4 years ago

Looking at my code it looks like it was intended to maybe be undefined, so in a way this is the correct way to do it given the previous code.

However I think I was stupid so instead it's better to create the table once when a sound is created to avoid the need for this check and two other lines of code nearby.