Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/source/cset.c
1069 views
1
/************
2
* cset.c *
3
************
4
*
5
* My code for creating all the "Channel Sets" on a per channel
6
* basis. We manage them here, and then just insert/remove/return them
7
* when a channel calls for them.
8
* Code for creating and modifying "Window Sets" on a per window
9
* basis.
10
*
11
* Note: Notice the shameless use of typecasting to get these functions
12
* to work as painlessly as possible.
13
*
14
* Written by Scott H Kilau
15
* Modified by Colten D Edwards for /wset
16
*
17
* Copyright(c) 1997
18
*
19
* See the COPYRIGHT file, or do a HELP IRCII COPYRIGHT
20
*/
21
22
#if 0
23
[Sheik(~sheik@spartan.pei.edu)] notice in struct.h that the cset struct *does*
24
have a ->next pointer.. thats for the future when we may want to
25
daisy chain cset's that don't have channels yet.. ie a user can
26
/cset *warez* and know that all warez channels would get defaulted
27
#endif
28
29
#include "irc.h"
30
static char cvsrevision[] = "$Id: cset.c 108 2011-02-02 12:13:54Z keaston $";
31
CVS_REVISION(cset_c)
32
#include "struct.h"
33
#include "vars.h" /* for do_boolean() and var_settings[] */
34
#include "window.h" /* for get_current_channel_by_refnum() */
35
#include "screen.h" /* for curr_scr_win */
36
#include "names.h" /* for lookup_channel() */
37
#include "log.h"
38
#include "ircaux.h"
39
#include "status.h"
40
#include "server.h"
41
#include "output.h"
42
#include "misc.h"
43
#include "list.h"
44
#include "cset.h"
45
#include "hash2.h"
46
#define MAIN_SOURCE
47
#include "modval.h"
48
49
void log_channel(CSetArray *, CSetList *);
50
void limit_channel(CSetArray *, CSetList *);
51
void set_msglog_channel_level(CSetArray *, CSetList *);
52
53
/*
54
* Array of structures for each of the cset vars... allows us to
55
* get an offset into the CSetList struct to that var
56
*/
57
static CSetArray cset_array[] = {
58
{ "AINV", INT_TYPE_VAR, offsetof(CSetList, set_ainv) ,NULL, 0 },
59
{ "ANNOY_KICK", BOOL_TYPE_VAR, offsetof(CSetList, set_annoy_kick) ,NULL, 0 },
60
{ "AOP", BOOL_TYPE_VAR, offsetof(CSetList, set_aop) ,NULL, 0 },
61
{ "AUTO_JOIN_ON_INVITE", BOOL_TYPE_VAR, offsetof(CSetList, set_auto_join_on_invite), NULL, 0 },
62
{ "AUTO_LIMIT", INT_TYPE_VAR, offsetof(CSetList, set_auto_limit), limit_channel, 0 },
63
{ "AUTO_REJOIN", INT_TYPE_VAR, offsetof(CSetList, set_auto_rejoin) ,NULL, 0 },
64
{ "BANTIME", INT_TYPE_VAR, offsetof(CSetList, set_bantime), NULL, 0 },
65
{ "BITCH", BOOL_TYPE_VAR, offsetof(CSetList, bitch_mode) ,NULL, 0 },
66
{ "CHANMODE", STR_TYPE_VAR, offsetof(CSetList, chanmode), NULL, 0 },
67
{ "CHANNEL_LOG", BOOL_TYPE_VAR, offsetof(CSetList, channel_log) ,log_channel, 0 },
68
{ "CHANNEL_LOG_FILE", STR_TYPE_VAR, offsetof(CSetList, channel_log_file), NULL, 0 },
69
{ "CHANNEL_LOG_LEVEL", STR_TYPE_VAR, offsetof(CSetList, log_level), set_msglog_channel_level, 0 },
70
{ "COMPRESS_MODES", BOOL_TYPE_VAR, offsetof(CSetList, compress_modes) ,NULL, 0 },
71
{ "CTCP_FLOOD_BAN", BOOL_TYPE_VAR, offsetof(CSetList, set_ctcp_flood_ban), NULL, 0 },
72
{ "DEOPFLOOD", BOOL_TYPE_VAR, offsetof(CSetList, set_deopflood) ,NULL, 0 },
73
{ "DEOPFLOOD_TIME", INT_TYPE_VAR, offsetof(CSetList, set_deopflood_time) ,NULL, 0 },
74
{ "DEOP_ON_DEOPFLOOD", INT_TYPE_VAR, offsetof(CSetList, set_deop_on_deopflood) ,NULL, 0 },
75
{ "DEOP_ON_KICKFLOOD", INT_TYPE_VAR, offsetof(CSetList, set_deop_on_kickflood) ,NULL, 0 },
76
{ "HACKING", INT_TYPE_VAR, offsetof(CSetList, set_hacking) ,NULL, 0 },
77
{ "JOINFLOOD", BOOL_TYPE_VAR, offsetof(CSetList, set_joinflood) ,NULL, 0 },
78
{ "JOINFLOOD_TIME", INT_TYPE_VAR, offsetof(CSetList, set_joinflood_time) ,NULL, 0 },
79
{ "KICKFLOOD", BOOL_TYPE_VAR, offsetof(CSetList, set_kickflood) ,NULL, 0 },
80
{ "KICKFLOOD_TIME", INT_TYPE_VAR, offsetof(CSetList, set_kickflood_time) ,NULL, 0 },
81
{ "KICK_IF_BANNED", BOOL_TYPE_VAR, offsetof(CSetList, set_kick_if_banned) ,NULL, 0 },
82
{ "KICK_ON_DEOPFLOOD", INT_TYPE_VAR, offsetof(CSetList, set_kick_on_deopflood) ,NULL, 0 },
83
{ "KICK_ON_JOINFLOOD", INT_TYPE_VAR, offsetof(CSetList, set_kick_on_joinflood) ,NULL, 0 },
84
{ "KICK_ON_KICKFLOOD", INT_TYPE_VAR, offsetof(CSetList, set_kick_on_kickflood) ,NULL, 0 },
85
{ "KICK_ON_NICKFLOOD", INT_TYPE_VAR, offsetof(CSetList, set_kick_on_nickflood) ,NULL, 0 },
86
{ "KICK_ON_PUBFLOOD", INT_TYPE_VAR, offsetof(CSetList, set_kick_on_pubflood) ,NULL, 0 },
87
{ "KICK_OPS", BOOL_TYPE_VAR, offsetof(CSetList, set_kick_ops), NULL, 0 },
88
{ "LAMEIDENT", BOOL_TYPE_VAR, offsetof(CSetList, set_lame_ident), NULL, 0},
89
{ "LAMELIST", BOOL_TYPE_VAR, offsetof(CSetList, set_lamelist) ,NULL, 0 },
90
{ "NICKFLOOD", BOOL_TYPE_VAR, offsetof(CSetList, set_nickflood) ,NULL, 0 },
91
{ "NICKFLOOD_TIME", INT_TYPE_VAR, offsetof(CSetList, set_nickflood_time) ,NULL, 0 },
92
{ "PUBFLOOD", BOOL_TYPE_VAR, offsetof(CSetList, set_pubflood) ,NULL, 0 },
93
{ "PUBFLOOD_IGNORE_TIME", INT_TYPE_VAR, offsetof(CSetList, set_pubflood_ignore) ,NULL, 0 },
94
{ "PUBFLOOD_TIME", INT_TYPE_VAR, offsetof(CSetList, set_pubflood_time) ,NULL, 0 },
95
{ "SHITLIST", BOOL_TYPE_VAR, offsetof(CSetList, set_shitlist) ,NULL, 0 },
96
{ "USERLIST", BOOL_TYPE_VAR, offsetof(CSetList, set_userlist) ,NULL, 0 },
97
{ NULL, 0, 0, NULL, 0 }
98
};
99
100
static WSetArray wset_array[] = {
101
{ "STATUS_AWAY", STR_TYPE_VAR, offsetof(WSet, status_away), offsetof(WSet, away_format), BX_build_status },
102
{ "STATUS_CDCCCOUNT", STR_TYPE_VAR, offsetof(WSet, status_cdcccount), offsetof(WSet, cdcc_format), BX_build_status },
103
{ "STATUS_CHANNEL", STR_TYPE_VAR, offsetof(WSet, status_channel), offsetof(WSet, channel_format), BX_build_status },
104
{ "STATUS_CHANOP", STR_TYPE_VAR, offsetof(WSet, status_chanop), -1, BX_build_status },
105
{ "STATUS_CLOCK", STR_TYPE_VAR, offsetof(WSet, status_clock), offsetof(WSet, clock_format), BX_build_status },
106
{ "STATUS_CPU_SAVER", STR_TYPE_VAR, offsetof(WSet, status_cpu_saver), offsetof(WSet, cpu_saver_format), BX_build_status },
107
{ "STATUS_DCCCOUNT", STR_TYPE_VAR, offsetof(WSet, status_dcccount), offsetof(WSet, dcccount_format), BX_build_status },
108
{ "STATUS_FLAG", STR_TYPE_VAR, offsetof(WSet, status_flag), offsetof(WSet, flag_format), BX_build_status },
109
{ "STATUS_FORMAT", STR_TYPE_VAR, offsetof(WSet, format_status), -1, BX_build_status },
110
{ "STATUS_FORMAT1", STR_TYPE_VAR, offsetof(WSet, format_status[1]), -1, BX_build_status },
111
{ "STATUS_FORMAT2", STR_TYPE_VAR, offsetof(WSet, format_status[2]), -1, BX_build_status },
112
{ "STATUS_FORMAT3", STR_TYPE_VAR, offsetof(WSet, format_status[3]), -1, BX_build_status },
113
{ "STATUS_HALFOP", STR_TYPE_VAR, offsetof(WSet, status_halfop), -1, BX_build_status },
114
{ "STATUS_HOLD", STR_TYPE_VAR, offsetof(WSet, status_hold), -1, BX_build_status },
115
{ "STATUS_HOLD_LINES", STR_TYPE_VAR, offsetof(WSet, status_hold_lines), offsetof(WSet, hold_lines_format), BX_build_status },
116
{ "STATUS_LAG", STR_TYPE_VAR, offsetof(WSet, status_lag), offsetof(WSet, lag_format), BX_build_status },
117
{ "STATUS_MAIL", STR_TYPE_VAR, offsetof(WSet, status_mail), offsetof(WSet, mail_format), BX_build_status },
118
{ "STATUS_MODE", STR_TYPE_VAR, offsetof(WSet, status_mode), offsetof(WSet, mode_format), BX_build_status },
119
{ "STATUS_MSGCOUNT", STR_TYPE_VAR, offsetof(WSet, status_msgcount), offsetof(WSet, msgcount_format), BX_build_status },
120
{ "STATUS_NICK", STR_TYPE_VAR, offsetof(WSet, status_nick), offsetof(WSet, nick_format), BX_build_status },
121
{ "STATUS_NOTIFY", STR_TYPE_VAR, offsetof(WSet, status_notify), offsetof(WSet, notify_format), BX_build_status },
122
{ "STATUS_OPER_KILLS", STR_TYPE_VAR, offsetof(WSet, status_oper_kills), offsetof(WSet, kills_format), BX_build_status },
123
{ "STATUS_QUERY", STR_TYPE_VAR, offsetof(WSet, status_query), offsetof(WSet, query_format), BX_build_status },
124
{ "STATUS_SCROLLBACK", STR_TYPE_VAR, offsetof(WSet, status_scrollback), -1, BX_build_status },
125
{ "STATUS_SERVER", STR_TYPE_VAR, offsetof(WSet, status_server), offsetof(WSet, server_format), BX_build_status },
126
{ "STATUS_TOPIC", STR_TYPE_VAR, offsetof(WSet, status_topic), offsetof(WSet, topic_format), BX_build_status },
127
{ "STATUS_UMODE", STR_TYPE_VAR, offsetof(WSet, status_umode), offsetof(WSet, umode_format), BX_build_status },
128
{ "STATUS_USER0", STR_TYPE_VAR, offsetof(WSet, status_user_formats0), -1, BX_build_status },
129
{ "STATUS_USER1", STR_TYPE_VAR, offsetof(WSet, status_user_formats1), -1, BX_build_status },
130
{ "STATUS_USER10", STR_TYPE_VAR, offsetof(WSet, status_user_formats10), -1, BX_build_status },
131
{ "STATUS_USER11", STR_TYPE_VAR, offsetof(WSet, status_user_formats11), -1, BX_build_status },
132
{ "STATUS_USER12", STR_TYPE_VAR, offsetof(WSet, status_user_formats12), -1, BX_build_status },
133
{ "STATUS_USER13", STR_TYPE_VAR, offsetof(WSet, status_user_formats13), -1, BX_build_status },
134
{ "STATUS_USER14", STR_TYPE_VAR, offsetof(WSet, status_user_formats14), -1, BX_build_status },
135
{ "STATUS_USER15", STR_TYPE_VAR, offsetof(WSet, status_user_formats15), -1, BX_build_status },
136
{ "STATUS_USER16", STR_TYPE_VAR, offsetof(WSet, status_user_formats16), -1, BX_build_status },
137
{ "STATUS_USER17", STR_TYPE_VAR, offsetof(WSet, status_user_formats17), -1, BX_build_status },
138
{ "STATUS_USER18", STR_TYPE_VAR, offsetof(WSet, status_user_formats18), -1, BX_build_status },
139
{ "STATUS_USER19", STR_TYPE_VAR, offsetof(WSet, status_user_formats19), -1, BX_build_status },
140
{ "STATUS_USER2", STR_TYPE_VAR, offsetof(WSet, status_user_formats2), -1, BX_build_status },
141
{ "STATUS_USER20", STR_TYPE_VAR, offsetof(WSet, status_user_formats20), -1, BX_build_status },
142
{ "STATUS_USER21", STR_TYPE_VAR, offsetof(WSet, status_user_formats21), -1, BX_build_status },
143
{ "STATUS_USER22", STR_TYPE_VAR, offsetof(WSet, status_user_formats22), -1, BX_build_status },
144
{ "STATUS_USER23", STR_TYPE_VAR, offsetof(WSet, status_user_formats23), -1, BX_build_status },
145
{ "STATUS_USER24", STR_TYPE_VAR, offsetof(WSet, status_user_formats24), -1, BX_build_status },
146
{ "STATUS_USER25", STR_TYPE_VAR, offsetof(WSet, status_user_formats25), -1, BX_build_status },
147
{ "STATUS_USER26", STR_TYPE_VAR, offsetof(WSet, status_user_formats26), -1, BX_build_status },
148
{ "STATUS_USER27", STR_TYPE_VAR, offsetof(WSet, status_user_formats27), -1, BX_build_status },
149
{ "STATUS_USER28", STR_TYPE_VAR, offsetof(WSet, status_user_formats28), -1, BX_build_status },
150
{ "STATUS_USER29", STR_TYPE_VAR, offsetof(WSet, status_user_formats29), -1, BX_build_status },
151
{ "STATUS_USER3", STR_TYPE_VAR, offsetof(WSet, status_user_formats3), -1, BX_build_status },
152
{ "STATUS_USER30", STR_TYPE_VAR, offsetof(WSet, status_user_formats30), -1, BX_build_status },
153
{ "STATUS_USER31", STR_TYPE_VAR, offsetof(WSet, status_user_formats31), -1, BX_build_status },
154
{ "STATUS_USER32", STR_TYPE_VAR, offsetof(WSet, status_user_formats32), -1, BX_build_status },
155
{ "STATUS_USER33", STR_TYPE_VAR, offsetof(WSet, status_user_formats33), -1, BX_build_status },
156
{ "STATUS_USER34", STR_TYPE_VAR, offsetof(WSet, status_user_formats34), -1, BX_build_status },
157
{ "STATUS_USER35", STR_TYPE_VAR, offsetof(WSet, status_user_formats35), -1, BX_build_status },
158
{ "STATUS_USER36", STR_TYPE_VAR, offsetof(WSet, status_user_formats36), -1, BX_build_status },
159
{ "STATUS_USER37", STR_TYPE_VAR, offsetof(WSet, status_user_formats37), -1, BX_build_status },
160
{ "STATUS_USER38", STR_TYPE_VAR, offsetof(WSet, status_user_formats38), -1, BX_build_status },
161
{ "STATUS_USER39", STR_TYPE_VAR, offsetof(WSet, status_user_formats39), -1, BX_build_status },
162
{ "STATUS_USER4", STR_TYPE_VAR, offsetof(WSet, status_user_formats4), -1, BX_build_status },
163
{ "STATUS_USER5", STR_TYPE_VAR, offsetof(WSet, status_user_formats5), -1, BX_build_status },
164
{ "STATUS_USER6", STR_TYPE_VAR, offsetof(WSet, status_user_formats6), -1, BX_build_status },
165
{ "STATUS_USER7", STR_TYPE_VAR, offsetof(WSet, status_user_formats7), -1, BX_build_status },
166
{ "STATUS_USER8", STR_TYPE_VAR, offsetof(WSet, status_user_formats8), -1, BX_build_status },
167
{ "STATUS_USER9", STR_TYPE_VAR, offsetof(WSet, status_user_formats9), -1, BX_build_status },
168
{ "STATUS_USERS", STR_TYPE_VAR, offsetof(WSet, status_users), offsetof(WSet, status_users_format), BX_build_status },
169
{ "STATUS_VOICE", STR_TYPE_VAR, offsetof(WSet, status_voice), -1, BX_build_status },
170
{ "STATUS_WINDOW", STR_TYPE_VAR, offsetof(WSet, status_window), -1, BX_build_status },
171
{ NULL, 0, 0, -1, NULL }
172
};
173
174
CSetList *cset_queue = NULL;
175
176
/*
177
* Returns the address of the requested field within the given CSetList.
178
*/
179
static void *get_cset_var_address(CSetList *tmp, int var)
180
{
181
void *ptr = ((char *)tmp + cset_array[var].offset);
182
return ptr;
183
}
184
185
/*
186
* returns the requested int from the cset struct
187
* Will work fine with either BOOL or INT type of csets.
188
*/
189
int BX_get_cset_int_var(CSetList *tmp, int var)
190
{
191
int *ptr = get_cset_var_address(tmp, var);
192
return *ptr;
193
}
194
195
char *BX_get_cset_str_var(CSetList *tmp, int var)
196
{
197
char **ptr = get_cset_var_address(tmp, var);
198
return *ptr;
199
}
200
201
/*
202
* sets the requested int from the cset struct
203
* Will work fine with either BOOL or INT type of csets.
204
*/
205
void BX_set_cset_int_var(CSetList *tmp, int var, int value)
206
{
207
int *ptr = get_cset_var_address(tmp, var);
208
*ptr = value;
209
}
210
211
void BX_set_cset_str_var(CSetList *tmp, int var, const char *value)
212
{
213
char **ptr = get_cset_var_address(tmp, var);
214
if (value)
215
malloc_strcpy(ptr, value);
216
else
217
new_free(ptr);
218
}
219
220
/*
221
* Next few functions ripped from vars.c, as we are really doing the same
222
* thing as those functions did, with a couple changes... The nice
223
* thing about this is that we will get the same "feel" now with
224
* SET's and CSET's
225
*/
226
static int find_cset_variable(CSetArray *array, char *org_name, int *cnt)
227
{
228
CSetArray *v, *first;
229
int len, var_index;
230
char *name = NULL;
231
232
len = strlen(org_name);
233
name = alloca(len + 1);
234
strcpy(name, org_name);
235
236
upper(name);
237
var_index = 0;
238
for (first = array; first->name; first++, var_index++)
239
{
240
if (strncmp(name, first->name, len) == 0)
241
{
242
*cnt = 1;
243
break;
244
}
245
}
246
if (first->name)
247
{
248
if (strlen(first->name) != len)
249
{
250
v = first;
251
for (v++; v->name; v++, (*cnt)++)
252
{
253
if (strncmp(name, v->name, len) != 0)
254
break;
255
}
256
}
257
return (var_index);
258
}
259
else
260
{
261
*cnt = 0;
262
return (-1);
263
}
264
}
265
266
267
static void set_cset_var_value(CSetList *tmp, int var_index, char *value)
268
{
269
char *rest;
270
CSetArray *var;
271
272
var = &(cset_array[var_index]);
273
274
switch (var->type)
275
{
276
case BOOL_TYPE_VAR:
277
if (value && *value && (value = next_arg(value, &rest))) {
278
if (do_boolean(value, (int *)get_cset_var_address(tmp, var_index)))
279
{
280
say("Value must be either ON, OFF, or TOGGLE");
281
break;
282
}
283
if (var->func)
284
var->func(var, tmp);
285
put_it("%s", convert_output_format(fget_string_var(FORMAT_CSET_FSET), "%s %s %s", var->name, tmp->channel, get_cset_int_var(tmp, var_index)?var_settings[ON] : var_settings[OFF]));
286
}
287
else
288
put_it("%s", convert_output_format(fget_string_var(FORMAT_CSET_FSET), "%s %s %s", var->name, tmp->channel, get_cset_int_var(tmp, var_index)?var_settings[ON] : var_settings[OFF]));
289
break;
290
291
case INT_TYPE_VAR:
292
if (value && *value && (value = next_arg(value, &rest)))
293
{
294
int val;
295
296
if (!is_number(value))
297
{
298
say("Value of %s must be numeric!", var->name);
299
break;
300
}
301
if ((val = atoi(value)) < 0)
302
{
303
say("Value of %s must be greater than 0", var->name);
304
break;
305
}
306
set_cset_int_var(tmp, var_index, val);
307
if (var->func)
308
var->func(var, tmp);
309
put_it("%s", convert_output_format(fget_string_var(FORMAT_CSET_FSET), "%s %s %d", var->name, tmp->channel, get_cset_int_var(tmp, var_index)));
310
}
311
else
312
put_it("%s", convert_output_format(fget_string_var(FORMAT_CSET_FSET), "%s %s %d", var->name, tmp->channel, get_cset_int_var(tmp, var_index)));
313
break;
314
case STR_TYPE_VAR:
315
if (value && *value)
316
{
317
set_cset_str_var(tmp, var_index, value);
318
if (var->func)
319
var->func(var, tmp);
320
put_it("%s", convert_output_format(fget_string_var(FORMAT_CSET_FSET), "%s %s %s", var->name, tmp->channel, get_cset_str_var(tmp, var_index) ));
321
}
322
else
323
put_it("%s", convert_output_format(fget_string_var(FORMAT_CSET_FSET), "%s %s %s", var->name, tmp->channel, (char *)get_cset_str_var(tmp, var_index)));
324
}
325
}
326
327
CSetList *check_cset_queue(char *channel, int add)
328
{
329
CSetList *c = NULL;
330
int found = 0;
331
if (!strchr(channel, '*') && !(c = (CSetList *)find_in_list((List **)&cset_queue, channel, 0)))
332
{
333
if (!add)
334
{
335
for (c = cset_queue; c; c = c->next)
336
if (!my_stricmp(c->channel, channel) || wild_match(c->channel, channel))
337
return c;
338
return NULL;
339
}
340
c = create_csets_for_channel(channel);
341
add_to_list((List **)&cset_queue, (List *)c);
342
found++;
343
}
344
if (c)
345
return c;
346
if (add && !found)
347
{
348
for (c = cset_queue; c; c = c->next)
349
if (!my_stricmp(c->channel, channel))
350
return c;
351
c = create_csets_for_channel(channel);
352
c->next = cset_queue;
353
cset_queue = c;
354
return c;
355
}
356
return NULL;
357
}
358
359
static inline void cset_variable_case1(char *channel, int var_index, char *args)
360
{
361
ChannelList *chan = NULL;
362
int tmp = 0;
363
int count = 0;
364
/*
365
* implement a queue for channels that don't exist... later...
366
* go home if user doesn't have any channels.
367
*/
368
if (current_window->server != -1)
369
{
370
for (chan = get_server_channels(current_window->server); chan; chan = chan->next)
371
{
372
tmp = var_index;
373
if (wild_match(channel, chan->channel))
374
{
375
set_cset_var_value(chan->csets, tmp, args);
376
count++;
377
}
378
}
379
}
380
/* no channel match. lets check the queue */
381
/* if (!count)*/
382
{
383
CSetList *c = NULL;
384
if (!count)
385
check_cset_queue(channel, 1);
386
for (c = cset_queue; c; c = c->next)
387
{
388
tmp = var_index;
389
if (!my_stricmp(channel, c->channel) || wild_match(channel, c->channel))
390
{
391
set_cset_var_value(c, tmp, args);
392
count++;
393
}
394
}
395
if (!count)
396
say("CSET_VARIABLE: No match in cset queue for %s", channel);
397
}
398
}
399
400
static inline void cset_variable_casedef(char *channel, int cnt, int var_index, char *args)
401
{
402
ChannelList *chan = NULL;
403
int tmp, tmp2;
404
int count = 0;
405
406
if (current_window->server != -1)
407
{
408
for (chan = get_server_channels(current_window->server); chan; chan = chan->next)
409
{
410
tmp = var_index;
411
tmp2 = cnt;
412
if (wild_match(channel, chan->channel))
413
{
414
for (tmp2 += tmp; tmp < tmp2; tmp++)
415
set_cset_var_value(chan->csets, tmp, empty_string);
416
count++;
417
}
418
}
419
}
420
/* if (!count) */
421
{
422
CSetList *c = NULL;
423
if (!count)
424
check_cset_queue(channel, 1);
425
for (c = cset_queue; c; c = c->next)
426
{
427
tmp = var_index;
428
tmp2 = cnt;
429
if (!my_stricmp(channel, c->channel) || wild_match(channel, c->channel))
430
{
431
for (tmp2 +=tmp; tmp < tmp2; tmp++)
432
set_cset_var_value(c, tmp, empty_string);
433
count++;
434
}
435
}
436
if (!count)
437
say("CSET_VARIABLE: No match in cset queue for %s", channel);
438
return;
439
}
440
441
}
442
443
static inline void cset_variable_noargs(char *channel)
444
{
445
int var_index = 0;
446
ChannelList *chan = NULL;
447
int count = 0;
448
449
if (current_window->server != -1)
450
{
451
for (chan = get_server_channels(current_window->server); chan; chan = chan->next)
452
{
453
if (wild_match(channel, chan->channel))
454
{
455
for (var_index = 0; var_index < NUMBER_OF_CSETS; var_index++)
456
set_cset_var_value(chan->csets, var_index, empty_string);
457
count++;
458
}
459
}
460
}
461
/* if (!count) */
462
{
463
CSetList *c = NULL;
464
if (!count)
465
check_cset_queue(channel, 1);
466
for (c = cset_queue; c; c = c->next)
467
{
468
if (!wild_match(channel, c->channel))
469
continue;
470
for (var_index = 0; var_index < NUMBER_OF_CSETS; var_index++)
471
set_cset_var_value(c, var_index, empty_string);
472
count++;
473
}
474
if (!count)
475
say("CSET_VARIABLE: No match in cset queue for %s", channel ? channel : empty_string);
476
return;
477
}
478
479
}
480
481
char *set_cset(char *var, ChannelList *chan, char *value)
482
{
483
int var_index, cnt = 0;
484
var_index = find_cset_variable(cset_array, var, &cnt);
485
if (cnt == 1)
486
{
487
CSetArray *var;
488
var = &(cset_array[var_index]);
489
switch(var->type)
490
{
491
case BOOL_TYPE_VAR:
492
{
493
int i = my_atol(value);
494
set_cset_int_var(chan->csets, var_index, i? 1 : 0);
495
break;
496
}
497
case INT_TYPE_VAR:
498
{
499
int i = my_atol(value);
500
set_cset_int_var(chan->csets, var_index, i);
501
break;
502
}
503
case STR_TYPE_VAR:
504
{
505
set_cset_str_var(chan->csets, var_index, value);
506
break;
507
}
508
default:
509
return NULL;
510
}
511
return value;
512
}
513
return NULL;
514
}
515
516
char *get_cset(char *var, ChannelList *chan, char *value)
517
{
518
int var_index, cnt = 0;
519
var_index = find_cset_variable(cset_array, var, &cnt);
520
if (cnt == 1)
521
{
522
char s[81];
523
CSetArray *var;
524
var = &(cset_array[var_index]);
525
*s = 0;
526
switch (var->type)
527
{
528
case BOOL_TYPE_VAR:
529
{
530
strcpy(s, get_cset_int_var(chan->csets, var_index)?var_settings[ON] : var_settings[OFF]);
531
if (value)
532
{
533
int val = -1;
534
if (!my_stricmp(value, on))
535
val = 1;
536
else if (!my_stricmp(value, off))
537
val = 0;
538
else
539
{
540
if (isdigit((unsigned char)*value))
541
val = (int)(*value - '0');
542
}
543
if (val != -1)
544
set_cset_int_var(chan->csets, var_index, val);
545
}
546
break;
547
}
548
case INT_TYPE_VAR:
549
{
550
strncpy(s, ltoa(get_cset_int_var(chan->csets, var_index)), 30);
551
if (value && isdigit((unsigned char)*value))
552
set_cset_int_var(chan->csets, var_index, my_atol(value));
553
break;
554
}
555
case STR_TYPE_VAR:
556
{
557
char *t;
558
t = m_strdup(get_cset_str_var(chan->csets, var_index));
559
if (value)
560
set_cset_str_var(chan->csets, var_index, value);
561
return t;
562
}
563
}
564
return m_strdup(s && *s ? s : empty_string);
565
}
566
return m_strdup(empty_string);
567
}
568
569
BUILT_IN_COMMAND(cset_variable)
570
{
571
char *var, *channel = NULL;
572
int no_args = 1, cnt, var_index, hook = 1;
573
574
if (from_server != -1 && current_window->server != -1)
575
{
576
if (args && *args && (is_channel(args) || *args == '*'))
577
channel = next_arg(args, &args);
578
else
579
channel = get_current_channel_by_refnum(0);
580
}
581
else if (args && *args && (is_channel(args) || *args == '*'))
582
channel = next_arg(args, &args);
583
584
if (!channel)
585
return;
586
587
if ((var = next_arg(args, &args)) != NULL)
588
{
589
if (*var == '-')
590
{
591
var++;
592
args = NULL;
593
}
594
var_index = find_cset_variable(cset_array, var, &cnt);
595
596
if (hook)
597
{
598
switch (cnt)
599
{
600
case 0:
601
say("No such variable \"%s\"", var);
602
return;
603
case 1:
604
cset_variable_case1(channel, var_index, args);
605
return;
606
default:
607
say("%s is ambiguous", var);
608
cset_variable_casedef(channel, cnt, var_index, args);
609
return;
610
}
611
}
612
}
613
if (no_args)
614
cset_variable_noargs(channel);
615
}
616
617
CSetList *create_csets_for_channel(char *channel)
618
{
619
CSetList *tmp;
620
#ifdef VAR_DEBUG
621
int i;
622
623
for (i = 1; i < NUMBER_OF_CSETS - 1; i++)
624
if (strcmp(cset_array[i-1].name, cset_array[i].name) >= 0)
625
ircpanic("Variable [%d] (%s) is out of order.", i, cset_array[i].name);
626
#endif
627
628
if (check_cset_queue(channel, 0))
629
{
630
if ((tmp = (CSetList *)find_in_list((List **)&cset_queue, channel, 0)))
631
return tmp;
632
for (tmp = cset_queue; tmp; tmp = tmp->next)
633
if (!my_stricmp(tmp->channel, channel) || wild_match(tmp->channel, channel))
634
return tmp;
635
}
636
tmp = (CSetList *) new_malloc(sizeof(CSetList));
637
/* use default settings. */
638
tmp->set_aop = get_int_var(AOP_VAR);
639
tmp->set_annoy_kick = get_int_var(ANNOY_KICK_VAR);
640
tmp->set_ainv = get_int_var(AINV_VAR);
641
tmp->set_auto_join_on_invite = get_int_var(AUTO_JOIN_ON_INVITE_VAR);
642
tmp->set_auto_rejoin = get_int_var(AUTO_REJOIN_VAR);
643
tmp->set_bantime = get_int_var(BANTIME_VAR);
644
tmp->compress_modes = get_int_var(COMPRESS_MODES_VAR);
645
tmp->bitch_mode = get_int_var(BITCH_VAR);
646
tmp->channel_log = 0;
647
648
tmp->log_level = m_strdup("ALL");
649
set_msglog_channel_level(cset_array, tmp);
650
#if defined(WINNT) || defined(__EMX__)
651
tmp->channel_log_file = m_sprintf("~/bx-conf/%s.log", channel+1);
652
#else
653
tmp->channel_log_file = m_sprintf("~/.BitchX/%s.log", channel+1);
654
#endif
655
tmp->set_joinflood = get_int_var(JOINFLOOD_VAR);
656
tmp->set_joinflood_time = get_int_var(JOINFLOOD_TIME_VAR);
657
tmp->set_ctcp_flood_ban = get_int_var(CTCP_FLOOD_BAN_VAR);
658
tmp->set_deop_on_deopflood = get_int_var(DEOP_ON_DEOPFLOOD_VAR);
659
tmp->set_deop_on_kickflood = get_int_var(DEOP_ON_KICKFLOOD_VAR);
660
tmp->set_deopflood = get_int_var(DEOPFLOOD_VAR);
661
tmp->set_deopflood_time = get_int_var(DEOPFLOOD_TIME_VAR);
662
663
tmp->set_hacking = get_int_var(HACKING_VAR);
664
665
tmp->set_kick_on_deopflood = get_int_var(KICK_ON_DEOPFLOOD_VAR);
666
tmp->set_kick_on_joinflood = get_int_var(KICK_ON_JOINFLOOD_VAR);
667
tmp->set_kick_on_kickflood = get_int_var(KICK_ON_KICKFLOOD_VAR);
668
tmp->set_kick_on_nickflood = get_int_var(KICK_ON_NICKFLOOD_VAR);
669
tmp->set_kick_on_pubflood = get_int_var(KICK_ON_PUBFLOOD_VAR);
670
671
tmp->set_kickflood = get_int_var(KICKFLOOD_VAR);
672
tmp->set_kickflood_time = get_int_var(KICKFLOOD_TIME_VAR);
673
tmp->set_kick_ops = get_int_var(KICK_OPS_VAR);
674
tmp->set_nickflood = get_int_var(NICKFLOOD_VAR);
675
tmp->set_nickflood_time = get_int_var(NICKFLOOD_TIME_VAR);
676
677
tmp->set_pubflood = get_int_var(PUBFLOOD_VAR);
678
tmp->set_pubflood_time = get_int_var(PUBFLOOD_TIME_VAR);
679
tmp->set_pubflood_ignore = 60;
680
tmp->set_userlist = get_int_var(USERLIST_VAR);
681
tmp->set_shitlist = get_int_var(SHITLIST_VAR);
682
tmp->set_lamelist = get_int_var(LAMELIST_VAR);
683
tmp->set_lame_ident = get_int_var(LAMEIDENT_VAR);
684
tmp->set_kick_if_banned = get_int_var(KICK_IF_BANNED_VAR);
685
tmp->set_auto_limit = get_int_var(AUTO_LIMIT_VAR);
686
687
688
malloc_strcpy(&tmp->chanmode, get_string_var(CHANMODE_VAR));
689
malloc_strcpy(&tmp->channel, channel);
690
691
return tmp;
692
}
693
694
void remove_csets_for_channel(CSetList *tmp)
695
{
696
new_free(&tmp->channel);
697
new_free(&tmp->channel_log_file);
698
new_free(&tmp->chanmode);
699
new_free(&tmp);
700
}
701
702
703
704
static int find_wset_variable(WSetArray *array, char *org_name, int *cnt)
705
{
706
WSetArray *v, *first;
707
int len, var_index;
708
char *name = NULL;
709
710
len = strlen(org_name);
711
name = alloca(len + 1);
712
strcpy(name, org_name);
713
714
upper(name);
715
var_index = 0;
716
for (first = array; first->name; first++, var_index++)
717
{
718
if (strncmp(name, first->name, len) == 0)
719
{
720
*cnt = 1;
721
break;
722
}
723
}
724
if (first->name)
725
{
726
if (strlen(first->name) != len)
727
{
728
v = first;
729
for (v++; v->name; v++, (*cnt)++)
730
{
731
if (strncmp(name, v->name, len) != 0)
732
break;
733
}
734
}
735
return (var_index);
736
}
737
else
738
{
739
*cnt = 0;
740
return (-1);
741
}
742
}
743
744
745
746
747
/*
748
* returns the requested int from the cset struct
749
* Will work fine with either BOOL or INT type of csets.
750
*/
751
char *BX_get_wset_string_var(WSet *tmp, int var)
752
{
753
char **ptr = (char **)((unsigned long)tmp + wset_array[var].offset);
754
return *ptr;
755
}
756
757
/*
758
* returns the requested int ADDRESS from the wset struct
759
* Will work fine with STR_TYPE_VAR type of csets.
760
*/
761
static char ** get_wset_str_var_address(WSet *tmp, int var)
762
{
763
char **ptr = (char **)((unsigned long)tmp + wset_array[var].offset);
764
return ptr;
765
}
766
767
/*
768
* returns the requested int ADDRESS from the wset struct
769
* Will work fine with STR_TYPE_VAR type of csets.
770
*/
771
char ** get_wset_format_var_address(WSet *tmp, int var)
772
{
773
char **ptr = NULL;
774
if (wset_array[var].format_offset != -1)
775
ptr = (char **)((unsigned long)tmp + wset_array[var].format_offset);
776
return ptr;
777
}
778
779
/*
780
* sets the requested string from the wset struct
781
*/
782
783
void BX_set_wset_string_var(WSet *tmp, int var, char *value)
784
{
785
char **ptr = (char **)((unsigned long)tmp + wset_array[var].offset);
786
if (value && *value)
787
malloc_strcpy(ptr, value);
788
else
789
new_free(ptr);
790
}
791
792
793
794
795
796
static void set_wset_var_value(Window *win, int var_index, char *value)
797
{
798
WSetArray *var;
799
800
var = &(wset_array[var_index]);
801
802
switch (var->type)
803
{
804
case STR_TYPE_VAR:
805
{
806
char **val = NULL;
807
if ((val = get_wset_str_var_address(win->wset, var_index)))
808
{
809
if (value)
810
{
811
if (*value)
812
malloc_strcpy(val, value);
813
else
814
{
815
put_it("%s", convert_output_format(fget_string_var(FORMAT_SET_FSET), "%s %s", var->name, *val?*val:empty_string));
816
return;
817
}
818
} else
819
new_free(val);
820
if (var->func)
821
(var->func) (win, *val, 0);
822
say("Value of %s set to %s", var->name, *val ?
823
*val : "<EMPTY>");
824
}
825
}
826
break;
827
default:
828
say("WSET_type not supported");
829
}
830
}
831
832
static inline void wset_variable_case1(Window *win, char *name, int var_index, char *args)
833
{
834
Window *tmp = NULL;
835
int count = 0;
836
int i;
837
if (!name)
838
{
839
set_wset_var_value(win, var_index, args);
840
return;
841
}
842
while ((traverse_all_windows(&tmp)))
843
{
844
i = var_index;
845
if (*name == '*')
846
{
847
set_wset_var_value(tmp, i, args);
848
count++;
849
}
850
else if ((tmp->name && wild_match(name, tmp->name)) || (tmp->refnum == my_atol(name)))
851
{
852
set_wset_var_value(tmp, i, args);
853
count++;
854
}
855
}
856
if (!count)
857
say("No such window name [%s]", name);
858
}
859
860
static inline void wset_variable_casedef(Window *win, char *name, int cnt, int var_index, char *args)
861
{
862
Window *tmp = NULL;
863
int count = 0;
864
int c, i;
865
if (!name)
866
{
867
for (cnt +=var_index; var_index < cnt; var_index++)
868
set_wset_var_value(win, var_index, args);
869
return;
870
}
871
while ((traverse_all_windows(&tmp)))
872
{
873
c = cnt;
874
i = var_index;
875
if (*name == '*')
876
{
877
for (c += i; i < c; i++)
878
set_wset_var_value(tmp, i, empty_string);
879
count++;
880
}
881
else if ((tmp->name && wild_match(name, tmp->name)) || (tmp->refnum == my_atol(name)) )
882
{
883
for (c += i; i < c; i++)
884
set_wset_var_value(tmp, i, empty_string);
885
count++;
886
}
887
}
888
if (!count)
889
say("No such window name [%s]", name);
890
}
891
892
static inline void wset_variable_noargs(Window *win, char *name)
893
{
894
Window *tmp = NULL;
895
int var_index = 0;
896
if (!name)
897
{
898
for (var_index = 0; var_index < NUMBER_OF_WSETS; var_index++)
899
set_wset_var_value(win, var_index, empty_string);
900
}
901
else
902
{
903
int count = 0;
904
while ((traverse_all_windows(&tmp)))
905
{
906
if (*name == '*')
907
{
908
for (var_index = 0; var_index < NUMBER_OF_WSETS; var_index++)
909
set_wset_var_value(tmp, var_index, empty_string);
910
count++;
911
}
912
else if ((tmp->name && wild_match(name, tmp->name)) || (tmp->refnum == my_atol(name)))
913
{
914
for (var_index = 0; var_index < NUMBER_OF_WSETS; var_index++)
915
set_wset_var_value(tmp, var_index, empty_string);
916
count++;
917
}
918
}
919
if (!count)
920
say("No such window name [%s]", name);
921
}
922
}
923
924
925
BUILT_IN_COMMAND(wset_variable)
926
{
927
char *var;
928
char *possible;
929
char *name = NULL;
930
int no_args = 1, cnt, var_index;
931
Window *win = screen_list->window_list;
932
933
if (args)
934
{
935
if (*args == '*')
936
name = next_arg(args, &args);
937
else if (args && *args)
938
{
939
possible = LOCAL_COPY(args);
940
name = next_arg(possible, &possible);
941
if (!(win = get_window_by_name(name)))
942
{
943
win = get_window_by_refnum(my_atol(name));
944
if (!win)
945
{
946
if (isdigit((unsigned char)*name))
947
{
948
say("No such window refnum %d", my_atol(name));
949
return;
950
}
951
}
952
else if (isdigit((unsigned char)*name))
953
var = next_arg(args, &args);
954
name = NULL;
955
}
956
else
957
var = next_arg(args, &args);
958
}
959
}
960
else
961
win = current_window;
962
963
964
if ((var = next_arg(args, &args)) != NULL)
965
{
966
if (*var == '-')
967
{
968
var++;
969
args = NULL;
970
}
971
var_index = find_wset_variable(wset_array, var, &cnt);
972
switch (cnt)
973
{
974
case 0:
975
say("No such variable \"%s\"", var);
976
return;
977
case 1:
978
wset_variable_case1(win, name, var_index, args);
979
update_all_status(win, NULL, 0);
980
update_all_windows();
981
return;
982
default:
983
say("%s is ambiguous", var);
984
wset_variable_casedef(win, name, cnt, var_index, args);
985
return;
986
}
987
}
988
if (no_args)
989
wset_variable_noargs(win, name);
990
}
991
992
993
WSet *create_wsets_for_window(Window *win)
994
{
995
WSet *tmp;
996
#ifdef VAR_DEBUG
997
int i;
998
999
for (i = 1; i < NUMBER_OF_CSETS - 1; i++)
1000
if (strcmp(wset_array[i-1].name, wset_array[i].name) >= 0)
1001
ircpanic("Variable [%d] (%s) is out of order.", i, wset_array[i].name);
1002
#endif
1003
1004
tmp = (WSet *) new_malloc(sizeof(WSet));
1005
1006
malloc_strcpy(&tmp->status_channel, get_string_var(STATUS_CHANNEL_VAR));
1007
malloc_strcpy(&tmp->status_chanop, get_string_var(STATUS_CHANOP_VAR));
1008
malloc_strcpy(&tmp->status_halfop, get_string_var(STATUS_HALFOP_VAR));
1009
malloc_strcpy(&tmp->status_clock, get_string_var(STATUS_CLOCK_VAR));
1010
malloc_strcpy(&tmp->status_hold_lines, get_string_var(STATUS_HOLD_LINES_VAR));
1011
malloc_strcpy(&tmp->status_hold, get_string_var(STATUS_HOLD_VAR));
1012
malloc_strcpy(&tmp->status_voice, get_string_var(STATUS_VOICE_VAR));
1013
malloc_strcpy(&tmp->status_dcccount, get_string_var(STATUS_DCCCOUNT_VAR));
1014
malloc_strcpy(&tmp->status_cdcccount, get_string_var(STATUS_CDCCCOUNT_VAR));
1015
malloc_strcpy(&tmp->status_cpu_saver, get_string_var(STATUS_CPU_SAVER_VAR));
1016
malloc_strcpy(&tmp->status_lag, get_string_var(STATUS_LAG_VAR));
1017
malloc_strcpy(&tmp->status_away, get_string_var(STATUS_AWAY_VAR));
1018
malloc_strcpy(&tmp->status_mail, get_string_var(STATUS_MAIL_VAR));
1019
malloc_strcpy(&tmp->status_mode, get_string_var(STATUS_MODE_VAR));
1020
malloc_strcpy(&tmp->status_notify, get_string_var(STATUS_NOTIFY_VAR));
1021
malloc_strcpy(&tmp->status_oper_kills, get_string_var(STATUS_OPER_KILLS_VAR));
1022
malloc_strcpy(&tmp->status_query, get_string_var(STATUS_QUERY_VAR));
1023
malloc_strcpy(&tmp->status_server, get_string_var(STATUS_SERVER_VAR));
1024
malloc_strcpy(&tmp->status_topic, get_string_var(STATUS_TOPIC_VAR));
1025
malloc_strcpy(&tmp->status_umode, get_string_var(STATUS_UMODE_VAR));
1026
malloc_strcpy(&tmp->status_users, get_string_var(STATUS_USERS_VAR));
1027
malloc_strcpy(&tmp->status_msgcount, get_string_var(STATUS_MSGCOUNT_VAR));
1028
malloc_strcpy(&tmp->status_nick, get_string_var(STATUS_NICK_VAR));
1029
malloc_strcpy(&tmp->status_flag, get_string_var(STATUS_FLAG_VAR));
1030
malloc_strcpy(&tmp->status_scrollback, get_string_var(STATUS_SCROLLBACK_VAR));
1031
1032
malloc_strcpy(&tmp->format_status[0], get_string_var(STATUS_FORMAT_VAR));
1033
malloc_strcpy(&tmp->format_status[1], get_string_var(STATUS_FORMAT1_VAR));
1034
malloc_strcpy(&tmp->format_status[2], get_string_var(STATUS_FORMAT2_VAR));
1035
malloc_strcpy(&tmp->format_status[3], get_string_var(STATUS_FORMAT3_VAR));
1036
1037
malloc_strcpy(&tmp->status_user_formats0, get_string_var(STATUS_USER0_VAR));
1038
malloc_strcpy(&tmp->status_user_formats1, get_string_var(STATUS_USER1_VAR));
1039
malloc_strcpy(&tmp->status_user_formats10, get_string_var(STATUS_USER10_VAR));
1040
malloc_strcpy(&tmp->status_user_formats11, get_string_var(STATUS_USER11_VAR));
1041
malloc_strcpy(&tmp->status_user_formats12, get_string_var(STATUS_USER12_VAR));
1042
malloc_strcpy(&tmp->status_user_formats13, get_string_var(STATUS_USER13_VAR));
1043
malloc_strcpy(&tmp->status_user_formats14, get_string_var(STATUS_USER14_VAR));
1044
malloc_strcpy(&tmp->status_user_formats15, get_string_var(STATUS_USER15_VAR));
1045
malloc_strcpy(&tmp->status_user_formats16, get_string_var(STATUS_USER16_VAR));
1046
malloc_strcpy(&tmp->status_user_formats17, get_string_var(STATUS_USER17_VAR));
1047
malloc_strcpy(&tmp->status_user_formats18, get_string_var(STATUS_USER18_VAR));
1048
malloc_strcpy(&tmp->status_user_formats19, get_string_var(STATUS_USER19_VAR));
1049
malloc_strcpy(&tmp->status_user_formats2, get_string_var(STATUS_USER2_VAR));
1050
malloc_strcpy(&tmp->status_user_formats20, get_string_var(STATUS_USER20_VAR));
1051
malloc_strcpy(&tmp->status_user_formats21, get_string_var(STATUS_USER21_VAR));
1052
malloc_strcpy(&tmp->status_user_formats22, get_string_var(STATUS_USER22_VAR));
1053
malloc_strcpy(&tmp->status_user_formats23, get_string_var(STATUS_USER23_VAR));
1054
malloc_strcpy(&tmp->status_user_formats24, get_string_var(STATUS_USER24_VAR));
1055
malloc_strcpy(&tmp->status_user_formats25, get_string_var(STATUS_USER25_VAR));
1056
malloc_strcpy(&tmp->status_user_formats26, get_string_var(STATUS_USER26_VAR));
1057
malloc_strcpy(&tmp->status_user_formats27, get_string_var(STATUS_USER27_VAR));
1058
malloc_strcpy(&tmp->status_user_formats28, get_string_var(STATUS_USER28_VAR));
1059
malloc_strcpy(&tmp->status_user_formats29, get_string_var(STATUS_USER29_VAR));
1060
malloc_strcpy(&tmp->status_user_formats3, get_string_var(STATUS_USER3_VAR));
1061
malloc_strcpy(&tmp->status_user_formats30, get_string_var(STATUS_USER30_VAR));
1062
malloc_strcpy(&tmp->status_user_formats31, get_string_var(STATUS_USER31_VAR));
1063
malloc_strcpy(&tmp->status_user_formats32, get_string_var(STATUS_USER32_VAR));
1064
malloc_strcpy(&tmp->status_user_formats33, get_string_var(STATUS_USER33_VAR));
1065
malloc_strcpy(&tmp->status_user_formats34, get_string_var(STATUS_USER34_VAR));
1066
malloc_strcpy(&tmp->status_user_formats35, get_string_var(STATUS_USER35_VAR));
1067
malloc_strcpy(&tmp->status_user_formats36, get_string_var(STATUS_USER36_VAR));
1068
malloc_strcpy(&tmp->status_user_formats37, get_string_var(STATUS_USER37_VAR));
1069
malloc_strcpy(&tmp->status_user_formats38, get_string_var(STATUS_USER38_VAR));
1070
malloc_strcpy(&tmp->status_user_formats39, get_string_var(STATUS_USER39_VAR));
1071
malloc_strcpy(&tmp->status_user_formats4, get_string_var(STATUS_USER4_VAR));
1072
malloc_strcpy(&tmp->status_user_formats5, get_string_var(STATUS_USER5_VAR));
1073
malloc_strcpy(&tmp->status_user_formats6, get_string_var(STATUS_USER6_VAR));
1074
malloc_strcpy(&tmp->status_user_formats7, get_string_var(STATUS_USER7_VAR));
1075
malloc_strcpy(&tmp->status_user_formats8, get_string_var(STATUS_USER8_VAR));
1076
malloc_strcpy(&tmp->status_user_formats9, get_string_var(STATUS_USER9_VAR));
1077
malloc_strcpy(&tmp->status_window, get_string_var(STATUS_WINDOW_VAR));
1078
win->wset = tmp;
1079
return tmp;
1080
}
1081
1082
void remove_wsets_for_window(Window *tmp)
1083
{
1084
new_free(&tmp->wset->status_channel);
1085
new_free(&tmp->wset->status_clock);
1086
new_free(&tmp->wset->status_hold_lines);
1087
new_free(&tmp->wset->status_hold);
1088
new_free(&tmp->wset->status_voice);
1089
new_free(&tmp->wset->status_dcccount);
1090
new_free(&tmp->wset->status_cdcccount);
1091
new_free(&tmp->wset->status_lag);
1092
new_free(&tmp->wset->status_away);
1093
new_free(&tmp->wset->status_nick);
1094
new_free(&tmp->wset->status_flag);
1095
new_free(&tmp->wset->status_mail);
1096
new_free(&tmp->wset->status_msgcount);
1097
new_free(&tmp->wset->status_cpu_saver);
1098
new_free(&tmp->wset->status_chanop);
1099
new_free(&tmp->wset->status_mode);
1100
1101
new_free(&tmp->wset->status_notify);
1102
new_free(&tmp->wset->status_oper_kills);
1103
new_free(&tmp->wset->status_query);
1104
new_free(&tmp->wset->status_server);
1105
new_free(&tmp->wset->status_topic);
1106
new_free(&tmp->wset->status_umode);
1107
new_free(&tmp->wset->status_users);
1108
new_free(&tmp->wset->status_scrollback);
1109
new_free(&tmp->wset->status_halfop);
1110
1111
new_free(&tmp->wset->status_user_formats1);
1112
new_free(&tmp->wset->status_user_formats10);
1113
new_free(&tmp->wset->status_user_formats11);
1114
new_free(&tmp->wset->status_user_formats12);
1115
new_free(&tmp->wset->status_user_formats13);
1116
new_free(&tmp->wset->status_user_formats14);
1117
new_free(&tmp->wset->status_user_formats15);
1118
new_free(&tmp->wset->status_user_formats16);
1119
new_free(&tmp->wset->status_user_formats17);
1120
new_free(&tmp->wset->status_user_formats18);
1121
new_free(&tmp->wset->status_user_formats19);
1122
new_free(&tmp->wset->status_user_formats2);
1123
new_free(&tmp->wset->status_user_formats20);
1124
new_free(&tmp->wset->status_user_formats21);
1125
new_free(&tmp->wset->status_user_formats22);
1126
new_free(&tmp->wset->status_user_formats23);
1127
new_free(&tmp->wset->status_user_formats24);
1128
new_free(&tmp->wset->status_user_formats25);
1129
new_free(&tmp->wset->status_user_formats26);
1130
new_free(&tmp->wset->status_user_formats27);
1131
new_free(&tmp->wset->status_user_formats28);
1132
new_free(&tmp->wset->status_user_formats29);
1133
new_free(&tmp->wset->status_user_formats3);
1134
new_free(&tmp->wset->status_user_formats30);
1135
new_free(&tmp->wset->status_user_formats31);
1136
new_free(&tmp->wset->status_user_formats32);
1137
new_free(&tmp->wset->status_user_formats33);
1138
new_free(&tmp->wset->status_user_formats34);
1139
new_free(&tmp->wset->status_user_formats35);
1140
new_free(&tmp->wset->status_user_formats36);
1141
new_free(&tmp->wset->status_user_formats37);
1142
new_free(&tmp->wset->status_user_formats38);
1143
new_free(&tmp->wset->status_user_formats39);
1144
new_free(&tmp->wset->status_user_formats4);
1145
new_free(&tmp->wset->status_user_formats5);
1146
new_free(&tmp->wset->status_user_formats6);
1147
new_free(&tmp->wset->status_user_formats7);
1148
new_free(&tmp->wset->status_user_formats8);
1149
new_free(&tmp->wset->status_user_formats9);
1150
new_free(&tmp->wset->status_user_formats0);
1151
1152
new_free(&tmp->wset->format_status[0]);
1153
new_free(&tmp->wset->format_status[1]);
1154
new_free(&tmp->wset->format_status[2]);
1155
new_free(&tmp->wset->format_status[3]);
1156
1157
new_free(&tmp->wset->status_format[0]);
1158
new_free(&tmp->wset->status_format[1]);
1159
new_free(&tmp->wset->status_format[2]);
1160
new_free(&tmp->wset->status_format[3]);
1161
new_free(&tmp->wset->status_line[0]);
1162
new_free(&tmp->wset->status_line[1]);
1163
new_free(&tmp->wset->status_line[2]);
1164
1165
new_free(&tmp->wset->mode_format);
1166
new_free(&tmp->wset->umode_format);
1167
new_free(&tmp->wset->topic_format);
1168
new_free(&tmp->wset->query_format);
1169
new_free(&tmp->wset->clock_format);
1170
new_free(&tmp->wset->hold_lines_format);
1171
new_free(&tmp->wset->channel_format);
1172
new_free(&tmp->wset->mail_format);
1173
new_free(&tmp->wset->server_format);
1174
new_free(&tmp->wset->notify_format);
1175
new_free(&tmp->wset->kills_format);
1176
new_free(&tmp->wset->lag_format);
1177
new_free(&tmp->wset->cpu_saver_format);
1178
new_free(&tmp->wset->msgcount_format);
1179
new_free(&tmp->wset->dcccount_format);
1180
new_free(&tmp->wset->cdcc_format);
1181
new_free(&tmp->wset->nick_format);
1182
new_free(&tmp->wset->away_format);
1183
new_free(&tmp->wset->flag_format);
1184
new_free(&tmp->wset->status_users_format);
1185
new_free(&tmp->wset->status_window);
1186
new_free(&tmp->wset->window_special_format);
1187
new_free(&tmp->wset);
1188
}
1189
1190
void log_channel(CSetArray *var, CSetList *cs)
1191
{
1192
ChannelList *chan;
1193
if (!cs->channel_log_file)
1194
{
1195
bitchsay("Try setting a channel log file first");
1196
set_cset_int_var(cs, CHANNEL_LOG_CSET, 0);
1197
return;
1198
}
1199
if ((chan = lookup_channel(cs->channel, from_server, 0)))
1200
do_log(cs->channel_log, cs->channel_log_file, &chan->msglog_fp);
1201
}
1202
1203
void set_msglog_channel_level(CSetArray *var, CSetList *cs)
1204
{
1205
ChannelList *chan;
1206
if ((chan = lookup_channel(cs->channel, from_server, 0)))
1207
{
1208
chan->log_level = parse_lastlog_level(cs->log_level, 1);
1209
set_cset_str_var(cs, CHANNEL_LOG_LEVEL_CSET, bits_to_lastlog_level(chan->log_level));
1210
}
1211
}
1212
1213
void do_logchannel(unsigned long level, ChannelList *chan, char *format, ...)
1214
{
1215
if (!chan || !get_cset_int_var(chan->csets, CHANNEL_LOG_CSET))
1216
return;
1217
if ((chan->log_level & level) && format)
1218
{
1219
char s[BIG_BUFFER_SIZE+1];
1220
va_list args;
1221
va_start(args, format);
1222
vsnprintf(s, BIG_BUFFER_SIZE, format, args);
1223
va_end(args);
1224
add_to_log(chan->msglog_fp, now, s, logfile_line_mangler);
1225
}
1226
}
1227
1228
void set_channel_limit(ChannelList *channel, int currentlimit, int add, int numusers)
1229
{
1230
if ((now - channel->limit_time) < 30)
1231
return;
1232
if (add && numusers)
1233
{
1234
if ((currentlimit - numusers) < (add / 2) && ((numusers + add) != currentlimit))
1235
my_send_to_server(channel->server, "MODE %s +l %d", channel->channel, numusers + add);
1236
else if ((currentlimit - numusers) > (currentlimit + (add / 2)) && ((numusers + add) != currentlimit))
1237
my_send_to_server(channel->server, "MODE %s +l %d", channel->channel, numusers + add);
1238
}
1239
else
1240
my_send_to_server(channel->server, "MODE %s -l", channel->channel);
1241
channel->limit_time = now;
1242
}
1243
1244
void check_channel_limit(ChannelList *chan)
1245
{
1246
if (chan && chan->csets && chan->csets->set_auto_limit && chan->have_op)
1247
{
1248
int count = 0;
1249
NickList *nick;
1250
for (nick = next_nicklist(chan, NULL); nick; nick = next_nicklist(chan, nick))
1251
count++;
1252
set_channel_limit(chan, chan->limit, chan->csets->set_auto_limit, count);
1253
}
1254
}
1255
1256
void limit_channel(CSetArray *var, CSetList *cs)
1257
{
1258
ChannelList *chan;
1259
if ((chan = lookup_channel(cs->channel, from_server, 0)))
1260
{
1261
if (cs->set_auto_limit)
1262
{
1263
int count = 0;
1264
NickList *nick;
1265
for (nick = next_nicklist(chan, NULL); nick; nick = next_nicklist(chan, nick))
1266
count++;
1267
set_channel_limit(chan, chan->limit, cs->set_auto_limit, count);
1268
} else
1269
set_channel_limit(chan, chan->limit, 0, 0);
1270
}
1271
}
1272
1273
#ifdef GUI
1274
CSetArray *return_cset_var(int nummer)
1275
{
1276
return &cset_array[nummer];
1277
}
1278
1279
WSetArray *return_wset_var(int nummer)
1280
{
1281
return &wset_array[nummer];
1282
}
1283
#endif
1284
1285
1286