Beispiel #1
0
        Process RunAndAccept(TournamentParticipant p)
        {
            var process = new Process();

            process.StartInfo.FileName        = p.PathToExe;
            process.StartInfo.Arguments       = $"127.0.0.1 {tournamentProxyPort}";
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.CreateNoWindow  = true;

            process.StartInfo.ErrorDialog = false;
            process.Start();
            var watch = new Stopwatch();

            watch.Start();
            while (watch.ElapsedMilliseconds < 1000)
            {
                if (listener.Pending())
                {
                    var client = listener.AcceptTcpClient();
                    client.ReadJson <JObject>();
                    client.ReadJson <JObject>();
                    var unityClient = new TcpClient();
                    unityClient.Connect(MultiplayerProxyConfigurations.UnityEndPoint);
                    Proxy.CreateChainAndStart(client, unityClient);
                    return(process);
                }
            }
            throw new Exception();
        }
Beispiel #2
0
        static bool Prefix(ref List <TournamentParticipant> ____participants, TournamentParticipant participant, bool firstTime, TournamentMatch __instance)
        {
            if (!__instance.IsPlayerParticipating())
            {
                return(true);
            }

            var teams          = __instance.Teams.CastList <MBTournamentTeam>();
            var playerTeam     = GetPlayerTeamFrom(teams);
            var nonPlayerTeams = teams;

            nonPlayerTeams.Remove(playerTeam);

            MBTournamentParticipant wrappedParticipant = participant;

            ____participants.Add(participant);

            if (playerTeam.IsParticipantRequired() &&
                (participant.IsPlayer || participant.IsPlayerCompanion() || participant.IsMarriedToPlayer() || participant.IsPlayerTroop()))
            {
                playerTeam.AddParticipant(participant);

                return(false);
            }

            if ((firstTime && participant.TryPlaceInNewOrSameTeam(teams.CastList <TournamentTeam>())) || participant.TryPlaceInAnyTeam(teams.CastList <TournamentTeam>()))
            {
                return(false);
            }

            return(false);
        }
Beispiel #3
0
 public ArchivedGame(GameData gameData, TournamentParticipant opponent, GameResult result, bool timeFlag = false)
 {
     GameData = gameData;
     Opponent = opponent;
     Result   = result;
     TimeFlag = timeFlag;
 }
Beispiel #4
0
        public static TournamentParticipant ToModel(this JoinTournamentRequest viewmodel, Int32 TournamentID)
        {
            TournamentParticipant model = new TournamentParticipant();

            model.UserID       = UserHelper.CurrentUserID;
            model.TournamentID = TournamentID;
            model.Registered   = DateTime.Now;

            return(model);
        }
 public BattleRoyalTournamentBehavior(TournamentGame tournamentGame, Settlement settlement, ITournamentGameBehavior gameBehavior, bool isPlayerParticipating)
 {
     this.Settlement      = settlement;
     this._tournamentGame = tournamentGame;
     this._gameBehavior   = gameBehavior;
     this.Rounds          = new TournamentRound[4];
     this.CreateParticipants(isPlayerParticipating);
     this.CurrentRoundIndex     = -1;
     this.LastMatch             = null;
     this.Winner                = null;
     this.IsPlayerParticipating = isPlayerParticipating;
 }
Beispiel #6
0
 public override void OnAgentRemoved(Agent affectedAgent, Agent affectorAgent, AgentState agentState, KillingBlow killingBlow)
 {
     if (!GameNetwork.IsClientOrReplay && !this.IsMatchEnded() && affectorAgent != null && affectedAgent != null && affectedAgent != affectorAgent && affectedAgent.IsHuman && affectorAgent.IsHuman)
     {
         var p = _match.GetParticipant(affectorAgent.Origin.UniqueSeed);
         if (firstKiller == null)
         {
             firstKiller = p;
         }
         achievements[p].NumberOfKills++;
     }
 }
Beispiel #7
0
        public static bool TryPlaceInNewOrSameTeam(this TournamentParticipant participant, IEnumerable <TournamentTeam> teams)
        {
            var participantWasPlaced = false;

            foreach (TournamentTeam team in teams)
            {
                if (team.IsParticipantRequired() && (!participant.HasTeam() || participant.WasPreviouslyOnTeam(team)))
                {
                    team.AddParticipant(participant);
                    participantWasPlaced = true;
                    break;
                }
            }

            return(participantWasPlaced);
        }
Beispiel #8
0
        public static bool TryPlaceInAnyTeam(this TournamentParticipant participant, IEnumerable <TournamentTeam> teams)
        {
            var participantWasPlaced = false;

            foreach (TournamentTeam team in teams)
            {
                if (!team.IsParticipantRequired())
                {
                    team.AddParticipant(participant);
                    participantWasPlaced = true;
                    break;
                }
            }

            return(participantWasPlaced);
        }
Beispiel #9
0
        internal static void EquipParticipant(
            SandBox.TournamentFightMissionController __instance,
            CultureObject ____culture,
            TournamentTeam team,
            Dictionary <TournamentTeam, int> mountMap,
            TournamentParticipant participant)
        {
            var equipment = BuildViableEquipmentSet();

            Log(new string('-', 50));
            LogWeaponsAndMount(equipment);
            if (!equipment[10].IsEmpty)
            {
                mountMap[team]++;
            }

            participant.MatchEquipment = equipment;
            AccessTools.Method(typeof(SandBox.TournamentFightMissionController), "AddRandomClothes")
            .Invoke(__instance, new object[] { ____culture, participant });
        }
Beispiel #10
0
        private void MigrateTournamentParticipant(DataContext db, MySqlConnection conn, DataSet set, MySqlDataAdapter adapter)
        {
            adapter.SelectCommand = new MySqlCommand("select * from tournaments_participants", conn);
            adapter.Fill(set, "tournaments_participants");
            try
            {
                foreach (DataRow entry in set.Tables["tournaments_participants"].Rows)
                {
                    if (Convert.ToInt32(entry["user_id"]) == 0 || new int[] { 12, 14, 20 }.Contains(Convert.ToInt32(entry["tournament_id"])))
                    {
                        continue;
                    }
                    int tournamentTeamID = -1;
                    int offsetID         = 0;
                    try { offsetID = TupleToId(db, Convert.ToInt32(entry["user_id"])); }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Skipping Participant : {0}", Convert.ToInt32(entry["user_id"]));
                        continue;
                    }
                    if (Convert.ToInt32(entry["tournament_id"]) == 0)
                    {
                        continue;
                    }
                    int tid = Convert.ToInt32(entry["tournament_id"]) - 7;
                    if (Convert.ToInt32(entry["tournament_id"]) > 20)
                    {
                        tid -= 4;
                    }
                    else
                    if (Convert.ToInt32(entry["tournament_id"]) > 16)
                    {
                        tid -= 3;
                    }
                    else
                    if (Convert.ToInt32(entry["tournament_id"]) > 11)
                    {
                        tid -= 1;
                    }

                    if (Convert.ToInt32(entry["team_id"]) != 0)
                    {
                        MySqlDataAdapter internalAdaper = new MySqlDataAdapter();
                        DataSet          internalSet    = new DataSet();
                        internalAdaper.SelectCommand = new MySqlCommand($"Select ID from tournaments_teams where ID={Convert.ToInt32(entry["team_id"])}", conn);
                        internalAdaper.Fill(internalSet, "tournaments_teams");

                        var ID = Convert.ToInt32(internalSet.Tables["tournaments_teams"].Rows[0]["ID"]);
                        tournamentTeamID = TournamentOldToNew[ID];
                    }
                    TournamentParticipant     part1 = null;
                    TournamentTeamParticipant part2 = null;

                    var tournament = db.Tournament.Find(tid);
                    if (tournament.TeamSize > 1)
                    {
                        var participant = new TournamentTeamParticipant()
                        {
                            Registered     = GetFromMySqlDate(new MySqlDateTime(entry["registered"].ToString())).Value,
                            TournamentTeam = db.TournamentTeam.Find(tournamentTeamID),
                            UserID         = offsetID,
                        };
                        part2 = participant;
                        if (participant.TournamentTeam == null)
                        {
                            continue;
                        }
                        db.TournamentTeamParticipant.Add(participant);
                    }
                    else
                    {
                        var participant = new TournamentParticipant()
                        {
                            Registered = GetFromMySqlDate(new MySqlDateTime(entry["registered"].ToString())).Value,
                            Tournament = db.Tournament.Find(tid),
                            UserID     = offsetID,
                        };
                        part1 = participant;
                        if (participant.Tournament == null)
                        {
                            continue;
                        }
                        db.TournamentParticipant.Add(participant);
                    }
                    try {
                        db.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Beispiel #11
0
 public static bool HasTeam(this TournamentParticipant participant)
 {
     return(participant.Team != null);
 }
Beispiel #12
0
 public static bool WasPreviouslyOnTeam(this TournamentParticipant participant, TournamentTeam team)
 {
     return(participant.Team.TeamColor == team.TeamColor);
 }
Beispiel #13
0
 public static bool ShouldAddToPlayerTeam(this TournamentParticipant participant)
 {
     return(Settings.BringCompanions && (participant.IsPlayerCompanion() || participant.IsMarriedToPlayer()));
 }
Beispiel #14
0
 public static bool IsPlayerCompanion(this TournamentParticipant participant)
 {
     return(participant.Character.IsHero && participant.Character.HeroObject.IsPlayerCompanion);
 }
Beispiel #15
0
 public static bool IsMarriedToPlayer(this TournamentParticipant participant)
 {
     return(participant.Character.HeroObject?.Spouse != null && participant.Character.HeroObject.Spouse == Hero.MainHero);
 }
Beispiel #16
0
        // Tournament Participant
        public static TournamentParticipantViewModelItem FromModel(this TournamentParticipantViewModelItem viewmodel, TournamentParticipant model)
        {
            viewmodel.ID        = model.ID;
            viewmodel.UserID    = model.UserID;
            viewmodel.FirstName = model.User.FirstName;
            viewmodel.LastName  = model.User.LastName;
            viewmodel.Nickname  = model.User.Nickname;

            return(viewmodel);
        }
 private void EndCurrentMatch()
 {
     this.LastMatch = this.CurrentMatch;
     this.CurrentRound.EndMatch();
     this._gameBehavior.OnMatchEnded();
     if (this.LastMatch.IsPlayerParticipating())
     {
         if (!this.LastMatch.Winners.All <TournamentParticipant>((TournamentParticipant x) => x.Character != CharacterObject.PlayerCharacter))
         {
             this.OnPlayerWinMatch();
         }
         else
         {
             this.OnPlayerEliminated();
         }
     }
     if (this.NextRound != null)
     {
         while (true)
         {
             if (!(
                     from x in this.LastMatch.Winners
                     where !x.IsAssigned
                     select x).Any <TournamentParticipant>())
             {
                 break;
             }
             foreach (TournamentParticipant winner in this.LastMatch.Winners)
             {
                 if (winner.IsAssigned)
                 {
                     continue;
                 }
                 this.NextRound.AddParticipant(winner, false);
                 winner.IsAssigned = true;
             }
         }
     }
     if (this.CurrentRound.CurrentMatch == null)
     {
         if (this.CurrentRoundIndex < 3)
         {
             this.CurrentRoundIndex = this.CurrentRoundIndex + 1;
             this.CalculateBet();
             return;
         }
         this.CalculateBet();
         InformationManager.AddQuickInformation(new TextObject("{=tWzLqegB}Tournament is over.", null), 0, null, "");
         this.Winner = this.LastMatch.Winners.FirstOrDefault <TournamentParticipant>();
         foreach (TournamentParticipant tournamentParticipant in this.LastMatch.Winners)
         {
             if (tournamentParticipant.Character == CharacterObject.PlayerCharacter)
             {
                 this.OnPlayerWinTournament();
             }
             if (!tournamentParticipant.Character.IsHero)
             {
                 continue;
             }
             Campaign.Current.TournamentManager.AddLeaderboardEntry(tournamentParticipant.Character.HeroObject);
             CampaignEventDispatcher.Instance.OnTournamentWon(tournamentParticipant.Character, this.Settlement.Town);
         }
         if (this.TournamentEnd != null)
         {
             this.TournamentEnd();
         }
     }
 }
        public static BackendUserViewModelItem FromModel(this BackendUserViewModelItem viewmodel, TournamentParticipant model)
        {
            viewmodel.ID         = model.ID;
            viewmodel.FirstName  = model.User.FirstName;
            viewmodel.LastName   = model.User.LastName;
            viewmodel.Nickname   = model.User.Nickname;
            viewmodel.Image      = "http://lan-netconnect.de/_api/images/team/no_image.png"; // TODO
            viewmodel.Email      = model.User.Email;
            viewmodel.SteamID    = model.User.SteamID;
            viewmodel.BattleTag  = model.User.BattleTag;
            viewmodel.Newsletter = model.User.Newsletter;
            viewmodel.IsAdmin    = model.User.IsAdmin;
            viewmodel.IsTeam     = model.User.IsTeam;

            return(viewmodel);
        }
Beispiel #19
0
 public static bool IsPlayerTroop(this TournamentParticipant participant)
 {
     return(!participant.Character.IsHero || participant.Character.HeroObject == Hero.MainHero);
 }
Beispiel #20
0
        private TournamentVerificationStatus Verify(TournamentParticipant e, string expectedLevel)
        {
            if (!File.Exists(e.PathToExe))
            {
                return(TournamentVerificationStatus.FileNotFound);
            }

            if (listener.Pending())
            {
                throw new VerificationException("Something is wrong: pending clients before client starts. Possible interference");
            }

            var process = new Process();

            process.StartInfo.FileName        = e.PathToExe;
            process.StartInfo.Arguments       = "127.0.0.1 " + verifyPort;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.CreateNoWindow  = true;
            process.Start();

            var watch = new Stopwatch();

            watch.Start();
            var result = TournamentVerificationStatus.OK;

            while (true)
            {
                if (listener.Pending())
                {
                    var client = listener.AcceptTcpClient();
                    try
                    {
                        var settings = client.ReadJson <GameSettings>();
                        Console.WriteLine(settings.LoadingData.Level);
                        var state = client.ReadJson <JObject>();
                    }
                    catch
                    {
                        result = TournamentVerificationStatus.WrongFormat;
                    }
                    break;
                }
                else if (watch.ElapsedMilliseconds > 1000)
                {
                    result = TournamentVerificationStatus.ConnectionFailed;
                    break;
                }
            }
            Thread.Sleep(500);
            while (listener.Pending())
            {
                var client = listener.AcceptTcpClient();
                var trash  = client.ReadJson <JObject>();
                if (result != TournamentVerificationStatus.ConnectionFailed)
                {
                    result = TournamentVerificationStatus.SecondConnectionDetected;
                }
            }

            process.Kill();
            return(result);
        }