Пример #1
0
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="client"></param>
        /// <param name="account"></param>
        /// <param name="password"></param>
        private void regist(ClientPeer client, string account, string password)
        {
            SingleExecute.Instance.Execute(() =>
            {
                if (accountCache.IsExist(account))
                {
                    //账号已经存在
                    //client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, "账号已经存在");
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -1);
                    return;
                }
                if (string.IsNullOrEmpty(account))
                {
                    //账号输入不合法
                    //client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, "账号输入不合法");
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -2);

                    return;
                }
                if (string.IsNullOrEmpty(password) || password.Length < 4 || password.Length > 16)
                {
                    //密码不合法
                    //client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, "密码不合法");
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -3);

                    return;
                }
                // 可以注册
                accountCache.Create(account, password);
                //client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, "注册成功");
                client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, 0);
            });
        }
Пример #2
0
        private void Regist(ClientPeer client, string account, string password)
        {
            SingleExecute.Instance.Execute(() =>
            {
                if (accountCache.IsExist(account))
                {
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -1);
                    Console.WriteLine(string.Format("错误:帐号已经存在"));
                    return;
                }

                if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(password))
                {
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -2);
                    Console.WriteLine(string.Format("错误:账号不合法"));
                    return;
                }

                if (string.IsNullOrEmpty(password) || password.Length < 4 || password.Length > 16)
                {
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -3);
                    Console.WriteLine(string.Format("错误:密码不合法"));
                    return;
                }

                accountCache.Create(account, password);
                client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, 0);
                Console.WriteLine(string.Format("注册成功"));
            });
        }
Пример #3
0
        private void Regist(ClientPeer client, string account, string password)
        {
            SingleExecute.Instance.Execute(() =>
            {
                if (accountCache.IsExist(account))
                {
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -1);
                    Console.WriteLine(string.Format("Error:Account already exist!"));
                    return;
                }
                if (string.IsNullOrEmpty(account))
                {
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -2);
                    Console.WriteLine(string.Format("Error:Account is invalid"));
                    return;
                }
                if (string.IsNullOrEmpty(password) || password.Length < 4 || password.Length > 16)
                {
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -3);
                    Console.WriteLine(string.Format("Error:Password is invalid"));
                    return;
                }

                accountCache.Create(account, password);
                client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, 0);
                Console.WriteLine(string.Format("Sign Up Successfully!"));
            });
        }
Пример #4
0
        /// <summary>
        /// 注册账号
        /// </summary>
        /// <param name="clientPeer"></param>
        /// <param name="acc"></param>
        /// <param name="pwd"></param>
        private void Register(ClientPeer clientPeer, string acc, string pwd)
        {
            SingleExcute.Instance.Excute(() =>
            {
                if (accountCache.IsExit(acc))//账号是否存在
                {
                    clientPeer.Send(OpCode.ACCOUNT, AccountSubCode.REGISTE_SRES, "账号已经存在");
                    return;
                }


                if (string.IsNullOrEmpty(acc))
                {
                    clientPeer.Send(OpCode.ACCOUNT, AccountSubCode.REGISTE_SRES, "输入的账号不合法");
                    return;
                }

                if (pwd.Length < 4 || pwd.Length > 16)
                {
                    clientPeer.Send(OpCode.ACCOUNT, AccountSubCode.REGISTE_SRES, "密码长度不合法");
                    return;
                }

                accountCache.Create(acc, pwd);
                clientPeer.Send(OpCode.ACCOUNT, AccountSubCode.REGISTE_SRES, "注册成功");
            });
        }
Пример #5
0
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="client"></param>
        /// <param name="info"></param>
        private void Regist(ClientPeer client, UserInfoDto info)
        {
            SingleExecute.Instance.Execute(() =>
            {
                var msg = new SocketMsg
                {
                    OpCode  = MsgType.Account,
                    SubCode = AccountCode.Regist_Check,
                    State   = AccountCode.Success
                };
                if (string.IsNullOrEmpty(info.Account))
                {
                    msg.State = AccountCode.AccountEntryIsIllegal;
                    client.Send(msg);
                    return;
                }

                if (string.IsNullOrEmpty(info.Password) || info.Password.Length < 4 || info.Password.Length > 16)
                {
                    msg.State = AccountCode.ThePasswordIsIllegal;
                    client.Send(msg);
                    return;
                }
                if (accountCache.IsExist(info.Account))
                {
                    msg.State = AccountCode.AccountAlreadyExists;
                    client.Send(msg);
                    return;
                }
                //查询数据库是否存在当前账号
                //var db = DatabaseHelper.GetInstance();
                //var userInfo = db.Queryable<UserInfo>().Where(w => w.Account == info.Account).ToList();
                //if (userInfo.Count > 0)
                //{
                //    msg.value = MsgType.AccountAlreadyExists;
                //    client.Send(msg);
                //    return;
                //}

                //可以注册了 放入缓存
                accountCache.Create(info.Account, info.Password);
                //try
                //{
                //    var user = new UserInfo
                //    {
                //        Account = info.Account,
                //        Password = info.Password
                //    };
                //    db.Insertable(user).ExecuteCommand();
                //}
                //catch (Exception e)
                //{
                //    Console.WriteLine(e.Message);
                //    throw;
                //}

                client.Send(msg);
            });
        }