/// <summary> /// Generates the lottery dictionary values from database /// </summary> public static void Initialize() { BountyUsers.Clear(); using (var dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("SELECT * FROM `rp_bounties`"); DataTable Table = dbClient.getTable(); if (Table != null) { foreach (DataRow Row in Table.Rows) { int UserId = Convert.ToInt32(Row["user_id"]); int AddedBy = Convert.ToInt32(Row["added_by"]); int Reward = Convert.ToInt32(Row["reward"]); double TimeStamp = Convert.ToDouble(Row["timestamp"]); double ExpiryTimeStamp = Convert.ToDouble(Row["timestamp_expire"]); Bounty Bounty = new Bounty(UserId, AddedBy, Reward, TimeStamp, ExpiryTimeStamp); if (!BountyUsers.ContainsKey(UserId)) { BountyUsers.TryAdd(UserId, Bounty); } } } } log.Info("Carregado " + BountyUsers.Count + " usuários com recompensa."); }
/// <summary> /// Adds the chosen client to the bounty /// </summary> /// <param name="New"></param> public static void AddBounty(Bounty New) { if (BountyUsers.ContainsKey(New.UserId)) { return; } BountyUsers.TryAdd(New.UserId, New); using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("INSERT INTO `rp_bounties` (`user_id`, `added_by`, `reward`, `timestamp`, `timestamp_expire`) VALUES (@userid, @addedby, @reward, @timestamp, @expirytimestamp)"); dbClient.AddParameter("userid", New.UserId); dbClient.AddParameter("addedby", New.AddedBy); dbClient.AddParameter("reward", New.Reward); dbClient.AddParameter("timestamp", New.TimeStamp); dbClient.AddParameter("expirytimestamp", New.ExpiryTimeStamp); dbClient.RunQuery(); } }