Exemplo n.º 1
0
        public bool GetPlayerArenaData(SQLPlayerData _PlayerData, out PlayerData.ArenaData _ResultArenaData)
        {
            SQLArenaInfo arenaInfo;

            if (GetPlayerArenaInfo(_PlayerData, out arenaInfo) == true)
            {
                return(GetPlayerArenaData(arenaInfo, out _ResultArenaData));
            }
            _ResultArenaData = null;
            return(false);
        }
Exemplo n.º 2
0
        public int GenerateNewPlayerArenaInfoEntry(PlayerData.ArenaData _ArenaData)
        {
            if (_ArenaData == null || (_ArenaData.Team2v2 == null && _ArenaData.Team3v3 == null && _ArenaData.Team5v5 == null))
            {
                return(0);
            }

            var conn = OpenConnection();

            try
            {
                Func <PlayerData.ArenaPlayerData, int> _GenerateNewPlayerArenaTeamDataEntry = (PlayerData.ArenaPlayerData _Data) =>
                {
                    if (_Data == null)
                    {
                        return(0);
                    }

                    using (var cmd = new NpgsqlCommand("INSERT INTO playerarenadatatable(id, teamname, teamrating, gamesplayed, gameswon, playergamesplayed, playerrating) VALUES (DEFAULT, :TeamName, :TeamRating, :GamesPlayed, :GamesWon, :PlayerGamesPlayed, :PlayerRating) RETURNING id", conn))
                    {
                        cmd.Parameters.Add(new NpgsqlParameter("TeamName", NpgsqlDbType.Text)).Value             = _Data.TeamName;
                        cmd.Parameters.Add(new NpgsqlParameter("TeamRating", NpgsqlDbType.Integer)).Value        = _Data.TeamRating;
                        cmd.Parameters.Add(new NpgsqlParameter("GamesPlayed", NpgsqlDbType.Integer)).Value       = _Data.GamesPlayed;
                        cmd.Parameters.Add(new NpgsqlParameter("GamesWon", NpgsqlDbType.Integer)).Value          = _Data.GamesWon;
                        cmd.Parameters.Add(new NpgsqlParameter("PlayerGamesPlayed", NpgsqlDbType.Integer)).Value = _Data.PlayerPlayed;
                        cmd.Parameters.Add(new NpgsqlParameter("PlayerRating", NpgsqlDbType.Integer)).Value      = _Data.PlayerRating;

                        using (var reader = cmd.ExecuteReader())
                        {
                            if (reader.Read() == true)
                            {
                                return(reader.GetInt32(0));
                            }
                        }
                    }

                    return(0);
                };

                int team_2v2_ID = _GenerateNewPlayerArenaTeamDataEntry(_ArenaData.Team2v2);
                int team_3v3_ID = _GenerateNewPlayerArenaTeamDataEntry(_ArenaData.Team3v3);
                int team_5v5_ID = _GenerateNewPlayerArenaTeamDataEntry(_ArenaData.Team5v5);

                using (var cmd = new NpgsqlCommand("INSERT INTO playerarenainfotable(id, team_2v2, team_3v3, team_5v5) VALUES (DEFAULT, :Team2v2, :Team3v3, :Team5v5) RETURNING id", conn))
                {
                    cmd.Parameters.Add(new NpgsqlParameter("Team2v2", NpgsqlDbType.Integer)).Value = (int)team_2v2_ID;
                    cmd.Parameters.Add(new NpgsqlParameter("Team3v3", NpgsqlDbType.Integer)).Value = (int)team_3v3_ID;
                    cmd.Parameters.Add(new NpgsqlParameter("Team5v5", NpgsqlDbType.Integer)).Value = (int)team_5v5_ID;

                    using (var reader = cmd.ExecuteReader())
                    {
                        if (reader.Read() == true)
                        {
                            return(reader.GetInt32(0));
                        }
                    }
                }
            }
            finally
            {
                CloseConnection();
            }
            return(0);
        }
Exemplo n.º 3
0
        public bool GetPlayerArenaData(SQLArenaInfo _ArenaInfo, out PlayerData.ArenaData _ResultArenaData)
        {
            _ResultArenaData = null;
            if (_ArenaInfo.IsNull() == true)
            {
                return(false);
            }

            int[] teamIDs        = new int[3];
            int   teamIDsCounter = 0;

            if (_ArenaInfo.Team2v2 != 0)
            {
                teamIDs[teamIDsCounter++] = _ArenaInfo.Team2v2;
            }
            if (_ArenaInfo.Team3v3 != 0)
            {
                teamIDs[teamIDsCounter++] = _ArenaInfo.Team3v3;
            }
            if (_ArenaInfo.Team5v5 != 0)
            {
                teamIDs[teamIDsCounter++] = _ArenaInfo.Team5v5;
            }
            if (teamIDs.Length > teamIDsCounter)
            {
                int[] oldTeamIDs = teamIDs;
                teamIDs = new int[teamIDsCounter];
                for (int i = 0; i < teamIDsCounter; ++i)
                {
                    teamIDs[i] = oldTeamIDs[i];
                }
            }

            var conn = OpenConnection();

            try
            {
                const int ID_COLUMN                = 0;
                const int TEAMNAME_COLUMN          = 1;
                const int TEAMRATING_COLUMN        = 2;
                const int GAMESPLAYED_COLUMN       = 3;
                const int GAMESWON_COLUMN          = 4;
                const int PLAYERGAMESPLAYED_COLUMN = 5;
                const int PLAYERRATING_COLUMN      = 6;

                using (var cmd = new NpgsqlCommand("SELECT id, teamname, teamrating, gamesplayed, gameswon, playergamesplayed, playerrating FROM PlayerArenaDataTable WHERE id = ANY(:IDs)", conn))
                {
                    {
                        var idsParam = new NpgsqlParameter("IDs", NpgsqlDbType.Array | NpgsqlDbType.Integer);
                        idsParam.Value = teamIDs;
                        cmd.Parameters.Add(idsParam);
                    }
                    using (var reader = cmd.ExecuteReader())
                    {
                        if (reader.HasRows == true)
                        {
                            _ResultArenaData = new PlayerData.ArenaData();
                            while (reader.Read() == true)
                            {
                                var arenaTeamData = new PlayerData.ArenaPlayerData();
                                int id            = reader.GetInt32(ID_COLUMN);

                                arenaTeamData.TeamName     = reader.GetString(TEAMNAME_COLUMN);
                                arenaTeamData.TeamRating   = reader.GetInt32(TEAMRATING_COLUMN);
                                arenaTeamData.GamesPlayed  = reader.GetInt32(GAMESPLAYED_COLUMN);
                                arenaTeamData.GamesWon     = reader.GetInt32(GAMESWON_COLUMN);
                                arenaTeamData.PlayerPlayed = reader.GetInt32(PLAYERGAMESPLAYED_COLUMN);
                                arenaTeamData.PlayerRating = reader.GetInt32(PLAYERRATING_COLUMN);

                                if (id == _ArenaInfo.Team2v2)
                                {
                                    _ResultArenaData.Team2v2 = arenaTeamData;
                                }
                                if (id == _ArenaInfo.Team3v3)
                                {
                                    _ResultArenaData.Team3v3 = arenaTeamData;
                                }
                                if (id == _ArenaInfo.Team5v5)
                                {
                                    _ResultArenaData.Team5v5 = arenaTeamData;
                                }
                            }
                            return(true);
                        }
                    }
                }
            }
            finally
            {
                CloseConnection();
            }
            return(false);
        }
Exemplo n.º 4
0
 public ArenaDataHistoryItem(ArenaData _Arena, UploadID _Uploader)
 {
     Data     = _Arena;
     Uploader = _Uploader;
 }