• Welcome to Valhalla Legends Archive.
 

[VB6]Bot wont join channels & nothin shows up on sceen.

Started by Learn, May 03, 2004, 03:11 PM

Previous topic - Next topic

Learn

I've recently started programming with VB and I really don't understand everything yet. And this error is baffling me.

Heres the details. I can type on the bot and send it to Bnet (it shows up in channel and i can whisper people) but i cant join channels with the /join command and i cant see the people chatting in Public Chat 1 (this is just a chat bot, I haven't gotten to the complexities of hashes yet) Also, nothing shows up in the Rich Text Box except "Connecting..." and "Connected as 'username' " but thats not Bnet.

Anyway here's the relevant code:

Private Sub sckBNET_DataArrival(ByVal bytesTotal As Long)
   Dim i&
   Dim a() As String
   Dim e() As String
   Dim p() As String
       sckBNET.GetData s, vbString
       a = Split(s, Chr(13))
       For i = LBound(a) To UBound(a)
           If Left(a(i), 1) = Chr(10) Then
           a(i) = Right(a(i), Len(a(i)) - 1)
           If InStr(1, a(i), Chr(32)) > 0 Then
           e = Split(a(i), Chr(32), 1)
           Else
           ReDim e(0)
           e(0) = a(i)
           End If
           Select Case e(0)
           Case "1001"
                   p = Split(a(i), Chr(32), 5)
                   p(4) = Mid(p(4), 2, Len(p(4)) - 2)
                   AddChat vbYellow, p(2) & " is in the channel."
                   'p(2) in channel
               Case "1002"
                   p = Split(a(i), Chr(32), 5)
                   p(4) = Mid(p(4), 2, Len(p(4)) - 2)
                   AddChat vbGreen, p(2) & " joined the channel."
                   'Join // p(2) joined channel
               Case "1003"
                   p = Split(a(i), Chr(32), 3)
                   AddChat vbRed, p(2) & " left the channel."
                   'Left // p(2) left Channel
               Case "1004"
                   p = Split(a(i), Chr(32), 4)
                   AddChat vbYellow, "<From:" & p(2) & ">", vbgray, Mid(p(4), 2, Len(p(4)) - 2)
                   'Whisper From
               Case "1005"
                   p = Split(a(i), Chr(32), 4)
                   AddChat vbYellow, "<" & p(2) & ">", vbWhite, Mid(p(4), 2, Len(p(4)) - 2)
                   'User // p(2) Message
               Case "1007"
                   p = Split(a(i), Chr(32), 2)
                   'Mid(p(2), 2, Len(p(2)) - 2) Channel
               Case "1009"
                   p = Split(a(i), Chr(32), 3)
                   'p(2) Flags
               Case "1010"
                   p = Split(a(i), Chr(32), 4)
                   AddChat vbCyan, "<To:" & p(2) & ">", vbgray, Mid(p(4), 2, Len(p(4)) - 2)
                   'Whisper to
               Case "1018"
                   p = Split(a(i), Chr(32), 2)
                   AddChat vbYellow, Mid(p(2), 2, Len(p(2)) - 2)
               Case "1019"
                   p = Split(a(i), Chr(32), 2)
                   AddChat vbRed, "Error: " & Mid(p(2), 2, Len(p(2)) - 2)
                   'Error
               Case "1023"
                   p = Split(a(i), Chr(32), 4)
                   AddChat vbYellow, "<" & p(2) & " " & Mid(p(4), 2, Len(p(4)) - 2) & ">"
                   'Emote
               Case "2000"
                   '
               Case "2010"
                   p = Split(a(i), Chr(32), 2)
                   'p(2) Logon
               Case Else
                   '
               End Select
       Next i
End Sub


Also, I'm getting the error "Next without for" any suggestions?

And thanks for any help.

FuzZ

Quote from: Learn on May 03, 2004, 03:11 PM
I've recently started programming with VB and I really don't understand everything yet. And this error is baffling me.

Heres the details. I can type on the bot and send it to Bnet (it shows up in channel and i can whisper people) but i cant join channels with the /join command and i cant see the people chatting in Public Chat 1 (this is just a chat bot, I haven't gotten to the complexities of hashes yet) Also, nothing shows up in the Rich Text Box except "Connecting..." and "Connected as 'username' " but thats not Bnet.

Anyway here's the relevant code:


Also, I'm getting the error "Next without for" any suggestions?

And thanks for any help.

You're missing an End If

       For i = LBound(a) To UBound(a)
           If Left(a(i), 1) = Chr(10) Then
           a(i) = Right(a(i), Len(a(i)) - 1)
           If InStr(1, a(i), Chr(32)) > 0 Then
           e = Split(a(i), Chr(32), 1)
           Else
           ReDim e(0)
           e(0) = a(i)
           End If
           Select Case e(0)
           Case "1001"
                   p = Split(a(i), Chr(32), 5)
                   p(4) = Mid(p(4), 2, Len(p(4)) - 2)
                   AddChat vbYellow, p(2) & " is in the channel."
                   'p(2) in channel
               Case "1002"
                   p = Split(a(i), Chr(32), 5)
                   p(4) = Mid(p(4), 2, Len(p(4)) - 2)
                   AddChat vbGreen, p(2) & " joined the channel."
                   'Join // p(2) joined channel
               Case "1003"
                   p = Split(a(i), Chr(32), 3)
                   AddChat vbRed, p(2) & " left the channel."
                   'Left // p(2) left Channel
               Case "1004"
                   p = Split(a(i), Chr(32), 4)
                   AddChat vbYellow, "<From:" & p(2) & ">", vbgray, Mid(p(4), 2, Len(p(4)) - 2)
                   'Whisper From
               Case "1005"
                   p = Split(a(i), Chr(32), 4)
                   AddChat vbYellow, "<" & p(2) & ">", vbWhite, Mid(p(4), 2, Len(p(4)) - 2)
                   'User // p(2) Message
               Case "1007"
                   p = Split(a(i), Chr(32), 2)
                   'Mid(p(2), 2, Len(p(2)) - 2) Channel
               Case "1009"
                   p = Split(a(i), Chr(32), 3)
                   'p(2) Flags
               Case "1010"
                   p = Split(a(i), Chr(32), 4)
                   AddChat vbCyan, "<To:" & p(2) & ">", vbgray, Mid(p(4), 2, Len(p(4)) - 2)
                   'Whisper to
               Case "1018"
                   p = Split(a(i), Chr(32), 2)
                   AddChat vbYellow, Mid(p(2), 2, Len(p(2)) - 2)
               Case "1019"
                   p = Split(a(i), Chr(32), 2)
                   AddChat vbRed, "Error: " & Mid(p(2), 2, Len(p(2)) - 2)
                   'Error
               Case "1023"
                   p = Split(a(i), Chr(32), 4)
                   AddChat vbYellow, "<" & p(2) & " " & Mid(p(4), 2, Len(p(4)) - 2) & ">"
                   'Emote
               Case "2000"
                   '
               Case "2010"
                   p = Split(a(i), Chr(32), 2)
                   'p(2) Logon
               Case Else
                   '
               End Select
       Next i


Should be


       For i = LBound(a) To UBound(a)
           If Left(a(i), 1) = Chr(10) Then
           a(i) = Right(a(i), Len(a(i)) - 1)
           If InStr(1, a(i), Chr(32)) > 0 Then
           e = Split(a(i), Chr(32), 1)
           Else
           ReDim e(0)
           e(0) = a(i)
           End If
           Select Case e(0)
           Case "1001"
                   p = Split(a(i), Chr(32), 5)
                   p(4) = Mid(p(4), 2, Len(p(4)) - 2)
                   AddChat vbYellow, p(2) & " is in the channel."
                   'p(2) in channel
               Case "1002"
                   p = Split(a(i), Chr(32), 5)
                   p(4) = Mid(p(4), 2, Len(p(4)) - 2)
                   AddChat vbGreen, p(2) & " joined the channel."
                   'Join // p(2) joined channel
               Case "1003"
                   p = Split(a(i), Chr(32), 3)
                   AddChat vbRed, p(2) & " left the channel."
                   'Left // p(2) left Channel
               Case "1004"
                   p = Split(a(i), Chr(32), 4)
                   AddChat vbYellow, "<From:" & p(2) & ">", vbgray, Mid(p(4), 2, Len(p(4)) - 2)
                   'Whisper From
               Case "1005"
                   p = Split(a(i), Chr(32), 4)
                   AddChat vbYellow, "<" & p(2) & ">", vbWhite, Mid(p(4), 2, Len(p(4)) - 2)
                   'User // p(2) Message
               Case "1007"
                   p = Split(a(i), Chr(32), 2)
                   'Mid(p(2), 2, Len(p(2)) - 2) Channel
               Case "1009"
                   p = Split(a(i), Chr(32), 3)
                   'p(2) Flags
               Case "1010"
                   p = Split(a(i), Chr(32), 4)
                   AddChat vbCyan, "<To:" & p(2) & ">", vbgray, Mid(p(4), 2, Len(p(4)) - 2)
                   'Whisper to
               Case "1018"
                   p = Split(a(i), Chr(32), 2)
                   AddChat vbYellow, Mid(p(2), 2, Len(p(2)) - 2)
               Case "1019"
                   p = Split(a(i), Chr(32), 2)
                   AddChat vbRed, "Error: " & Mid(p(2), 2, Len(p(2)) - 2)
                   'Error
               Case "1023"
                   p = Split(a(i), Chr(32), 4)
                   AddChat vbYellow, "<" & p(2) & " " & Mid(p(4), 2, Len(p(4)) - 2) & ">"
                   'Emote
               Case "2000"
                   '
               Case "2010"
                   p = Split(a(i), Chr(32), 2)
                   'p(2) Logon
               Case Else
                   '
               End Select
            End If
       Next i


I'm sure the tabbing isn't correct but, whatever.

Hope this helps you :)

Edit-> I think I made a mistake, yes I did. Fixed.

Edit-> Removed Code from his quote.

Learn


Dyndrilliac

#3
For the joining channels part, sending text and joining channels are two completely different events, so it makes sense you aren't joining channels when you send the command if all your sending is text (Note: This is AFAIK...).

I don't quite remember if you have to send something before this, but if you refer to BnetDocs, you see there is a packet labeled SID_JOINCHANNEL. It is sent from the client (you) to the server (bnet).
Quote(DWORD)   Flags
(STRING)  Channel
That's the structure of 0x0C, SID_JOINCHANNEL. To join channels, send that with the appropriate information.

Hope that helped, if only slightly.

Note: At the time I'm writing this I am assuming your simply sending 0x0E with just text, and further assuming that joining channels using /rejoin doesn't work that way. So far I've used JOINCHANNEL, it seemed common sense at the time.
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

Newby

Looks like a chat connection to me. Not a binary one.
- 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.

Learn


Eli_1

To join a channel you would just do something like:

Socket.SendData "/join " & ChannelNameStoredHere vbCrLf
DoEvents '// DoEvents is optional...

Learn

Thanks Eli_1

ATHF owns =]

Here's the module code maybe this will help more:

Public Sub AddChat(ParamArray saElements() As Variant)
On Error Resume Next
Dim i As Integer
  If Len(frmMain.rtbChannel) > 50000 Then
      frmMain.rtbChannel.Text = ""
      AddChat vbYellow, "Chat screen auto cleared!"
  End If
  With frmMain.rtbChannel
      .SelStart = Len(.Text)
      .SelLength = 0
      .SelColor = vbWhite
      .SelText = "[" & Format(Time, "hh:mm:ss") & "] "
      .SelStart = Len(.Text)
  End With
  For i = LBound(saElements) To UBound(saElements) Step 2
      With frmMain.rtbChannel
          .SelStart = Len(.Text)
          .SelLength = 0
          .SelColor = saElements(i)
          .SelText = saElements(i + 1) & Left$(vbCrLf, -2 * CLng((i + 1) = UBound(saElements)))
          .SelStart = Len(.Text)
      End With
  Next i
End Sub


by the way the

   sckBNET.SendData "/join & ChannelNameStoredHere & "
   DoEvents '// DoEvents is optional...
End Sub


didnt work

Eli_1

Quote from: Learn on May 04, 2004, 03:39 PM
Thanks Eli_1

ATHF owns =]

Here's the module code maybe this will help more:

Public Sub AddChat(ParamArray saElements() As Variant)
. . . <code block>
End Sub


by the way the

   sckBNET.SendData "/join & ChannelNameStoredHere & "
   DoEvents '// DoEvents is optional...
End Sub


didnt work

That's because the code I gave you wasn't    sckBNET.SendData "/join & ChannelNameStoredHere & "
   DoEvents '// DoEvents is optional...
End Sub


It's suppost to be
sckBNET.SendData "/join " & ChannelNameStoredHere & vbCrLf

Where 'ChannelNameStoredHere' is a String which has a channel name as it's value. You won't be able to join private channels, so make sure it's something like "Public chat ub3r hax0r".

And as for the AddChat code, I've never used .SelLength = 0 before. So try removing those. And try calling it like this once:

Dim blah(1)
blah(0) = RGB(0, 255, 0)
blah(1) = "This is a test."
AddChat blah


Edit: Also, eww@On Error Resume Next. Try to get into the habit of checking for errors and handling them as needed, as opposed to just ignoring them.

Dyndrilliac

#9
Eh, modify it so the quotes aren't around the variable name.

'Pseudo Code
sckBnet.SendData "/join " & ChannelVariableNameHere
DoEvents


edit:
* Dyndrilliac = too slow :P
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

Eli_1

Quote from: Dyndrilliac on May 04, 2004, 04:00 PM
Eh, modify it so the quotes aren't around the variable name.

'Pseudo Code
sckBnet.SendData "/join " & ChannelVariableNameHere
DoEvents


You have to make sure you append vbCrLF onto the end of it. If you don't, battle.net will assume you have more data to send to it. I believe this is so people can use telnet to log onto the server, because vbCrLf (carriage return -- \r\n?) won't be sent untill enter is pressed.

Telnet sends the data you input as you input it. Bnet needs to wait for the carriage return, or the output would look like this.
Quote
<Eli_1> /
<Eli_1> j
<Eli_1> o
<Eli_1> i
<Eli_1> n
<Eli_1>  
ect...

'Pseudo Code
sckBnet.SendData "/join " & ChannelVariableNameHere & vbCrLF
'// bwahaha, I'm way too fast for you, Dynd. :P
DoEvents



Edit: What does CrLf stand for?
Carriage Return ________ ________
Carriage Return Line Feed??

Learn

Ok, I did:

Dim blah(1)
blah(0) = RGB(0, 255, 0)
blah(1) = "This is a test."
AddChat blah


And I got:

Compile Error:

Duplicate declaration in certain scope.

Eli_1

LoL, I think that would mean you have a variable named blah already. Use something other than blah(), it was just an example. blah2 perhaps?

Learn

Holyshit.. I just hit connect on my bot and the screen filled with the time thing( [HH:MM:SS] not the H,M,S things but the actual time), and VB froze.  :o

Edit: If ChannelVariableNameHere is a string, shouldn't i dim it is a string?

Eli_1

Quote
Edit: If ChannelVariableNameHere is a string, shouldn't i dim it is a string?
Of course...  ::)