/// <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); } }); }
private void HandleGetRankList(ClientPeer client) { SingleExec.Exec(() => { RankListDto dto = DatabaseManager.GetRankListDto(); client.SendNetMsg(OpCode.account, AccountCode.getRankListSRes, dto); }); }
/// <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); }); }
/// <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); } }); }