Starfox64 / FoxedBot

FoxedBot - The SteamBot for Garry's Mod
GNU General Public License v2.0
16 stars 7 forks source link

Long announce messages crashes clients #10

Closed zambony closed 9 years ago

zambony commented 9 years ago

I decided to check out what would happen if I typed out a full message (whether it would wrap or not) and.. well... it crashed my game. I tried editing the code to wrap the text to the panel, but then I realized you overwrote PANEL:SetText() to just draw text, so I wasn't sure how to get that to wrap.

Starfox64 commented 9 years ago

It already wraps I'm using markup (meaning you can use the font and color HTML tags in your text). I tried announcing long text and had no issues I don't know if the crash is caused by the GUI or the networking.

zambony commented 9 years ago

That's odd. I typed out a sentence (about 40 characters) and I lagged briefly, then my game proceeded to crash and gave me the error "STACK OVERFLOW" or something to that effect.

Starfox64 commented 9 years ago

Are you on singleplayer / listenserver?

zambony commented 9 years ago

I was on a listen server, yes. I assume that must be the problem then...

Starfox64 commented 9 years ago

Here is what wrapping looks like http://steamcommunity.com/id/_fr_starfox64/screenshot/713029906825849449

Are you running the latest update that was pushed yesterday? I'd like to see is if bromvlieg changes fixed it.

zambony commented 9 years ago

The latest version gm_bromsock? Yes. And FoxedBot*

zambony commented 9 years ago

I'm actually thinking now that it might be due to the fact that I added the avatar of the player who sent the announcement next to the header. Somehow... EDIT: Just kidding, tried it on a fresh version of the file. Still crashes.

Starfox64 commented 9 years ago

Could you remove your modifications, do some testing with the latest versions and tell me if you are still experiencing issues.

zambony commented 9 years ago

Done on a fresh installation in singleplayer, crashed me. Are you pasting in text that is already wrapped (lorem ipsum generators) or are you typing out a string? I've just been typing out long sentences with no newline characters.

Error message image

Starfox64 commented 9 years ago

I'm having no issues when sending very long strings (max SteamChat length). However I'm pushing a fix to ignore errors on the listening socket.

zambony commented 9 years ago

Could it be a result of the server port I have set for it? 27015 for server and 25000 for listening

Starfox64 commented 9 years ago

Well yes it is, the server port (as said in the README) isn't source's it's a unique port per server reserved for FoxedBot.

zambony commented 9 years ago

Well if FoxedBot.ServerPort is anything other than 27015, commands sent to the bot don't go through.

zambony commented 9 years ago

Oh dear god I really am dumb. Changed the port in settings.js on the bot's end to 25100 and it works, same with text wrapping. Ok.

Well thanks for your help, sorry for the trouble!

EDIT: Nevermind, text wrapping works but I still crash with long messages.

Starfox64 commented 9 years ago

Does the server or the client crash?

zambony commented 9 years ago

Well unfortunately I don't have the luxury of having a dedicated server, so I'm on a listen server, and I can't tell which crashes since the game closes out and gives me the error "hl2.exe has encountered an error and needs to close"

Starfox64 commented 9 years ago

Is it only when the text is "too long"? Try using chat instead and tell me if it does it too.

zambony commented 9 years ago

Yes it crashes too with chat, but it tolerates longer messages before crashing.

Starfox64 commented 9 years ago

Oh and I was wondering, why do you need FoxedBot for a listen server? (I don't think I'll be able to help you there) What is considered too long?

zambony commented 9 years ago

Well I'm the developer for a community and we don't have a dev server, so I have to resort to using singleplayer. As well, I'm hesitant to live-test it on the server if it does indeed crash when sending chat messages and announcements.

Too long seems to be more than 35 characters, no line breaks or newline characters.

Starfox64 commented 9 years ago

Do you get this when sending an rcon command?

zambony commented 9 years ago

Yes.

Starfox64 commented 9 years ago

So this is a server issue, does the server ever gets empty so you can test FoxedBot on it?

zambony commented 9 years ago

Our server usually has anywhere from 26-42 people on it, and by the time it is empty, it's about one in the morning and I don't want to be falling asleep while trying to test things. I'll see if I can borrow a friend's server later, but I don't know if he'll let me.

Starfox64 commented 9 years ago

Ok, sorry but at this point I have no more hints.

zambony commented 9 years ago

All right, thank you for trying anyway. I'll maybe comment again if and when I get to try it on a real server.

zambony commented 9 years ago

Got a dedicated server and when I look in the console, when sending a large announcement or chat message, the console prints this error and will actually most of the time crash the server

[FoxedBot] Received an invalid packet.

Exact amount of characters it will allow is 47

Starfox64 commented 9 years ago

Could you install something like wireshark, send the packet to an external IP (not loopback else it won't capture it) and send me the content of the failed packets.

zambony commented 9 years ago

Never used wireshark before. How exactly would I do this?

zambony commented 9 years ago

Long !chat message crashes the server with this error

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

Attempting to print the table being sent to the server. Shorter messages successfully print the table, longer ones throw this error

[ERROR] lua/includes/util.lua:43: bad argument #1 to 'pairs' (table expected, got nil)
  1. pairs - [C]:-1
   2. PrintTable - lua/includes/util.lua:43
    3. unknown - addons/foxedbot/lua/foxedbot/sv_foxedbot.lua:18
     4. v - [C]:-1
      5. unknown - lua/includes/modules/hook.lua:84
Starfox64 commented 9 years ago

First off, in the bot settings.js, select an external IP for a server, if you choose 127.0.0.1 it won't work. In wireshark select your network adapter and click start, send an announcement to the server with the external IP then stop the wireshark capture and look for the packet that was sent. and show be the packet in HEX.

In filters you can type tcp to remove all the useless packets.

zambony commented 9 years ago

I can't exactly copy the hex. Would a picture work?

Starfox64 commented 9 years ago

Yup

zambony commented 9 years ago

Here is the packet I selected which pops up when I send announcements that are too long.

And here is the hex

Starfox64 commented 9 years ago

Can you show me a packet that works too?

zambony commented 9 years ago

Sorry, wrong packet. http://puu.sh/ggBaU.png

zambony commented 9 years ago

Here's a packet that is showing different information when I send messages that are too long:

Starfox64 commented 9 years ago

That last one isn't working right? also can you post the full packet, this one is missing the first part.

zambony commented 9 years ago

whoops, sorry about that and yes the last one doesn't go through

Starfox64 commented 9 years ago

In lib/functions.js at line 72 could you add console.log(size);, and send a couple message (short and long ones) and tell me if you see any values that seems too big.

zambony commented 9 years ago

All of them went through except the last one.

Starfox64 commented 9 years ago

Could you send The last one again (Exact same message) and capture the packet using wireshark.

zambony commented 9 years ago

Okay

Starfox64 commented 9 years ago

In lib/function.js can you replace sendToServer with this and tell me what happens. (If it fails can you send me the packet)

https://gist.github.com/Starfox64/6971b4d1eb3be47c20ce

May I ask you where you get this from?

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
zambony commented 9 years ago

The bad_alloc comes from what I assume is going over the limit for chat.AddText If I send a message with !chat that is very long, it takes down the server with that error.

zambony commented 9 years ago

Now even short messages don't go through.

Starfox64 commented 9 years ago

Does the server crash?

I meant where do you find that error not how.

zambony commented 9 years ago

The server doesn't crash with the new modifications, the message just doesn't appear on the server.

And the other error I find in my console right after it crashes from chat.

Starfox64 commented 9 years ago

Oh Ok thats because you are running a dedicated server I understand now.

I'm gonna look into the new code.

Starfox64 commented 9 years ago

I just updated the gist, try the new code it was a dumb mistake. https://gist.github.com/Starfox64/6971b4d1eb3be47c20ce