Avatar wrote:
I am confused :)
I thought I talk to the gamespy masterserver, then I get a challenge key. I ecrypt this key using your vb.net implementation. with this new decrypted key, I can ask for the serverlist.
Yes thats correct, but you get the server list decrypted, the encryption is beeing done at your computer.
You open connection, gamespy send you a "Secure key", you encrypt that key and get a "valid", now you send a new packet that include the valid key, the response will be a decrypted server list, at this point you send it for encryption.
Here is my full code, obviusly you cant use it in C but you might get an idea how its done, you can use the same "challange" and "gamekey".
Code:
Imports System.Text
Imports System.IO
Imports System.Net.Sockets
Public Class GameSpy
'//Secure Key Encryption
Dim sA As New gsmalg2
'//Serverlist Encryption
Declare Ansi Function Encode Lib "C:\enctype2_decoder.dll" Alias "enctype2_wrapper" _
(ByVal gamekey() As Byte, ByVal buffer() As Byte, ByVal len As Integer) As Integer
Private Sub cb_ReceiveServers_click(ByVal Sender As System.Object, ByVal E As System.EventArgs) Handles cb_ReceiveServers.Click
Dim TcpClient As New TcpClient()
Dim HandShake(22) As Byte
Lb_Servers.Items.Clear()
TcpClient.Connect("207.38.11.34", 28900)
Dim Reader As New StreamReader(TcpClient.GetStream, Encoding.Default, False)
'//Open Conection, Receive Secure key & Encode
TcpClient.GetStream.Read(HandShake, 0, 21)
Dim Valid As String = sA.Valid(Encoding.Default.GetString(HandShake).Substring(15, 6))
'//Send Challange
Dim Challange() As Byte = createPacket(Valid, "", True)
TcpClient.GetStream.Write(Challange, 0, Challange.Length)
'//Receive Packet
Dim Data() As Byte = Encoding.Default.GetBytes(Reader.ReadToEnd.Replace(Chr(0), " ").Replace(Chr(1), " ").Trim)
TcpClient.GetStream.Close()
'//enctype2_wrapper!
Dim Key() As Byte = Encoding.Default.GetBytes("d4kZca"), _
Length As Integer = Encode(Key, Data, Data.Length), _
S As String = Encoding.Default.GetChars(Data)
'//IP & Port's to Lisbox (-7 Becouse of "\final" at end)
For i As Integer = 0 To Length - 7 Step 6
Lb_Servers.Items.Add( _
Asc(S(i)) & "." & Asc(S(i + 1)) & "." & Asc(S(i + 2)) & "." & Asc(S(i + 3)) & ":" & Asc(S(i + 4)) * 256 + Asc(S(i + 5)))
Next
Me.Text = "Server IP:s ( " & Lb_Servers.Items.Count & " )"
End Sub
Public Function createPacket _
(ByVal Valid As String, Optional ByVal Filter As String = "", Optional ByVal Compressed As Boolean = True) As Byte()
createPacket = Encoding.Default.GetBytes( _
"\gamename\gamespy2\gamever\20603020\enctype\2\validate" & Valid & _
"\final\list" & IIf(Compressed = True, "cmp", "") & _
"\gamename\battlefield2" & IIf(Len(Filter) > 0, "\where" & Filter, "") & "\final")
End Function
End Class