X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/cebe31278d4990696382196884fa42d897b15a3f..36a1a882e0852f29a63b4e7cfad5e465dfa14fde:/server/choose.c diff --git a/server/choose.c b/server/choose.c index 6de1b45..06c9601 100644 --- a/server/choose.c +++ b/server/choose.c @@ -173,6 +173,16 @@ static unsigned long compute_weight(const char *track, if(*required_tags && !tag_intersection(track_tags, required_tags)) return 0; + /* Use the configured weight if available */ + if((s = kvp_get(prefs, "weight"))) { + long n; + errno = 0; + + n = strtol(s, 0, 10); + if((errno == 0 || errno == ERANGE) && n >= 0) + return n; + } + return 90000; } @@ -182,11 +192,15 @@ static int collect_tracks_callback(const char *track, struct kvp *prefs, void attribute((unused)) *u, DB_TXN attribute((unused)) *tid) { - const unsigned long weight = compute_weight(track, data, prefs); + unsigned long weight = compute_weight(track, data, prefs); if(weight) { struct weighted_track *const t = xmalloc(sizeof *t); + /* Clamp weight so that we can fit in billions of tracks when we do + * arithmetic in long long */ + if(weight > 0x7fffffff) + weight = 0x7fffffff; t->next = tracks; t->track = track; t->weight = weight;