Exemplo n.º 1
0
        private async void OnTransaction(object sender, TransactionEventArgs e)
        {
            if (e.ContributorId == Id)
            {
                LastAmount = e.Credits;
                if (e.Date.HasValue)
                {
                    LastDonation = e.Date.Value;
                }
                TotalCredits += e.Credits;

                // If the player is online, notify them about the transaction
                foreach (string s in Texts.SplitIntoLines(
                             _scope.Formatter.FormatNewDonation(_receiver, this, LastAmount)))
                {
                    _receiver.SendInfoMessage(s);
                }

                // Check for tier upgrades
                int oldTier = Tier;
                await _scope.Tiers.UpgradeTier(this, true);

                if (Tier != oldTier)
                {
                    // Delay the message according to the config
                    await Task.Delay(_scope.Config.NotificationCheckSeconds);

                    foreach (string s in Texts.SplitIntoLines(
                                 _scope.Formatter.FormatNewTier(_receiver, this, _scope.Tiers.Get(Tier))))
                    {
                        _receiver.SendInfoMessage(s);
                    }
                }

                // Suppress notifications from being set on the database
                e.SuppressNotifications = true;
            }
        }
Exemplo n.º 2
0
		private async void OnTransaction(object sender, TransactionEventArgs e)
		{
			if (e.ContributorId == Id)
			{
				LastAmount = e.Credits;
				if (e.Date.HasValue)
					LastDonation = e.Date.Value;
				TotalCredits += e.Credits;

				// If the player is online, notify them about the transaction
				foreach (string s in Texts.SplitIntoLines(
					_scope.Formatter.FormatNewDonation(_receiver, this, LastAmount)))
				{
					_receiver.SendInfoMessage(s);
				}

				// Check for tier upgrades
				int oldTier = Tier;
				await _scope.Tiers.UpgradeTier(this, true);
				if (Tier != oldTier)
				{
					// Delay the message according to the config
					await Task.Delay(_scope.Config.NotificationCheckSeconds);

					foreach (string s in Texts.SplitIntoLines(
						_scope.Formatter.FormatNewTier(_receiver, this, _scope.Tiers.Get(Tier))))
					{
						_receiver.SendInfoMessage(s);
					}
				}

				// Suppress notifications from being set on the database
				e.SuppressNotifications = true;
			}
		}
Exemplo n.º 3
0
		object restNewTransactionV2(RestRequestArgs args)
		{
			int userID;

			if (!Int32.TryParse(args.Verbs["user_id"], out userID))
				return RestInvalidParam("user_id");

			if (String.IsNullOrWhiteSpace(args.Parameters["credits"]))
				return RestMissingParam("credits");

			float credits;
			if (!Single.TryParse(args.Parameters["credits"], out credits))
				return RestInvalidParam("credits");

			long dateUnix = 0;
			if (!String.IsNullOrWhiteSpace(args.Parameters["date"]))
				Int64.TryParse(args.Parameters["date"], out dateUnix);

			Contributor con = _main.Contributors.GetByXenforoId(userID);
			bool success = false;

			if (con == null)
			{
				// Transactions must never be ignored. If the contributor doesn't exist, create it
				con = new Contributor(0);
				con.XenforoId = userID;
				con.LastAmount = credits;
				if (dateUnix > 0)
					con.LastDonation = dateUnix.FromUnixTime();
				con.Tier = 1;
				con.TotalCredits = credits;

				success = _main.Contributors.Add(con);
				if (!success)
				{
					TShock.Log.ConsoleInfo($"CTRS-WARNING: Failed to register contribution made by forum user ID [{userID}]!");
				}

				// Fire the Transaction event (must be done after Add to include the contributor Id)
				Transaction?.Invoke(_main.Contributors, new TransactionEventArgs(con.Id, credits, dateUnix.FromUnixTime()));
			}
			else
			{
				ContributorUpdates updates = 0;

				con.LastAmount = credits;
				updates |= ContributorUpdates.LastAmount;

				if (dateUnix > 0)
				{
					con.LastDonation = dateUnix.FromUnixTime();
					updates |= ContributorUpdates.LastDonation;
				}

				con.TotalCredits += credits;
				updates |= ContributorUpdates.TotalCredits;

				// Fire the Transaction event
				var transactionArgs = new TransactionEventArgs(con.Id, credits, dateUnix.FromUnixTime());
				Transaction?.Invoke(_main.Contributors, transactionArgs);

				// Suppress notifications if needed
				if (!transactionArgs.SuppressNotifications)
				{
					con.Notifications |= Notifications.NewDonation;
					con.Notifications |= Notifications.TierUpdate;
					updates |= ContributorUpdates.Notifications;
				}

				success = _main.Contributors.Update(con, updates);
			}
			if (!success)
				return RestError("Transaction was not registered properly.");
			else
				return RestResponse("Transaction successful.");
		}