1
General Programming / Re: [C#] Packet Buffer & Parser
« on: December 09, 2006, 12:12:25 am »
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!:
There's my socket stuff....?
Code: [Select]
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();
}
Code: [Select]
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);
}
Code: [Select]
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....?