public static void UpdateMainPageLotteries(XLottery lottery) { int LotteryLeftTime = (lottery.EndTime > 0) ? Helper.LotteryHelper.CalcLeftTime(lottery.ID) : -1; int ItemsNumRecord; double Today_JackpotPriceRecord; int TodayGamesNum = Helper.LotteryHelper.TodaysGames(lottery.SteamGameID, out Today_JackpotPriceRecord, out ItemsNumRecord, 0).Length; double MaxJackpot_Rub = LotteryHelper.RUB_MaxJackpotPrice[lottery.SteamGameID]; double MaxJackpot = LotteryHelper.MaxJackpotPrice[lottery.SteamGameID]; if(lottery.JackpotPrice > MaxJackpot) { MaxJackpot = lottery.JackpotPrice; } if((lottery.JackpotPrice * lottery.RubCurrency) > MaxJackpot_Rub) { MaxJackpot_Rub = (lottery.JackpotPrice * lottery.RubCurrency); } string MaxJackpot_Rub_Str = MaxJackpot_Rub.ToString("###,###,##0"); string MaxJackpot_Str = MaxJackpot.ToString("###,##0.00"); Client[] wclients = BaseFuncs.GetWebsocketClients<SiteGameSlot>().ToArray(); for (int i = 0; i < wclients.Length; i++) { string max_jackpot = ""; Client client = wclients[i]; if (client != null) { ushort currency = Helper.UserHelper.GetCurrency(client); string jackpot = ""; if (currency == 1) { jackpot = (lottery.JackpotPrice * lottery.RubCurrency).ToString("###,###,##0"); max_jackpot = MaxJackpot_Rub_Str; } else if (currency == 0) { jackpot = lottery.JackpotPrice.ToString("###,##0.00"); max_jackpot = MaxJackpot_Str; } client.SendWebsocket("MainPageLotteries" + BaseFuncs.WSplit + lottery.SteamGameID + BaseFuncs.WSplit + lottery.GamersCount + BaseFuncs.WSplit + jackpot + BaseFuncs.WSplit + LotteryLeftTime + BaseFuncs.WSplit + lottery.JackpotItemsNum + BaseFuncs.WSplit + TodayGamesNum + BaseFuncs.WSplit + max_jackpot); } } }
public override bool Init(Client client) { if (client.ConnType == ConnectionType.WebSocket && client.WSData != null) { //Logger.ConsoleLog(client.WSData, ConsoleColor.Yellow); string[] wsdata = Regex.Split(client.WSData, BaseFuncs.WSplit); if (wsdata[0].Equals("GetProfile")) { XUser user; uint userID; if (uint.TryParse(wsdata[1], out userID) && Helper.UserHelper.Table.SelectByID(userID, out user)) { int Winrate; int GamesCount = user.CSGO_GamesCount + user.DOTA_GamesCount; int WonCount = user.DOTA_WonCount + user.CSGO_WonCount; if (WonCount > 0) { Winrate = (int)(WonCount / ((double)GamesCount / 100d)); } else { Winrate = 0; } string BetPrice = ""; string WonPrice = ""; ushort currency = Helper.UserHelper.GetCurrency(client); if(currency == 1) { BetPrice = (user.CSGO_RUB_TotalBetPrice + user.DOTA_RUB_TotalBetPrice).ToString("###,###,##0"); WonPrice = (user.CSGO_RUB_WonTotalPrice + user.DOTA_RUB_WonTotalPrice).ToString("###,###,##0"); } else if(currency == 0) { BetPrice = (user.CSGO_TotalBetPrice + user.DOTA_TotalBetPrice).ToString("###,##0.00"); WonPrice = (user.CSGO_WonTotalPrice + user.DOTA_WonTotalPrice).ToString("###,##0.00"); } string GroupName = ""; XUser owner; if(user.GroupOwnerID >= 0 && Helper.UserHelper.Table.SelectByID((uint)user.GroupOwnerID, out owner)) { GroupName = (owner.GroupName.Length > 0) ? owner.GroupName : owner.Name; } string Games = ""; int CurrentTime = Helper.GetCurrentTime(); XLottery[] Lots = new XLottery[0]; Helper.LotteryHelper.Table.SelectArrFromEnd(data => { if (data.WinnersToken > 0) { XLotteryBet b; if (Helper.LotteryHelper.TableBet.SelectOne(bt => bt.LotteryID == data.ID && bt.UserID == user.ID && (data.EndTime + 30) <= CurrentTime, out b)) { int wr = Convert.ToInt32(Math.Round((100 * data.WinnersBetPrice) / data.JackpotPrice)); string jc = ""; if (currency == 1) { jc = (data.JackpotPrice * data.RubCurrency).ToString("###,###,##0"); } else if (currency == 0) { jc = data.JackpotPrice.ToString("###,##0.00"); } ushort wnr = 0; if (data.Winner == user.ID) { wnr = 1; } Games += data.ID + ";" + data.ID.ToString("000-000-000") + ";" + wr + ";" + data.JackpotItemsNum + ";" + jc + ";" + wnr + "↑"; return true; } } return false; }, out Lots, 0, 15); client.SendWebsocket("GetProfile" + BaseFuncs.WSplit + user.Name + BaseFuncs.WSplit + user.Avatar + BaseFuncs.WSplit + GamesCount + BaseFuncs.WSplit + WonCount + BaseFuncs.WSplit + Winrate + BaseFuncs.WSplit + (user.CSGO_TotalBetItemsCount + user.DOTA_TotalBetItemsCount) + BaseFuncs.WSplit + (user.CSGO_WonItemsCount + user.DOTA_WonItemsCount) + BaseFuncs.WSplit + BetPrice + BaseFuncs.WSplit + WonPrice + BaseFuncs.WSplit + user.ProfileURL + BaseFuncs.WSplit + user.GroupOwnerID + BaseFuncs.WSplit + GroupName + BaseFuncs.WSplit + Games + BaseFuncs.WSplit + ((Lots.Length < 15) ? 0 : 1)); } } else if (wsdata[0].Equals("GroupPage")) { //ws.send("GroupPage{{=BaseFuncs.WSplit}}EntryToGroup{{=BaseFuncs.WSplit}}{{=Group.ID}}"); uint GroupID; XUser User; if (uint.TryParse(wsdata[2], out GroupID)) { if (wsdata[1].Equals("Connect")) { if (WebSocketPage.ClientsGroupPage.ContainsKey(GroupID)) { WebSocketPage.ClientsGroupPage[GroupID].Add(client); } else { List<Client> cls = new List<Client>(); cls.Add(client); WebSocketPage.ClientsGroupPage.Add(GroupID, cls); } } else if (wsdata[1].Equals("EntryToGroup") && Helper.UserHelper.GetCurrentUser(client, out User)) { int OldGroup = User.GroupOwnerID; if (Helper.GroupHelper.EnterToGroup(GroupID, client)) { WebSocketPage.UpdateGroupData(GroupID); if (OldGroup > -1) { WebSocketPage.UpdateGroupData(Convert.ToUInt32(OldGroup)); } } } else if (wsdata[1].Equals("ExitFromGroup") && Helper.UserHelper.GetCurrentUser(client, out User)) { if (Helper.GroupHelper.ExitFromGroup(GroupID, client)) { WebSocketPage.UpdateGroupData(GroupID); } } } } else if(wsdata[0].Equals("MyGroupPage")) { XUser User; if (Helper.UserHelper.GetCurrentUser(client, out User)) { if (wsdata[1].Equals("ChangeName")) { if (Helper.GroupHelper.UpdateNameByID(User.ID, wsdata[2])) { WebSocketPage.UpdateGroupData(User.ID); } } } } else if (wsdata[0].Equals("GetInventory")) { XUser User; uint SteamGameID; int ItemsNum; int FromNum; ushort SortByLowPrice; if (Helper.UserHelper.GetCurrentUser(client, out User) && uint.TryParse(wsdata[1], out SteamGameID) && int.TryParse(wsdata[2], out FromNum) && int.TryParse(wsdata[3], out ItemsNum) && ushort.TryParse(wsdata[4], out SortByLowPrice)) { UsersInventory Inventory = null; bool InList = Helper.UserHelper.GetSteamInventory(User.ID, SteamGameID, out Inventory); if (InList) { WebSocketPage.GetWebsocket_SteamInventory(Inventory, client, SortByLowPrice, FromNum, ItemsNum, SteamGameID, wsdata[5]); } else { Helper.UserHelper.WaitingList_InventoryClient(User.ID, client, SteamGameID, ItemsNum); } } } else if (wsdata[0].Equals("GetLocalInventory")) { XUser User; uint SteamGameID; int ItemsNum; int FromNum; ushort SortByLowPrice; if (Helper.UserHelper.GetCurrentUser(client, out User) && uint.TryParse(wsdata[1], out SteamGameID) && int.TryParse(wsdata[2], out FromNum) && int.TryParse(wsdata[3], out ItemsNum) && ushort.TryParse(wsdata[4], out SortByLowPrice)) { Logger.ConsoleLog("Local:" + ItemsNum); string StrItems = ""; List<USteamItem> SteamItems = Helper.SteamItemsHelper.SearchByString(Helper.UserHelper.GetSteamLocalInventory(User.ID, SteamGameID), wsdata[5]); if (SortByLowPrice == 1) { SteamItems = (from it in SteamItems orderby it.Price ascending select it).ToList(); } if (FromNum < 0) { FromNum = 0; } else if (FromNum > ItemsNum && FromNum == SteamItems.Count) { FromNum -= ItemsNum; } for (int i = FromNum; i < Math.Min(FromNum + ItemsNum, SteamItems.Count); i++) { StrItems += WebSocketPage.InventoryItemToString(SteamItems[i]); } string total_price_str; Helper.UserHelper.GetLocalSteamInventoryTotalPrice(User.ID, SteamGameID, out total_price_str); WebSocketPage.UpdateLocalInventory(StrItems, total_price_str, SteamItems.Count, client); } } else if (wsdata[0].Equals("LotteryPage")) { XLottery x_lot; uint LotteryID; if (wsdata[1].Equals("Connect") && uint.TryParse(wsdata[2], out LotteryID) && Helper.LotteryHelper.Table.SelectByID(LotteryID, out x_lot)) { if (WebSocketPage.ClientsLotteryPage.ContainsKey(x_lot.ID)) { WebSocketPage.ClientsLotteryPage[x_lot.ID].Add(client); } else { List<Client> cls = new List<Client>(); cls.Add(client); WebSocketPage.ClientsLotteryPage.Add(x_lot.ID, cls); } } else if (wsdata[1].Equals("SetBet")) { /*assert_id : item_type (0: chip, 1: steam: 2: local) ; */ XUser user; if (Helper.UserHelper.GetCurrentUser(client, out user)) { if (uint.TryParse(wsdata[2], out LotteryID) && Helper.LotteryHelper.Table.SelectByID(LotteryID, out x_lot)) { string[] bet = wsdata[3].Split(';'); if (bet.Length > 1) { List<USteamItem> SteamItems = new List<USteamItem>(); List<Chip> Chips = new List<Chip>(); for (int i = 0; i < Math.Min(25, bet.Length); i++) { string[] item = bet[i].Split(':'); int item_type; ulong assert_id; uint item_id; if (item.Length >= 2 && ulong.TryParse(item[0], out assert_id) && int.TryParse(item[1], out item_type) && uint.TryParse(item[2], out item_id)) { if (item_type == 1 || item_type == 2) { USteamItem SteamItem = new USteamItem(); SteamItem.ID = item_id; SteamItem.AssertID = assert_id; SteamItems.Add(SteamItem); } else if (item_type == 3) { Chip chip = new Chip(); chip.ID = item_id; chip.AssertID = assert_id; Chips.Add(chip); } } } ushort result = Helper.LotteryHelper.SetBet(x_lot.ID, user.ID, SteamItems, Chips, client); Logger.ConsoleLog(result + "::test from: " + SteamItems.Count + "::" + Chips.Count); if (result != 2) { client.SendWebsocket("BetDone" + BaseFuncs.WSplit + result); } } } } } } else if (wsdata[0].Equals("UpdateTradeURL")) { XUser user; if (Helper.UserHelper.GetCurrentUser(client, out user)) { string token; ulong partner; if (wsdata[1].Contains("partner=") && wsdata[1].Contains("token=") && ulong.TryParse(Regex.Split(wsdata[1], "partner=")[1].Split('&')[0], out partner)) { token = Regex.Split(wsdata[1], "token=")[1]; if (token.Length > 0 && partner > 0) { if (token != user.TradeToken || partner != user.TradePartner) { user.TradeToken = token; user.TradePartner = partner; Helper.UserHelper.Table.UpdateByID(user, user.ID); Logger.ConsoleLog("Updated trade url (" + user.ID + "):" + user.TradeToken); } client.SendWebsocket("UpdateTradeURL" + BaseFuncs.WSplit + "1" + BaseFuncs.WSplit + partner + BaseFuncs.WSplit + token); } } else { client.SendWebsocket("UpdateTradeURL" + BaseFuncs.WSplit + "0"); } } } else if(wsdata[0].Equals("SendLocalItemsToSteam")) { XUser user; uint SteamGameID; if (Helper.UserHelper.GetCurrentUser(client, out user) && uint.TryParse(wsdata[1], out SteamGameID)) { Helper.SteamBotHelper.SendLocalItemsToSteam(user, SteamGameID, client); } } else if (wsdata[0].Equals("BuyChip")) { XUser user; uint chipID; if (Helper.UserHelper.GetCurrentUser(client, out user) && uint.TryParse(wsdata[1], out chipID)) { Chip chip; if(Helper.ChipHelper.SelectByID(chipID, out chip)) { double ChipPrice = chip.Cost; if(user.Currency == 1) { ChipPrice *= Helper.Rub_ExchangeRate; if(user.Wallet >= ChipPrice) { user.Wallet -= ChipPrice; Helper.UserHelper.Table.UpdateByID(user, user.ID); Helper.ChipHelper.AddChipToUser(chip.ID, user.ID); client.SendWebsocket("BuyChip" + BaseFuncs.WSplit + "1" + BaseFuncs.WSplit + chip.ID + BaseFuncs.WSplit + user.Wallet); } else { client.SendWebsocket("BuyChip" + BaseFuncs.WSplit + "0"); } } } } } else if(wsdata[0].Equals("GroupChat")) { uint GroupID; if (wsdata[1].Equals("Connect") && uint.TryParse(wsdata[2], out GroupID) && Helper.UserHelper.UserExist(GroupID)) { if(WebSocketPage.GroupClients.ContainsKey(GroupID)) { WebSocketPage.GroupClients[GroupID].Add(client); } else { List<Client> Clients = new List<Client>(); Clients.Add(client); WebSocketPage.GroupClients.Add(GroupID, Clients); } } } } return false; }
public static void SendLotteryRoulette(XLottery XLottery, List<LotteryRouletteData> RouletteData, XUser Winner) { if (ClientsLotteryPage.ContainsKey(XLottery.ID)) { // from 1: JackpotItems 2: JackpotPrice 3:Winner.ID 4: Winner.Name 5:RaundNumber 6: WinnerToken 7:(JackpotPrice * 100) 8: Winner.Avatar string ws = ""; // 12: data foreach (LotteryRouletteData data in RouletteData) { ws += data.UsersAvatar + "↑" + data.Token.ToString("D8") + "↑" + data.Winner + "↓"; } for (int i = 0; i < WebSocketPage.ClientsLotteryPage[XLottery.ID].Count; i++) { if (WebSocketPage.ClientsLotteryPage[XLottery.ID][i] == null || WebSocketPage.ClientsLotteryPage[XLottery.ID][i].Closed) { WebSocketPage.ClientsLotteryPage[XLottery.ID].RemoveAt(i--); continue; } string extra = XLottery.JackpotItemsNum + BaseFuncs.WSplit; string WinnersBetPrice; if (Helper.UserHelper.GetCurrency(WebSocketPage.ClientsLotteryPage[XLottery.ID][i]) == 1) { extra += (XLottery.JackpotPrice * XLottery.RubCurrency).ToString("###,###,##0"); WinnersBetPrice = (XLottery.WinnersBetPrice * XLottery.RubCurrency).ToString("###,###,##0"); } else { extra += XLottery.JackpotPrice.ToString("###,##0.00"); WinnersBetPrice = XLottery.WinnersBetPrice.ToString("###.##0.00"); } extra += BaseFuncs.WSplit + Winner.ID + BaseFuncs.WSplit + Winner.Name + BaseFuncs.WSplit; extra += XLottery.RaundNumber + BaseFuncs.WSplit + XLottery.WinnersToken + BaseFuncs.WSplit + (XLottery.JackpotPrice * 100) + BaseFuncs.WSplit + Winner.Avatar + BaseFuncs.WSplit; // 9: wonrate; 10: winners_items_num; 11: winners_price extra += XLottery.Wonrate + BaseFuncs.WSplit + XLottery.WinnersBetItemsNum + BaseFuncs.WSplit + WinnersBetPrice + BaseFuncs.WSplit; extra += ws + BaseFuncs.WSplit; XUser CurrentUser; if (Helper.UserHelper.GetCurrentUser(WebSocketPage.ClientsLotteryPage[XLottery.ID][i], out CurrentUser) && CurrentUser.ID == Winner.ID) { extra += 1.ToString(); Logger.ConsoleLog("Winner detected!", ConsoleColor.Yellow); } else { extra += 0.ToString(); } //14 extra += BaseFuncs.WSplit + BaseFuncs.MD5(XLottery.RaundNumber.ToString()); Logger.ConsoleLog("User:"******"LotteryRouletteStarted" + BaseFuncs.WSplit + extra); } WebSocketPage.ClientsLotteryPage.Remove(XLottery.ID); } WebSocketPage.UpdateMainPageLotteries(XLottery); }