News:

Help! We're trapped in the computer, and the computer is trapped in 2008! Someone call the time police!

Main Menu

[C#] Packet Buffer & Parser

Started by Smarter, December 06, 2006, 07:49:20 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MyndFyre

That means that your "len" variable is less than 0.
Quote from: Joe on January 23, 2011, 11:47:54 PM
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Quote from: Rule on May 26, 2009, 02:02:12 PMOur species really annoys me.

Smarter


Smarter

Ok, i'm stumped, my buffer is like empty, always, no idea why, sorry for all the help ?'s but I'm eager to get this to work!:

        public void OnConnect()
        {
            sckBNET = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sckBNLS = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sckBNET.Connect("useast.battle.net", 6112);
            sckBNLS.Connect("bnls.valhallalegends.com", 9367);
            //watch for data ( asynchronously )...
            AddC("[BNLS]: Connecting...");
            AddC("[BNET]: Connecting...");
            if (sckBNET.Connected == true)
            {
                AddC("[BNET]: Connected.");
            }
            if (sckBNLS.Connected == true)
            {
                AddC("[BNLS]: Connected.");
            }
            DataBuffer x0 = new DataBuffer();
            x0.InsertByte(0);
            byte[] x = x0.GetData();
            sckBNET.Send(x);
            DataBuffer buf = new DataBuffer();
            int procid = 0;
            buf.InsertInt32(procid);
            string platformid = "IX86";
            buf.InsertDwordString(platformid);
            string productid = "PXES";
            buf.InsertDwordString(productid);
            byte version = 0xCF;
            buf.InsertByte(version);
            buf.InsertInt32(0);
            buf.InsertInt32(0);
            buf.InsertInt32(0);
            buf.InsertInt32(0);
            buf.InsertInt32(0);
            buf.InsertCString("USA");
            buf.InsertCString("United States");
            byte[] p50 = buf.GetData();
            sckBNET.Send(p50);
            AddC("C > S - 0x50 SID_AUTH_INFO!");
            WaitForData();
           
        }

public void WaitForData()
        {
            // now start to listen for any data...
            m_asynResult = sckBNET.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, pfnCallBack, null);
            m_asynResult2 = sckBNLS.BeginReceive(bnlsbufr, 0, bnlsbufr.Length, SocketFlags.None, pfnCallBack2, null);
            if (pfnCallBack == null)
                pfnCallBack = new AsyncCallback(OnDataReceived);
            //if (pfnCallBack2 == null)
            //    pfnCallBack2 = new AsyncCallback(OnDataReceived);
           
        }

public void OnDataReceived(IAsyncResult asyn)
        {
            int len = BitConverter.ToInt16(buffer, 2) - 4;
            byte[] data = new byte[512];
            if (len < 0)
            {
                sckBNET.Receive(buffer, 0, SocketFlags.None);
            }
            HandlePacket(buffer[1], data, len);
            //end receive...
            int iRx = 0;
            iRx = sckBNET.EndReceive(asyn);

            WaitForData();
        }


There's my socket stuff....?