I can't give you an example but I sure can give you the structure
I've written alot of IRC clients, first in mIRC scripts, then using VB, then finally attempting C++..
Firstly you need some basic socket knowledge,
1) Sockets -
IRC runs on TCP/IP, port 6667 usually... Most IRC servers use IDENT clients... therefore when you create a bot you need 2 sockets.
The first is a tcp_connect (host: irc.irc.com, port: 6667)
The second is a tcp_listen (host: localhost, port 22)
You only need the first to start off with, however by accepting IDENT requests, you speed up login time significantly, also certain IRC servers don't allow non-IDENT clients because of flooding.
There are PLENTY of examples of how to use sockets in C++ at
http://www.planetsourcecode.com check it out.
2) Talking with the IRC server
Once you have the connection setup, it is actually very simple to join a channel...
Basically you setup your program to periodically check for incoming packets from the server, IRC servers communicate via delimited strings... basically:
PRIVMSG: nIcKnAmE hey dude wasssssup!\n\bNOTICE: #blah ircbOt welcome user!\n\b
* \n\b is the same as crlf , however it's been so long that i can't remember the correct letters
it's 2 characters, 'break' and 'newline' mybe not in that order
FOR MORE INFO ON THE CORRECT FORMAT SEARCH FOR 'irc protocol'
The IRC protocol is universal among IRC servers...
---
When you connect to an IRC server you must give certain information like:
"NICK primary alternative" & crlf
"USER name email something : 0 : 0 " & crlf
"JOIN #channel" & crlf
Now like I said, it's been awhile! but this is all stated on the IRC protocol...
____
Once you have connected and given the right info, the IRC server will tell you so!
Now you probably wanna be able to tell what the server is saying! so you can make the bot do different things...
basically this is what it looks like in code
function parseirc($string) // usage example : $errornumber = parseirc("ERROR: 666")
{
$array = split(crlf, $string); // split the string and store it as an array of variables
for ($i = 0, $i > count($array), $i++) // for each line of the string
{
// you can now refer to each line as $array[$i]
if ($array <> "")
{
if ($array[$i] == "ERROR: 666")
{
return("error, could not set nickname!";
}
else
{
...
}
}
} // end of loop
} //end of function
What this does is takes more than one line of server respone does something with it line by line... as you can tell.. a server might tell you a whole lot of shit! prehaps you might wanna parse error codes first, then server notices (like when you join a channel successfully) and then user messages/authentication.
All I can suggest is that for an efficient bot, I would have a C++ program which talks to a database.. or creates xml files for authentication. But you could always just use pre-compiled passwords/settings, or a plain txt file.
-----
Any more questions? just let me know
hope you actually read this, took me awhile