示例#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
        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();
        }