private void ProcessPolicyFile()
        {
            var s = new NetworkStream(skt);
            var wtr = new NWriter(s);
            wtr.WriteNullTerminatedString(@"<cross-domain-policy>
    <allowed-access-from domain=""*"" to-ports=""*"" />
</cross-domain-policy>");
            wtr.Write((byte) '\r');
            wtr.Write((byte) '\n');
            parent.Disconnect();
        }
예제 #2
0
        public static void WritePacket(NWriter wtr, Packet pkt, ClientProcessor psr)
        {
            MemoryStream s = new MemoryStream();
            pkt.Write(psr, new NWriter(s));

            byte[] content = s.ToArray();
            content = pkt.Crypt(psr, content);
            wtr.Write(content.Length + 5);
            wtr.Write((byte)pkt.ID);
            wtr.Write(content);
        }
예제 #3
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 { }
        }
예제 #4
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);
        }
예제 #5
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());
        }
예제 #6
0
 public void Write(NWriter wtr)
 {
     wtr.Write(X);
     wtr.Write(Y);
 }
예제 #7
0
 public void Write(NWriter wtr)
 {
     wtr.Write(Time);
     Position.Write(wtr);
 }
예제 #8
0
 public void Write(NWriter wtr)
 {
     wtr.Write(ObjectType);
     Stats.Write(wtr);
 }
예제 #9
0
        public void Write(NWriter wtr)
        {
            wtr.Write(Id);
            Position.Write(wtr);

            wtr.Write((short)Stats.Length);
            foreach (var i in Stats)
            {
                wtr.Write((byte)i.Key);
                if (i.Value is string) wtr.WriteUTF(i.Value as string);
                else wtr.Write((int)i.Value);
            }
        }
 public void Write(Client psr, NWriter wtr)
 {
     wtr.Write(Width);
     wtr.Write(Height);
     wtr.Write(Bytes);
 }
 public void Write(Client psr, NWriter wtr)
 {
     wtr.Write(ObjectType);
     Stats.Write(psr, wtr);
 }
 public void Write(Client psr, NWriter wtr)
 {
     wtr.Write(X);
     wtr.Write(Y);
 }
 public void Write(Client psr, NWriter wtr)
 {
     wtr.Write(Time);
     Position.Write(psr, wtr);
 }
 public void Write(Client psr, NWriter wtr)
 {
     wtr.Write(ObjectId);
     wtr.Write(SlotId);
     wtr.Write(ObjectType);
 }