Beispiel #1
0
        private void OnClientConnected(NamedPipeConnection <IdleMessage, IdleMessage> connection)
        {
            if (!connectedToService)
            {
                Utilities.Log(string.Format("idleMon Client {0} is now connected!", connection.Id));

                //On connection, we'll send a MD5 hash of the MachineGUID+UserName+Current system time
                SendPipeMessage(PacketID.Authenticate, false, Utilities.GenerateAuthString(Environment.UserName), Environment.UserName, PacketID.Authenticate, connection);
            }
            else
            {
                Utilities.Log("New connection, but already connected to service?");
                connection.Close();
            }
        }
Beispiel #2
0
        private void OnClientMessage(NamedPipeConnection <IdleMessage, IdleMessage> connection, IdleMessage message)
        {
            if (!authenticatedClients.Contains(connection) && message.packetId != (int)PacketID.Authenticate)
            {
                Utilities.Log($"{connection.Name}: has not authenticated, and sending non-auth first packet; closing pipe.");
                connection.Close();
            }

            switch (message.packetId)
            {
            case (int)PacketID.Authenticate:

                if (Utilities.VerifyAuthString(message.data, message.data2))
                {
                    Utilities.Log($"{connection.Name}: {message.data2} has authenticated successfully.");
                    authenticatedClients.Add(connection);

                    timer.Start();
                    if (monitorFullscreen)
                    {
                        fullscreenTimer.Start();
                    }
                    connectedToService = true;

                    SendPipeMessage(PacketID.Hello, Utilities.IsIdle(), Environment.UserName, "", PacketID.None, connection);
                }
                else
                {
                    Utilities.Log($"{connection.Name}: incorrect authentication packet; closing pipe.");
                    connection.Close();
                }
                break;

            case (int)PacketID.RunProgram:
                Utilities.Log($"Running program: {message.data} {message.data2}");

                Utilities.LaunchProcess(message.data, message.data2);

                break;

            case (int)PacketID.RunInUserSession:

                Utilities.Log($"RunInUserSession received: {message.isIdle}");

                RunInUserSession = message.isIdle;

                if (!message.isIdle)
                {
                    RunInUserSessioneMenuItem.Text = "Run miners on the Desktop";
                }
                else
                {
                    RunInUserSessioneMenuItem.Text = "Run miners in the System session";
                }

                break;

            case ((int)PacketID.Pause):
                Utilities.Log("Pause received from MiningService.");
                PauseMining(true);
                break;

            case ((int)PacketID.Resume):
                Utilities.Log("Resume received from MiningService.");
                PauseMining(false);
                break;

            case ((int)PacketID.IdleTime):

                int minutes = Int32.Parse(message.data);

                if (minutes < 0 || minutes > 3600)
                {
                    Utilities.minutesIdle = 10;
                }
                else
                {
                    Utilities.minutesIdle = minutes;
                }

                Utilities.Log("IdleTime received from MiningService: " + Utilities.minutesIdle);

                break;

            case ((int)PacketID.Stealth):
                Utilities.Log("Stealth received from MiningService: " + message.isIdle);

                //stealthMode = message.isIdle;
                //if (stealthMode)

                //InitializeComponent();

                /*
                 * if (Program.stealthMode) {
                 *  Utilities.Log("Stealth initialized.");
                 * } else
                 * {
                 *  TrayIcon.Visible = false;
                 * }
                 */
                break;

            case ((int)PacketID.Log):
                if (message.isIdle)
                {
                    enableLogging = message.isIdle;
                    Utilities.Log("Logging initialized.");
                }
                break;

            case ((int)PacketID.Message):
                if (TrayIcon != null)
                {
                    ShowNotification(message.data, ToolTipIcon.None, 1000);
                }
                break;

            case ((int)PacketID.Stop):

                StopIdleMon();
                break;

            case ((int)PacketID.Fullscreen):
                if (message.isIdle)
                {
                    monitorFullscreen = message.isIdle;
                    fullscreenTimer.Start();
                    Utilities.Log("Fullscreen monitoring initialized.");
                }
                break;

            case ((int)PacketID.CheckFullscreenStillRunning):
                if (message.isIdle)
                {
                    CheckFullscreenStillRunning = message.isIdle;
                    fullscreenTimer.Start();
                    Utilities.Log("Received CheckFullscreenStillRunning: " + message.isIdle);
                }
                break;

            case ((int)PacketID.IgnoreFullscreenApp):

                Utilities.ignoredFullscreenApps.Add(message.data);
                //Utilities.Log("Received IgnoreFullscreenApp: " + message.data);
                break;

            case ((int)PacketID.Notifications):

                Utilities.ShowDesktopNotifications = message.isIdle;

                break;

            case ((int)PacketID.Hello):

                if (message.requestId == (int)PacketID.Pause)
                {
                    PauseMining(stateToSet: true, showTrayNotification: false);
                    if (TrayIcon != null)
                    {
                        ShowNotification("Mining is currently Paused.", ToolTipIcon.None, 1000);
                    }
                }

                if (message.requestId == (int)PacketID.Resume)
                {
                    PauseMining(stateToSet: false, showTrayNotification: false);
                }
                break;
            }
        }
Beispiel #3
0
        private void OnServerMessage(NamedPipeConnection <IdleMessage, IdleMessage> connection, IdleMessage message)
        {
            Config.sessionLaunchAttempts = 0;
            Config.isPipeConnected       = true;

            if (!Config.hasClientAuthenticated && message.packetId != (int)Config.PacketID.Authenticate)
            {
                Utilities.Log($"{connection.Name}: has not authenticated, and sending non-auth first packet; closing pipe: {message.packetId}");
                connection.Close();
            }

            switch (message.packetId)
            {
            case ((int)Config.PacketID.Authenticate):

                if (Utilities.VerifyAuthString(message.data, message.data2))
                {
                    Utilities.Log($"{message.data2} has authenticated successfully.");

                    Config.hasClientAuthenticated = true;

                    connection.PushMessage(new IdleMessage
                    {
                        packetId  = (int)Config.PacketID.Authenticate,
                        isIdle    = false,
                        requestId = (int)Config.PacketID.None,
                        data      = Utilities.GenerateAuthString("SYSTEM"),
                        data2     = "SYSTEM"
                    });
                }
                else
                {
                    Utilities.Log($"{connection.Name}: incorrect authentication packet; closing pipe.");
                    connection.Close();
                }

                break;

            case ((int)Config.PacketID.Idle):
                Utilities.Debug("Idle received from " + message.data + ": " + message.isIdle);

                if (Config.isUserLoggedIn)
                {
                    if (!Config.isMiningPaused)
                    {
                        connection.PushMessage(new IdleMessage
                        {
                            packetId  = (int)Config.PacketID.Message,
                            isIdle    = false,
                            requestId = (int)Config.PacketID.None,
                            data      = "You have been detected as " + (message.isIdle ? "idle." : "active.")
                        });
                    }
                    else
                    {
                        if (!message.isIdle)
                        {
                            connection.PushMessage(new IdleMessage
                            {
                                packetId  = (int)Config.PacketID.Message,
                                isIdle    = false,
                                requestId = (int)Config.PacketID.None,
                                data      = "You have been detected as active but mining is paused!"
                            });
                        }
                    }

                    Config.cpuUsageQueue = new Queue <int>();

                    Config.isUserIdle = message.isIdle;
                    OnMinerTimerEvent(minerTimer, null);        //call the minerTime event immediately to process the change.
                }
                break;

            case ((int)Config.PacketID.Pause):
                Config.isMiningPaused = true;
                Utilities.KillMiners();
                Utilities.Log("Mining has been paused by IdleMon.");

                connection.PushMessage(new IdleMessage
                {
                    packetId  = (int)Config.PacketID.Pause,
                    isIdle    = false,
                    requestId = (int)Config.PacketID.None,
                    data      = ""
                });

                break;

            case ((int)Config.PacketID.Resume):
                Config.isMiningPaused = false;
                Utilities.Log("Mining has been resumed by IdleMon.");

                connection.PushMessage(new IdleMessage
                {
                    packetId  = (int)Config.PacketID.Resume,
                    isIdle    = false,
                    requestId = (int)Config.PacketID.None,
                    data      = ""
                });

                break;

            case ((int)Config.PacketID.Stop):

                Abort();

                break;

            case ((int)Config.PacketID.IgnoreFullscreenApp):

                Config.settings.ignoredFullscreenApps.Add(message.data);

                Config.WriteConfigToFile();

                break;

            case ((int)Config.PacketID.Fullscreen):

                lock (Config.timeLock)
                {
                    if (message.isIdle && Config.fullscreenDetected != true && !Config.isMiningPaused)
                    {
                        Utilities.Log("idleMon detected Fullscreen program: " + message.data);

                        connection.PushMessage(new IdleMessage
                        {
                            packetId  = (int)Config.PacketID.Message,
                            isIdle    = false,
                            requestId = (int)Config.PacketID.None,
                            data      = "Mining has been stopped because " + message.data + " was detected fullscreen."
                        });
                    }

                    if (message.isIdle)
                    {
                        Utilities.KillMiners();
                    }

                    Config.fullscreenDetected = message.isIdle;
                }

                break;

            case (int)Config.PacketID.RunInUserSession:

                Utilities.Log($"RunInUserSession received: {message.isIdle}");
                Config.settings.runInUserSession = message.isIdle;
                Utilities.KillMiners();

                break;

            case ((int)Config.PacketID.Hello):
                Utilities.Log($"idleMon user {message.data} connected");
                Config.isUserIdle = message.isIdle;

                connection.PushMessage(new IdleMessage
                {
                    packetId  = (int)Config.PacketID.Log,
                    isIdle    = Config.settings.enableLogging,
                    requestId = (int)Config.PacketID.None,
                    data      = ""
                });

                connection.PushMessage(new IdleMessage
                {
                    packetId  = (int)Config.PacketID.Notifications,
                    isIdle    = Config.settings.showDesktopNotifications,
                    requestId = (int)Config.PacketID.None,
                    data      = ""
                });

                connection.PushMessage(new IdleMessage
                {
                    packetId  = (int)Config.PacketID.IdleTime,
                    isIdle    = false,
                    requestId = (int)Config.PacketID.None,
                    data      = Config.settings.minutesUntilIdle.ToString()
                });

                connection.PushMessage(new IdleMessage
                {
                    packetId  = (int)Config.PacketID.Fullscreen,
                    isIdle    = Config.settings.monitorFullscreen,
                    requestId = (int)Config.PacketID.None,
                    data      = ""
                });

                //
                connection.PushMessage(new IdleMessage
                {
                    packetId  = (int)Config.PacketID.CheckFullscreenStillRunning,
                    isIdle    = Config.settings.checkIfFullscreenAppStillRunning,
                    requestId = (int)Config.PacketID.None,
                    data      = ""
                });

                connection.PushMessage(new IdleMessage
                {
                    packetId  = (int)Config.PacketID.RunInUserSession,
                    isIdle    = Config.settings.runInUserSession,
                    requestId = (int)Config.PacketID.None,
                    data      = ""
                });

                foreach (var app in Config.settings.ignoredFullscreenApps)
                {
                    connection.PushMessage(new IdleMessage
                    {
                        packetId  = (int)Config.PacketID.IgnoreFullscreenApp,
                        isIdle    = false,
                        requestId = (int)Config.PacketID.None,
                        data      = app
                    });
                }

                if (Config.isMiningPaused)
                {
                    connection.PushMessage(new IdleMessage
                    {
                        packetId  = (int)Config.PacketID.Hello,
                        isIdle    = false,
                        requestId = (int)Config.PacketID.Pause,
                        data      = ""
                    });
                }
                else
                {
                    connection.PushMessage(new IdleMessage
                    {
                        packetId  = (int)Config.PacketID.Hello,
                        isIdle    = false,
                        requestId = (int)Config.PacketID.Resume,
                        data      = ""
                    });
                }

                break;

            default:
                Utilities.Debug("MiningService Idle default: " + message.packetId);
                break;
            }
        }