From d42e98caaaf4f07c8d1252236f03eb68b8be4619 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sat, 13 Dec 2008 15:48:31 +0000 Subject: [PATCH 1/1] Add 'adopt' command. This adopts a randomly picked track by changing its origin to 'adopted' and its submitter to the calling user. The nice UIs don't support this yet but you can access it from the command line. Organization: Straylight/Edgeware From: Richard Kettlewell Document 'origin' and update 'state' in disorder_protocol(5). --- clients/disorder.c | 7 +++++++ doc/disorder_protocol.5.in | 39 ++++++++++++++++++++++++++++++++------ lib/client.c | 9 +++++++++ lib/client.h | 1 + lib/eclient.c | 14 ++++++++++++++ lib/eclient.h | 5 ++++- lib/queue.h | 3 +-- python/disorder.py.in | 4 ++++ server/server.c | 26 +++++++++++++++++++++++++ 9 files changed, 99 insertions(+), 9 deletions(-) diff --git a/clients/disorder.c b/clients/disorder.c index 4afc568..8dc6d7f 100644 --- a/clients/disorder.c +++ b/clients/disorder.c @@ -577,6 +577,11 @@ static void cf_schedule_unset_global(char **argv) { exit(EXIT_FAILURE); } +static void cf_adopt(char **argv) { + if(disorder_adopt(getclient(), argv[0])) + exit(EXIT_FAILURE); +} + static const struct command { const char *name; int min, max; @@ -586,6 +591,8 @@ static const struct command { } commands[] = { { "adduser", 2, 3, cf_adduser, isarg_rights, "USERNAME PASSWORD [RIGHTS]", "Create a new user" }, + { "adopt", 1, 1, cf_adopt, 0, "ID", + "Adopt a randomly picked track" }, { "allfiles", 1, 2, cf_allfiles, isarg_regexp, "DIR [~REGEXP]", "List all files and directories in DIR" }, { "authorize", 1, 2, cf_authorize, isarg_rights, "USERNAME [RIGHTS]", diff --git a/doc/disorder_protocol.5.in b/doc/disorder_protocol.5.in index a35e7f7..ba37e67 100644 --- a/doc/disorder_protocol.5.in +++ b/doc/disorder_protocol.5.in @@ -57,6 +57,10 @@ then the \fBdefault_rights\fR setting applies instead. Requires the \fBadmin\fR right, and only works on local connections. .TP +.B adopt \fIID\fR +Adopts a randomly picked track, leaving it in a similar state to if it was +picked by this user. Requires the \fBplay\fR right. +.TP .B allfiles \fIDIRECTORY\fR [\fIREGEXP\fR] List all the files and directories in \fIDIRECTORY\fR in a response body. If \fIREGEXP\fR is present only matching files and directories are returned. @@ -495,6 +499,26 @@ The time the track was played at. .B scratched The user that scratched the track. .TP +.B origin +The origin of the track. Valid origins are: +.RS +.TP 12 +.B adopted +The track was originally randomly picked but has been adopted by a user. +.TP +.B picked +The track was picked by a user. +.TP +.B random +The track was randomly picked. +.TP +.B scheduled +The track was played from a scheduled action. +.TP +.B scratch +The track is a scratch sound. +.RE +.TP .B state The current track state. Valid states are: @@ -503,12 +527,6 @@ Valid states are: .B failed The player failed (exited with nonzero status but wasn't scratched). .TP -.B isscratch -The track is actually a scratch. -.TP -.B no_player -No player could be found for the track. -.TP .B ok The track was played without any problems. .TP @@ -518,6 +536,9 @@ The track was scratched. .B started The track is currently playing. .TP +.B paused +Track is playing but paused. +.TP .B unplayed In the queue, hasn't been played yet. .TP @@ -536,6 +557,9 @@ The time the track was added to the queue. .TP .B wstat The wait status of the player in decimal. +.PP +Note that \fBorigin\fR is new with DisOrder 4.3, and obsoletes some old +\fBstate\fR values. .SH NOTES Times are decimal integers using the server's \fBtime_t\fR. .PP @@ -553,6 +577,9 @@ keyword followed by (optionally) parameters. The parameters are quoted in the usual DisOrder way. Currently the following keywords are used: .TP +.B adopted \fIID\fR \fIUSERNAME\fR +\fIUSERNAME\fR adopted track \fIID\fR. +.TP .B completed \fITRACK\fR Completed playing \fITRACK\fR .TP diff --git a/lib/client.c b/lib/client.c index 9a676c9..00d7cf5 100644 --- a/lib/client.c +++ b/lib/client.c @@ -1302,6 +1302,15 @@ int disorder_schedule_add(disorder_client *c, return rc; } +/** @brief Adopt a track + * @param c Client + * @param id Track ID to adopt + * @return 0 on success, non-0 on error + */ +int disorder_adopt(disorder_client *c, const char *id) { + return disorder_simple(c, 0, "adopt", id, (char *)0); +} + /* Local Variables: c-basic-offset:2 diff --git a/lib/client.h b/lib/client.h index 746daed..89f3037 100644 --- a/lib/client.h +++ b/lib/client.h @@ -131,6 +131,7 @@ int disorder_schedule_add(disorder_client *c, const char *priority, const char *action, ...); +int disorder_adopt(disorder_client *c, const char *id); #endif /* CLIENT_H */ diff --git a/lib/eclient.c b/lib/eclient.c index 19d8d7c..b7b502b 100644 --- a/lib/eclient.c +++ b/lib/eclient.c @@ -1404,6 +1404,20 @@ int disorder_eclient_adduser(disorder_eclient *c, "adduser", user, password, rights, (char *)0); } +/** @brief Adopt a track + * @param c Client + * @param completed Called on completion + * @param id Track ID + * @param v Passed to @p completed + */ +int disorder_eclient_adopt(disorder_eclient *c, + disorder_eclient_no_response *completed, + const char *id, + void *v) { + return simple(c, no_response_opcallback, (void (*)())completed, v, + "adopt", id, (char *)0); +} + /* Log clients ***************************************************************/ /** @brief Monitor the server log diff --git a/lib/eclient.h b/lib/eclient.h index 6578a75..359a71b 100644 --- a/lib/eclient.h +++ b/lib/eclient.h @@ -483,7 +483,10 @@ int disorder_eclient_adduser(disorder_eclient *c, void *v); void disorder_eclient_enable_connect(disorder_eclient *c); void disorder_eclient_disable_connect(disorder_eclient *c); - +int disorder_eclient_adopt(disorder_eclient *c, + disorder_eclient_no_response *completed, + const char *id, + void *v); #endif /* diff --git a/lib/queue.h b/lib/queue.h index 17a6d22..1c70cfd 100644 --- a/lib/queue.h +++ b/lib/queue.h @@ -94,8 +94,7 @@ extern const char *const playing_states[]; enum track_origin { /** @brief Track was picked at random and then adopted by a user * - * @c submitter identifies who adopted it. This isn't implemented - * yet. + * @c submitter identifies who adopted it. */ origin_adopted, diff --git a/python/disorder.py.in b/python/disorder.py.in index e99f18b..e873e49 100644 --- a/python/disorder.py.in +++ b/python/disorder.py.in @@ -905,6 +905,10 @@ class client: """Add a scheduled event""" self._simple("schedule-add", str(when), priority, action, *rest) + def adopt(self, id): + """Adopt a randomly picked track""" + self._simple("adopt", id) + ######################################################################## # I/O infrastructure diff --git a/server/server.c b/server/server.c index 0b2458d..18f6851 100644 --- a/server/server.c +++ b/server/server.c @@ -1573,6 +1573,31 @@ static int c_schedule_add(struct conn *c, return 1; } +static int c_adopt(struct conn *c, + char **vec, + int attribute((unused)) nvec) { + struct queue_entry *q; + + if(!c->who) { + sink_writes(ev_writer_sink(c->w), "550 no identity\n"); + return 1; + } + if(!(q = queue_find(vec[0]))) { + sink_writes(ev_writer_sink(c->w), "550 no such track on the queue\n"); + return 1; + } + if(q->origin != origin_random) { + sink_writes(ev_writer_sink(c->w), "550 not a random track\n"); + return 1; + } + q->origin = origin_adopted; + q->submitter = xstrdup(c->who); + eventlog("adopted", q->id, q->submitter, (char *)0); + queue_write(); + sink_writes(ev_writer_sink(c->w), "250 OK\n"); + return 1; +} + static const struct command { /** @brief Command name */ const char *name; @@ -1594,6 +1619,7 @@ static const struct command { rights_type rights; } commands[] = { { "adduser", 2, 3, c_adduser, RIGHT_ADMIN|RIGHT__LOCAL }, + { "adopt", 1, 1, c_adopt, RIGHT_PLAY }, { "allfiles", 0, 2, c_allfiles, RIGHT_READ }, { "confirm", 1, 1, c_confirm, 0 }, { "cookie", 1, 1, c_cookie, 0 }, -- [mdw]