Outline: I'm writing a simple IRC client for the PSP. So far I connect, recv some data, and send the USER and NICK messages. My problem is getting data and moving the buffer.
This is what I've got (clearly not done). Basically, I'm trying to get the recv buffer to keep the data on the left, and append as it comes in. But that's not what happens. What ends up happing is this (ignore the error for now):
What it should look like is:
USER rabbittest rabbittest irc.lan.st :Spencer
NICK rabbittest
:irc.lan.st NOTICE AUTH :*** Looking up your hostname...
:irc.lan.st NOTICE AUTH :*** Found your hostname (cached)
:irc.lan.st NOTICE rabbittest :*** If you are having problems connecting due to ping timeouts, please type /quote pong D379BDA9 or /raw pong D379BDA9 now.
PING :D379BDA9
IRC's messages are \r\n delimited, so what I'm trying to do is get the data up to the first \r\n, print it (for now), and then remove it, but it's not working ><
while(bytesRecv != SOCKET_ERROR)
{
bytesRecv = recv(s, recvbuf + offset, 2048, 0);
if(bytesRecv == 0)
{
printf("Connection closed\n");
break;
}
offset += bytesRecv;
buff.add(recvbuf);
ZeroMemory(recvbuf, sizeof(recvbuf));
buff.parse();
}
void Buffer::parse()
{
int pos = (int)(strstr(this->bufferdata, "\r\n") - this->bufferdata + 1);
if(pos > 1)
{
char *piece = new char[pos];
ZeroMemory(piece, sizeof(piece));
strncpy(piece, this->bufferdata, pos);
this->movenext(pos);
printf("%s\r\n", piece);
}
}
void Buffer::movenext(int length)
{
char *temp = new char[sizeof(this->bufferdata)];
this->bufferdata;
ZeroMemory(this->bufferdata, sizeof(this->bufferdata));
strncpy(this->bufferdata, temp + length, sizeof(temp));
}