Beispiel #1
0
        private IVoteHandler GetVoteHandler(Database.Model.Vote vote)
        {
            IVoteHandler handler = null;
            var          type    = ObjectContext.GetObjectType(vote.GetType());

            try
            {
                handler = _scope.Resolve(typeof(IVoteHandler <>).MakeGenericType(type), new TypedParameter(typeof(Database.Model.Vote), vote)) as IVoteHandler;
            }
            catch (Exception ex)
            {
                Logging.LogException($"Failed to resolve IVoteHandler for type '{type.Name}'", ex, GetType(), LogLevel.ERROR, ExceptionLevel.Unhandled);
                return(null);
            }

            if (handler == null)
            {
                Logging.Log($"Failed to resolve IVoteHandler for type '{type.Name}'", GetType(), LogLevel.ERROR);
                return(null);
            }

            return(handler);
        }
Beispiel #2
0
        private async Task VoteFinished(ArkServerContext serverContext, IEfDatabaseContext db, Database.Model.Vote vote, bool noAnnouncement = false, VoteResult?forcedResult = null)
        {
            var handler = GetVoteHandler(vote);

            if (handler == null)
            {
                return;
            }

            var votesFor     = vote.Votes.Count(x => x.VotedFor);
            var votesAgainst = vote.Votes.Count(x => !x.VotedFor);

#if DEBUG
            vote.Result = forcedResult ?? (vote.Votes.Count >= 1 && votesFor > votesAgainst ? VoteResult.Passed : VoteResult.Failed);
#else
            vote.Result = forcedResult ?? (vote.Votes.Count >= 3 && votesFor > votesAgainst ? VoteResult.Passed : VoteResult.Failed);
#endif

            VoteStateChangeResult result = null;
            try
            {
                result = await handler.VoteFinished(serverContext, _config, _constants, db);

                try
                {
                    if (!noAnnouncement && result != null)
                    {
                        if (result.MessageRcon != null)
                        {
                            await serverContext.Steam.SendRconCommand($"serverchat {result.MessageRcon.ReplaceRconSpecialChars()}");
                        }
                        if (result.MessageAnnouncement != null && !string.IsNullOrWhiteSpace(_config.Discord.AnnouncementChannel))
                        {
                            await _discordManager.SendTextMessageToChannelNameOnAllServers(_config.Discord.AnnouncementChannel, result.MessageAnnouncement);
                        }
                    }
                }
                catch { /* ignore all exceptions */ }

                if (result != null && result.React != null)
                {
                    if (result.ReactDelayInMinutes <= 0)
                    {
                        await result.React();
                    }
                    else
                    {
                        await _scheduledTasksManager.StartCountdown(serverContext, result.ReactDelayFor, result.ReactDelayInMinutes, result.React);
                    }
                }
            }
            catch (Exception ex)
            {
                //todo: better exception handling structure
                Logging.LogException(ex.Message, ex, GetType(), LogLevel.ERROR, ExceptionLevel.Unhandled);
            }
            db.SaveChanges();
        }
 public UpdateServerVoteHandler(Database.Model.Vote vote, IArkServerService arkServerService)
 {
     _vote             = vote as UpdateServerVote;
     _arkServerService = arkServerService;
 }
Beispiel #4
0
 public BanVoteHandler(Database.Model.Vote vote)
 {
     _vote = vote as BanVote;
 }
Beispiel #5
0
 public void OnVoteResultForced(Database.Model.Vote item, VoteResult forcedResult)
 {
     VoteResultForced?.Invoke(this, new VoteResultForcedEventArgs {
         Item = item, Result = forcedResult
     });
 }
Beispiel #6
0
 public void OnVoteInitiated(Database.Model.Vote item)
 {
     VoteInitiated?.Invoke(this, new VoteInitiatedEventArgs {
         Item = item
     });
 }
 public DestroyWildDinosVoteHandler(Database.Model.Vote vote)
 {
     _vote = vote as DestroyWildDinosVote;
 }
Beispiel #8
0
 public RestartServerVoteHandler(Database.Model.Vote vote, IArkServerService arkServerService)
 {
     _vote             = vote as RestartServerVote;
     _arkServerService = arkServerService;
 }
Beispiel #9
0
 public SetTimeOfDayVoteHandler(Database.Model.Vote vote)
 {
     _vote = vote as SetTimeOfDayVote;
 }