コード例 #1
0
		/// <summary>
		/// Gets the player matching the specified ID as an asynchronous operation.
		/// </summary>
		/// <param name="playerID"></param>
		/// <returns>A task with the return type of list of <see cref="PlayerInfo"/> objects.</returns>
		public Task<PlayerInfo> GetPlayerAsync(int playerID)
		{
			return Task.Run(() =>
			{
				using (QueryResult reader = db.QueryReader("SELECT * FROM UserSpecificFunctions WHERE UserID=@0;", playerID.ToString()))
				{
					if (reader.Read())
					{
						PlayerInfo playerInfo = new PlayerInfo();
						playerInfo.Load(reader);
						return playerInfo;
					}
				}

				return null;
			});
		}
コード例 #2
0
		/// <summary>
		/// Asynchronously inserts a player into the database.
		/// </summary>
		/// <param name="player"></param>
		/// <returns></returns>
		public Task<bool> AddPlayerAsync(PlayerInfo player)
		{
			return Task.Run(() => 
			{
				try
				{
					lock (PlayerData)
					{
						PlayerData.Add(player);
						string query = "INSERT INTO UserSpecificFunctions (UserID, Prefix, Suffix, Color, Permissions) VALUES (@0, @1, @2, @3, @4);";
						return db.Query(query, player.UserID, player.Prefix, player.Suffix, player.ChatColor, player.Permissions.Any() ? player.Permissions.Separate(",") : null) == 1;
					}
				}
				catch(Exception ex)
				{
					TShock.Log.Error(ex.ToString());
					return false;
				}
			});
		}