Author | Message | Time |
---|---|---|
Dynobird | K, so this is my first attempt at making a bot... Just to let you know, I don't want to write my own packets (yet) so I copied rabbit's packet from here. I call botconnect and its methods via my GUI. It then performs the sendAndReceive method without any errors (well, it could have sent the wrong stuff, but it doesnt kill the connection), and asks for an input. Here's where I'm stumped. What am I supposed to input! Has the b.net handshake changed since rabbit wrote his packet? Also, the DataInputStream/DataOutputStream classes are deprecated, but my IDE (netbeans) allows me to use them nevertheless. I tried iago's suggestion of just using InputStream and OutputStream but those classes are abstract... and I'm unfamiliar with abstract classes. Perhaps I should learn how to handle abstract classes, and then use them... but if I don't have to then I would rather not. I also took the suggestion of changing chars to bytes... Can someone help me out? Here's my code: [code] /* * "My Pathetic Attempt" Part 2 */ import java.net.*; import java.io.*; public class botconnect { private Socket sock; private DataInputStream in; private DataOutputStream out; /***** I call the constructors and methods via my GUI *****/ public botconnect() {} public botconnect(String server, int port) { try { sock = new Socket(server, port); } catch(IOException e) { System.out.println(e); killSock(); } try { in = new DataInputStream(sock.getInputStream()); out = new DataOutputStream(sock.getOutputStream()); } catch(IOException e) { System.out.println(e); killSock(); } System.out.println("IO Streams created"); } //packet stuff that I copied from rabbit public void sendAndReceive() { if(sock != null && in != null && out != null) { try { out.write((byte) 0x01); out.write((byte) 0xFF); out.write((byte) 0x50); out.write((byte) 0x00); out.write((byte) 0x3A); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.writeChars("68XIRATS"); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0xC9); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.write((byte) 0x00); out.writeChars("USA"); out.write((byte) 0x00); out.writeChars("United States"); out.write((byte) 0x00); System.out.println("0x50 sent"); String response; while(true){ response = in.readLine(); if(response != null) { System.out.println(response); response = null; killSock(); break; } } } catch(IOException e) { System.out.println(e); killSock(); } } } public void killSock() { try { sock.close(); in.close(); out.close(); } catch(IOException e) { System.out.println(e); } } } [/code] | August 10, 2005, 8:49 PM |
Lenny | I believe iago meant that you should use those InputStream/OutputStream classes in a more concrete context. Take note that in the java API that the Socket class returns a concrete instance of its InputStream and OutputStream. You can treat these instances as any concrete class. | August 10, 2005, 9:00 PM |
Quarantine | you REALLY should write a packet buffer. | August 10, 2005, 9:01 PM |
Dynobird | hrm, OK, what does the packet that I copied from rabbit actually do... I learned that in the "b.net handshake" there's a lot of sends and receives, where b.net prompts you for stuff and you have to put in precisely what it wants. But the code that I copied from rabbit only seems to send stuff, so... what does it actually do? Also, I'd like to be able to just copy/paste a packet in my botconnect class for the meanwhile, or write my own packet buffer and copy/paste all the sends and receives in the b.net handshake. Where can I find a simple packet in Java that just gets a bot into a channel? | August 10, 2005, 9:03 PM |
R.a.B.B.i.T | [quote author=Dynobird link=topic=12486.msg123851#msg123851 date=1123706972] K, so this is my first attempt at making a bot... Just to let you know, I don't want to write my own packets (yet) so I copied rabbit's packet from here. I call botconnect and its methods via my GUI. It then performs the sendAndReceive method without any errors (well, it could have sent the wrong stuff, but it doesnt kill the connection), and asks for an input. Here's where I'm stumped. What am I supposed to input! Has the b.net handshake changed since rabbit wrote his packet? Also, the DataInputStream/DataOutputStream classes are deprecated, but my IDE (netbeans) allows me to use them nevertheless. I tried iago's suggestion of just using InputStream and OutputStream but those classes are abstract... and I'm unfamiliar with abstract classes. Perhaps I should learn how to handle abstract classes, and then use them... but if I don't have to then I would rather not. I also took the suggestion of changing chars to bytes... Can someone help me out? Here's my code: [code] /* * snipped */ [/code] [/quote] Please note that I wrote that so that I could make sure I was handling sockets correctly. I fully intended to write a buffer later. Also, I suck at Java. | August 10, 2005, 9:04 PM |
R.a.B.B.i.T | [quote author=Dynobird link=topic=12486.msg123862#msg123862 date=1123707798] OK, so let's say I write a packet buffer... I'd rather not research b.net protocol, is there anywhere I can just copy/paste what I have to write into the buffer :P [/quote]You don't have to research it, as that is already done quite extensively, all you have to do is implement it. | August 10, 2005, 9:05 PM |
Lenny | You don't even have to necessarily write it. An opensource packetbuffer in java is already available. All you simply need to do is understand how to use it. http://myjavaserver.com/~madc0w/ServlerBot/bncc/recieve/ http://myjavaserver.com/~madc0w/ServlerBot/bncc/send/ | August 10, 2005, 9:14 PM |
R.a.B.B.i.T | OO! Also, there is a Battle.Net buffer, available courtesy iago: http://www.javaop.com/ JavaOp is an open-source Battle.Net bot written in Java. | August 10, 2005, 9:46 PM |
Dynobird | Thanks rabbit and lenny, I'll get started on that stuff. | August 11, 2005, 1:51 AM |
Dynobird | My goal right now is just to get my bot into a channel. I looked at BnetDocs and it's kinda confusing. I also looked at iago's JavaOp, and it's all way above me. So, can someone lead me through the bare minimum that I need to get my bot into a channel? My guess right now is that I'll have to create separate packets for the logon sequences and BNLS messages, and then send them using the packet buffer that you guys showed me, found here. Also, are there any easy-to-understand src examples of how to do the logon sequences and BNLS messages in java? | August 11, 2005, 9:03 PM |
Dynobird | EDIT: I deleted my post because Iago just helped me. I was sending 0x13 between username/password when I should have sent 0x0a. | August 16, 2005, 7:35 PM |
Dynobird | My bot connects as a Chat client and can only go in public channels. Right now, I'm not concerned with the private channels part; I know that is very difficult and I'm going to save that for last. First, I need to make my bot send out messages in the public chat channels. So, I have three questions: 1) Should I stick with using the OutputStream object? Or should I use a different kind of stream for my output. 2) Should I send my messages in bytes, char arrays, individual chars (processing a char array through a for loop) or Strings? 3) Two parts... INTRO: I need to put my send and receive functions in different threads, but I need them both to have access to the socket, in, and out objects, so they have to be in the same class. I can't subclass and extend the class that has the socket/in/out objects because then I won't be able to extend Thread in that subclass. QUESTION: So, how do you make multiple threads in a single class and have them work independently of eachother? Would all of the threads (in the single class, not subclassed) go by one run method? And if so, how does that run method determine which thread was started? A code example of multiple threads in a single class would be nice. | August 20, 2005, 3:15 AM |