Beispiel #1
0
        public async Task <ActionResult <TaskResult> > CancelOrder(string orderid, string accountid, string auth)
        {
            // Account logic first
            Entity account = await Entity.FindAsync(accountid);

            if (account == null)
            {
                return(new TaskResult(false, "Failed to find account " + accountid));
            }

            User authUser = await _context.Users.AsQueryable().FirstOrDefaultAsync(u => u.Api_Key == auth);

            if (authUser == null)
            {
                return(new TaskResult(false, "Failed to find auth account."));
            }

            StockOffer stockOffer = await _context.StockOffers.FindAsync(orderid);

            if (stockOffer == null)
            {
                return(new TaskResult(false, "Failed to find offer " + orderid));
            }

            // Authority check
            if (!await account.HasPermissionAsync(authUser, "eco"))
            {
                return(new TaskResult(false, "You do not have permission to trade for this entity!"));
            }

            if (stockOffer.Order_Type == "BUY")
            {
                _context.StockOffers.Remove(stockOffer);

                await _context.SaveChangesAsync();

                // Refund user and delete offer
                decimal refund = stockOffer.Amount * stockOffer.Target;

                TransactionRequest transaction = new TransactionRequest(EconomyManager.VooperiaID, account.Id, refund, $"Stock buy cancellation: {stockOffer.Amount} {stockOffer.Ticker}@{stockOffer.Target}", ApplicableTax.None, true);
                TaskResult         transResult = await transaction.Execute();

                if (!transResult.Succeeded)
                {
                    return(transResult);
                }
            }
            else if (stockOffer.Order_Type == "SELL")
            {
                _context.StockOffers.Remove(stockOffer);

                await _context.SaveChangesAsync();

                // Refund user stock and delete offer
                await ExchangeManager.AddStock(stockOffer.Ticker, stockOffer.Amount, accountid, _context);
            }

            string json = JsonConvert.SerializeObject(stockOffer);

            await ExchangeHub.Current.Clients.All.SendAsync("StockOfferCancel", json);

            return(new TaskResult(true, "Successfully removed order."));
        }
Beispiel #2
0
        public async void UpdateRanks()
        {
            Console.WriteLine("Doing rank job");

            using (VooperContext context = new VooperContext(DBOptions))
            {
                Group government = context.Groups.AsQueryable().FirstOrDefault(x => x.Name == "Vooperia");

                if (government == null)
                {
                    Console.WriteLine("Holy f**k something is wrong.");
                }

                leaderboard = context.Users.AsEnumerable().Where(u => u.Email != u.UserName).OrderByDescending(u => u.GetTotalXP()).ToList();

                List <SocketGuildUser> userList = new List <SocketGuildUser>();

                // Add connected users
                foreach (User userData in leaderboard)
                {
                    SocketGuildUser user = null;

                    if (userData.discord_id != null)
                    {
                        //user = server.Users.FirstOrDefault(x => x.Id == (ulong)userData.discord_id);
                        user = server.GetUser((ulong)userData.discord_id);
                    }

                    if (user != null)
                    {
                        // Clear roles if muted
                        if (userData.GetDiscordRoles().Any(r => r.Name == "Muted"))
                        {
                            if (user.Roles.Contains(spleenRole))
                            {
                                await user.RemoveRoleAsync(spleenRole);
                            }
                            if (user.Roles.Contains(crabRole))
                            {
                                await user.RemoveRoleAsync(crabRole);
                            }
                            if (user.Roles.Contains(gatyRole))
                            {
                                await user.RemoveRoleAsync(gatyRole);
                            }
                            if (user.Roles.Contains(corgiRole))
                            {
                                await user.RemoveRoleAsync(corgiRole);
                            }
                            if (user.Roles.Contains(oofRole))
                            {
                                await user.RemoveRoleAsync(oofRole);
                            }
                        }
                        else
                        {
                            userList.Add(user);
                        }
                    }
                }

                int counter = 0;

                int totalUsers = userList.Count;


                GovControls govControls = await GovControls.GetCurrentAsync(context);

                decimal UBITotal = govControls.UBIAccount;
                govControls.UBIAccount = 0;

                context.GovControls.Update(govControls);
                await context.SaveChangesAsync();


                int spleenUserCount = totalUsers / 100;
                int crabUserCount   = (totalUsers / 20) - spleenUserCount;
                int gatyUserCount   = (totalUsers / 10) - spleenUserCount - crabUserCount;
                int corgiUserCount  = (totalUsers / 4) - spleenUserCount - crabUserCount - gatyUserCount;
                int oofUserCount    = (totalUsers / 2) - spleenUserCount - crabUserCount - gatyUserCount - corgiUserCount;

                int unrankedCount = totalUsers - spleenUserCount - crabUserCount - gatyUserCount - corgiUserCount - oofUserCount;

                decimal spleenPay   = 0.0m;
                decimal crabPay     = 0.0m;
                decimal gatyPay     = 0.0m;
                decimal corgiPay    = 0.0m;
                decimal oofPay      = 0.0m;
                decimal unrankedPay = 0.0m;

                if (spleenUserCount > 0)
                {
                    spleenPay = (UBITotal * (govControls.SpleenPayPercent / 100.0m)) / spleenUserCount;
                }
                if (crabUserCount > 0)
                {
                    crabPay = (UBITotal * (govControls.CrabPayPercent / 100.0m)) / crabUserCount;
                }
                if (gatyUserCount > 0)
                {
                    gatyPay = (UBITotal * (govControls.GatyPayPercent / 100.0m)) / gatyUserCount;
                }
                if (corgiUserCount > 0)
                {
                    corgiPay = (UBITotal * (govControls.CorgiPayPercent / 100.0m)) / corgiUserCount;
                }
                if (oofUserCount > 0)
                {
                    oofPay = (UBITotal * (govControls.OofPayPercent / 100.0m)) / oofUserCount;
                }
                if (unrankedCount > 0)
                {
                    unrankedPay = (UBITotal * (govControls.UnrankedPayPercent / 100.0m)) / unrankedCount;
                }

                foreach (SocketGuildUser discordUser in userList)
                {
                    User webUser = context.Users.FirstOrDefault(u => u.discord_id == discordUser.Id);

                    // Update pfp in storage
                    webUser.Image_Url = webUser.GetPfpUrl();
                    context.Update(webUser);
                    await context.SaveChangesAsync();

                    bool hasSpleen = discordUser.Roles.Contains(spleenRole);
                    bool hasCrab   = discordUser.Roles.Contains(crabRole);
                    bool hasGaty   = discordUser.Roles.Contains(gatyRole);
                    bool hasCorgi  = discordUser.Roles.Contains(corgiRole);
                    bool hasOof    = discordUser.Roles.Contains(oofRole);

                    bool hasCitizen  = discordUser.Roles.Contains(patreonCitizen) || discordUser.Roles.Contains(youtubeCitizen);
                    bool hasSoldier  = discordUser.Roles.Contains(patreonSoldier);
                    bool hasLoyalist = discordUser.Roles.Contains(patreonLoyalist);
                    bool hasHero     = discordUser.Roles.Contains(patreonHero);
                    bool hasMadlad   = discordUser.Roles.Contains(patreonMadlad);

                    bool patron = hasCitizen || hasSoldier || hasLoyalist || hasHero || hasMadlad;

                    // Inactivity tax
                    if (Math.Abs(webUser.Discord_Last_Message_Time.Subtract(DateTime.UtcNow).TotalDays) > 14 && !patron)
                    {
                        decimal tax = webUser.Credits * (govControls.InactivityTaxRate / 100.0M);

                        TransactionRequest req = new TransactionRequest(webUser.Id, EconomyManager.VooperiaID, tax, "Inactivity Tax", ApplicableTax.None, true);

                        TaskResult result = await req.Execute();

                        if (result.Succeeded)
                        {
                            govControls.InactivityTaxRevenue += tax;

                            // Add to UBI
                            govControls.UBIAccount += tax * (govControls.UBIBudgetPercent / 100.0M);

                            context.GovControls.Update(govControls);

                            await context.SaveChangesAsync();
                        }

                        // Remove last role
                        if (hasSpleen)
                        {
                            await discordUser.RemoveRoleAsync(spleenRole);
                        }
                        if (hasCrab)
                        {
                            await discordUser.RemoveRoleAsync(crabRole);
                        }
                        if (hasGaty)
                        {
                            await discordUser.RemoveRoleAsync(gatyRole);
                        }
                        if (hasCorgi)
                        {
                            await discordUser.RemoveRoleAsync(corgiRole);
                        }
                        if (hasOof)
                        {
                            await discordUser.RemoveRoleAsync(oofRole);
                        }

                        continue;
                    }

                    // Set district
                    if (!String.IsNullOrWhiteSpace(webUser.district))
                    {
                        var oldDistrictRoles = discordUser.Roles.Where(x => x.Name.Contains("District") && !x.Name.Contains(webUser.district));

                        if (oldDistrictRoles.Count() > 0)
                        {
                            await discordUser.RemoveRolesAsync(oldDistrictRoles);
                        }

                        if (!discordUser.Roles.Any(x => x.Name == webUser.district + " District"))
                        {
                            await discordUser.AddRoleAsync(districtRoles[webUser.district + " District"]);
                        }
                    }

                    // Spleen rank
                    if (counter <= spleenUserCount)
                    {
                        // Add new role
                        if (!hasSpleen)
                        {
                            await discordUser.AddRoleAsync(spleenRole);
                        }

                        // Remove last role
                        if (hasCrab)
                        {
                            await discordUser.RemoveRoleAsync(crabRole);
                        }
                        if (hasGaty)
                        {
                            await discordUser.RemoveRoleAsync(gatyRole);
                        }
                        if (hasCorgi)
                        {
                            await discordUser.RemoveRoleAsync(corgiRole);
                        }
                        if (hasOof)
                        {
                            await discordUser.RemoveRoleAsync(oofRole);
                        }

                        if (webUser != null)
                        {
                            //TransactionRequest transaction = new TransactionRequest(webUser.economy_id, government.economy_id, 238827, "UBI Mistake Fix", ApplicableTax.None, true);
                            TransactionRequest transaction = new TransactionRequest(government.Id, webUser.Id, spleenPay, "UBI Payment", ApplicableTax.None, true);
                            EconomyManager.RequestTransaction(transaction);
                        }
                    }
                    // Crab rank
                    else if (counter <= spleenUserCount + crabUserCount)
                    {
                        // Add new role
                        if (!hasCrab)
                        {
                            await discordUser.AddRoleAsync(crabRole);
                        }

                        // Remove last role
                        if (hasSpleen)
                        {
                            await discordUser.RemoveRoleAsync(spleenRole);
                        }
                        if (hasGaty)
                        {
                            await discordUser.RemoveRoleAsync(gatyRole);
                        }
                        if (hasCorgi)
                        {
                            await discordUser.RemoveRoleAsync(corgiRole);
                        }
                        if (hasOof)
                        {
                            await discordUser.RemoveRoleAsync(oofRole);
                        }

                        if (webUser != null)
                        {
                            //TransactionRequest transaction = new TransactionRequest(webUser.economy_id, government.economy_id, 146267, "UBI Mistake Fix", ApplicableTax.None, true);
                            TransactionRequest transaction = new TransactionRequest(government.Id, webUser.Id, crabPay, "UBI Payment", ApplicableTax.None, true);
                            EconomyManager.RequestTransaction(transaction);
                        }
                    }
                    // Gaty rank
                    else if (counter <= spleenUserCount + crabUserCount + gatyUserCount)
                    {
                        // Add new role
                        if (!hasGaty)
                        {
                            await discordUser.AddRoleAsync(gatyRole);
                        }

                        // Remove last role
                        if (hasSpleen)
                        {
                            await discordUser.RemoveRoleAsync(spleenRole);
                        }
                        if (hasCrab)
                        {
                            await discordUser.RemoveRoleAsync(crabRole);
                        }
                        if (hasCorgi)
                        {
                            await discordUser.RemoveRoleAsync(corgiRole);
                        }
                        if (hasOof)
                        {
                            await discordUser.RemoveRoleAsync(oofRole);
                        }

                        if (webUser != null)
                        {
                            //TransactionRequest transaction = new TransactionRequest(webUser.economy_id, government.economy_id, 125698, "UBI Mistake Fix", ApplicableTax.None, true);
                            TransactionRequest transaction = new TransactionRequest(government.Id, webUser.Id, gatyPay, "UBI Payment", ApplicableTax.None, true);
                            EconomyManager.RequestTransaction(transaction);
                        }
                    }
                    // Corgi rank
                    else if (counter <= spleenUserCount + crabUserCount + gatyUserCount + corgiUserCount)
                    {
                        // Add new role
                        if (!hasCorgi)
                        {
                            await discordUser.AddRoleAsync(corgiRole);
                        }

                        // Remove last role
                        if (hasSpleen)
                        {
                            await discordUser.RemoveRoleAsync(spleenRole);
                        }
                        if (hasCrab)
                        {
                            await discordUser.RemoveRoleAsync(crabRole);
                        }
                        if (hasGaty)
                        {
                            await discordUser.RemoveRoleAsync(gatyRole);
                        }
                        if (hasOof)
                        {
                            await discordUser.RemoveRoleAsync(oofRole);
                        }

                        if (webUser != null)
                        {
                            //TransactionRequest transaction = new TransactionRequest(webUser.economy_id, government.economy_id, 110369, "UBI Mistake Fix", ApplicableTax.None, true);
                            TransactionRequest transaction = new TransactionRequest(government.Id, webUser.Id, corgiPay, "UBI Payment", ApplicableTax.None, true);
                            EconomyManager.RequestTransaction(transaction);
                        }
                    }
                    // Oof rank
                    else if (counter <= spleenUserCount + crabUserCount + gatyUserCount + corgiUserCount + oofUserCount)
                    {
                        // Add new role
                        if (!hasOof)
                        {
                            await discordUser.AddRoleAsync(oofRole);
                        }

                        // Remove last role
                        if (hasSpleen)
                        {
                            await discordUser.RemoveRoleAsync(spleenRole);
                        }
                        if (hasCrab)
                        {
                            await discordUser.RemoveRoleAsync(crabRole);
                        }
                        if (hasGaty)
                        {
                            await discordUser.RemoveRoleAsync(gatyRole);
                        }
                        if (hasCorgi)
                        {
                            await discordUser.RemoveRoleAsync(corgiRole);
                        }

                        if (webUser != null)
                        {
                            //TransactionRequest transaction = new TransactionRequest(webUser.economy_id, government.economy_id, 91085, "UBI Mistake Fix", ApplicableTax.None, true);
                            TransactionRequest transaction = new TransactionRequest(government.Id, webUser.Id, oofPay, "UBI Payment", ApplicableTax.None, true);
                            EconomyManager.RequestTransaction(transaction);
                        }
                    }
                    // Unranked
                    else
                    {
                        // Remove last role
                        if (hasSpleen)
                        {
                            await discordUser.RemoveRoleAsync(spleenRole);
                        }
                        if (hasCrab)
                        {
                            await discordUser.RemoveRoleAsync(crabRole);
                        }
                        if (hasGaty)
                        {
                            await discordUser.RemoveRoleAsync(gatyRole);
                        }
                        if (hasCorgi)
                        {
                            await discordUser.RemoveRoleAsync(corgiRole);
                        }
                        if (hasOof)
                        {
                            await discordUser.RemoveRoleAsync(oofRole);
                        }

                        if (webUser != null)
                        {
                            //TransactionRequest transaction = new TransactionRequest(webUser.economy_id, government.economy_id, 125698, "UBI Mistake Fix", ApplicableTax.None, true);
                            TransactionRequest transaction = new TransactionRequest(government.Id, webUser.Id, unrankedPay, "UBI Payment", ApplicableTax.None, true);
                            EconomyManager.RequestTransaction(transaction);
                        }
                    }

                    if (patron)
                    {
                        webUser = await context.Users.FindAsync(webUser.Id);

                        if (hasMadlad)
                        {
                            webUser.Credits += 500;
                        }
                        else if (hasHero)
                        {
                            webUser.Credits += 350;
                        }
                        else if (hasLoyalist)
                        {
                            webUser.Credits += 175;
                        }
                        else if (hasSoldier)
                        {
                            webUser.Credits += 60;
                        }
                        else if (hasCitizen)
                        {
                            webUser.Credits += 20;
                        }

                        context.Update(webUser);
                        await context.SaveChangesAsync();
                    }

                    counter++;
                }
            }


            Console.WriteLine("Finished rank system");
        }
Beispiel #3
0
        public async Task <ActionResult <TaskResult> > SubmitStockBuy(string ticker, int count, decimal price, string accountid, string auth)
        {
            // Account logic first
            Entity account = await Entity.FindAsync(accountid);

            if (account == null)
            {
                return(new TaskResult(false, "Failed to find account " + accountid));
            }

            User authUser = await _context.Users.AsQueryable().FirstOrDefaultAsync(u => u.Api_Key == auth);

            if (authUser == null)
            {
                return(new TaskResult(false, "Failed to find auth account."));
            }

            StockDefinition stockDef = await _context.StockDefinitions.FindAsync(ticker.ToUpper());

            if (stockDef == null)
            {
                return(new TaskResult(false, "Failed to find stock with ticker " + ticker));
            }

            // Authority check
            if (!await account.HasPermissionAsync(authUser, "eco"))
            {
                return(new TaskResult(false, "You do not have permission to trade for this entity!"));
            }

            // At this point the account is authorized //
            if (count < 1)
            {
                return(new TaskResult(false, "You must buy a positive number of stocks!"));
            }

            if (price == 0)
            {
                StockOffer lowOffer = await ExchangeManager.GetLowestSellOffer(ticker, _context);

                if (lowOffer != null)
                {
                    price = lowOffer.Target;
                }
                else
                {
                    return(new TaskResult(false, "There is no market rate!"));
                }
            }

            if (price < 0)
            {
                return(new TaskResult(false, "Negatives are not allowed!"));
            }

            decimal totalPrice = count * price;

            if (totalPrice > account.Credits)
            {
                return(new TaskResult(false, "You cannot afford this!"));
            }

            TransactionRequest transaction = new TransactionRequest(account.Id, EconomyManager.VooperiaID, totalPrice, $"Stock purchase: {count} {ticker}@{price}", ApplicableTax.None, false);
            TaskResult         transResult = await transaction.Execute();

            if (!transResult.Succeeded)
            {
                return(transResult);
            }

            // Create offer
            StockOffer buyOffer = new StockOffer()
            {
                Id         = Guid.NewGuid().ToString(),
                Amount     = count,
                Order_Type = "BUY",
                Owner_Name = account.Name,
                Owner_Id   = account.Id,
                Target     = price.Round(),
                Ticker     = ticker
            };

            _context.StockOffers.Add(buyOffer);
            await _context.SaveChangesAsync();

            string json = JsonConvert.SerializeObject(buyOffer);

            await ExchangeHub.Current.Clients.All.SendAsync("StockOffer", json);

            return(new TaskResult(true, $"Successfully posted BUY order {buyOffer.Id}"));
        }
Beispiel #4
0
        private static void Main()
        {
            var cust = new
                       {
                           Id = "3",
                           Name = "Test",
                           Email = "*****@*****.**",
                           Address1 = "123 Main St",
                           City = "Charlotte",
                           State = "NC",
                           Zip = "29028",
                       };

            var card = new
                       {
                           AccountType = AccountTypes.C,
                           NameOnCard = "Test",
                           AccountNumber = "4012000033330026",
                           RoutingNumber = "123456780",
                           ExpMonth = (string)null,
                           ExpYear = (string)null,
                       };

            var trnx = new
                       {
                           Amount = 1234.56m,
                       };

            var conn = new VancoConnection(ConfigurationManager.ConnectionStrings["Vanco"].ConnectionString);

            // Login
            var loginRequest = new LoginRequest();
            var loginResponse = loginRequest.Execute(conn);
            Console.WriteLine("SessionId: " + loginResponse.SessionId);

            // Add Payment method
            var eftRequest = new EftRequest
                             {
                                 CustomerId = cust.Id,
                                 AddNewCustomer = true,
                                 Name = cust.Name,
                                 Email = cust.Email,
                                 BillingAddr1 = cust.Address1,
                                 BillingCity = cust.City,
                                 BillingState = cust.State,
                                 BillingZip = cust.Zip,
                                 AccountType = card.AccountType,
                                 NameOnCard = card.NameOnCard,
                                 AccountNumber = card.AccountNumber,
                                 RoutingNumber = card.RoutingNumber,
                                 ExpMonth = card.ExpMonth,
                                 ExpYear = card.ExpYear,
                             };
            var eftResponse = eftRequest.Execute(conn);
            Console.WriteLine("PaymentMethodRef: " + eftResponse.PaymentMethodRef);

            // Get Payment Methods
            var methodsRequest = new PaymentMethodsRequest
                          {
                              CustomerId = cust.Id,
                          };
            var methodsResponse = methodsRequest.Execute(conn);
            Console.WriteLine("PaymentMethods: " + methodsResponse.PaymentMethodCount);

            // Transaction
            var trnxRequest = new TransactionRequest
                       {
                           CustomerId = cust.Id,
                           PaymentMethodRef = methodsResponse.PaymentMethods[methodsResponse.PaymentMethods.Count - 1].PaymentMethodRef,
                           Amount = trnx.Amount,
                           FrequencyCode = Frequencies.O,
                       };
            var trnxResponse = trnxRequest.Execute(conn);
            if (!string.IsNullOrWhiteSpace(trnxResponse.ErrorList))
            {
                Console.WriteLine("Error: " + VancoConnection.GetErrorMessages(trnxResponse.ErrorList));
            }
            Console.WriteLine("TrnxId: " + trnxResponse.TransactionRef);

            // Logout
            var logout = new LogoutRequest().Execute(conn);
            Console.WriteLine("Logout: " + logout);

            Console.ReadKey();
        }