Пример #1
0
    public void ConfirmBanUser()
    {
        var request = new BanRequest();

        try {
            if (!string.IsNullOrEmpty(banTimeInHours.text))
            {
                request.DurationInHours = uint.Parse(banTimeInHours.text);
            }
        } catch (System.Exception e) {
            request.DurationInHours = 0;
        }
        request.Reason    = banReason.text;
        request.PlayFabId = lastPlayerIdentifier.playerID;
        var banList = new List <BanRequest>();

        banList.Add(request);
        PlayFabAdminAPI.BanUsers(new BanUsersRequest {
            Bans = banList
        },
                                 result => {
            banModal.SetActive(false);
            Debug.Log("BAN USER OK: " + result.ToJson().ToString());
            Inform(string.Format("{0} was successfully banned for {1} hours for \"{2}\"",
                                 lastPlayerIdentifier.displayName, banTimeInHours.text, banReason.text));
        },
                                 error => {
            Debug.LogError("BAN PLAYER FAILED: " + error.ToString());
            Inform("Unable to ban user! " + error.ErrorMessage);
            banModal.SetActive(false);
        });
    }
Пример #2
0
        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.CloseSessionByUserId(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);
        }
Пример #3
0
 public Task <BanResponse> Ban(BanRequest request)
 {
     return(ConnectionManager.SendRequestAndWaitResponse <BanResponse>(request));
 }
Пример #4
0
 //
 public override Task <BanReply> Ban(BanRequest request, ServerCallContext context)
 {
 }
Пример #5
0
 public IActionResult Ban(BanRequest request)
 {
     throw new NotImplementedException();
 }