示例#1
0
        /// <summary>
        /// Insert a vote to kick a user
        /// </summary>
        /// <param name="userVote">The user's vote</param>
        /// <returns></returns>
        public Entities.ActionResponses.VoteToKick Execute(Entities.GamePlayerKickVote userVote)
        {
            string cacheKey = string.Format("KickUser_{0}_FromGame_{1}", userVote.KickUserId, userVote.GameID);

            Entities.User kickUser = _selectUser.Execute(userVote.KickUserId);

            Entities.ActionResponses.VoteToKick response = _insert.Execute(userVote);

            if (response.TotalVotes == 1 &&
                response.ResponseCode == Entities.ActionResponses.Enums.VoteToKick.VoteSuccessful &&
                userVote.Vote)
            {
                String jobId = BackgroundJob.Schedule(() => _checkVotes.Execute(userVote.GameID, userVote.KickUserId), TimeSpan.FromSeconds(30));

                MemoryCache.Default.Set(cacheKey, jobId, new CacheItemPolicy {
                    SlidingExpiration = TimeSpan.FromMinutes(1)
                });
            }

            if (response.AllVotesCasted)
            {
                var cachedJobId = MemoryCache.Default.Get(cacheKey);

                if (cachedJobId != null && cachedJobId is String)
                {
                    BackgroundJob.Delete(cachedJobId as String);
                }
                else
                {
                    _checkVotes.Execute(userVote.GameID, userVote.KickUserId);
                }
            }
            else
            {
                _sendMessage.Voted(userVote.GameID, kickUser, response.VotesToKick,
                                   response.VotesToStay,
                                   response.AlreadyVoted);
            }

            response.KickUser = kickUser;
            return(response);
        }
示例#2
0
        /// <summary>
        /// Check to see if the user has enough votes to be kicked
        /// </summary>
        /// <param name="gameID">The ID of the game the user belongs to</param>
        /// <param name="kickUserId">The ID of the user to kick</param>
        public void Execute(Int32 gameID, Int32 kickUserId)
        {
            Int32 votedToKick    = 0;
            Int32 votedNotToKick = 0;

            _checkVotes.Execute(gameID, kickUserId, out votedToKick, out votedNotToKick);

            Boolean kickUser = votedToKick > votedNotToKick;

            Entities.User kickedUser = _selectUser.Execute(kickUserId);

            if (votedToKick > 0)
            {
                _sendMessage.VoteComplete(gameID, kickedUser, votedToKick, votedNotToKick, kickUser);
            }

            if (kickUser)
            {
                //TODO: When spectator's can be kicked this will need to change
                _leaveGame.Execute(gameID, kickedUser, Entities.Enums.GamePlayerType.Player);
            }
        }