Esempio 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";
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Gets Seeds and Hashes from the DB or creates new if not present
    /// </summary>
    /// <param name="user"></param>
    /// <returns></returns>
    public static DiceGameHash Get(Member user)
    {
        var diceGameHashes = TableHelper.SelectRows <DiceGameHash>(TableHelper.MakeDictionary("UserId", user.Id));

        if (diceGameHashes.Count == 0)
        {
            DiceGameHash hash = new DiceGameHash();
            hash.UserId = user.Id;
            hash.GenerateFirstHashes();
            hash.Save();
            return(hash);
        }
        return(diceGameHashes[0]);
    }
Esempio n. 3
0
    public void btnRandomize_Click(object sender, EventArgs e)
    {
        try
        {
            string digitsOnly = NewClientSeedTextBox.Text;

            if (digitsOnly.Length != 24)
            {
                throw new MsgException(U4200.CLIENTSEEDNOTVALID1);
            }

            foreach (char c in digitsOnly)
            {
                if (!char.IsDigit(c))
                {
                    throw new MsgException(U4200.CLIENTSEEDNOTVALID2);
                }
            }

            DiceGameHash CurrentDiceGameHash = DiceGameHash.Get(user);
            CurrentDiceGameHash.UpdateClientSeed(NewClientSeedTextBox.Text);
            CurrentDiceGameHash.Save();

            Response.Redirect("dicegame.aspx");
        }
        catch (MsgException ex)
        {
            ErrorMessagePanel.Visible = true;
            ErrorMessage.Text         = ex.Message;
        }
        catch (Exception ex)
        {
            ErrorLogger.Log(ex);
            throw ex;
        }
    }
Esempio 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();
    }