mIRC Home    About    Download    Register    News    Help

Print Thread
#157475 25/08/06 11:49 AM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
im thinking of building an irc bot in c++, but a few questions

in c++ sockets the data is returned in chunks, not messages like in mirc.

so i need to deal with this chunk and split by the necessary \r\n's

do messages have \r\n at the end of them? or just \n ? or just \r?
any got any sample code for parsing incoming data from the server in c++? its a bit tricky with the \n and \r stuff to parse it properly

Last edited by pouncer; 25/08/06 11:50 AM.
#157476 25/08/06 12:13 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
I haven't checked sockets at the winapi level yet so I don't know how much control you have, but I assume you can read past the crlf (\r = cr, lf = \n, crlf = \r\n), thus meaning you read more than one line of data at a time, so you'll have to parse it.

As for parsing, strtok() might help. Look it up on google.

#157477 25/08/06 12:49 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
thanks. theres 1 thing that im slightly confused about.

for e.g:, lets say the server sends this back to me, this is a whole chunk with 2 messages in it

(obviously in mirc sockread, i would receive this in 2 messages, but c++ sockets recv in chunks)

Code:
pouncer privmsg #chan :hello
johhny quit chan timeout


where exactly are the \r\n's ?

pouncer privmsg #chan :hello\r\n
johhny quit chan timeout\r\n

or:

pouncer privmsg #chan :hello\n
johhny quit chan timeout\r\n

thats what im confused about

Last edited by pouncer; 25/08/06 12:53 PM.
#157478 25/08/06 01:14 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
IRC commands are separated by \r\n, so:

pouncer!x@y.z PRIVMSG #chan :hello\r\n
johhny!x@y.z QUIT :timeout\r\n

#157479 25/08/06 03:25 PM
Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
I could be wrong, but last time I wrote one, this chunking never happened. Given the IRCd sends out events as they happen, and doesn't usually 'group' them in to one segment, you should be fine with one read is one event.

Again, I could be uttering complete and utter bologna, but I think it stops you at a crlf. best thing to do is make a connection, and echo it.


-KingTomato
#157480 25/08/06 04:49 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
Quote:
I could be wrong, but last time I wrote one, this chunking never happened. Given the IRCd sends out events as they happen, and doesn't usually 'group' them in to one segment, you should be fine with one read is one event.

Again, I could be uttering complete and utter bologna, but I think it stops you at a crlf. best thing to do is make a connection, and echo it.


yeah i seem to receive the data in chunks. ive now parsed the data successfully and got the bot to connect and join the channel fine.

if anyone is interested, in the C sockets on the recv the messages may _not_ even have the \r\n at the end of it in which case you have to wait for the next message and append it to the buffer

i then split this buffer into the different individual messages by splitting them through the \r\n and i perform commands on these single messages.


Link Copied to Clipboard