コード例 #1
0
        static void Main(string[] args)
        {
            // set allowed protocol to download from
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (args.Length == 0)
            {
                Application.Run(new Form1());
            }
            else
            {
                var np = new NFKProcess();
                // connect to server
                if (args[0].StartsWith("nfk://"))
                {
                    var serverAddress = getServerAddress(args[0]);
                    var spectator     = !args[0].Contains("play");
                    if (!NFKHelper.SendPing(serverAddress))
                    {
                        Common.ShowError("Connection timeout", "Could not connect to NFK server " + serverAddress);
                        return;
                    }
                    if (!spectator)
                    {
                        // if play mode then just run a game and exit
                        np.RunGame(serverAddress);
                        return;
                    }
                    // run nfk
                    np.Run(serverAddress, false);

                    np.WatchForExit();
                }
                // play demo
                else
                {
                    var demoUrl = getDemoPath(args[0]);
                    Application.Run(new Form2(demoUrl, np));
                    if (!String.IsNullOrEmpty(NFKHelper.DemoFile))
                    {
                        // show video intro after the download form
                        if (np.Intro != null && !np.Intro.CloseFlag && np.GameRunning)
                        {
                            Application.Run(np.Intro);
                        }
                    }
                }
                // this form is used to keep program running
                if (np.StubForm != null && !np.StubForm.CloseFlag && np.GameRunning)
                {
                    Application.Run(np.StubForm);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Wait for game loading and adjust progress bar
        /// </summary>
        private void waitGameLoading()
        {
            lblUrl.Text = "Loading demo file ...";

            if (!NFKHelper.IsValidDemoFile(NFKHelper.DemoFile))
            {
                NFKHelper.DemoFile = null;
                Common.ShowError("Error", "Invalid NFK demo file\n" + NFKHelper.DemoFile);
                userMode = false;
                this.Close();
            }

            // run nfk
            np.Run(NFKHelper.DemoFile);
            np.WatchForExit();

            var gameLoadTime = Properties.Settings.Default.GameLoadTime > 0
                ? Properties.Settings.Default.GameLoadTime
                : NFKHelper.GAME_LOAD_TIME_DEFAULT;
            int interval = (int)(gameLoadTime - NFKHelper.INTRO_TIME) / (progressBar1.Maximum - progressBar1.Value);

            if (interval >= 0)
            {
                // run until prograss bar is filled for 100%
                for (; progressBar1.Value < progressBar1.Maximum; progressBar1.Value++)
                {
                    // if abort button clicked
                    if (String.IsNullOrEmpty(NFKHelper.DemoFile))
                    {
                        break;
                    }
                    Thread.Sleep(interval);
                    Application.DoEvents();
                }
            }

            userMode = false;
            this.Close();
        }