This repository has been archived by the owner on May 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathatl-bann.c
1012 lines (953 loc) · 26.4 KB
/
atl-bann.c
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
/********************** Buko: B A N N E R stuff ************************/
/**************************************************************************/
#include "atl-head.h"
#include "atl-mydb.h"
#define MAX_BANNER_LEN 40 /* max dlzka banneru */
#define MAX_BANNER_LEN_LUSER 20 /* max dlzka banneru pre luzrof (<WIZ) ;) */
#define MYSTRLEN(x) ((int)strlen(x)) /* Eliminate ANSI problem */
#define FONTFILEMAGICNUMBER "flf2"
#define FSUFFIXLEN MYSTRLEN(TMPSUFFIX)
#define DEFAULTCOLUMNS 80
#define MAXFIRSTLINELEN 1000
/***
* deklaracie internych funkcii banneru
***/
int create_banner(UR_OBJECT user1, UR_OBJECT user2, int type, char *inpstr, int output);
int freefont();
void splitline(UR_OBJECT user1, UR_OBJECT user2, int output);
/***
* figlet (C) 1991, 1993, 1994 Glenn Chappell and Ian Chai
* Internet: <[email protected]> and <[email protected]>
* Modified by Buko <[email protected]> for Atlantis talker <www.atlantis.sk
* Banner (C) 1997,1998 by Buko
***/
int x;
/***
* POZOR NA TOTO: ak sa vyskytne font, ktory je vacsi ako M alebo N, vznikne overflow, ktory zhodi talker!!!
***/
#define M 30 /* vyska fontu -> dalej alokovane v strukture fcharnode! */
#define N 30 /* sirka fontu cim vacsi rozmer, tym vasciu cast pamate zaberie */
#define DEFAULTFONTFILE "small.flf" /* defaultny font ;) */
/***
* Globals dealing with chars that are read
***/
typedef long inchr; /* "char" read from stdin */
inchr inchrline[2000]; /* Alloc'd inchr inchrline[inchrlinelenlimit+1]; */
/* Note: not null-terminated. */
int inchrlinelen,inchrlinelenlimit;
/***
* Globals dealing with chars that are written
***/
typedef struct fc {
inchr ord;
char thechar[M][N]; /* Alloc'd char thechar[charheight][]; */
struct fc *next;
} fcharnode;
fcharnode *fcharlist;
char currchar[M][N];
int currcharwidth;
char outline[M][80]; /* Alloc'd char outline[charheight][outlinelenlimit+1]; */
int outlinelen;
/***
* Globals affected by command line options
***/
int deutschflag,justification,paragraphflag,right2left;
/***
* smushmode: (given after "-m" command line switch)
* -2: Get default value from font file (default)
* -1: Do not smush
* For explanation of non-negative values, see smushem().
***/
int smushmode;
int outputwidth;
int outlinelenlimit;
char fontdirname[255],*fontname;
/***
* Globals read from font file
***/
char hardblank;
int charheight,defaultmode;
/***
* myalloc
* Calls malloc. If malloc returns error, prints error message and quits.
***/
char *myalloc(size_t size)
{
char *ptr;
if ((ptr = (char*)malloc(size))==NULL) {
fprintf(stderr,"Out of memory\n");
exit(1);
}
else {
return ptr;
}
}
/***
* skiptoeol
* Skips to the end of a line, given a stream.
***/
void skiptoeol(FILE *fp)
{
int dummy;
while (dummy=getc(fp),dummy!='\n'&&dummy!=EOF);
}
/***
* getparams
* Handles all command-line parameters. Puts all parameters within bounds except smushmode.
* Zatial som to spravil tak, ze to len nastavuje default parametre. Najdolezitejsi je fontname
***/
void getparams(char *fontsubor)
{
int firstfont;
sprintf(fontdirname,"%s%c",TMPFOLDER,DIRSEP);
firstfont = 1;
fontname = (char*)myalloc(sizeof(char)*(MYSTRLEN(DEFAULTFONTFILE)+1));
strcpy(fontname,DEFAULTFONTFILE); /* Some systems don't have strdup() */
if ((MYSTRLEN(fontname)>=FSUFFIXLEN)?!strcmp(fontname+MYSTRLEN(fontname)-FSUFFIXLEN,TMPSUFFIX):0) {
fontname[MYSTRLEN(fontname)-FSUFFIXLEN]='\0';
}
smushmode = -2; /* default -2 - berie smushing nastavenia z fontfile, -1 - do not smush! */
deutschflag = 0;
justification = 1; /* 1 == centered -1 == default */
right2left = -1; /* default -1, 1 == odzadu */
paragraphflag = 0;
outputwidth = DEFAULTCOLUMNS; /* sirka outputu */
outlinelenlimit = outputwidth-1;
if (firstfont) {
free(fontname);
firstfont = 0;
}
fontname = fontsubor;
if ((MYSTRLEN(fontname)>=FSUFFIXLEN)?!strcmp(fontname+MYSTRLEN(fontname)-FSUFFIXLEN,TMPSUFFIX):0) {
fontname[MYSTRLEN(fontname)-FSUFFIXLEN] = '\0';
}
}
/***
* clrline
* Clears both the input (inchrline) and output (outline) storage.
***/
void clrline(void)
{
int i;
for (i=0;i<charheight;i++) {
outline[i][0] = '\0';
}
outlinelen = 0;
inchrlinelen = 0;
}
/***
* readfontchar
* Reads a font character from the font file, and places it in a newly-allocated entry in the list.
***/
void readfontchar(FILE *file,inchr theord,char *line,int maxlen)
{
int row,k;
char endchar;
fcharnode *fclsave;
fclsave = fcharlist;
fcharlist = (fcharnode*)malloc(sizeof(fcharnode));
fcharlist->ord = theord;
for (x=0;x<M;x++)
strcpy(fcharlist->thechar[x],"");
fcharlist->next = fclsave;
for (row=0;row<charheight;row++) {
if (fgets(line,maxlen+1,file)==NULL) {
line[0] = '\0';
}
k = MYSTRLEN(line)-1;
while (k>=0 && isspace(line[k])) {
k--;
}
if (k>=0) {
endchar = line[k];
while (k>=0 ? line[k]==endchar : 0) {
k--;
}
}
line[k+1] = '\0';
strcpy(fcharlist->thechar[row],line);
}
}
/***
* readfont
* Allocates memory, initializes variables, and reads in the font.
***/
int readfont(void)
{
int i,row,numsread;
inchr theord;
int maxlen,cmtlines,ffright2left;
char *fontpath,*fileline,magicnum[5];
FILE *fontfile;
int namelen;
namelen=MYSTRLEN(fontdirname);
fontpath=(char*)myalloc(sizeof(char)*(namelen+MYSTRLEN(fontname)+FSUFFIXLEN+2));
fontfile=NULL;
if (!strchr(fontname,DIRSEP)) {
strcpy(fontpath,fontdirname);
fontpath[namelen]=DIRSEP;
fontpath[namelen+1]='\0';
strcat(fontpath,fontname);
strcat(fontpath,TMPSUFFIX);
fontfile=ropen(fontpath,"r");
}
if (fontfile==NULL) {
strcpy(fontpath,fontname);
strcat(fontpath,TMPSUFFIX);
fontfile=ropen(fontpath,"r");
if (fontfile==NULL)
return 0;
}
fscanf(fontfile,"%4s",magicnum);
fileline=(char*)myalloc(sizeof(char)*(MAXFIRSTLINELEN+1));
if (fgets(fileline,MAXFIRSTLINELEN+1,fontfile)==NULL)
fileline[0]='\0';
if (MYSTRLEN(fileline)>0?fileline[MYSTRLEN(fileline)-1]!='\n':0)
skiptoeol(stdin);
/* Nacitanie dolezitych parametrov fontu!! */
numsread = sscanf(fileline,"%*c%c %d %*d %d %d %d%*[ \t]%d",&hardblank,&charheight,&maxlen,&defaultmode,&cmtlines,&ffright2left);
free(fileline);
if (strcmp(magicnum,FONTFILEMAGICNUMBER) || numsread<5)
return 1;
for (i=1;i<=cmtlines;i++)
skiptoeol(fontfile);
if (numsread<6)
ffright2left = 0;
if (charheight<1)
charheight = 1;
if (maxlen<1)
maxlen = 1;
maxlen+=100; /* Give ourselves some extra room */
if (smushmode<-1)
smushmode = -1;
if (right2left<0)
right2left = ffright2left;
if (justification<0)
justification = 2*right2left;
fileline=(char*)myalloc(sizeof(char)*(maxlen+1));
/* Allocate "missing" character */
fcharlist=(fcharnode*)malloc(sizeof(fcharnode));
fcharlist->ord=0;
for (x=0;x<M;x++)
strcpy(fcharlist->thechar[x],"");
fcharlist->next=NULL;
for (row=0;row<charheight;row++)
fcharlist->thechar[row][0]='\0';
for (theord=' ';theord<='~';theord++)
readfontchar(fontfile,theord,fileline,maxlen);
fclose(fontfile);
deltempfile(fontpath); /* vymazanie docasneho suboru s fontom */
free(fontpath);
free(fileline);
return 1;
}
/***
* linealloc
***/
void linealloc(void)
{
inchrlinelenlimit=outputwidth*4+100;
inchrline[0]='\0';
clrline();
}
/***
* getletter
* Sets currchar to point to the font entry for the given character.
* Sets currcharwidth to the width of this character.
***/
void getletter(inchr c)
{
int x;
fcharnode *charptr;
for (charptr=fcharlist;charptr==NULL?0:charptr->ord!=c;charptr=charptr->next);
if (charptr!=NULL) {
for (x=0;x<M;x++)
strcpy(currchar[x],charptr->thechar[x]);
}
else {
for (charptr=fcharlist;charptr==NULL?0:charptr->ord!=0;charptr=charptr->next);
for (x=0;x<M;x++)
strcpy(currchar[x],charptr->thechar[x]);
}
currcharwidth = MYSTRLEN(currchar[0]);
}
/***
* smushem
* Given 2 characters, attempts to smush them into 1, according to smushmode. Returns smushed character or '\0' if no smushing can be done. Assumes smushmode >= 0.
* smushmode values are sum of following (all values smush blanks):
* 1: Smush equal chars (not hardblanks)
* 2: Smush '_' with any char in hierarchy below
* 4: hierarchy: "|", "/\", "[]", "{}", "()", "<>"
* Each class in hier. can be replaced by later class.
* 8: [ + ] -> |, { + } -> |, ( + ) -> |
* 16: / + \ -> X, > + < -> X (only in that order)
* 32: hardblank + hardblank -> hardblank
***/
char smushem(char lch,char rch)
{
if (lch==' ')
return rch;
if (rch==' ')
return lch;
if (smushmode & 32) {
if (lch==hardblank && rch==hardblank)
return lch;
}
if (lch==hardblank || rch==hardblank)
return '\0';
if (smushmode & 1) {
if (lch==rch)
return lch;
}
if (smushmode & 2) {
if (lch=='_' && strchr("|/\\[]{}()<>",rch))
return rch;
if (rch=='_' && strchr("|/\\[]{}()<>",lch))
return lch;
}
if (smushmode & 4) {
if (lch=='|' && strchr("/\\[]{}()<>",rch))
return rch;
if (rch=='|' && strchr("/\\[]{}()<>",lch))
return lch;
if (strchr("/\\",lch) && strchr("[]{}()<>",rch))
return rch;
if (strchr("/\\",rch) && strchr("[]{}()<>",lch))
return lch;
if (strchr("[]",lch) && strchr("{}()<>",rch))
return rch;
if (strchr("[]",rch) && strchr("{}()<>",lch))
return lch;
if (strchr("{}",lch) && strchr("()<>",rch))
return rch;
if (strchr("{}",rch) && strchr("()<>",lch))
return lch;
if (strchr("()",lch) && strchr("<>",rch))
return rch;
if (strchr("()",rch) && strchr("<>",lch))
return lch;
}
if (smushmode & 8) {
if (lch=='[' && rch==']')
return '|';
if (rch=='[' && lch==']')
return '|';
if (lch=='{' && rch=='}')
return '|';
if (rch=='{' && lch=='}')
return '|';
if (lch=='(' && rch==')')
return '|';
if (rch=='(' && lch==')')
return '|';
}
if (smushmode & 16) {
if (lch=='/' && rch=='\\')
return 'X';
if (rch=='/' && lch=='\\')
return 'X';
if (lch=='>' && rch=='<')
return 'X';
/* Don't want the reverse of above to give 'X'. */
}
return '\0';
}
/***
* smushamt
* Returns the maximum amount that the current character can be smushed into the current line.
***/
int smushamt(void)
{
int maxsmush,amt;
int row,linebd,charbd;
char ch1,ch2;
if (smushmode==-1)
return 0;
maxsmush=currcharwidth;
for (row=0;row<charheight;row++) {
if (right2left) {
for (charbd=MYSTRLEN(currchar[row]);ch1=currchar[row][charbd],(charbd>0&&(!ch1||ch1==' '));charbd--);
for (linebd=0;ch2=outline[row][linebd],ch2==' ';linebd++);
amt=linebd+currcharwidth-1-charbd;
}
else {
for (linebd=MYSTRLEN(outline[row]);ch1 = outline[row][linebd],(linebd>0&&(!ch1||ch1==' '));linebd--);
for (charbd=0;ch2=currchar[row][charbd],ch2==' ';charbd++);
amt=charbd+outlinelen-1-linebd;
}
if (!ch1||ch1==' ')
amt++;
else if (ch2)
if (smushem(ch1,ch2)!='\0')
amt++;
if (amt<maxsmush)
maxsmush = amt;
}
return maxsmush;
}
/***
* addchar
* Attempts to add the given character onto the end of the current line.
* Returns 1 if this can be done, 0 otherwise.
***/
int addchar(inchr c)
{
int smushamount,row,k;
char templine[500];
getletter(c);
smushamount=smushamt();
if (outlinelen+currcharwidth-smushamount>outlinelenlimit || inchrlinelen+1>inchrlinelenlimit)
return 0;
strcpy(templine,"");
for (row=0;row<charheight;row++) {
if (right2left) {
strcpy(templine,currchar[row]);
for (k=0;k<smushamount;k++)
templine[currcharwidth-smushamount+k]=smushem(templine[currcharwidth-smushamount+k],outline[row][k]);
strcat(templine,outline[row]+smushamount);
strcpy(outline[row],templine);
}
else {
for (k=0;k<smushamount;k++)
outline[row][outlinelen-smushamount+k]=smushem(outline[row][outlinelen-smushamount+k],currchar[row][k]);
strcat(outline[row],currchar[row]+smushamount);
}
}
outlinelen=MYSTRLEN(outline[0]);
inchrline[inchrlinelen++] = c;
return 1;
}
/***
* putstring
* Prints out the given null-terminated string, substituting blanks for hardblanks.
* If outputwidth is 1, prints the entire string; otherwise prints at most outputwidth-1 characters.
* Prints a newline at the end of the string.
* The string is left-justified, centered or right-justified (taking outputwidth as the screen width) if justification is 0, 1 or 2, respectively.
***/
char *putstring(char string[80])
{
static char out[2000];
int i,len,ii=0;
for (i=0;i<2000;i++)
out[i]='\0';
len=MYSTRLEN(string);
if (outputwidth>1) {
if (len>outputwidth-1)
len=outputwidth-1;
if (justification>0)
for (i=1;(3-justification)*i+len+justification-2<outputwidth;i++)
out[ii++]=' ';
}
for (i=0;i<len;i++)
out[ii++]=string[i]==hardblank?' ':string[i];
out[ii++]='\n';
out[ii]='\0';
return out;
}
/***
* printline
* Prints outline using putstring, then clears the current line.
***/
void printline(UR_OBJECT user1, UR_OBJECT user2, int output)
{
int i, j;
char vystupny_banner[2000];
/* banner() */
if (output==1) {
for (i=0;i<charheight;i++) {
strcpy(vystupny_banner,putstring(outline[i]));
write_room(user1->room,vystupny_banner);
}
clrline();
}
/* tbanner() */
if (output==2) {
for (i=0;i<charheight;i++) {
strcpy(vystupny_banner,putstring(outline[i]));
sprintf(text,"~OL%s~RS",vystupny_banner);
write_user(user1, text);
if (user1!=user2)
write_user(user2, text);
}
clrline();
}
/* sbanner() */
if (output==3) {
for (i=0;i<charheight;i++) {
strcpy(vystupny_banner,putstring(outline[i]));
if (user1->room->group==2) { /* OSTROV => do roomy a vsetkych okolo */
write_room(user1->room,vystupny_banner);
for (j=0;j<MAX_LINKS;j++)
if (user1->room->link[j]!=NULL)
write_room_except(user1->room->link[j],vystupny_banner, user1);
}
else {
write_room_except(NULL,vystupny_banner,user1);
write_user(user1,vystupny_banner);
}
}
clrline();
}
}
/***
* splitline
* Splits inchrline at the last word break (bunch of consecutive blanks).
* Makes a new line out of the first part and prints it using printline.
* Makes a new line out of the second part and returns.
***/
void splitline(UR_OBJECT user1,UR_OBJECT user2, int output)
{
int i,gotspace,lastspace,len1,len2;
inchr *part1,*part2;
part1=(inchr*)myalloc(sizeof(inchr)*(inchrlinelen+1));
part2=(inchr*)myalloc(sizeof(inchr)*(inchrlinelen+1));
gotspace=lastspace=0;
for (i=inchrlinelen-1;i>=0;i--) {
if (!gotspace && inchrline[i]==' ') {
gotspace = 1;
lastspace = i;
}
if (gotspace && inchrline[i]!=' ')
break;
}
len1=i+1;
len2=inchrlinelen-lastspace-1;
for (i=0;i<len1;i++)
part1[i]=inchrline[i];
for (i=0;i<len2;i++)
part2[i]=inchrline[lastspace+1+i];
clrline();
for (i=0;i<len1;i++)
addchar(part1[i]);
printline(user1, user2, output);
for (i=0;i<len2;i++)
addchar(part2[i]);
free(part1);
free(part2);
}
/***
* Agetchar
* Replacement to getchar().
* Acts exactly like getchar if -A is NOT specified, else obtains input from All remaining command line words.
***/
int Agetchar(int flag,char *buffer)
{
int c; /* current character */
/* find next character */
c=buffer[flag++]&0xFF; /* get appropriate char of buffer */
if (!c) /* at '\0' that terminates word? */
c='\0'; /* (allows "hello '' world" to do \n at '') */
return c; /* return appropriate character */
}
/***
* banner - klasika, vypise vsetkym v miestnosti
***/
extern void banner(UR_OBJECT user,char *inpstr)
{
char name[15];
int type;
int max_font_id;
int min_font_id;
max_font_id=getfontid(1);
min_font_id=getfontid(0);
if (user->muzzled) {
write_user(user,"Si umlcany - nemozes pouzivat banner.\n");
return;
}
if (!strcmp(word[1],"-h")) {
help_fonts(user);
return;
}
if (word_count<3 || !is_number(word[1])) {
sprintf( text,"Pouzi: .banner <typ> <sprava>\n Dostupne typy: ~OL%d-%d~RS\n",min_font_id,max_font_id);
write_user(user,text);
return;
}
type=atoi(word[1]);
if (type<min_font_id || type>max_font_id) {
sprintf(text,"Typ musi byt cele kladne cislo a musi byt z rozsahu %d-%d.\n",min_font_id,max_font_id);
write_user(user,text);
return;
}
if ((user->level<MOZENADAVAT) && (contains_swearing(inpstr,user)) && (ban_swearing)) {
write_user(user,noswearing);
sprintf(text,"~OL~FR\07[CENZURA: %s sa pokusil%s napisat skaredy banner!]~RS\n",user->name,pohl(user,"","a"));
writesys(WIZ,1,text,user);
return;
}
if ((contains_advert(inpstr) && (user->level<MOZEFARBICKOVAT))) {
write_user(user,nocolors);
return;
}
if (user->vis)
strcpy(name,user->name);
else
strcpy(name,invisname(user));
inpstr=remove_first(inpstr);
if (user->level<WIZ && strlen(inpstr)>MAX_BANNER_LEN_LUSER) {
sprintf(text,"Nemozes generovat banner dlhsi ako %d znakov.\n",MAX_BANNER_LEN_LUSER);
write_user(user,text);
return;
}
if (strlen(inpstr)>MAX_BANNER_LEN) {
sprintf(text,"Sorry, maximalna dlzka banneru je %d znakov.\n",MAX_BANNER_LEN);
write_user(user,text);
return;
}
if (user->pp < BANNERCAN) { /*PP*/
sprintf(text,"Mas malo energie (%d), potrebujes aspon %d!\n",user->pp, BANNERCAN);
write_user(user,text);
return;
}
sprintf(text,"~FR%s ~RS~FWnapisal%s banner[~OL%d~RS]:\n",name,pohl(user,"","a"),type);
write_room(user->room,text);
if (!create_banner(user, NULL, type,inpstr,1)) {
write_user(user,"Chyba pri nacitavani fontu! ;(\n");
return;
}
decrease_pp(user,BANNERDEC,0);
freefont();
clrline();
}
/***
* tbanner
* tell_banner, je mozne tellovat aj sam sebe
***/
extern void tbanner(UR_OBJECT user,char *inpstr)
{
int max_font_id;
int min_font_id;
char name[15];
int type;
UR_OBJECT u;
max_font_id=getfontid(1);
min_font_id=getfontid(0);
if (user->muzzled) {
write_user(user,"Si umlcany - nemozes pouzivat tbanner.\n");
return;
}
if (!strcmp(word[1],"-h")) {
help_fonts(user);
return;
}
if (is_number(word[1]) && word_count>2) {
u=user;
type=atoi(word[1]);
}
else {
if (word_count<4 || !is_number(word[2])) {
sprintf(text,"Pouzi: .tbanner [user] <typ> <sprava>\n Dostupne typy: ~OL%d-%d~RS\n",min_font_id,max_font_id);
write_user(user,text);
return;
}
type=atoi(word[2]);
if (!(u=get_user(word[1]))) {
write_user(user,notloggedon);
return;
}
inpstr=remove_first(inpstr);
}
if (type<min_font_id || type>max_font_id) {
sprintf(text,"Typ musi byt cele kladne cislo a musi byt z rozsahu %d-%d.\n",min_font_id,max_font_id);
write_user(user,text);
return;
}
if (user->vis)
strcpy(name,user->name);
else
strcpy(name,invisname(user));
inpstr=remove_first(inpstr);
if (user->level<WIZ && strlen(inpstr)>MAX_BANNER_LEN_LUSER) {
sprintf(text,"Nemozes generovat banner dlhsi ako %d znakov.\n",MAX_BANNER_LEN_LUSER);
write_user(user,text);
return;
}
if (strlen(inpstr)>MAX_BANNER_LEN) {
sprintf(text,"Sorry, maximalna dlzka banneru je %d znakov.\n",MAX_BANNER_LEN);
write_user(user,text);
return;
}
if (u->ignall) {
if (u->malloc_start!=NULL)
sprintf(text,"%s prave nieco pise v editore.\n",u->name);
else if (u->filepos)
sprintf(text,"%s prave cita nejaky text.\n",u->name);
else
sprintf(text,"%s prave ignoruje vsetky hlasky.\n",u->name);
write_user(user,text);
return;
}
if (u->igntell) {
if (user->level<WIZ || u->level>=user->level) {
sprintf(text,"%s ignoruje telly a ostatne privatne hlasky.\n",u->name);
write_user(user,text);
return;
}
else if (user->level>WIZ || u->level<user->level) {
sprintf(text,"%s by ta normalne mal%s ignorovat.\n",u->name,pohl(u,"","a"));
write_user(user,text);
}
}
if (check_ignore_user(user,u)) { /* ignorovanie single usera */
sprintf(text,"%s Ta ignoruje.\n",u->name);
write_user(user,text);
return;
}
if (u->room->group!=user->room->group) {
sprintf(text,"%s je od teba prilis vzdialen%s na bannerovanie!\n",u->name,pohl(u,"y","a"));
write_user(user,text);
return;
}
if (((user->room->sndproof) || (u->room->sndproof)) && (user->room!=u->room)) {
if (user->room->sndproof) {
sprintf(text,"Nachadzas sa vo zvukotesnej miestnosti, %s Ta nemoze pocut.\n",u->name);
write_user(user,text);
return;
}
if (u->room->sndproof) {
sprintf(text,"%s sa nachadza vo zvukotesnej miestnosti, nemoze Ta pocut.\n",u->name);
write_user(user,text);
return;
}
}
if ((user->jailed) && (user->pp<MAXPP)) {
write_user(user,"V zalari LEN z plneho hrdla (s plnymi pp-ckami ;)!\n");
return;
}
if (user!=u) {
sprintf(text,"~OL~FW%s dostal%s banner:\n", u->name, pohl(u,"","a"));
write_user(user,text);
sprintf(text,"~OL~FW%s Ti posiela banner[%d]:\n",name,type);
write_user(u,text);
}
else {
sprintf(text,"Takto vyzera banner ~OL%d~RS:\n", type);
write_user(user,text);
}
if (!create_banner(u, user, type,inpstr,2)) {
write_user(user,"Chyba pri nacitavani fontu! ;(\n");
return;
}
freefont();
clrline();
}
/***
* sbanner
* shout_banner - vidia vsetci (okem tych, co maju ignshout)
***/
extern void sbanner(UR_OBJECT user,char *inpstr)
{
int max_font_id;
int min_font_id;
char name[15];
int type,i;
max_font_id=getfontid(1);
min_font_id=getfontid(0);
if (user->muzzled) {
write_user(user,"Si umlcany - nemozes pouzivat sbanner.\n");
return;
}
if (!strcmp(word[1],"-h")) {
help_fonts(user);
return;
}
if (word_count<3 || !is_number(word[1])) {
sprintf(text,"Pouzi: .sbanner <typ> <sprava>\n Dostupne typy: ~OL%d-%d~RS\n",min_font_id,max_font_id);
write_user(user,text);
return;
}
type=atoi(word[1]);
if (type<min_font_id || type>max_font_id) {
sprintf(text,"Typ musi byt cele kladne cislo a musi byt z rozsahu %d-%d.\n",min_font_id,max_font_id);
write_user(user,text);
return;
}
if ((user->level<MOZENADAVAT) && (contains_swearing(inpstr,user)) && (ban_swearing)) {
write_user(user,noswearing);
sprintf(text,"~OL~FR\07[CENZURA: %s sa pokusil%s napisat skaredy banner!]~RS\n",user->name,pohl(user,"","a"));
writesys(WIZ,1,text,user);
return;
}
if (contains_advert(inpstr) && (user->level<MOZEFARBICKOVAT)) {
write_user(user,nocolors);
return;
}
if (user->vis)
strcpy(name,user->name);
else
strcpy(name,invisname(user));
inpstr=remove_first(inpstr);
if (user->level<WIZ && strlen(inpstr)>MAX_BANNER_LEN_LUSER) {
sprintf(text,"Nemozes generovat banner dlhsi ako %d znakov.\n",MAX_BANNER_LEN_LUSER);
write_user(user,text);
return;
}
if (strlen(inpstr)>MAX_BANNER_LEN) {
sprintf(text,"Sorry, maximalna dlzka banneru je %d znakov.\n",MAX_BANNER_LEN);
write_user(user,text);
return;
}
if (user->pp < SBANNERCAN) {
sprintf(text,"Mas malo energie (%d), potrebujes aspon %d!\n",user->pp, SBANNERCAN);
write_user(user,text);
return;
}
sprintf(text,"~OL~FYVyslal%s si banner:\n",pohl(user,"","a"));
write_user(user,text);
sprintf(text,"~OL~FY%s vyslal%s banner[~FW%d~FY]: ~RS~FW%s\n",name,pohl(user,"","a"),type, inpstr);
if (user->room->group==2) {/* OSTROV */
write_room_except(user->room,text,user); /* do roomy */
for (i=0;i<MAX_LINKS;i++) /* a vsetkych okolo */
if (user->room->link[i]!=NULL)
write_room_except(user->room->link[i],text,user);
sprintf(text,"~OL~FY%s vyslal%s banner: ~FG[~RS~FW%s~OL~FG]~RS\n",name,pohl(user,"","a"),inpstr);
record_portalisshout(user->room->label,text);
}
else {
write_room_except(NULL,text,user);
sprintf(text,"~OL~FY%s %s banner: ~FG[~RS~FW%s~OL~FG]~RS\n",name,pohl(user,"vyslal","vyslala"),inpstr);
record_shout(text);
}
if (!create_banner(user, NULL, type,inpstr,3)) {
write_user(user,"Chyba pri nacitavani fontu! ;(\n");
return;
}
decrease_pp(user,SBANNERDEC,SBANNERDYN);
freefont();
clrline();
}
/***
* create_banner(user,type,inpstr,output) - dostane typ banneru a inpstr a vystup je v podobe tych peknych pismeniek, ake jednoduche, ze? ;)
* output:
* 1 - banner - generuje v danej roome
* 2 - tell banner - telluje danemu luserovi
* 3 - shout banner - vidia vsetci
***/
extern int create_banner(UR_OBJECT user1,UR_OBJECT user2,int type,char *inpstr,int output)
{
FILE *fptff;
char meno_fontu[50];
inchr c;
int i;
char tempfontfilename[255];
char query[100];
MYSQL_RES *result;
MYSQL_ROW row;
int wordbreakmode;
int char_not_added;
int flag=0;
/***
* wordbreakmode:
* -1: /^$/ and blanks are to be absorbed (when line break was forced
* by a blank or character larger than outlinelenlimit)
* 0: /^ *$/ and blanks are not to be absorbed
* 1: /[^ ]$/ no word break yet
* 2: /[^ ] *$/
* 3: /[^ ]$/ had a word break
***/
/* font tahame z DB, zapiseme do docasneho suboru, nakoniec zmazeme */
sprintf(query,"SELECT `fontbody` FROM `fonts` where `fontid`=%d and `enabled`='Y'",type);
if (!(result=mysql_result(query)))
return 0;
if (mysql_num_rows(result)!=1)
return 0;
row=mysql_fetch_row(result);
sprintf(meno_fontu,"%s-font%s",user1->name,TMPSUFFIX);
sprintf(tempfontfilename,"%s%c%s",TMPFOLDER,DIRSEP,meno_fontu);
if ((fptff=ropen(tempfontfilename,"w"))==NULL)
return 0;
fprintf(fptff,"%s",row[0]);
mysql_free_result(result);
fclose(fptff);
getparams(meno_fontu); /* Nastavenia parametrov - dolezite!!! */
if (!readfont())
return 0; /* neuspesne nacitanie fontov! skoncili sme, jasna sprava! ;) */
linealloc();
wordbreakmode = 0; /* typ modu brejkovania slov - vid vyssie (0) */
/* Main cyklus ;) */
while ((c = Agetchar(flag++,inpstr))!='\0') {
if (isascii(c)&&isspace(c))
c=(c=='\t'||c==' ')?' ':'\n';
if ((c>'\0' && c<' ' && c!='\n') || c==127)
continue;
/***
* Note: The following code is complex and thoroughly tested.
* Be careful when modifying!
***/
do {
char_not_added = 0;
if (wordbreakmode== -1) {
if (c==' ')
break;
else if (c=='\n') {
wordbreakmode = 0;
break;
}
wordbreakmode = 0;
}
if (c=='\n') {
printline(user1, user2, output);
wordbreakmode = 0;
}
else if (addchar(c)) {
if (c!=' ')
wordbreakmode = (wordbreakmode>=2)?3:1;
else
wordbreakmode = (wordbreakmode>0)?2:0;
}
else if (outlinelen==0) {
for (i=0;i<charheight;i++) {
if (right2left && outputwidth>1)
putstring(currchar[i]+MYSTRLEN(currchar[i])-outlinelenlimit);
else
putstring(currchar[i]);
}
wordbreakmode = -1;
}
else if (c==' ') {
if (wordbreakmode==2)
splitline(user1, user2, output);
else
printline(user1, user2, output);
wordbreakmode = -1;
}
else {
if (wordbreakmode>=2)
splitline(user1, user2, output);
else
printline(user1, user2, output);
wordbreakmode = (wordbreakmode==3)?1:0;
char_not_added = 1;
}
} while (char_not_added);
} /* end while */
if (outlinelen!=0)
printline(user1, user2, output);
return 1;
}
/***
* freefont
* uvolni naalokovanu pamat, pokial v nej niesu ine vnorene nedealokovane smerniky, zrusi pointer na strukturu, etc, etc.. ;)
***/
extern int freefont(void)
{
fcharnode *pomocny;
while (fcharlist) {
pomocny=fcharlist->next;
free((void *)fcharlist);
fcharlist=pomocny;
}
fcharlist=NULL;
return 1;
}