示例#1
0
        /// <summary>
        /// 处理登录请求
        /// </summary>
        /// <param name="client"></param>
        /// <param name="dto"></param>
        private void HandleLogin(ClientPeer client, AccountDto dto)
        {
            SingleExec.Exec(() =>
            {
                if (!DatabaseManager.IsUserNameExist(dto.username))
                {
                    client.SendNetMsg(OpCode.account, AccountCode.loginSRes, AccountReturnCode.userNotFound);
                    return;
                }

                if (DatabaseManager.IsOnline(dto.username))
                {
                    client.SendNetMsg(OpCode.account, AccountCode.loginSRes, AccountReturnCode.userOnline);
                    return;
                }

                if (DatabaseManager.IsPasswordMatch(dto.username, dto.passwordHash))
                {
                    //设置登录状态
                    DatabaseManager.Login(dto.username, client);

                    //登录成功
                    client.SendNetMsg(OpCode.account, AccountCode.loginSRes, AccountReturnCode.success);
                }
                else
                {
                    client.SendNetMsg(OpCode.account, AccountCode.loginSRes, AccountReturnCode.passwordNotMatch);
                }
            });
        }
示例#2
0
 private void HandleGetRankList(ClientPeer client)
 {
     SingleExec.Exec(() =>
     {
         RankListDto dto = DatabaseManager.GetRankListDto();
         client.SendNetMsg(OpCode.account, AccountCode.getRankListSRes, dto);
     });
 }
示例#3
0
 /// <summary>
 /// 获取当前客户端登录用户的信息
 /// </summary>
 /// <param name="client"></param>
 private void HandleGetUserInfo(ClientPeer client)
 {
     SingleExec.Exec(() =>
     {
         UserInfoDto dto = DatabaseManager.CreateUserInfoDto(client.userId);
         client.SendNetMsg(OpCode.account, AccountCode.getUserInfoSRes, dto);
     });
 }
示例#4
0
        /// <summary>
        /// 处理客户端的注册请求
        /// </summary>
        private void HandleRegister(ClientPeer client, AccountDto dto)
        {
            SingleExec.Exec(() =>
            {
                if (DatabaseManager.IsUserNameExist(dto.username))
                {
                    client.SendNetMsg(OpCode.account, AccountCode.registerSRes, AccountReturnCode.userExist);
                    return;
                }

                try
                {
                    DatabaseManager.CreateUser(dto.username, dto.passwordHash);
                    client.SendNetMsg(OpCode.account, AccountCode.registerSRes, AccountReturnCode.success);
                }
                catch (MySqlException e)
                {
                    Console.WriteLine(e);
                }
            });
        }