Пример #1
0
 /// <summary>
 /// 类型:方法
 /// 名称:UserInfo
 /// 作者:taixihuase
 /// 作用:通过现有的 UserInfo 对象构造新的 UserInfo 对象
 /// 编写日期:2015/7/12
 /// </summary>
 /// <param name="user"></param>
 public UserInfo(UserInfo user)
 {
     Guid = user.Guid;
     UniqueId = user.UniqueId;
     Account = user.Account;
     Nickname = user.Nickname;
 }
Пример #2
0
 /// <summary>
 /// 类型:方法
 /// 名称:Character
 /// 作者:taixihuase
 /// 作用:通过用户信息构造一个角色对象
 /// 编写日期:2015/7/22
 /// </summary>
 /// <param name="user"></param>
 public Character(UserInfo user)
     : base(user)
 {
     Position = new Position();
     Experience = new Experience();
     Occupation = new Occupation();
     Attribute = new CharacterAttribute();
     Weapons = new WeaponCollection();
     Armors = new ArmorCollection();
     Jewels = new JewelCollection();
     Skills = new SkillCollection();
 }
Пример #3
0
        /// <summary>
        /// 类型:方法
        /// 名称:GetUserInfo
        /// 作者:taixihuase
        /// 作用:尝试从数据库获取获取用户信息
        /// 编写日期:2015/7/24
        /// </summary>
        /// <param name="user"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public UserCollection.UserReturn GetUserInfo(UserInfo user, string password)
        {
            UserCollection.UserReturn userReturn = new UserCollection.UserReturn();

            if (user.Account == "test" || user.Account == "siege" || user.Account == "online")
            {
                if (password == "1234")
                {
                    if (user.Account == "siege")
                    {
                        user.UniqueId = 1;
                        user.Nickname = "abcd";
                    }
                    else if (user.Account == "online")
                    {
                        user.UniqueId = 2;
                        user.Nickname = "efgh";
                    }
                    else
                    {
                        user.UniqueId = 3;
                        user.Nickname = "test";
                    }

                    userReturn.ReturnCode = Default;
                    userReturn.DebugMessage.Append("用户信息正确!");
                }
                else
                {
                    userReturn.ReturnCode = WrongPassword;
                    userReturn.DebugMessage.Append("密码错误!");
                }
            }
            else
            {
                userReturn.ReturnCode = Unregister;
                userReturn.DebugMessage.Append("该账号未注册!");
            }

            return userReturn;
        }
Пример #4
0
        /// <summary>
        /// 类型:方法
        /// 名称:UserOnline
        /// 作者:taixihuase
        /// 作用:通过接收并添加一个用户信息进行登录
        /// 编写日期:2015/7/12
        /// </summary>
        /// <param name="user"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public UserReturn UserOnline(UserInfo user, string password)
        {
            // 从数据库获取用户信息
            UserReturn userReturn = Server.Data.UserData.GetUserInfo(user, password);

            #region 判断用户登录信息是否正确,正确则尝试登录,错误则直接返回

            if (userReturn.ReturnCode == UserReturn.ReturnCodeType.Default)
            {
                lock (this)
                {
                    // 如果已查得登录信息
                    if (GuidToUniqueId.ContainsKey(user.Guid) || AccountToUniqueId.ContainsKey(user.Account) ||
                        UniqueIdToUser.ContainsKey(user.UniqueId))
                    {
                        userReturn.ReturnCode = RepeatedLogin;
                        userReturn.DebugMessage.Append("重复登录!");
                    }
                    else
                    {
                        // 添加用户信息

                        GuidToUniqueId.Add(user.Guid, user.UniqueId);

                        user.LoginTime = DateTime.Now;
                        user.Status = Loginning;

                        UniqueIdToUser.Add(user.UniqueId, user);
                        if (!AccountToUniqueId.ContainsKey(user.Account))
                        {
                            AccountToUniqueId.Add(user.Account, user.UniqueId);
                        }
                        if (!NicknameToUniqueId.ContainsKey(user.Nickname))
                        {
                            NicknameToUniqueId.Add(user.Nickname, user.UniqueId);
                        }

                        userReturn.ReturnCode = Success;
                        userReturn.DebugMessage.Append("登录成功!");
                    }
                }
            }

            #endregion

            return userReturn;
        }
Пример #5
0
        /// <summary>
        /// 类型:方法
        /// 名称:CreateCharacter
        /// 作者:taixihuase
        /// 作用:当成功获取到角色数据时触发创建角色事件
        /// 编写日期:2015/7/29
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        private IEnumerator CreateCharacter(object sender, UserInfo user)
        {
            CreateCharacter create;
            while ((create = FindObjectOfType<CreateCharacter>()) == null)
            {
                yield return null;
            }
            CreateCharacterEventArgs cc = new CreateCharacterEventArgs(user);
            create.OnCreate(sender, cc);

            Destroy(transform.parent.gameObject);
        }
Пример #6
0
        /// <summary>
        /// 类型:方法
        /// 名称:TryLogin
        /// 作者:taixihuase
        /// 作用:通过登录数据尝试登录
        /// 编写日期:2015/7/14
        /// </summary>
        /// <param name="operationRequest"></param>
        /// <param name="sendParameters"></param>
        /// <param name="peer"></param>
        private static void TryLogin(OperationRequest operationRequest, SendParameters sendParameters, ServerPeer peer)
        {
            ServerPeer.Log.Debug("Logining...");

            LoginInfo login = (LoginInfo)
                Serialization.Deserialize(operationRequest.Parameters[(byte) ParameterCode.Login]);

            #region 对账号密码进行判断

            ServerPeer.Log.Debug(DateTime.Now + " : Loginning...");
            ServerPeer.Log.Debug(login.Account);
            ServerPeer.Log.Debug(login.Password);

            // 获取用户资料
            UserInfo user = new UserInfo(peer.PeerGuid, login.Account);
            UserCollection.UserReturn userReturn = peer.Server.Users.UserOnline(user, login.Password);

            // 若成功取得用户资料
            if (userReturn.ReturnCode == UserCollection.UserReturn.ReturnCodeType.Success)
            {
                ServerPeer.Log.Debug(user.LoginTime + " :User " + user.Nickname + " loginning...");

                // 用于选择的数据返回参数
                var parameter = new Dictionary<byte, object>();

                // 用于选择的字符串信息
                string message = "";

                // 用于选择的返回值
                short returnCode = -1;

                #region 获取角色资料

                Character character = new Character(user);
                CharacterCollection.CharacterReturn characterReturn =
                    peer.Server.Characters.SearchCharacter(character);

                // 若取得角色资料
                if (characterReturn.ReturnCode == CharacterCollection.CharacterReturn.ReturnCodeType.Success)
                {
                    byte[] playerBytes = Serialization.Serialize(character);
                    parameter.Add((byte) ParameterCode.Login, playerBytes);
                    returnCode = (short) ErrorCode.Ok;
                    message = "";

                    peer.Server.Characters.CharacterLoad(character);
                }
                else if (characterReturn.ReturnCode == CharacterNotFound)
                {
                    byte[] userBytes = Serialization.Serialize(user);
                    parameter.Add((byte) ParameterCode.Login, userBytes);
                    returnCode = (short) ErrorCode.CharacterNotFound;
                    message = characterReturn.DebugMessage.ToString();
                }

                #endregion

                OperationResponse response = new OperationResponse((byte) OperationCode.Login, parameter)
                {
                    ReturnCode = returnCode,
                    DebugMessage = message
                };
                peer.SendOperationResponse(response, sendParameters);
                ServerPeer.Log.Debug(user.LoginTime + " : User " + user.Account + " logins successfully");
            }
            // 若重复登录
            else if (userReturn.ReturnCode == RepeatedLogin)
            {
                OperationResponse response = new OperationResponse((byte) OperationCode.Login)
                {
                    ReturnCode = (short) ErrorCode.RepeatedOperation,
                    DebugMessage = "账号已登录!"
                };
                peer.SendOperationResponse(response, sendParameters);
                ServerPeer.Log.Debug(DateTime.Now + " : Failed to login " + user.Account + " Because of " +
                                     Enum.GetName(typeof (UserCollection.UserReturn.ReturnCodeType),
                                         userReturn.ReturnCode));
            }
            else
            {
                // 返回非法登录错误
                OperationResponse response = new OperationResponse((byte) OperationCode.Login)
                {
                    ReturnCode = (short) ErrorCode.InvalidOperation,
                    DebugMessage = userReturn.DebugMessage.ToString()
                };
                peer.SendOperationResponse(response, sendParameters);
                ServerPeer.Log.Debug(DateTime.Now + " : Failed to login " + user.Account + " Because of " +
                                     Enum.GetName(typeof (UserCollection.UserReturn.ReturnCodeType),
                                         userReturn.ReturnCode));
            }

            #endregion
        }
Пример #7
0
 public void SetUserInfo(UserInfo user)
 {
     User = user;
 }
Пример #8
0
 public void SaveUser(UserInfo user)
 {
     
 }
 /// <summary>
 /// 类型:方法
 /// 名称:CreateCharacterEventArgs
 /// 作者:taixihuase
 /// 作用:用创建角色时所需的数据构造事件数据
 /// 编写日期:2015/7/26
 /// </summary>
 /// <param name="user"></param>
 public CreateCharacterEventArgs(UserInfo user)
 {
     User = user;
 }