I’m making a simple IRC client for myself because I really don’t see the need for a lot of mIRC’s functionality, but I’m having problems cleaning up the input from the server.
Right now, on connect, I’m getting the following:
[16:37] :young.home.net NOTICE AUTH :** Looking up your hostname…
:young.home.net NOTICE AUTH :** Found your hostname
PING :DE7AED31
[16:37] :DE7AED31!nospoof@young.home.net PRIVMSG Logan :VERSION
:young.home.net 451 PING :You have not registered
[16:37] :young.home.net 001 Logan :Welcome to the YoungNet IRC Network Logan!lyoung@127.0.0.1
:young.home.net 002 Logan :Your host is young.home.net, running version Unreal3.2.8.1
:young.home.net 003 Logan :This server was created Sun Apr 12 14:47:33 2009
I’m trying to clean it up to read like this:
[16:37] -young.home.net- ** Looking up your hostname…
[16:37] -young.home.net- ** Found your hostname
[16:37] [Logan] VERSION
[16:37] You have not registered
Welcome to the YoungNet IRC Network Logan!lyoung@127.0.0.1
Your host is young.home.net, running version Unreal3.2.8.1
This server was created Sun Apr 12 14:47:33 2009
I’ve read the IRCP (RFC 1459) and I understand the formatting of the server input, but I can’t seem to strip out the unwanted stuff… A friend suggested loading the input into an array and deal with each item individually, but I can’t seem to make it work. I have tried, but it doesn’t seem to make a difference… Here’s my code
Public Function recv() As String
Dim mail As String
Try
Dim Data(4096) As Byte
sock.Receive(Data, 4096, Net.Sockets.SocketFlags.None)
mail = System.Text.ASCIIEncoding.UTF8.GetString(Data)
If mail.Contains(" ") Then
If mail.Contains("PING") Then
Dim pserv As String = mail.Substring(mail.IndexOf(":"), mail.Length - mail.IndexOf(":"))
pserv = pserv.TrimEnd(Chr(0))
'MsgBox("pserv: " & pserv)
send("PONG " & pserv)
ElseIf mail.Substring(mail.IndexOf(" ") + 1, 7) = "PRIVMSG" Then
Dim tmparr() As String = Nothing
Dim rnick, rmsg As String
mail = mail.Remove(0, 1)
tmparr = mail.Split("!")
rnick = tmparr(0)
tmparr = mail.Split(":")
rmsg = tmparr(1)
mail = "<" & rnick & "> " & rmsg
ElseIf mail.Substring(mail.IndexOf(" ") + 1, 6) = "NOTICE" Then
Dim tmparr() As String = Nothing
Dim rnick, rmsg As String
mail = mail.Remove(0, 1)
tmparr = mail.Split("!")
rnick = tmparr(0)
tmparr = mail.Split(":")
rmsg = tmparr(1)
mail = "-" & rnick & "- " & rmsg
Else
Dim tmparr() As String = Nothing
Dim rnick, rmsg As String
tmparr = mail.Split(" ")
rnick = tmparr(0)
tmparr = mail.Split(":")
rmsg = tmparr(1)
mail = rmsg
End If
End If
mail = g.Timestamp & mail
Catch ex As Exception
MsgBox(ex.ToString)
mail = "ERROR: " & ex.Message & vbCrLf
End Try
Return mail
End Function
Any pointers here would be greatly appreciated.
OK, I got so busy after I found the solution here that I completely forgot about stackoverflow…
[http://www.mirc.net/raws/][1]
[1]: http://www.mirc.net/raws/ contains a list of raw numeric codes that neatly categorize the server output to the client app.
There’s a few splits to get through before you can use the raw numerics, however. See below: