Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Knowledge Base > Tutors' Corner > IRC Protocol


Reply
 
Thread Tools Display Modes
  #1  
Old 09-29-2001, 05:45 PM
Squirm's Avatar
Squirm Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default IRC Protocol


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:

Code:
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.

Code:
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.

Code:
Sock.SendData "JOIN #blah" & vbCrLf

To send a message to a channel you use PRIVMSG:

Code:
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.

Code:
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 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

Edit by Iceplug: See also:
programming for IRC with VB tutorial
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing

Last edited by OnErr0r; 10-16-2009 at 05:43 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->