Anope IRC Services  Version 1.8
cs_topic.c
Go to the documentation of this file.
1 /* ChanServ core functions
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  *
11  *
12  */
13 /*************************************************************************/
14 
15 #include "module.h"
16 
17 static int do_cs_topic(User * u);
18 static void myChanServHelp(User * u);
19 
26 int AnopeInit(int argc, char **argv)
27 {
28  Command *c;
29 
30  moduleAddAuthor("Anope");
31  moduleAddVersion(VERSION_STRING);
33 
34  c = createCommand("TOPIC", do_cs_topic, NULL, CHAN_HELP_TOPIC, -1, -1,
35  -1, -1);
37 
39 
40  return MOD_CONT;
41 }
42 
46 void AnopeFini(void)
47 {
48 
49 }
50 
55 static void myChanServHelp(User * u)
56 {
57  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_TOPIC);
58 }
59 
65 static int do_cs_topic(User * u)
66 {
67  char *chan = strtok(NULL, " ");
68  char *topic = strtok(NULL, "");
69 
70  Channel *c;
71  ChannelInfo *ci;
72 
73  if (!chan) {
74  syntax_error(s_ChanServ, u, "TOPIC", CHAN_TOPIC_SYNTAX);
75  } else if (!(c = findchan(chan))) {
76  notice_lang(s_ChanServ, u, CHAN_X_NOT_IN_USE, chan);
77  } else if (!(ci = c->ci)) {
78  notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, c->name);
79  } else if (ci->flags & CI_VERBOTEN) {
80  notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, ci->name);
81  } else if (!is_services_admin(u) && !check_access(u, ci, CA_TOPIC)) {
82  notice_lang(s_ChanServ, u, PERMISSION_DENIED);
83  } else {
84  if (ci->last_topic)
85  free(ci->last_topic);
86  ci->last_topic = topic ? sstrdup(topic) : NULL;
88  ci->last_topic_time = time(NULL);
89 
90  if (c->topic)
91  free(c->topic);
92  c->topic = topic ? sstrdup(topic) : NULL;
94  if (ircd->topictsbackward) {
95  c->topic_time = c->topic_time - 1;
96  } else {
97  c->topic_time = ci->last_topic_time;
98  }
99 
100  if (is_services_admin(u) && !check_access(u, ci, CA_TOPIC))
101  alog("%s: %s!%s@%s changed topic of %s as services admin.",
102  s_ChanServ, u->nick, u->username, u->host, c->name);
103  if (ircd->join2set) {
104  if (whosends(ci) == s_ChanServ) {
106  anope_cmd_mode(NULL, c->name, "+o %s", GET_BOT(s_ChanServ));
107  }
108  }
109  anope_cmd_topic(whosends(ci), c->name, u->nick, topic ? topic : "",
110  c->topic_time);
111  if (ircd->join2set) {
112  if (whosends(ci) == s_ChanServ) {
113  anope_cmd_part(s_ChanServ, c->name, NULL);
114  }
115  }
116  }
117  return MOD_CONT;
118 }
void AnopeFini(void)
Definition: cs_topic.c:46
char nick[NICKMAX]
Definition: services.h:875
E void anope_cmd_part(char *nick, char *chan, const char *fmt,...)
Definition: ircd.c:367
E IRCDVar * ircd
Definition: extern.h:39
E int check_access(User *user, ChannelInfo *ci, int what)
Definition: chanserv.c:1974
E void anope_cmd_join(char *user, char *channel, time_t chantime)
Definition: ircd.c:352
#define CI_VERBOTEN
Definition: services.h:725
char topic_setter[NICKMAX]
Definition: services.h:1004
char * host
Definition: services.h:878
E char * strscpy(char *d, const char *s, size_t len)
Definition: db-merger.c:1886
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
ChannelInfo * ci
Definition: services.h:1001
E void syntax_error(char *service, User *u, const char *command, int msgnum)
Definition: language.c:295
char name[CHANMAX]
Definition: services.h:654
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
time_t last_topic_time
Definition: services.h:667
char last_topic_setter[NICKMAX]
Definition: services.h:666
int AnopeInit(int argc, char **argv)
Definition: cs_topic.c:26
char * last_topic
Definition: services.h:665
E Channel * findchan(const char *chan)
Definition: channels.c:394
E char * sstrdup(const char *s)
Definition: memory.c:105
E void anope_cmd_topic(char *whosets, char *chan, char *whosetit, char *topic, time_t when)
Definition: ircd.c:145
uint32 flags
Definition: services.h:669
time_t creation_time
Definition: services.h:1002
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
MDE void moduleSetChanHelp(void(*func)(User *u))
Definition: modules.c:2090
static int do_cs_topic(User *u)
Definition: cs_topic.c:65
Command * c
Definition: ns_recover.c:17
#define CHANSERV
Definition: modules.h:60
E void alog(const char *fmt,...) FORMAT(printf
#define MOD_CONT
Definition: modules.h:54
E int is_services_admin(User *u)
Definition: operserv.c:591
int topictsbackward
Definition: services.h:322
#define whosends(ci)
Definition: extern.h:163
char * username
Definition: services.h:877
char * topic
Definition: services.h:1003
E void anope_cmd_mode(char *source, char *dest, const char *fmt,...)
Definition: ircd.c:211
Definition: modules.h:99
MDE Command * createCommand(const char *name, int(*func)(User *u), int(*has_priv)(User *u), int help_all, int help_reg, int help_oper, int help_admin, int help_root)
Definition: modules.c:987
#define NICKMAX
Definition: config.h:62
time_t topic_time
Definition: services.h:1005
int join2set
Definition: services.h:318
char name[CHANMAX]
Definition: services.h:1000
E char * s_ChanServ
Definition: extern.h:285
#define GET_BOT(bot)
Definition: services.h:271
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
static void myChanServHelp(User *u)
Definition: cs_topic.c:55
#define CA_TOPIC
Definition: services.h:787
#define MOD_UNIQUE
Definition: module.h:11