1 /* cmd_neonserv_topic.c - NeonServ v5.4
2 * Copyright (C) 2011-2012 Philipp Kreil (pk910)
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "cmd_neonserv.h"
21 * ADVANCEDTOPIC enabled
25 * ADVANCEDTOPIC disabled
29 #define ADVANCEDTOPIC_MAXID 9
31 CMD_BIND(neonserv_cmd_topic) {
33 MYSQL_ROW row, default_row = NULL;
34 int advanced_topic, i;
38 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);
40 row = mysql_fetch_row(res);
41 if(!row[0] || !row[3] || !row[4]) {
42 printf_mysql_query("SELECT `channel_exttopic`, `channel_enftopic`, `channel_topicsnarf` FROM `channels` WHERE `channel_name` = 'defaults'");
43 default_row = mysql_fetch_row(mysql_use());
47 advanced_topic = atoi(default_row[0]);
49 advanced_topic = atoi(row[0]);
52 putsock(client, "TOPIC %s :%s", chan->name, row[5]);
53 reply(textclient, user, "NS_TOPIC_DONE", row[5]);
57 int uaccess = getChannelAccess(user, chan);
58 if(uaccess >= atoi((row[3] ? row[3] : default_row[1]))) {
60 newtopic = merge_argv(argv, 0, argc);
61 if(uaccess >= atoi((row[4] ? row[4] : default_row[2]))) {
62 //set the default topic
63 printf_mysql_query("UPDATE `channels` SET `channel_defaulttopic` = '%s' WHERE `channel_id` = '%d'", escape_string(newtopic), chan->channel_id);
65 putsock(client, "TOPIC %s :%s", chan->name, newtopic);
66 reply(textclient, user, "NS_TOPIC_DONE", newtopic);
71 char *advtopics[ADVANCEDTOPIC_MAXID];
73 topic_id = atoi(argv[0]);
74 if(!topic_id || topic_id > ADVANCEDTOPIC_MAXID) {
75 reply(textclient, user, "NS_EXTTOPIC_INVALID_ID", argv[0]);
81 while((a = strstr(b, "\n")) != NULL) {
83 if(i == ADVANCEDTOPIC_MAXID-1) break;
88 for(;i < ADVANCEDTOPIC_MAXID;i++)
91 //just show the topic with this id
92 reply(textclient, user, "NS_EXTTOPIC_TOPICID", topic_id, advtopics[topic_id-1]);
95 newtopic = merge_argv(argv, 1, argc);
96 if(!strcmp(newtopic, "*"))
98 advtopics[topic_id-1] = newtopic;
99 char topiclist[MAXLEN*2];
101 int topiclistpos = 0;
102 for(i = 0; i < ADVANCEDTOPIC_MAXID; i++) {
103 if(topiclistpos + strlen(advtopics[i]) + 2 >= MAXLEN) break;
104 topiclistpos += sprintf(topiclist+topiclistpos, (i ? "\n%s" : "%s"), advtopics[i]);
106 printf_mysql_query("UPDATE `channels` SET `channel_exttopic_topic` = '%s' WHERE `channel_id` = '%d'", escape_string(topiclist), chan->channel_id);
107 //now build the new topic and set it...
110 char *topicpart, *debugbb;
111 while((a = strstr(b, "%")) != NULL) {
113 if(isdigit(a[1]) && a[1] - 48 > 0) {
114 topicpart = advtopics[a[1] - 49];
115 if(isdigit(topicpart[0]) && isdigit(b[strlen(b)-1]))
116 debugbb = "\002\002"; //double bold to prevent following digits used as color code
119 topiclistpos += sprintf(topiclist + topiclistpos, "%s%s%s", b, debugbb, topicpart);
122 topiclistpos += sprintf(topiclist + topiclistpos, "%s%%", b);
126 topiclistpos += sprintf(topiclist + topiclistpos, "%s", b);
127 if(topiclistpos > MAXLEN)
128 topiclist[MAXLEN] = '\0';
129 putsock(client, "TOPIC %s :%s", chan->name, topiclist);
130 reply(textclient, user, "NS_TOPIC_DONE", topiclist);
133 newtopic = merge_argv(argv, 0, argc);
134 char topiclist[MAXLEN*2];
136 int topiclistpos = 0;
139 while((a = strstr(b, "*")) != NULL) {
141 if(isdigit(newtopic[0]) && isdigit(b[strlen(b)-1]))
142 debugbb = "\002\002"; //double bold to prevent following digits used as color code
145 topiclistpos += sprintf(topiclist + topiclistpos, "%s%s%s", b, debugbb, newtopic);
148 topiclistpos += sprintf(topiclist + topiclistpos, "%s", b);
149 if(topiclistpos > MAXLEN)
150 topiclist[MAXLEN] = '\0';
151 putsock(client, "TOPIC %s :%s", chan->name, topiclist);
152 reply(textclient, user, "NS_TOPIC_DONE", topiclist);
157 #undef ADVANCEDTOPIC_MAXID