从IRC Server输入中清除不必要的文本

时间:2011-02-21 14:48:28

标签: vb.net string irc

我为自己创建了一个简单的IRC客户端,因为我真的不知道需要很多mIRC的功能,但是我在清理输入时遇到了问题。服务器。

现在,在连接时,我得到以下内容:

  

[16:37]:young.home.net注意事项:**查找你的主机名...
  :young.home.net注意事项:**找到您的主机名
  PING:DE7AED31
  [16:37]:DE7AED31!nospoof@young.home.net PRIVMSG Logan:VERSION
  :young.home.net 451 PING:你还没有注册   [16:37]:young.home.net 001 Logan:欢迎来到YoungNet IRC网络Logan !lyoung@127.0.0.1
  :young.home.net 002 Logan:您的主机是young.home.net,运行版本为Unreal3.2.8.1   :young.home.net 003 Logan:这个服务器是在2009年4月12日14:47:33创建的

我试图将其清理干净,如下所示:

  

[16:37] -young.home.net- **查找你的主机名......
  [16:37] -young.home.net- **找到你的主人名
  [16:37] [洛根]版本
  [16:37]你还没有注册   欢迎来到YoungNet IRC网络Logan !lyoung@127.0.0.1
  你的主机是young.home.net,运行版本Unreal3.2.8.1   这个服务器是在2009年4月12日14:47:33创建的

我已经阅读了IRCP(RFC 1459),我理解了服务器输入的格式,但我似乎无法删除不需要的东西......一位朋友建议将输入加载到排列和单独处理每个项目,但我似乎无法使其工作。我试过了,但它似乎没有什么区别......这是我的代码

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

非常感谢这里的任何指示。

1 个答案:

答案 0 :(得分:1)

好的,我在这里找到解决方案之后很忙,我完全忘记了stackoverflow ...

[http://www.mirc.net/raws/] [1]

[1]:http://www.mirc.net/raws/包含一个原始数字代码列表,它将服务器输出整齐地分类到客户端应用程序。

然而,在使用原始数字之前,需要进行一些分割。见下文:

' This function takes the raw input from the server as a parameter.
' NOTE: No modification has been done before this point.

Private Function Clean(ByVal Target As String) As String
    ' Get each line
    Dim temp() As String = Target.Split(vbCrLf)
    Dim back As String = Nothing

    ' For each line in the current string
    For i As Integer = 0 To temp.Length - 1
        ' Split the line 
        Dim result() As String = temp(i).Split(New String() {" :"}, StringSplitOptions.None)
        Dim j As Integer = Nothing
        Try
            ' NOTICE AUTH messages aren't covered in raw format, so this cleans those up
            If result(0).Contains("NOTICE AUTH") Then
                If Left(result(0), 1) <> ":" Then
                    ' g.Timestamp = "[" & Now.Hour & ":" & Now.Minute & "]"
                    back += g.Timestamp & " (" & result(0).Substring(2, result(0).IndexOf(" ") - 2) & ") " & result(1) & vbCrLf
                Else
                    back += g.Timestamp & " (" & result(0).Substring(1, result(0).IndexOf(" ") - 1) & ") " & result(1) & vbCrLf
                    g.host = result(0).Substring(1, result(0).IndexOf(" ") - 1)
                End If
            End If

            If Integer.TryParse(result(0).Substring(result(0).IndexOf(" ") + 1, 3), j) Then
                Select Case result(0).Substring(result(0).IndexOf(" ") + 1, 3)
                    ' For each code, modify the input here, this is just an example of what I've done...
                    Case "001" : back += ":=:" & vbCrLf & g.Timestamp & result(1) & vbCrLf
                End Select
            End If
        Catch ex As Exception

        End Try
    Next

    ' More stuff goes here (handling PING? PONG! events and such)

    Return back
End Function