Ejemplo n.º 1
0
 public void initTeam(LiteDatabase db, Tournament tourn, Team t, Player p)
 {
     registerTeamToTournament(db, t);
     registerTournamentTeamPlayer(db, tourn, t, p);
 }
Ejemplo n.º 2
0
        public void getTournamentBracket(MySqlConnection conn, ref Tournament tourney, long tourn_id)
        {
            string q = string.Format("SELECT * FROM matchups WHERE tournament_id = '{0}' ORDER BY ID DESC", tourn_id);

            MySqlDataReader rdr = ExecuteQuery(conn, q);

            //Populate Rounds
            tourney.CreateBracket();

            while (rdr.Read())
            {
                long _uid    = rdr.GetInt64(rdr.GetOrdinal("ID"));
                int  ordinal = rdr.GetOrdinal("team1_id");

                ordinal = rdr.GetOrdinal("team1_id");
                long _team1_id = rdr.IsDBNull(ordinal) ? 0 : rdr.GetInt64(ordinal);
                ordinal = rdr.GetOrdinal("team2_id");
                long _team2_id          = rdr.IsDBNull(ordinal) ? 0 : rdr.GetInt64(ordinal);
                bool status_in_progress = rdr.GetBoolean(rdr.GetOrdinal("status_in_progress"));
                ordinal = rdr.GetOrdinal("next_matchup_id");
                long _next_matchup_id = rdr.IsDBNull(ordinal) ? 0 : rdr.GetInt64(ordinal);
                ordinal = rdr.GetOrdinal("winner_id");
                ulong _winner_id = rdr.IsDBNull(ordinal) ? 0 : rdr.GetUInt64(ordinal);
                int   _round_Id  = rdr.GetInt32(rdr.GetOrdinal("round_id"));
                ordinal = rdr.GetOrdinal("team1_reported_winner_id");
                ulong _team1_reported_winner_id = rdr.IsDBNull(ordinal) ? 0 : rdr.GetUInt64(ordinal);
                ordinal = rdr.GetOrdinal("team2_reported_winner_id");
                ulong  _team2_reported_winner_id = rdr.IsDBNull(ordinal) ? 0 : rdr.GetUInt64(ordinal);
                string lobby_name = rdr.GetString(rdr.GetOrdinal("lobby_name"));
                string lobby_pass = rdr.GetString(rdr.GetOrdinal("lobby_pass"));

                Matchup m = new Matchup();
                m.UID       = _uid;
                m.RoundID   = _round_Id;
                m.LobbyName = lobby_name;
                m.LobbyPass = lobby_pass;

                if (_team1_id > 0)
                {
                    m.Team1 = tourney.getTeamByUID(_team1_id);
                }
                else
                {
                    m.Team1 = null;
                }
                if (_team2_id > 0)
                {
                    m.Team2 = tourney.getTeamByUID(_team2_id);
                }
                else
                {
                    m.Team2 = null;
                }

                //Reported Winners
                if (_team1_reported_winner_id > 0)
                {
                    m.Team1ReportedWinner = tourney.getTeamByUID(_team1_id);
                }
                else
                {
                    m.Team1ReportedWinner = null;
                }
                if (_team2_reported_winner_id > 0)
                {
                    m.Team2ReportedWinner = tourney.getTeamByUID(_team2_id);
                }
                else
                {
                    m.Team2ReportedWinner = null;
                }

                if (_winner_id > 0)
                {
                    m.Winner = tourney.getTeamByUID(_team2_id);
                }
                else
                {
                    m.Winner = null;
                }

                if (_next_matchup_id > 0)
                {
                    m.Next = tourney.getmatchupByUID(_next_matchup_id);
                }

                m.InProgress = status_in_progress; //Winner setting can mess up stuff
                tourney.bracket.Rounds[_round_Id].Matchups.Add(m);
            }
            rdr.Close();
        }
Ejemplo n.º 3
0
        //Bracket
        public void registerBracket(MySqlConnection conn, Tournament t, ulong tourn_id)
        {
            setTournamentBracketGeneratedStatus(conn, tourn_id, true);
            setTournamentRoundNumber(conn, tourn_id, t.bracket.Rounds.Count);

            for (int i = t.bracket.Rounds.Count - 1; i >= 0; i--)
            {
                Round r = t.bracket.Rounds[i];
                for (int j = 0; j < r.Matchups.Count; j++)
                {
                    Matchup m = r.Matchups[j];
                    //Register Matchup to DB
                    string q   = "INSERT INTO matchups (tournament_id, team1_id, team2_id, next_matchup_id, round_id, team1_reported_winner_id, team2_reported_winner_id) VALUES (@tournament_id, @team1_id, @team2_id, @next_matchup_id, @round_id, @team1_reported_winner_id, @team2_reported_winner_id)";
                    var    cmd = GenerateCommand(conn, q);
                    cmd.Parameters.AddWithValue("@tournament_id", tourn_id);
                    cmd.Parameters.AddWithValue("@round_id", i);

                    //Team1
                    if (m.Team1 != null)
                    {
                        if (m.Team1.IsDummy)
                        {
                            cmd.Parameters.AddWithValue("@team1_id", DBNull.Value);
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@team1_id", m.Team1.UID);
                        }
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("@team1_id", DBNull.Value);
                    }

                    //Team2
                    if (m.Team2 != null)
                    {
                        if (m.Team2.IsDummy)
                        {
                            cmd.Parameters.AddWithValue("@team2_id", DBNull.Value);
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@team2_id", m.Team2.UID);
                        }
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("@team2_id", DBNull.Value);
                    }


                    //Team1 reported winner
                    if (m.Team1ReportedWinner != null)
                    {
                        if (m.Team1ReportedWinner.IsDummy)
                        {
                            cmd.Parameters.AddWithValue("@team1_reported_winner_id", DBNull.Value);
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@team1_reported_winner_id", m.Team1ReportedWinner.UID);
                        }
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("@team1_reported_winner_id", DBNull.Value);
                    }

                    //Team2 reported winner
                    if (m.Team2ReportedWinner != null)
                    {
                        if (m.Team2ReportedWinner.IsDummy)
                        {
                            cmd.Parameters.AddWithValue("@team2_reported_winner_id", DBNull.Value);
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@team2_reported_winner_id", m.Team2ReportedWinner.UID);
                        }
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("@team2_reported_winner_id", DBNull.Value);
                    }

                    //Next Match
                    if (m.Next != null)
                    {
                        cmd.Parameters.AddWithValue("@next_matchup_id", m.Next.UID);
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("@next_matchup_id", DBNull.Value);
                    }

                    MySqlDataReader rdr         = cmd.ExecuteReader();
                    long            matchup_uid = cmd.LastInsertedId;
                    m.UID = matchup_uid;
                    rdr?.Close();
                }
            }
        }
Ejemplo n.º 4
0
        public void ApplySingleMatchupUpdate(MySqlConnection conn, Matchup m, ref Tournament t)
        {
            //Update Matchup to DB
            string q   = "UPDATE matchups SET status_in_progress = @status_in_progress, team1_id=@team1_id, team2_id=@team2_id, winner_id=@winner_id, team1_reported_winner_id=@team1_reported_winner_id, team2_reported_winner_id=@team2_reported_winner_id, lobby_name=@lobby_name, lobby_pass=@lobby_pass WHERE tournament_id = @tournament_id AND ID = @uid";
            var    cmd = GenerateCommand(conn, q);

            cmd.Parameters.AddWithValue("@tournament_id", t.info.UID);
            cmd.Parameters.AddWithValue("@uid", m.UID);
            cmd.Parameters.AddWithValue("@status_in_progress", m.InProgress);
            cmd.Parameters.AddWithValue("@lobby_name", m.LobbyName);
            cmd.Parameters.AddWithValue("@lobby_pass", m.LobbyPass);

            //Team1
            if (m.Team1 != null)
            {
                if (m.Team1.IsDummy)
                {
                    cmd.Parameters.AddWithValue("@team1_id", DBNull.Value);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@team1_id", m.Team1.UID);
                }
            }
            else
            {
                cmd.Parameters.AddWithValue("@team1_id", DBNull.Value);
            }

            //Team2
            if (m.Team2 != null)
            {
                if (m.Team2.IsDummy)
                {
                    cmd.Parameters.AddWithValue("@team2_id", DBNull.Value);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@team2_id", m.Team2.UID);
                }
            }
            else
            {
                cmd.Parameters.AddWithValue("@team2_id", DBNull.Value);
            }

            //Team1 reported winner
            if (m.Team1ReportedWinner != null)
            {
                if (m.Team1ReportedWinner.IsDummy)
                {
                    cmd.Parameters.AddWithValue("@team1_reported_winner_id", DBNull.Value);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@team1_reported_winner_id", m.Team1ReportedWinner.UID);
                }
            }
            else
            {
                cmd.Parameters.AddWithValue("@team1_reported_winner_id", DBNull.Value);
            }

            //Team2 reported winner
            if (m.Team2ReportedWinner != null)
            {
                if (m.Team2ReportedWinner.IsDummy)
                {
                    cmd.Parameters.AddWithValue("@team2_reported_winner_id", DBNull.Value);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@team2_reported_winner_id", m.Team2ReportedWinner.UID);
                }
            }
            else
            {
                cmd.Parameters.AddWithValue("@team2_reported_winner_id", DBNull.Value);
            }

            //Winner
            if (m.Winner != null)
            {
                if (m.Team2.IsDummy)
                {
                    cmd.Parameters.AddWithValue("@winner_id", DBNull.Value);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@winner_id", m.Winner.UID);
                }
            }
            else
            {
                cmd.Parameters.AddWithValue("@winner_id", DBNull.Value);
            }

            //Next Match
            if (m.Next != null)
            {
                cmd.Parameters.AddWithValue("@next_matchup_id", m.Next.UID);
            }
            else
            {
                cmd.Parameters.AddWithValue("@next_matchup_id", DBNull.Value);
            }

            //Lobby Info

            MySqlDataReader rdr = cmd.ExecuteReader();

            rdr?.Close();
        }