Exemplo n.º 1
0
        public void StartTimers()
        {
            minerTimer.Start();
            sessionTimer.Start();

            if (Config.settings.monitorCpuTemp || Config.settings.monitorGpuTemp)
            {
                temperatureTimer.Start();
            }

            //apiCheckTimer.Start();

            //Let's try to start IdleMon now
            CheckSession();

            //start attempting to connect to IdleMon through a NamedPipe
            Config.client.Start();

            if (Config.settings.preventSleep)
            {
                Utilities.PreventSleep();
            }

            Config.currentSessionId = ProcessExtensions.GetSession();
            Utilities.CheckForSystem(Config.currentSessionId);
        }
Exemplo n.º 2
0
        /*
         * private async Task<String> getTestObjects(string url)
         * {
         *  var httpClient = new HttpClient();
         *  httpClient.Timeout = System.TimeSpan.FromMilliseconds(2000);
         *  var response = await httpClient.GetAsync(url);
         *  var result = await response.Content.ReadAsStringAsync();
         *
         *  return result;
         * }
         *
         * private void OnApiTimer(object sender, ElapsedEventArgs e)
         * {
         *  //this timer is disabled, but just in case let's return out of it asap as it's not setup for xmrig
         *  return;
         *
         *  try
         *  {
         *      if (Config.isCurrentlyMining != true)
         *          return;
         *
         *      XmrRoot test = JsonConvert.DeserializeObject<XmrRoot>(getTestObjects("http://127.0.0.1:16000/api.json").Result);
         *
         *      //Utilities.Log("Pool: " + test.connection.pool);
         *      //Utilities.Log("Average Hashrate: " + test.hashrate.total.Average());
         *      //Utilities.Log("Highest Hashrate: " + test.hashrate.highest);
         *      //Utilities.Log("Shares Acc: " + test.results.shares_good);
         *      //Utilities.Log("Uptime: " + test.connection.uptime);
         *      //Utilities.Log("Ping: " + test.connection.ping);
         *
         *      if (test.connection.uptime == 0)
         *          failUptime++;
         *      else
         *          failUptime = 0;
         *
         *      //if (test.hashrate.total.Average() <= 5)
         *      //    failHashrate++;
         *      //else
         *      //    failHashrate = 0;
         *
         *      if (failUptime >= 5 || failHashrate >= 5)
         *      {
         *          failUptime = 0;
         *          failHashrate = 0;
         *          Utilities.KillProcess();
         *      }
         *
         *      //Utilities.Log(failHashrate + " - " + failUptime);
         *  } catch (Exception ex)
         *  {
         *      Utilities.Log("api: " + ex.Message);
         *  }
         * }
         */

        #endregion Old API Json reading section (not used)

        #region Timers/Events

        private void CheckSession()
        {
            if (!Utilities.IsSystem())
            {
                if (!Config.isPipeConnected)
                {
                    Utilities.KillProcess(Config.idleMonExecutable);
                    Utilities.LaunchProcess(Config.idleMonExecutable, "");
                }
                Config.isUserLoggedIn = true;
                return;
            }

            Config.currentSessionId = ProcessExtensions.GetSession();

            //Utilities.Debug("OnSessionTimer: SessionID " + Config.currentSessionId);

            Utilities.CheckForSystem(Config.currentSessionId);

            //Utilities.Debug(string.Format("Session: {0} - isLoggedIn: {1} - connected: {2} - sessionAttempts: {3} - isUserIdle: {4}", Config.currentSessionId, Config.isUserLoggedIn, Config.isPipeConnected, Config.sessionLaunchAttempts, Config.isUserIdle));

            if (Config.sessionLaunchAttempts > 4)
            {
                Utilities.Log("Unable to start IdleMon in user session; stopping service.", force: true);
                host.Stop();
                return;
            }

            if (Config.isUserLoggedIn && Config.computerIsLocked)
            {
                if (Config.isPipeConnected)
                {
                    Utilities.KillProcess(Config.idleMonExecutable);
                    Config.sessionLaunchAttempts = 0;
                    Config.isUserIdle            = true;
                }
                return;
            }

            if (Config.isUserLoggedIn && !Config.isPipeConnected)
            {
                Config.sessionLaunchAttempts++;
                Utilities.KillProcess(Config.idleMonExecutable);

                /* Not currently working.. May have to find a different way.
                 * string args = Config.settings.stealthMode ? "-stealth" : "";
                 * args += Config.settings.enableLogging ? "-log" : "";
                 */

                Utilities.Log("Attempting to start IdleMon in SessionID " + Config.currentSessionId + ". User: " + Utilities.GetUsernameBySessionId(Config.currentSessionId, false));

                ProcessExtensions.StartProcessAsCurrentUser(Config.idleMonExecutable, null, null, false, Config.currentSessionId);
                return;
            }
            else if (!Config.isUserLoggedIn && Config.isPipeConnected)
            {
                Config.sessionLaunchAttempts = 0;
                Utilities.KillProcess(Config.idleMonExecutable);
            }
            else if (!Config.isUserLoggedIn)
            {
                Config.sessionLaunchAttempts = 0;

                if (Config.currentSessionId > 0 && Config.remoteDisconnectedSession == -1)
                {
                    Config.isUserLoggedIn = true;
                }
            }
        }
Exemplo n.º 3
0
        public void SessionChanged(SessionChangedArguments args)
        {
            lock (Config.timeLock)
            {
                switch (args.ReasonCode)
                {
                case Topshelf.SessionChangeReasonCode.SessionLock:
                    Utilities.Log(string.Format("Session: {0} - Reason: {1} - Lock", args.SessionId, args.ReasonCode));
                    Config.isUserLoggedIn   = false;
                    Config.computerIsLocked = true;
                    Config.currentSessionId = args.SessionId;
                    Config.isUserIdle       = true;

                    if (Config.settings.resumePausedMiningOnLockOrLogoff)
                    {
                        Config.isMiningPaused = false;
                    }

                    break;

                case Topshelf.SessionChangeReasonCode.SessionLogoff:
                    Config.isUserLoggedIn = false;
                    Utilities.Log(string.Format("Session: {0} - Reason: {1} - Logoff", args.SessionId, args.ReasonCode));
                    Config.currentSessionId = 0;
                    Config.isUserIdle       = true;

                    if (Config.settings.resumePausedMiningOnLockOrLogoff)
                    {
                        Config.isMiningPaused = false;
                    }

                    break;

                case Topshelf.SessionChangeReasonCode.SessionUnlock:
                case Topshelf.SessionChangeReasonCode.ConsoleConnect:
                    Config.isUserLoggedIn   = true;
                    Config.computerIsLocked = false;
                    Utilities.Log(string.Format("Session: {0} - Reason: {1} - Unlock", args.SessionId, args.ReasonCode));
                    Config.currentSessionId = args.SessionId;
                    Config.isUserIdle       = false;
                    break;

                case Topshelf.SessionChangeReasonCode.SessionLogon:
                    Config.isUserLoggedIn   = true;
                    Config.computerIsLocked = false;
                    Utilities.Log(string.Format("Session: {0} - Reason: {1} - Login", args.SessionId, args.ReasonCode));
                    Config.currentSessionId = args.SessionId;
                    Config.isUserIdle       = false;
                    break;

                case Topshelf.SessionChangeReasonCode.RemoteDisconnect:
                    Config.isUserLoggedIn   = false;
                    Config.computerIsLocked = true;
                    Utilities.Log(string.Format("Session: {0} - Reason: {1} - RemoteDisconnect", args.SessionId, args.ReasonCode));
                    Config.currentSessionId          = args.SessionId;
                    Config.remoteDisconnectedSession = args.SessionId;
                    Config.isUserIdle = true;

                    if (Config.currentSessionId == 0)
                    {
                        if (Config.settings.resumePausedMiningOnLockOrLogoff)
                        {
                            Config.isMiningPaused = false;
                        }
                    }

                    return;

                case Topshelf.SessionChangeReasonCode.RemoteConnect:
                    Config.isUserLoggedIn   = true;
                    Config.computerIsLocked = false;
                    Utilities.Log(string.Format("Session: {0} - Reason: {1} - RemoteConnect", args.SessionId, args.ReasonCode));
                    Config.currentSessionId = ProcessExtensions.GetSession();
                    Config.isUserIdle       = false;
                    break;

                default:
                    Utilities.Debug(string.Format("Session: {0} - Other - Reason: {1}", args.SessionId, args.ReasonCode));
                    break;
                }
                Config.remoteDisconnectedSession = -1;
                Config.fullscreenDetected        = false;
                Utilities.KillMiners();
                Utilities.KillProcess(Config.idleMonExecutable);
                Config.cpuUsageQueue = new Queue <int>();
            }
        }