Ejemplo n.º 1
0
        public void PlayDemo(string filename)
        {
            if (File.Exists(filename))
            {
                this.connState   = ConnectionState.Connected;
                this.demoPlaying = true;

                this.demoFileStream       = File.OpenRead(filename);
                this.demoStream           = new Q3DemoStream(this.demoFileStream, this);
                this.q3HuffDemoReadStream = new Q3HuffmanStream(this.demoStream, CompressionMode.Decompress);
                q3HuffDemoReadStream.InitWithQ3Data();
                q3HuffDemoReadStream.TreeIsFrozen = true;

                try {
                    while (this.connState >= ConnectionState.Connected && this.connState < ConnectionState.Primed)
                    {
                        ReadPacket(this.q3HuffDemoReadStream);
                    }

                    this.firstDemoFrameSkipped = false;

                    while (true)
                    {
                        ReadPacket(this.q3HuffDemoReadStream);
                    }
                } catch (Exception ex) {
                    // Demo end
                }
            }
            else
            {
                throw new FileNotFoundException("Demo file not found", filename);
            }
        }
Ejemplo n.º 2
0
        public void Connect(IPAddress ip, int port)
        {
            Random rnd = new Random();

            qport = ( ushort )rnd.Next(65536);                  // Generate port from 0 to 65535 (inclusively)
            // STATIC_DEBUG
            //qport = 0x2233; // ( short ) rnd.Next ( 65536 );	// Generate port from 0 to 65535 (inclusively)
            incomingSequence = 0;
            outgoingSequence = 1;

            IPEndPoint ep = new IPEndPoint(ip, port);

            sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            try { sock.Connect(ep); } catch { throw; }
            q3NetStream   = new Q3NetworkStream(sock, this, FileAccess.ReadWrite);
            q3CryptStream = new Q3CryptStream(q3NetStream, this, FileAccess.ReadWrite);
            q3HuffCStream = new Q3HuffmanStream(q3CryptStream, CompressionMode.Compress);
            q3HuffCStream.InitWithQ3Data();
            q3HuffCStream.TreeIsFrozen = true;

            q3HuffDStream = new Q3HuffmanStream(q3CryptStream, CompressionMode.Decompress);
            q3HuffDStream.InitWithQ3Data();
            q3HuffDStream.TreeIsFrozen = true;

            if (DoConnectionlessHandshake())
            {
                // enter main loop

                SendUserInfo();                         // FIXIT: move this out of here

                while (true)
                {
                    ReadPacket(q3HuffDStream);
                    SendCmd();
                    System.Threading.Thread.Sleep(10);
                }
            }
            else
            {
                throw new Exception(string.Format("Could not connect to {0}", ep));
            }
        }