Exemplo n.º 1
0
        private static void MakePacketAndSend(ClientManager MyClient, byte[] content)
        {
            short ContentLenght = (short)content.Length;
            byte  RandomPubKey  = XCRYPT.AddRandPubKey();


            //Console.WriteLine("Sending: " + ContentLenght + " | " + RandomPubKey);

            using (MemoryStream stream = new MemoryStream())
            {
                int len = 0;
                using (BinaryWriter bw = new BinaryWriter(stream, Encoding.UTF8))
                {
                    bw.Write((short)ContentLenght);
                    bw.Write((byte)RandomPubKey);
                    bw.Write(XCRYPT.Encrypt(content, XCRYPT.GetPubKeyIndex(RandomPubKey), XCRYPT.LoginServerPrivkey));
                    len = (int)bw.BaseStream.Length;
                }
                stream.Flush();
                byte[] buffer = stream.GetBuffer();
                Array.Resize(ref buffer, len);

                Send(MyClient, buffer);
            }
        }
Exemplo n.º 2
0
        public static byte[] GetPacketDataDecrypted(byte[] data)
        {
            byte[] Buffer;
            using (MemoryStream ms = new MemoryStream(data))
            {
                using (BinaryReader br = new BinaryReader(ms, Encoding.UTF8))
                {
                    short PacketLen = br.ReadInt16();
                    byte  pubkey    = br.ReadByte();

                    byte[] content = br.ReadBytes(PacketLen);

                    using (MemoryStream ms2 = new MemoryStream())
                    {
                        using (BinaryWriter bw = new BinaryWriter(ms2))
                        {
                            byte PubKeyIndex = XCRYPT.GetPubKeyIndex(pubkey);
                            bw.Write(XCRYPT.Decrypt(content, PubKeyIndex, XCRYPT.GameManagerServerPrivKey));
                        }
                        ms2.Flush();
                        Buffer = ms2.GetBuffer();
                        Array.Resize(ref Buffer, content.Length);
                    }
                }
            }
            return(Buffer);
        }
Exemplo n.º 3
0
        public ReadPacket(byte[] data)
        {
            try
            {
                buffer = data;
                using (MemoryStream ms = new MemoryStream(buffer))
                {
                    using (BinaryReader br = new BinaryReader(ms, Encoding.UTF8))
                    {
                        short PacketLen = br.ReadInt16();
                        byte  pubkey    = br.ReadByte();
                        Head.len    = PacketLen;
                        Head.pubkey = pubkey;

                        byte[] content = br.ReadBytes(PacketLen);

                        using (MemoryStream ms2 = new MemoryStream())
                        {
                            using (BinaryWriter bw = new BinaryWriter(ms2))
                            {
                                byte PubKeyIndex = XCRYPT.GetPubKeyIndex(pubkey);
                                bw.Write(XCRYPT.Decrypt(content, PubKeyIndex, XCRYPT.LoginServerPrivkey));
                            }
                            ms2.Flush();
                            body = ms2.GetBuffer();
                            Array.Resize(ref body, content.Length);
                        }


                        /*
                         * using (MemoryStream ms2 = new MemoryStream())
                         * {
                         *  using (BinaryWriter bw = new BinaryWriter(ms2, Encoding.UTF8))
                         *  {
                         *      //byte PubKeyIndex = XCRYPT.GetPubKeyIndex(pubkey);
                         *      //bw.Write(XCRYPT.Decrypt(content, PubKeyIndex, XCRYPT.LoginServerPrivkey));
                         *      bw.Write(500);
                         *  }
                         *
                         *  byte[] buff = ms2.GetBuffer();
                         *  Array.Resize(ref buff, (int)ms2.Length);
                         *  body = buff;
                         *
                         * }
                         */
                    }
                }
                Initialized = true;
            }
            catch
            {
                Initialized = false;
                return;
            }
        }