示例#1
0
        static void Main(string[] args)
        {
            ConsoleUtilities.DeleteMenu(ConsoleUtilities.GetSystemMenu(ConsoleUtilities.GetConsoleWindow(), false), ConsoleUtilities.SC_CLOSE, ConsoleUtilities.MF_BYCOMMAND);
            consoleHandler = new ConsoleUtilities.HandlerRoutine(ConsoleCtrlCheck);
            ConsoleUtilities.SetConsoleCtrlHandler(consoleHandler, true);

            ConfigureLogging();

            X509Certificate  x509Certificate  = Assembly.GetEntryAssembly().GetModules()[0].GetSignerCertificate();
            X509Certificate2 x509Certificate2 = x509Certificate != null ? new X509Certificate2(x509Certificate) : null;
            var signTool = new SignTool(x509Certificate2);

            if (x509Certificate2 == null || x509Certificate2.GetCertHashString() != "793D48CE7A9DDC71CE8A31E0929D215165FA9B8E")
            {
                logger.Fatal("Certificate is missing or could not be verified.");
                logger.Info("Certificate Hash: ", x509Certificate2?.GetCertHashString());
                Console.ReadLine();
                return;
            }

            CreateServer();
            StartServer();

            gameCore.StartCommandInputThread(true);
        }
示例#2
0
        static void RunRemoteApp(string Server, string MID, string Username, string Password, string Program, string Args)
        {
            ConsoleColor c = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Yellow;

#if DEBUG
            Console.WriteLine("MachineID:      " + MID);
#endif

            if (Password == "*")
            {
                IntPtr      hwnd = ConsoleUtilities.GetConsoleWindow();
                frmPassword pwd  = new frmPassword(Server, Username);
                if (pwd.ShowDialog(new WindowWrapper(hwnd)) != System.Windows.Forms.DialogResult.OK)
                {
                    Console.ForegroundColor = c;
                    return;
                }
                Password = pwd.Password;
            }

            Console.WriteLine("Connecting to server: " + Server);

            net = new Network();
            if (net.Connect(Server) == false)
            {
                Console.ForegroundColor = c;
                net = null;
                return;
            }

            if (net.Login(Username, Password) == false)
            {
                if (net.LoginError == null)
                {
                    Console.WriteLine("Login failed: ???");
                }
                else
                {
                    Console.WriteLine("Login failed: " + net.LoginError.Error);
                }
                Console.ForegroundColor = c;
                net = null;
                return;
            }

            if (LoopPing == false)
            {
                if (net.PushPing(MID) == false)
                {
                    Console.WriteLine("Remote machine does not respond to \"Ping\"");
                    Console.ForegroundColor = c;
                    net.CloseConnection();
                    net = null;
                    return;
                }
            }
            else
            {
                Console.CancelKeyPress += Console_CancelKeyPress_BreakPing;
                do
                {
                    if (net.PushPing(MID) == false)
                    {
                        Console.WriteLine("Remote machine does not respond to \"Ping\" - Retrying");
                        Thread.Sleep(2000);
                    }
                    else
                    {
                        break;
                    }
                } while (LoopPing == true);
                Console.CancelKeyPress -= Console_CancelKeyPress_BreakPing;
                if (LoopPing == false)
                {
                    Console.ForegroundColor = c;
                    net.CloseConnection();
                    net = null;
                    return;
                }
            }

            PushRunTask rt = new PushRunTask();
            rt.Executable = Program;
            rt.Args       = Args;
            rt.Option     = PushRunTaskOption.SystemUserConsoleRedir;

            PushRunTaskResult rtres = net.PushRunFile(MID, rt);
            if (rtres == null)
            {
                Console.WriteLine("Cannot start application: ???");
                Console.ForegroundColor = c;
                net.CloseConnection();
                net = null;
                return;
            }
            if (rtres.Result != 0)
            {
                string errorMessage = new Win32Exception((int)(rtres.Result)).Message;
                Console.WriteLine("Cannot start application: 0x" + rtres.Result.ToString("X") + " " + errorMessage);
                Console.ForegroundColor = c;
                net.CloseConnection();
                net = null;
                return;
            }

            StdIOSession = rtres.SessionID;
            MachineID    = MID;

#if DEBUG
            Console.WriteLine("SessionID:      " + net.Session);
            Console.WriteLine("STDIOSessionID: " + StdIOSession);
#endif

            Console.WriteLine("Connected.");
            Console.ForegroundColor = c;
            Thread.Sleep(1000);
        }