public static int SendPacketManually(string PlainStr) { if (!Misc.CheckHexString(PlainStr)) { MessageBox.Show("封包数据格式错误,请检查十六进制字符串的格式是否正确"); return(0); } byte[] plain = Misc.HexString2ByteArray(PlainStr); _PacketData SendPacketData = new _PacketData(); Packet.ParsePacket(plain, ref SendPacketData); Packet.CalculateResult(ref SendPacketData); //更新序列号 SendPacketData.userId = Packet.UserId; //修改为当前登录的米米号 plain = Packet.GroupPacket(ref SendPacketData); byte[] cipher = Packet.encrypt(plain); int res = SendPacket.Send(Packet.Socket, cipher); Packet.Result = SendPacketData.result; Packet.SendPacketNum++; Program.UI.AddList("send", Packet.SendPacketNum, ref SendPacketData, plain, cipher); return(res); }
public static int ProcessingSendPacket(int socket, byte[] cipher, int length) { _PacketData SendPacketData = new _PacketData(); int res = 0; if (cipher.Length < 17 || Misc.ByteArray2HexString(cipher, 2) != "00 00 ") { #region 直接过滤的发送封包(这个包也得发送出去,但是我们的封包解析程序不会解析这一条封包) res = SendPacket.Send(socket, cipher); //直接发送封包 if (cipher.Length > 20) { Console.WriteLine("发送封包-解析过滤 : [ {0}...... ]\n", Misc.ByteArray2HexString(cipher, 20)); } else { Console.WriteLine("发送封包-解析过滤 : [ {0}]\n", Misc.ByteArray2HexString(cipher)); } #endregion } else { #region 需要解析的发送封包 if (!HaveLogin) { Socket = socket; //通信号 } byte[] plain; if (NeedDecrypt(cipher)) { plain = decrypt(cipher); //解密封包 ParsePacket(plain, ref SendPacketData); //解析封包 CalculateResult(ref SendPacketData); //修改序列号 plain = GroupPacket(ref SendPacketData); //组合封包 cipher = encrypt(plain); //加密封包 } else //无需加密只有一种情况,即处于登录界面 { //这种情况下并不需要修改序列号,只解析封包即可 plain = cipher; ParsePacket(plain, ref SendPacketData); //解析封包 #region 登陆前 伪造米米号 // 如果 "伪造米米号" 对应的文本框不为空, // 则登录前的封包,米米号修改为该文本框中的米米号。 // 这个是用于测试赛尔号的伪造登录。正常游戏则置空即可。 if (!HaveLogin && !String.IsNullOrEmpty(Program.UI.textBox11.Text) && !String.IsNullOrEmpty(Program.UI.textBox12.Text) && Program.UI.textBox12.Text.Length == 32 && SendPacketData.cmdId == 103) { int iSubUserId = Int32.Parse(Program.UI.textBox11.Text); byte[] subUserId = Misc.Int2ByteArray(iSubUserId); subUserId.CopyTo(cipher, 9); subUserId.CopyTo(plain, 9); byte[] doubleMD5Pwd; doubleMD5Pwd = System.Text.Encoding.UTF8.GetBytes(Program.UI.textBox12.Text); doubleMD5Pwd.CopyTo(cipher, 17); doubleMD5Pwd.CopyTo(plain, 17); ParsePacket(plain, ref SendPacketData); } #endregion } res = SendPacket.Send(socket, cipher); //发送封包 if (HaveLogin) { Result = SendPacketData.result; //更新全局序列号(登录前的不用更新,也不能更新) } SendPacketNum++; //发送封包的总序号 Program.UI.AddList("send", SendPacketNum, ref SendPacketData, plain, cipher); //UI界面的列表增加这条发送记录 #endregion } return(res); }