Example #1
0
        public static async void SendPacket(Packets.BasePacket packet)
        {
            byte[] buffer = packet.GetBytes();
            if (packet.UseTCP)
            {
                // Send a tcp version
                TcpClient tcp = new TcpClient();
                await tcp.ConnectAsync(IPAddress.Parse(packet.IP), packet.Port);
                await tcp.GetStream().WriteAsync(buffer, 0, buffer.Length);
            }
            else
            {
                // Send a UDP version
                //if(client == null) client = new UdpClient(new IPEndPoint(IPAddress.Any, PORT));
                //await client.SendAsync(buffer, buffer.Length, new IPEndPoint(IPAddress.Parse(packet.IP), packet.Port));
                Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

                IPAddress serverAddr = IPAddress.Parse(packet.IP);

                IPEndPoint endPoint = new IPEndPoint(serverAddr, packet.Port);

                sock.SendTo(buffer, endPoint);
            }
        }
Example #2
0
        public void OnSendUniversal(Packets.Server.SendUniversal p)
        {
            ClientManager.LeaveCriticalArea();
            while (!Client.netIO.Crypt.IsReady)
            {
                System.Threading.Thread.Sleep(100);
            }
            ClientManager.EnterCriticalArea();
            string tmp = "Sender:{0}\r\nOpcode:0x{1:X4}\r\nName:{2}\r\n\r\n{5}\r\n\r\nLength:{3}\r\nData:\r\n{4}\r\n";
            string tmp2 = this.DumpData(p);
            tmp = string.Format(tmp, "Server" , p.ID, this.ToString(), p.data.Length, tmp2, "{0}");
            Console.WriteLine(tmp);
            Packets.Server.SendUniversal p1 = new PacketProxy.Packets.Server.SendUniversal();
            p1.data = new byte[p.data.Length];
            p.data.CopyTo(p1.data, 0);
            this.Client.packetContainerServer.Add(p1);
            this.Client.packets.Add(p1);
            if (p.ID == 0x33 && this.Client.firstlevel != 2)
            {
                byte serverid = p.GetByte(2);
                byte size = p.GetByte(3);
                size--;
                string ip = System.Text.Encoding.ASCII.GetString(p.GetBytes(size, 4));
                int port = p.GetInt((ushort)(5 + size));
                if (Program.pm != null)
                {
                    Program.pm.Stop();
                }
                Program.pm = new ProxyClientManager();
                Program.pm.firstlvlen = 2;
                Program.pm.IP = ip;
                Program.pm.port = port;
                Program.pm.packetContainerServer = PacketContainer.Instance.packetsMap;
                Program.pm.packetContainerClient = PacketContainer.Instance.packetsClient;
                Program.pm.packets = PacketContainer.Instance.packets2;
                Program.pm.StartNetwork(port);
                Program.pm.ready = true;
                byte[] buf = System.Text.Encoding.UTF8.GetBytes("127.0.0.001");
                p.data = new byte[buf.Length + 9];
                p.ID = 0x33;
                p.PutByte(serverid, 2);
                p.PutByte((byte)(buf.Length + 1), 3);
                p.PutBytes(buf, 4);
                p.PutInt(port, (ushort)(5 + buf.Length));
            }
            if (p.ID == 0x157C)
            {

            }

            Client.netIO.SendPacket(p);
        }
 private FileContentResult SendPackets(IEnumerable <Packet> packets) =>
 File(Packets.GetBytes(packets), "application/octet-stream");