Exemplo n.º 1
0
 public static Packet ReadPacket(NReader rdr, ClientProcessor psr)
 {
     int len = rdr.ReadInt32() - 5;
     byte id = rdr.ReadByte();
     Packet packet = Packets[(PacketID)id].CreateInstance();
     byte[] content = rdr.ReadBytes(len);
     packet.Read(psr, new NReader(new MemoryStream(packet.Crypt(psr, content))));
     return packet;
 }
Exemplo n.º 2
0
        static void ServePolicyFile(IAsyncResult ar)
        {
            var cli = (ar.AsyncState as TcpListener).EndAcceptTcpClient(ar);
            (ar.AsyncState as TcpListener).BeginAcceptTcpClient(ServePolicyFile, ar.AsyncState);
            try
            {
                var s = cli.GetStream();
                var rdr = new NReader(s);
                var wtr = new NWriter(s);
                if (rdr.ReadNullTerminatedString() == "<policy-file-request/>")
                {
                    wtr.WriteNullTerminatedString(@"<cross-domain-policy>
     <allow-access-from domain=""*"" to-ports=""*"" />
</cross-domain-policy>");
                    wtr.Write((byte)'\r');
                    wtr.Write((byte)'\n');
                }
                cli.Close();
            }
            catch { }
        }
Exemplo n.º 3
0
        void ProcessCli()
        {
            try
            {
                var rdr = new NReader(new NetworkStream(skt));
                var wtr = new NWriter(dest.GetStream());
                while (true)
                {
                    int len = rdr.ReadInt32();
                    byte id = rdr.ReadByte();
                    byte[] content = rdr.ReadBytes(len - 5);

                    var state = ReceiveKey.SaveState();

                    content = ReceiveKey.Crypt(content);
                    ReceiveKey.LoadState(state);
                    //if (id == 17)
                    //{
                    //    MemoryStream ms = new MemoryStream();
                    //    using (NWriter w = new NWriter(ms))
                    //    using (NReader r = new NReader(new MemoryStream(content)))
                    //    {
                    //        w.WriteUTF(r.ReadUTF());
                    //        Console.WriteLine(r.ReadInt32()); w.Write(-3);
                    //        w.WriteUTF(r.ReadUTF());
                    //        w.WriteUTF(r.ReadUTF());
                    //        w.WriteUTF(r.ReadUTF());
                    //        w.Write(r.ReadInt32());
                    //        var c = r.ReadBytes(r.ReadInt16());
                    //        w.Write((short)c.Length);
                    //        w.Write(c);
                    //        w.Write32UTF(r.Read32UTF());
                    //        w.WriteUTF(r.ReadUTF());
                    //        w.WriteUTF(r.ReadUTF());
                    //        w.WriteUTF(r.ReadUTF());
                    //        w.WriteUTF(r.ReadUTF());
                    //    }
                    //    content = ms.ToArray();
                    //}
                    if (id == 4)
                    {
                        using (NReader r = new NReader(new MemoryStream(content)))
                        {
                            var Name = rdr.ReadUTF();
                            var Host = rdr.ReadUTF();
                            var Port = rdr.ReadInt32();
                            var GameId = rdr.ReadInt32();
                            var KeyTime = rdr.ReadInt32();
                            var Key = rdr.ReadBytes(rdr.ReadInt16());
                        }
                    }
                    content = ReceiveKey.Crypt(content);
                    ReceiveKey.LoadState(state);


                    wtr.Write(len);
                    wtr.Write((byte)id);
                    wtr.Write(content);

                    cliPkts.Add(new Packet() { id = id, content = ReceiveKey.Crypt(content) });
                }
            }
            catch { }
            finally
            {
                skt.Close();
            }
            for (var i = 0; i < cliPkts.Count; i++)
                File.WriteAllBytes("cli_pkt/" + i + "_" + cliPkts[i].id, cliPkts[i].content);
        }
Exemplo n.º 4
0
        void ProcessSvr()
        {
            try
            {
                var rdr = new NReader(dest.GetStream());
                var wtr = new NWriter(new NetworkStream(skt));
                while (true)
                {
                    int len = rdr.ReadInt32() - 5;
                    byte id = rdr.ReadByte();
                    byte[] content = rdr.ReadBytes(len);

                    wtr.Write(len + 5);
                    wtr.Write((byte)id);
                    wtr.Write(content);

                    svrPkts.Add(new Packet() { id = id, content = SendKey.Crypt(content) });
                }
            }
            catch { }
            finally
            {
                skt.Close();
            }
            JsonMap map = new JsonMap();
            for (var i = 0; i < svrPkts.Count; i++)
            {
                File.WriteAllBytes("svr_pkt/" + i + "_" + svrPkts[i].id, svrPkts[i].content);
                if (svrPkts[i].id == 37)
                {
                    map.Init(IPAddress.NetworkToHostOrder(BitConverter.ToInt32(svrPkts[i].content, 0)),
                        IPAddress.NetworkToHostOrder(BitConverter.ToInt32(svrPkts[i].content, 4)));
                    File.WriteAllBytes("mapinfo.packet", svrPkts[i].content);
                }
                if (svrPkts[i].id == 5)
                {
                    using (NReader rdr = new NReader(new MemoryStream(svrPkts[i].content)))
                    {
                        short count = rdr.ReadInt16();
                        for (var x = 0; x < count; x++)
                        {
                            map.Tiles[rdr.ReadInt16()][rdr.ReadInt16()] = (Tile)rdr.ReadByte();
                        }
                        count = rdr.ReadInt16();
                        for (var x = 0; x < count; x++)
                        {
                            ObjectDef def = ObjectDef.Read(rdr);
                            def.Stats.Position.X -= 0.5F;
                            def.Stats.Position.Y -= 0.5F;
                            if (def.Stats.Position.X == (int)def.Stats.Position.X &&
                                def.Stats.Position.Y == (int)def.Stats.Position.Y)
                            {
                                int _x = (int)def.Stats.Position.X;
                                int _y = (int)def.Stats.Position.Y;
                                Array.Resize(ref map.Entities[_x][_y], map.Entities[_x][_y].Length + 1);
                                ObjectDef[] arr = map.Entities[_x][_y];

                                arr[arr.Length - 1] = def;
                            }
                        }
                    }
                }
            }
            File.WriteAllText("map.jm", map.ToJson());
        }
Exemplo n.º 5
0
 protected override void Read(ClientProcessor psr, NReader rdr)
 {
 }
Exemplo n.º 6
0
 protected abstract void Read(ClientProcessor psr, NReader rdr);
Exemplo n.º 7
0
 public static ObjectDef Read(NReader rdr)
 {
     ObjectDef ret = new ObjectDef();
     ret.ObjectType = rdr.ReadInt16();
     ret.Stats = ObjectStats.Read(rdr);
     return ret;
 }
Exemplo n.º 8
0
 public static TimedPosition Read(NReader rdr)
 {
     TimedPosition ret = new TimedPosition();
     ret.Time = rdr.ReadInt32();
     ret.Position = Position.Read(rdr);
     return ret;
 }
Exemplo n.º 9
0
 public static Position Read(NReader rdr)
 {
     Position ret = new Position();
     ret.X = rdr.ReadSingle();
     ret.Y = rdr.ReadSingle();
     return ret;
 }
Exemplo n.º 10
0
        public static ObjectStats Read(NReader rdr)
        {
            ObjectStats ret = new ObjectStats();
            ret.Id = rdr.ReadInt32();
            ret.Position = Position.Read(rdr);
            ret.Stats = new KeyValuePair<StatsType, object>[rdr.ReadInt16()];
            for (var i = 0; i < ret.Stats.Length; i++)
            {
                StatsType type = (StatsType)rdr.ReadByte();
                if (type == StatsType.Guild || type == StatsType.Name)
                    ret.Stats[i] = new KeyValuePair<StatsType, object>(type, rdr.ReadUTF());
                else
                    ret.Stats[i] = new KeyValuePair<StatsType, object>(type, rdr.ReadInt32());
            }

            return ret;
        }
Exemplo n.º 11
0
 protected abstract void Read(ClientProcessor psr, NReader rdr);
Exemplo n.º 12
0
 protected override void Read(ClientProcessor psr, NReader rdr)
 {
 }