public static void Clear() { lock (Options) Options.Clear(); lock (bets) bets.Clear(); lock (FalseEntries) FalseEntries.Clear(); lock (Winners) Winners.Clear(); }
private static void BetQueueHandler(object state) { if (Running) { lock (bets) { if (bets.Count > 0) { Chat.SendMessage("A total of " + bets.Count + " bets have been placed!"); string finalmessage = ""; lock (FalseEntries) { foreach (string user in FalseEntries.Keys) { string msg = "the option number does not exist"; if (FalseEntries[user] == 1) { msg = "the option does not exist"; } else if (FalseEntries[user] == 2) { msg = "the amount you put is invalid"; } else if (FalseEntries[user] == 3) { msg = "you have insufficient " + Currency.Name; } if (finalmessage.Length + msg.Length > 996) { Chat.SendMessage(finalmessage); finalmessage = ""; } finalmessage += user + ", " + msg + ". "; } FalseEntries.Clear(); if (finalmessage != "") { Chat.SendMessage(finalmessage); } } } } if (Api.GetUnixTimeNow() - LastAnnouncedCost > 60) { LastAnnouncedCost = Api.GetUnixTimeNow(); string temp = "Betting open for: "; lock (Options) for (int i = 0; i < Options.Count; i++) { temp += "(" + (i + 1).ToString() + ") " + Options[i] + (i + 1 < Options.Count ? ", " : ""); } Chat.SendMessage(temp + "."); Chat.SendMessage("Min bet: " + MinBet + " " + Currency.Name + ", Max bet: " + MaxBet + " " + Currency.Name + "."); } } }
public static void CreatePool(int min, int max, int reward, List <string> lOptions) { MinBet = min; MaxBet = max; WinReward = reward; lock (Options) Options = lOptions; TotalBets = 0; lock (bets) bets.Clear(); lock (FalseEntries) FalseEntries.Clear(); lock (Winners) Winners.Clear(); Locked = false; Running = true; }
private static void Command_Bet(string user, Command cmd, string[] args, string origin) { if (Running) { if (args.Length > 0) { int Value; if (args[0] == "help") { if (Api.GetUnixTimeNow() - LastUsedHelp < 60 && Users.GetLevel(user) < 1) { return; } LastUsedHelp = Api.GetUnixTimeNow(); if (!Locked) { string temp = "Betting open for: "; lock (Options) for (int i = 0; i < Options.Count; i++) { temp += "(" + (i + 1).ToString() + ") " + Options[i] + " - " + getNumberOfBets(Options[i]) + " bets (" + getTotalBetsOn(Options[i]) + " " + Currency.Name + ")" + (i + 1 < Options.Count ? ", " : ""); } Chat.SendMessage(temp + "."); Chat.SendMessage("Bet by typing \"!bet 50 #1\" to bet 50 " + Currency.Name + " on option 1, \"bet 25 #2\" to bet 25 " + Currency.Name + " on option 2, etc."); } else { string temp = "The pool is now closed, the following options were open for betting: "; lock (Options) for (int i = 0; i < Options.Count; i++) { temp += "(" + (i + 1).ToString() + ") " + Options[i] + " - " + getNumberOfBets(Options[i]) + " bets (" + getTotalBetsOn(Options[i]) + " " + Currency.Name + ")" + (i + 1 < Options.Count ? ", " : ""); } Chat.SendMessage(temp + "."); } } else if (!Locked && int.TryParse(args[0], out Value) && args.Length > 1) { string option = ""; List <string> compiledargs = Commands.GetArgs(args, 1).ToList(); if (compiledargs.Count > 0) { option = compiledargs[0]; } if (option.ToLower() == args[1].ToLower()) { if (option.StartsWith("#")) { int optionnumber = 0; if (int.TryParse(option.Substring(1), out optionnumber)) { option = GetOptionFromNumber(optionnumber); if (option == "") { //Chat.SendMessage(user + " the option number does not exist"); lock (FalseEntries) { if (!FalseEntries.ContainsKey(user)) { FalseEntries.Add(user, 0); BetQueue.Change(10000, Timeout.Infinite); } } return; } } } } placeBet(user, option, Value); } } else { //if (isInPool(user)) Chat.SendMessage(user + ": " + bets[user].Key + " (" + bets[user].Value + ")"); } } }
public static bool placeBet(string user, string option, int amount) { if (Running && !Locked) { lock (bets) { lock (FalseEntries) { lock (Options) { if (!FalseEntries.ContainsKey(user) && !bets.ContainsKey(user)) { BetQueue.Change(10000, Timeout.Infinite); } if (Options.Contains(option)) { if (amount >= MinBet && amount <= MaxBet) { int paid = 0; if (bets.ContainsKey(user)) { paid = bets[user].Value; } if (Currency.Check(user) + paid >= amount) { if (bets.ContainsKey(user)) { bets.Remove(user); } Currency.Add(user, paid); Currency.Remove(user, amount); bets.Add(user, new KeyValuePair <string, int>(option, amount)); if (FalseEntries.ContainsKey(user)) { FalseEntries.Remove(user); } return(true); } else { if (!FalseEntries.ContainsKey(user)) { FalseEntries.Add(user, 3); } } } else { if (!FalseEntries.ContainsKey(user)) { FalseEntries.Add(user, 2); } } } else { if (!FalseEntries.ContainsKey(user)) { FalseEntries.Add(user, 1); } } } } } } return(false); }