LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-22-2003, 06:10 AM   #1
xconspirisist
Member
 
Registered: Dec 2002
Location: United Kingdom
Distribution: Ubuntu
Posts: 276

Rep: Reputation: 30
basic Open source c++ IRC bot.


hey there. I looking for an opensource example of an irc bot. all I want it for it to be able to send messages to a channel. I dont need kicking, banning, management, users, or trivia, none of that. Can anyone direct me to a project like this, or much better a c++ tutorial in coding a unix c++ irc bot. Cheers, xc.
 
Old 11-22-2003, 04:45 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Maybe http://sourceforge.net/projects/supybot/ (written in Python, not in C, but Python code is easy to read).
 
Old 11-23-2003, 05:12 AM   #3
scorpatron
Member
 
Registered: Nov 2003
Location: New Zealand
Distribution: Redhat 9 2.4.20-8 Athlon, Windows 2000 Professional, FreeBSD
Posts: 122

Rep: Reputation: 15
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
 
Old 11-23-2003, 07:48 AM   #4
xconspirisist
Member
 
Registered: Dec 2002
Location: United Kingdom
Distribution: Ubuntu
Posts: 276

Original Poster
Rep: Reputation: 30
I was desperatly trying to find examples on pscode.com - but just couldent find them anywhere? if you could direct me to one you find, that'd be cool, meenwhile ill do a search aswell.
 
Old 11-23-2003, 09:33 AM   #5
scorpatron
Member
 
Registered: Nov 2003
Location: New Zealand
Distribution: Redhat 9 2.4.20-8 Athlon, Windows 2000 Professional, FreeBSD
Posts: 122

Rep: Reputation: 15
well, you're probably searching for the wrong thing.

You want a complete example of what you're looking for so you can "rip it off" into a finished product.

Trust me you will save yourself a lot of time and produce a better product if you split your project into 2 steps.

1) The tcp socket for connecting to the irc server (search for tcp sockets at planetsourcecode.com)

2) The parsing of string server messages (very very simple! bascially make your bot console based, then try print the server response strings on the screen!)

well.. just a thaught.

Also you should state the true purpose of your IRC bot, if you're making a channel protector for your private use, then fine, download a premade irc bot which is secure and is easy to run on linux..

if you're making a malicious irc flood client, then be warned.... if you are attempting to find an example off the net then "rip it off" for your purposes.. you are what we here consider as a "script kiddy".

If you would like to actually learn programming I suggest starting off with the channel protection!

(Sorry if I sound like an a@s but I don't like IRC flooders)
 
Old 11-23-2003, 04:27 PM   #6
xconspirisist
Member
 
Registered: Dec 2002
Location: United Kingdom
Distribution: Ubuntu
Posts: 276

Original Poster
Rep: Reputation: 30
no no, im only in it for the *fun*. I just want to see if I can make a bot that auto connects to my own chanel, talks a bit, I can talk though it, and prehaps, I might evolve it into some sort of channel protector, but thats unlikly.
 
Old 11-24-2003, 08:14 PM   #7
scorpatron
Member
 
Registered: Nov 2003
Location: New Zealand
Distribution: Redhat 9 2.4.20-8 Athlon, Windows 2000 Professional, FreeBSD
Posts: 122

Rep: Reputation: 15
well what you're talking about is easy

go into console, type telnet irc.irctoo.net

should look like this :

[scorpion@www scorpion]$ telnet irc.irctoo.net 6667
Trying 205.160.101.121...
Connected to irc.irctoo.net.
Escape character is '^]'.
:rma.va.us.irctoo.net NOTICE AUTH :*** Looking up your hostname...
:rma.va.us.irctoo.net NOTICE AUTH :*** Checking Ident
:rma.va.us.irctoo.net NOTICE AUTH :*** Found your hostname
:rma.va.us.irctoo.net NOTICE AUTH :*** No Ident response

<Type:>

NICK scorp scorpjkl
USER lihj lihj kljhkl kljh : 0 0
JOIN #gcwsystems

NOTICE #gcwsystems im connected under telnet

----

Now if you can do that manually under console, it's not very hard to do it in C++!

like I said before..

1) Create a working socket to your IRC server (irc.irctoo.net port 6667 is an example)
2) Talk to the server (as demonstrated above)

if you actually decide to do this let me know
 
Old 11-25-2003, 06:50 AM   #8
xconspirisist
Member
 
Registered: Dec 2002
Location: United Kingdom
Distribution: Ubuntu
Posts: 276

Original Poster
Rep: Reputation: 30
Im sorry, ive found the easy way out. I found an IRC class on the net. ill be using this for the bot, as ive decided to write it from scratch, I dont want any loopholes in it anyway : )

Ill study the class in more detail, and hack it to bits later to see how it works. but thanks for the help anyway.
 
Old 08-10-2009, 12:49 PM   #9
jsweazy
LQ Newbie
 
Registered: Aug 2009
Posts: 2

Rep: Reputation: 0
Quote:
Originally Posted by scorpatron View Post
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
scorpatron,

you seem to know a good amount about IRC bots, I was wandering if you could help me get a start on one. I have read up on IRC protocols and Sockets. I cant even think of where to start with programing one. I would love to learn, and have been wanting to
 
Old 05-14-2010, 09:52 PM   #10
noden
LQ Newbie
 
Registered: Aug 2009
Location: Denmark
Distribution: Debian
Posts: 29

Rep: Reputation: 18
I know that this thread is pretty old but some might still be interested.
I have a very basic but working C++ IRC Bot source code for linux available in my Public SkyDrive folder at http://kingscradle.spaces.live.com/
It contain a lot of comments and is as simple as I can make it.
it also shows how the sockets are made etc.
Feel free to try it out, modify or what ever you want.

This direct link should work:
http://cid-cea720470f97d6d4.skydrive.../ircbot.tar.gz
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Alice or other IRC Chat Bot neenee Linux - General 5 12-27-2012 04:06 PM
IRC Ruby Bot Law1213 Linux - Software 0 01-03-2005 10:48 AM
Need IRC Bot Program (Like Winbot.) Any reccomendations? Kevin1290X KTPX Linux - Software 3 09-06-2004 02:33 PM
Open Source IRC Clients? drdroid Programming 6 11-14-2003 05:32 PM
Do u think IRC is a good source of help? rickenbacherus Linux - General 6 04-02-2003 11:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration