当前位置: 首页>>代码示例>>C#>>正文


C# UserAccount.LoadCharacterIDs方法代码示例

本文整理汇总了C#中UserAccount.LoadCharacterIDs方法的典型用法代码示例。如果您正苦于以下问题:C# UserAccount.LoadCharacterIDs方法的具体用法?C# UserAccount.LoadCharacterIDs怎么用?C# UserAccount.LoadCharacterIDs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserAccount的用法示例。


在下文中一共展示了UserAccount.LoadCharacterIDs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Login

        /// <summary>
        /// Tries to log in an account.
        /// </summary>
        /// <param name="socket">The socket used to communicate with the client.</param>
        /// <param name="name">The name of the account.</param>
        /// <param name="password">The account password.</param>
        /// <param name="userAccount">When this method returns <see cref="AccountLoginResult.Successful"/>,
        /// contains the <see cref="IUserAccount"/> that was logged in to. Otherwise, this value will be null.</param>
        /// <returns>If <see cref="AccountLoginResult.Successful"/>, the login was successful. Otherwise, contains
        /// the reason why the login failed.</returns>
        public AccountLoginResult Login(IIPSocket socket, string name, string password, out IUserAccount userAccount)
        {
            // Try to load the account data
            var accountTable = DbController.GetQuery<SelectAccountQuery>().TryExecute(name);
            if (accountTable == null)
            {
                userAccount = null;
                return AccountLoginResult.InvalidName;
            }

            // Check the password
            var encodedPass = EncodePassword(password);
            if (!StringComparer.OrdinalIgnoreCase.Equals(encodedPass, accountTable.Password))
            {
                userAccount = null;
                return AccountLoginResult.InvalidPassword;
            }

            // Check if the account is already logged in to
            if (accountTable.CurrentIp.HasValue)
            {
                if (ServerSettings.Default.AccountDropExistingConnectionWhenInUse)
                {
                    // Kick existing user so the new connection can enter the account
                    UserAccount existingAccount;
                    lock (_accountsSync)
                    {
                        if (!_accounts.TryGetValue(name, out existingAccount))
                            existingAccount = null;
                    }

                    if (existingAccount != null)
                        existingAccount.Dispose();
                }
                else
                {
                    // Let the existing user stay connected and reject the new connection to the account
                    userAccount = null;
                    return AccountLoginResult.AccountInUse;
                }
            }

            // Try to mark the account as in use
            if (!DbController.GetQuery<TrySetAccountIPIfNullQuery>().Execute(accountTable.ID, socket.IP))
            {
                userAccount = null;
                return AccountLoginResult.AccountInUse;
            }

            // Try to add the new account to the collection
            lock (_accountsSync)
            {
                // If for some reason an account instance already exists, close it
                UserAccount existingAccount;
                if (_accounts.TryGetValue(name, out existingAccount))
                {
                    const string errmsg = "UserAccount for `{0}` already existing in _accounts collection somehow.";
                    if (log.IsErrorEnabled)
                        log.ErrorFormat(errmsg, name);
                    Debug.Fail(string.Format(errmsg, name));

                    userAccount = null;
                    return AccountLoginResult.AccountInUse;
                }

                // Create the account instance
                userAccount = new UserAccount(accountTable, socket, this);

                // Add
                _accounts.Add(name, (UserAccount)userAccount);
            }

            // Load the characters in this account
            userAccount.LoadCharacterIDs();

            // Record the login IP
            DbController.GetQuery<InsertAccountIPQuery>().Execute(userAccount.ID, socket.IP);

            return AccountLoginResult.Successful;
        }
开发者ID:wtfcolt,项目名称:game,代码行数:90,代码来源:UserAccountManager.cs


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