00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #define MODULE_NAME "channels"
00028
00029 #define start channels_LTX_start
00030
00031 static eggdrop_t *egg = NULL;
00032
00033 static int setstatic, use_info, chan_hack, global_aop_min, global_aop_max,
00034 global_ban_time, global_exempt_time, global_invite_time;
00035
00036
00037
00038
00039
00040
00041 static void write_channels()
00042 {
00043 FILE *f;
00044 char s[121], w[1024], w2[1024], name[163];
00045 struct chanset_t *chan;
00046 struct udef_struct *ul;
00047
00048 if (!chanfile[0])
00049 return;
00050 sprintf(s, "%s~new", chanfile);
00051 f = fopen(s, "w");
00052 chmod(s, userfile_perm);
00053 if (f == NULL) {
00054 putlog(LOG_MISC, "*", "ERROR writing channel file.");
00055 return;
00056 }
00057 fprintf(f, "#Dynamic Channel File for %s (%s) -- written %s\n", myname, ver,
00058 ctime(&now));
00059 for (chan = chanset; chan; chan = chan->next) {
00060 convert_element(chan->dname, name);
00061 get_mode_protect(chan, w);
00062 convert_element(w, w2);
00063 fprintf(f,
00064 "channel %s %s%schanmode %s aop_delay %d:%d ban_time %d "
00065 "exempt_time %d invite_time %d %cenforcebans %cdynamicbans "
00066 "%cautoop %cgreet %cdontkickops %cstatuslog %cautovoice %csecret "
00067 "%ccycle %cinactive %cdynamicexempts %chonor-global-bans "
00068 "%chonor-global-exempts %chonor-global-invites %cdynamicinvites "
00069 "%cnodesynch ", channel_static(chan) ? "set" : "add", name,
00070 channel_static(chan) ? " " : " { ", w2, chan->aop_min,
00071 chan->aop_max, chan->ban_time, chan->exempt_time,
00072 chan->invite_time,
00073 PLSMNS(channel_enforcebans(chan)),
00074 PLSMNS(channel_dynamicbans(chan)),
00075 PLSMNS(channel_autoop(chan)),
00076 PLSMNS(channel_greet(chan)),
00077 PLSMNS(channel_dontkickops(chan)),
00078 PLSMNS(channel_logstatus(chan)),
00079 PLSMNS(channel_autovoice(chan)),
00080 PLSMNS(channel_secret(chan)),
00081 PLSMNS(channel_cycle(chan)),
00082 PLSMNS(channel_inactive(chan)),
00083 PLSMNS(channel_dynamicexempts(chan)),
00084 PLSMNS(channel_honor_global_bans(chan)),
00085 PLSMNS(channel_honor_global_exempts(chan)),
00086 PLSMNS(channel_honor_global_invites(chan)),
00087 PLSMNS(channel_dynamicinvites(chan)),
00088 PLSMNS(channel_nodesynch(chan)));
00089 for (ul = udef; ul; ul = ul->next) {
00090 if (ul->defined && ul->name) {
00091 if (ul->type == UDEF_FLAG)
00092 fprintf(f, "%c%s%s ", getudef(ul->values, chan->dname) ? '+' : '-',
00093 "udef_flag_", ul->name);
00094 else if (ul->type == UDEF_INT)
00095 fprintf(f, "%s%s %d ", "udef_int_", ul->name, getudef(ul->values,
00096 chan->dname));
00097 else if (ul->type == UDEF_STR) {
00098 char *p;
00099 p = (char *)getudef(ul->values, chan->dname);
00100 if (!p) strcpy(p, "{}");
00101 fprintf(f, "udef_str_%s %s ", ul->name, p);
00102 }
00103 else
00104 putlog(LOG_DEBUG, "*", "UDEF-ERROR: unknown type %d", ul->type);
00105 }
00106 }
00107 fprintf(f, "%s\n", channel_static(chan) ? "" : "}");
00108 if (fflush(f)) {
00109 putlog(LOG_MISC, "*", "ERROR writing channel file.");
00110 fclose(f);
00111 return;
00112 }
00113 }
00114 fclose(f);
00115 unlink(chanfile);
00116 movefile(s, chanfile);
00117 }
00118
00119 static void channels_report(int idx, int details)
00120 {
00121 struct chanset_t *chan;
00122 int i;
00123 char s[1024], s2[100];
00124 struct flag_record fr = {FR_CHAN | FR_GLOBAL, 0, 0, 0, 0, 0};
00125
00126 for (chan = chanset; chan; chan = chan->next) {
00127 if (idx != DP_STDOUT)
00128 get_user_flagrec(dcc[idx].user, &fr, chan->dname);
00129 if ((idx == DP_STDOUT) || glob_master(fr) || chan_master(fr)) {
00130 s[0] = 0;
00131 if (channel_greet(chan))
00132 strcat(s, "greet, ");
00133 if (channel_autoop(chan))
00134 strcat(s, "auto-op, ");
00135 if (s[0])
00136 s[strlen(s) - 2] = 0;
00137 if (!s[0])
00138 strcpy(s, _("lurking"));
00139 get_mode_protect(chan, s2);
00140 if (!channel_inactive(chan)) {
00141 if (channel_active(chan)) {
00142
00143 if (chan->dname[0]=='!') {
00144 dprintf(idx, " %-10s: %2d member%s enforcing \"%s\" (%s), "
00145 "unique name %s\n", chan->dname, chan->channel.members,
00146 (chan->channel.members==1) ? "," : "s,", s2, s, chan->name);
00147 } else {
00148 dprintf(idx, " %-10s: %2d member%s enforcing \"%s\" (%s)\n",
00149 chan->dname, chan->channel.members,
00150 chan->channel.members == 1 ? "," : "s,", s2, s);
00151 }
00152 } else {
00153 dprintf(idx, " %-10s: (%s), enforcing \"%s\" (%s)\n", chan->dname,
00154 channel_pending(chan) ? "pending" : "not on channel", s2, s);
00155 }
00156 } else {
00157 dprintf(idx, " %-10s: channel is set +inactive\n",
00158 chan->dname);
00159 }
00160 if (details) {
00161 s[0] = 0;
00162 i = 0;
00163 if (channel_enforcebans(chan))
00164 i += my_strcpy(s + i, "enforce-bans ");
00165 if (channel_dynamicbans(chan))
00166 i += my_strcpy(s + i, "dynamic-bans ");
00167 if (channel_autoop(chan))
00168 i += my_strcpy(s + i, "op-on-join ");
00169 if (channel_greet(chan))
00170 i += my_strcpy(s + i, "greet ");
00171 if (channel_dontkickops(chan))
00172 i += my_strcpy(s + i, "dont-kick-ops ");
00173 if (channel_logstatus(chan))
00174 i += my_strcpy(s + i, "log-status ");
00175 if (channel_secret(chan))
00176 i += my_strcpy(s + i, "secret ");
00177 if (!channel_static(chan))
00178 i += my_strcpy(s + i, "dynamic ");
00179 if (channel_autovoice(chan))
00180 i += my_strcpy(s + i, "autovoice ");
00181 if (channel_cycle(chan))
00182 i += my_strcpy(s + i, "cycle ");
00183 if (channel_dynamicexempts(chan))
00184 i += my_strcpy(s + i, "dynamic-exempts ");
00185 if (channel_dynamicinvites(chan))
00186 i += my_strcpy(s + i, "dynamic-invites ");
00187 if (channel_inactive(chan))
00188 i += my_strcpy(s + i, "inactive ");
00189 if (channel_nodesynch(chan))
00190 i += my_strcpy(s + i, "nodesynch ");
00191 if (channel_honor_global_bans(chan))
00192 i += my_strcpy(s + i, "honor-global-bans ");
00193 if (channel_honor_global_exempts(chan))
00194 i += my_strcpy(s + i, "honor-global-exempts ");
00195 if (channel_honor_global_invites(chan))
00196 i += my_strcpy(s + i, "honor-global-invites ");
00197 dprintf(idx, " Options: %s\n", s);
00198 if (details) {
00199 dprintf(idx, " Bans last %d mins.\n", chan->ban_time);
00200 dprintf(idx, " Exemptions last %d mins.\n", chan->exempt_time);
00201 dprintf(idx, " Invitations last %d mins.\n", chan->invite_time);
00202 }
00203 }
00204 }
00205 }
00206 }
00207
00208 static char *channels_close()
00209 {
00210 write_channels();
00211 free_udef(udef);
00212 if (lastdeletedmask)
00213 free(lastdeletedmask);
00214 rem_builtins("chon", my_chon);
00215 rem_builtins("dcc", C_dcc_irc);
00216 script_delete_commands(channel_script_cmds);
00217 rem_tcl_commands(channels_cmds);
00218 rem_tcl_strings(my_tcl_strings);
00219 rem_tcl_ints(my_tcl_ints);
00220 rem_tcl_coups(mychan_tcl_coups);
00221 del_hook(HOOK_USERFILE, (Function) channels_writeuserfile);
00222 del_hook(HOOK_BACKUP, (Function) backup_chanfile);
00223 del_hook(HOOK_REHASH, (Function) channels_rehash);
00224 del_hook(HOOK_PRE_REHASH, (Function) channels_prerehash);
00225 del_hook(HOOK_MINUTELY, (Function) check_expired_bans);
00226 del_hook(HOOK_MINUTELY, (Function) check_expired_exempts);
00227 del_hook(HOOK_MINUTELY, (Function) check_expired_invites);
00228 Tcl_UntraceVar(interp, "global-chanset",
00229 TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
00230 traced_globchanset, NULL);
00231 rem_help_reference("channels.help");
00232 rem_help_reference("chaninfo.help");
00233 module_undepend(MODULE_NAME);
00234 return NULL;
00235 }
00236
00237 EXPORT_SCOPE char *start();
00238
00239 char *start(eggdrop_t *eggdrop)
00240 {
00241 egg = eggdrop;
00242 global_aop_min = 5;
00243 global_aop_max = 30;
00244 setstatic = 0;
00245 lastdeletedmask = 0;
00246 use_info = 1;
00247 strcpy(chanfile, "chanfile");
00248 chan_hack = 0;
00249 strcpy(glob_chanmode, "nt");
00250 udef = NULL;
00251 global_ban_time = 120;
00252 global_exempt_time = 60;
00253 global_invite_time = 60;
00254 strcpy(glob_chanset,
00255 "-enforcebans "
00256 "+dynamicbans "
00257 "-autoop "
00258 "+greet "
00259 "+statuslog "
00260 "-secret "
00261 "-autovoice "
00262 "+cycle "
00263 "+dontkickops "
00264 "-inactive "
00265 "+dynamicexempts "
00266 "+dynamicinvites "
00267 "+honor-global-bans "
00268 "+honor-global-exempts "
00269 "+honor-global-invites "
00270 "-nodesynch ");
00271 module_register(MODULE_NAME, channels_table, 1, 0);
00272 if (!module_depend(MODULE_NAME, "eggdrop", 107, 0)) {
00273 module_undepend(MODULE_NAME);
00274 return "This module needs eggdrop1.7.0 or later";
00275 }
00276 add_hook(HOOK_MINUTELY, (Function) check_expired_bans);
00277 add_hook(HOOK_MINUTELY, (Function) check_expired_exempts);
00278 add_hook(HOOK_MINUTELY, (Function) check_expired_invites);
00279 add_hook(HOOK_USERFILE, (Function) channels_writeuserfile);
00280 add_hook(HOOK_BACKUP, (Function) backup_chanfile);
00281 add_hook(HOOK_REHASH, (Function) channels_rehash);
00282 add_hook(HOOK_PRE_REHASH, (Function) channels_prerehash);
00283 Tcl_TraceVar(interp, "global-chanset",
00284 TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
00285 traced_globchanset, NULL);
00286 add_builtins("chon", my_chon);
00287 add_builtins("dcc", C_dcc_irc);
00288 script_create_commands(channel_script_cmds);
00289 add_tcl_commands(channels_cmds);
00290 add_tcl_strings(my_tcl_strings);
00291 add_help_reference("channels.help");
00292 add_help_reference("chaninfo.help");
00293 add_tcl_ints(my_tcl_ints);
00294 add_tcl_coups(mychan_tcl_coups);
00295 read_channels(0);
00296 setstatic = 1;
00297 return NULL;
00298 }