3 * ADVANCEDTOPIC enabled
7 * ADVANCEDTOPIC disabled
11 #define ADVANCEDTOPIC_MAXID 9
13 static CMD_BIND(neonserv_cmd_topic) {
16 MYSQL_ROW row, default_row = NULL;
17 int advanced_topic, i;
21 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);
23 row = mysql_fetch_row(res);
24 if(!row[0] || !row[3] || !row[4]) {
25 printf_mysql_query("SELECT `channel_exttopic`, `channel_enftopic`, `channel_topicsnarf` FROM `channels` WHERE `channel_name` = 'defaults'");
26 default_row = mysql_fetch_row(mysql_use());
30 advanced_topic = atoi(default_row[0]);
32 advanced_topic = atoi(row[0]);
35 putsock(client, "TOPIC %s :%s", chan->name, row[5]);
36 reply(getTextBot(), user, "NS_TOPIC_DONE", row[5]);
39 int uaccess = getChannelAccess(user, chan, 1);
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);
52 char *advtopics[ADVANCEDTOPIC_MAXID];
54 topic_id = atoi(argv[0]);
55 if(!topic_id || topic_id > ADVANCEDTOPIC_MAXID) {
56 reply(getTextBot(), user, "NS_EXTTOPIC_INVALID_ID", argv[0]);
62 while((a = strstr(b, "\n")) != NULL) {
64 if(i == ADVANCEDTOPIC_MAXID-1) break;
69 for(;i < ADVANCEDTOPIC_MAXID;i++)
72 //just show the topic with this id
73 reply(getTextBot(), user, "NS_EXTTOPIC_TOPICID", topic_id, advtopics[topic_id-1]);
76 newtopic = merge_argv(argv, 1, argc);
77 advtopics[topic_id-1] = newtopic;
78 char topiclist[MAXLEN*2];
81 for(i = 0; i < ADVANCEDTOPIC_MAXID; i++) {
82 if(topiclistpos + strlen(advtopics[i]) + 2 >= MAXLEN) break;
83 topiclistpos += sprintf(topiclist+topiclistpos, (i ? "\n%s" : "%s"), advtopics[i]);
85 printf_mysql_query("UPDATE `channels` SET `channel_exttopic_topic` = '%s' WHERE `channel_id` = '%d'", escape_string(topiclist), chan->channel_id);
86 //now build the new topic and set it...
89 while((a = strstr(b, "%")) != NULL) {
91 if(isdigit(a[1]) && a[1] - 48 > 0) {
92 topiclistpos += sprintf(topiclist + topiclistpos, "%s%s", b, advtopics[a[1] - 49]);
95 topiclistpos += sprintf(topiclist + topiclistpos, "%s%%", b);
99 topiclistpos += sprintf(topiclist + topiclistpos, "%s", b);
100 if(topiclistpos > MAXLEN)
101 topiclist[MAXLEN] = '\0';
102 putsock(client, "TOPIC %s :%s", chan->name, topiclist);
103 reply(getTextBot(), user, "NS_TOPIC_DONE", topiclist);
105 newtopic = merge_argv(argv, 0, argc);
106 char topiclist[MAXLEN*2];
108 int topiclistpos = 0;
110 while((a = strstr(b, "*")) != NULL) {
112 topiclistpos += sprintf(topiclist + topiclistpos, "%s%s", b, newtopic);
115 topiclistpos += sprintf(topiclist + topiclistpos, "%s", b);
116 if(topiclistpos > MAXLEN)
117 topiclist[MAXLEN] = '\0';
118 putsock(client, "TOPIC %s :%s", chan->name, topiclist);
119 reply(getTextBot(), user, "NS_TOPIC_DONE", topiclist);
123 #undef ADVANCEDTOPIC_MAXID