IRC formatting help

  • 12 years ago
    Hi guys,
    string manipulation is not my strongest point so i would like some help if possible :)

    i have this code here :

    private void IrcCommandReceived(string IrcCommand) {  //This receives EVERYTHING sent by IRC server
                 Console.WriteLine(IrcCommand);
            }
    when i run my script everything works fine xcept it spits out whole bunch of gibberish that would need to be formatted i have read the irc RFC i just dont know how to go about formatting my string.

    any help would be apreciated













  • 12 years ago

    Ok, bare in mind, i know this is vb.net but it won't take much to translate it to c#. it's some pretty old cold. wrote them about 2 years ago. was also made to be multithreaded, so some parts you don't need. but it does parse anything the irc server can throw at it. I'll be rewriting the bot in a few weeks, so if you still need a c# parser by then i'll paste mine. btw, think there's a vb.net -> c# translater thing here

    #Region " Structures "
        Public Structure PrivateMessageData
            Dim Host As String
            Dim nick As String
            Dim Message As String
            Dim ToNick As String
            Dim Args() As String
            Dim server As String
        End Structure
        Public Structure ChannelMessageData
            Dim Channel As String
            Dim host As String
            Dim nick As String
            Dim message As String
            Dim server As String
        End Structure
        Public Structure CommandMessageData
            Dim channel As String
            Dim host As String
            Dim Action As String
            Dim Nick As String
        End Structure
        Public Structure ServerMessageData
            Dim server As String
            Dim code As String
            Dim concerns As String
            Dim channel As String
            Dim message As String
        End Structure
        Public Structure ThreadSafeParsing
            Dim data As String
            Dim sock As clsSocket
        End Structure
    #End region
    #Region " Server message parsers "
        Public Sub ParsePrivMSG(ByVal state As Object)
            Dim d_temp As ThreadSafeParsing = CType(state, ThreadSafeParsing)
            Try
                Dim data As String = d_temp.data
                Dim pmData As PrivateMessageData
                Dim lock As New Object
                SyncLock lock
                    If Trim(data) = "" Or InStr(data, "!") - 1 <= 0 Then Exit Sub
                    With pmData
                        data = Strings.Replace(Strings.Right(data, Len(data) - 1), vbCrLf, "") 'vbcrlf
                        .nick = Strings.Left(data, InStr(data, "!") - 1)
                        .Host = GenerateHost(Trim(Strings.Replace(Strings.Left(Strings.Replace(data, .nick & "!", ""), InStr(Strings.Replace(data, .nick & "!", ""), " ")), .nick & "!", "")))
                        data = LTrim(Strings.Right(data, Len(data) - InStr(LCase(data), "privmsg ") - Len("privmsg ") + 1))














































                        .ToNick = Trim(Strings.Left(data, InStr(data, " ")))
                        data = Strings.Right(data, Len(data) - InStr(data, ":"))
                        Do Until InStr(data, "  ") = 0
                            data = Strings.Replace(data, "  ", " ")
                        Loop
                        .Message = data
                        .Args = Split(LTrim(RTrim(data)), " ")
                    End With
                    irc(d_temp.sock.tag).pmData = pmData
                End SyncLock
            Catch ex As Exception
                Critical.ReportError(ex)
            End Try
        End Sub
        Public Sub ParseChannel(ByVal state As Object)
            Dim d_temp As ThreadSafeParsing = CType(state, ThreadSafeParsing)
            Try
                Dim data As String = d_temp.data
                Dim cmData As ChannelMessageData
                Dim lock As New Object
                SyncLock lock
                    If Trim(data) = "" Or InStr(data, "!") - 1 <= 0 Then Exit Sub
                    With cmData
                        data = Strings.Replace(Strings.Right(data, Len(data) - 1), vbCrLf, "") 'vbcrlf
                        .nick = Strings.Left(data, InStr(data, "!") - 1)
                        .host = GenerateHost(Trim(Strings.Replace(Strings.Left(Strings.Replace(data, .nick & "!", ""), InStr(Strings.Replace(data, .nick & "!", ""), " ")), .nick & "!", "")))
                        data = LTrim(Strings.Right(data, Len(data) - InStr(LCase(data), "privmsg ") - Len("privmsg ") + 1))

























                        .Channel = Trim(Replace(Trim(Strings.Left(data, InStr(data, " "))), "#", ""))
                        data = Strings.Right(data, Len(data) - InStr(data, ":"))
                        Do Until InStr(data, "  ") = 0
                            data = Strings.Replace(data, "  ", " ")
                        Loop
                        .message = data
                    End With
                    irc(d_temp.sock.tag).chnData = cmData
                End SyncLock
            Catch ex As Exception
                Critical.ReportError(ex)
            End Try
        End Sub
        Public Sub ParseCommand(ByVal state As Object)
            Dim d_temp As ThreadSafeParsing = CType(state, ThreadSafeParsing)
            Try
                Dim data As String = d_temp.data
                Dim xmData As CommandMessageData
                Dim lock As New Object
                SyncLock lock
                    If Trim(data) = "" Or InStr(data, "!") - 1 <= 0 Then Exit Sub
                    With xmData
                        data = Strings.Right(data, Len(data) - 1)
                        .Nick = Strings.Left(data, InStr(data, "!") - 1)
                        data = Strings.Right(data, Len(data) - Len(.Nick) - 1)
                        .host = GenerateHost(Strings.Left(data, InStr(data, " ") - 1))
                        data = Strings.Right(data, Len(data) - InStr(data, " "))
                        .Action = Strings.Left(data, InStr(data, " ") - 1)
                        data = Strings.Right(data, Len(data) - InStr(data, " "))
                        .channel = Replace(Strings.Right(LTrim(RTrim(data)), Len(data) - InStr(data, "#")), vbCrLf, "")
                        data = Strings.Right(data, Len(data) - InStr(data, " "))
                    End With
                    irc(d_temp.sock.tag).cmdData = xmData
                End SyncLock
            Catch ex As Exception
                ReportError(ex)
            End Try
        End Sub
        Public Sub ParseServerMessage(ByVal state As Object)
            Dim d_temp As ThreadSafeParsing = CType(state, ThreadSafeParsing)
            Try
                Dim data As String = d_temp.data
                Dim ssData As ServerMessageData
                Dim lock As New Object
                SyncLock lock
                    With ssData
                        Dim temp() As String = Split(data)
                        .code = temp(1)
                        .concerns = temp(2)
                        .server = Strings.Replace(temp(0), ":", "")
                        If InStr(.server, "!") <> 0 Then
                            .message = ""
                            .server = Split(.server, "!")(0)
                            .channel = Replace(Replace(temp(3), ":", ""), "#", "")
                        Else
                            .channel = Replace(IIf(Strings.Left(temp(3), 1) = "#", temp(3), temp(4)), "#", "")
                            .message = Strings.Right(data, Len(data) - 1)
                            .message = Strings.Right(.message, Len(data) - InStr(.message, ":") - 1)
                        End If
                        Select Case UCase(.code)
                            Case "INVITE" : .code = 341
                        End Select
                    End With
                    irc(d_temp.sock.tag).srvData = ssData
                End SyncLock
            Catch ex As Exception
                ReportError(ex)
            End Try
        End Sub
    #end region




































































Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity.” - Dennis Ritchie