File: cset.c

package info (click to toggle)
ircii-pana 1%3A1.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 14,048 kB
  • ctags: 14,567
  • sloc: ansic: 130,654; sql: 6,041; makefile: 4,313; cpp: 1,270; tcl: 1,230; sh: 638; java: 151
file content (1308 lines) | stat: -rw-r--r-- 44,452 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
/************
 *  cset.c  *
 ************
 *
 * My code for creating all the "Channel Sets" on a per channel
 * basis. We manage them here, and then just insert/remove/return them 
 * when a channel calls for them.
 * Code for creating and modifying "Window Sets" on a per window
 * basis. 
 *
 * Note: Notice the shameless use of typecasting to get these functions
 *	 to work as painlessly as possible.
 *
 * Written by Scott H Kilau
 * Modified by Colten D Edwards for /wset
 *
 * Copyright(c) 1997
 *
 * See the COPYRIGHT file, or do a HELP IRCII COPYRIGHT
 */

#if 0
[Sheik(~sheik@spartan.pei.edu)] notice in struct.h that the cset struct *does*
          have a ->next pointer.. thats for the future when we may want to
                    daisy chain cset's that don't have channels yet..  ie  a user can
                              /cset *warez*  and know that all warez channels would get defaulted
#endif                              

#include "irc.h"
static char cvsrevision[] = "$Id: cset.c,v 1.1.1.1 2003/04/11 01:09:07 dan Exp $";
CVS_REVISION(cset_c)
#include "struct.h"
#include "vars.h"    /* for do_boolean() and var_settings[] */
#include "window.h"  /* for get_current_channel_by_refnum() */
#include "screen.h"  /* for curr_scr_win */
#include "names.h"   /* for lookup_channel() */
#include "log.h"
#include "ircaux.h"
#include "status.h"
#include "server.h"
#include "output.h"
#include "misc.h"
#include "list.h"
#include "cset.h"
#include "hash2.h"
#define MAIN_SOURCE
#include "modval.h"

void log_channel(CSetArray *, CSetList *);
void limit_channel(CSetArray *, CSetList *);
void set_msglog_channel_level(CSetArray *, CSetList *);

/*
 * Array of structures for each of the cset vars... allows us to
 * get an offset into the CSetList struct to that var
 */
static CSetArray cset_array[] = {
{ "AINV",			INT_TYPE_VAR,	offsetof(CSetList, set_ainv) ,NULL, 0 },
{ "ANNOY_KICK",			BOOL_TYPE_VAR,	offsetof(CSetList, set_annoy_kick) ,NULL, 0 },
{ "AOP",			BOOL_TYPE_VAR,	offsetof(CSetList, set_aop) ,NULL, 0 },
{ "AUTO_JOIN_ON_INVITE",	BOOL_TYPE_VAR,	offsetof(CSetList, set_auto_join_on_invite), NULL, 0 },
{ "AUTO_LIMIT",			INT_TYPE_VAR,	offsetof(CSetList, set_auto_limit), limit_channel, 0 },
{ "AUTO_REJOIN",		INT_TYPE_VAR,   offsetof(CSetList, set_auto_rejoin) ,NULL, 0 },
{ "BANTIME",			INT_TYPE_VAR,	offsetof(CSetList, set_bantime), NULL, 0 },
{ "BITCH",			BOOL_TYPE_VAR,	offsetof(CSetList, bitch_mode) ,NULL, 0 },
{ "CHANMODE",			STR_TYPE_VAR,	offsetof(CSetList, chanmode), NULL, 0 },
{ "CHANNEL_LOG",		BOOL_TYPE_VAR,	offsetof(CSetList, channel_log) ,log_channel, 0 },
{ "CHANNEL_LOG_FILE",		STR_TYPE_VAR,	offsetof(CSetList, channel_log_file), NULL, 0 },
{ "CHANNEL_LOG_LEVEL",		STR_TYPE_VAR,	offsetof(CSetList, log_level), set_msglog_channel_level, 0 },
{ "COMPRESS_MODES",		BOOL_TYPE_VAR,	offsetof(CSetList, compress_modes) ,NULL, 0 },
{ "CTCP_FLOOD_BAN",		BOOL_TYPE_VAR,	offsetof(CSetList, set_ctcp_flood_ban), NULL, 0 },
{ "DEOPFLOOD",			BOOL_TYPE_VAR,	offsetof(CSetList, set_deopflood) ,NULL, 0 },
{ "DEOPFLOOD_TIME",		INT_TYPE_VAR,	offsetof(CSetList, set_deopflood_time) ,NULL, 0 },
{ "DEOP_ON_DEOPFLOOD",		INT_TYPE_VAR,	offsetof(CSetList, set_deop_on_deopflood) ,NULL, 0 },
{ "DEOP_ON_KICKFLOOD",		INT_TYPE_VAR,	offsetof(CSetList, set_deop_on_kickflood) ,NULL, 0 },
{ "HACKING",			INT_TYPE_VAR,	offsetof(CSetList, set_hacking) ,NULL, 0 },
{ "JOINFLOOD",			BOOL_TYPE_VAR,	offsetof(CSetList, set_joinflood) ,NULL, 0 },
{ "JOINFLOOD_TIME",		INT_TYPE_VAR,	offsetof(CSetList, set_joinflood_time) ,NULL, 0 },
{ "KICKFLOOD",			BOOL_TYPE_VAR,	offsetof(CSetList, set_kickflood) ,NULL, 0 },
{ "KICKFLOOD_TIME",		INT_TYPE_VAR,	offsetof(CSetList, set_kickflood_time) ,NULL, 0 },
{ "KICK_IF_BANNED",		BOOL_TYPE_VAR,  offsetof(CSetList, set_kick_if_banned) ,NULL, 0 },
{ "KICK_ON_DEOPFLOOD",		INT_TYPE_VAR,   offsetof(CSetList, set_kick_on_deopflood) ,NULL, 0 },
{ "KICK_ON_JOINFLOOD",		INT_TYPE_VAR,	offsetof(CSetList, set_kick_on_joinflood) ,NULL, 0 },
{ "KICK_ON_KICKFLOOD",		INT_TYPE_VAR,   offsetof(CSetList, set_kick_on_kickflood) ,NULL, 0 },
{ "KICK_ON_NICKFLOOD",		INT_TYPE_VAR,   offsetof(CSetList, set_kick_on_nickflood) ,NULL, 0 },
{ "KICK_ON_PUBFLOOD",		INT_TYPE_VAR,   offsetof(CSetList, set_kick_on_pubflood) ,NULL, 0 },
{ "KICK_OPS",			BOOL_TYPE_VAR,	offsetof(CSetList, set_kick_ops), NULL, 0 },
{ "LAMEIDENT",			BOOL_TYPE_VAR,	offsetof(CSetList, set_lame_ident), NULL, 0},
{ "LAMELIST",			BOOL_TYPE_VAR,  offsetof(CSetList, set_lamelist) ,NULL, 0 },
{ "NICKFLOOD",			BOOL_TYPE_VAR,	offsetof(CSetList, set_nickflood) ,NULL, 0 },
{ "NICKFLOOD_TIME",		INT_TYPE_VAR,	offsetof(CSetList, set_nickflood_time) ,NULL, 0 },
{ "PUBFLOOD",			BOOL_TYPE_VAR,	offsetof(CSetList, set_pubflood) ,NULL, 0 },
{ "PUBFLOOD_IGNORE_TIME",	INT_TYPE_VAR,	offsetof(CSetList, set_pubflood_ignore) ,NULL, 0 },
{ "PUBFLOOD_TIME",		INT_TYPE_VAR,	offsetof(CSetList, set_pubflood_time) ,NULL, 0 },
{ "SHITLIST",			BOOL_TYPE_VAR,  offsetof(CSetList, set_shitlist) ,NULL, 0 },
{ "USERLIST",			BOOL_TYPE_VAR,  offsetof(CSetList, set_userlist) ,NULL, 0 },
{ NULL,				0,		0, NULL, 0 }
};

static WSetArray wset_array[] = {
{ "STATUS_AWAY",		STR_TYPE_VAR,	offsetof(WSet, status_away),		offsetof(WSet, away_format), BX_build_status },
{ "STATUS_CDCCCOUNT",		STR_TYPE_VAR,	offsetof(WSet, status_cdcccount),	offsetof(WSet, cdcc_format), BX_build_status },
{ "STATUS_CHANNEL",		STR_TYPE_VAR,	offsetof(WSet, status_channel),		offsetof(WSet, channel_format), BX_build_status },
{ "STATUS_CHANOP",		STR_TYPE_VAR,	offsetof(WSet, status_chanop),		-1, BX_build_status },
{ "STATUS_CLOCK",		STR_TYPE_VAR,	offsetof(WSet, status_clock),		offsetof(WSet, clock_format), BX_build_status },
{ "STATUS_CPU_SAVER",		STR_TYPE_VAR,	offsetof(WSet, status_cpu_saver), 	offsetof(WSet, cpu_saver_format), BX_build_status },
{ "STATUS_DCCCOUNT",		STR_TYPE_VAR,	offsetof(WSet, status_dcccount),	offsetof(WSet, dcccount_format), BX_build_status },
{ "STATUS_FLAG",		STR_TYPE_VAR,   offsetof(WSet, status_flag),		offsetof(WSet, flag_format), BX_build_status },
{ "STATUS_FORMAT",              STR_TYPE_VAR,   offsetof(WSet, format_status),		-1, BX_build_status },
{ "STATUS_FORMAT1",             STR_TYPE_VAR,   offsetof(WSet, format_status[1]),	-1, BX_build_status },
{ "STATUS_FORMAT2",             STR_TYPE_VAR,   offsetof(WSet, format_status[2]),	-1, BX_build_status },
{ "STATUS_FORMAT3",             STR_TYPE_VAR,   offsetof(WSet, format_status[3]),	-1, BX_build_status },
{ "STATUS_HALFOP",		STR_TYPE_VAR,	offsetof(WSet, status_halfop),		-1, BX_build_status },
{ "STATUS_HOLD",		STR_TYPE_VAR,	offsetof(WSet, status_hold),		-1, BX_build_status },
{ "STATUS_HOLD_LINES",		STR_TYPE_VAR,	offsetof(WSet, status_hold_lines),	offsetof(WSet, hold_lines_format), BX_build_status },
{ "STATUS_LAG",			STR_TYPE_VAR,	offsetof(WSet, status_lag),		offsetof(WSet, lag_format), BX_build_status },
{ "STATUS_MAIL",		STR_TYPE_VAR,	offsetof(WSet, status_mail),		offsetof(WSet, mail_format), BX_build_status },
{ "STATUS_MODE",		STR_TYPE_VAR,	offsetof(WSet, status_mode),		offsetof(WSet, mode_format), BX_build_status },
{ "STATUS_MSGCOUNT",		STR_TYPE_VAR,	offsetof(WSet, status_msgcount),	offsetof(WSet, msgcount_format), BX_build_status },
{ "STATUS_NICK",		STR_TYPE_VAR,	offsetof(WSet, status_nick),		offsetof(WSet, nick_format), BX_build_status },
{ "STATUS_NOTIFY",		STR_TYPE_VAR,	offsetof(WSet, status_notify),		offsetof(WSet, notify_format), BX_build_status },
{ "STATUS_OPER_KILLS",		STR_TYPE_VAR,	offsetof(WSet, status_oper_kills),	offsetof(WSet, kills_format), BX_build_status },
{ "STATUS_QUERY",		STR_TYPE_VAR,	offsetof(WSet, status_query),		offsetof(WSet, query_format), BX_build_status },
{ "STATUS_SCROLLBACK",		STR_TYPE_VAR,	offsetof(WSet, status_scrollback),	-1, BX_build_status },
{ "STATUS_SERVER",		STR_TYPE_VAR,	offsetof(WSet, status_server),		offsetof(WSet, server_format), BX_build_status },
{ "STATUS_TOPIC",		STR_TYPE_VAR,	offsetof(WSet, status_topic),		offsetof(WSet, topic_format), BX_build_status },
{ "STATUS_UMODE",		STR_TYPE_VAR,	offsetof(WSet, status_umode),		offsetof(WSet, umode_format), BX_build_status },
{ "STATUS_USER0",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats0),	-1, BX_build_status },
{ "STATUS_USER1",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats1),	-1, BX_build_status },
{ "STATUS_USER10",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats10),	-1, BX_build_status },
{ "STATUS_USER11",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats11),	-1, BX_build_status },
{ "STATUS_USER12",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats12),	-1, BX_build_status },
{ "STATUS_USER13",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats13),	-1, BX_build_status },
{ "STATUS_USER14",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats14),	-1, BX_build_status },
{ "STATUS_USER15",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats15),	-1, BX_build_status },
{ "STATUS_USER16",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats16),	-1, BX_build_status },
{ "STATUS_USER17",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats17),	-1, BX_build_status },
{ "STATUS_USER18",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats18),	-1, BX_build_status },
{ "STATUS_USER19",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats19),	-1, BX_build_status },
{ "STATUS_USER2",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats2),	-1, BX_build_status },
{ "STATUS_USER20",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats20),	-1, BX_build_status },
{ "STATUS_USER21",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats21),	-1, BX_build_status },
{ "STATUS_USER22",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats22),	-1, BX_build_status },
{ "STATUS_USER23",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats23),	-1, BX_build_status },
{ "STATUS_USER24",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats24),	-1, BX_build_status },
{ "STATUS_USER25",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats25),	-1, BX_build_status },
{ "STATUS_USER26",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats26),	-1, BX_build_status },
{ "STATUS_USER27",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats27),	-1, BX_build_status },
{ "STATUS_USER28",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats28),	-1, BX_build_status },
{ "STATUS_USER29",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats29),	-1, BX_build_status },
{ "STATUS_USER3",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats3),	-1, BX_build_status },
{ "STATUS_USER30",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats30),	-1, BX_build_status },
{ "STATUS_USER31",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats31),	-1, BX_build_status },
{ "STATUS_USER32",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats32),	-1, BX_build_status },
{ "STATUS_USER33",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats33),	-1, BX_build_status },
{ "STATUS_USER34",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats34),	-1, BX_build_status },
{ "STATUS_USER35",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats35),	-1, BX_build_status },
{ "STATUS_USER36",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats36),	-1, BX_build_status },
{ "STATUS_USER37",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats37),	-1, BX_build_status },
{ "STATUS_USER38",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats38),	-1, BX_build_status },
{ "STATUS_USER39",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats39),	-1, BX_build_status },
{ "STATUS_USER4",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats4),	-1, BX_build_status },
{ "STATUS_USER5",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats5),	-1, BX_build_status },
{ "STATUS_USER6",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats6),	-1, BX_build_status },
{ "STATUS_USER7",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats7),	-1, BX_build_status },
{ "STATUS_USER8",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats8),	-1, BX_build_status },
{ "STATUS_USER9",		STR_TYPE_VAR,	offsetof(WSet, status_user_formats9),	-1, BX_build_status },
{ "STATUS_USERS",		STR_TYPE_VAR,	offsetof(WSet, status_users),		offsetof(WSet, status_users_format), BX_build_status },
{ "STATUS_VOICE",		STR_TYPE_VAR,	offsetof(WSet, status_voice),		-1, BX_build_status },
{ "STATUS_WINDOW",		STR_TYPE_VAR,	offsetof(WSet, status_window),		-1, BX_build_status },
{ NULL,				0,		0, -1, NULL } 
};

CSetList *cset_queue = NULL;

/*
 * returns the requested int from the cset struct
 * Will work fine with either BOOL or INT type of csets.
 */
int BX_get_cset_int_var(CSetList *tmp, int var)
{
	int val = *(int *)((void *)tmp + cset_array[var].offset);
	return val;
}

char *BX_get_cset_str_var(CSetList *tmp, int var)
{
	char *s = *(char **) ((void *)tmp + cset_array[var].offset);
	return s;
}

/*
 * returns the requested int from the cset struct
 * Will work fine with either BOOL or INT type of csets.
 */
int cset_getflag(CSetList *tmp, int var)
{
	int val = *(int *)((void *)tmp + cset_array[var].flag);
	return val;
}

/*
 * sets the requested int from the cset struct
 * Will work fine with either BOOL or INT type of csets.
 */
void cset_setflag(CSetList *tmp, int var, int value)
{
	int *ptr = (int *) ((void *)tmp + cset_array[var].flag);
	*ptr = value;
}

/*
 * returns the requested int ADDRESS from the cset struct
 * Will work fine with either BOOL or INT type of csets.
 */
static void * get_cset_int_var_address(CSetList *tmp, int var)
{
	void *ptr = ((void *)tmp + cset_array[var].offset);
	return ptr;
}



/*
 * sets the requested int from the cset struct
 * Will work fine with either BOOL or INT type of csets.
 */
void BX_set_cset_int_var(CSetList *tmp, int var, int value)
{
	int *ptr = (int *) ((void *)tmp + cset_array[var].offset);
	*ptr = value;
}


void BX_set_cset_str_var(CSetList *tmp, int var, char *value)
{
	char **ptr = (char **) ((void *)tmp + cset_array[var].offset);
	if (value)
		malloc_strcpy(ptr, value);
	else
		new_free(ptr);
}

/*
 * Next few functions ripped from vars.c, as we are really doing the same
 * thing as those functions did, with a couple changes... The nice
 * thing about this is that we will get the same "feel" now with
 * SET's and CSET's
 */
static int find_cset_variable(CSetArray *array, char *org_name, int *cnt)
{
	CSetArray *v, *first;
	int     len, var_index;
	char    *name = NULL;

	len = strlen(org_name);
	name = alloca(len + 1);
	strcpy(name, org_name);

	upper(name);
	var_index = 0;
	for (first = array; first->name; first++, var_index++) 
	{
		if (strncmp(name, first->name, len) == 0) 
		{
			*cnt = 1;
			break;
		}
	}
	if (first->name) 
	{
		if (strlen(first->name) != len) 
		{
			v = first;
			for (v++; v->name; v++, (*cnt)++) 
			{
				if (strncmp(name, v->name, len) != 0)
					break;
			}
		}
		return (var_index);
	}
	else 
	{
		*cnt = 0;
		return (-1);
	}
}


static void set_cset_var_value(CSetList *tmp, int var_index, char *value)
{
	char    *rest;
	CSetArray *var;

	var = &(cset_array[var_index]);

	switch (var->type) 
	{
	case BOOL_TYPE_VAR:
        	if (value && *value && (value = next_arg(value, &rest))) {
			if (do_boolean(value, (int *)get_cset_int_var_address(tmp, var_index)))
			{
				say("Value must be either ON, OFF, or TOGGLE");
				break;
			}
			if (var->func)
				var->func(var, tmp);
			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]));
		}
		else 
			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]));
		break;

	case INT_TYPE_VAR:
		if (value && *value && (value = next_arg(value, &rest))) 
		{
			int     val;

			if (!is_number(value)) 
			{
				say("Value of %s must be numeric!", var->name);
				break;
			}
			if ((val = atoi(value)) < 0) 
			{
				say("Value of %s must be greater than 0", var->name);
				break;
			}
			set_cset_int_var(tmp, var_index, val);
			if (var->func)
				var->func(var, tmp);
			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)));
		}
		else 
			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)));
		break;
	case STR_TYPE_VAR:
		if (value && *value)
		{
			set_cset_str_var(tmp, var_index, value);
			if (var->func)
				var->func(var, tmp);
			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) ));
		}
		else
			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)));
	}
}

CSetList *check_cset_queue(char *channel, int add)
{
	CSetList *c = NULL;
	int found = 0;
	if (!strchr(channel, '*') && !(c = (CSetList *)find_in_list((List **)&cset_queue, channel, 0)))
	{
		if (!add) 
		{
			for (c = cset_queue; c; c = c->next)
				if (!my_stricmp(c->channel, channel) || wild_match(c->channel, channel))
					return c;
			return NULL;
		}
		c = create_csets_for_channel(channel);
		add_to_list((List **)&cset_queue, (List *)c);
		found++;
	}
	if (c)
		return c;
	if (add && !found)
	{
		for (c = cset_queue; c; c = c->next)
			if (!my_stricmp(c->channel, channel))
				return c;
		c = create_csets_for_channel(channel);
		c->next = cset_queue;
		cset_queue = c;
		return c;
	}
	return NULL;
}

static inline void cset_variable_case1(char *channel, int var_index, char *args)
{
	ChannelList *chan = NULL;
	int tmp = 0;
	int count = 0;
	/* 
	 * implement a queue for channels that don't exist... later...
	 * go home if user doesn't have any channels.
	 */
	if (current_window->server > -1)
	{
		for (chan = get_server_channels(current_window->server); chan; chan = chan->next) 
		{
			tmp = var_index;
			if (wild_match(channel, chan->channel))
			{
				set_cset_var_value(chan->csets, tmp, args);
				count++;
			}
		}
	}
	/* no channel match. lets check the queue */
/*	if (!count)*/
	{
		CSetList *c = NULL;
		if (!count)
			check_cset_queue(channel, 1);
		for (c = cset_queue; c; c = c->next)
		{
			tmp = var_index;
			if (!my_stricmp(channel, c->channel) || wild_match(channel, c->channel))
			{
				set_cset_var_value(c, tmp, args);
				count++;
			}
		}
		if (!count)
			say("CSET_VARIABLE: No match in cset queue for %s", channel);
	}
}

static inline void cset_variable_casedef(char *channel, int cnt, int var_index, char *args)
{
	ChannelList *chan = NULL; 
	int tmp, tmp2;
	int count = 0;
	
	if (current_window->server > -1)
	{
		for (chan = get_server_channels(current_window->server); chan; chan = chan->next) 
		{
			tmp = var_index;
			tmp2 = cnt;
			if (wild_match(channel, chan->channel)) 
			{
				for (tmp2 += tmp; tmp < tmp2; tmp++)
					set_cset_var_value(chan->csets, tmp, empty_string);
				count++;
			}
		}
	}
/*	if (!count) */
	{
		CSetList *c = NULL;
		if (!count)
			check_cset_queue(channel, 1);
		for (c = cset_queue; c; c = c->next)
		{
			tmp = var_index;
			tmp2 = cnt;
			if (!my_stricmp(channel, c->channel) || wild_match(channel, c->channel))
			{
				for (tmp2 +=tmp; tmp < tmp2; tmp++)
					set_cset_var_value(c, tmp, empty_string);
				count++;
			}
		}
		if (!count)
			say("CSET_VARIABLE: No match in cset queue for %s", channel);
		return;
	}

}

static inline void cset_variable_noargs(char *channel)
{
	int var_index = 0;
	ChannelList *chan = NULL; 
	int count = 0;

	if (current_window->server > -1)
	{
		for (chan = get_server_channels(current_window->server); chan; chan = chan->next) 
		{
			if (wild_match(channel, chan->channel)) 
			{	
				for (var_index = 0; var_index < NUMBER_OF_CSETS; var_index++)
					set_cset_var_value(chan->csets, var_index, empty_string);
				count++;
			}
		}
	}
/*	if (!count) */
	{
		CSetList *c = NULL;
		if (!count)
			check_cset_queue(channel, 1);
		for (c = cset_queue; c; c = c->next)
		{
			if (!wild_match(channel, c->channel))
				continue;
			for (var_index = 0; var_index < NUMBER_OF_CSETS; var_index++)
				set_cset_var_value(c, var_index, empty_string);
			count++;
		}
		if (!count)
			say("CSET_VARIABLE: No match in cset queue for %s", channel ? channel : empty_string);
		return;
	}

}

char *set_cset(char *var, ChannelList *chan, char *value)
{
int var_index, cnt = 0;
	var_index = find_cset_variable(cset_array, var, &cnt);
	if (cnt == 1)
	{
		CSetArray *var;
		var = &(cset_array[var_index]);
		switch(var->type)
		{
			case BOOL_TYPE_VAR:
			{
				int i = my_atol(value);
				set_cset_int_var(chan->csets, var_index, i? 1 : 0);
				break;
			}
			case INT_TYPE_VAR:
			{
				int i = my_atol(value);
				set_cset_int_var(chan->csets, var_index, i);
				break;
			}
			case STR_TYPE_VAR:
			{
				set_cset_str_var(chan->csets, var_index, value);
				break;
			}
			default:
				return NULL;
		}
		return value;
	}
	return NULL;
}

char *get_cset(char *var, ChannelList *chan, char *value)
{
int var_index, cnt = 0;
	var_index = find_cset_variable(cset_array, var, &cnt);
	if (cnt == 1)
	{
		char s[81];
		CSetArray *var;
		var = &(cset_array[var_index]);
		*s = 0;
		switch (var->type)
		{
			case BOOL_TYPE_VAR:
			{
				strcpy(s, get_cset_int_var(chan->csets, var_index)?var_settings[ON] : var_settings[OFF]);
				if (value)
				{
					int val = -1;
					if (!my_stricmp(value, on))
						val = 1;
					else if (!my_stricmp(value, off))
						val = 0;
					else
					{
						if (isdigit((unsigned char)*value))
							val = (int)(*value - '0');
					}
					if (val != -1)
						set_cset_int_var(chan->csets, var_index, val);
				}
				break;
			}
			case INT_TYPE_VAR:
			{
				strncpy(s, ltoa(get_cset_int_var(chan->csets, var_index)), 30);
				if (value && isdigit((unsigned char)*value))
					set_cset_int_var(chan->csets, var_index, my_atol(value)); 
				break;
			}
			case STR_TYPE_VAR:
			{
				char *t;
				t = m_strdup(get_cset_str_var(chan->csets, var_index));
				if (value)
					set_cset_str_var(chan->csets, var_index, value);
				return t;
			}
		}		
		return m_strdup(s && *s ? s : empty_string);
	}
	return m_strdup(empty_string);
}

BUILT_IN_COMMAND(cset_variable)
{
	char    *var, *channel = NULL;
	int     no_args = 1, cnt, var_index, hook = 1;

	if (from_server != -1 && current_window->server > -1)
	{
		if (args && *args && (is_channel(args) || *args == '*'))
			channel = next_arg(args, &args);
		else
			channel = get_current_channel_by_refnum(0);
	}
	else if (args && *args && (is_channel(args) || *args == '*'))
		channel = next_arg(args, &args);
		
	if (!channel)
		return;

	if ((var = next_arg(args, &args)) != NULL) 
	{
		if (*var == '-') 
		{
			var++;
			args = NULL;
		}
		var_index = find_cset_variable(cset_array, var, &cnt);
		
		if (hook)
		{
			switch (cnt) 
			{
				case 0:
					say("No such variable \"%s\"", var);
					return;
				case 1:
					cset_variable_case1(channel, var_index, args);
					return;
				default:
					say("%s is ambiguous", var);
					cset_variable_casedef(channel, cnt, var_index, args);
					return;
			}
		}
	}
	if (no_args)
		cset_variable_noargs(channel);
}

CSetList *create_csets_for_channel(char *channel)
{
	CSetList *tmp; 
#ifdef VAR_DEBUG
 	int i;
	
	for (i = 1; i < NUMBER_OF_CSETS - 1; i++)
		if (strcmp(cset_array[i-1].name, cset_array[i].name) >= 0)
			ircpanic("Variable [%d] (%s) is out of order.", i, cset_array[i].name);
#endif

	if (check_cset_queue(channel, 0))
	{
		if ((tmp = (CSetList *)find_in_list((List **)&cset_queue, channel, 0)))
			return tmp;
		for (tmp = cset_queue; tmp; tmp = tmp->next)
			if (!my_stricmp(tmp->channel, channel) || wild_match(tmp->channel, channel))
				return tmp;
	}		
	tmp = (CSetList *) new_malloc(sizeof(CSetList));
	/* use default settings. */
	tmp->set_aop = get_int_var(AOP_VAR);
	tmp->set_annoy_kick = get_int_var(ANNOY_KICK_VAR);
	tmp->set_ainv = get_int_var(AINV_VAR);
	tmp->set_auto_join_on_invite = get_int_var(AUTO_JOIN_ON_INVITE_VAR);
	tmp->set_auto_rejoin = get_int_var(AUTO_REJOIN_VAR);
	tmp->set_bantime = get_int_var(BANTIME_VAR);
	tmp->compress_modes = get_int_var(COMPRESS_MODES_VAR);
	tmp->bitch_mode = get_int_var(BITCH_VAR);
	tmp->channel_log = 0;
	
	tmp->log_level = m_strdup("ALL");	
	set_msglog_channel_level(cset_array, tmp); 
#if defined(WINNT) || defined(__EMX__)
	tmp->channel_log_file = m_sprintf("~/bx-conf/%s.log", channel+1);
#else
	tmp->channel_log_file = m_sprintf("~/.BitchX/%s.log", channel+1);
#endif
	tmp->set_joinflood = get_int_var(JOINFLOOD_VAR);
	tmp->set_joinflood_time = get_int_var(JOINFLOOD_TIME_VAR);
	tmp->set_ctcp_flood_ban = get_int_var(CTCP_FLOOD_BAN_VAR);
	tmp->set_deop_on_deopflood = get_int_var(DEOP_ON_DEOPFLOOD_VAR);
	tmp->set_deop_on_kickflood = get_int_var(DEOP_ON_KICKFLOOD_VAR);
	tmp->set_deopflood = get_int_var(DEOPFLOOD_VAR);
	tmp->set_deopflood_time = get_int_var(DEOPFLOOD_TIME_VAR);

	tmp->set_hacking = get_int_var(HACKING_VAR);

	tmp->set_kick_on_deopflood = get_int_var(KICK_ON_DEOPFLOOD_VAR);
	tmp->set_kick_on_joinflood = get_int_var(KICK_ON_JOINFLOOD_VAR);
	tmp->set_kick_on_kickflood = get_int_var(KICK_ON_KICKFLOOD_VAR);
	tmp->set_kick_on_nickflood = get_int_var(KICK_ON_NICKFLOOD_VAR);
	tmp->set_kick_on_pubflood = get_int_var(KICK_ON_PUBFLOOD_VAR);

	tmp->set_kickflood = get_int_var(KICKFLOOD_VAR);
	tmp->set_kickflood_time = get_int_var(KICKFLOOD_TIME_VAR);
	tmp->set_kick_ops = get_int_var(KICK_OPS_VAR);
	tmp->set_nickflood = get_int_var(NICKFLOOD_VAR);
	tmp->set_nickflood_time = get_int_var(NICKFLOOD_TIME_VAR);

	tmp->set_pubflood = get_int_var(PUBFLOOD_VAR);
	tmp->set_pubflood_time = get_int_var(PUBFLOOD_TIME_VAR);
	tmp->set_pubflood_ignore = 60;
	tmp->set_userlist = get_int_var(USERLIST_VAR);
	tmp->set_shitlist = get_int_var(SHITLIST_VAR);
	tmp->set_lamelist = get_int_var(LAMELIST_VAR);
	tmp->set_lame_ident = get_int_var(LAMEIDENT_VAR);
	tmp->set_kick_if_banned = get_int_var(KICK_IF_BANNED_VAR);
	tmp->set_auto_limit = get_int_var(AUTO_LIMIT_VAR);

	
	malloc_strcpy(&tmp->chanmode, get_string_var(CHANMODE_VAR));
	malloc_strcpy(&tmp->channel, channel);

	return tmp;
}

void remove_csets_for_channel(CSetList *tmp)
{
	new_free(&tmp->channel);
	new_free(&tmp->channel_log_file);
	new_free(&tmp->chanmode);
	new_free(&tmp);
}



static int find_wset_variable(WSetArray *array, char *org_name, int *cnt)
{
	WSetArray *v, *first;
	int     len, var_index;
	char    *name = NULL;

	len = strlen(org_name);
	name = alloca(len + 1);
	strcpy(name, org_name);

	upper(name);
	var_index = 0;
	for (first = array; first->name; first++, var_index++) 
	{
		if (strncmp(name, first->name, len) == 0) 
		{
			*cnt = 1;
			break;
		}
	}
	if (first->name) 
	{
		if (strlen(first->name) != len) 
		{
			v = first;
			for (v++; v->name; v++, (*cnt)++) 
			{
				if (strncmp(name, v->name, len) != 0)
					break;
			}
		}
		return (var_index);
	}
	else 
	{
		*cnt = 0;
		return (-1);
	}
}




/*
 * returns the requested int from the cset struct
 * Will work fine with either BOOL or INT type of csets.
 */
char *BX_get_wset_string_var(WSet *tmp, int var)
{
	char **ptr = (char **)((unsigned long)tmp + wset_array[var].offset);
	return *ptr;
}

/*
 * returns the requested int ADDRESS from the wset struct
 * Will work fine with STR_TYPE_VAR type of csets.
 */
static char ** get_wset_str_var_address(WSet *tmp, int var)
{
	char **ptr = (char **)((unsigned long)tmp + wset_array[var].offset);
	return ptr;
}

/*
 * returns the requested int ADDRESS from the wset struct
 * Will work fine with STR_TYPE_VAR type of csets.
 */
char ** get_wset_format_var_address(WSet *tmp, int var)
{
	char **ptr = NULL;
	if (wset_array[var].format_offset != -1)
		ptr = (char **)((unsigned long)tmp + wset_array[var].format_offset);
	return ptr;
}

/*
 * sets the requested string from the wset struct
 */

void BX_set_wset_string_var(WSet *tmp, int var, char *value)
{
	char **ptr = (char **)((unsigned long)tmp + wset_array[var].offset);
	if (value && *value)
		malloc_strcpy(ptr, value);
	else
		new_free(ptr);
}





static void set_wset_var_value(Window *win, int var_index, char *value)
{
	WSetArray *var;

	var = &(wset_array[var_index]);

	switch (var->type) 
	{
	case STR_TYPE_VAR:
		{
			char **val = NULL;
			if ((val = get_wset_str_var_address(win->wset, var_index))) 
			{
				if (value)
				{
					if (*value)
						malloc_strcpy(val, value);
					else
					{
						put_it("%s", convert_output_format(fget_string_var(FORMAT_SET_FSET), "%s %s", var->name, *val?*val:empty_string));
						return;
					}
				} else
					new_free(val);
				if (var->func)
					(var->func) (win, *val, 0);
				say("Value of %s set to %s", var->name, *val ?
					*val : "<EMPTY>");
			}
		}
		break;
	default:
		say("WSET_type not supported");
	}
}

static inline void wset_variable_case1(Window *win, char *name, int var_index, char *args)
{
Window *tmp = NULL;
int count = 0;
int i;
	if (!name)
	{
		set_wset_var_value(win, var_index, args);
		return;
	}
	while ((traverse_all_windows(&tmp)))
	{
		i = var_index;
		if (*name == '*')
		{
			set_wset_var_value(tmp, i, args);
			count++;
		}
		else if ((tmp->name && wild_match(name, tmp->name)) || (tmp->refnum == my_atol(name)))
		{
			set_wset_var_value(tmp, i, args);
			count++;
		}
	}
	if (!count)
		say("No such window name [%s]", name);
}

static inline void wset_variable_casedef(Window *win, char *name, int cnt, int var_index, char *args)
{
Window *tmp = NULL;
int count = 0;
int c, i;
	if (!name)
	{
		for (cnt +=var_index; var_index < cnt; var_index++)
			set_wset_var_value(win, var_index, args);
		return;
	}
	while ((traverse_all_windows(&tmp)))
	{
		c = cnt;
		i = var_index;
		if (*name == '*')
		{
			for (c += i; i < c; i++)
				set_wset_var_value(tmp, i, empty_string);
			count++;
		}
		else if ((tmp->name && wild_match(name, tmp->name)) || (tmp->refnum == my_atol(name)) ) 
		{
			for (c += i; i < c; i++)
				set_wset_var_value(tmp, i, empty_string);
			count++;
		}
	}
	if (!count)
		say("No such window name [%s]", name);
}

static inline void wset_variable_noargs(Window *win, char *name)
{
Window *tmp = NULL;
int var_index = 0;
	if (!name)
	{
		for (var_index = 0; var_index < NUMBER_OF_WSETS; var_index++)
			set_wset_var_value(win, var_index, empty_string);
	} 
	else
	{
		int count = 0;
		while ((traverse_all_windows(&tmp)))
		{
			if (*name == '*')
			{
				for (var_index = 0; var_index < NUMBER_OF_WSETS; var_index++)
					set_wset_var_value(tmp, var_index, empty_string);
				count++;
			}
			else if ((tmp->name && wild_match(name, tmp->name)) || (tmp->refnum == my_atol(name)))
			{
				for (var_index = 0; var_index < NUMBER_OF_WSETS; var_index++)
					set_wset_var_value(tmp, var_index, empty_string);
				count++;
			}
		}
		if (!count)
			say("No such window name [%s]", name);
	}
}


BUILT_IN_COMMAND(wset_variable)
{
	char    *var;
	char	*possible;
	char 	*name = NULL;
	int     no_args = 1, cnt, var_index;
	Window *win = screen_list->window_list;

	if (args)
	{
		if (*args == '*')
			name = next_arg(args, &args);
		else if (args && *args)
		{
			possible = LOCAL_COPY(args);
			name = next_arg(possible, &possible);
			if (!(win = get_window_by_name(name)))
			{
				win = get_window_by_refnum(my_atol(name));
				if (!win)
				{
					if (isdigit((unsigned char)*name))
					{
						say("No such window refnum %d", my_atol(name));
						return;
					}
				} 
				else if (isdigit((unsigned char)*name))
					var = next_arg(args, &args);
				name = NULL;
			}
			else
				var = next_arg(args, &args);
		}
	}
	else 
		win = current_window;

	
	if ((var = next_arg(args, &args)) != NULL) 
	{
		if (*var == '-') 
		{
			var++;
			args = NULL;
		}
		var_index = find_wset_variable(wset_array, var, &cnt);
		switch (cnt) 
		{
			case 0:
				say("No such variable \"%s\"", var);
				return;
			case 1:
				wset_variable_case1(win, name, var_index, args);
				update_all_status(win, NULL, 0);
				update_all_windows();
				return;
			default:
				say("%s is ambiguous", var);
				wset_variable_casedef(win, name, cnt, var_index, args);
				return;
		}
	}
	if (no_args) 
		wset_variable_noargs(win, name);
}


WSet *create_wsets_for_window(Window *win)
{
	WSet *tmp; 
#ifdef VAR_DEBUG
 	int i;
	
	for (i = 1; i < NUMBER_OF_CSETS - 1; i++)
		if (strcmp(wset_array[i-1].name, wset_array[i].name) >= 0)
			ircpanic("Variable [%d] (%s) is out of order.", i, wset_array[i].name);
#endif

	tmp = (WSet *) new_malloc(sizeof(WSet));

	malloc_strcpy(&tmp->status_channel, get_string_var(STATUS_CHANNEL_VAR));
	malloc_strcpy(&tmp->status_chanop, get_string_var(STATUS_CHANOP_VAR));
	malloc_strcpy(&tmp->status_halfop, get_string_var(STATUS_HALFOP_VAR));
	malloc_strcpy(&tmp->status_clock, get_string_var(STATUS_CLOCK_VAR));
	malloc_strcpy(&tmp->status_hold_lines, get_string_var(STATUS_HOLD_LINES_VAR));
	malloc_strcpy(&tmp->status_hold, get_string_var(STATUS_HOLD_VAR));
	malloc_strcpy(&tmp->status_voice, get_string_var(STATUS_VOICE_VAR));
	malloc_strcpy(&tmp->status_dcccount, get_string_var(STATUS_DCCCOUNT_VAR));
	malloc_strcpy(&tmp->status_cdcccount, get_string_var(STATUS_CDCCCOUNT_VAR));
	malloc_strcpy(&tmp->status_cpu_saver, get_string_var(STATUS_CPU_SAVER_VAR));
	malloc_strcpy(&tmp->status_lag, get_string_var(STATUS_LAG_VAR));
	malloc_strcpy(&tmp->status_away, get_string_var(STATUS_AWAY_VAR));
	malloc_strcpy(&tmp->status_mail, get_string_var(STATUS_MAIL_VAR));
	malloc_strcpy(&tmp->status_mode, get_string_var(STATUS_MODE_VAR));
	malloc_strcpy(&tmp->status_notify, get_string_var(STATUS_NOTIFY_VAR));
	malloc_strcpy(&tmp->status_oper_kills, get_string_var(STATUS_OPER_KILLS_VAR));
	malloc_strcpy(&tmp->status_query, get_string_var(STATUS_QUERY_VAR));
	malloc_strcpy(&tmp->status_server, get_string_var(STATUS_SERVER_VAR));
	malloc_strcpy(&tmp->status_topic, get_string_var(STATUS_TOPIC_VAR));
	malloc_strcpy(&tmp->status_umode, get_string_var(STATUS_UMODE_VAR));
	malloc_strcpy(&tmp->status_users, get_string_var(STATUS_USERS_VAR));
	malloc_strcpy(&tmp->status_msgcount, get_string_var(STATUS_MSGCOUNT_VAR));
	malloc_strcpy(&tmp->status_nick, get_string_var(STATUS_NICK_VAR));
	malloc_strcpy(&tmp->status_flag, get_string_var(STATUS_FLAG_VAR));		
	malloc_strcpy(&tmp->status_scrollback, get_string_var(STATUS_SCROLLBACK_VAR));

	malloc_strcpy(&tmp->format_status[0], get_string_var(STATUS_FORMAT_VAR));
	malloc_strcpy(&tmp->format_status[1], get_string_var(STATUS_FORMAT1_VAR));
	malloc_strcpy(&tmp->format_status[2], get_string_var(STATUS_FORMAT2_VAR));
	malloc_strcpy(&tmp->format_status[3], get_string_var(STATUS_FORMAT3_VAR));

	malloc_strcpy(&tmp->status_user_formats0, get_string_var(STATUS_USER0_VAR));
	malloc_strcpy(&tmp->status_user_formats1, get_string_var(STATUS_USER1_VAR));
	malloc_strcpy(&tmp->status_user_formats10, get_string_var(STATUS_USER10_VAR));
	malloc_strcpy(&tmp->status_user_formats11, get_string_var(STATUS_USER11_VAR));
	malloc_strcpy(&tmp->status_user_formats12, get_string_var(STATUS_USER12_VAR));
	malloc_strcpy(&tmp->status_user_formats13, get_string_var(STATUS_USER13_VAR));
	malloc_strcpy(&tmp->status_user_formats14, get_string_var(STATUS_USER14_VAR));
	malloc_strcpy(&tmp->status_user_formats15, get_string_var(STATUS_USER15_VAR));
	malloc_strcpy(&tmp->status_user_formats16, get_string_var(STATUS_USER16_VAR));
	malloc_strcpy(&tmp->status_user_formats17, get_string_var(STATUS_USER17_VAR));
	malloc_strcpy(&tmp->status_user_formats18, get_string_var(STATUS_USER18_VAR));
	malloc_strcpy(&tmp->status_user_formats19, get_string_var(STATUS_USER19_VAR));
	malloc_strcpy(&tmp->status_user_formats2, get_string_var(STATUS_USER2_VAR));
	malloc_strcpy(&tmp->status_user_formats20, get_string_var(STATUS_USER20_VAR));
	malloc_strcpy(&tmp->status_user_formats21, get_string_var(STATUS_USER21_VAR));
	malloc_strcpy(&tmp->status_user_formats22, get_string_var(STATUS_USER22_VAR));
	malloc_strcpy(&tmp->status_user_formats23, get_string_var(STATUS_USER23_VAR));
	malloc_strcpy(&tmp->status_user_formats24, get_string_var(STATUS_USER24_VAR));
	malloc_strcpy(&tmp->status_user_formats25, get_string_var(STATUS_USER25_VAR));
	malloc_strcpy(&tmp->status_user_formats26, get_string_var(STATUS_USER26_VAR));
	malloc_strcpy(&tmp->status_user_formats27, get_string_var(STATUS_USER27_VAR));
	malloc_strcpy(&tmp->status_user_formats28, get_string_var(STATUS_USER28_VAR));
	malloc_strcpy(&tmp->status_user_formats29, get_string_var(STATUS_USER29_VAR));
	malloc_strcpy(&tmp->status_user_formats3, get_string_var(STATUS_USER3_VAR));
	malloc_strcpy(&tmp->status_user_formats30, get_string_var(STATUS_USER30_VAR));
	malloc_strcpy(&tmp->status_user_formats31, get_string_var(STATUS_USER31_VAR));
	malloc_strcpy(&tmp->status_user_formats32, get_string_var(STATUS_USER32_VAR));
	malloc_strcpy(&tmp->status_user_formats33, get_string_var(STATUS_USER33_VAR));
	malloc_strcpy(&tmp->status_user_formats34, get_string_var(STATUS_USER34_VAR));
	malloc_strcpy(&tmp->status_user_formats35, get_string_var(STATUS_USER35_VAR));
	malloc_strcpy(&tmp->status_user_formats36, get_string_var(STATUS_USER36_VAR));
	malloc_strcpy(&tmp->status_user_formats37, get_string_var(STATUS_USER37_VAR));
	malloc_strcpy(&tmp->status_user_formats38, get_string_var(STATUS_USER38_VAR));
	malloc_strcpy(&tmp->status_user_formats39, get_string_var(STATUS_USER39_VAR));
	malloc_strcpy(&tmp->status_user_formats4, get_string_var(STATUS_USER4_VAR));
	malloc_strcpy(&tmp->status_user_formats5, get_string_var(STATUS_USER5_VAR));
	malloc_strcpy(&tmp->status_user_formats6, get_string_var(STATUS_USER6_VAR));
	malloc_strcpy(&tmp->status_user_formats7, get_string_var(STATUS_USER7_VAR));
	malloc_strcpy(&tmp->status_user_formats8, get_string_var(STATUS_USER8_VAR));
	malloc_strcpy(&tmp->status_user_formats9, get_string_var(STATUS_USER9_VAR));
	malloc_strcpy(&tmp->status_window, get_string_var(STATUS_WINDOW_VAR));
	win->wset = tmp;	
	return tmp;
}

void remove_wsets_for_window(Window *tmp)
{
	new_free(&tmp->wset->status_channel);
	new_free(&tmp->wset->status_clock); 
	new_free(&tmp->wset->status_hold_lines);
	new_free(&tmp->wset->status_hold);
	new_free(&tmp->wset->status_voice);
	new_free(&tmp->wset->status_dcccount);
	new_free(&tmp->wset->status_cdcccount);
	new_free(&tmp->wset->status_lag); 
	new_free(&tmp->wset->status_away); 
	new_free(&tmp->wset->status_nick);
	new_free(&tmp->wset->status_flag);	
	new_free(&tmp->wset->status_mail);
	new_free(&tmp->wset->status_msgcount);
	new_free(&tmp->wset->status_cpu_saver);
	new_free(&tmp->wset->status_chanop);
	new_free(&tmp->wset->status_mode);
	
	new_free(&tmp->wset->status_notify);
	new_free(&tmp->wset->status_oper_kills);
	new_free(&tmp->wset->status_query);
	new_free(&tmp->wset->status_server);
	new_free(&tmp->wset->status_topic);
	new_free(&tmp->wset->status_umode);
	new_free(&tmp->wset->status_users);
	new_free(&tmp->wset->status_scrollback);
	new_free(&tmp->wset->status_halfop);	

	new_free(&tmp->wset->status_user_formats1);
	new_free(&tmp->wset->status_user_formats10);
	new_free(&tmp->wset->status_user_formats11);
	new_free(&tmp->wset->status_user_formats12);
	new_free(&tmp->wset->status_user_formats13);
	new_free(&tmp->wset->status_user_formats14);
	new_free(&tmp->wset->status_user_formats15);
	new_free(&tmp->wset->status_user_formats16);
	new_free(&tmp->wset->status_user_formats17);
	new_free(&tmp->wset->status_user_formats18);
	new_free(&tmp->wset->status_user_formats19);
	new_free(&tmp->wset->status_user_formats2);
	new_free(&tmp->wset->status_user_formats20);
	new_free(&tmp->wset->status_user_formats21);
	new_free(&tmp->wset->status_user_formats22);
	new_free(&tmp->wset->status_user_formats23);
	new_free(&tmp->wset->status_user_formats24);
	new_free(&tmp->wset->status_user_formats25);
	new_free(&tmp->wset->status_user_formats26);
	new_free(&tmp->wset->status_user_formats27);
	new_free(&tmp->wset->status_user_formats28);
	new_free(&tmp->wset->status_user_formats29);
	new_free(&tmp->wset->status_user_formats3);
	new_free(&tmp->wset->status_user_formats30);
	new_free(&tmp->wset->status_user_formats31);
	new_free(&tmp->wset->status_user_formats32);
	new_free(&tmp->wset->status_user_formats33);
	new_free(&tmp->wset->status_user_formats34);
	new_free(&tmp->wset->status_user_formats35);
	new_free(&tmp->wset->status_user_formats36);
	new_free(&tmp->wset->status_user_formats37);
	new_free(&tmp->wset->status_user_formats38);
	new_free(&tmp->wset->status_user_formats39);
	new_free(&tmp->wset->status_user_formats4);
	new_free(&tmp->wset->status_user_formats5);
	new_free(&tmp->wset->status_user_formats6);
	new_free(&tmp->wset->status_user_formats7);
	new_free(&tmp->wset->status_user_formats8);
	new_free(&tmp->wset->status_user_formats9);
	new_free(&tmp->wset->status_user_formats0);

	new_free(&tmp->wset->format_status[0]);
	new_free(&tmp->wset->format_status[1]);
	new_free(&tmp->wset->format_status[2]);
	new_free(&tmp->wset->format_status[3]); 

	new_free(&tmp->wset->status_format[0]);
	new_free(&tmp->wset->status_format[1]);
	new_free(&tmp->wset->status_format[2]);
	new_free(&tmp->wset->status_format[3]); 
	new_free(&tmp->wset->status_line[0]);
	new_free(&tmp->wset->status_line[1]);
	new_free(&tmp->wset->status_line[2]);

	new_free(&tmp->wset->mode_format);
	new_free(&tmp->wset->umode_format);
	new_free(&tmp->wset->topic_format);
	new_free(&tmp->wset->query_format);
	new_free(&tmp->wset->clock_format);
	new_free(&tmp->wset->hold_lines_format);
	new_free(&tmp->wset->channel_format);
	new_free(&tmp->wset->mail_format);
	new_free(&tmp->wset->server_format);
	new_free(&tmp->wset->notify_format);
	new_free(&tmp->wset->kills_format);
	new_free(&tmp->wset->lag_format);
	new_free(&tmp->wset->cpu_saver_format);
	new_free(&tmp->wset->msgcount_format);
	new_free(&tmp->wset->dcccount_format);
	new_free(&tmp->wset->cdcc_format);
	new_free(&tmp->wset->nick_format);
	new_free(&tmp->wset->away_format);
	new_free(&tmp->wset->flag_format);
	new_free(&tmp->wset->status_users_format);
	new_free(&tmp->wset->status_window);
	new_free(&tmp->wset->window_special_format);
	new_free(&tmp->wset);
}

void log_channel(CSetArray *var, CSetList *cs)
{
	ChannelList *chan;
	if (!cs->channel_log_file)
	{
		bitchsay("Try setting a channel log file first");
		set_cset_int_var(cs, CHANNEL_LOG_CSET, 0);
		return;
	}
	if ((chan = lookup_channel(cs->channel, from_server, 0)))
		do_log(cs->channel_log, cs->channel_log_file, &chan->msglog_fp);
}

void set_msglog_channel_level(CSetArray *var, CSetList *cs)
{
	ChannelList *chan;
	if ((chan = lookup_channel(cs->channel, from_server, 0)))
	{
		chan->log_level = parse_lastlog_level(cs->log_level, 1);
		set_cset_str_var(cs, CHANNEL_LOG_LEVEL_CSET, bits_to_lastlog_level(chan->log_level));
	}
}

void do_logchannel(unsigned long level, ChannelList *chan, char *format, ...)
{
	if (!chan || !get_cset_int_var(chan->csets, CHANNEL_LOG_CSET))
		return;
	if ((chan->log_level & level) && format)
	{
		char s[BIG_BUFFER_SIZE+1];
		va_list args;
		va_start(args, format);
		vsnprintf(s, BIG_BUFFER_SIZE, format, args);
		va_end(args);
		add_to_log(chan->msglog_fp, now, s, logfile_line_mangler);
	}
}

void set_channel_limit(ChannelList *channel, int currentlimit, int add, int numusers)
{
	if ((now - channel->limit_time) < 30)
		return;
	if (add && numusers)
	{
		if ((currentlimit - numusers) < (add / 2) && ((numusers + add) != currentlimit))
			my_send_to_server(channel->server, "MODE %s +l %d", channel->channel, numusers + add);
		else if ((currentlimit - numusers) > (currentlimit + (add / 2)) && ((numusers + add) != currentlimit))
			my_send_to_server(channel->server, "MODE %s +l %d", channel->channel, numusers + add);
	}
	else
		my_send_to_server(channel->server, "MODE %s -l", channel->channel);
	channel->limit_time = now;
}

void check_channel_limit(ChannelList *chan)
{
	if (chan && chan->csets && chan->csets->set_auto_limit && chan->chop)
	{
		int count = 0;
		NickList *nick;
		for (nick = next_nicklist(chan, NULL); nick; nick = next_nicklist(chan, nick))
			count++;
		set_channel_limit(chan, chan->limit, chan->csets->set_auto_limit, count);
	}
}

void limit_channel(CSetArray *var, CSetList *cs)
{
ChannelList *chan;
	if ((chan = lookup_channel(cs->channel, from_server, 0)))
	{
		if (cs->set_auto_limit)
		{
			int count = 0;
			NickList *nick;
			for (nick = next_nicklist(chan, NULL); nick; nick = next_nicklist(chan, nick))
				count++;
			set_channel_limit(chan, chan->limit, cs->set_auto_limit, count);
		} else
			set_channel_limit(chan, chan->limit, 0, 0);
	}
}

#ifdef GUI
CSetArray *return_cset_var(int nummer)
{
   return &cset_array[nummer];
}

WSetArray *return_wset_var(int nummer)
{
   return &wset_array[nummer];
}
#endif