Fix a couple of error cases regarding temp channel creation/deletion.
}
if (i == 0) {
rootChan = createChannel(0, chdesc.name, chdesc.description);
+ rootChan->noenter = chdesc.noenter;
list_add_tail(&rootChan->flatlist_node, &channels);
if (strcmp(defaultChannelName, chdesc.name) == 0)
defaultChan = rootChan;
else {
channel_t *ch, *ch_itr = NULL;
ch = Chan_createChannel(chdesc.name, chdesc.description);
+ ch->noenter = chdesc.noenter;
if (strcmp(defaultChannelName, chdesc.name) == 0) {
Log_info("Setting default channel %s", ch->name);
}
if (defaultChan == NULL)
defaultChan = rootChan;
+
+ if (defaultChan->noenter)
+ Log_fatal("Error in channel configuration: default channel is marked as noenter");
/* Channel links */
for (i = 0; ; i++) {
return Chan_playerJoin(ch_itr, client);
}
+bool_t Chan_playerJoin_id_test(int channelid)
+{
+ channel_t *ch_itr = NULL;
+ do {
+ Chan_iterate(&ch_itr);
+ } while (ch_itr != NULL && ch_itr->id != channelid);
+ if (ch_itr == NULL) {
+ Log_warn("Channel id %d not found - ignoring.", channelid);
+ return false;
+ }
+ if (ch_itr->noenter)
+ return false;
+ else
+ return true;
+}
+
#if 0
void Chan_addChannel_id(int parentId, channel_t *ch)
{
char name[MAX_TEXT];
char desc[MAX_TEXT];
struct channel *parent;
- bool_t temporary;
+ bool_t temporary, noenter;
struct dlist node;
struct dlist subs;
struct dlist clients;
void Chan_removeClient(channel_t *c, client_t *client);
int Chan_playerJoin(channel_t *ch, client_t *client);
int Chan_playerJoin_id(int channelid, client_t *client);
+bool_t Chan_playerJoin_id_test(int channelid);
channel_t *Chan_iterate(channel_t **channelpptr);
channel_t *Chan_iterate_siblings(channel_t *parent, channel_t **channelpptr);
channel_t *Chan_createChannel(const char *name, const char *desc);
sprintf(configstr, "channels.[%d].name", index);
setting = config_lookup(&configuration, configstr);
if (setting == NULL)
- return -1;
+ return -1; /* Required */
strncpy(chdesc->name, config_setting_get_string(setting), MAX_TEXT);
sprintf(configstr, "channels.[%d].parent", index);
setting = config_lookup(&configuration, configstr);
if (setting == NULL)
- return -1;
+ return -1; /* Required */
strncpy(chdesc->parent, config_setting_get_string(setting), MAX_TEXT);
sprintf(configstr, "channels.[%d].description", index);
setting = config_lookup(&configuration, configstr);
- if (setting == NULL)
- return -1;
- strncpy(chdesc->description, config_setting_get_string(setting), MAX_TEXT);
+ if (setting == NULL) /* Optional */
+ strncpy(chdesc->description, "", MAX_TEXT);
+ else
+ strncpy(chdesc->description, config_setting_get_string(setting), MAX_TEXT);
+
+ sprintf(configstr, "channels.[%d].noenter", index);
+ setting = config_lookup(&configuration, configstr);
+ if (setting == NULL) /* Optional */
+ chdesc->noenter = false;
+ else
+ chdesc->noenter = config_setting_get_bool(setting);
return 0;
}
char parent[MAX_TEXT];
char name[MAX_TEXT];
char description[MAX_TEXT];
+ bool_t noenter;
} conf_channel_t;
typedef struct {
}
if (msg->payload.userState->has_channel_id) {
int leave_id;
+ if (!Chan_playerJoin_id_test(msg->payload.userState->channel_id))
+ break;
leave_id = Chan_playerJoin_id(msg->payload.userState->channel_id, client);
if (leave_id > 0) {
- /* XXX - need to send update to remove channel if temporary */
Log_debug("Removing channel ID %d", leave_id);
sendmsg = Msg_create(ChannelRemove);
sendmsg->payload.channelRemove->channel_id = leave_id;
if (sendmsg != NULL)
Client_send_message_except(NULL, sendmsg);
break;
+
case TextMessage:
msg->payload.textMessage->has_actor = true;
msg->payload.textMessage->actor = client->sessionId;
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;
}
}
+ 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...
*/
sendmsg->payload.userState->has_channel_id = true;
sendmsg->payload.userState->channel_id = newchan->id;
Client_send_message_except(NULL, sendmsg);
- Chan_playerJoin(newchan, client);
+
+ leave_id = Chan_playerJoin(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;