• Welcome to Valhalla Legends Archive.
 

Need help deciding when to stop

Started by Tontow, May 16, 2005, 08:27 PM

Previous topic - Next topic

Tontow

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


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


The code works correctly if you type "/join channel", BUT bnet sends the following in one chunck.

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.

And it stops after

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


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.

Newby

I think I understand your question. UBound(arrayofdata) tells you the upperbound of the array.
- Newby

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote<TehUser> Man, I can't get Xorg to work properly.  This sucks.
<torque> you should probably kill yourself
<TehUser> I think I will.  Thanks, torque.

Ringo


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


Then handle each packet in the below sub
(or in the Lower to Upper loop in the DataArrival sub)

Public Sub Parser(data As String)
'data = packet
End Sub


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

Tontow


txtchanlist.Text = tempstring(2) & Chr(32) & tempstring(4) & vbCrLf & txtchanlist.Text


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:

1001 US
1001 USER moogle-perro 0000 [SEXP]
ER Tryout 0010 [CHAT]

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")

Hdx

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)~-~

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

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.

Tontow

Quote from: HdxBmx27 on May 16, 2005, 11:40 PM
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)~-~

The following is unparsed
(note: chan-NEL menu)

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.



Hdx

Seems to me that your not clearing your buffer when you reconnect :/
~-~(HDX)~-~

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

Tontow

umm, thats not from a reconnect

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.

R.a.B.B.i.T

Quote from: Tontow on May 16, 2005, 08:27 PM
    Case Else '"phraseing error" display raw data
AHHHHHHHHHHHHHHHHHHH!!!!!!!!!
PET PEEVE!!!!!

parsing*