Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: brew on April 01, 2007, 06:43 AM

Title: BNCS 0x09! help please.
Post by: brew on April 01, 2007, 06:43 AM
So on Bnetdocs, I looked up the 0x09 for getting a game list, and apparently there are four "product specific conditions", and it tells you what only the first condition is (game type), and none of the others.  Does anyone have any idea what the other three are?
Title: Re: BNCS 0x09! help please.
Post by: Ersan on April 01, 2007, 10:24 AM
Try using search (http://forum.valhallalegends.com/index.php?action=search) before asking dumb questions...
Title: Re: BNCS 0x09! help please.
Post by: brew on April 01, 2007, 12:35 PM
Thanks, ersan. I didn't find out what they're for, but I found a topic of another person trying to parse the 0x09 and he showed his send0x09 sub... i'm still not sure where he got the values for the other 3 product specific parameters but it seems to be working for me.
Title: Re: BNCS 0x09! help please.
Post by: l2k-Shadow on April 01, 2007, 01:20 PM
Why don't you use a packet logger and see what the game sends?
Title: Re: BNCS 0x09! help please.
Post by: brew on April 01, 2007, 04:10 PM
Because I have no idea where my starcraft disk is
Title: Re: BNCS 0x09! help please.
Post by: Explicit on April 01, 2007, 04:17 PM
Quote from: brew on April 01, 2007, 04:10 PM
Because I have no idea where my starcraft disk is

That still isn't an excuse.
Title: Re: BNCS 0x09! help please.
Post by: Barabajagal on April 01, 2007, 04:27 PM
Packet.ClearOutbound
    s = &H0
    G = &H0
    If Config.Game = STAR Or Config.Game = SEXP Or Config.Game = SSHR Or Config.Game = JSTR Then
        l = &H30
    Else
        l = &H0
    End If
    C = &HFF
    Packet.InsertDWORD G
    Packet.InsertDWORD l
    Packet.InsertDWORD s
    Packet.InsertDWORD C
    Packet.InsertNTString GameName
    Packet.InsertNTString GamePass
    Packet.InsertNTString ""
Title: Re: BNCS 0x09! help please.
Post by: brew on April 01, 2007, 08:27 PM
Quote from: [RealityRipple] on April 01, 2007, 04:27 PM
Packet.ClearOutbound
    s = &H0
    G = &H0
    If Config.Game = STAR Or Config.Game = SEXP Or Config.Game = SSHR Or Config.Game = JSTR Then
        l = &H30
    Else
        l = &H0
    End If
    C = &HFF
    Packet.InsertDWORD G
    Packet.InsertDWORD l
    Packet.InsertDWORD s
    Packet.InsertDWORD C
    Packet.InsertNTString GameName
    Packet.InsertNTString GamePass
    Packet.InsertNTString ""

There are a number of things I would like to comment about that:
1. For the game statstring, it should not be "". It should be vbNullString, always, for many different reasons.
2. The first "dword" is acually two words: The first being the game type which you want to get the list for, the values for this are the same as in the 0x1C statstring. (for example, 0x000A = Use Map Settings)
3. The last dword is acually the max number of games you want to be returned.
4. "If Config.Game = STAR Or Config.Game = SEXP Or Config.Game = SSHR Or Config.Game = JSTR Then"
Uh.... you should consider using short circuit evaluation or nested ifs.


Public Sub Send0x09()
    With pbuffer
        .InsertWORD &HA              'Product Specific 1
        .InsertWORD 0                'Product Specific 2
        .InsertDWORD &H1F            'Product Specific 3
        .InsertDWORD 0               'Product Specific 4
        .InsertDWORD 10              'Max games
        .InsertNTString vbNullString 'Game Name
        .InsertNTString vbNullString 'Game Password
        .InsertNTString vbNullString 'Game Statstring
        .sendPacket &H9
    End With
    AddChat vbYellow, "Sending 0x09..."
End Sub

is the code I'm using.

Thank you for helping, reality.
Title: Re: BNCS 0x09! help please.
Post by: Barabajagal on April 01, 2007, 08:44 PM
What I have works just fine for listing all games. The last DWord (C) is not max games for D1, it's what level to display at. When set to &HFF, it lists games for all levels, and lists all games for all other clients. As for not using vbNullString... I don't know why I didn't. Momentary lapse of reason I guess.
Title: Re: BNCS 0x09! help please.
Post by: warz on April 01, 2007, 09:14 PM
"" equates to a 'null string', most likely. i'd assume it's just the null byte, as well as vbnullstring.
Title: Re: BNCS 0x09! help please.
Post by: Barabajagal on April 01, 2007, 09:55 PM
No, "" is not a null string in Visual Basic. We've already had this discussion.
Title: Re: BNCS 0x09! help please.
Post by: warz on April 01, 2007, 10:11 PM
Quote from: [RealityRipple] on April 01, 2007, 09:55 PM
No, "" is not a null string in Visual Basic. We've already had this discussion.

So, what does it equate to?
Title: Re: BNCS 0x09! help please.
Post by: Barabajagal on April 01, 2007, 10:16 PM
A null terminator (00) I guess? Read in this topic (http://forum.valhallalegends.com/index.php?topic=16511) for more info.

Edit: There was another topic somewhere else where we went more in depth with it, but I can't find it...
Title: Re: BNCS 0x09! help please.
Post by: warz on April 01, 2007, 10:45 PM
Quote from: [RealityRipple] on April 01, 2007, 10:16 PM
A null terminator (00) I guess? Read in this topic (http://forum.valhallalegends.com/index.php?topic=16511) for more info.

Edit: There was another topic somewhere else where we went more in depth with it, but I can't find it...

Assuming we're talking about string related functions, is a single null terminating byte not a null string? A function looking for the null terminator in a string would stop on the first byte either way. '00' (a null terminator) and '00 00 00 00' (a null terminated array of null bytes) are both evaluated as a single null terminator, or null string (meaning a string with no content, other than the terminator) which might look like "" in-code. So, you know that "" does not equate to a null string, but you say it equates to a null terminator? What's the difference?

Edit: After reading that post, I now know that visual basic stores strings as unicode.
Title: Re: BNCS 0x09! help please.
Post by: Barabajagal on April 01, 2007, 10:47 PM
"" takes up memory, vbNullString doesn't.

Edit: http://forums.devx.com/showthread.php?t=70074 might clear some things up.
Title: Re: BNCS 0x09! help please.
Post by: warz on April 01, 2007, 10:56 PM
Quote from: [RealityRipple] on April 01, 2007, 10:47 PM
"" takes up memory, vbNullString doesn't.

Edit: http://forums.devx.com/showthread.php?t=70074 might clear some things up.

both take up memory. unicode strings just take up a lot more. 4 + (length_of_string * 2), in fact. so, the header of a unicode string would be why "" would not equate to a single null terminating byte.
Title: Re: BNCS 0x09! help please.
Post by: Barabajagal on April 01, 2007, 11:04 PM
Did you even read the link?
Title: Re: BNCS 0x09! help please.
Post by: UserLoser on April 02, 2007, 12:40 PM
Brew, find your Starcraft CD and get to work.  There's plenty of information out there about this message and it has been covered numerous of times.

Quote from: [RealityRipple] on April 01, 2007, 09:55 PM
No, "" is not a null string in Visual Basic. We've already had this discussion.

Truth spoken
Title: Re: BNCS 0x09! help please.
Post by: warz on April 02, 2007, 01:31 PM
No, I didn't read the forum link you gave, but I read this, more helpful, page - http://www.aivosto.com/vbtips/stringopt2.html#memorylayout
Title: Re: BNCS 0x09! help please.
Post by: brew on April 02, 2007, 05:17 PM
Quote from: UserLoser on April 02, 2007, 12:40 PM
Brew, find your Starcraft CD and get to work.  There's plenty of information out there about this message and it has been covered numerous of times.

If there's plenty of information out there about this message, then how come I have to find my Starcraft CD and get to work? Shouldn't I just be able to use the search feature of this forum?

Also...

FF 09 75 04 'header
0A 00 'game type
00 00 'parameter
0A 00 01 00 'unknown
09 04 'address family
00 00 02 00 'address family?
C5 2C 'port?
A2 53 66 3F 'ip address
00 00 00 00 'sin_zero
00 00 00 00 'sin_zero
04 00 00 00 'game status
45 00 00 00 'elapsed time
31 32 30 30 30 20 68 79 64 72 61 73 21 21 20 44 4F 4E 54 20 53 55 43 00 'game name
00  'game password
2C 31 34 2C 31 37 2C 36 2C 2C 61 2C 2C 31 2C 62 66 37 39 33 33 61 61 2C 36 2C 2C 78 44 61 4E 0D 07 48 79 64 72 61 6C 69 73 6B 20 41 74 74 61 63 6B 20 31 32 2C 30 30 30 0D 00 'game statstring


According to bnet docs, half of the IP Address is really where the port would be, same with the address family.. etc, just doesn't make sense. Check for yourself. When really, I believe bnetdocs just might be wrong. I would have posted something about it there, but it doesn't allow the creation of new accounts.... go figure.... and someone PLEASE fix the documentation on the S > C 0x09.
Title: Re: BNCS 0x09! help please.
Post by: Barabajagal on April 02, 2007, 05:36 PM
Working on the Receive side now?

Here's my crappy way of doing it:
Private Sub SID_Recv_GETADVLISTEX()
Dim GameType()   As Long
Dim param()      As Long
Dim IP()         As String
Dim Status()     As Long
Dim Time()       As Long
Dim GameName()   As String
Dim Pass()       As String
Dim Statstring() As String
Dim GameCount    As Long
Dim I            As Long
Dim tmp          As Variant
Dim NewData      As String
Dim TmpPort      As Long
Dim TmpIP        As String
    On Error GoTo Erred
    GameCount = Packet.GetDWORD
    If GameCount = 0 Then
        Select Case Packet.GetDWORD
            Case 1
                RaiseEvent BNetError("Game Doesn't Exist")
            Case 2
                RaiseEvent BNetError("Incorrect Password")
            Case 3
                RaiseEvent BNetError("Game Full")
            Case 4
                RaiseEvent BNetError("Game Already Started")
            Case 6
                RaiseEvent BNetError("Too Many Server Requests")
            Case Else
                RaiseEvent BNetError("Unknown Game Error")
        End Select
    Else
        For I = 0 To GameCount - 1
            ReDim Preserve GameType(I) As Long
            ReDim Preserve param(I) As Long
            ReDim Preserve IP(I) As String
            ReDim Preserve Status(I) As Long
            ReDim Preserve Time(I) As Long
            ReDim Preserve GameName(I) As String
            ReDim Preserve Pass(I) As String
            ReDim Preserve Statstring(I) As String
            GameType(I) = Packet.GetWORD
            param(I) = Packet.GetWORD
            tmp = Packet.GetDWORD
            tmp = Packet.GetWORD
            TmpPort = htons(Packet.GetWORD)
            TmpIP = Packet.GetString(4)
            IP(I) = Asc(Mid$(TmpIP, 1, 1)) & "." & _
                    Asc(Mid$(TmpIP, 2, 1)) & "." & _
                    Asc(Mid$(TmpIP, 3, 1)) & "." & _
                    Asc(Mid$(TmpIP, 4, 1)) & ":" & TmpPort
            tmp = Packet.GetDWORD
            tmp = Packet.GetDWORD
            Status(I) = Packet.GetDWORD
            Time(I) = Packet.GetDWORD
            GameName(I) = Packet.GetNTString
            Pass(I) = Packet.GetNTString
            Statstring(I) = Packet.GetNTString
            If Config.Game = WAR3 Or Config.Game = W3XP Then
                DecodeMapData Mid$(Statstring(I), 2), NewData
                Statstring(I) = Mid$(NewData, 21)
            End If
        Next I
        RaiseEvent GameListing(GameType(), param(), IP(), Status(), Time(), GameName(), Pass(), Statstring())
    End If
Exit Sub
Erred:
    RaiseEvent CritError(Err.Description, Err.Number, Err.Source, "SID_Recv_GETADVLISTEX")
End Sub


A few notes: htons is an API call ( Private Declare Function htons Lib "wsock32.dll" (ByVal hostshort As Long) As Long ), anything that says tmp=something means the value isn't important (I set it to a variable to make debug.print easier and see what they are). DecodeMapData is a function I found on here (I think it was in Java and I had to port it to VB).

Edit: Some more notes I forgot to mention: The first unknown (DWORD) is the Language ID (Like 1033 (0x409) for enUS). The second unknown (WORD) is usually 2. The last two (DWORDS) are usually 0's.
Title: Re: BNCS 0x09! help please.
Post by: UserLoser on April 02, 2007, 08:36 PM
Quote from: brew on April 02, 2007, 05:17 PM
According to bnet docs, half of the IP Address is really where the port would be, same with the address family.. etc, just doesn't make sense. Check for yourself. When really, I believe bnetdocs just might be wrong. I would have posted something about it there, but it doesn't allow the creation of new accounts.... go figure.... and someone PLEASE fix the documentation on the S > C 0x09.

Last time I checked there was nothing wrong with the documentation on S->C 0x09.  What does BnetDocs say as opposed to that log you just posted?  I can't view BnetDocs at the moment.  That log you posted with comments next to it look ok, are those comments lining up with the formatting BnetDocs has?
Title: Re: BNCS 0x09! help please.
Post by: Barabajagal on April 02, 2007, 08:53 PM
http://www.aznsoulja.com/bnetdocs/content8e9c.html?Section=m&Code=10

Except, the third field (Unknown) is the language ID of the game creator.
Title: Re: BNCS 0x09! help please.
Post by: brew on April 02, 2007, 08:54 PM
Quote from: UserLoser on April 02, 2007, 08:36 PM
Last time I checked there was nothing wrong with the documentation on S->C 0x09.  What does BnetDocs say as opposed to that log you just posted?  I can't view BnetDocs at the moment.  That log you posted with comments next to it look ok, are those comments lining up with the formatting BnetDocs has?

No, They are not. According to bnet docs, this would how the data would be parsed:


For each list item:
(WORD) Game Type
(WORD) Parameter
(DWORD) Unknown
(WORD) Address Family (Always AF_INET)
(WORD) Port
(DWORD) Host's IP
(DWORD) sin_zero (0)
(DWORD) sin_zero (0)
(DWORD) Game Status
(DWORD) Elapsed time (in seconds)
(STRING) Game name
(STRING) Game password
(STRING) Game statstring

FF 09 75 04 'header
0A 00 'game type
00 00 'parameter
0A 00 01 00 'unknown
09 04 'address family
00 00 'port <---this is where i knew it had to be wrong, the port just can't be 0.
02 00 C5 2C 'hosts ip
A2 53 66 3F 'sin_zero
00 00 00 00 'sin_zero
00 00 00 00 'game status
04 00 00 00 'elapsed time
45 00 00 00 31 32 30 30 30 20 68 79 64 72 61 73 21 21 20 44 4F 4E 54 20 53 55 43 00 'game name
00 'game password
2C 31 34 2C 31 37 2C 36 2C 2C 61 2C 2C 31 2C 62 66 37 39 33 33 61 61 2C 36 2C 2C 78 44 61 4E 0D 07 48 79 64 72 61 6C 69 73 6B 20 41 74 74 61 63 6B 20 31 32 2C 30 30 30 0D 00 'game statstring


As you can obviously see, this is an entire 4 bytes off! very misleading.

And btw, thank you Reality for the help with parsing it.
Title: Re: BNCS 0x09! help please.
Post by: Barabajagal on April 02, 2007, 09:04 PM
Brew... you're reading the documentation wrong. The header is followed by a DWORD with the number of games listed.
Title: Re: BNCS 0x09! help please.
Post by: UserLoser on April 02, 2007, 09:23 PM
Quote from: [RealityRipple] on April 02, 2007, 09:04 PM
Brew... you're reading the documentation wrong. The header is followed by a DWORD with the number of games listed.

lol  ::)
Title: Re: BNCS 0x09! help please.
Post by: brew on April 03, 2007, 02:18 PM
oops......  ::) Then I assume the game type would be.... the first part of the "unknown". okay thank you lol :( i feel like a moron (which i should)