+ case ChannelState:
+ {
+ channel_t *ch_itr, *parent, *newchan;
+ int leave_id;
+ /* Don't allow any changes to existing channels */
+ if (msg->payload.channelState->has_channel_id) {
+ sendPermissionDenied(client, "Not supported by uMurmur");
+ break;
+ }
+ /* Must have parent */
+ if (!msg->payload.channelState->has_parent) {
+ sendPermissionDenied(client, "Not supported by uMurmur");
+ break;
+ }
+ /* Must have name */
+ if (msg->payload.channelState->name == NULL) {
+ sendPermissionDenied(client, "Not supported by uMurmur");
+ break;
+ }
+ /* Must be temporary channel */
+ if (msg->payload.channelState->temporary != true) {
+ sendPermissionDenied(client, "Only temporary channels are supported by uMurmur");
+ break;
+ }
+ /* Check channel name is OK */
+ if (strlen(msg->payload.channelState->name) > MAX_TEXT) {
+ sendPermissionDenied(client, "Channel name too long");
+ break;
+ }
+
+ parent = Chan_fromId(msg->payload.channelState->parent);
+ if (parent == NULL)
+ break;
+ ch_itr = NULL;
+ while (Chan_iterate_siblings(parent, &ch_itr) != NULL) {
+ if (strcmp(ch_itr->name, msg->payload.channelState->name) == 0) {
+ sendPermissionDenied(client, "Channel already exists");
+ break;
+ }
+ }
+ if (ch_itr != NULL)
+ break;
+
+ /* Disallow temporary channels as siblings to temporary channels */
+ if (parent->temporary) {
+ sendPermissionDenied(client, "Parent channel is temporary channel");
+ break;
+ }
+
+ /* XXX - Murmur looks for "\\w" and sends perm denied if not found.
+ * I don't know why so I don't do that here...
+ */
+
+ /* Create the channel */
+ newchan = Chan_createChannel(msg->payload.channelState->name,
+ msg->payload.channelState->description);
+ newchan->temporary = true;
+ Chan_addChannel(parent, newchan);
+ msg->payload.channelState->has_channel_id = true;
+ msg->payload.channelState->channel_id = newchan->id;
+ Msg_inc_ref(msg);
+ Client_send_message_except(NULL, msg);
+
+ /* Join the creating user */
+ sendmsg = Msg_create(UserState);
+ sendmsg->payload.userState->has_session = true;
+ sendmsg->payload.userState->session = client->sessionId;
+ sendmsg->payload.userState->has_channel_id = true;
+ sendmsg->payload.userState->channel_id = newchan->id;
+ Client_send_message_except(NULL, sendmsg);
+
+ leave_id = Chan_userJoin(newchan, client);
+ if (leave_id > 0) {
+ Log_debug("Removing channel ID %d", leave_id);
+ sendmsg = Msg_create(ChannelRemove);
+ sendmsg->payload.channelRemove->channel_id = leave_id;
+ Client_send_message_except(NULL, sendmsg);
+ }
+ }
+ break;
+