Beispiel #1
0
        /// <summary></summary>
        public void EnsureServer()
        {
            if (Server == null)
            {
                if (ProtocolType == NetType.Tcp)
                {
                    var server = new TcpServer();
                    Server = server;
                    //server.ReuseAddress = true;
                    server.NewSession += server_Accepted;
                }
                else
                {
                    var server = new UdpServer();
                    //Server = server;
                    //server.ReuseAddress = true;
                    server.Received += server_Received;
                    //server.Bind();
                    server.ReceiveAsync();
                }

                Server.Start();

                WriteLog("监听:{0}", Server);
            }
        }
Beispiel #2
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 #3
0
        /// <summary></summary>
        public void EnsureServer()
        {
            if (Server == null)
            {
                if (ProtocolType == ProtocolType.Tcp)
                {
                    var server = new TcpServer();
                    Server = server;
                    //server.ReuseAddress = true;
                    server.NewSession += server_Accepted;
                }
                else
                {
                    var server = new UdpServer();
                    //Server = server;
                    //server.ReuseAddress = true;
                    server.Received += server_Received;
                    //server.Bind();
                    server.ReceiveAsync();
                }

                Server.Start();

                WriteLog("监听:{0}", Server);
            }
        }