Squirm
09-29-2001, 05:45 PM
Hi, me again.
Whilst looking for my next VB project, I noticed that #blah, our IRC channel, has its own bot, VBPro. I enquired about whether this was actually coded in VB, and it turns out it isnt. So, I thought, I would like to have a go at making my own bot. So, I researched a little on IRC protocol and came up with this little 'guide' :
You need a winsock control. For my example I called it Sock. To start the ball rolling you need to put the following code somewhere:
Sock.Connect sServer, 6667
sServer is a string containing a known IRC server, such as "efnet.demon.co.uk", which I use. The port is usually 6666, 6667, or 6668. Many servers seem to support all 3. This will get you connected to the IRC server. But, thats only the beginning. You still need ident.
Private Sub Sock_Connect()
Sock.SendData "NICK " & sNick & vbCrLf
Sock.SendData "USER " & sNick & " " & Sock.LocalHostName & " " & _
UCase(Sock.LocalHostName & ":" & Sock.LocalPort & "/0") & " :" & sName & vbCrLf
End Sub
This sends all you connection details to the IRC server. NICK is a command to set your nickname on IRC. USER is a command to send all of the details about the user. sNick is a string variable containing a nickname, such as "MyNick22" which people will see you as online. sName is a string containing your real name, such as "John".
If this is successful, the server will connect you fully, and most likely send you a load of stuff. To better understand all of it, I would recommend using Debug.Print to display all incoming data through the winsock. You will receive a lot of stuff, mainly server statistics, message of the day (MOTD) and other fluff. After all this, you can start to use IRC.
To join a channel you use the command JOIN followed by the channel name.
Sock.SendData "JOIN #blah" & vbCrLf
To send a message to a channel you use PRIVMSG:
Sock.SendData "PRIVMSG #blah : Hi, this is my message" & vbCrLf
There are many other commands, such as NOTICE, MODE, PART, which you will gradually learn as you experiment, by analysing what comes in via the Debug window.
To leave IRC, simply closing the connection is not a good idea. A better method is to send the QUIT command and then the IRC server will close the connection for you.
Private Sub cmdClose_Click()
Sock.SendData "QUIT : Going to lunch...." & vbCrLf
End Sub
Other users will see that you have quit along with the message Going to lunch..... Then, the IRC server will close the connection for you. This is the best way of going about things.
Well, thats about it for IRC. This is just a starter, and there is much much more to know. For a start, there a server messages and codes which you can intercept, and you might want to try parsing incoming data to display in a RTB in colours, much like mIRC. Or, you might, like me, try to make a bot. If you are interested, this article merely touches the surface. Go visit The IRC RFC (http://www.irchelp.org/irchelp/rfc/index.html) for more info.......
Final Note: Whenever sending any data via the winsock control, always make sure it ends it vbCrLf, which signifies the end of the data. My failure to realise this crashed my PC numerous times, so be warned.
Good luck ;)
See also:
programming for IRC with VB tutorial (http://www.xtremevbtalk.com/showthread.php?p=379047#post379047)
Whilst looking for my next VB project, I noticed that #blah, our IRC channel, has its own bot, VBPro. I enquired about whether this was actually coded in VB, and it turns out it isnt. So, I thought, I would like to have a go at making my own bot. So, I researched a little on IRC protocol and came up with this little 'guide' :
You need a winsock control. For my example I called it Sock. To start the ball rolling you need to put the following code somewhere:
Sock.Connect sServer, 6667
sServer is a string containing a known IRC server, such as "efnet.demon.co.uk", which I use. The port is usually 6666, 6667, or 6668. Many servers seem to support all 3. This will get you connected to the IRC server. But, thats only the beginning. You still need ident.
Private Sub Sock_Connect()
Sock.SendData "NICK " & sNick & vbCrLf
Sock.SendData "USER " & sNick & " " & Sock.LocalHostName & " " & _
UCase(Sock.LocalHostName & ":" & Sock.LocalPort & "/0") & " :" & sName & vbCrLf
End Sub
This sends all you connection details to the IRC server. NICK is a command to set your nickname on IRC. USER is a command to send all of the details about the user. sNick is a string variable containing a nickname, such as "MyNick22" which people will see you as online. sName is a string containing your real name, such as "John".
If this is successful, the server will connect you fully, and most likely send you a load of stuff. To better understand all of it, I would recommend using Debug.Print to display all incoming data through the winsock. You will receive a lot of stuff, mainly server statistics, message of the day (MOTD) and other fluff. After all this, you can start to use IRC.
To join a channel you use the command JOIN followed by the channel name.
Sock.SendData "JOIN #blah" & vbCrLf
To send a message to a channel you use PRIVMSG:
Sock.SendData "PRIVMSG #blah : Hi, this is my message" & vbCrLf
There are many other commands, such as NOTICE, MODE, PART, which you will gradually learn as you experiment, by analysing what comes in via the Debug window.
To leave IRC, simply closing the connection is not a good idea. A better method is to send the QUIT command and then the IRC server will close the connection for you.
Private Sub cmdClose_Click()
Sock.SendData "QUIT : Going to lunch...." & vbCrLf
End Sub
Other users will see that you have quit along with the message Going to lunch..... Then, the IRC server will close the connection for you. This is the best way of going about things.
Well, thats about it for IRC. This is just a starter, and there is much much more to know. For a start, there a server messages and codes which you can intercept, and you might want to try parsing incoming data to display in a RTB in colours, much like mIRC. Or, you might, like me, try to make a bot. If you are interested, this article merely touches the surface. Go visit The IRC RFC (http://www.irchelp.org/irchelp/rfc/index.html) for more info.......
Final Note: Whenever sending any data via the winsock control, always make sure it ends it vbCrLf, which signifies the end of the data. My failure to realise this crashed my PC numerous times, so be warned.
Good luck ;)
See also:
programming for IRC with VB tutorial (http://www.xtremevbtalk.com/showthread.php?p=379047#post379047)