Beispiel #1
0
        public async Task Update()
        {
            var result = await UdpServer.ReceiveAsync();

            var parsed   = Packet.Parse(result.Buffer);
            var endPoint = result.RemoteEndPoint;

//            Console.WriteLine($"{parsed}");

            switch (parsed.Type)
            {
            case PacketType.UnconnectedPing: { await SendRaw(endPoint, UnconnectedPongPacket.FromPing(parsed.Get <UnconnectedPingPacket>(), Guid, "MCPE.AlphaServer")); break; }

            case PacketType.OpenConnectionRequest1: { await SendRaw(endPoint, OpenConnectionReplyPacket.FromRequest(parsed.Get <OpenConnectionRequestPacket>(), Guid, endPoint)); break; }

            case PacketType.OpenConnectionRequest2: {
                var packet = parsed.Get <OpenConnectionRequestPacket>();
                var Client = new UdpConnection(endPoint);
                Clients.Add(endPoint, Client);
                await SendRaw(endPoint, OpenConnectionReplyPacket.FromRequest(packet, Guid, endPoint));

                break;
            }

            case PacketType.RakNetPacket: { await HandleRakNetPacket(parsed.Get <RakNetPacket>(), endPoint); break; }

            default:
                break;
            }
        }
Beispiel #2
0
        public async Task Send(UdpConnection Client, params RakPacket[] packets)
        {
            var rakPacket = RakNetPacket.Create(Client.Sequence);

            Client.Sequence = Client.Sequence.Add(1);
            rakPacket.Enclosing.AddRange(packets);
            var data = rakPacket.Serialize();
            await UdpServer.SendAsync(data, data.Length, Client.EndPoint);
        }