Author | Message | Time |
---|---|---|
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: [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[/code] Also, I'm getting the error "Next without for" any suggestions? And thanks for any help. | May 3, 2004, 8:11 PM |
FuzZ | [quote author=Learn link=board=31;threadid=6638;start=0#msg58276 date=1083615066] 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. [/quote] You're missing an End If [code] 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 [/code] Should be [code] 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 [/code] 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. | May 3, 2004, 9:02 PM |
Learn | What about the first problem? | May 4, 2004, 1:01 AM |
Dyndrilliac | 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[/quote] 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. | May 4, 2004, 3:00 AM |
Newby | Looks like a chat connection to me. Not a binary one. | May 4, 2004, 3:15 AM |
Learn | Yea, It's a chat bot. I don't know binary. | May 4, 2004, 6:42 PM |
Eli_1 | To join a channel you would just do something like: [code] Socket.SendData "/join " & ChannelNameStoredHere vbCrLf DoEvents '// DoEvents is optional... [/code] | May 4, 2004, 6:50 PM |
Learn | Thanks Eli_1 ATHF owns =] Here's the module code maybe this will help more: [code]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[/code] by the way the [code] sckBNET.SendData "/join & ChannelNameStoredHere & " DoEvents '// DoEvents is optional... End Sub[/code] didnt work | May 4, 2004, 8:39 PM |
Eli_1 | [quote author=Learn link=board=31;threadid=6638;start=0#msg58466 date=1083703157] Thanks Eli_1 ATHF owns =] Here's the module code maybe this will help more: [code]Public Sub AddChat(ParamArray saElements() As Variant) . . . <code block> End Sub[/code] by the way the [code] sckBNET.SendData "/join & ChannelNameStoredHere & " DoEvents '// DoEvents is optional... End Sub[/code] didnt work [/quote] That's because the code I gave you wasn't [code] sckBNET.SendData "/join & ChannelNameStoredHere & " DoEvents '// DoEvents is optional... End Sub[/code] It's suppost to be [code] sckBNET.SendData "/join " & ChannelNameStoredHere & vbCrLf[/code] 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: [code] Dim blah(1) blah(0) = RGB(0, 255, 0) blah(1) = "This is a test." AddChat blah [/code] 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. | May 4, 2004, 8:59 PM |
Dyndrilliac | Eh, modify it so the quotes aren't around the variable name. [code]'Pseudo Code sckBnet.SendData "/join " & ChannelVariableNameHere DoEvents[/code] edit: [me=Dyndrilliac]= too slow :P[/me] | May 4, 2004, 9:00 PM |
Eli_1 | [quote author=Dyndrilliac link=board=31;threadid=6638;start=0#msg58472 date=1083704401] Eh, modify it so the quotes aren't around the variable name. [code]'Pseudo Code sckBnet.SendData "/join " & ChannelVariableNameHere DoEvents[/code] [/quote] 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... [/quote] [code]'Pseudo Code sckBnet.SendData "/join " & ChannelVariableNameHere & vbCrLF '// bwahaha, I'm way too fast for you, Dynd. :P DoEvents[/code] Edit: What does CrLf stand for? Carriage Return ________ ________ Carriage Return Line Feed?? | May 4, 2004, 9:02 PM |
Learn | Ok, I did: [code]Dim blah(1) blah(0) = RGB(0, 255, 0) blah(1) = "This is a test." AddChat blah[/code] And I got: Compile Error: Duplicate declaration in certain scope. | May 4, 2004, 9:07 PM |
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? | May 4, 2004, 9:12 PM |
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? | May 4, 2004, 9:16 PM |
Eli_1 | [quote] Edit: If ChannelVariableNameHere is a string, shouldn't i dim it is a string? [/quote] Of course... ::) | May 4, 2004, 9:18 PM |
Learn | Ok is this fine? : [code]Dim ChannelVariableNameHere As String sckBNET.SendData "/join " & ChannelVariableNameHere & vbCrLf DoEvents[/code] | May 4, 2004, 9:27 PM |
Eli_1 | No. The channelname string needs to contain some channel name. That right there would send: "/join " & vbCrLf. Before you send it you need to set ChannelVariableNameHere to something. [code] ChannelVariableNameHere = "Public Chat Drop"[/code] | May 4, 2004, 9:33 PM |
Learn | Oh yea, forgot that. [code]Dim Channel As String Channel = Public_Chat_John sckBNET.SendData "/join " & Channel & vbCrLf DoEvents[/code] Is that ok? | May 4, 2004, 9:36 PM |
Eli_1 | No man. Public_Chat_John is undefined. You need to use quotes. Use "Public Chat Drop". | May 4, 2004, 9:40 PM |
Learn | Ok, sorry if I'm annoying you, but where does the Dim ChannelNameVariable as String blah blah blah go? And i keep getting "Next without for" error with this cod[code]Private Sub txtSend_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then KeyAscii = 0 'No Beep sckBNET.SendData txtSend.Text & vbCrLf txtSend.Text = "" Const VK_RETURN = 13 If KeyAscii = VK_RETURN Then Winsock.SendData txtSend.Text & vbCrLf '/* Notice I'm putting vbCrLf on the end of the text :O */ DoEvents '/* DoEvents isn't needed. I use it '** because on one of my really old '** computers it won't send if I leave DoEvents '** out. Btw, these are all comments, learn. */ End If Next i End Sub[/code] | May 4, 2004, 9:53 PM |
Eli_1 | [quote author=Learn link=board=31;threadid=6638;start=15#msg58494 date=1083707626] Ok, sorry if I'm annoying you, but where does the Dim ChannelNameVariable as String blah blah blah go? And i keep getting "Next without for" error with this cod[code]Private Sub txtSend_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then KeyAscii = 0 'No Beep sckBNET.SendData txtSend.Text & vbCrLf txtSend.Text = "" Const VK_RETURN = 13 If KeyAscii = VK_RETURN Then Winsock.SendData txtSend.Text & vbCrLf '/* Notice I'm putting vbCrLf on the end of the text :O */ DoEvents '/* DoEvents isn't needed. I use it '** because on one of my really old '** computers it won't send if I leave DoEvents '** out. Btw, these are all comments, learn. */ End If Next i End Sub[/code] [/quote] 1.) You have code that does the same thing twice. 2.) You have Next i, when there is no For loop starting it (delete Next i). 3.) You're missing an End If. delete: [code] If KeyAscii = 13 Then KeyAscii = 0 'No Beep sckBNET.SendData txtSend.Text & vbCrLf txtSend.Text = "" [/code] You put the join channel code anywhere you want. I would put it in the sckBNET_Connect() event so that your bot joins a "home" channel when it logs on. | May 4, 2004, 9:56 PM |
Learn | DAMMIT!!!!!!!! SO CONFUSED [code]Private Sub mnuFileConnect_Click() sckBNET.Connect "useast.battle.net", 6112 AddChat vbYellow, "Connecting..." Next i Dim Channel As String Channel = "Public Chat John" sckBNET.SendData "/join " & Channel & vbCrLf DoEvents End Sub[/code] "Next without for" error Jesus christ, could you explain to me where/when i put "End If" and "Next i" | May 4, 2004, 10:11 PM |
Eli_1 | You only need an End If if you have an if statement. Example: [code] If Username = "asdfasdf" Then 'do stuff End if[/code] You only need a Next i if you have a for loop that uses the variable i. Example: [code] Dim i as integer for i = 1 to 10 msgbox "MerF?!", vbOKOnly, "NerFFF?!" next i[/code] And you can't join a channel untill you log in. There should be a function called sckBNET_Connect(). That function is called when the socket connects to the server. Similar to how sckBNET_Close() and sckBNET_Error() will be called when you are disconnected. In sckBNET_Connect() you would put your log in code and the join channel code. Example: [code] Private Sub sckBNET_Connect() With sckBNET .SendData Chr(3) & Chr(4) & "John" & vbCrLf '/* This will send the protocol byte 0x03 (CHAT) '** It will also send 0x04 with it. '** This will disable echo, so the server doesn't '** echo back what you send it (for telnet). */ .SendData "ub3rleet" & vbCrLf '/* This will send your password to the server. '** which in this example is 'ub3rleet'. */ Dim HomeChannel as String '// Your home channel HomeChannel = "Public Chat Drop" '// Set home channel .SendData "/join " & HomeChannel & vbCrLf '/* This will send the join command with '** with the parameter 'Public Chat Drop' to '** the server. You could accomplish the same '** thing by simply doing: '** '** .SendData "/join Public Chat Drop" & vbCrLf '*/ End With '/* We need an End With because we used With at the '** top. Similar to how we need End Sub, because we '** have 'Private Sub ..." at the top. */ End Sub [/code] All the comments might make it look intimidating to you, so I'll take them out so you can see what it looks like w/o them. At least read through them though, because they explain why the code works. Exact same code without comments: [code] Private Sub sckBNET_Connect() With sckBNET .SendData Chr(3) & Chr(4) & "John" & vbCrLf .SendData "ub3rleet" & vbCrLf Dim HomeChannel as String HomeChannel = "Public Chat Drop" .SendData "/join " & HomeChannel & vbCrLf End With End Sub [/code] | May 4, 2004, 10:22 PM |
Stealth | [quote author=Learn link=board=31;threadid=6638;start=15#msg58494 date=1083707626] Ok, sorry if I'm annoying you, but where does the Dim ChannelNameVariable as String blah blah blah go? And i keep getting "Next without for" error with this cod[code]Private Sub txtSend_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then KeyAscii = 0 'No Beep sckBNET.SendData txtSend.Text & vbCrLf txtSend.Text = "" Const VK_RETURN = 13 If KeyAscii = VK_RETURN Then Winsock.SendData txtSend.Text & vbCrLf '/* Notice I'm putting vbCrLf on the end of the text :O */ DoEvents '/* DoEvents isn't needed. I use it '** because on one of my really old '** computers it won't send if I leave DoEvents '** out. Btw, these are all comments, learn. */ End If Next i End Sub[/code] [/quote] I would strongly suggest learning more about VB and how it works before you continue any further. Get a book or visit a few online tutorials. | May 4, 2004, 10:30 PM |
Learn | Hi, Stealth you make ownage bots.. wanna help me? =]] and Stealth do you know VB? Was Stealthbot programmed with VB? And if you do know VB how did you learn? Trial and Error? Book? Teacher? And do you suggest a book that you know is good? But Eli_1 i already have a connect command, isnt there i way to join a home channel afer connecting with my mnuFile_Connect thing? | May 4, 2004, 10:43 PM |
Eli_1 | sckBNET_Connect() is not a connect command, god damnit. It is an event winsock calls when it is connected to the server. If you try sending data before your connected, you'll get pretty errors. I'm trying to be as helpful as I possibly can. But now I'm starting to think you never read anything I took the time to type for you, because if you did, you'd know you can't. And you'd also know before trying to join a channel you need to send the protocol byte for CHAT(3) and then log in. Anyway, I'm done. Good luck to you. | May 4, 2004, 11:04 PM |
Dyndrilliac | [quote author=Learn link=board=31;threadid=6638;start=15#msg58513 date=1083710621] Hi, Stealth you make ownage bots.. wanna help me? =]] and Stealth do you know VB? Was Stealthbot programmed with VB? And if you do know VB how did you learn? Trial and Error? Book? Teacher? And do you suggest a book that you know is good? But Eli_1 i already have a connect command, isnt there i way to join a home channel afer connecting with my mnuFile_Connect thing? [/quote] Yes it was and yes he does. I also suggest you learn the language before writing a bot. Your skipping learning your ABC's to being an english professor at Harvard. | May 4, 2004, 11:18 PM |
Learn | Thanks for all your help Eli_1. Nice metaphor Dyndrilliac. How do you suggest learning the language? Do you know any good sites? A title to a good book, perhaps? If so any info would be much appreciated. Also, I've searched for tutorials online, none of the free ones are good, that I've found. | May 4, 2004, 11:36 PM |
Stealth | [quote author=Learn link=board=31;threadid=6638;start=15#msg58513 date=1083710621] Hi, Stealth you make ownage bots.. wanna help me? =]] and Stealth do you know VB? Was Stealthbot programmed with VB? And if you do know VB how did you learn? Trial and Error? Book? Teacher? And do you suggest a book that you know is good? But Eli_1 i already have a connect command, isnt there i way to join a home channel afer connecting with my mnuFile_Connect thing? [/quote] I took a class last year in school that taught VB. It was based on a book, exactly which one I forget. Grok has posted a link to Bruce McKinney's Hardcore Visual Basic, which looks like a very good source of information. Search the forums Bruce McKinney and see what you find. | May 5, 2004, 1:23 AM |
Eli_1 | I also took Introduction to Programming in 9th grade. The book we used was: Visual Basic 6 How to Program Deitel & Deitel T.R. Nieto www.deitel.com | May 5, 2004, 1:58 AM |
Dyndrilliac | www.programmingtutorials.com | May 5, 2004, 7:36 PM |
Networks | Anything for advanced programmers? I still don't know quite everything yet. But I definetly know 80% of it, I think possibly more. | May 5, 2004, 11:32 PM |