Пример #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.Creat(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("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!"));
            });
        }
Пример #3
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))
                {
                    //client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, "密码不合法");
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -3);
                    return;//密码不合法
                }

                accountCache.Creat(account, password);
                //client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, "注册成功");
                client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, 0);
            });
        }
Пример #4
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("注册成功"));
            });
        }
Пример #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);
            });
        }
Пример #6
0
 private void Login(ClientPeer client, string account, string password)
 {
     SingleExecute.Instance.Execute(() => {
         if (accountCache.IsExist(account))  //存在该账号
         {
             //然后判断密码
             if (accountCache.IsMatch(account, password))
             {
                 //密码正确
                 //client.StartSend(OpCode.ACCOUNT, AccountCode.LOGIN, "密码正确...");
                 if (accountCache.IsOnline(account))
                 {
                     //账号在线
                     client.StartSend(OpCode.ACCOUNT, AccountCode.LOGIN, "账号已经在线");
                     Console.WriteLine("账号已经在线...");
                 }
                 else
                 {
                     //登录成功
                     accountCache.Online(account, client);
                     client.StartSend(OpCode.ACCOUNT, AccountCode.LOGIN, "登录成功");
                     Console.WriteLine("登录成功...");
                 }
             }
             else
             {
                 //密码输入错误
                 client.StartSend(OpCode.ACCOUNT, AccountCode.LOGIN, "密码输入错误");
                 Console.WriteLine("密码输入错误");
             }
         }
         else
         {
             //不存在该账号
             client.StartSend(OpCode.ACCOUNT, AccountCode.LOGIN, "不存在该账号");
             Console.WriteLine("不存在该账号");
         }
     });
 }