public BanResponse Ban(ISession session, BanRequest request) { var response = request.CreateResponse<BanResponse>(); User targetUser = null; using (var uow = UnitOfWorkFactory.Create()) { targetUser = uow.UsersRepository.FirstMatching(UserSpecification.Id(request.TargetUserId)); if (targetUser != null) { try { if (request.Ban) targetUser.Ban(session.User); else targetUser.UnBan(session.User); response.Result = BanResponseType.Success; uow.Commit(); } catch (ModeratorsRightsRequiredException) { response.Result = BanResponseType.Failed; } } } if (response.Result == BanResponseType.Success && targetUser != null) { //let's kick him\her from the server! _sessionManager.CloseSessionByPlayerId(targetUser.Id); //send a notification to everybody that we've banned him\her _sessionManager.SendToEachChatSessions( new BanNotification { Ban = request.Ban, ActorName = session.User.Name, Reason = request.Reason, TargetId = session.User.Id, TargetName = targetUser.Name }); } return response; }
public Task<BanResponse> Ban(BanRequest request) { return ConnectionManager.SendRequestAndWaitResponse<BanResponse>(request); }