Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/source/cdcc.c
1069 views
1
/* CDCC v2 1.00 (c) Copyright 1996 William Glozer */
2
/* ----------------------------------------------- */
3
/* Last revision 04.19.96 by Ananda */
4
5
/* New CDCC for BitchX and any other clients that deserve to run it :) */
6
/* Note that I did use a lot of code/ideas from a copy of CDCC written */
7
/* for BitchX by panasync, so thanks to him for alot of the code and */
8
/* ideas :) I would appreciate any bugs reported to me as soon as is */
9
/* possible, and cdcc.c + cdcc.h for any mods you do... if you modify */
10
/* it for your client, I can add those mods as #ifdefs so the next ver */
11
/* will work with your client and have all the new stuff. -Ananda '96 */
12
/* Modifed even more by panasync ([email protected]) to */
13
/* interface cleanly and nicely with BitchX. Blame all bugs on me */
14
/* instead of Ananda */
15
16
#define CDCC_FLUD
17
18
#include "irc.h"
19
static char cvsrevision[] = "$Id: cdcc.c 3 2008-02-25 09:49:14Z keaston $";
20
CVS_REVISION(cdcc_c)
21
#include "ircaux.h"
22
#include "struct.h"
23
#include "commands.h"
24
#include "ignore.h"
25
#include "ctcp.h"
26
#include "hook.h"
27
#include "dcc.h"
28
#include "flood.h"
29
#include "screen.h"
30
#include "parse.h"
31
#include "output.h"
32
#include "input.h"
33
#include "server.h"
34
#include "vars.h"
35
#include "list.h"
36
#include "userlist.h"
37
#include "misc.h"
38
#include "who.h"
39
40
#include "cdcc.h"
41
#include "misc.h"
42
43
#define MAIN_SOURCE
44
#include "modval.h"
45
46
#ifdef WANT_CDCC
47
48
/* external ircII stuff */
49
static int l_timer (char *, char *);
50
static int r_info (char *, char *);
51
static int r_rmsend (char *, char *);
52
static int r_queue (char *, char *);
53
static int l_tsend (char *, char *);
54
static int l_tresend (char *, char *);
55
static int l_resume (char *, char *);
56
static int l_describe (char *, char *);
57
static int l_help(char *, char *);
58
59
/* add a pack to the offer list */
60
static int l_offer(char *, char *);
61
62
/* send a pack to someone */
63
static int l_send(char *, char *);
64
65
/* re-send a pack to someone */
66
static int l_resend(char *, char *);
67
68
/* remove a pack or all packs from the offer list */
69
static int l_doffer(char *, char *);
70
71
/* localy list offered packs */
72
static int l_list(char *, char *);
73
74
/* notify the channel that packs are offered */
75
static int l_notice(char *, char *);
76
77
/* view your queue */
78
static int l_queue(char *, char *);
79
80
/* save all offered packs to cdcc.save */
81
static int l_save(char *, char *);
82
83
/* load packs from cdcc.save */
84
static int l_load(char *, char *);
85
86
static int l_minspeed(char *, char *);
87
88
static int l_secure(char *, char *);
89
90
/* remote CDCC commands */
91
/* -------------------- */
92
93
/* show help to a remote user */
94
static int r_help(char *, char *);
95
96
/* list packs offered to remote user */
97
static int r_list(char *, char *);
98
99
/* send pack to remote user */
100
static int r_send(char *, char *);
101
102
/* re-send pack to remote user */
103
static int r_rsend(char *, char *);
104
105
#if 0
106
/* send pack to remote user */
107
static int r_tsend(char *, char *);
108
109
/* re-send pack to remote user */
110
static int r_trsend(char *, char *);
111
#endif
112
113
/* add files */
114
static void add_files(char *, char *);
115
/* add description */
116
static void add_desc(char *, char *);
117
/* remove pack/all packs */
118
static void del_pack(char *, char *);
119
/* add/remove public channel */
120
static int l_channel(char *, char *);
121
/* add note to a pack */
122
static int l_note(char *, char *);
123
static int l_echo(char *, char *);
124
static int l_stats(char *, char *);
125
static int l_type(char *, char *);
126
/* add a person to the dcc queue */
127
int BX_add_to_queue(char *, char *, pack *);
128
129
void dcc_getfile_resume (char *, char *);
130
131
/* local commands */
132
local_cmd local[] = {
133
{ "CHANNEL", l_channel, "public timer channel" },
134
{ "DESCRIBE", l_describe, "change description of pack" },
135
{ "DOFFER", l_doffer, "remove pack from the offer list" },
136
{ "LIST", l_list, "list the packs you have offered" },
137
{ "LOAD", l_load, "load packs saved to .cdcc.save or specified name" },
138
{ "HELP", l_help, "cdcc help" },
139
{ "MINSPEED", l_minspeed, "minspeed for cdcc ( #.##) [mintime in seconds]" },
140
{ "NOTICE", l_notice, "notify the channel of offered packs" },
141
{ "OFFER", l_offer, "add a pack to the offer list" },
142
{ "PLIST", l_plist, "publicly list your offered packs" },
143
{ "QUEUE", l_queue, "view entries in the send queue" },
144
{ "SAVE", l_save, "save your offerlist to .cdcc.save or specified name" },
145
{ "SEND", l_send, "send a pack to user" },
146
{ "RESEND", l_resend, "re-send a pack to user" },
147
{ "TSEND", l_tsend, "tdcc send a pack to user" },
148
{ "TRESEND", l_tresend, "tdcc resend a pack to user" },
149
#ifdef MIRC_BROKEN_DCC_RESUME
150
{ "RESUME", l_resume, "mirc resume" },
151
#endif
152
{ "TIMER", l_timer, "public list timer in minutes" },
153
{ "NOTE", l_note, "add note to pack number"},
154
{ "TYPE", l_type, "toggle between public and notice" },
155
{ "ECHO", l_echo, "toggle echo on/off" },
156
{ "STATS", l_stats, "display cdcc statistics" },
157
{ "SECURE", l_secure, "adds a password to a pack"},
158
{ "ON", NULL, "cdcc offers on" },
159
{ "OFF", NULL, "cdcc offers off" },
160
{ empty_string, NULL, empty_string }
161
};
162
#define NUM_LOCAL (sizeof(local) / sizeof(local_cmd))
163
164
/* remote commands */
165
remote_cmd remote[] = {
166
{ "HELP", r_help, "help on CDCC commands" },
167
{ "RESEND", r_rsend, "have CDCC resend pack #N"},
168
#ifdef MIRC_BROKEN_DCC_RESUME
169
{ "RESUME", r_rmsend, "have CDCC resume pack #N"},
170
#endif
171
{ "SEND", r_send, "have CDCC send pack #N" },
172
#if 0
173
{ "TRESEND", r_trsend, "have CDCC tresend pack #N"},
174
{ "TSEND", r_tsend, "have CDCC tsend pack #N" },
175
#endif
176
{ "LIST", r_list, "list of offered packs" },
177
{ "INFO", r_info, "info on pack #N" },
178
{ "QUEUE", r_queue, "queue status for us" },
179
{ empty_string, NULL, empty_string },
180
};
181
#define NUM_REMOTE (sizeof(remote) / sizeof(remote_cmd))
182
183
/* ahh yes, global variables :( well, interfacing with ircII is a pain in */
184
/* the ass, and I couldn't figure out a better way... more than one of my */
185
/* routines need these... the static will keep them from being used by any */
186
/* functions outside of cdcc.c */
187
188
unsigned int cdcc_numpacks = 0;
189
unsigned int send_numpacks = 0;
190
191
pack *offerlist = NULL;
192
static pack *newpack;
193
194
static queue *queuelist = NULL;
195
static unsigned long total_size_of_packs = 0;
196
static int numqueue = 0;
197
static int ptimer = 0;
198
static int do_notice_list = 0;
199
static int do_cdcc_echo = 1;
200
201
double cdcc_minspeed = 0.0;
202
static char *public_channel = NULL;
203
204
205
extern double dcc_max_rate_out, dcc_bytes_out, dcc_max_rate_in, dcc_bytes_in;
206
207
#define cparse(s) convert_output_format(s, NULL, NULL)
208
209
/* parse a users CDCC command */
210
BUILT_IN_COMMAND(cdcc)
211
{
212
int i;
213
char *cmd, *rest;
214
215
cmd = next_arg(args, &args);
216
rest = next_arg(args, &args);
217
if (!cmd)
218
{
219
l_list(NULL, NULL);
220
put_it("%s: CDCC is [\002%s\002]. Use \002/cdcc help\002 to get help with cdcc", cparse(get_string_var(CDCC_PROMPT_VAR)), on_off(get_int_var(CDCC_VAR)));
221
return;
222
}
223
if (!my_stricmp(cmd, "ON") || !my_stricmp(cmd, "OFF"))
224
{
225
set_int_var(CDCC_VAR, !my_stricmp(cmd, "ON") ? 1 : 0);
226
put_it("%s: offers \002%s\002", cparse(get_string_var(CDCC_PROMPT_VAR)), cmd);
227
return;
228
}
229
230
for (i = 0; *local[i].name; i++)
231
{
232
if (!my_stricmp(local[i].name, cmd) && local[i].function)
233
{
234
local[i].function(rest, args);
235
return;
236
}
237
}
238
put_it("%s: unknown command \002%s\002", cparse(get_string_var(CDCC_PROMPT_VAR)), cmd);
239
return;
240
}
241
242
static int l_help(char *cmd, char *args)
243
{
244
int i;
245
char buffer[BIG_BUFFER_SIZE+1];
246
if (!cmd)
247
{
248
int c = 0;
249
*buffer = 0;
250
for (i = 0; *local[i].name; i++)
251
{
252
strmcat(buffer, local[i].name, BIG_BUFFER_SIZE);
253
strmcat(buffer, space, BIG_BUFFER_SIZE);
254
if (++c == 5)
255
{
256
put_it("%s", convert_output_format("$G $[13]0 $[13]1 $[13]2 $[13]3 $[13]4", "%s", buffer));
257
*buffer = 0;
258
c = 0;
259
}
260
}
261
if (c)
262
put_it("%s", convert_output_format("$G $[13]0 $[13]1 $[13]2 $[13]3 $[13]4", "%s", buffer));
263
userage("CDCC help", "%R[%ncommand%R]%n to get help on specific commands");
264
}
265
else
266
{
267
int done = 0;
268
for (i = 0; *local[i].name; i++)
269
{
270
if (my_stricmp(local[i].name, cmd))
271
continue;
272
sprintf(buffer, "CDCC %s", cmd);
273
userage(buffer, local[i].help?local[i].help:" - No help available");
274
done++;
275
}
276
if (!done)
277
put_it("%s", convert_output_format("$G CDCC - No such command", NULL, NULL));
278
}
279
return 0;
280
}
281
282
/* parse a remote message CDCC command */
283
char *msgcdcc(char *from, char *to, char *args)
284
{
285
int i;
286
char *secure = NULL;
287
char *cdcc, *rest, *cmd, *temp = NULL;
288
289
temp = LOCAL_COPY(args);
290
cdcc = next_arg(temp, &temp);
291
if (!cdcc || (my_strnicmp(cdcc, "XDCC", 4) && my_strnicmp(cdcc, "CDCC", 4)))
292
return args;
293
if (!get_int_var(CDCC_VAR))
294
return args;
295
if ((check_ignore(from, FromUserHost, to, IGNORE_CDCC, NULL) == IGNORED))
296
return args;
297
298
if (!check_flooding(from, CDCC_FLOOD, args, NULL) || !offerlist)
299
return NULL;
300
301
302
if ((secure = get_string_var(CDCC_SECURITY_VAR)))
303
{
304
UserList *tmp;
305
char *pass = NULL;
306
if (*secure == '0' && strlen(secure) == 1)
307
goto got_good_pass;
308
if (temp && *temp)
309
pass = strrchr(temp, ' ');
310
if (pass && *pass)
311
{
312
pass++;
313
if (*pass && !my_stricmp(pass, secure))
314
{
315
*pass-- = 0;
316
goto got_good_pass;
317
}
318
}
319
#ifdef WANT_USERLIST
320
if (!(tmp = lookup_userlevelc("*", FromUserHost, "*", NULL)) || !(tmp->flags & ADD_DCC))
321
return args;
322
#else
323
return args;
324
#endif
325
}
326
got_good_pass:
327
cmd = next_arg(temp, &temp);
328
if (!cmd)
329
return args;
330
331
rest = temp;
332
333
for (i = 0; *remote[i].name; i++)
334
{
335
if (!my_stricmp(cmd, remote[i].name))
336
{
337
remote[i].function(from, rest);
338
return NULL;
339
}
340
}
341
queue_send_to_server(from_server, "NOTICE %s :try /ctcp %s cdcc help",from, get_server_nickname(from_server));
342
return args;
343
}
344
345
static int r_info(char *args, char *rest)
346
{
347
if (rest && *rest)
348
{
349
char *q;
350
pack *ptr = NULL;
351
352
q = next_arg(rest, &rest);
353
for (ptr = offerlist; ptr; ptr = ptr->next)
354
if (matchmcommand(q, ptr->num))
355
break;
356
if (ptr)
357
queue_send_to_server(from_server, "NOTICE %s :%d file%s %d gets %ld size %2.4f minspeed %ld time added",args, ptr->numfiles, plural(ptr->numfiles), ptr->gets, ptr->size, ptr->minspeed, ptr->timeadded);
358
else
359
queue_send_to_server(from_server, "NOTICE %s :Invalid info request", args);
360
}
361
return 0;
362
}
363
364
static int r_queue(char *args, char *rest)
365
{
366
queue *new = NULL;
367
int count;
368
int num = 0;
369
char buffer[BIG_BUFFER_SIZE+1];
370
if (queuelist && args)
371
{
372
*buffer = 0;
373
for (new = queuelist, count = 1; new; new = new->next)
374
{
375
if (!my_stricmp(new->nick, args))
376
{
377
num++;
378
strmopencat(buffer, BIG_BUFFER_SIZE, ltoa(count), ",", NULL);
379
count++;
380
}
381
}
382
if (num)
383
{
384
chop(buffer, 1);
385
queue_send_to_server(from_server, "NOTICE %s :You have %d packs queued at %s", args, num, buffer);
386
}
387
else
388
queue_send_to_server(from_server, "NOTICE %s :You have no packs queued.", args);
389
}
390
return 0;
391
}
392
393
static int do_local_send(char *command, char *args, char *rest)
394
{
395
pack *ptr = NULL;
396
char *temp = NULL, *file = NULL, *dccinfo = NULL, *q = NULL, *p;
397
int maxdcc, maxqueue;
398
int tdcc = 0;
399
int queued_files = 0;
400
int count = 0;
401
402
if (*command == 'T')
403
tdcc = 1;
404
if (!args || !*args)
405
return 0;
406
407
maxdcc = get_int_var(DCC_SEND_LIMIT_VAR);
408
maxqueue = get_int_var(DCC_QUEUE_LIMIT_VAR);
409
410
while (1)
411
{
412
if (!(temp = next_arg(rest, &rest)))
413
break;
414
415
if (isdigit((unsigned char)*temp) || (*(temp+1) && isdigit((unsigned char)*(temp+1))))
416
{
417
if (*temp == '#')
418
temp++;
419
for (ptr = offerlist; ptr; ptr = ptr->next)
420
if (matchmcommand(temp, ptr->num))
421
break;
422
}
423
if (ptr)
424
{
425
if (maxdcc && get_active_count() >= maxdcc)
426
{
427
if (maxqueue && (numqueue >= maxqueue))
428
{
429
put_it("%s: all dcc and queue slots full", cparse(get_string_var(CDCC_PROMPT_VAR)));
430
if (queued_files)
431
put_it("%s: Queued %d files", cparse(get_string_var(CDCC_PROMPT_VAR)), queued_files );
432
return count + queued_files;
433
}
434
queued_files += add_to_queue(args, command, ptr);
435
do_hook(CDCC_SEND_NICK_LIST, "%s %s %s %d %d %d %s %s", args, "unknown", command, ptr->num, ptr->numfiles, ptr->gets, ptr->file, ptr->desc);
436
437
continue;
438
}
439
440
put_it("%s: %s %s%s%s pack #\002%d\002 (\002%d\002 file%s)", cparse(get_string_var(CDCC_PROMPT_VAR)),
441
!my_stricmp(command, "SEND")||!my_stricmp(command,"TSEND")?"sending":"resending",
442
UND_TOG_STR, args, UND_TOG_STR, ptr->num, ptr->numfiles,
443
plural(ptr->numfiles));
444
malloc_strcpy(&file, ptr->file);
445
q = file;
446
447
for (p = new_next_arg(file, &file); p && *p; p = new_next_arg(file, &file))
448
{
449
malloc_sprintf(&dccinfo, "%s \"%s\"", args, p);
450
if (!my_stricmp(command, "SEND") || !my_stricmp(command, "TSEND"))
451
dcc_filesend(command, dccinfo);
452
else
453
dcc_resend(command, dccinfo);
454
}
455
send_numpacks++;
456
count++;
457
ptr->gets++;
458
do_hook(CDCC_SEND_NICK_LIST, "%s %s %s %d %d %d %s %s", args, "unknown", command, ptr->num, ptr->numfiles, ptr->gets, ptr->file, ptr->desc);
459
}
460
else
461
{
462
if (offerlist && (isdigit((unsigned char)*temp) || (*(temp+1) && (isdigit((unsigned char)*(temp+1))))))
463
put_it("%s: No such pack number", cparse(get_string_var(CDCC_PROMPT_VAR)));
464
else
465
{
466
malloc_sprintf(&dccinfo, "%s \"%s\"", args, temp);
467
if (!my_stricmp(command, "SEND") || !my_stricmp(command, "TSEND"))
468
dcc_filesend(command, dccinfo);
469
else
470
dcc_resend(command, dccinfo);
471
count++;
472
}
473
}
474
new_free(&q);
475
file = NULL;
476
}
477
if (queued_files)
478
put_it("%s: Queued %d files", cparse(get_string_var(CDCC_PROMPT_VAR)), queued_files);
479
new_free(&dccinfo);
480
new_free(&q);
481
return count + queued_files;
482
}
483
484
static int l_send(char *args, char *rest)
485
{
486
do_local_send("SEND", args, rest);
487
return 0;
488
}
489
490
static int l_resend(char *args, char *rest)
491
{
492
do_local_send("RESEND", args, rest);
493
return 0;
494
}
495
496
#ifdef MIRC_BROKEN_DCC_RESUME
497
static int l_resume(char *args, char *rest)
498
{
499
do_local_send("RESUME", args, rest);
500
return 0;
501
}
502
#endif
503
504
static int l_tsend(char *args, char *rest)
505
{
506
do_local_send("TSEND", args, rest);
507
return 0;
508
}
509
510
static int l_tresend(char *args, char *rest)
511
{
512
do_local_send("TRESEND", args, rest);
513
return 0;
514
}
515
516
517
/*resends a pack to the requestee*/
518
/*Added by Wicked Angel: [email protected]*/
519
/*It wasn't hard ... but hey ... it seemed like a good idea :>*/
520
/* routine modified highly by Colten Edwards. */
521
522
static int do_dcc_sends(char *command, char *from, char *args)
523
{
524
pack *ptr;
525
char *temp = NULL, *file = NULL, *dccinfo = NULL, *q = NULL, *p;
526
char *password = NULL;
527
int maxdcc, maxqueue;
528
int count = 0;
529
int queued_files = 0;
530
531
maxdcc = get_int_var(DCC_SEND_LIMIT_VAR);
532
maxqueue = get_int_var(DCC_QUEUE_LIMIT_VAR);
533
534
while (1)
535
{
536
if (!(temp = next_arg(args, &args)))
537
break;
538
if (args && *args && (!my_isdigit(args)))
539
password = next_arg(args, &args);
540
541
for (ptr = offerlist; ptr; ptr = ptr->next)
542
if (matchmcommand(temp, ptr->num))
543
break;
544
if (ptr)
545
{
546
if (ptr->password && (!password || (password && strcmp(ptr->password, password))))
547
{
548
put_it("%s: Attempted get of secure pack %d from %s failed. [%s]", cparse(get_string_var(CDCC_PROMPT_VAR)), ptr->num, from, !password? "No Password": "Invalid Password");
549
queue_send_to_server(from_server, "NOTICE %s :\002CDCC\002: Failed attempt to get secure pack %d", from, ptr->num);
550
continue;
551
}
552
if (maxdcc && ((maxdcc - get_active_count()) < ptr->numfiles || get_active_count() >= maxdcc))
553
{
554
if (maxqueue && (numqueue >= maxqueue))
555
{
556
if (queued_files)
557
{
558
put_it("%s: Queued %d files for %s", cparse(get_string_var(CDCC_PROMPT_VAR)), queued_files, from);
559
queue_send_to_server(from_server, "NOTICE %s :\002CDCC\002: all slots full... Some requests ignored. Added to queue for %d requests", from, queued_files);
560
}
561
else
562
queue_send_to_server(from_server, "NOTICE %s :\002CDCC\002: all dcc and queue slots full... Try again later", from);
563
564
return 0;
565
}
566
queued_files += add_to_queue(from, command, ptr);
567
count++;
568
do_hook(CDCC_SEND_NICK_LIST, "%s %s %s %d %d %d %s %s", from, FromUserHost, command, ptr->num, ptr->numfiles, ptr->gets, ptr->file, ptr->desc);
569
continue;
570
}
571
572
put_it("%s: %s %s%s%s pack #\002%d\002 (\002%d\002 file%s)", cparse(get_string_var(CDCC_PROMPT_VAR)),
573
!my_stricmp(command, "SEND")||!my_stricmp(command, "TSEND")?"sending":!my_stricmp(command,"RESUME")?"resuming":"resending", UND_TOG_STR, from, UND_TOG_STR,
574
ptr->num, ptr->numfiles, plural(ptr->numfiles));
575
malloc_strcpy(&file, ptr->file);
576
q = file;
577
578
for (p = next_arg(file, &file); p && *p; p = next_arg(file, &file))
579
{
580
malloc_sprintf(&dccinfo, "%s %s", from, p);
581
if (!my_stricmp(command, "RESEND") || !my_stricmp(command, "TRESEND"))
582
dcc_resend(command, dccinfo);
583
#ifdef MIRC_BROKEN_DCC_RESUME
584
else if (!my_stricmp(command, "RESUME"))
585
dcc_resume(command, dccinfo);
586
#endif
587
else
588
dcc_filesend(command, dccinfo);
589
}
590
send_numpacks++;
591
ptr->gets++;
592
do_hook(CDCC_SEND_NICK_LIST, "%s %s %s %d %d %d %s %s", from, FromUserHost, command, ptr->num, ptr->numfiles, ptr->gets, ptr->file, ptr->desc);
593
}
594
else if (!count)
595
queue_send_to_server(from_server, "NOTICE %s :\002CDCC\002: invalid pack number", from);
596
count++;
597
new_free(&q);
598
file = NULL;
599
}
600
if (queued_files)
601
{
602
put_it("%s: Queued %d files for %s", cparse(get_string_var(CDCC_PROMPT_VAR)), queued_files, from);
603
queue_send_to_server(from_server, "NOTICE %s :\002CDCC\002: all slots full... Added to the queue for %d requests", from, queued_files);
604
}
605
new_free(&dccinfo);
606
new_free(&q);
607
return 0;
608
}
609
610
611
static int r_rsend(char *from, char *args)
612
{
613
do_dcc_sends("RESEND", from, args);
614
return 0;
615
}
616
617
#ifdef MIRC_BROKEN_DCC_RESUME
618
static int r_rmsend(char *from, char *args)
619
{
620
do_dcc_sends("RESUME", from, args);
621
return 0;
622
}
623
#endif
624
625
#if 0
626
static int r_trsend(char *from, char *args)
627
{
628
do_dcc_sends("TRESEND", from, args);
629
return 0;
630
}
631
632
static int r_tsend(char *from, char *args)
633
{
634
do_dcc_sends("TSEND", from, args);
635
return 0;
636
}
637
#endif
638
639
/* senD a pack to the remote user */
640
static int r_send(char *from, char *args)
641
{
642
do_dcc_sends("SEND", from, args);
643
return 0;
644
}
645
646
647
/* remote pack list */
648
static int r_list(char *from, char *args)
649
{
650
pack *ptr;
651
char size[30];
652
char mrate_out[30];
653
char mrate_in[30];
654
char bytes_out[30];
655
char bytes_in[30];
656
char speed_out[30];
657
char *type_msg;
658
int once = 0;
659
660
sprintf(mrate_out, "%1.3g", dcc_max_rate_out);
661
sprintf(mrate_in, "%1.3g", dcc_max_rate_in);
662
sprintf(bytes_out, "%1.3g", dcc_bytes_out);
663
sprintf(bytes_in, "%1.3g", dcc_bytes_in);
664
sprintf(speed_out, "%1.3g", cdcc_minspeed);
665
666
type_msg = (do_notice_list)? "NOTICE":"PRIVMSG";
667
668
for (ptr = offerlist; ptr; ptr = ptr->next)
669
{
670
if (!once && do_hook(CDCC_PREPACK_LIST, "%s %s %s %d %d %d %d %d %s %s %s %s %lu %s",
671
"NOTICE", from, get_server_nickname(from_server),
672
cdcc_numpacks,
673
get_int_var(DCC_SEND_LIMIT_VAR)-get_active_count(),
674
get_int_var(DCC_SEND_LIMIT_VAR), numqueue,
675
get_int_var(DCC_QUEUE_LIMIT_VAR),
676
mrate_out, bytes_out, mrate_in, bytes_in,
677
total_size_of_packs, speed_out))
678
{
679
queue_send_to_server(from_server,"NOTICE %s :Files Offered: /ctcp %s CDCC send #N for pack N", from, get_server_nickname(from_server));
680
if (get_int_var(DCC_SEND_LIMIT_VAR))
681
queue_send_to_server(from_server, "NOTICE %s : [%d pack%s %d/%d slots open]", from,
682
cdcc_numpacks, plural(cdcc_numpacks), get_int_var(DCC_SEND_LIMIT_VAR)-get_active_count(), get_int_var(DCC_SEND_LIMIT_VAR));
683
else
684
queue_send_to_server(from_server, "NOTICE %s : [%d pack%s]", from, cdcc_numpacks,plural(cdcc_numpacks));
685
}
686
if (ptr->size / 1024 > 999)
687
sprintf(size, "\002%4.1f\002mb",
688
(((double)ptr->size) / 1024) / 1024);
689
else
690
sprintf(size, "\002%4.1f\002kb", (((double)ptr->size) / 1024));
691
692
if (do_hook(CDCC_PACK_LIST, "%s %s %d %d %lu %d %s",
693
"NOTICE", from, ptr->num, ptr->numfiles, ptr->size, ptr->gets, ptr->desc))
694
{
695
queue_send_to_server(from_server, "NOTICE %s :#%d \037(\037%10s\037:\037\002%4d\002 get%s\037)\037 %s",
696
from, ptr->num, size, ptr->gets, plural(ptr->gets),
697
ptr->desc ? ptr->desc : "no description");
698
}
699
if (ptr->notes && do_hook(CDCC_NOTE_LIST, "%s %s %s", "NOTICE", from, ptr->notes))
700
queue_send_to_server(from_server, "NOTICE %s :\t%s", from, ptr->notes);
701
once++;
702
}
703
if (once)
704
do_hook(CDCC_POSTPACK_LIST, "%s %s %s %d %d %d %d %d %s %s %s %s %lu %s",
705
"NOTICE", from, get_server_nickname(from_server),
706
cdcc_numpacks, get_int_var(DCC_SEND_LIMIT_VAR)-get_active_count(),
707
get_int_var(DCC_SEND_LIMIT_VAR), numqueue, get_int_var(DCC_QUEUE_LIMIT_VAR),
708
mrate_out, bytes_out, mrate_in, bytes_in, total_size_of_packs, speed_out);
709
return 0;
710
}
711
712
/* remote help display */
713
static int r_help(char *from, char *args)
714
{
715
int i;
716
#ifdef CDCC_FLUD
717
if (args && *args)
718
{
719
char *q;
720
q = next_arg(args, &args);
721
for (i = 0; *remote[i].name; i++)
722
{
723
if (!my_stricmp(remote[i].name, q))
724
{
725
queue_send_to_server(from_server, "NOTICE %s :\002CDCC\002: %-6s - %s",
726
from, remote[i].name, remote[i].help);
727
break;
728
}
729
}
730
}
731
else
732
{
733
char buffer[BIG_BUFFER_SIZE+1];
734
char *q = buffer;
735
for (i = 0; *remote[i].name; i++)
736
{
737
snprintf(q, BIG_BUFFER_SIZE, "%s ", remote[i].name);
738
q = &buffer[strlen(buffer)];
739
}
740
queue_send_to_server(from_server, "NOTICE %s :\002CDCC\002: %s", from, buffer);
741
}
742
#endif
743
return 0;
744
}
745
746
747
/* remove a pack or all packs from the offerlist */
748
static int l_doffer(char *args, char *rest)
749
{
750
if (!cdcc_numpacks) {
751
put_it("%s: you have no packs offered", cparse(get_string_var(CDCC_PROMPT_VAR)));
752
return 0;
753
}
754
if (args && *args)
755
{
756
char * temp = NULL;
757
malloc_sprintf(&temp, "%s %s", args, rest ? rest : empty_string);
758
del_pack(NULL, temp);
759
new_free(&temp);
760
l_list(NULL, NULL);
761
}
762
else
763
{
764
l_list(NULL, NULL);
765
add_wait_prompt("Remove pack [* for all packs]: ", del_pack, empty_string, WAIT_PROMPT_LINE, 1);
766
}
767
return 0;
768
}
769
770
/* localy list the packs you have offered */
771
static int l_list(char *args, char *rest)
772
{
773
pack *ptr;
774
char temp[30];
775
776
if (!cdcc_numpacks)
777
{
778
put_it("%s: you have no packs offered", cparse(get_string_var(CDCC_PROMPT_VAR)));
779
return 0;
780
}
781
if (args)
782
{
783
char *num = next_arg(args, &args);
784
int it;
785
786
it = my_atol(num);
787
if (it <= 0)
788
return 0;
789
for (ptr = offerlist; ptr; ptr= ptr->next)
790
{
791
if (it == ptr->num)
792
{
793
char *temp = NULL;
794
char *p, *q;
795
int i = 1;
796
malloc_strcpy(&temp, ptr->file);
797
q = temp;
798
while (temp && *temp)
799
{
800
p = next_arg(temp, &temp);
801
put_it("#%-2d %-2d %-2d %s",
802
ptr->num, ptr->gets, i++, p);
803
}
804
805
new_free(&q);
806
break;
807
}
808
}
809
}
810
else
811
{
812
813
put_it("%s", convert_output_format("# files size gets minspeed description", NULL, NULL));
814
for (ptr = offerlist; ptr; ptr = ptr->next)
815
{
816
sprintf(temp, "%4.1f", _GMKv(ptr->size));
817
/* buggy SUNOS doesn't like this next line at all. Why?
818
sprintf(temp2, "%4.1f", (double)(ptr->minspeed));*/
819
put_it("%-2d \002%3d\002 %6s%-4s \002%4d\002 0.0 %s",
820
ptr->num, ptr->numfiles,
821
temp, _GMKs(ptr->size), /*temp2*/ptr->gets, ptr->desc);
822
}
823
}
824
return 0;
825
}
826
827
/* add a pack to the offer list */
828
static int l_offer(char *args, char *rest)
829
{
830
char *tmp = NULL;
831
if (args && *args)
832
{
833
tmp = m_sprintf("%s %s", args, rest?rest:empty_string);
834
add_files(NULL, tmp);
835
}
836
else
837
{
838
malloc_sprintf(&tmp, "Add file(s) to pack%s #%d : ", plural(cdcc_numpacks), cdcc_numpacks+1);
839
add_wait_prompt(tmp, add_files, empty_string, WAIT_PROMPT_LINE, 1);
840
}
841
new_free(&tmp);
842
return 0;
843
}
844
845
/* display the offerlist to current channel */
846
int l_plist(char *args, char *rest)
847
{
848
pack *ptr;
849
char *chan = NULL, *string = NULL;
850
char size[20];
851
char mrate_out[30];
852
char mrate_in[30];
853
char bytes_out[30];
854
char bytes_in[30];
855
char speed_out[30];
856
char *type_msg;
857
int maxdccs, blocksize, maxqueue;
858
859
if (!get_current_channel_by_refnum(0) || !cdcc_numpacks || (args && *args && !is_channel(args))) {
860
put_it("%s: you %s",cparse(get_string_var(CDCC_PROMPT_VAR)),
861
cdcc_numpacks ? "are not on a channel!" :
862
"have no packs offered!");
863
return 0;
864
}
865
type_msg = (do_notice_list)? "NOTICE":"PRIVMSG";
866
867
if (args && *args)
868
chan = LOCAL_COPY(args);
869
else
870
chan = LOCAL_COPY(get_current_channel_by_refnum(0));
871
872
maxdccs = get_int_var(DCC_SEND_LIMIT_VAR);
873
blocksize = get_int_var(DCC_BLOCK_SIZE_VAR);
874
maxqueue = get_int_var(DCC_QUEUE_LIMIT_VAR);
875
set_display_target(chan, LOG_CRAP);
876
sprintf(mrate_out, "%1.3g", dcc_max_rate_out);
877
sprintf(mrate_in, "%1.3g", dcc_max_rate_in);
878
sprintf(bytes_out, "%1.3g", dcc_bytes_out);
879
sprintf(bytes_in, "%1.3g", dcc_bytes_in);
880
sprintf(speed_out, "%1.3g", cdcc_minspeed);
881
if (do_hook(CDCC_PREPACK_LIST, "%s %s %s %d %d %d %d %d %s %s %s %s %lu %s", type_msg, chan, get_server_nickname(from_server), cdcc_numpacks, get_int_var(DCC_SEND_LIMIT_VAR)-get_active_count(), get_int_var(DCC_SEND_LIMIT_VAR), numqueue, get_int_var(DCC_QUEUE_LIMIT_VAR), mrate_out, bytes_out, mrate_in, bytes_in, total_size_of_packs, speed_out))
882
{
883
if (get_int_var(QUEUE_SENDS_VAR))
884
{
885
malloc_sprintf(&string, "\037[\037cdcc\037]\037 \002%d\002 file%s offered\037-\037 /ctcp \002%s\002 cdcc send #x for pack #x",
886
cdcc_numpacks, plural(cdcc_numpacks), get_server_nickname(from_server));
887
queue_send_to_server(from_server, "%s %s :%s",
888
do_notice_list?"NOTICE":"PRIVMSG", chan, string);
889
malloc_sprintf(&string, "\037[\037cdcc\037]\037 dcc block size\037:\037 \002%d\002, slots open\037:\037 \002%2d\002/\002%2d\002, dcc queue\037:\037 \002%2d\002/\002%2d\002",
890
(blocksize) ? blocksize : 1024, maxdccs - get_active_count(),
891
maxdccs, maxqueue - numqueue, maxqueue);
892
queue_send_to_server(from_server, "%s %s :%s",
893
do_notice_list?"NOTICE":"PRIVMSG", chan, string);
894
}
895
else
896
{
897
malloc_sprintf(&string, "\037[\037cdcc\037]\037 \002%d\002 file%s offered\037-\037 /ctcp \002%s\002 cdcc send #x for pack #x",
898
cdcc_numpacks, plural(cdcc_numpacks), get_server_nickname(from_server));
899
send_text(chan, string, do_notice_list?"NOTICE":NULL, do_cdcc_echo, 0);
900
malloc_sprintf(&string, "\037[\037cdcc\037]\037 dcc block size\037:\037 \002%d\002, slots open\037:\037 \002%2d\002/\002%2d\002, dcc queue\037:\037 \002%2d\002/\002%2d\002",
901
(blocksize) ? blocksize : 1024, maxdccs - get_active_count(),
902
maxdccs, maxqueue - numqueue, maxqueue);
903
send_text(chan, string, do_notice_list?"NOTICE":NULL, do_cdcc_echo, 0);
904
}
905
}
906
for (ptr = offerlist; ptr; ptr = ptr->next)
907
{
908
if (ptr->size / 1024 > 999)
909
sprintf(size, "\002%3.2f\002mb",
910
(float) (ptr->size / 1024) / 1024);
911
else
912
sprintf(size, "\002%3.2f\002kb", (float) ptr->size / 1024);
913
914
if (do_hook(CDCC_PACK_LIST, "%s %s %d %d %lu %d %s",
915
type_msg, chan, ptr->num, ptr->numfiles, ptr->size, ptr->gets, ptr->desc))
916
{
917
if (get_int_var(QUEUE_SENDS_VAR))
918
{
919
malloc_sprintf(&string, "\037%%\037 #%-2d \037(\037%10s\037:\037\002%4d\002 get%s\037)\037 %s",
920
ptr->num, size, ptr->gets, plural(ptr->gets),
921
ptr->desc ? ptr->desc : "no description");
922
queue_send_to_server(from_server, "%s %s :%s",
923
do_notice_list?"NOTICE":"PRIVMSG", chan, string);
924
}
925
else
926
{
927
malloc_sprintf(&string, "\037%%\037 #%-2d \037(\037%10s\037:\037\002%4d\002 get%s\037)\037 %s",
928
ptr->num, size, ptr->gets, plural(ptr->gets),
929
ptr->desc ? ptr->desc : "no description");
930
send_text(chan, string, do_notice_list?"NOTICE":NULL, do_cdcc_echo, 0);
931
}
932
}
933
if (ptr->notes && do_hook(CDCC_NOTE_LIST, "%s %s %s", type_msg, chan, ptr->notes))
934
{
935
malloc_sprintf(&string, "\t%s", ptr->notes);
936
if (get_int_var(QUEUE_SENDS_VAR))
937
queue_send_to_server(from_server, "%s %s :%s",
938
do_notice_list?"NOTICE":"PRIVMSG", chan, string);
939
else
940
send_text(chan, string, do_notice_list?"NOTICE":NULL, do_cdcc_echo, 0);
941
}
942
}
943
do_hook(CDCC_POSTPACK_LIST, "%s %s %s %d %d %d %d %d %s %s %s %s %lu %s",
944
type_msg, chan, get_server_nickname(from_server), cdcc_numpacks,
945
get_int_var(DCC_SEND_LIMIT_VAR)-get_active_count(),
946
get_int_var(DCC_SEND_LIMIT_VAR), numqueue,
947
get_int_var(DCC_QUEUE_LIMIT_VAR), mrate_out, bytes_out,
948
mrate_in, bytes_in, total_size_of_packs, speed_out);
949
reset_display_target();
950
return 0;
951
}
952
953
/* notify the current channel that packs are offered */
954
static int l_notice(char *args, char *rest)
955
{
956
char *string = NULL, *chan = NULL;
957
char mrate_out[30];
958
char mrate_in[30];
959
char bytes_out[30];
960
char bytes_in[30];
961
char speed_out[30];
962
963
if (!get_current_channel_by_refnum(0) || !cdcc_numpacks || (args && *args && !is_channel(args))) {
964
put_it("%s: you %s",cparse(get_string_var(CDCC_PROMPT_VAR)),
965
cdcc_numpacks ? "are not on a channel!" :
966
"have no packs offered!");
967
return 0;
968
}
969
970
if (args && *args)
971
malloc_strcpy(&chan, args);
972
else
973
malloc_strcpy(&chan, get_current_channel_by_refnum(0));
974
975
set_display_target(chan, LOG_CRAP);
976
sprintf(mrate_out, "%1.3g", dcc_max_rate_out);
977
sprintf(mrate_in, "%1.3g", dcc_max_rate_in);
978
sprintf(bytes_out, "%1.3g", dcc_bytes_out);
979
sprintf(bytes_in, "%1.3g", dcc_bytes_in);
980
sprintf(speed_out, "%1.3g", cdcc_minspeed);
981
if (do_hook(CDCC_PREPACK_LIST, "%s %s %s %d %d %d %d %d %s %s %s %s %lu %s", "NOTICE", chan, get_server_nickname(from_server), cdcc_numpacks, get_int_var(DCC_SEND_LIMIT_VAR)-get_active_count(), get_int_var(DCC_SEND_LIMIT_VAR), numqueue, get_int_var(DCC_QUEUE_LIMIT_VAR), mrate_out, bytes_out, mrate_in, bytes_in, total_size_of_packs, speed_out))
982
{
983
malloc_sprintf(&string, "\037[\037cdcc\037]\037 \002%d\002 file%s offered\037-\037 \037\"\037/ctcp \002%s\002 cdcc list\037\"\037 for pack list",
984
cdcc_numpacks, plural(cdcc_numpacks), get_server_nickname(from_server));
985
if (get_int_var(QUEUE_SENDS_VAR))
986
queue_send_to_server(from_server, "NOTICE %s :%s", chan, string);
987
else
988
send_text(chan, string, "NOTICE", do_cdcc_echo, 0);
989
990
}
991
992
do_hook(CDCC_POSTPACK_LIST, "%s %s %s %d %d %d %d %d %s %s %s %s %lu %s",
993
"NOTICE", chan, get_server_nickname(from_server), cdcc_numpacks,
994
get_int_var(DCC_SEND_LIMIT_VAR)-get_active_count(),
995
get_int_var(DCC_SEND_LIMIT_VAR), numqueue,
996
get_int_var(DCC_QUEUE_LIMIT_VAR), mrate_out, bytes_out, mrate_in,
997
bytes_in, total_size_of_packs, speed_out);
998
reset_display_target();
999
new_free(&chan);
1000
new_free(&string);
1001
return 0;
1002
}
1003
1004
/* display entries in your send queue */
1005
static int l_queue(char *args, char *rest)
1006
{
1007
queue *ptr, *del, *prev = NULL;
1008
int num = 1;
1009
char *command = NULL;
1010
int count = 0;
1011
1012
if (!queuelist)
1013
{
1014
put_it("%s: there are no queue entries",cparse(get_string_var(CDCC_PROMPT_VAR)));
1015
return 0;
1016
}
1017
1018
if (args && *args)
1019
command = next_arg(args, &args);
1020
if ((command == NULL) || !my_stricmp(command, "LIST"))
1021
{
1022
for (ptr = queuelist; ptr; ptr = ptr->next, num++)
1023
{
1024
if (command && rest && *rest && !wild_match(rest, ptr->nick))
1025
continue;
1026
if (command)
1027
{
1028
if (do_hook(CDCC_QUEUE_LIST, "%s %s %d %d %s", ptr->nick, my_ctime(ptr->time), ptr->num, ptr->numfiles, ptr->desc))
1029
put_it("#\002%2d\002 nick: \037%9s\037 (\002%d\002 file%s)",
1030
num, ptr->nick, ptr->numfiles,
1031
plural(ptr->numfiles));
1032
} else
1033
count++;
1034
}
1035
if (count && !command)
1036
put_it("%s: %d entries in the queue", cparse(get_string_var(CDCC_PROMPT_VAR)), count);
1037
return 0;
1038
}
1039
else if (!my_stricmp(command, "REMOVE"))
1040
{
1041
char *n;
1042
int success = 0;
1043
n = rest;
1044
if (!n || !*n)
1045
return 0;
1046
for (ptr = queuelist; ptr;)
1047
{
1048
del = ptr;
1049
ptr = ptr->next;
1050
count++;
1051
if (matchmcommand(n, count) || wild_match(n, del->nick))
1052
{
1053
if (prev)
1054
prev->next=del->next;
1055
else
1056
queuelist=del->next;
1057
new_free(&del->file);
1058
new_free(&del->nick);
1059
new_free(&del->desc);
1060
new_free((char **)&del);
1061
success++;
1062
} else
1063
prev = del;
1064
}
1065
put_it("%s: deleted %d of %d entries from the queue", cparse(get_string_var(CDCC_PROMPT_VAR)), success, count);
1066
1067
}
1068
else
1069
put_it("%s: /Cdcc queue remove #|nick /Cdcc queue list [nick]", cparse(get_string_var(CDCC_PROMPT_VAR)));
1070
return 0;
1071
}
1072
1073
/* save all of your offered packs */
1074
static int l_save(char *args, char *rest)
1075
{
1076
#ifdef PUBLIC_ACCESS
1077
bitchsay("This command has been disabled on a public access system");
1078
return;
1079
#else
1080
FILE *file;
1081
char *name = NULL, *expand = NULL;
1082
pack *ptr;
1083
int count = 0;
1084
char *fn;
1085
1086
if (!offerlist)
1087
{
1088
put_it("%s: you have no packs offered", cparse(get_string_var(CDCC_PROMPT_VAR)));
1089
return 0;
1090
}
1091
if (args)
1092
fn = args;
1093
else
1094
#if defined(WINNT) || defined(__EMX__)
1095
fn = "cdcc.save";
1096
#else
1097
fn = ".cdcc.save";
1098
#endif
1099
malloc_sprintf(&expand, "~/%s", fn);
1100
name = expand_twiddle(expand);
1101
new_free(&expand);
1102
1103
#if defined(WINNT) || defined(__EMX__)
1104
if (!name || !(file = fopen(name, "wt")))
1105
#else
1106
if (!name || !(file = fopen(name, "w")))
1107
#endif
1108
{
1109
put_it("%s: couldn't open \"%s\"", cparse(get_string_var(CDCC_PROMPT_VAR)),name?name:empty_string);
1110
new_free(&name);
1111
return 0;
1112
}
1113
fprintf(file, "#cdcc save file 1.0\n");
1114
for (ptr = offerlist; ptr; ptr = ptr->next)
1115
{
1116
fprintf(file, "%s\n", ptr->file);
1117
fprintf(file, "%s %d\n", ptr->desc, ptr->numfiles);
1118
fprintf(file, "%s\n", ptr->notes?ptr->notes:empty_string);
1119
fprintf(file, "%d %lu 0.00 %d %lu %s\n", ptr->gets, ptr->size, ptr->server, (unsigned long)ptr->timeadded, ptr->password?ptr->password:empty_string);
1120
count++;
1121
}
1122
1123
fclose(file);
1124
put_it("%s: \002%d\002 pack%s saved to %s", cparse(get_string_var(CDCC_PROMPT_VAR)),
1125
count, plural(count), name);
1126
new_free(&name);
1127
1128
return 0;
1129
#endif
1130
}
1131
1132
/* load packs from cdcc.save */
1133
static int l_load(char *args, char *rest)
1134
{
1135
FILE *file;
1136
char *buffer = NULL, *expand = NULL, *temp;
1137
pack *ptr, *last = NULL;
1138
char *p, *q;
1139
int count = 0;
1140
int got_header = 0;
1141
1142
#if defined(WINNT) || defined(__EMX__)
1143
malloc_sprintf(&expand, "~/%s", args ? args: "cdcc.save");
1144
#else
1145
malloc_sprintf(&expand, "~/%s", args ? args: ".cdcc.save");
1146
#endif
1147
buffer = expand_twiddle(expand);
1148
new_free(&expand);
1149
1150
if (!buffer || !(file = fopen(buffer, "rt")))
1151
{
1152
put_it("%s: couldn't open \"%s\"", cparse(get_string_var(CDCC_PROMPT_VAR)), buffer ? buffer : expand);
1153
new_free(&buffer);
1154
return 0;
1155
}
1156
1157
for (ptr = offerlist; ptr; ptr = ptr->next)
1158
last = ptr;
1159
1160
new_free(&buffer);
1161
buffer = new_malloc(BIG_BUFFER_SIZE+1);
1162
1163
while (fgets(buffer, BIG_BUFFER_SIZE, file)) {
1164
p = buffer;
1165
buffer[BIG_BUFFER_SIZE-1] = 0;
1166
chop(buffer, 1);
1167
if (!got_header)
1168
{
1169
if (my_strnicmp(p, "#cdcc save file 1.0", 16))
1170
{
1171
put_it("File is not a cdcc save file.");
1172
break;
1173
}
1174
got_header++;
1175
continue;
1176
}
1177
ptr = (pack *) new_malloc(sizeof(pack));
1178
ptr->num = ++cdcc_numpacks;
1179
malloc_strcpy(&ptr->file, buffer);
1180
1181
fgets(buffer, BIG_BUFFER_SIZE, file);
1182
chop(buffer, 1);
1183
1184
temp = strrchr(buffer, ' ');
1185
*temp = '\0';
1186
temp++;
1187
malloc_strcpy(&ptr->desc, buffer);
1188
1189
if (*temp && !isdigit((unsigned char)*temp))
1190
{
1191
put_it("%s: not a cdcc pack aborting", cparse(get_string_var(CDCC_PROMPT_VAR)));
1192
new_free(&ptr->file);
1193
new_free((char **)&ptr);
1194
fclose(file);
1195
return 0;
1196
}
1197
ptr->numfiles = atoi(temp);
1198
1199
fgets(buffer, BIG_BUFFER_SIZE, file);
1200
chop(buffer, 1);
1201
if (*buffer)
1202
malloc_strcpy(&ptr->notes, buffer);
1203
1204
1205
fgets(buffer, BIG_BUFFER_SIZE, file);
1206
chop(buffer, 1);
1207
1208
if ((q = next_arg(p, &p)))
1209
ptr->gets = my_atol(q);
1210
if ((q = next_arg(p, &p)))
1211
ptr->size = my_atol(q);
1212
next_arg(p, &p); /* skip over min speed for now */
1213
if ((q = next_arg(p, &p)))
1214
ptr->server = my_atol(q);
1215
1216
if ((q = next_arg(p, &p)))
1217
ptr->timeadded = my_atol(q);
1218
1219
if (p && *p)
1220
ptr->password = m_strdup(q);
1221
1222
/* ptr->gets = atoi(strtok(buffer, space));*/
1223
/* ptr->size = atol(strtok(NULL, space));*/
1224
/* ptr->minspeed = atof(strtok(NULL,"\r")); */
1225
1226
total_size_of_packs += ptr->size;
1227
ptr->next = NULL;
1228
1229
if (last) {
1230
last->next = ptr;
1231
last = ptr;
1232
} else {
1233
offerlist = ptr;
1234
last = offerlist;
1235
}
1236
count++;
1237
}
1238
1239
fclose(file);
1240
put_it("%s: \002%d\002 pack%s loaded", cparse(get_string_var(CDCC_PROMPT_VAR)), count, plural(count));
1241
set_int_var(_CDCC_PACKS_OFFERED_VAR, cdcc_numpacks);
1242
new_free(&buffer);
1243
1244
return 0;
1245
}
1246
1247
1248
1249
/* --- Misc functions --- */
1250
1251
/* add file/files to a pack */
1252
static void add_files(char *args, char *rest)
1253
{
1254
char *thefile = NULL, *expand = NULL, *path = NULL;
1255
char *temp = NULL, *filebuf = NULL;
1256
char *fptr = NULL, *f_path = NULL;
1257
1258
DIR *dptr = NULL;
1259
struct dirent *dir;
1260
struct stat statbuf;
1261
1262
path = alloca(strlen(rest)+1);
1263
strcpy(path, rest);
1264
1265
temp = alloca(BIG_BUFFER_SIZE + 1);
1266
*temp = 0;
1267
1268
f_path = alloca(BIG_BUFFER_SIZE + 1);
1269
*f_path = 0;
1270
1271
newpack = (pack *) new_malloc(sizeof(pack));
1272
1273
while((thefile = new_next_arg(path, &path)))
1274
{
1275
if (!thefile || !*thefile)
1276
break;
1277
if ((fptr = strrchr(thefile, '/')))
1278
{
1279
*fptr++ = 0;
1280
strcpy(f_path, thefile);
1281
}
1282
else
1283
{
1284
fptr = thefile;
1285
strcpy(f_path, "~");
1286
}
1287
if ((expand = expand_twiddle(f_path)))
1288
dptr = opendir(expand);
1289
if (!dptr)
1290
{
1291
put_it("%s: you cannot access dir %s. Attempting to continue", cparse(get_string_var(CDCC_PROMPT_VAR)),expand ? expand : thefile);
1292
new_free(&expand);
1293
new_free(&filebuf);
1294
continue;
1295
}
1296
while ((dir = readdir(dptr)))
1297
{
1298
if (!dir->d_ino || !wild_match(fptr, dir->d_name))
1299
continue;
1300
sprintf(temp, "%s/%s", expand, dir->d_name);
1301
stat(temp, &statbuf);
1302
sprintf(temp, "\"%s/%s\"", expand, dir->d_name);
1303
if (filebuf)
1304
malloc_strcat(&filebuf, space);
1305
malloc_strcat(&filebuf, temp);
1306
1307
if (S_ISDIR(statbuf.st_mode))
1308
continue;
1309
newpack->size += statbuf.st_size;
1310
newpack->numfiles++;
1311
total_size_of_packs += statbuf.st_size;
1312
}
1313
closedir(dptr);
1314
}
1315
if (!newpack->numfiles)
1316
{
1317
put_it("%s: no files found, aborting...", cparse(get_string_var(CDCC_PROMPT_VAR)));
1318
new_free(&expand);
1319
new_free(&filebuf);
1320
new_free((char **) &newpack);
1321
return;
1322
}
1323
1324
newpack->timeadded = now;
1325
newpack->num = ++cdcc_numpacks;
1326
newpack->server = from_server;
1327
set_int_var(_CDCC_PACKS_OFFERED_VAR, cdcc_numpacks);
1328
malloc_strcpy(&newpack->file, filebuf);
1329
1330
sprintf(temp, "Description of pack #%d : ", cdcc_numpacks);
1331
add_wait_prompt(temp, add_desc, empty_string, WAIT_PROMPT_LINE, 1);
1332
1333
new_free(&expand);
1334
new_free(&filebuf);
1335
1336
return;
1337
}
1338
1339
/* add a notes type description to the pack */
1340
static void add_note(char *args, char *rest)
1341
{
1342
if (rest && *rest)
1343
{
1344
malloc_strcpy(&newpack->notes, rest);
1345
put_it("%s: added note to pack #\002%d\002 %s", cparse(get_string_var(CDCC_PROMPT_VAR)), newpack->num, newpack->notes);
1346
}
1347
}
1348
1349
/* add a description to the new pack, and add to list */
1350
static void add_desc(char *args, char *rest)
1351
{
1352
pack *ptr, *last = NULL;
1353
char size[20];
1354
char *temp = NULL;
1355
1356
malloc_strcpy(&newpack->desc, rest);
1357
1358
for (ptr = offerlist; ptr; ptr = ptr->next)
1359
last = ptr;
1360
1361
if (last)
1362
last->next = newpack;
1363
else
1364
offerlist = newpack;
1365
newpack->next = NULL;
1366
1367
if (newpack->size / 1024 > 999)
1368
sprintf(size, "\002%3.2f\002mb", (double) (newpack->size / 1024) / 1024);
1369
else
1370
sprintf(size, "\002%3.2f\002kb", (double) newpack->size / 1024);
1371
put_it("%s: added pack #\002%d\002, \002%d\002 file%s (%s)", cparse(get_string_var(CDCC_PROMPT_VAR)),
1372
newpack->num, newpack->numfiles,
1373
plural(newpack->numfiles == 1), size);
1374
malloc_sprintf(&temp, "Notes for pack #%d : ", cdcc_numpacks);
1375
add_wait_prompt(temp, add_note, empty_string, WAIT_PROMPT_LINE, 1);
1376
new_free(&temp);
1377
return;
1378
}
1379
1380
/* handle the actual removing of packs / all packs */
1381
static void del_pack(char *args, char *rest)
1382
{
1383
pack *ptr, *last = offerlist;
1384
int packnum;
1385
int num = 0;
1386
1387
if (!rest || !*rest)
1388
{
1389
put_it("%s: No pack specified for removal", cparse(get_string_var(CDCC_PROMPT_VAR)));
1390
return;
1391
}
1392
if (*rest == '*') {
1393
cdcc_numpacks = 0;
1394
for (ptr = last = offerlist; last;)
1395
{
1396
ptr = last->next;
1397
new_free(&last->desc);
1398
new_free(&last->notes);
1399
new_free(&last->file);
1400
new_free(&last->password);
1401
new_free((char **) &last);
1402
last = ptr;
1403
}
1404
offerlist = NULL;
1405
total_size_of_packs = 0;
1406
set_int_var(_CDCC_PACKS_OFFERED_VAR, 0);
1407
put_it("%s: removed all packs from offer list", cparse(get_string_var(CDCC_PROMPT_VAR)));
1408
return;
1409
}
1410
1411
while (rest && *rest)
1412
{
1413
packnum = atoi(next_arg(rest, &rest));
1414
if (packnum <= 0)
1415
{
1416
put_it("%s: invalid pack specification", cparse(get_string_var(CDCC_PROMPT_VAR)));
1417
continue;
1418
}
1419
1420
for (ptr = offerlist; ptr; ptr = ptr->next)
1421
{
1422
if (ptr->num == packnum)
1423
{
1424
if (ptr != offerlist)
1425
last->next = ptr->next;
1426
else
1427
offerlist = ptr->next;
1428
1429
new_free(&ptr->desc);
1430
new_free(&ptr->file);
1431
new_free(&ptr->notes);
1432
new_free(&ptr->password);
1433
total_size_of_packs -= ptr->size;
1434
new_free((char **) &ptr);
1435
cdcc_numpacks--;
1436
set_int_var(_CDCC_PACKS_OFFERED_VAR, cdcc_numpacks);
1437
put_it("%s: removed pack \002%d\002 from offer list",cparse(get_string_var(CDCC_PROMPT_VAR)), packnum);
1438
num++;
1439
break;
1440
}
1441
last = ptr;
1442
}
1443
}
1444
if (num)
1445
{
1446
for (ptr = offerlist,num = 1; ptr; ptr = ptr->next)
1447
ptr->num = num++;
1448
}
1449
else
1450
put_it("%s: pack \002%s\002 does not exist", cparse(get_string_var(CDCC_PROMPT_VAR)),rest);
1451
return;
1452
}
1453
1454
/* add a person to the dcc send queue */
1455
int BX_add_to_queue(char *nick, char *command, pack *sendpack)
1456
{
1457
queue *ptr = NULL, *last = NULL, *new = NULL;
1458
static char *lastnick = NULL;
1459
int count;
1460
1461
if (!sendpack || !sendpack->file)
1462
{
1463
put_it("%s: ERROR occured in cdcc add to queue", cparse(get_string_var(CDCC_PROMPT_VAR)));
1464
return 0;
1465
}
1466
if (queuelist)
1467
{
1468
for (new = queuelist, count = 1; new; new = new->next)
1469
{
1470
if (!my_stricmp(nick, new->nick) && !my_stricmp(sendpack->file, new->file))
1471
{
1472
if (!lastnick || my_stricmp(lastnick, nick))
1473
queue_send_to_server(from_server, "NOTICE %s :\002CDCC\002: You're already Queued for %s at position %d", nick, new->desc, count);
1474
put_it("%s: Already queued %d files for %s at %d", cparse(get_string_var(CDCC_PROMPT_VAR)), sendpack->numfiles, nick, count);
1475
return 0;
1476
}
1477
}
1478
}
1479
new = (queue *) new_malloc(sizeof(queue));
1480
malloc_strcpy(&new->nick, nick);
1481
malloc_strcpy(&new->file, sendpack->file);
1482
malloc_strcpy(&new->desc, sendpack->desc);
1483
new->time = now;
1484
new->numfiles = sendpack->numfiles;
1485
new->server = from_server;
1486
new->command = m_strdup(command);
1487
new->next = NULL;
1488
sendpack->gets++;
1489
1490
for (ptr = queuelist, count = 1; ptr; ptr = ptr->next, count++)
1491
last = ptr;
1492
1493
if (last)
1494
last->next = new;
1495
else
1496
queuelist = new;
1497
numqueue++;
1498
put_it("%s: Queue position %d queuing %d files for %s", cparse(get_string_var(CDCC_PROMPT_VAR)), numqueue, sendpack->numfiles, nick);
1499
if (!lastnick || (lastnick && my_stricmp(lastnick, nick)))
1500
malloc_strcpy(&lastnick, nick);
1501
return 1;
1502
}
1503
1504
/* check queue & send files... called by irc.c io() */
1505
void dcc_sendfrom_queue(void)
1506
{
1507
queue *ptr = queuelist;
1508
char *dccinfo = NULL, *file = NULL, *temp = NULL;
1509
int old_server = from_server;
1510
int active = 0;
1511
1512
if (!ptr)
1513
return;
1514
active = get_active_count();
1515
if (active && active >= get_int_var(DCC_SEND_LIMIT_VAR))
1516
return;
1517
1518
put_it("%s: sending \037%s\037 \002%d\002 file%s from queue", cparse(get_string_var(CDCC_PROMPT_VAR)),
1519
ptr->nick, ptr->numfiles,
1520
plural(ptr->numfiles));
1521
1522
file = LOCAL_COPY(ptr->file);
1523
1524
if (ptr->server < server_list_size() && is_server_connected(ptr->server))
1525
from_server = ptr->server;
1526
1527
while ((temp = new_next_arg(file, &file)))
1528
{
1529
if (!temp || !*temp)
1530
break;
1531
malloc_sprintf(&dccinfo, "%s %s", ptr->nick, temp);
1532
if (ptr->command)
1533
{
1534
if (!my_stricmp(ptr->command, "RESEND") || !my_stricmp(ptr->command, "TRESEND"))
1535
dcc_resend(ptr->command, dccinfo);
1536
#ifdef MIRC_BROKEN_DCC_RESUME
1537
else if (!my_stricmp(ptr->command, "RESUME"))
1538
dcc_resume(ptr->command, dccinfo);
1539
#endif
1540
else
1541
dcc_filesend(NULL, dccinfo);
1542
}
1543
else
1544
dcc_filesend(ptr->command, dccinfo);
1545
}
1546
new_free(&dccinfo);
1547
1548
queuelist = ptr->next;
1549
new_free(&ptr->nick);
1550
new_free(&ptr->file);
1551
new_free(&ptr->command);
1552
new_free((char **) &ptr);
1553
numqueue--;
1554
from_server = old_server;
1555
return;
1556
}
1557
1558
static time_t plist_last_time = 0;
1559
static void get_minspeed(char *args, char *rest)
1560
{
1561
char *last = NULL;
1562
unsigned long cdcc_mintime = 0;
1563
if (rest && *rest)
1564
cdcc_minspeed = strtod(rest, &last);
1565
if (cdcc_minspeed)
1566
{
1567
put_it("%s: Minspeed value to %1.4g KB/s", cparse(get_string_var(CDCC_PROMPT_VAR)),cdcc_minspeed);
1568
if (last && *last && isdigit((unsigned char)*last))
1569
{
1570
cdcc_mintime = strtod(last, NULL);
1571
set_int_var(_CDCC_MINSPEED_TIME_VAR, cdcc_mintime);
1572
put_it("%s: Minspeed time to %5d seconds", cparse(get_string_var(CDCC_PROMPT_VAR)), cdcc_mintime);
1573
}
1574
else if (!get_int_var(_CDCC_MINSPEED_TIME_VAR))
1575
put_it("%s: Make sure and /set _CDCC_MINSPEED_TIME as well", cparse(get_string_var(CDCC_PROMPT_VAR)));
1576
}
1577
else
1578
cdcc_minspeed = 0.0;
1579
1580
}
1581
1582
static int l_minspeed(char *args, char *rest)
1583
{
1584
char *temp = NULL;
1585
malloc_sprintf(&temp, "%s min-speed (0 to disable): ", cparse(get_string_var(CDCC_PROMPT_VAR)));
1586
if (args && *args)
1587
get_minspeed(NULL, args);
1588
else
1589
add_wait_prompt(temp, get_minspeed, empty_string, WAIT_PROMPT_LINE, 1);
1590
new_free(&temp);
1591
return 0;
1592
}
1593
1594
static void get_ptimer(char *args, char *rest)
1595
{
1596
if (rest && *rest)
1597
ptimer = strtoul(rest, NULL, 10);
1598
ptimer *= 60;
1599
if (ptimer)
1600
put_it("%s: Ptimer interval %d minutes", cparse(get_string_var(CDCC_PROMPT_VAR)),ptimer/60);
1601
else
1602
plist_last_time = 0;
1603
}
1604
1605
static int l_timer(char *args, char *rest)
1606
{
1607
char *temp = NULL;
1608
malloc_sprintf(&temp, "%s p-timer interval(s) (0 to disable): ", cparse(get_string_var(CDCC_PROMPT_VAR)));
1609
if (args && *args)
1610
get_ptimer(NULL, args);
1611
else
1612
add_wait_prompt(temp, get_ptimer, empty_string, WAIT_PROMPT_LINE, 1);
1613
new_free(&temp);
1614
return 0;
1615
}
1616
1617
static void get_pchannel(char *args, char *rest)
1618
{
1619
if (rest && *rest && is_channel(rest))
1620
malloc_strcpy(&public_channel, rest);
1621
else if (rest && *rest && *rest == '*')
1622
{
1623
int i = get_window_server(0);
1624
ChannelList *chan;
1625
if (i != -1)
1626
{
1627
new_free(&public_channel);
1628
for (chan = get_server_channels(i); chan; chan = chan->next)
1629
m_s3cat(&public_channel, ",", chan->channel);
1630
} else
1631
new_free(&public_channel);
1632
}
1633
else
1634
new_free(&public_channel);
1635
if (public_channel)
1636
put_it("%s: Public timer channel(s) are [%s]", cparse(get_string_var(CDCC_PROMPT_VAR)),public_channel);
1637
else
1638
put_it("%s: Disabled %s public timer channel(s)", cparse(get_string_var(CDCC_PROMPT_VAR)), cparse(get_string_var(CDCC_PROMPT_VAR)));
1639
}
1640
1641
static int l_channel(char *args, char *rest)
1642
{
1643
if (args && *args)
1644
get_pchannel(NULL, args);
1645
else
1646
if (public_channel)
1647
put_it("%s: Public timer channel is [%s]", cparse(get_string_var(CDCC_PROMPT_VAR)),public_channel);
1648
else
1649
put_it("%s: Disabled %s public timer channel", cparse(get_string_var(CDCC_PROMPT_VAR)), cparse(get_string_var(CDCC_PROMPT_VAR)));
1650
return 0;
1651
}
1652
1653
void cdcc_timer_offer(void)
1654
{
1655
if (!offerlist || !ptimer)
1656
return;
1657
if (now - plist_last_time > ptimer)
1658
{
1659
plist_last_time = now;
1660
if (do_notice_list)
1661
l_notice(public_channel, NULL);
1662
else
1663
l_plist(public_channel, NULL);
1664
}
1665
}
1666
1667
static void add_note1(unsigned long pnum, char *note)
1668
{
1669
pack *this_pack = NULL;
1670
int i;
1671
if (pnum && note)
1672
{
1673
for (i = 1, this_pack = offerlist; this_pack; this_pack = this_pack->next, i++)
1674
if (i == pnum)
1675
break;
1676
if (this_pack)
1677
{
1678
if (note && *note)
1679
malloc_strcpy(&this_pack->notes, note);
1680
else
1681
new_free(&this_pack->notes);
1682
}
1683
else
1684
put_it("%s: Invalid pack number %ld", cparse(get_string_var(CDCC_PROMPT_VAR)), pnum);
1685
1686
}
1687
else
1688
put_it("%s: Invalid pack number %ld", cparse(get_string_var(CDCC_PROMPT_VAR)), pnum);
1689
}
1690
1691
static void add_describe(unsigned long pnum, char *describe)
1692
{
1693
pack *this_pack = NULL;
1694
int i;
1695
if (pnum && describe)
1696
{
1697
for (i = 1, this_pack = offerlist; this_pack; this_pack = this_pack->next, i++)
1698
if (i == pnum)
1699
break;
1700
if (this_pack)
1701
malloc_strcpy(&this_pack->desc, describe);
1702
else
1703
put_it("%s: Invalid pack number %ld", cparse(get_string_var(CDCC_PROMPT_VAR)), pnum);
1704
1705
}
1706
else
1707
put_it("%s: Invalid pack number %ld", cparse(get_string_var(CDCC_PROMPT_VAR)), pnum);
1708
}
1709
1710
static unsigned long got_pnum = 0;
1711
static unsigned long got_dnum = 0;
1712
1713
static void get_pnote1(char *args, char *rest)
1714
{
1715
if (got_pnum && rest)
1716
add_note1(got_pnum, rest);
1717
got_pnum = 0;
1718
}
1719
1720
static void get_desc(char *args, char *rest)
1721
{
1722
if (got_dnum && rest)
1723
add_describe(got_dnum, rest);
1724
got_dnum = 0;
1725
}
1726
1727
static void get_pnote(char *args, char *rest)
1728
{
1729
unsigned long pnum = 0;
1730
char *temp = NULL;
1731
char *p;
1732
if ((p = next_arg(rest, &rest)))
1733
pnum = strtoul(p, NULL, 10);
1734
if (rest && *rest)
1735
add_note1(pnum, rest);
1736
else
1737
{
1738
got_pnum = pnum;
1739
malloc_sprintf(&temp, "%s note to add to pack %ld ", cparse(get_string_var(CDCC_PROMPT_VAR)), pnum);
1740
add_wait_prompt(temp, get_pnote1, empty_string, WAIT_PROMPT_LINE, 1);
1741
new_free(&temp);
1742
}
1743
}
1744
1745
static void get_describe(char *args, char *rest)
1746
{
1747
unsigned long pnum = 0;
1748
char *temp = NULL;
1749
char *p;
1750
if ((p = next_arg(rest, &rest)))
1751
pnum = strtoul(p, NULL, 10);
1752
if (rest && *rest)
1753
add_describe(pnum, rest);
1754
else
1755
{
1756
got_dnum = pnum;
1757
malloc_sprintf(&temp, "%s description to add to pack %ld ", cparse(get_string_var(CDCC_PROMPT_VAR)), pnum);
1758
add_wait_prompt(temp, get_desc, empty_string, WAIT_PROMPT_LINE, 1);
1759
new_free(&temp);
1760
}
1761
}
1762
1763
static int l_note(char *args, char *rest)
1764
{
1765
char *temp = NULL;
1766
if (!offerlist)
1767
return 0;
1768
malloc_sprintf(&temp, "%s add note to pack #: ", cparse(get_string_var(CDCC_PROMPT_VAR)));
1769
if (args && *args)
1770
get_pnote(NULL, args);
1771
else
1772
add_wait_prompt(temp, get_pnote, empty_string, WAIT_PROMPT_LINE, 1);
1773
new_free(&temp);
1774
return 1;
1775
}
1776
1777
static int l_describe(char *args, char *rest)
1778
{
1779
char *temp = NULL;
1780
if (!offerlist)
1781
return 0;
1782
malloc_sprintf(&temp, "%s change description of pack #: ", cparse(get_string_var(CDCC_PROMPT_VAR)));
1783
if (args && *args)
1784
get_describe(NULL, args);
1785
else
1786
add_wait_prompt(temp, get_describe, empty_string, WAIT_PROMPT_LINE, 1);
1787
new_free(&temp);
1788
return 1;
1789
}
1790
1791
static int l_type(char *args, char *rest)
1792
{
1793
if (args && *args)
1794
do_notice_list = do_notice_list ? 0 : 1;
1795
put_it("%s: type of output for offer set to [%s]", cparse(get_string_var(CDCC_PROMPT_VAR)), do_notice_list? "Notice":"privmsg");
1796
return 0;
1797
}
1798
1799
static int l_echo(char *args, char *rest)
1800
{
1801
if (args && *args)
1802
do_cdcc_echo = do_cdcc_echo ? 0 : 1;
1803
put_it("%s: local echo set to [%s]", cparse(get_string_var(CDCC_PROMPT_VAR)), on_off(do_cdcc_echo));
1804
return 0;
1805
}
1806
1807
static int l_stats(char *args, char *rest)
1808
{
1809
char cdcc_minspeed_s[80];
1810
sprintf(cdcc_minspeed_s, "%1.3f", cdcc_minspeed);
1811
put_it("%s",convert_output_format(" %G������������������������%K[%C cdcc stat %K]%G���������������������͸", NULL));
1812
put_it("%s",convert_output_format(" %G� �", NULL));
1813
put_it("%s",convert_output_format(" %G�%g��%K[%Cp%ctimer %K]%g��-%K[%Ct%cype %K]%gķ�%K[%Ct%cotal %Cp%cacks%K]%g���%K[%Cs%cent %K]%gķ�[%Cq%cueue%K]%gķ%G�", NULL));
1814
put_it("%s",convert_output_format(" %G�%g� %W$[-10]0 %g� %W$[-10]1 %g� %W$[-10]2 %g� %W$[-8]3 %g� %W$[-7]4 %g�%G�", "%d %s %d %d %d", ptimer, do_notice_list ?"notice":"privmsg", cdcc_numpacks, send_numpacks, numqueue));
1815
put_it("%s",convert_output_format(" %G�%g������������Ľ����������������������������Ľ�������������������Ľ%G�", NULL));
1816
put_it("%s",convert_output_format(" %G� CDCC channel �", NULL));
1817
put_it("%s",convert_output_format(" %G� %W$[63]0-%G �", "%s", !public_channel ? "current channel": public_channel));
1818
put_it("%s",convert_output_format(" %g�����%K[%C %c %C %c %K]%g�������%K[%C %c %C %c %K]%g��ķ����������%K[%Ct%coggles%K]%g���������ķ", NULL));
1819
put_it("%s",convert_output_format(" %g� %C %n %W$[-6]0%n%R %g� %C %n %W$[-6]1%n%R %g� %Ct%nimer: %W$[-3]2%n %Ce%ncho: %W$[-3]3 %g�", "1 1 %s %s", on_off(ptimer), on_off(do_cdcc_echo)));
1820
put_it("%s",convert_output_format(" %g� %C %n %W$[-6]0%n%R %g� %C %n %W$[-6]1%n%R %g� %Cm%ninspeed: %W$[-3]2%n %Cs%necure:%W$[-3]3 %g�", "1 1 %s %s", cdcc_minspeed == 0.0 ? "off":cdcc_minspeed_s, on_off(get_string_var(CDCC_SECURITY_VAR) ? 1 : 0)));
1821
put_it("%s",convert_output_format(" %g�����������������Ľ����������������������������������������������Ľ", NULL));
1822
return 0;
1823
}
1824
1825
/*
1826
* TimeCawp needed this particular function so I coded it for him.
1827
* personally I don't think it's needed, but then who am I to say.
1828
*/
1829
1830
BUILT_IN_FUNCTION(function_cdcc)
1831
{
1832
pack *ptr;
1833
char *p;
1834
int it = 0;
1835
if (!cdcc_numpacks)
1836
return m_strdup(empty_string);
1837
1838
if (!(p = next_arg(input, &input)))
1839
return m_strdup(empty_string);
1840
if (!(it = my_atol(p)))
1841
return m_sprintf("%d", cdcc_numpacks);
1842
1843
for (ptr = offerlist; ptr; ptr= ptr->next)
1844
{
1845
if (it == ptr->num)
1846
return m_sprintf("%d %d %lu %d %s", ptr->num, ptr->numfiles, ptr->size, ptr->gets, ptr->desc);
1847
}
1848
return m_strdup(empty_string);
1849
}
1850
1851
BUILT_IN_FUNCTION(function_sendcdcc)
1852
{
1853
char *nick = NULL;
1854
int count = 0;
1855
int old_window_display = window_display;
1856
1857
window_display = 0;
1858
if ((nick = next_arg(input, &input)))
1859
count = do_local_send("SEND", nick, input);
1860
window_display = old_window_display;
1861
return m_sprintf("%d", count);
1862
}
1863
1864
static void add_password(unsigned long pnum, char *password)
1865
{
1866
pack *this_pack = NULL;
1867
int i;
1868
if (pnum && password)
1869
{
1870
for (i = 1, this_pack = offerlist; this_pack; this_pack = this_pack->next, i++)
1871
if (i == pnum)
1872
break;
1873
if (this_pack)
1874
{
1875
if (password && *password)
1876
malloc_strcpy(&this_pack->password, password);
1877
else
1878
{
1879
new_free(&this_pack->password);
1880
put_it("%s: Removed passwd from %ld", cparse(get_string_var(CDCC_PROMPT_VAR)), pnum);
1881
}
1882
}
1883
else
1884
put_it("%s: Invalid pack number %ld", cparse(get_string_var(CDCC_PROMPT_VAR)), pnum);
1885
1886
}
1887
else
1888
put_it("%s: Invalid pack number %ld", cparse(get_string_var(CDCC_PROMPT_VAR)), pnum);
1889
}
1890
1891
1892
static void get_passwd(char *args, char *rest)
1893
{
1894
if (got_dnum && rest)
1895
add_password(got_dnum, rest);
1896
got_dnum = 0;
1897
}
1898
1899
static void get_password(char *args, char *rest)
1900
{
1901
unsigned long pnum = 0;
1902
char *temp = NULL;
1903
char *p;
1904
if ((p = next_arg(rest, &rest)))
1905
pnum = strtoul(p, NULL, 10);
1906
if (rest && *rest)
1907
add_password(pnum, rest);
1908
else
1909
{
1910
got_dnum = pnum;
1911
malloc_sprintf(&temp, "%s password to add to pack %ld: ", cparse(get_string_var(CDCC_PROMPT_VAR)), pnum);
1912
add_wait_prompt(temp, get_passwd, empty_string, WAIT_PROMPT_LINE, 1);
1913
new_free(&temp);
1914
}
1915
}
1916
1917
static int l_secure(char *args, char *rest)
1918
{
1919
char *temp = NULL;
1920
if (!offerlist)
1921
return 0;
1922
malloc_sprintf(&temp, "%s change password of pack #: ", cparse(get_string_var(CDCC_PROMPT_VAR)));
1923
if (args && *args)
1924
get_password(NULL, args);
1925
else
1926
add_wait_prompt(temp, get_password, empty_string, WAIT_PROMPT_LINE, 1);
1927
new_free(&temp);
1928
return 0;
1929
}
1930
1931
int BX_get_num_queue(void)
1932
{
1933
return numqueue;
1934
}
1935
1936
#else /* WANT_CDCC */
1937
1938
/* this is required for functions.c to compile properly */
1939
1940
BUILD_IN_FUNCTION(function_cdcc)
1941
{
1942
return m_strdup(empty_string);
1943
}
1944
1945
BUILT_IN_FUNCTION(function_sendcdcc)
1946
{
1947
return m_strdup(empty_string);
1948
}
1949
1950
int get_num_queue(void)
1951
{
1952
return 0;
1953
}
1954
1955
#endif
1956
1957