diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-09-24 12:20:01 +0200 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-09-24 12:20:01 +0200 |
commit | 99961ccd710e5300de5fb749aa10619632ac96e9 (patch) | |
tree | 301bea3c2becdbe50b95959a2b28f09f3ff6c31e /src | |
parent | 30d46afbaeb1539d250938f375553d8c496b06cf (diff) | |
download | cmumble-99961ccd710e5300de5fb749aa10619632ac96e9.tar.gz cmumble-99961ccd710e5300de5fb749aa10619632ac96e9.tar.bz2 cmumble-99961ccd710e5300de5fb749aa10619632ac96e9.zip |
Add lc (list channels) command
Diffstat (limited to 'src')
-rw-r--r-- | src/cmumble.c | 43 | ||||
-rw-r--r-- | src/cmumble.h | 11 | ||||
-rw-r--r-- | src/commands.c | 14 |
3 files changed, 66 insertions, 2 deletions
diff --git a/src/cmumble.c b/src/cmumble.c index f815456..cc2d22d 100644 --- a/src/cmumble.c +++ b/src/cmumble.c @@ -22,6 +22,21 @@ find_user(struct cmumble_context *ctx, uint32_t session) return user; } +static struct cmumble_channel * +find_channel(struct cmumble_context *ctx, uint32_t id) +{ + struct cmumble_channel *channel = NULL; + GList *l; + + for (l = ctx->channels; l; l = l->next) + if (((struct cmumble_channel *) l->data)->id == id) { + channel = l->data; + break; + } + + return channel; +} + static void recv_udp_tunnel(MumbleProto__UDPTunnel *tunnel, struct cmumble_context *ctx) { @@ -68,8 +83,32 @@ recv_version(MumbleProto__Version *version, struct cmumble_context *ctx) static void recv_channel_state(MumbleProto__ChannelState *state, struct cmumble_context *ctx) { - g_print("channel: id: %u, parent: %u, name: %s, description: %s, temporary: %d, position: %d\n", - state->channel_id, state->parent, state->name, state->description, state->temporary, state->position); + struct cmumble_channel *channel; + + channel = find_channel(ctx, state->channel_id); + if (channel == NULL) { + channel = g_slice_new0(struct cmumble_channel); + if (channel == NULL) { + g_printerr("Out of memory.\n"); + exit(1); + } + ctx->channels = g_list_prepend(ctx->channels, channel); + + if (channel->name) + g_free(channel->name); + if (channel->description) + g_free(channel->description); + } + + channel->id = state->channel_id; + if (state->name) + channel->name = g_strdup(state->name); + channel->parent = state->parent; + if (state->description) + channel->description = g_strdup(state->description); + + channel->temporary = state->temporary; + channel->position = state->position; } static void diff --git a/src/cmumble.h b/src/cmumble.h index ad0ab33..9078bb8 100644 --- a/src/cmumble.h +++ b/src/cmumble.h @@ -31,6 +31,7 @@ struct cmumble_context { int64_t sequence; GList *users; + GList *channels; }; struct cmumble_user { @@ -42,6 +43,16 @@ struct cmumble_user { GstAppSrc *src; }; +struct cmumble_channel { + uint32_t id; + uint32_t parent; + char *name; + char *description; + + gboolean temporary; + int32_t position; +}; + enum udp_message_type { udp_voice_celt_alpha, udp_ping, diff --git a/src/commands.c b/src/commands.c index e8ad9d6..0e24f70 100644 --- a/src/commands.c +++ b/src/commands.c @@ -21,6 +21,19 @@ list_users(struct cmumble_context *ctx) } static void +list_channels(struct cmumble_context *ctx) +{ + struct cmumble_channel *channel = NULL; + GList *l; + + for (l = ctx->channels; l; l = l->next) { + channel = l->data; + + g_print("%4d: %s\n", channel->id, channel->name); + } +} + +static void quit(struct cmumble_context *ctx) { rl_already_prompted = 1; @@ -47,6 +60,7 @@ help(struct cmumble_context *ctx) static const struct cmumble_command commands[] = { { "lu", list_users, "list users" }, + { "lc", list_channels, "list channels" }, { "clear", clear, "clear screen" }, { "help", help, "show this help" }, { "quit", quit, "quit " PACKAGE }, |