示例#1
0
        public async void CheckForPasswordedMatchesAndSendNotificationsAsync(object state, ElapsedEventArgs args)
        {
            _db = new LadderDbContext();
            var match = _db.Matches.FirstOrDefault(match => match.MatchState == MatchState.Passworded);

            if (match == null)
            {
                return;
            }
            //very bad here, need to refactor
            foreach (var player in match.Players)
            {
                var playerfromDb = _db.Users.SingleOrDefault(user => user.Nick == player);
                await _client.GetUser(playerfromDb.DiscordId).SendMessageAsync(
                    "Match is starting." +
                    Environment.NewLine +
                    $"Team 1: {string.Join(", ",match.Players.Take(Constants.REQUIRED_AMOUNT_OF_PLAYERS / 2))}" +
                    Environment.NewLine +
                    $"Team 2: {string.Join(", ",match.Players.TakeLast(Constants.REQUIRED_AMOUNT_OF_PLAYERS / 2))}" +
                    Environment.NewLine +
                    "Open the game and paste this into the console:" +
                    Environment.NewLine +
                    $"`name {player}; password {match.Password}; connect {match.ServerIp};`");
            }
            match.MatchState = MatchState.SentNotifications;
            _db.Update(match);
            await _db.SaveChangesAsync();
        }
示例#2
0
 public LadderWeek LadderWeek(int weekId)
 {
     using (var db = new LadderDbContext())
     {
         return db.LadderWeeks.Find(weekId);
     }
 }
示例#3
0
 public Match GetMatchById(int id)
 {
     using (var db = new LadderDbContext())
     {
         return db.Matches.Find(id);
     }
 }
示例#4
0
 public LadderWeek CurrentWeek()
 {
     using (var db = new LadderDbContext())
     {
         return db.LadderWeeks.Where(c => c.IsCurrent).First();
     }
 }
示例#5
0
        private async Task MessageReceived(SocketMessage message)
        {
            if (message.Author.Id != Constants.AUTHORIZED_USER_ID)
            {
                return;
            }
            _db = new LadderDbContext();
            var matchId = Guid.NewGuid();
            await _db.Matches.AddAsync(
                new Match
            {
                Id         = matchId,
                Players    = new string[0],
                MatchState = MatchState.Created
            });

            await _db.SaveChangesAsync();

            var channel      = _client.GetChannel(Constants.AUTHORIZED_CHANNEL) as IMessageChannel;
            var announcement = await channel.SendMessageAsync(
                $"||{matchId}||" +
                Environment.NewLine +
                "@everyone" +
                Environment.NewLine +
                "New match!");

            await announcement.AddReactionAsync(new Emoji(Constants.PLUS_REACTION_EMOTE));
        }
示例#6
0
        public int GetPlayerStanding(int weekId, int playerId)
        {
            using (var db = new LadderDbContext())
            {
                return (from s in db.Standings
                        where s.LadderWeekId == weekId && s.PlayerId == playerId
                        select s.Position).First();

            }
        }
示例#7
0
        public List<LadderWeek> LadderWeeks()
        {
            using (var db = new LadderDbContext())
            {
                var c = from LadderWeek s in db.LadderWeeks.Include(l => l.Standings)
                        select s;

                return c.ToList();
            }
        }
示例#8
0
 public List<Match> CurrentMatches()
 {
     using (var db = new LadderDbContext())
     {
         var c = from Match s in db.Matches.Include(w => w.Winner).Include(l => l.Looser)
                 where s.LadderWeek.IsCurrent
                 orderby s.DateOfMatch
                 select s;
         return c.ToList();
     }
 }
 public List<Standing> CurrentStandings()
 {
     using (var db = new LadderDbContext())
     {
         var c = from Standing s in db.Standings.Include(l => l.Player)
                 where s.LadderWeek.IsCurrent
                 orderby s.Position
                 select s;
         return c.ToList();
     }
 }
示例#10
0
 public IEnumerable<Match> GetAllMatches(params Expression<Func<Match, object>>[] includeProperties)
 {
     using (var db = new LadderDbContext())
     {
         IQueryable<Match> query = db.Matches;
         foreach (var includeProperty in includeProperties)
         {
             query = query.Include(includeProperty);
         }
         return query.ToList();
     }
 }
示例#11
0
        private static void GoToLadder()
        {
            using (var db = new LadderDbContext())
            {
                Console.WriteLine("All People in database:");
                foreach (var item in db.LadderWeeks)
                {
                    Console.WriteLine(" - {0}", item.WeekNumber);
                }
            }

            Console.WriteLine("Done.");
            Console.ReadLine();
        }
示例#12
0
        private static void GoToLadder()
        {
            using (var db = new LadderDbContext())
            {
                Console.WriteLine("All People in database:");
                foreach (var item in db.LadderWeeks)
                {
                    Console.WriteLine(" - {0}", item.WeekNumber);
                }
            }

            Console.WriteLine("Done.");
            Console.ReadLine();
        }
示例#13
0
        async void CheckForMatchesWithEnoughPlayersAndPasswordServerAsync(object state, ElapsedEventArgs args)
        {
            _db = new LadderDbContext();
            var match = _db.Matches.FirstOrDefault(match => match.MatchState == MatchState.GotEnoughPlayers);

            if (match == null)
            {
                return;
            }
            var pw = "pug";

            await SendCommandAsync($"rcon myrcon g_password {pw}");

            match.MatchState = MatchState.Passworded;
            match.ServerIp   = $"{_ip}:29070";
            match.Password   = pw;
            _db.Update(match);
            await _db.SaveChangesAsync();
        }
示例#14
0
        private async Task ReactionAdded(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel,
                                         SocketReaction reaction)
        {
            if (reaction.User.Value.IsBot)
            {
                return;
            }
            if (reaction.Emote.Name != Constants.PLUS_REACTION_EMOTE)
            {
                await message.Value.RemoveReactionAsync(reaction.Emote, reaction.User.Value, RequestOptions.Default);

                return;
            }
            await message.Value.RemoveReactionAsync(new Emoji(Constants.PLUS_REACTION_EMOTE), _client.CurrentUser);

            _db = new LadderDbContext();
            if (!_db.Users.Any(user => user.Nick == reaction.User.Value.Username))
            {
                await _db.Users.AddAsync(new User
                {
                    Id        = Guid.NewGuid(),
                    Nick      = reaction.User.Value.Username,
                    DiscordId = reaction.User.Value.Id
                });
            }

            var matchId = Guid.Parse(message.Value.Content.Split(Environment.NewLine)[0].Split("||")[1]);
            var match   = _db.Matches.SingleOrDefault(match => match.Id == matchId);

            match.Players = match.Players.Append(reaction.User.Value.Username).ToArray();
            if (match.Players.Length == Constants.REQUIRED_AMOUNT_OF_PLAYERS)
            {
                match.MatchState = MatchState.GotEnoughPlayers;
            }

            await _db.SaveChangesAsync();
        }
示例#15
0
 public PlayersController(LadderDbContext db)
 {
     _db = db;
 }
示例#16
0
 public Player Player(int playerId)
 {
     using (var db = new LadderDbContext())
     {
         db.Configuration.LazyLoadingEnabled = false;
         var c = from Player s in db.Players.Include("Standings").Include("Standings.LadderWeek")
                 where s.Id == playerId
                 select s;
         return c.First();
     }
 }
示例#17
0
 public List<Match> PlayerMatches(int playerId)
 {
     using (var db = new LadderDbContext())
     {
         var c = from Match s in db.Matches.Include(w => w.Winner).Include(l => l.Looser).Include(t => t.LadderWeek)
                 where s.LooserId == playerId || s.WinnerId == playerId
                 orderby s.DateOfMatch
                 select s;
         return c.ToList();
     }
 }