protected override void ReceivedData(SocketAsyncEventArgs e) { byte[] receivedData = e.Buffer; IBnlsRequestToken node = e.UserToken as IBnlsRequestToken; int pktLen; if (node.RequestBuffer == null) { pktLen = BitConverter.ToInt16(receivedData, 0); node.RequestBuffer = new byte[pktLen]; } else { pktLen = BitConverter.ToInt16(node.RequestBuffer, 0); } Buffer.BlockCopy(receivedData, 0, node.RequestBuffer, node.RequestBufferCount, receivedData.Length); node.RequestBufferCount += receivedData.Length; if (node.RequestBufferCount < pktLen) { int diffLen = pktLen - node.RequestBufferCount; ReceiveNoLock(diffLen, e.UserToken); } else { receivingResetEvent.Set(); ParseBnls(node.RequestBuffer, node); } }
public void ReceivedBnlsMessage(IBnlsRequestToken token) { if (token is VersionCheckRequestToken) { VersionCheckRequestToken vcrt = token as VersionCheckRequestToken; if (!ViewModelLocator.MainWindowViewModelStatic.AccountsModel.VersionBytes.ContainsKey(botAccount.Product)) { // Insert the Product, signal a reconnect ViewModelLocator.MainWindowViewModelStatic.AccountsModel.VersionBytes.Add(botAccount.Product, (byte)vcrt.VersionByte); lock (eventSync) { BnetEvent beEvt = new BnetEvent(); beEvt.EventId = 0x21; eventQueue.Enqueue(beEvt); } } else { // Store the current version byte, if we get a "Invalid Version" we can try to reconnect if ((int)ViewModelLocator.MainWindowViewModelStatic.AccountsModel.VersionBytes[botAccount.Product] < vcrt.VersionByte) { ViewModelLocator.MainWindowViewModelStatic.AccountsModel.VersionBytes[botAccount.Product] = (byte)vcrt.VersionByte; // VersionByte sent from BNLS is greater than what we have stored BnetEvent beEvt = new BnetEvent(); beEvt.EventId = 0x21; Messenger.Default.Send <BnetEvent>(beEvt, connectionToken); } else { BnetPacket bntPkt = new BnetPacket(); bntPkt.InsertInt32(clientToken); bntPkt.InsertInt32(vcrt.Version); bntPkt.InsertInt32(vcrt.Checksum); bntPkt.InsertInt32(1); bntPkt.InsertInt32(0); bntPkt.InsertInt32(botAccount.CdKey.Length); MBNCSUtil.CdKey key = null; try { key = MBNCSUtil.CdKey.CreateDecoder(botAccount.CdKey); } catch (ArgumentOutOfRangeException) { // TODO: Post error. return; } if (!key.IsValid) { return; } bntPkt.InsertInt32(key.Product); bntPkt.InsertInt32(key.Value1); bntPkt.InsertInt32(0); bntPkt.InsertBytes(key.GetHash(clientToken, serverToken)); bntPkt.InsertBytes(vcrt.Statstring); bntPkt.InsertByte(0); bntPkt.InsertString(botAccount.Username); SendPacket(0x51, bntPkt); } } } else if (token is LogonChallengeRequestToken) { LogonChallengeRequestToken lcrt = token as LogonChallengeRequestToken; BnetPacket accountLogon = new BnetPacket(); foreach (var logonData in lcrt.ChallengeData) { accountLogon.InsertInt32(logonData); } accountLogon.InsertString(botAccount.Username); SendPacket(0x53, accountLogon); } else if (token is CreateAccountRequestToken) { CreateAccountRequestToken cart = token as CreateAccountRequestToken; BnetPacket createAccount = new BnetPacket(); foreach (var createAccountData in cart.AccountCreateData) { createAccount.InsertInt32(createAccountData); } createAccount.InsertString(botAccount.Username); SendPacket(0x52, createAccount); } else if (token is LogonProofRequestToken) { LogonProofRequestToken lprt = token as LogonProofRequestToken; BnetPacket logonProof = new BnetPacket(); foreach (var logonProofData in lprt.LogonProofData) { logonProof.InsertInt32(logonProofData); } SendPacket(0x54, logonProof); } }
private void ParseBnls(byte[] incomingData, IBnlsRequestToken node) { DataReader dr = new DataReader(incomingData); dr.ReadInt16(); byte pktId = dr.ReadByte(); switch (pktId) { case 0x01: VersionCheckRequestToken vcrt2 = node as VersionCheckRequestToken; dr.ReadInt32(); int cdKeySeed = dr.ReadInt32(); vcrt2.ClientToken = cdKeySeed; int[] cdKeyData = dr.ReadInt32Array(9); vcrt2.CdKeySeed = cdKeySeed; vcrt2.CdKeyData = cdKeyData; Messenger.Default.Send<IBnlsRequestToken>(node, node); vcrt2.RequestBuffer = null; vcrt2.RequestBufferCount = 0; break; case 0x02: LogonChallengeRequestToken lcrt = node as LogonChallengeRequestToken; int[] challengeData = dr.ReadInt32Array(8); lcrt.ChallengeData = challengeData; Messenger.Default.Send<IBnlsRequestToken>(node, node); lcrt.RequestBuffer = null; lcrt.RequestBufferCount = 0; break; case 0x03: LogonProofRequestToken lprt = node as LogonProofRequestToken; int[] logonProofData = dr.ReadInt32Array(5); lprt.LogonProofData = logonProofData; Messenger.Default.Send<IBnlsRequestToken>(node, node); lprt.RequestBuffer = null; lprt.RequestBufferCount = 0; break; case 0x04: CreateAccountRequestToken cart = node as CreateAccountRequestToken; int[] accountCreateData = dr.ReadInt32Array(16); cart.AccountCreateData = accountCreateData; Messenger.Default.Send<IBnlsRequestToken>(node, node); cart.RequestBuffer = null; cart.RequestBufferCount = 0; break; case 0x0D: node.RequestBuffer = null; node.RequestBufferCount = 0; break; case 0x1A: dr.ReadInt32(); VersionCheckRequestToken vcrt = node as VersionCheckRequestToken; vcrt.Version = dr.ReadInt32(); vcrt.Checksum = dr.ReadInt32(); vcrt.Statstring = dr.ReadByteArrayNt(); dr.ReadInt32(); vcrt.VersionByte = dr.ReadInt32(); Messenger.Default.Send<IBnlsRequestToken>(node, node); vcrt.RequestBufferCount = 0; vcrt.RequestBuffer = null; break; } }
private void ParseBnls(byte[] incomingData, IBnlsRequestToken node) { DataReader dr = new DataReader(incomingData); dr.ReadInt16(); byte pktId = dr.ReadByte(); switch (pktId) { case 0x01: VersionCheckRequestToken vcrt2 = node as VersionCheckRequestToken; dr.ReadInt32(); int cdKeySeed = dr.ReadInt32(); vcrt2.ClientToken = cdKeySeed; int[] cdKeyData = dr.ReadInt32Array(9); vcrt2.CdKeySeed = cdKeySeed; vcrt2.CdKeyData = cdKeyData; Messenger.Default.Send <IBnlsRequestToken>(node, node); vcrt2.RequestBuffer = null; vcrt2.RequestBufferCount = 0; break; case 0x02: LogonChallengeRequestToken lcrt = node as LogonChallengeRequestToken; int[] challengeData = dr.ReadInt32Array(8); lcrt.ChallengeData = challengeData; Messenger.Default.Send <IBnlsRequestToken>(node, node); lcrt.RequestBuffer = null; lcrt.RequestBufferCount = 0; break; case 0x03: LogonProofRequestToken lprt = node as LogonProofRequestToken; int[] logonProofData = dr.ReadInt32Array(5); lprt.LogonProofData = logonProofData; Messenger.Default.Send <IBnlsRequestToken>(node, node); lprt.RequestBuffer = null; lprt.RequestBufferCount = 0; break; case 0x04: CreateAccountRequestToken cart = node as CreateAccountRequestToken; int[] accountCreateData = dr.ReadInt32Array(16); cart.AccountCreateData = accountCreateData; Messenger.Default.Send <IBnlsRequestToken>(node, node); cart.RequestBuffer = null; cart.RequestBufferCount = 0; break; case 0x0D: node.RequestBuffer = null; node.RequestBufferCount = 0; break; case 0x1A: dr.ReadInt32(); VersionCheckRequestToken vcrt = node as VersionCheckRequestToken; vcrt.Version = dr.ReadInt32(); vcrt.Checksum = dr.ReadInt32(); vcrt.Statstring = dr.ReadByteArrayNt(); dr.ReadInt32(); vcrt.VersionByte = dr.ReadInt32(); Messenger.Default.Send <IBnlsRequestToken>(node, node); vcrt.RequestBufferCount = 0; vcrt.RequestBuffer = null; break; } }
public void ReceivedBnlsMessage(IBnlsRequestToken token) { if (token is VersionCheckRequestToken) { VersionCheckRequestToken vcrt = token as VersionCheckRequestToken; if (!ViewModelLocator.MainWindowViewModelStatic.AccountsModel.VersionBytes.ContainsKey(botAccount.Product)) { // Insert the Product, signal a reconnect ViewModelLocator.MainWindowViewModelStatic.AccountsModel.VersionBytes.Add(botAccount.Product, (byte)vcrt.VersionByte); lock (eventSync) { BnetEvent beEvt = new BnetEvent(); beEvt.EventId = 0x21; eventQueue.Enqueue(beEvt); } } else { // Store the current version byte, if we get a "Invalid Version" we can try to reconnect if ((int)ViewModelLocator.MainWindowViewModelStatic.AccountsModel.VersionBytes[botAccount.Product] < vcrt.VersionByte) { ViewModelLocator.MainWindowViewModelStatic.AccountsModel.VersionBytes[botAccount.Product] = (byte)vcrt.VersionByte; // VersionByte sent from BNLS is greater than what we have stored BnetEvent beEvt = new BnetEvent(); beEvt.EventId = 0x21; Messenger.Default.Send<BnetEvent>(beEvt, connectionToken); } else { BnetPacket bntPkt = new BnetPacket(); bntPkt.InsertInt32(clientToken); bntPkt.InsertInt32(vcrt.Version); bntPkt.InsertInt32(vcrt.Checksum); bntPkt.InsertInt32(1); bntPkt.InsertInt32(0); bntPkt.InsertInt32(botAccount.CdKey.Length); MBNCSUtil.CdKey key = null; try { key = MBNCSUtil.CdKey.CreateDecoder(botAccount.CdKey); } catch (ArgumentOutOfRangeException) { // TODO: Post error. return; } if (!key.IsValid) return; bntPkt.InsertInt32(key.Product); bntPkt.InsertInt32(key.Value1); bntPkt.InsertInt32(0); bntPkt.InsertBytes(key.GetHash(clientToken, serverToken)); bntPkt.InsertBytes(vcrt.Statstring); bntPkt.InsertByte(0); bntPkt.InsertString(botAccount.Username); SendPacket(0x51, bntPkt); } } } else if (token is LogonChallengeRequestToken) { LogonChallengeRequestToken lcrt = token as LogonChallengeRequestToken; BnetPacket accountLogon = new BnetPacket(); foreach (var logonData in lcrt.ChallengeData) { accountLogon.InsertInt32(logonData); } accountLogon.InsertString(botAccount.Username); SendPacket(0x53, accountLogon); } else if (token is CreateAccountRequestToken) { CreateAccountRequestToken cart = token as CreateAccountRequestToken; BnetPacket createAccount = new BnetPacket(); foreach (var createAccountData in cart.AccountCreateData) createAccount.InsertInt32(createAccountData); createAccount.InsertString(botAccount.Username); SendPacket(0x52, createAccount); } else if (token is LogonProofRequestToken) { LogonProofRequestToken lprt = token as LogonProofRequestToken; BnetPacket logonProof = new BnetPacket(); foreach (var logonProofData in lprt.LogonProofData) logonProof.InsertInt32(logonProofData); SendPacket(0x54, logonProof); } }