• Welcome to Valhalla Legends Archive.
 

Java sending 0x50

Started by OldMcDonald, April 19, 2010, 06:44 PM

Previous topic - Next topic

OldMcDonald

I'm sending everything successfully but I get no ping response back.

Here is my code:


import java.net.*;
import java.io.*;


public class bnetConnection{

    String host = "211.233.0.54";
    Socket skt = new Socket(host, 6112);
    String received;
    int id;

    BufferedReader myInput = new BufferedReader(new InputStreamReader(skt.getInputStream()));
    PrintStream myOutput = new PrintStream(skt.getOutputStream());
    buffer buff = new buffer();
   
 
   
    bnetConnection() throws Exception {
     
             myOutput.write(0x01);

    }
   
    public void send50() throws Exception{
       
        System.out.println("Connected to " + host);
        System.out.println("Sending Authorization");

        int verb = 0x0D;

         
        buff.addDWord(0);
        buff.addString("68XI");
        buff.addString("VD2D");
        buff.addDWord(verb);
        buff.addDWord(0);
        buff.addDWord(0);
        buff.addDWord(0);
        buff.addDWord(0);
        buff.addDWord(0);
        buff.addNTString("USA");
        buff.addNTString("United States");
        sendpack(0x50);
        System.out.println("Authorization Sent...");
        id = myInput.read();
        System.out.println("Received " + id);
       
       
    }
   
    public void Parseping() throws Exception{
       
        System.out.println("Got the ping");
    }

     public void Parsesend50() throws Exception{

         System.out.println("Got the packet 50 response");
    }


  /////////////////////////////////////////////////////////////////////////////

    public void sendpack(int p_id) throws Exception{

         



           
           myOutput.write(0xFF);
           myOutput.write(p_id);
           myOutput.write(buff.buffer.length + 3);
            //I'm only adding 3 because when I packet log it with 4 it is one bigger
            //than the actual packet


           myOutput.write(buff.buffer);
         
           
   }
}



I'm using iagos buffer class with this which can be located here:
http://www.google.com/codesearch/p?hl=en#LCtTldHliGI/trunk/BNUBot/src/org/jbls/util/Buffer.java&q=buffer%20package:http://bnubot\.googlecode\.com&sa=N&cd=1&ct=rc


When i packet log this is what i send:



0000  00 1a 70 d9 6e 5a 00 1b  fc 69 78 a4 08 00 45 00   ..p.nZ.. .ix...E.
0010  00 29 06 9e 40 00 80 06  27 ae c0 a8 01 64 3f f0   .)..@... '....d?.
0020  ca 86 ec 73 17 e0 c5 3f  90 11 82 a2 44 c7 50 18   ...s...? ....D.P.
0030  fa f0 c6 48 00 00 01                               ...H...       

0000  00 1a 70 d9 6e 5a 00 1b  fc 69 78 a4 08 00 45 00   ..p.nZ.. .ix...E.
0010  00 7b 06 9f 40 00 80 06  27 5b c0 a8 01 64 3f f0   .{..@... '[...d?.
0020  ca 86 ec 73 17 e0 c5 3f  90 12 82 a2 44 c7 50 18   ...s...? ....D.P.
0030  fa f0 b5 49 00 00 ff 50  53 00 00 00 00 36 38 58   ...I...P S....68X
0040  49 56 44 32 44 0d 00 00  00 00 00 00 00 00 00 00   IVD2D... ........
0050  00 00 00 00 00 00 00 00  00 00 00 00 00 55 53 41   ........ .....USA
0060  00 55 6e 69 74 65 64 20  53 74 61 74 65 73 00 00   .United  States..
0070  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ........ ........
0080  00 00 00 00 00 00 00 00  00                        ........ . 



Then i receive this:


0000  00 1b fc 69 78 a4 00 1a  70 d9 6e 5a 08 00 45 00   ...ix... p.nZ..E.
0010  00 24 6f 73 00 00 6d 11  11 d3 3f f0 ca 86 c0 a8   .$os..m. ..?.....
0020  01 64 17 e0 17 e0 00 10  1b c3 05 00 00 00 74 65   .d...... ......te
0030  6e 62 00 00 00 00 00 00  00 00 00 00               nb...... ....   




And after send this out:

0000  00 1a 70 d9 6e 5a 00 1b  fc 69 78 a4 08 00 45 00   ..p.nZ.. .ix...E.
0010  00 40 06 a0 00 00 80 01  67 9a c0 a8 01 64 3f f0   .@...... g....d?.
0020  ca 86 03 03 c9 a1 00 00  00 00 45 00 00 24 6f 72   ........ ..E..$or
0030  00 00 6d 11 11 d4 3f f0  ca 86 c0 a8 01 64 17 e0   ..m...?. .....d..
0040  17 e0 00 10 1b c3 05 00  00 00 74 65 6e 62         ........ ..tenb 


Finally I get the last reponse bnet gives me:

0000  00 1b fc 69 78 a4 00 1a  70 d9 6e 5a 08 00 45 00   ...ix... p.nZ..E.
0010  00 24 6f 73 00 00 6d 11  11 d3 3f f0 ca 86 c0 a8   .$os..m. ..?.....
0020  01 64 17 e0 17 e0 00 10  1b c3 05 00 00 00 74 65   .d...... ......te
0030  6e 62 00 00 00 00 00 00  00 00 00 00               nb...... ....   

Hdx

1) NEVER access internal variables directly. They are public for a few specific reasons.
2) Use buff.Size() not buff.buffer.length you'll notice how there is a shit load of extra nulls at the end of your packet.
3) Its general practice to extend the Buffer class to make it protocol specific. See It overrides .GetBuffer() to add the packet ID/length to the data.

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

OldMcDonald

okay im using this now:   myOutput.write(buff.size() + 3);

also the only way to cut off the nulls at the end is if i go into the buffer class and change maxLength = maxLength * 2; to maxLength = maxLength + 1 in the verifyLength method.

Should I make that tweak in the buffer? Or will it interfere somehow.

Hdx

Dont fuck with the buffer class, its perfect(tm)
Just use it properly.
.GetBuffer()
Like I said, DON'T ACCESS INTERNAL VARIABLES!

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

OldMcDonald

alright i successfully received packets 25 and 50 =D. Thanks a lot... lol I oversaw the methods that returned the length and buffer