tfaughnan / artoo

Barebones IRC bot / astromech droid (WIP 🚧)
GNU General Public License v3.0
1 stars 4 forks source link

set a more conservative IRC maximum message length #16

Open antithalian opened 6 months ago

antithalian commented 6 months ago

IRC message lengths include the hostmask, which is hard to determine with 100% accuracy

a robust and simple fix is to simply set the maximum length to a conservative value of around 400

tfaughnan commented 6 months ago

Have you tested this? Ideally I’d prefer to fix the logic in client.PrintfPrivmsg than make unnecessarily large adjustments to the constant

antithalian commented 6 months ago

I tested the equivalent in bobbit. Mostly made the PR here, too, as a joke haha.

The problem is that the hostmask is included in what the server considers to be the message length (I think since that's included in the length of what it sends out to clients), so to really know the proper maximum length you have to know the length of the hostmask, which can change.

I've been reading up on this stuff all day and finally got tired of it a little bit ago, but basically if you want a conservative maximum you could go off of the server's reported maximum HOSTLEN except not all servers actually report that despite it being required. To instead keep track of the actual hostmask at all times you'd need to request the CHGHOST capability from the server and watch for CHGHOST messages that reference the bot. You get into a lot of edge cases then, though, like "what if the server doesn't support that capability", and probably need to have a reasonable maximum to default to anyways.

Long story short, you need a pretty full-featured client to robustly keep track of the actual maximum length of a message that you can send, and apparently the standard guess to avoid needing that is that ~400 will be okay.