Ejemplo n.º 1
0
    public void MenuButton_Click(object sender, EventArgs e)
    {
        ErrorMessagePanel.Visible = false;
        var TheButton = (Button)sender;
        int viewIndex = Int32.Parse(TheButton.CommandArgument);

        MenuMultiView.ActiveViewIndex = viewIndex;

        //Change button style
        foreach (Button b in MenuButtonPlaceHolder.Controls)
        {
            b.CssClass = "";
        }
        TheButton.CssClass = "ViewSelected";

        if (viewIndex == 3)
        {
            //enable betting
            currentWindow.Text = "3";
            InvestmentsGridView.DataBind();
        }
        else if (viewIndex == 2)
        {
            //Disable betting
            currentWindow.Text = "2";

            DiceGameHash CurrentDiceGameHash = DiceGameHash.Get(user);
            CurrentDiceGameHash.ArchiveServerSeedAndHash();
            string serverSeedPrevious = CurrentDiceGameHash.ServerSeedPrevious;
            string serverHashPrevious = CurrentDiceGameHash.ServerHashPrevious;
            string clientSeedPrevious = CurrentDiceGameHash.ClientSeedCurrent;
            string numberOfBets       = DiceGameHashLogic.GetNumberOfBets(user.Id).ToString();
            CurrentDiceGameHash.GenerateServerSeedAndHash();
            CurrentDiceGameHash.Save();
            string serverHashCurrent = CurrentDiceGameHash.ServerHashCurrent;

            LastServerSeedLabel.Text     = serverSeedPrevious;
            LastServerSeedHashLabel.Text = serverHashPrevious;
            LastClientSeedLabel.Text     = clientSeedPrevious;
            NumberOfRollsLabel.Text      = numberOfBets;
            NewServerSeedHashLabel.Text  = serverHashCurrent;
            NewClientSeedTextBox.Text    = DiceGameHashLogic.GenerateClientSeed();
        }
        else if (viewIndex == 1)
        {
            //enable betting
            currentWindow.Text = "1";
        }

        else if (viewIndex == 0)
        {
            //enable betting
            currentWindow.Text = "0";
        }
        else if (viewIndex == 4)
        {
            //disable betting
            currentWindow.Text = "4";
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Generates new Server Seed and Hash
    /// </summary>
    public void GenerateServerSeedAndHash()
    {
        ArchiveServerSeedAndHash();

        DateTime currentDate = DateTime.Now;

        ServerSeedCurrent = DiceGameHashLogic.GenerateServerSeed(currentDate, User.Name, AppSettings.Offerwalls.UniversalHandlerPassword);
        ServerHashCurrent = DiceGameHashLogic.GenerateServerHash(ServerSeedCurrent);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Generates first set of hashes
    /// </summary>
    private void GenerateFirstHashes()
    {
        CreatedDateCurrent  = DateTime.Now;
        CreatedDatePrevious = DateTime.Now.Zero();
        DateTime currentDate = DateTime.Now;

        ServerSeedCurrent = DiceGameHashLogic.GenerateServerSeed(currentDate, User.Name, AppSettings.Offerwalls.UniversalHandlerPassword);
        ServerHashCurrent = DiceGameHashLogic.GenerateServerHash(ServerSeedCurrent);
        ClientSeedCurrent = DiceGameHashLogic.GenerateClientSeed();
    }
Ejemplo n.º 4
0
    public static void TryToBet(Money maxProfit, Money minBet, decimal formChance, Money formBetAmount, int houseEdge, Money formProfit, bool low)
    {
        if (formBetAmount < minBet)
        {
            throw new MsgException(U4200.BETTOOLOW + " " + minBet);
        }
        else if (formChance <= 0)
        {
            throw new MsgException(U4200.CHANCEBELOWZERO);
        }
        else if (formChance > AppSettings.DiceGame.MaxChance)
        {
            throw new MsgException(U4200.CHANCETOOHIGH);
        }

        Money houseProfit = formBetAmount * houseEdge / formChance;

        if (formProfit > maxProfit)
        {
            throw new MsgException(U4200.PROFITTOOHIGH + " " + maxProfit);
        }
        else if (formProfit <= Money.Zero)
        {
            throw new MsgException(U4200.PROFITBELOWZERO);
        }
        else if (houseProfit < new Money(0.00000001))
        {
            throw new MsgException(U4200.HOUSEPROFITTOOLOW);
        }

        Member User = Member.Current;

        DiceGameHash CurrentDiceGameHash = DiceGameHash.Get(User);
        UserBet      Bet = new UserBet();

        Bet.UserId = User.Id;

        if (User.PurchaseBalance < formBetAmount)
        {
            throw new MsgException(L1.NOTENOUGHFUNDS);
        }

        string  serverSeed    = CurrentDiceGameHash.ServerSeedCurrent;
        string  clientSeed    = CurrentDiceGameHash.ClientSeedCurrent;
        string  salt          = DiceGameHashLogic.GenerateSalt(clientSeed, Bet.UserId);
        string  hashToCompute = DiceGameHashLogic.ComputeHash(salt, serverSeed);
        decimal diceRoll      = RollTheDice(hashToCompute);
        bool    hasWon        = HasWon(formChance, low, diceRoll);
        string  query;

        Bet.BetSize = formBetAmount;
        Bet.BetDate = DateTime.Now;
        Bet.Chance  = formChance;
        Bet.Low     = low;
        if (hasWon)
        {
            Bet.Profit = formProfit;
            User.AddToMainBalance(Bet.Profit, "Dice bet win", BalanceLogType.Other);
            query = SiteInvestmentManager.GetUpdateAmountQuery(formProfit.Negatify());

            //To do: should investors lose money based on betsize or profit?
            //AppSettings.DiceGame.HouseProfit += (houseProfit);
        }
        else
        {
            Bet.Profit = Bet.BetSize.Negatify();
            User.SubtractFromPurchaseBalance(Bet.BetSize, "Dice bet lose", BalanceLogType.Other);

            query = SiteInvestmentManager.GetUpdateAmountQuery(formBetAmount);
            //AppSettings.DiceGame.HouseProfit += ((0.01m * formBetAmount));
        }
        Bet.Roll = diceRoll;
        Bet.Save();

        string clearTableQuery = " DELETE FROM SiteInvestments WHERE Amount = 0;";

        TableHelper.ExecuteRawCommandNonQuery(query + clearTableQuery);

        AppSettings.DiceGame.Save();
        User.SaveBalances();
    }