Beispiel #1
0
        protected override void OnPacketReceived(byte[] bytes, IPEndPoint receivedFrom)
        {
            var datagram = new DatagramPacket(bytes, bytes.Length, receivedFrom);
            var packet = new NfsPacket(datagram);
            var e = new UdpPacketReceivedEventArgs(packet, receivedFrom);

            //Console.WriteLine("\nPacket Received : EndPoint: " + _listener.Client.Client.LocalEndPoint.ToString());

            uint xId = packet.XID = packet.GetUInt();
            uint type = packet.GetUInt();

            if (type == (int)RpcSignalType.Call) {
                Call(ref packet, xId);
            }
            else if (type == (int)RpcSignalType.Reply) {
                Reply(ref packet, xId);
            }

            //RaisePacketReceived(e);

            if (packet.ProgramID == this.ProgramID) {
                //Console.WriteLine("Found program: " + packet.ProgramID);
                Process(packet, receivedFrom);
            }
        }
Beispiel #2
0
        private void DiscoveryOnUdpPacketReceived(object sender, UdpPacketReceivedEventArgs args)
        {
            var msg      = Encoding.ASCII.GetString(args.Data);
            var msgArr   = msg.Split(':');
            var remoteId = Guid.Parse(msgArr[0]);

            if (remoteId == CoreApp.Guid)
            {
                return;
            }
            var remoteIP       = IPAddress.Parse(msgArr[1]);
            var remotePort     = Int32.Parse(msgArr[2]);
            var remoteEndpoint = new IPEndPoint(remoteIP, remotePort);

            AddReplicator(remoteEndpoint);
        }
Beispiel #3
0
        private async void DiscoveryOnUdpPacketReceived(object sender, UdpPacketReceivedEventArgs args)
        {
            var msg      = Encoding.ASCII.GetString(args.Data);
            var msgArr   = msg.Split(':');
            var remoteId = Guid.Parse(msgArr[1]);

            if (_id == remoteId)
            {
                return;
            }

            var remoteIP       = IPAddress.Parse(msgArr[2]);
            var remoteHost     = int.Parse(msgArr[3]);
            var remoteEndpoint = new IPEndPoint(remoteIP, remoteHost);
            await _comunicationManager.ConnectAsync(remoteEndpoint);
        }
Beispiel #4
0
		protected override void OnPacketReceived(byte[] bytes, IPEndPoint receivedFrom) {
			var datagram = new DatagramPacket(bytes, bytes.Length, receivedFrom);
			var packet = new NfsPacket(datagram);
			var e = new UdpPacketReceivedEventArgs(packet, receivedFrom);

			//Console.WriteLine("\nPacket Received : EndPoint: " + _listener.Client.Client.LocalEndPoint.ToString());

			uint xId = packet.XID = packet.GetUInt();
			uint type = packet.GetUInt();

			if (type == (int)RpcSignalType.Call) {
				Call(ref packet, xId);
			}
			else if (type == (int)RpcSignalType.Reply) {
				Reply(ref packet, xId);
			}

			//RaisePacketReceived(e);

			if (packet.ProgramID == this.ProgramID) {
				//Console.WriteLine("Found program: " + packet.ProgramID);
				Process(packet, receivedFrom);
			}
		}
Beispiel #5
0
 private void EnqueueMessage(object sender, UdpPacketReceivedEventArgs e)
 {
     _comunicationManager.Receive(e.EndPoint, e.Data);
 }
Beispiel #6
0
        private void DiscoveryOnUdpPacketReceived(object sender, UdpPacketReceivedEventArgs args)
        {
            var msg = Encoding.ASCII.GetString(args.Data);
            var msgArr = msg.Split(':');
            var remoteId = Guid.Parse(msgArr[1]);
            if(_id == remoteId) return;

            var remoteIP = IPAddress.Parse(msgArr[2]);
            var remoteHost = int.Parse(msgArr[3]);
            var remoteEndpoint = new IPEndPoint(remoteIP, remoteHost);
            _comunicationManager.Connect(remoteEndpoint);
        }
        private void net_Received(object sender, UdpPacketReceivedEventArgs e) 
        {
            TS2Packet packet = new TS2Packet();
            packet.ReadPacket(e.Response.Buffer);
            ClientID = packet.ClientID;
            RealClientID = packet.ClientID;
            Stream stream = null;
            BinaryReader reader = null;
            try
            {
                if (packet.Data == null)
                {
                    packet.Data = new byte[] { 0x00 };
                }
                stream = new MemoryStream(packet.Data);
                reader = new BinaryReader(stream);
            }
            catch (Exception err)
            {
            }
            switch (packet.Class)
            {
                case TS2.CONNECTION:
                    switch (packet.Type)
                    {
                        case TS2.LOGINREPLY:
                            LoginHandler(reader);
                            break;
                        case TS2.PING_REPLY:
                            PingSequenceNumber = packet.SequenceNumber+1;
                            break;
                        default:
                            Console.WriteLine("Unhandled Packet Type");
                            break;
                    }
                    break;

                case TS2.STANDARD:
                    switch (packet.Type)
                    {
                        case TS2.PLAYERLIST:
                            PlayerListHandler(reader);
                            break;
                        case TS2.CHANNELLIST:
                            if (pingThread == null)
                            {
                                pingThread = new Thread(new ThreadStart(PingThread));
                                pingThread.Start();
                            }
                            break;
                        case TS2.NEWPLAYER:
                            NewPlayerHandler(reader);
                            break;
                        case TS2.PLAYERQUIT:
                            Console.WriteLine("Player left!");
                            PlayerQuitHandler(reader);
                            break;
                        default:
                            break;
                    }
                    AckHandler(packet.SequenceNumber);
                    break;

                case TS2.ACK:
                    if (disconnectPending)
                    {
                        if (packet.SequenceNumber == this.dcSequenceNumber)
                        {
                            disconnectPending = false;
                        }
                    }
                    AckHandler(packet.SequenceNumber);
                    this.SequenceNumber = packet.SequenceNumber + 1;
                    break;

                default:
                    Console.WriteLine("Unknown Packet");
                    break;
            }
        }