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]);
39 int uaccess = getChannelAccess(user, chan, 0);
40 if(uaccess >= atoi((row[3] ? row[3] : default_row[1]))) {
42 newtopic = merge_argv(argv, 0, argc);
43 if(uaccess >= atoi((row[4] ? row[4] : default_row[2]))) {
44 //set the default topic
45 printf_mysql_query("UPDATE `channels` SET `channel_defaulttopic` = '%s' WHERE `channel_id` = '%d'", escape_string(newtopic), chan->channel_id);
47 putsock(client, "TOPIC %s :%s", chan->name, newtopic);
48 reply(getTextBot(), user, "NS_TOPIC_DONE", newtopic);
53 char *advtopics[ADVANCEDTOPIC_MAXID];
55 topic_id = atoi(argv[0]);
56 if(!topic_id || topic_id > ADVANCEDTOPIC_MAXID) {
57 reply(getTextBot(), user, "NS_EXTTOPIC_INVALID_ID", argv[0]);
63 while((a = strstr(b, "\n")) != NULL) {
65 if(i == ADVANCEDTOPIC_MAXID-1) break;
70 for(;i < ADVANCEDTOPIC_MAXID;i++)
73 //just show the topic with this id
74 reply(getTextBot(), user, "NS_EXTTOPIC_TOPICID", topic_id, advtopics[topic_id-1]);
77 newtopic = merge_argv(argv, 1, argc);
78 if(!strcmp(newtopic, "*"))
80 advtopics[topic_id-1] = newtopic;
81 char topiclist[MAXLEN*2];
84 for(i = 0; i < ADVANCEDTOPIC_MAXID; i++) {
85 if(topiclistpos + strlen(advtopics[i]) + 2 >= MAXLEN) break;
86 topiclistpos += sprintf(topiclist+topiclistpos, (i ? "\n%s" : "%s"), advtopics[i]);
88 printf_mysql_query("UPDATE `channels` SET `channel_exttopic_topic` = '%s' WHERE `channel_id` = '%d'", escape_string(topiclist), chan->channel_id);
89 //now build the new topic and set it...
92 while((a = strstr(b, "%")) != NULL) {
94 if(isdigit(a[1]) && a[1] - 48 > 0) {
95 topiclistpos += sprintf(topiclist + topiclistpos, "%s%s", b, advtopics[a[1] - 49]);
98 topiclistpos += sprintf(topiclist + topiclistpos, "%s%%", b);
102 topiclistpos += sprintf(topiclist + topiclistpos, "%s", b);
103 if(topiclistpos > MAXLEN)
104 topiclist[MAXLEN] = '\0';
105 putsock(client, "TOPIC %s :%s", chan->name, topiclist);
106 reply(getTextBot(), user, "NS_TOPIC_DONE", topiclist);
109 newtopic = merge_argv(argv, 0, argc);
110 char topiclist[MAXLEN*2];
112 int topiclistpos = 0;
114 while((a = strstr(b, "*")) != NULL) {
116 topiclistpos += sprintf(topiclist + topiclistpos, "%s%s", b, newtopic);
119 topiclistpos += sprintf(topiclist + topiclistpos, "%s", b);
120 if(topiclistpos > MAXLEN)
121 topiclist[MAXLEN] = '\0';
122 putsock(client, "TOPIC %s :%s", chan->name, topiclist);
123 reply(getTextBot(), user, "NS_TOPIC_DONE", topiclist);
128 #undef ADVANCEDTOPIC_MAXID