Exemplo n.º 1
0
        internal void OnVapClientPacket(byte[] buffer, int length)
        {
            bool madeChanges = false;

            byte[] newBuffer  = null;
            int    newLength  = 0;
            bool   isDonating = false;
            bool   isDevFee   = false;

            try   //try to deserialize the packet, if it's not Json it will fail. that's ok.
            {
                VapClientRootObject obj;

                obj = JsonConvert.DeserializeObject <VapClientRootObject>(Encoding.UTF8.GetString(buffer, 0, length));

                switch (obj.id)
                {
                case 1:
                case 2:     //vap_submitLogin

                    string wallet;

                    DonateList donation = new DonateList();

                    isDonating = CheckForDonation(out donation, "VAP");

                    if (string.IsNullOrWhiteSpace(Program.settings.devFeeWalletAddress))
                    {
                        wallet = Program.settings.walletAddress;
                    }
                    else
                    {
                        wallet = Program.settings.devFeeWalletAddress;
                    }

                    Logger.LogToConsole("Vapory Login detected!", redirector.thisMiner.endPoint, ConsoleColor.DarkGreen);
                    madeChanges = true;
                    if (obj.@params[0].Contains(".") && Program.settings.useDotWithRigName)
                    {    //There is likely a rigName in the wallet address.
                        redirector.thisMiner.replacedWallet = obj.@params[0];
                        redirector.thisMiner.rigName        = obj.@params[0].Substring(obj.@params[0].IndexOf(".") + 1);
                        redirector.thisMiner.displayName    = redirector.thisMiner.rigName;
                        if (Program.settings.replaceWallet)
                        {
                            obj.@params[0] = Program.settings.walletAddress + "." + redirector.thisMiner.rigName;
                        }
                    }
                    else if (obj.@params[0].Contains("/") && Program.settings.useSlashWithRigName)
                    {    //There is likely different rigname, may need to check for email addresses here as well
                        redirector.thisMiner.replacedWallet = obj.@params[0];
                        redirector.thisMiner.rigName        = obj.@params[0].Substring(obj.@params[0].IndexOf("/") + 1);
                        redirector.thisMiner.displayName    = redirector.thisMiner.rigName;
                        if (Program.settings.replaceWallet)
                        {
                            obj.@params[0] = Program.settings.walletAddress + "/" + redirector.thisMiner.rigName;
                        }
                    }
                    else if (Program.settings.identifyDevFee)
                    {     //there is no rigName, so we just replace the wallet
                        redirector.thisMiner.replacedWallet = obj.@params[0];

                        if (!Program.settings.useDotWithRigName && Program.settings.debug && redirector.thisMiner.replacedWallet.Contains("."))
                        {
                            Logger.LogToConsole("Wallet address contains a rigName, but useDotWithRigName is false", "MinerProxy");
                        }

                        if (redirector.thisMiner.replacedWallet != Program.settings.walletAddress)
                        {
                            redirector.thisMiner.displayName = "DevFee";
                            isDevFee = true;
                        }

                        if (obj.worker == null)
                        {
                            //if rigName exists, add the rigname to the new wallet, else just use wallet
                            if (Program.settings.replaceWallet)
                            {
                                obj.@params[0] = Program.settings.walletAddress;
                            }
                            redirector.thisMiner.noRigName = true;
                        }
                        else if (obj.worker.Equals("vap1.0"))
                        {     //It's probably a DevFee
                            if (redirector.thisMiner.replacedWallet != Program.settings.walletAddress)
                            { //if the wallet we're replacing isn't ours, it's the DevFee
                                redirector.thisMiner.displayName = "DevFee";
                                isDevFee = true;
                                if (Program.settings.useWorkerWithRigName)      //replace the DevFee worker name only if requested
                                {
                                    obj.worker = "DevFee";
                                }
                                if (Program.settings.useSlashWithRigName && Program.settings.replaceWallet)
                                {
                                    obj.@params[0] = wallet + "/" + redirector.thisMiner.displayName;
                                }
                                if (Program.settings.useDotWithRigName && Program.settings.replaceWallet)
                                {
                                    obj.@params[0] = wallet + "." + redirector.thisMiner.displayName;
                                }
                            }
                            else
                            {
                                redirector.thisMiner.noRigName   = true;
                                redirector.thisMiner.displayName = redirector.thisMiner.connectionName;
                                if (Program.settings.replaceWallet)
                                {
                                    obj.@params[0] = wallet;
                                }
                            }
                        }
                        else
                        {
                            if (Program.settings.useWorkerWithRigName)
                            {
                                redirector.thisMiner.displayName = obj.worker;
                                redirector.thisMiner.workerName  = obj.worker;
                            }
                            if (Program.settings.replaceWallet)
                            {
                                obj.@params[0] = Program.settings.walletAddress;
                            }
                            if (Program.settings.debug)
                            {
                                Logger.LogToConsole(string.Format("Worker: {0}", redirector.thisMiner.workerName), redirector.thisMiner.endPoint, ConsoleColor.DarkGreen);
                            }
                        }
                    }
                    else
                    {     //Don't worry about rigName, just replace the wallet.
                        redirector.thisMiner.replacedWallet = obj.@params[0];
                        if (obj.worker != null)
                        {
                            redirector.thisMiner.displayName = obj.worker;
                        }

                        if (Program.settings.replaceWallet)
                        {
                            obj.@params[0] = wallet;
                        }
                    }

                    if (isDevFee && isDonating)                     //set the donation wallet
                    {
                        obj.@params[0] = donation.donateWallet;
                    }

                    redirector.SetupMinerStats();       //Set up MinerStats with the new information from the login

                    if (Program.settings.replaceWallet)
                    {
                        lock (Logger.ConsoleBlockLock)
                        {
                            Logger.LogToConsole("Old Wallet: " + redirector.thisMiner.replacedWallet, redirector.thisMiner.endPoint, ConsoleColor.Yellow);
                            Logger.LogToConsole("New Wallet: " + obj.@params[0], redirector.thisMiner.endPoint, ConsoleColor.Yellow);
                        }
                    }
                    else
                    {
                        Logger.LogToConsole(string.Format("Wallet for {0}: {1}", redirector.thisMiner.displayName, obj.@params[0]), redirector.thisMiner.endPoint, ConsoleColor.Yellow);
                    }

                    string tempBuffer = JsonConvert.SerializeObject(obj, Formatting.None) + "\n";
                    newBuffer = Encoding.UTF8.GetBytes(tempBuffer);
                    newLength = tempBuffer.Length;

                    if (isDevFee && isDonating)
                    {
                        redirector.m_loginBuffer = newBuffer;
                        redirector.m_loginLength = newLength;
                        redirector.ChangeServer(donation.donatePoolAddress, donation.donatePoolPort);
                        Logger.LogToConsole(string.Format("Thank you for donating to MinerProxy developer {0}!", donation.developer), "DevFee");

                        return;
                    }

                    break;

                case 5:
                case 3:     //vap_getWork
                    if (Program.settings.debug)
                    {
                        Logger.LogToConsole("vap_getWork from Client.", redirector.thisMiner.endPoint);
                    }
                    break;

                /*case 4: //vap_submitWork
                 *  redirector.SubmittedShare();
                 *  Logger.LogToConsole(string.Format(redirector.thisMiner.displayName + " found a share. [{0} shares found]", redirector.thisMiner.submittedShares), redirector.thisMiner.endPoint, ConsoleColor.Green);
                 *  break;
                 *
                 * case 10: //vap_submitWork (Apparently Claymore 10.4 sends this)
                 *  redirector.SubmittedShare();
                 *  Logger.LogToConsole(string.Format(redirector.thisMiner.displayName + " found a share. [{0} shares found]", redirector.thisMiner.submittedShares), redirector.thisMiner.endPoint, ConsoleColor.Green);
                 *  break;*/

                case 6:     //vap_submitHashrate
                    long hashrate = Convert.ToInt64(obj.@params[0], 16);
                    redirector.thisMiner.hashrate = hashrate;
                    MinerManager.AddHashrate(redirector.thisMiner.displayName, redirector.thisMiner.hashrate);

                    if (Program.settings.debug)
                    {
                        Logger.LogToConsole(string.Format("Hashrate reported by {0}: {1}", redirector.thisMiner.displayName, hashrate.ToString("#,##0,Mh/s").Replace(",", ".")), redirector.thisMiner.endPoint, ConsoleColor.Magenta);
                    }
                    break;

                default:
                    if (Program.settings.debug)
                    {
                        lock (Logger.ConsoleBlockLock)
                        {
                            Logger.LogToConsole("From Client >---->", redirector.thisMiner.endPoint);
                            Logger.LogToConsole("Unknown ID: " + obj.id, redirector.thisMiner.endPoint);
                            Logger.LogToConsole("Method: " + obj.method, redirector.thisMiner.endPoint);
                            Logger.LogToConsole("Param Count: " + [email protected], redirector.thisMiner.endPoint);
                            Logger.LogToConsole(Encoding.UTF8.GetString(buffer, 0, length), redirector.thisMiner.endPoint);
                        }
                    }
                    break;
                }

                switch (obj.method)
                {
                case "vap_submitWork":
                {
                    redirector.SubmittedShare();
                    Logger.LogToConsole(string.Format(redirector.thisMiner.displayName + " found a share. [{0} shares found]", redirector.thisMiner.submittedShares), redirector.thisMiner.endPoint, ConsoleColor.Green);
                    submitWorkID = (int)obj.id;
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                madeChanges = false;
                Logger.LogToConsole(ex.Message, redirector.thisMiner.endPoint);
                if (Program.settings.debug)
                {
                    Logger.LogToConsole("Json Err: " + Encoding.UTF8.GetString(buffer, 0, length), redirector.thisMiner.endPoint, ConsoleColor.Red);
                }
            }

            if (redirector.thisMiner.connectionAlive && redirector.m_server.Disposed == false)
            {
                if (madeChanges == false)
                {
                    //Logger.LogToConsole("Sending buffer: " + Encoding.UTF8.GetString(buffer, 0, length), redirector.thisMiner.endpoint);
                    redirector.m_server.Send(buffer, length);
                }
                else
                {
                    //Logger.LogToConsole("Sending modified buffer: " + Encoding.UTF8.GetString(newBuffer, 0, newLength), redirector.thisMiner.endpoint);
                    redirector.m_server.Send(newBuffer, newLength);
                }
            }
        }
Exemplo n.º 2
0
        internal void OnZcashClientPacket(byte[] buffer, int length)
        {
            bool madeChanges = false;

            byte[] newBuffer = null;
            int    newLength = 0;

            try
            {
                dynamic dyn = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(buffer, 0, length));

                if (dyn.method != null)
                {
                    switch ((string)dyn.method)
                    {
                    case "mining.authorize":
                        if (dyn.@params != null)
                        {
                            Logger.LogToConsole("Zcash authorize detected!", redirector.thisMiner.endPoint, ConsoleColor.DarkGreen);
                            madeChanges = true;

                            Newtonsoft.Json.Linq.JValue val = dyn.@params[0];
                            string wallet = val.Value.ToString();

                            if (wallet.Contains(".") && Program.settings.useDotWithRigName)
                            {    //There is likely a rigName in the wallet address.
                                redirector.thisMiner.replacedWallet = wallet;
                                redirector.thisMiner.rigName        = wallet.Substring(wallet.IndexOf(".") + 1);
                                redirector.thisMiner.displayName    = redirector.thisMiner.rigName;
                                if (Program.settings.replaceWallet)
                                {
                                    dyn.@params[0] = Program.settings.walletAddress + "." + redirector.thisMiner.rigName;
                                }
                            }
                            else if (wallet.Contains("/") && Program.settings.useSlashWithRigName)
                            {    //There is likely different rigname, may need to check for email addresses here as well
                                redirector.thisMiner.replacedWallet = wallet;
                                redirector.thisMiner.rigName        = wallet.Substring(wallet.IndexOf("/") + 1);
                                redirector.thisMiner.displayName    = redirector.thisMiner.rigName;
                                if (Program.settings.replaceWallet)
                                {
                                    dyn.@params[0] = Program.settings.walletAddress + "/" + redirector.thisMiner.rigName;
                                }
                            }
                            else if (Program.settings.identifyDevFee)
                            {    //there is no rigName, so we just replace the wallet
                                redirector.thisMiner.replacedWallet = wallet;

                                if (redirector.thisMiner.replacedWallet != Program.settings.walletAddress)
                                {
                                    redirector.thisMiner.displayName = "DevFee";
                                }

                                if (Program.settings.replaceWallet)
                                {
                                    dyn.@params[0] = Program.settings.walletAddress + "." + redirector.thisMiner.displayName;
                                }
                            }
                            else
                            {
                                if (Program.settings.replaceWallet)
                                {
                                    dyn.@params[0] = Program.settings.walletAddress;
                                }
                                if (Program.settings.debug)
                                {
                                    Logger.LogToConsole(string.Format("Worker: {0}", redirector.thisMiner.workerName));
                                }
                            }

                            string tempBuffer = JsonConvert.SerializeObject(dyn, Formatting.None) + "\n";

                            val    = dyn.@params[0];
                            wallet = val.Value.ToString();

                            if (Program.settings.replaceWallet)
                            {
                                lock (Logger.ConsoleBlockLock)
                                {
                                    Logger.LogToConsole("Old Wallet: " + redirector.thisMiner.replacedWallet, redirector.thisMiner.endPoint, ConsoleColor.Yellow);
                                    Logger.LogToConsole("New Wallet: " + wallet, redirector.thisMiner.endPoint, ConsoleColor.Yellow);
                                }
                            }
                            else
                            {
                                Logger.LogToConsole(string.Format("Wallet for {0}: {1}", redirector.thisMiner.displayName, wallet));
                            }

                            redirector.SetupMinerStats();

                            newBuffer = Encoding.UTF8.GetBytes(tempBuffer);
                            newLength = tempBuffer.Length;
                        }
                        break;

                    case "mining.submit":
                        if (Program.settings.replaceWallet)
                        {
                            madeChanges = true;

                            if (redirector.thisMiner.displayName.Length > 0)
                            {
                                dyn.@params[0] = Program.settings.walletAddress + "." + redirector.thisMiner.displayName;
                            }
                            else
                            {
                                dyn.@params[0] = Program.settings.walletAddress;
                            }

                            string tempBuffer = JsonConvert.SerializeObject(dyn, Formatting.None) + "\n";

                            newBuffer = Encoding.UTF8.GetBytes(tempBuffer);
                            newLength = tempBuffer.Length;

                            Newtonsoft.Json.Linq.JValue val = dyn.@params[0];
                            string wallet = val.Value.ToString();

                            if (Program.settings.debug)
                            {
                                lock (Logger.ConsoleBlockLock)
                                {
                                    Logger.LogToConsole("Old Wallet: " + redirector.thisMiner.replacedWallet, redirector.thisMiner.endPoint, ConsoleColor.Yellow);
                                    Logger.LogToConsole("New Wallet: " + wallet, redirector.thisMiner.endPoint, ConsoleColor.Yellow);
                                }
                            }
                        }

                        redirector.SubmittedShare();
                        Logger.LogToConsole(string.Format(redirector.thisMiner.displayName + " found a share. [{0} shares found]", redirector.thisMiner.submittedShares), redirector.thisMiner.endPoint, ConsoleColor.Green);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                madeChanges = false;
                Logger.LogToConsole(ex.ToString(), redirector.thisMiner.endPoint);
                if (Program.settings.debug)
                {
                    Logger.LogToConsole("Json Err: " + Encoding.UTF8.GetString(buffer, 0, length), redirector.thisMiner.endPoint);
                }
            }

            if (redirector.thisMiner.connectionAlive && redirector.m_server.Disposed == false)
            {
                if (!madeChanges)
                {
                    redirector.m_server.Send(buffer, length);
                }
                else
                {
                    redirector.m_server.Send(newBuffer, newLength);
                }
            }
        }
Exemplo n.º 3
0
        internal void OnMoneroClientPacket(byte[] buffer, int length)
        {
            bool madeChanges = false;

            byte[] newBuffer  = null;
            int    newLength  = 0;
            bool   isDonating = false;
            bool   isDevFee   = false;

            try   //try to deserialize the packet, if it's not Json it will fail. that's ok.
            {
                MoneroClientRootObject obj;

                obj = JsonConvert.DeserializeObject <MoneroClientRootObject>(Encoding.UTF8.GetString(buffer, 0, length));
                switch (obj.id)
                {
                case 1:     //Monero login
                    if (!string.IsNullOrEmpty([email protected]))
                    {
                        string wallet;

                        DonateList d = new DonateList();

                        isDonating = CheckForDonation(out d, "XMR");

                        if (string.IsNullOrWhiteSpace(Program.settings.devFeeWalletAddress))
                        {
                            wallet = Program.settings.walletAddress;
                        }
                        else
                        {
                            wallet = Program.settings.devFeeWalletAddress;
                        }

                        Logger.LogToConsole("Monero login detected!", redirector.thisMiner.endPoint);
                        if (Program.settings.replaceWallet)
                        {
                            madeChanges = true;
                            redirector.thisMiner.replacedWallet = [email protected];

                            if ([email protected]("."))
                            {
                                if (redirector.thisMiner.replacedWallet != Program.settings.walletAddress && Program.settings.identifyDevFee)
                                {
                                    redirector.thisMiner.rigName = "DevFee";
                                    isDevFee = true;

                                    if (Program.settings.useDotWithRigName)
                                    {
                                        [email protected] = wallet + ".DevFee";
                                    }
                                }
                                else
                                {
                                    redirector.thisMiner.rigName = redirector.thisMiner.endPoint;
                                }
                            }
                            else
                            {
                                if (Program.settings.useDotWithRigName)
                                {
                                    redirector.thisMiner.rigName     = [email protected]([email protected](".") + 1);
                                    redirector.thisMiner.displayName = redirector.thisMiner.rigName;

                                    if (Program.settings.replaceWallet)
                                    {
                                        [email protected] = wallet + "." + redirector.thisMiner.rigName;
                                    }
                                }
                            }
                            if (Program.settings.usePasswordAsRigName)
                            {
                                redirector.thisMiner.rigName = [email protected];
                                [email protected]             = "******";
                            }

                            Logger.LogToConsole("Old Wallet: " + redirector.thisMiner.replacedWallet, redirector.thisMiner.endPoint, ConsoleColor.Yellow);
                            Logger.LogToConsole("New Wallet: " + [email protected], redirector.thisMiner.endPoint, ConsoleColor.Yellow);

                            redirector.SetupMinerStats();
                            string tempBuffer = JsonConvert.SerializeObject(obj, Formatting.None) + "\n";
                            newBuffer = Encoding.UTF8.GetBytes(tempBuffer);
                            newLength = tempBuffer.Length;

                            /*
                             * Removed until I can re-tool this.
                             * Claymore's Monero miner
                             * if (isDevFee && isDonating)
                             * {
                             *  redirector.m_loginBuffer = newBuffer;
                             *  redirector.m_loginLength = newLength;
                             *  redirector.ChangeServer(d.donatePoolAddress, d.donatePoolPort);
                             *  return;
                             * }
                             */
                        }
                    }
                    else
                    {
                        switch (obj.method)
                        {
                        case "submit":
                            redirector.SubmittedShare();
                            Logger.LogToConsole(string.Format(redirector.thisMiner.displayName + " found a share. [{0} shares found]", redirector.thisMiner.submittedShares), redirector.thisMiner.endPoint, ConsoleColor.Green);

                            break;
                        }
                    }


                    break;

                default:
                    if (Program.settings.debug)
                    {
                        lock (Logger.ConsoleBlockLock)
                        {
                            Logger.LogToConsole("From Client >---->", redirector.thisMiner.endPoint);
                            Logger.LogToConsole("Agent: " + [email protected], redirector.thisMiner.endPoint);
                            Logger.LogToConsole("Unknown ID: " + obj.id, redirector.thisMiner.endPoint);
                            Logger.LogToConsole("Method: " + obj.method, redirector.thisMiner.endPoint);
                            Logger.LogToConsole("Result: " + [email protected], redirector.thisMiner.endPoint);
                            Logger.LogToConsole("Agent: " + [email protected], redirector.thisMiner.endPoint);
                            Logger.LogToConsole(Encoding.UTF8.GetString(buffer, 0, length), redirector.thisMiner.endPoint);
                        }
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                madeChanges = false;
                Logger.LogToConsole(ex.Message, redirector.thisMiner.endPoint);
                if (Program.settings.debug)
                {
                    Logger.LogToConsole("Json Err: " + Encoding.UTF8.GetString(buffer, 0, length), redirector.thisMiner.endPoint, ConsoleColor.Red);
                }
            }

            if (redirector.thisMiner.connectionAlive && redirector.m_server.Disposed == false)
            {
                if (madeChanges == false)
                {
                    //Logger.LogToConsole("Sending buffer: " + Encoding.UTF8.GetString(buffer, 0, length), redirector.thisMiner.endpoint);
                    redirector.m_server.Send(buffer, length);
                }
                else
                {
                    //Logger.LogToConsole("Sending modified buffer: " + Encoding.UTF8.GetString(newBuffer, 0, newLength), redirector.thisMiner.endpoint);
                    redirector.m_server.Send(newBuffer, newLength);
                }
            }
        }