• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# DB.User类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中TShockAPI.DB.User的典型用法代码示例。如果您正苦于以下问题:C# User类的具体用法?C# User怎么用?C# User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



User类属于TShockAPI.DB命名空间,在下文中一共展示了User类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SendEmail

        public static void SendEmail(TSPlayer player, string email, User user)
        {
            MailMessage mail = new MailMessage(AccountRecovery.Config.EmailFrom, email);
            SmtpClient client = new SmtpClient();
            client.Timeout = 15000;
            client.Host = AccountRecovery.Config.HostSMTPServer;
            client.Port = AccountRecovery.Config.HostPort;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential(AccountRecovery.Config.ServerEmailAddress, AccountRecovery.Config.ServerEmailPassword);
            client.EnableSsl = true;
            //client.ServicePoint.MaxIdleTime = 1;
            mail.Subject = AccountRecovery.Config.EmailSubjectLine;
            mail.Body = AccountRecovery.Config.EmailBodyLine;
            mail.IsBodyHtml = AccountRecovery.Config.UseHTML;

            string passwordGenerated = GeneratePassword(AccountRecovery.Config.GeneratedPasswordLength);
            TShock.Users.SetUserPassword(user, passwordGenerated);
            TShock.Log.ConsoleInfo("{0} has requested a new password succesfully.", user.Name);

            mail.Body = string.Format(mail.Body.Replace("$NEW_PASSWORD", passwordGenerated));
            mail.Body = string.Format(mail.Body.Replace("$USERNAME", user.Name));

            client.Send(mail);
            client.Dispose();
            player.SendSuccessMessage("A new password has been generated and sent to {0} for {1}.", email, user.Name);
            TShock.Log.ConsoleInfo("A new password has been generated and sent to {0} for {1}.", email, user.Name);
        }
开发者ID:Marcus101RR,项目名称:AccountRecovery,代码行数:28,代码来源:Utilities.cs


示例2: AddAsync

		public async Task<bool> AddAsync(User user, DateTime expiration)
		{
			return await Task.Run(() =>
			{
				syncLock.EnterWriteLock();

				try
				{
					return db.Query("INSERT INTO Mutes VALUES (@0, @1, @2, @3, @4, @5)",
						null,
						user.Name,
						user.UUID,
						JsonConvert.DeserializeObject<List<string>>(user.KnownIps)[0],
						DateTime.UtcNow.ToString("s"),
						expiration.ToString("s")) > 0;
				}
				catch (Exception ex)
				{
					TShock.Log.Error(ex.ToString());
					return false;
				}
				finally
				{
					syncLock.ExitWriteLock();
				}
			});
		}
开发者ID:CrazyLegsSteph,项目名称:EssentialsPlus,代码行数:27,代码来源:MuteManager.cs


示例3: OnAccountDelete

		public static void OnAccountDelete(User u)
		{
			if (AccountDelete == null)
				return;

			AccountDelete(new AccountDeleteEventArgs(u));
		}
开发者ID:sliekasirdis79,项目名称:TShock,代码行数:7,代码来源:AccountHooks.cs


示例4: ChangeGroup

        public bool ChangeGroup(object Player, object Group)
        {
            TShockAPI.TSPlayer p = null;
            TShockAPI.DB.User u = new TShockAPI.DB.User();
            string g = "";

            if ((p = GetPlayer(Player)) == null) {
                return false;
            }

            if (Group is string) {
                g = Group as string;
            } else if (Group is TShockAPI.Group) {
                g = (Group as TShockAPI.Group).Name;
            }

            if (string.IsNullOrEmpty(g) == true) {
                return false;
            }

            try {
                u.Name = p.User.Name;
                TShockAPI.TShock.Users.SetUserGroup(u, g);
            } catch (Exception ex) {
                ScriptLog.ErrorFormat("tshock_change_group", "Group change failed: {0}", ex.Message);
                return false;
            }

            return true;
        }
开发者ID:Enerdy,项目名称:Jist,代码行数:30,代码来源:tshock.cs


示例5: RemoteClient_PacketReceived

        private void RemoteClient_PacketReceived(Client sender, Client.PacketReceivedEventArgs e)
        {
            PacketType packetType = (PacketType)e.Reader.ReadInt16();

            //Disconnect the user if he attempts to do anything else before authenticating.
            if (packetType != PacketType.Authenticate && !Authenticated)
            {
                Disconnect("Your attempt at sending packets before authenticating has been ignored!");
                return;
            }
            switch (packetType)
            {
                case PacketType.Authenticate:
                    InterfaceType = (InterfaceType)e.Reader.ReadByte();
                    int major = e.Reader.ReadInt32();
                    int minor = e.Reader.ReadInt32();
                    if (Rtc.buildVersion.Major != major || Rtc.buildVersion.Minor != minor)
                    {
                        Disconnect($"Your version ({major}.{minor}) is incompatible with the server's version ({Rtc.buildVersion.Major}.{Rtc.buildVersion.Minor}).");
                        return;
                    }
                    string Username = e.Reader.ReadString();
                    string Password = e.Reader.ReadString();
                    TSUser = TShock.Users.GetUserByName(Username);

                    if (TSUser == null || !TSUser.VerifyPassword(Password))
                    {
                        Disconnect("Invalid username/password or insufficient privileges.");
                        return;
                    }
                    Group g = TShock.Groups.GetGroupByName(TSUser.Group);

                    if (!g.HasPermission("*"))
                    {
                        Disconnect("Invalid username/password or insufficient privileges.");
                        return;
                    }
                    Authenticated = true;
                    Packet pck = new Packet((short)PacketType.MessageBuffer, (short)Rtc.MessagesBuffer.Length);
                    for (int i = 0; i < Rtc.MessagesBuffer.Length; i++)
                    {
                        if (!string.IsNullOrEmpty(Rtc.MessagesBuffer[i]))
                           pck.Write(Rtc.ColorBuffer[i], Rtc.MessagesBuffer[i]);

                    }
                    sender.Send(pck);
                    break;
                case PacketType.Input:
                    string text = e.Reader.ReadString();
                    Rtc.ConsoleInput.SendText(text);
                    break;
            }
        }
开发者ID:LaurensDeV,项目名称:Remote-TShock-Console,代码行数:53,代码来源:ConsoleClient.cs


示例6: InsertTradeLog

 public static bool InsertTradeLog(User trader, User tradee, string traderItems, string tradeeItems, DateTime tradeDate)
 {
     try
     {
         return TShock.CharacterDB.database.Query("INSERT INTO TradeRequestLogs (Trader, Tradee, TraderItems, TradeeItems, TradeDate) VALUES (@0, @1, @2, @3, @4);", trader.Name, tradee.Name, traderItems, tradeeItems, tradeDate.ToString("s")) != 0;
     }
     catch (Exception ex)
     {
         TShock.Log.Error(ex.ToString());
     }
     return false;
 }
开发者ID:Marcus101RR,项目名称:TradeRequest,代码行数:12,代码来源:Utilities.cs


示例7: GetUserTradeLogs

        public static IList<string> GetUserTradeLogs(User user, bool recent)
        {
            try
            {
				if(recent)
				{
					using (var reader = TShock.DB.QueryReader("SELECT * FROM TradeRequestLogs ORDER BY TradeRequestLogs.TradeDate DESC LIMIT 20"))
					{
						IList<string> results = new List<string>();
						while (reader.Read())
						{
							string trader = reader.Get<String>("Trader");
							string tradee = reader.Get<String>("Tradee");
							string traderItems = reader.Get<String>("TraderItems");
							string tradeeItems = reader.Get<String>("TradeeItems");
							string tradeDate = reader.Get<String>("TradeDate");

							results.Add(string.Format("{0} - {1} {2} <-> {3} {4}", DateTime.Parse(tradeDate), trader, traderItems, tradeeItems, tradee));
						}
						return results;
					}
				}
				else
				{
					// using (var reader = TShock.DB.QueryReader("SELECT * FROM TradeRequestLogs WHERE Trader LIKE '%@0%' OR Tradee LIKE '%@1%'", user.Name, user.Name))
					using (var reader = TShock.DB.QueryReader("SELECT * FROM TradeRequestLogs WHERE [email protected] OR [email protected]", user.Name, user.Name))
					{
						IList<string> results = new List<string>();
						while (reader.Read())
						{
							string trader = reader.Get<String>("Trader");
							string tradee = reader.Get<String>("Tradee");
							string traderItems = reader.Get<String>("TraderItems");
							string tradeeItems = reader.Get<String>("TradeeItems");
							string tradeDate = reader.Get<String>("TradeDate");

							results.Add(string.Format("{0} - {1} {2} <-> {3} {4}", DateTime.Parse(tradeDate), trader, traderItems, tradeeItems, tradee));
						}
						return results;
					}
				}
            }
            catch (Exception ex)
            {
                TShock.Log.ConsoleError("FetchHashedPasswordAndGroup SQL returned an error: " + ex);
            }
            return null;
        }
开发者ID:Marcus101RR,项目名称:TradeRequest,代码行数:48,代码来源:Utilities.cs


示例8: AddUser

		/// <summary>
		/// Adds a given username to the database
		/// </summary>
		/// <param name="user">User user</param>
		public void AddUser(User user)
		{
			if (!TShock.Groups.GroupExists(user.Group))
				throw new GroupNotExistsException(user.Group);

			int ret;
			try
			{
				ret = _database.Query("INSERT INTO Users (Username, Password, UUID, UserGroup, Registered) VALUES (@0, @1, @2, @3, @4);", user.Name,
					user.Password, user.UUID, user.Group, DateTime.UtcNow.ToString("s"));
			}
			catch (Exception ex)
			{
				// Detect duplicate user using a regexp as Sqlite doesn't have well structured exceptions
				if (Regex.IsMatch(ex.Message, "Username.*not unique"))
					throw new UserExistsException(user.Name);
				throw new UserManagerException("AddUser SQL returned an error (" + ex.Message + ")", ex);
			}

			if (1 > ret)
				throw new UserExistsException(user.Name);

			Hooks.AccountHooks.OnAccountCreate(user);
		}
开发者ID:sliekasirdis79,项目名称:TShock,代码行数:28,代码来源:UserManager.cs


示例9: AddUser

        /// <summary>
        /// Adds a given username to the database
        /// </summary>
        /// <param name="user">User user</param>
        public void AddUser(User user)
        {
            if (!TShock.Groups.GroupExists(user.Group))
                throw new GroupNotExistsException(user.Group);

            int ret;
            try
            {
                ret = database.Query("INSERT INTO Users (Username, Password, UserGroup) VALUES (@0, @1, @2);", user.Name,
                                   TShock.Utils.HashPassword(user.Password), user.Group);
            }
            catch (Exception ex)
            {
                // Detect duplicate user using a regexp as Sqlite doesn't have well structured exceptions
                if (Regex.IsMatch(ex.Message, "Username.*not unique"))
                    throw new UserExistsException(user.Name);
                throw new UserManagerException("AddUser SQL returned an error (" + ex.Message + ")", ex);
            }

            if (1 > ret)
                throw new UserExistsException(user.Name);
        }
开发者ID:k0rd,项目名称:TShock,代码行数:26,代码来源:UserManager.cs


示例10: SeedInitialData

        public bool SeedInitialData(User user)
        {
            var inventory = new StringBuilder();

            var items = new List<NetItem>(TShock.ServerSideCharacterConfig.StartingInventory);
            if (items.Count < NetItem.MaxInventory)
                items.AddRange(new NetItem[NetItem.MaxInventory - items.Count]);

            string initialItems = String.Join("~", items.Take(NetItem.MaxInventory));
            try
            {
                database.Query("INSERT INTO tsCharacter (Account, Health, MaxHealth, Mana, MaxMana, Inventory, spawnX, spawnY, questsCompleted) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8);",
                               user.ID,
                               TShock.ServerSideCharacterConfig.StartingHealth,
                               TShock.ServerSideCharacterConfig.StartingHealth,
                               TShock.ServerSideCharacterConfig.StartingMana,
                               TShock.ServerSideCharacterConfig.StartingMana,
                               initialItems,
                               -1,
                               -1,
                               0);
                return true;
            }
            catch (Exception ex)
            {
                TShock.Log.Error(ex.ToString());
            }

            return false;
        }
开发者ID:sylar605,项目名称:TshockCN,代码行数:30,代码来源:CharacterManager.cs


示例11: AccountCreateEventArgs

 public AccountCreateEventArgs(User user)
 {
     this.User = user;
 }
开发者ID:NyxStudios,项目名称:TShock,代码行数:4,代码来源:AccountHooks.cs


示例12: ManageUsers

        //Todo: Add separate help text for '/user add' and '/user del'. Also add '/user addip' and '/user delip'
        private static void ManageUsers(CommandArgs args)
        {
            // This guy needs to go away for the help later on to take effect.

            //if (args.Parameters.Count < 2)
            //{
            //    args.Player.SendMessage("Syntax: /user <add/del> <ip/user:pass> [group]");
            //    args.Player.SendMessage("Note: Passwords are stored with SHA512 hashing. To reset a user's password, remove and re-add them.");
            //    return;
            //}

            // This guy needs to be here so that people don't get exceptions when they type /user
            if (args.Parameters.Count < 1)
            {
                args.Player.SendMessage("Invalid user syntax. Try /user help.", Color.Red);
                return;
            }

            string subcmd = args.Parameters[0];

            // Add requires a username:password pair/ip address and a group specified.
            if (subcmd == "add")
            {
                var namepass = args.Parameters[1].Split(':');
                var user = new User();

                try
                {
                    if (args.Parameters.Count > 2)
                    {
                        if (namepass.Length == 2)
                        {
                            user.Name = namepass[0];
                            user.Password = namepass[1];
                            user.Group = args.Parameters[2];
                        }
                        else if (namepass.Length == 1)
                        {
                            user.Address = namepass[0];
                            user.Group = args.Parameters[2];
                            user.Name = user.Address;
                        }
                        if (!string.IsNullOrEmpty(user.Address))
                        {
                            args.Player.SendMessage("IP address admin added. If they're logged in, tell them to rejoin.", Color.Green);
                            args.Player.SendMessage("WARNING: This is insecure! It would be better to use a user account instead.", Color.Red);
                            TShock.Users.AddUser(user);
                            Log.ConsoleInfo(args.Player.Name + " added IP " + user.Address + " to group " + user.Group);
                        }
                        else
                        {
                            args.Player.SendMessage("Account " + user.Name + " has been added to group " + user.Group + "!", Color.Green);
                            TShock.Users.AddUser(user);
                            Log.ConsoleInfo(args.Player.Name + " added Account " + user.Name + " to group " + user.Group);
                        }
                    }
                    else
                    {
                        args.Player.SendMessage("Invalid syntax. Try /user help.", Color.Red);
                    }
                }
                catch (UserManagerException ex)
                {
                    args.Player.SendMessage(ex.Message, Color.Green);
                    Log.ConsoleError(ex.ToString());
                }
            }
            // User deletion requires a username
            else if (subcmd == "del" && args.Parameters.Count == 2)
            {
                var user = new User();
                if (args.Parameters[1].Contains("."))
                    user.Address = args.Parameters[1];
                else
                    user.Name = args.Parameters[1];

                try
                {
                    TShock.Users.RemoveUser(user);
                    args.Player.SendMessage("Account removed successfully.", Color.Green);
                    Log.ConsoleInfo(args.Player.Name + " successfully deleted account: " + args.Parameters[1]);
                }
                catch (UserManagerException ex)
                {
                    args.Player.SendMessage(ex.Message, Color.Red);
                    Log.ConsoleError(ex.ToString());
                }
            }
            // Password changing requires a username, and a new password to set
            else if (subcmd == "password")
            {
                var user = new User();
                user.Name = args.Parameters[1];

                try
                {

                    if (args.Parameters.Count == 3)
                    {
//.........这里部分代码省略.........
开发者ID:Icehawk78,项目名称:TShock,代码行数:101,代码来源:Commands.cs


示例13: SetUserGroup

        /// <summary>
        /// Sets the group for a given username
        /// </summary>
        /// <param name="user">User user</param>
        /// <param name="group">string group</param>
        public void SetUserGroup(User user, string group)
        {
            try
            {
                Group grp = TShock.Groups.GetGroupByName(group);
                if (null == grp)
                    throw new GroupNotExistsException(group);

                if (database.Query("UPDATE Users SET UserGroup = @0 WHERE Username = @1;", group, user.Name) == 0)
                    throw new UserNotExistException(user.Name);

                // Update player group reference for any logged in player
                foreach (var player in TShock.Players.Where(p => null != p && p.UserAccountName == user.Name))
                {
                    player.Group = grp;
                }
            }
            catch (Exception ex)
            {
                throw new UserManagerException("SetUserGroup SQL returned an error", ex);
            }
        }
开发者ID:k0rd,项目名称:TShock,代码行数:27,代码来源:UserManager.cs


示例14: DeleteAsync

		public async Task<bool> DeleteAsync(User user)
		{
			return await Task.Run(() =>
			{
				syncLock.EnterWriteLock();
				string query = db.GetSqlType() == SqlType.Mysql ?
					"DELETE FROM Mutes WHERE UUID = @0 OR IP = @1 ORDER BY ID DESC LIMIT 1" :
					"DELETE FROM Mutes WHERE ID IN (SELECT ID FROM Mutes WHERE UUID = @0 OR IP = @1 ORDER BY ID DESC LIMIT 1)";

				try
				{
					return db.Query(query, user.UUID, JsonConvert.DeserializeObject<List<string>>(user.KnownIps)[0]) > 0;
				}
				catch (Exception ex)
				{
					TShock.Log.Error(ex.ToString());
					return false;
				}
				finally
				{
					syncLock.ExitWriteLock();
				}
			});
		}
开发者ID:CrazyLegsSteph,项目名称:EssentialsPlus,代码行数:24,代码来源:MuteManager.cs


示例15: SetUserGroup

        /// <summary>
        /// Sets the group for a given username
        /// </summary>
        /// <param name="user">User user</param>
        /// <param name="group">string group</param>
        public void SetUserGroup(User user, string group)
        {
            try
            {
                if (!TShock.Groups.GroupExists(group))
                    throw new GroupNotExistsException(group);

                if (database.Query("UPDATE Users SET UserGroup = @0 WHERE Username = @1;", group, user.Name) == 0)
                    throw new UserNotExistException(user.Name);
            }
            catch (Exception ex)
            {
                throw new UserManagerException("SetUserGroup SQL returned an error", ex);
            }
        }
开发者ID:DaGamesta,项目名称:TShock,代码行数:20,代码来源:UserManager.cs


示例16: RemoveUser

        /// <summary>
        /// Removes a given username from the database
        /// </summary>
        /// <param name="user">User user</param>
        public void RemoveUser(User user)
        {
            try
            {
                int affected = -1;
                if (!string.IsNullOrEmpty(user.Address))
                {
                    affected = database.Query("DELETE FROM Users WHERE [email protected]", user.Address);
                }
                else
                {
                    affected = database.Query("DELETE FROM Users WHERE [email protected]", user.Name);
                }

                if (affected < 1)
                    throw new UserNotExistException(string.IsNullOrEmpty(user.Address) ? user.Name : user.Address);
            }
            catch (Exception ex)
            {
                throw new UserManagerException("RemoveUser SQL returned an error", ex);
            }
        }
开发者ID:DaGamesta,项目名称:TShock,代码行数:26,代码来源:UserManager.cs


示例17: GetUser

        public User GetUser(User user)
        {
            try
            {
                QueryResult result;
                if (string.IsNullOrEmpty(user.Address))
                {
                    result = database.QueryReader("SELECT * FROM Users WHERE [email protected]", user.Name);
                }
                else
                {
                    result = database.QueryReader("SELECT * FROM Users WHERE [email protected]", user.Address);
                }

                using (var reader = result)
                {
                    if (reader.Read())
                    {
                        user.ID = reader.Get<int>("ID");
                        user.Group = reader.Get<string>("Usergroup");
                        user.Password = reader.Get<string>("Password");
                        user.Name = reader.Get<string>("Username");
                        user.Address = reader.Get<string>("IP");
                        return user;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new UserManagerException("GetUserID SQL returned an error", ex);
            }
            throw new UserNotExistException(string.IsNullOrEmpty(user.Address) ? user.Name : user.Address);
        }
开发者ID:DaGamesta,项目名称:TShock,代码行数:33,代码来源:UserManager.cs


示例18: GetUser

        public User GetUser(User user)
        {
            bool multiple = false;
            string query;
            string type;
            object arg;
            if (0 != user.ID)
            {
                query = "SELECT * FROM Users WHERE [email protected]";
                arg = user.ID;
                type = "id";
            }
            else
            {
                query = "SELECT * FROM Users WHERE [email protected]";
                arg = user.Name;
                type = "name";
            }

            try
            {
                using (var result = database.QueryReader(query, arg))
                {
                    if (result.Read())
                    {
                        user = LoadUserFromResult(user, result);
                        // Check for multiple matches
                        if (!result.Read())
                            return user;
                        multiple = true;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new UserManagerException("GetUser SQL returned an error (" + ex.Message + ")", ex);
            }
            if (multiple)
                throw new UserManagerException(String.Format("Multiple users found for {0} '{1}'", type, arg));

            throw new UserNotExistException(user.Name);
        }
开发者ID:k0rd,项目名称:TShock,代码行数:42,代码来源:UserManager.cs


示例19: RemoveUser

        /// <summary>
        /// Removes a given username from the database
        /// </summary>
        /// <param name="user">User user</param>
        public void RemoveUser(User user)
        {
            try
            {
                int affected = database.Query("DELETE FROM Users WHERE [email protected]", user.Name);

                if (affected < 1)
                    throw new UserNotExistException(user.Name);
            }
            catch (Exception ex)
            {
                throw new UserManagerException("RemoveUser SQL returned an error", ex);
            }
        }
开发者ID:k0rd,项目名称:TShock,代码行数:18,代码来源:UserManager.cs


示例20: UpdateLogin

 public void UpdateLogin(User user)
 {
     try
     {
         if (database.Query("UPDATE Users SET LastAccessed = @0, KnownIps = @1 WHERE Username = @2;", DateTime.Now.ToString("G"), user.KnownIps, user.Name) == 0)
             throw new UserNotExistException(user.Name);
     }
     catch (Exception ex)
     {
         throw new UserManagerException("UpdateLogin SQL returned an error", ex);
     }
 }
开发者ID:k0rd,项目名称:TShock,代码行数:12,代码来源:UserManager.cs



注:本文中的TShockAPI.DB.User类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Mpeg4.BoxHeader类代码示例发布时间:2022-05-26
下一篇:
C# DB.SqlTableCreator类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap