ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/vendor/ircservices-5.1.24/modules/protocol/halfop.c
Revision: 3389
Committed: Fri Apr 25 14:12:15 2014 UTC (11 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 4697 byte(s)
Log Message:
- Imported ircservices-5.1.24

File Contents

# Content
1 /* Halfop (+h) related functions.
2 *
3 * IRC Services is copyright (c) 1996-2009 Andrew Church.
4 * E-mail: <achurch@achurch.org>
5 * Parts written by Andrew Kempe and others.
6 * This program is free but copyrighted software; see the file GPL.txt for
7 * details.
8 */
9
10 #include "services.h"
11 #include "modules.h"
12 #include "language.h"
13 #include "modules/chanserv/chanserv.h"
14
15 #include "halfop.h"
16
17 /*************************************************************************/
18
19 static Module *halfop_module_chanserv;
20
21 static int halfop_old_XOP_REACHED_LIMIT = -1;
22 static int halfop_old_XOP_NICKS_ONLY = -1;
23 static int halfop_old_HELP_SOP_MID2 = -1;
24 static int halfop_old_HELP_AOP_MID = -1;
25
26 static const char **halfop_p_s_ChanServ = NULL; /* never used if NULL */
27 #define s_ChanServ (*halfop_p_s_ChanServ)
28
29 /*************************************************************************/
30 /*************************************************************************/
31
32 /* Callback to handle ChanServ CLEAR HALFOPS. */
33
34 static void clear_halfops(Channel *chan);
35
36 static int halfop_cs_clear(User *u, Channel *c, const char *what)
37 {
38 if (stricmp(what, "HALFOPS") == 0) {
39 clear_halfops(c);
40 set_cmode(NULL, c);
41 notice_lang(s_ChanServ, u, CHAN_CLEARED_HALFOPS, c->name);
42 return 1;
43 }
44 return 0;
45 }
46
47
48 static void clear_halfops(Channel *chan)
49 {
50 struct c_userlist *cu;
51 static int32 mode_h = -1;
52
53 if (mode_h < 0)
54 mode_h = mode_char_to_flag('h', MODE_CHANUSER);
55 LIST_FOREACH (cu, chan->users) {
56 if (cu->mode & mode_h)
57 set_cmode(s_ChanServ, chan, "-h", cu->user->nick);
58 }
59 }
60
61 /*************************************************************************/
62 /*************************************************************************/
63
64 /* Callback to watch for modules being loaded. */
65
66 static int halfop_load_module(Module *mod, const char *name)
67 {
68 if (strcmp(name, "chanserv/main") == 0) {
69 halfop_module_chanserv = mod;
70 halfop_p_s_ChanServ = get_module_symbol(mod, "s_ChanServ");
71 if (halfop_p_s_ChanServ) {
72 if (!(add_callback(mod, "CLEAR", halfop_cs_clear)))
73 module_log("halfop: Unable to add ChanServ CLEAR callback");
74 } else {
75 module_log("halfop: Symbol `s_ChanServ' not found, CLEAR"
76 " HALFOPS will not be available");
77 }
78 }
79 return 0;
80 }
81
82 /*************************************************************************/
83
84 /* Callback to watch for modules being unloaded. */
85
86 static int halfop_unload_module(Module *mod)
87 {
88 if (mod == halfop_module_chanserv) {
89 halfop_p_s_ChanServ = NULL;
90 halfop_module_chanserv = NULL;
91 }
92 return 0;
93 }
94
95 /*************************************************************************/
96
97 int init_halfop(void)
98 {
99 if (!add_callback(NULL, "load module", halfop_load_module)
100 || !add_callback(NULL, "unload module", halfop_unload_module)
101 ) {
102 module_log("halfop: Unable to add callbacks");
103 exit_halfop();
104 return 0;
105 }
106 protocol_features |= PF_HALFOP;
107 halfop_old_XOP_REACHED_LIMIT =
108 mapstring(CHAN_XOP_REACHED_LIMIT, CHAN_XOP_REACHED_LIMIT_HOP);
109 halfop_old_XOP_NICKS_ONLY =
110 mapstring(CHAN_XOP_NICKS_ONLY, CHAN_XOP_NICKS_ONLY_HOP);
111 halfop_old_HELP_SOP_MID2 =
112 mapstring(CHAN_HELP_SOP_MID2, CHAN_HELP_SOP_MID2_HALFOP);
113 halfop_old_HELP_AOP_MID =
114 mapstring(CHAN_HELP_AOP_MID, CHAN_HELP_AOP_MID_HALFOP);
115 return 1;
116 }
117
118 /*************************************************************************/
119
120 void exit_halfop(void)
121 {
122 if (halfop_module_chanserv)
123 halfop_unload_module(halfop_module_chanserv);
124 if (halfop_old_HELP_AOP_MID >= 0)
125 mapstring(CHAN_HELP_AOP_MID, halfop_old_HELP_AOP_MID);
126 if (halfop_old_HELP_SOP_MID2 >= 0)
127 mapstring(CHAN_HELP_SOP_MID2, halfop_old_HELP_SOP_MID2);
128 if (halfop_old_XOP_NICKS_ONLY >= 0)
129 mapstring(CHAN_XOP_NICKS_ONLY, halfop_old_XOP_NICKS_ONLY);
130 if (halfop_old_XOP_REACHED_LIMIT >= 0)
131 mapstring(CHAN_XOP_REACHED_LIMIT, halfop_old_XOP_REACHED_LIMIT);
132 halfop_old_HELP_AOP_MID = -1;
133 halfop_old_HELP_SOP_MID2 = -1;
134 halfop_old_XOP_NICKS_ONLY = -1;
135 halfop_old_XOP_REACHED_LIMIT = -1;
136 remove_callback(NULL, "unload module", halfop_unload_module);
137 remove_callback(NULL, "load module", halfop_load_module);
138 }
139
140 /*************************************************************************/
141
142 #undef s_ChanServ
143
144 /*
145 * Local variables:
146 * c-file-style: "stroustrup"
147 * c-file-offsets: ((case-label . *) (statement-case-intro . *))
148 * indent-tabs-mode: nil
149 * End:
150 *
151 * vim: expandtab shiftwidth=4:
152 */