コード例 #1
0
        public SQLPlayerID GenerateNewPlayerEntry(SQLUploadID _UploadID, PlayerData.Player _PlayerData)
        {
            WowVersionEnum wowVersion = VF_RealmPlayersDatabase.StaticValues.GetWowVersion(_PlayerData.Realm);
            SQLPlayerID    playerID   = new SQLPlayerID();
            var            conn       = OpenConnection();

            try
            {
                using (var cmd = new NpgsqlCommand("INSERT INTO playertable(id, name, realm, latestuploadid) VALUES (DEFAULT, :Name, :Realm, :LatestUploadID) RETURNING id", conn))
                {
                    cmd.Parameters.Add(new NpgsqlParameter("Name", NpgsqlDbType.Text)).Value              = _PlayerData.Name;
                    cmd.Parameters.Add(new NpgsqlParameter("Realm", NpgsqlDbType.Integer)).Value          = (int)_PlayerData.Realm;
                    cmd.Parameters.Add(new NpgsqlParameter("LatestUploadID", NpgsqlDbType.Integer)).Value = (int)0;
                    using (var reader = cmd.ExecuteReader())
                    {
                        if (reader.Read() == true)
                        {
                            playerID = new SQLPlayerID(reader.GetInt32(0));
                        }
                    }
                }
            }
            finally
            {
                CloseConnection();
            }

            if (playerID.IsValid() == false)
            {
                return(playerID);
            }

            return(UpdateLatestPlayerDataEntry(playerID, _UploadID, _PlayerData));
        }
コード例 #2
0
        public bool UpdatePlayerEntry(SQLPlayerID _PlayerID, SQLUploadID _UploadID)
        {
            if (_PlayerID.IsValid() == false || _UploadID.IsValid() == false)
            {
                return(false);
            }

            int affectedRows = 0;
            var conn         = OpenConnection();

            try
            {
                using (var cmd = new NpgsqlCommand("UPDATE playertable SET latestuploadid = :LatestUploadID WHERE id = :ID", conn))
                {
                    cmd.Parameters.Add(new NpgsqlParameter("ID", NpgsqlDbType.Integer)).Value             = (int)_PlayerID;
                    cmd.Parameters.Add(new NpgsqlParameter("LatestUploadID", NpgsqlDbType.Integer)).Value = (int)_UploadID;
                    affectedRows = cmd.ExecuteNonQuery();
                }
            }
            finally
            {
                CloseConnection();
            }

            if (affectedRows == 1)
            {
                return(true);
            }

            if (affectedRows > 1)
            {
                VF_RealmPlayersDatabase.Logger.ConsoleWriteLine("Error, UpdatePlayerEntry somehow modified more than 1 line. This is pretty weird and unexpected!!!");
            }
            return(false);
        }
コード例 #3
0
        public SQLPlayerID UpdateLatestPlayerDataEntry(SQLPlayerID _PlayerID, SQLUploadID _UploadID, PlayerData.Player _PlayerData)
        {
            WowVersionEnum wowVersion = VF_RealmPlayersDatabase.StaticValues.GetWowVersion(_PlayerData.Realm);
            SQLPlayerData  playerData = new SQLPlayerData();

            playerData.PlayerID        = _PlayerID;
            playerData.UploadID        = _UploadID;
            playerData.UpdateTime      = _PlayerData.LastSeen;
            playerData.PlayerCharacter = _PlayerData.Character;
            playerData.PlayerGuildID   = GenerateNewPlayerGuildDataEntry(_PlayerData.Guild);
            playerData.PlayerHonorID   = GenerateNewPlayerHonorDataEntry(_PlayerData.Honor, wowVersion);
            playerData.PlayerGearID    = GenerateNewPlayerGearDataEntry(_PlayerData.Gear, wowVersion);
            if (wowVersion != WowVersionEnum.Vanilla)
            {
                playerData.PlayerArenaID   = GenerateNewPlayerArenaInfoEntry(_PlayerData.Arena);
                playerData.PlayerTalentsID = GenerateNewPlayerTalentsDataEntry(_PlayerData.TalentPointsData);
            }
            else
            {
                playerData.PlayerArenaID   = 0;
                playerData.PlayerTalentsID = 0;
            }
            if (GenerateNewPlayerDataEntry(playerData) == true)
            {
                if (UpdatePlayerEntry(playerData.PlayerID, playerData.UploadID) == false)
                {
                    VF_RealmPlayersDatabase.Logger.ConsoleWriteLine("Error in UpdateLatestPlayerDataEntry, could not UpdatePlayerEntry!!!");
                    return(SQLPlayerID.Invalid());
                }
            }
            else
            {
                VF_RealmPlayersDatabase.Logger.ConsoleWriteLine("Error in UpdateLatestPlayerDataEntry, could not GenerateNewPlayerDataEntry!!!");
                return(SQLPlayerID.Invalid());
            }
            return(_PlayerID);
        }