Lieber Besucher, herzlich willkommen bei: Banana-Coding.com - Java Knuddels Emulator. Falls dies dein erster Besuch auf dieser Seite ist, lies bitte die Hilfe durch. Dort wird dir die Bedienung dieser Seite näher erläutert. Darüber hinaus solltest du dich registrieren, um alle Funktionen dieser Seite nutzen zu können. Benutze das Registrierungsformular, um dich zu registrieren oder informiere dich ausführlich über den Registrierungsvorgang. Falls du dich bereits zu einem früheren Zeitpunkt registriert hast, kannst du dich hier anmelden.
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
Class BananaChat
Private decodeKey As Byte()
Dim Writer As BinaryWriter
Dim Reada As BinaryReader
Dim Stream As Stream
Dim Nch As Char = Convert.ToChar(&H0)
Private Sub W(T As String, Optional C As ConsoleColor = ConsoleColor.Gray)
Console.ForegroundColor = C
Console.WriteLine(T)
Console.ForegroundColor = ConsoleColor.Gray
End Sub
Public Sub Connect(Ip As String, Port As Integer)
Dim Client As New TcpClient(Ip, Port)
Stream = Client.GetStream()
W(String.Concat(Environment.NewLine, ">> Connected to ", Ip, " on Port ", Port), ConsoleColor.DarkGreen)
Writer = New BinaryWriter(Stream)
Reada = New BinaryReader(Stream)
Readd()
Dim Handshake As Byte() = New Byte() {&H0}
Send(Handshake, True)
W(">>##### Handshake done.", ConsoleColor.Blue)
W("Answer : " & WriteandReceive(Encoding.UTF8.GetBytes("t" & Nch & "V9.0asq"), True), ConsoleColor.Red)
W(">> Version sent.", ConsoleColor.DarkCyan)
End Sub
Public Sub Login(Acc As String, Pass As String, Channel As String)
Dim Login As Byte() = Encoding.UTF8.GetBytes(String.Concat("n", Nch, Channel, Nch, Acc, Nch, Pass, Nch, "F"))
W(WriteandReceive(Login, False), ConsoleColor.Yellow)
End Sub
#Region "SendandReceive"
Private Function WriteandReceive(T As [Byte](), EncodeMessage As Boolean) As String
Send(T, EncodeMessage)
Return Encoding.ASCII.GetString(Receive)
End Function
Private Sub Send(T As [Byte](), EncodeMessage As Boolean)
Dim D As [Byte]()
If EncodeMessage Then D = Encode(T) Else D = T
Writer.Write(D)
End Sub
Private Function Receive() As [Byte]()
Return Decode(Stream)
End Function
Private Sub Readd()
Dim F As New Thread(Sub()
While True
Dim x = Receive()
Dim S As String() = Encoding.Default.GetString(x).Split(Convert.ToChar(&H0))
For Each p As String In S
W(p)
Next
End While
End Sub)
F.IsBackground = True : F.Start()
End Sub
#End Region
#Region "EncodeandDecode"
Private Function Encode(message As Byte()) As Byte()
Dim length As Integer = message.Length - 1
If length < 128 Then
Return {CByte(length)}.Concat(message).ToArray()
Else
Dim count As Integer
While 32 << (count + 1 << 3) <= length
count += 1
End While
count += 1
Dim len As New List(Of Byte)
len.Add(CByte(count << 5 Or &H80 Or length And &H1F))
For i = 1 To count
len.Add(CByte(length >> 8 * (i - 1) + 5))
Next
Return len.Concat(message).ToArray()
End If
End Function
Private Function Decode(Stream As Stream) As Byte()
Dim first As SByte = Reada.ReadSByte()
Dim length As Integer
If first >= 0 Then
length = first + 1
Else
length = first And &H1F + 1
Dim count As Integer = first And &H60 >> 5
For i As Integer = 0 To count - 1
length += Reada.ReadByte() << (i << 3) + 5
Next
End If
Dim B(length - 1) As Byte
For r As Integer = 0 To length - 1
B(r) = CByte(Reada.ReadByte() Xor (If(decodeKey IsNot Nothing AndAlso r < decodeKey.Length, decodeKey(r), 0)))
Next
Return B
End Function
#End Region
End Class
End Class
|