I am writing a simple IRC Bot in C++. I am having issues, however, parsing "PING" properly. I cannot seem to extract the "PING" string from the output. I have a sample program setup (statically) with the same setup as my IRC bot and I can parse the string, but it does not seem to write properly when I actually apply the method to the bot.
Here is what I am trying to do:
char* Process::pingPong(std::string data)
{
char* pong = (char*)malloc(10);
if(strstr(data.c_str(),"PING"))
{
if(sscanf(data.c_str(), "%*[^\n|^PING] PING :%s", pong) > 0)
{
return pong;
}
}
free(pong);
return NULL; // Don't do anything if there is no ping to respond to
}
This function is called within the reading loop and (theoretically, after I return properly) will write the proper output to the server if it does not return NULL.
So this is being handled in the read-loop as follows:
char* ping = proc.pingPong(data);
if(ping != NULL)
{
char* pong = "PONG :";
std::strcat(pong,ping);
sock.writeData(sock.Connection,pong);
}
Thanks for your help!
Also, please note, I have done several checks and it IS making it to sscanf(), but in my test (where the std::string var is static) this method works to find PING. However, in practice it does not seem to work.