2 #include "cmd_neonserv.h"
5 * ADVANCEDTOPIC enabled
9 * ADVANCEDTOPIC disabled
13 #define ADVANCEDTOPIC_MAXID 9
15 CMD_BIND(neonserv_cmd_topic) {
17 MYSQL_ROW row, default_row = NULL;
18 int advanced_topic, i;
22 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);
24 row = mysql_fetch_row(res);
25 if(!row[0] || !row[3] || !row[4]) {
26 printf_mysql_query("SELECT `channel_exttopic`, `channel_enftopic`, `channel_topicsnarf` FROM `channels` WHERE `channel_name` = 'defaults'");
27 default_row = mysql_fetch_row(mysql_use());
31 advanced_topic = atoi(default_row[0]);
33 advanced_topic = atoi(row[0]);
36 putsock(client, "TOPIC %s :%s", chan->name, row[5]);
37 reply(getTextBot(), user, "NS_TOPIC_DONE", row[5]);
41 int uaccess = getChannelAccess(user, chan, 0);
42 if(uaccess >= atoi((row[3] ? row[3] : default_row[1]))) {
44 newtopic = merge_argv(argv, 0, argc);
45 if(uaccess >= atoi((row[4] ? row[4] : default_row[2]))) {
46 //set the default topic
47 printf_mysql_query("UPDATE `channels` SET `channel_defaulttopic` = '%s' WHERE `channel_id` = '%d'", escape_string(newtopic), chan->channel_id);
49 putsock(client, "TOPIC %s :%s", chan->name, newtopic);
50 reply(getTextBot(), user, "NS_TOPIC_DONE", newtopic);
55 char *advtopics[ADVANCEDTOPIC_MAXID];
57 topic_id = atoi(argv[0]);
58 if(!topic_id || topic_id > ADVANCEDTOPIC_MAXID) {
59 reply(getTextBot(), user, "NS_EXTTOPIC_INVALID_ID", argv[0]);
65 while((a = strstr(b, "\n")) != NULL) {
67 if(i == ADVANCEDTOPIC_MAXID-1) break;
72 for(;i < ADVANCEDTOPIC_MAXID;i++)
75 //just show the topic with this id
76 reply(getTextBot(), user, "NS_EXTTOPIC_TOPICID", topic_id, advtopics[topic_id-1]);
79 newtopic = merge_argv(argv, 1, argc);
80 if(!strcmp(newtopic, "*"))
82 advtopics[topic_id-1] = newtopic;
83 char topiclist[MAXLEN*2];
86 for(i = 0; i < ADVANCEDTOPIC_MAXID; i++) {
87 if(topiclistpos + strlen(advtopics[i]) + 2 >= MAXLEN) break;
88 topiclistpos += sprintf(topiclist+topiclistpos, (i ? "\n%s" : "%s"), advtopics[i]);
90 printf_mysql_query("UPDATE `channels` SET `channel_exttopic_topic` = '%s' WHERE `channel_id` = '%d'", escape_string(topiclist), chan->channel_id);
91 //now build the new topic and set it...
94 while((a = strstr(b, "%")) != NULL) {
96 if(isdigit(a[1]) && a[1] - 48 > 0) {
97 topiclistpos += sprintf(topiclist + topiclistpos, "%s%s", b, advtopics[a[1] - 49]);
100 topiclistpos += sprintf(topiclist + topiclistpos, "%s%%", b);
104 topiclistpos += sprintf(topiclist + topiclistpos, "%s", b);
105 if(topiclistpos > MAXLEN)
106 topiclist[MAXLEN] = '\0';
107 putsock(client, "TOPIC %s :%s", chan->name, topiclist);
108 reply(getTextBot(), user, "NS_TOPIC_DONE", topiclist);
111 newtopic = merge_argv(argv, 0, argc);
112 char topiclist[MAXLEN*2];
114 int topiclistpos = 0;
116 while((a = strstr(b, "*")) != NULL) {
118 topiclistpos += sprintf(topiclist + topiclistpos, "%s%s", b, newtopic);
121 topiclistpos += sprintf(topiclist + topiclistpos, "%s", b);
122 if(topiclistpos > MAXLEN)
123 topiclist[MAXLEN] = '\0';
124 putsock(client, "TOPIC %s :%s", chan->name, topiclist);
125 reply(getTextBot(), user, "NS_TOPIC_DONE", topiclist);
130 #undef ADVANCEDTOPIC_MAXID