Valhalla Legends Forums Archive | Visual Basic Programming | Need help deciding when to stop

AuthorMessageTime
Tontow
I can't seem to get it right, so here is my code thus far.

[code]
Public Sub sckclient_DataArrival(ByVal bytesTotal As Long)
Dim tempdata As String
Dim tempstring() As String, tempstring2() As String
Dim index As Integer
index = 0

sckclient.GetData tempdata
txtmainchat.Text = tempdata & vbCrLf & txtmainchat.Text

'phrase chat string events
'message format; (PacketID/event id) ((event/ message type/) (if join or user client type)) (user) (flag) (message in " ")
tempstring2 = Split(tempdata, vbCrLf) ' split each line

Do Until Right(tempstring2(index), 1) = ""
Select Case Left(tempstring2(index), 4)
    Case "1001" 'user already in channel: 1001 USER Tryout 0010 [CHAT]
        'MsgBox ("boom")
       
        tempstring = Split(tempstring2(index), " ")
        txtchanlist.Text = tempstring(2) & Chr(32) & tempstring(4) & vbCrLf & txtchanlist.Text
    Case "1002" 'join
    Case "1003" 'leave
    Case "1004" 'you got wisper
    Case "1005" 'talk
    Case "1006" 'admin, make announcement
    Case "1007" 'channel
    Case "1009" '????
    Case "1010" 'you sent whipser
    Case "1013" 'channel is full
    Case "1014" 'channel dose not exist
    Case "1015" 'channel is restricted
    Case "1018" 'info, normally sent right after logon?
    Case "1019" 'error
    Case "1023" 'emote
    Case Else '"phraseing error" display raw data
End Select
'MsgBox (tempstring2(index))
index = index + 1
Loop

End Sub
[/code]

The code works correctly if you type "/join channel", BUT bnet sends the following in one chunck.
[code]
2010 NAME me]r[lin
1007 CHANNEL "Public Chat 1"
1001 USER NetMasters@Lordaeron 0000 [W3XP]
1001 USER Nikkole@Lordaeron 0000 [WAR3]
1001 USER Melee4Life 0000 [D2XP]
1001 USER Tryout 0010 [CHAT]
1001 USER sonyhan@Lordaeron 0000 [W3XP]
1001 USER moogle-perro 0000 [SEXP]
1001 USER Savanx2000@Lordaeron 0000 [WAR3]
1001 USER mail-moogle 0000 [SEXP]
1001 USER me]r[lin 0010 [CHAT]
1018 INFO "Welcome to Battle.net!"
1018 INFO "This server is hosted by AT&T."
1018 INFO "There are currently 301 users in C
Connection from [***.***.***.*** (ip address)]

Enter your account name and password.
Use 'anonymous' if you only want to issue queries.
[/code]
And it stops after
[code]
Enter your account name and password.
Use 'anonymous' if you only want to issue queries.
[/code]

Is there any way to find out if there is a next element in an array without getting a subscript out of range error?

note: txtmainchat.Text is a text box where all chat is displayed and txtchanlist.Text
is a text box where all the users in the chat room are listed.
May 17, 2005, 1:27 AM
Newby
I think I understand your question. UBound(arrayofdata) tells you the upperbound of the array.
May 17, 2005, 1:40 AM
Ringo
[code]
Private Sub sckclient_DataArrival(ByVal bytesTotal As Long)
Dim tempdata As String
Dim tempstring2 As Variant
  Me.sckclient.GetData tempdata
      tempstring2 = Split(tempdata, vbCrLf)
         'bases an array on the number of packets in the clump split by vbCrLf
         For i = LBound(tempstring2) To UBound(tempstring2)                
             Parser tempstring2(i) 'send each message to a parser sub
         Next i
End Sub
[/code]

Then handle each packet in the below sub
(or in the Lower to Upper loop in the DataArrival sub)
[code]
Public Sub Parser(data As String)
'data = packet
End Sub
[/code]

I cant see any reassion why the above code would cause a subscript out of range error, but i havent tested it so i help it works/helps
May 17, 2005, 3:45 AM
Tontow
[code]
txtchanlist.Text = tempstring(2) & Chr(32) & tempstring(4) & vbCrLf & txtchanlist.Text
[/code]

though it happens almost rarely, sometimes battlenet will send part of a string/packet then a full packet then the rest of the other packet
ie:
[code]
1001 US
1001 USER moogle-perro 0000 [SEXP]
ER Tryout 0010 [CHAT]
[/code]
and so when it trys tempstring(4), a subscript out of range error occurs; its going to be a pain working in a fix if I can manage to figure out how to do it. (I'd rather not use "on error resume next")
May 17, 2005, 4:37 AM
HdxBmx27
Tyhe only way I know of handeling a mal-formed packet is simply droping it before you overflow your buffer :/
Not that i have EVER in all my time w/ b.net programming have ever recived a mal-formed packet unless i parsed them wrong :/
~-~(HDX)~-~
May 17, 2005, 4:40 AM
K
Do the following algorithm:

have a static buffer, MyBuff;
whenever you receive data from Battle.Net, append it to MyBuff;
then, while MyBuff contains a Carriage Return / Line Feed, take the first line out of the buffer and parse it.  Continue until there isn't a CrLf character left.

This way, you will only parse complete elements from the stream; incomplete elements will be buffered until they are completed.
May 17, 2005, 8:48 AM
Tontow
[quote author=HdxBmx27 link=topic=11606.msg112707#msg112707 date=1116304806]
Not that i have EVER in all my time w/ b.net programming have ever recived a mal-formed packet unless i parsed them wrong :/
~-~(HDX)~-~
[/quote]

The following is unparsed
(note: chan-NEL menu)
[code]
nel menu."

Username: Password:

2010 NAME me]r[lin
1007 CHANNEL "Public Chat 1"
1001 USER Abunai52@Lordaeron 0000 [W3XP]
1001 USER DarkDragon9092@Lordaeron 0000 [W3XP]
1001 USER mikeyman87@Lordaeron 0000 [W3XP]
1001 USER Gram 0010 [CHAT]
1001 USER me]r[lin 0010 [CHAT]
1018 INFO "Welcome to Battle.net!"
1018 INFO "This server is hosted by AT&T."
1018 INFO "There are currently 292 users in Chat, and 145676 users playing 31378 games on Battle.net."
1019 ERROR "Chatting with this game is restricted to the channels listed in the chan
Connection from [4.242.108.182]

Enter your account name and password.
Use 'anonymous' if you only want to issue queries.

[/code]
May 17, 2005, 6:23 PM
HdxBmx27
Seems to me that your not clearing your buffer when you reconnect :/
~-~(HDX)~-~
May 17, 2005, 7:28 PM
Tontow
umm, thats not from a reconnect
May 17, 2005, 9:48 PM
111787
https://www.x86labs.org/forum/index.php?topic=973.0
https://www.x86labs.org/forum/index.php?topic=974.0

Those might help.  It is important to remember that Packets are terminated by a VbCrLf and aren't always recieved in one event.
May 18, 2005, 12:01 AM
R.a.B.B.i.T
[quote author=Tontow link=topic=11606.msg112680#msg112680 date=1116293243]
[code]    Case Else '"phraseing error" display raw data[/code]
[/quote]AHHHHHHHHHHHHHHHHHHH!!!!!!!!!
PET PEEVE!!!!!

parsing*
May 18, 2005, 6:58 PM

Search