IRC ignores messages


#1

I’m developing my own bot using C++ and recently I encountered a weird problem with IRC. The bot works fine, reads messages and performs some simple commands. But after some time of bot inactivity (connection still remains opened) twitch IRC ignores first message of my bot. All other messages are being sent.
This is what happens step by step:

  1. I send command to chat in browser.
  2. Bot answers it.
  3. I leave my chat tab open but do some other things for a while.
  4. I send same command again.
  5. There is no answer from the bot.
  6. I check logs. Bot received message, proceded it and sent its response (or at least it seems so, I can’t check if it was actually sent to twitch but the code was executed).
  7. I send the command again.
  8. Now bot answers me.

This is how I send messages to IRC.

tosend = “PRIVMSG #” + this->channel + " :" + tosend + “\r\n\r\n”;
char *buffer = new char[512];
strcpy(buffer, tosend.c_str());
int *bytes = new int(0),
*total = new int(0),
*length = new int(strlen(buffer)-1);
while(*total < *length) {
*bytes = ::send(this->s, tosend.c_str(), tosend.length(), 0);
if(*bytes == -1) return false;
*total += *bytes;
}
delete bytes, total, length;
delete[] buffer;

P.S. The message is followed by double \r\n because single \r\n doesn’t seem to work for me.


#2

Just a couple thoughts that might or might not help:

  • Are you replying to the PING messages the server sends to you?
  • The fact that you need a double \r\n indicates an issue with your code somewhere.

#3

Thanks to you message, I checked ping response. I messed it up. Instead of sending only “PONG :tmi.twitch.tv\r\n”, I was sending entire buffer, which was storing response. So I sent response + 490 bytes of some random data. Any message that twitch received after such ping response consisted of 490 bytes of random data + actual message. The problem is solved now.