public bool SelectByID(uint ID, out Chip chip) { for (int i = 0; i < ChipHelper.Chips.Count; i++) { if (ChipHelper.Chips[i].ID == ID) { chip = ChipHelper.Chips[i]; return true; } } chip = new Chip(); return false; }
private void CreateChip(double cost) { Chip chip = new Chip(); chip.ID = (Chips.Count > 0) ? ChipHelper.Chips.Last().ID + 1 : 0; chip.Cost = cost; chip.Cost_Str = cost.ToString("###,##0.00"); string path = "FileStorage\\Upload\\Chips\\" + chip.ID + ".jpg"; if (File.Exists(path)) { chip.Image = FilesProcessor.CacheFile(File.ReadAllBytes(path), ".jpg"); } ChipHelper.Chips.Add(chip); }
public bool SelectChipByAssertID(ulong AssertID, uint UserID, out Chip Chip) { if(this.UserExist(UserID)) { XChipUsersInventory XChipInventory; if (this.Table_ChipUsersInventory.SelectOne(data => data.AssertID == AssertID && data.UserID == UserID && !data.Deleted, out XChipInventory) && Helper.ChipHelper.SelectByID(XChipInventory.ChipID, out Chip)) { Chip.AssertID = XChipInventory.AssertID; //Logger.ConsoleLog(XChipInventory.AssertID + "::" + Chip.AssertID); return true; } } Chip = new Chip(); return false; }
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; }