3 * ADVANCEDTOPIC enabled
7 * ADVANCEDTOPIC disabled
11 #define ADVANCEDTOPIC_MAXID 9
13 static CMD_BIND(neonserv_cmd_topic) {
15 MYSQL_ROW row, default_row = NULL;
16 int advanced_topic, i;
20 printf_mysql_query("SELECT `channel_exttopic`, `channel_exttopic_topic`, `channel_topicmask`, `channel_enftopic`, `channel_topicsnarf`, `channel_defaulttopic` FROM `channels` WHERE `channel_id` = '%d'", chan->channel_id);
22 row = mysql_fetch_row(res);
23 if(!row[0] || !row[3] || !row[4]) {
24 printf_mysql_query("SELECT `channel_exttopic`, `channel_enftopic`, `channel_topicsnarf` FROM `channels` WHERE `channel_name` = 'defaults'");
25 default_row = mysql_fetch_row(mysql_use());
29 advanced_topic = atoi(default_row[0]);
31 advanced_topic = atoi(row[0]);
34 putsock(client, "TOPIC %s :%s", chan->name, row[5]);
35 reply(getTextBot(), user, "NS_TOPIC_DONE", row[5]);
38 int uaccess = getChannelAccess(user, chan, 1);
39 if(uaccess >= atoi((row[3] ? row[3] : default_row[1]))) {
41 newtopic = merge_argv(argv, 0, argc);
42 if(uaccess >= atoi((row[4] ? row[4] : default_row[2]))) {
43 //set the default topic
44 printf_mysql_query("UPDATE `channels` SET `channel_defaulttopic` = '%s' WHERE `channel_id` = '%d'", escape_string(newtopic), chan->channel_id);
46 putsock(client, "TOPIC %s :%s", chan->name, newtopic);
47 reply(getTextBot(), user, "NS_TOPIC_DONE", newtopic);
51 char *advtopics[ADVANCEDTOPIC_MAXID];
53 topic_id = atoi(argv[0]);
54 if(!topic_id || topic_id > ADVANCEDTOPIC_MAXID) {
55 reply(getTextBot(), user, "NS_EXTTOPIC_INVALID_ID", argv[0]);
61 while((a = strstr(b, "\n")) != NULL) {
63 if(i == ADVANCEDTOPIC_MAXID-1) break;
68 for(;i < ADVANCEDTOPIC_MAXID;i++)
71 //just show the topic with this id
72 reply(getTextBot(), user, "NS_EXTTOPIC_TOPICID", topic_id, advtopics[topic_id-1]);
75 newtopic = merge_argv(argv, 1, argc);
76 advtopics[topic_id-1] = newtopic;
77 char topiclist[MAXLEN*2];
80 for(i = 0; i < ADVANCEDTOPIC_MAXID; i++) {
81 if(topiclistpos + strlen(advtopics[i]) + 2 >= MAXLEN) break;
82 topiclistpos += sprintf(topiclist+topiclistpos, (i ? "\n%s" : "%s"), advtopics[i]);
84 printf_mysql_query("UPDATE `channels` SET `channel_exttopic_topic` = '%s' WHERE `channel_id` = '%d'", escape_string(topiclist), chan->channel_id);
85 //now build the new topic and set it...
88 while((a = strstr(b, "%")) != NULL) {
90 if(isdigit(a[1]) && a[1] - 48 > 0) {
91 topiclistpos += sprintf(topiclist + topiclistpos, "%s%s", b, advtopics[a[1] - 49]);
94 topiclistpos += sprintf(topiclist + topiclistpos, "%s%%", b);
98 topiclistpos += sprintf(topiclist + topiclistpos, "%s", b);
99 if(topiclistpos > MAXLEN)
100 topiclist[MAXLEN] = '\0';
101 putsock(client, "TOPIC %s :%s", chan->name, topiclist);
102 reply(getTextBot(), user, "NS_TOPIC_DONE", topiclist);
104 newtopic = merge_argv(argv, 0, argc);
105 char topiclist[MAXLEN*2];
107 int topiclistpos = 0;
109 while((a = strstr(b, "*")) != NULL) {
111 topiclistpos += sprintf(topiclist + topiclistpos, "%s%s", b, newtopic);
114 topiclistpos += sprintf(topiclist + topiclistpos, "%s", b);
115 if(topiclistpos > MAXLEN)
116 topiclist[MAXLEN] = '\0';
117 putsock(client, "TOPIC %s :%s", chan->name, topiclist);
118 reply(getTextBot(), user, "NS_TOPIC_DONE", topiclist);
122 #undef ADVANCEDTOPIC_MAXID