forked from Discriminator/PDW
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Misc.cpp
2742 lines (2313 loc) · 71.8 KB
/
Misc.cpp
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
//
// Misc.cpp
//
#ifndef STRICT
#define STRICT 1
#endif
#include <windows.h>
#include "headers\pdw.h"
#include "headers\initapp.h"
#include "headers\gfx.h"
#include "headers\decode.h"
#include "headers\misc.h"
#include "headers\language.h"
#include "headers\sound_in.h"
#include "headers\helper_funcs.h"
#include "utils\binary.h"
#include "utils\smtp.h"
#define FILTER_PARAM_LEN 500
#define MAXIMUM_GROUPSIZE 1000
#define CAPCODES_INDEX 0
#define MAX_SEPFILES 32
#define MONITOR 0
#define FILTER 1
#define SEPARATE 2
#define BLOCK_ADDRESS 0
#define BLOCK_TIME 1
#define BLOCK_CHECKSUM 2
#define BLOCK_MSGADDRESS 0x01 // == 1
#define BLOCK_ONLYMSG 0x02 // == 2
#define BLOCK_TIMER 0x03 // == 3
#define BLOCK_OPTION 0x03 // == First 2 bits
#define BLOCK_LOGFILE 0x04
#define OPEN_FILE 0
#define CLOSE_FILES 1
#define CURRENT 0
#define PREVIOUS 1
#define BUILDSHOWLINE_LINEFEED 1
#define BUILDSHOWLINE_LASTCHAR 2
unsigned int bch[1025], ecs[25]; // error correction sequence
int iMatch=-1, iAddrMatch=-1, iTextMatch=-1, iTextLength=0;
int iTextPositions[10], iTextLengths[10];
int iCurrentCycle, iCurrentFrame; // Current flex cycle / frame
int aGroupCodes[17][MAXIMUM_GROUPSIZE];
int GroupFrame[17] = { -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1 };
int iPanePos=0; // PH: Current line position, used by Wordwrap
int iLabelspace_Logfile[2]; // PH: # of spaces before label ([MONITOR] / [FILTER])
int iConvertingGroupcall=0; // PH: Set with groupbit if converting a groupcall
bool bMode_IDLE=true; // PH: Set if not receiving data
bool bMobitexReplace; // PH: Set if a mobitex message needs to be replaced (replace.txt)
char szMobitexReplace[256]; // PH: Contains mobitex replacement string (replace.txt)
char aNumeric[17]={"0123456789*U -]["}; // contains numeric paging data format
bool bShown[2] = { false, false };
bool bLogged[3] = { false, false, false };
char Current_MSG[9][MAX_STR_LEN]; // PH: Buffer for all message items
// 1 = MSG_CAPCODE
// 2 = MSG_TIME
// 3 = MSG_DATE
// 4 = MSG_MODE
// 5 = MSG_TYPE
// 6 = MSG_BITRATE
// 7 = MSG_MESSAGE
// 8 = MSG_MOBITEX
char Previous_MSG[2][9][MAX_STR_LEN]; // PH: Buffer for previous message items
// PH: [8]=last filtered messagetext
unsigned long int iSecondsElapsed=0;
unsigned long int aMessages[1000][3] = {0}; // PH: Array used for blocking messages
char szLogFileLine[MAX_STR_LEN+64]; // PH: Current Logfile line
char szSepfilenames[MAX_SEPFILES][MAX_PATH];// PH: Buffer for current separate filename and the sepfiles in current groupcall
FILE* pSepFilterFiles[MAX_SEPFILES];
extern char szWindowText[6][1000];
extern char szFilenameDate[16]; // PH: Global buffer for date as filename
BYTE message_color[MAX_STR_LEN+1]; // buffer for filter colors
BYTE messageitems_colors[7]; // buffer for message items colors
unsigned char message_buffer[MAX_STR_LEN+1];// buffer for message characters
unsigned char mobitex_buffer[MAX_STR_LEN+1];// buffer for mobitex characters
unsigned char rev_msg_buffer[MAX_STR_LEN+1];// required for logfile output
int iMessageIndex=0;
char *dsc_pchar;
BYTE *dsc_pcolor;
FILE *pBlocked = NULL; // PH: Used for blocked messages
void ResetBools();
bool BlockChecker(char *address, int fnu, char *message, bool reject);
// Displays debug messages in the filter pane.
void misc_debug_msg(char *msg)
{
display_color(&Pane2, COLOR_MESSAGE);
display_show_strV2(&Pane2, msg);
}
// Reverse words in buffer which contain characters from the current character set.
// Note: Used by Hebrew language which displays messages right to left.
void reverse_msg_words(void)
{
unsigned char *s = message_buffer;
int r;
int start_x, end_x;
int v = strlen((char *)s);
for (int loop=0; loop < v; loop++)
{
if (in_lang_tbl(message_buffer[loop]) || isdigit(message_buffer[loop]))
{
start_x = loop;
while (loop < v)
{
// If not a digit and not in language table then endof word/number.
// Allow control characters.
if (!in_lang_tbl(message_buffer[loop+1]))
{
if (message_buffer[loop+1] > 65) break;
}
if (message_buffer[loop+1] == 0) break;
loop++;
}
end_x = loop;
if (end_x > start_x)
{
r = 0;
while (end_x >= start_x) rev_msg_buffer[r++] = message_buffer[end_x--];
rev_msg_buffer[r] = 0;
r=0;
while (rev_msg_buffer[r] != 0)
{
message_buffer[start_x++] = rev_msg_buffer[r];
r++;
}
}
}
}
}
// Passes string to filter buffer
void display_show_str(PaneStruct *pane, char strin[])
{
for (int x=0; ((strin[x] != 0) && (x < 256)); x++)
{
display_show_char(pane, strin[x]);
}
}
// Passes string to "pane's" buffer.
void display_show_strV2(PaneStruct *pane, char strin[])
{
for (int x=0; ((strin[x] != 0) && (x < 256)); x++)
{
build_show_line(pane, strin[x], 0);
}
}
// Builds the filter string to be shown in the upper/lower panes.
void display_show_char(PaneStruct *pane, char cin)
{
if (Profile.monitor_mobitex)
{
if (cin == 0)
{
message_buffer[iMessageIndex] = '·';
mobitex_buffer[iMessageIndex] = '·';
}
else if ((cin > 0) && (cin < 32))
{
message_buffer[iMessageIndex] = cin+32;
mobitex_buffer[iMessageIndex] = cin; // Keep original characters
}
else if ((cin > 126) && (cin != '»'))
{
message_buffer[iMessageIndex] = ' ';
mobitex_buffer[iMessageIndex] = cin; // Keep original characters
}
else
{
message_buffer[iMessageIndex] = cin;
mobitex_buffer[iMessageIndex] = cin; // Keep original characters
}
}
else
{
if (cin == '\n')
{
cin = '»'; // PH: Convert 'new line' to '»'
}
else if (cin > 127)
{
cin = '?'; // PH: Display a questionmark instead of 'unknown' characters
}
else if ((cin > 0 && cin < 32 && cin != 10) &&
(cin != 23 && cin != 4 && !Profile.monitor_acars && !Profile.monitor_mobitex))
{
cin = '?'; // PH: Display a questionmark instead of 'unknown' characters
}
message_buffer[iMessageIndex] = cin;
}
message_color[iMessageIndex] = pane->currentColor;
if (iMessageIndex < MAX_STR_LEN-1) iMessageIndex++;
} // end of display_show_char
// - Output characters to the selected Pane's buffer.
// - Displays line of text when complete.
// - After displaying line, start over on next line.
//void build_show_line(PaneStruct *pane, char cin, int linefeed)
void build_show_line(PaneStruct *pane, char cin, int option)
{
int index = iItemPositions[7]; // PH: Used when moving to new line
if (option == BUILDSHOWLINE_LINEFEED)
{
display_line(pane); // terminate/display line/start new line.
// Get buffer pointers & set correct postion in buffers.
dsc_pchar = pane->buff_char + pane->Bottom*(LINE_SIZE+1);
dsc_pcolor = pane->buff_color + pane->Bottom*(LINE_SIZE+1);
// Add spacing to continue message on next line in correct field.
for (int i=0; i<index; i++)
{
*dsc_pchar++ = ' ';
*dsc_pcolor++ = COLOR_MESSAGE;
pane->currentPos++;
}
iPanePos = pane->currentPos; // Get current pane position
return;
}
// Get buffer pointers.
dsc_pchar = pane->buff_char;
dsc_pcolor = pane->buff_color;
// Get character/color.
dsc_pchar [pane->Bottom*(LINE_SIZE+1) + pane->currentPos] = cin;
dsc_pcolor[pane->Bottom*(LINE_SIZE+1) + pane->currentPos] = pane->currentColor;
// Increment line position.
pane->currentPos++;
// Start new line?
if (option != BUILDSHOWLINE_LASTCHAR)
{
if ((pane->currentPos > NewLinePoint) || (pane->currentPos == LINE_SIZE))
{
display_line(pane); // terminate/display line/start new line.
// Get buffer pointers & set correct postion in buffers.
dsc_pchar = pane->buff_char + pane->Bottom*(LINE_SIZE+1);
dsc_pcolor = pane->buff_color + pane->Bottom*(LINE_SIZE+1);
// PH: If monitoring ACARS and no linefeed, ensure a correct spacing
if (Profile.monitor_acars) index += 16;
// Add spacing to continue message on next line in correct field.
for (int i=0; i<index; i++)
{
*dsc_pchar++ = ' ';
*dsc_pcolor++ = COLOR_MESSAGE;
pane->currentPos++;
}
}
}
iPanePos = pane->currentPos; // Get current pane position
} // end of build_show_line()
// Display the current line.
void display_line(PaneStruct *pane)
{
RECT rect;
unsigned int xx;
int scroll_amt, iVscrollInc;
char *pchar = pane->buff_char;
BYTE *pcolor = pane->buff_color;
extern unsigned int iSelectionStartRow, iSelectionEndRow;
pchar [pane->Bottom*(LINE_SIZE+1) + pane->currentPos] = 0;
pcolor[pane->Bottom*(LINE_SIZE+1) + pane->currentPos] = COLOR_UNUSED;
pane->currentPos = 0;
pane->Bottom++;
// No space left in pane's buffer so remove first line to allow
// a new line to be added on the end!
if (pane->Bottom == pane->buff_lines)
{
pane->Bottom--;
// scroll the buffer lines up 1 line
for (xx=0; xx<pane->Bottom; xx++)
{
memcpy(&pchar [xx*(LINE_SIZE+1)], &pchar [(xx+1)*(LINE_SIZE+1)], LINE_SIZE+1);
memcpy(&pcolor[xx*(LINE_SIZE+1)], &pcolor[(xx+1)*(LINE_SIZE+1)], LINE_SIZE+1);
}
pchar[xx*(LINE_SIZE+1) + 0] = 0;
pcolor[xx*(LINE_SIZE+1) + 0] = COLOR_UNUSED;
pane->iVscrollPos--;
}
pane->iVscrollMax = max(0,pane->Bottom - pane->cyLines);
// check if we need to scroll the display (i.e. are we at bottom?)
if (pane->Bottom == (pane->iVscrollPos + (pane->cyLines) + 1))
{
iVscrollInc = 1;
iVscrollInc = max(-(pane->iVscrollPos), min(iVscrollInc, pane->iVscrollMax - pane->iVscrollPos));
pane->iVscrollPos += iVscrollInc;
scroll_amt = cyChar * iVscrollInc;
ScrollWindow(pane->hWnd, 0, -scroll_amt, NULL, NULL);
rect.top = (pane->cyLines - 1) * cyChar;
rect.bottom = pane->cyClient;
rect.left = 0;
rect.right = pane->cxClient;
InvalidateRect(pane->hWnd, &rect, TRUE);
SetScrollRange(pane->hWnd, SB_VERT, 0, pane->iVscrollMax, FALSE);
SetScrollPos (pane->hWnd, SB_VERT, pane->iVscrollPos, TRUE);
if (select_on && selected && (pane == select_pane))
{
iSelectionStartRow -= iVscrollInc; // also scroll selection
iSelectionEndRow -= iVscrollInc;
InvertSelection();
selected = 1;
}
}
else // don't need to scroll display so just update
{
rect.top = 0; // (pane->Bottom-1) * cyChar; *Changed J.P*
rect.bottom = pane->Bottom * cyChar;
rect.left = 0;
rect.right = pane->cxClient;
InvalidateRect(pane->hWnd, &rect, TRUE);
}
UpdateWindow(pane->hWnd);
iPanePos = 0;
}
void AddAssignment(int assignedframe, int groupbit, int capcode)
{
if ((GroupFrame[groupbit] != assignedframe) &&
(GroupFrame[groupbit] != -1) &&
(aGroupCodes[groupbit][CAPCODES_INDEX]))
{
if (groupbit < 16) Remove_MissedGroupcall(groupbit);
}
if (aGroupCodes[groupbit][CAPCODES_INDEX] < MAXIMUM_GROUPSIZE)
{
aGroupCodes[groupbit][CAPCODES_INDEX]++;
aGroupCodes[groupbit][aGroupCodes[groupbit][CAPCODES_INDEX]] = capcode;
GroupFrame[groupbit] = assignedframe;
}
if (iMessageIndex)
{
message_buffer[iMessageIndex] = 0; // terminate the buffer string
iMessageIndex = 0;
}
}
void ConvertGroupcall(int groupbit, char *vtype, int capcode)
{
char szFile[MAX_PATH];
extern int nCount_Blocked; // PH: To keep track of the number of blocked messages
extern int nCount_Missed[2];
int addresses=0;
char address[16]="";
message_buffer[iMessageIndex] = 0; // terminate the buffer string
if (capcode >= 2029568 && capcode <= 2029583) // PH: If current capcode is a groupcode
{
if (GroupFrame[groupbit] == iCurrentFrame)
{
SortGroupCall(groupbit); // PH: Sort current groupcall in ascending order
if (Profile.BlockDuplicate)
{
for (int nCapcode=1; nCapcode <= aGroupCodes[groupbit][CAPCODES_INDEX]; nCapcode++)
{
addresses += aGroupCodes[groupbit][nCapcode]; // Make a sum of all capcodes
}
addresses += aGroupCodes[groupbit][CAPCODES_INDEX] << 25; // MSB bits represent the number of capcodes
sprintf(address, "%i", addresses);
if (BlockChecker(address, 0, (char*)message_buffer, false))
{
if (Profile.show_rejectblocked)
{
sprintf(szWindowText[5], "Blocked Duplicate GroupMessage : %i %s", 2029568+groupbit, message_buffer);
}
if (Profile.BlockDuplicate & BLOCK_LOGFILE)
{
sprintf(szFile, "%s\\blocked.txt", szPath);
if ((pBlocked = fopen(szFile, "a")) != NULL)
{
Get_Date_Time();
fprintf(pBlocked, "%i %s %s %s\n", 2029568+groupbit, szCurrentTime, szCurrentDate, message_buffer);
fclose(pBlocked);
pBlocked = NULL;
}
}
nCount_Blocked++;
GroupFrame[groupbit] = -1;
memset(aGroupCodes[groupbit], 0, sizeof(aGroupCodes[groupbit]));
iMessageIndex = 0;
return;
}
}
iConvertingGroupcall=groupbit+1;
strcpy(Current_MSG[MSG_TYPE], " GROUP ");
CreateDateFilename("", NULL); // Get current date to use as filename
for (int nCapcode=1; nCapcode <= aGroupCodes[groupbit][CAPCODES_INDEX]; nCapcode++)
{
if (aGroupCodes[groupbit][nCapcode] == 9999999) strcpy(Current_MSG[MSG_CAPCODE], "???????");
else sprintf(Current_MSG[MSG_CAPCODE], "%07i", aGroupCodes[groupbit][nCapcode]);
ShowMessage(); // PH: Display current short instruction
}
sprintf(Current_MSG[MSG_CAPCODE], "%07i", capcode);
strcpy(Current_MSG[MSG_TYPE], vtype);
ShowMessage(); // PH: Display current groupcode & original vector type
memset(aGroupCodes[groupbit], 0, sizeof(int) * MAXIMUM_GROUPSIZE);
GroupFrame[groupbit] = -1;
iConvertingGroupcall=0; // PH: Reset for next groupmessage
}
else
{
if (GroupFrame[groupbit] != -1) Remove_MissedGroupcall(groupbit);
if (Current_MSG[MSG_BITRATE][3] == '0') nCount_Missed[1]++;
CountBiterrors(5);
ShowMessage(); // PH: Display only groupcode
return;
}
}
iMessageIndex = 0;
}
void SortGroupCall(int groupbit) // PH: Sort aGroupCodes[groupbit]
{
for (int nCapcode=1; nCapcode <= aGroupCodes[groupbit][CAPCODES_INDEX]; nCapcode++)
{
int min, j;
for (min=nCapcode, j=nCapcode+1; aGroupCodes[groupbit][j] > 0; j++)
{
if (aGroupCodes[groupbit][j] < aGroupCodes[groupbit][min]) min = j;
}
int tmp=aGroupCodes[groupbit][nCapcode];
aGroupCodes[groupbit][nCapcode] = aGroupCodes[groupbit][min];
aGroupCodes[groupbit][min] = tmp; // swap them
}
}
void Check4_MissedGroupcalls()
{
int difference, assignedframe;
int currentframe=iCurrentFrame;
for (int groupbit=0; groupbit<16; groupbit++)
{
if (GroupFrame[groupbit] != -1) // Check if assignment in buffer for this groupcode
{
assignedframe = GroupFrame[groupbit]; // Get assigned frame
if ((assignedframe > 120) && (currentframe < 8)) currentframe += 128; // Assigned frame was in previous cycle
if ((assignedframe < 8) && (currentframe > 120)) assignedframe += 128; // Assigned frame is in next cycle
difference = assignedframe-currentframe; // Calculate difference
if (difference <= 0) // If difference is 0 or lower, a groupcall has been missed
{
Remove_MissedGroupcall(groupbit);
}
}
}
}
void Remove_MissedGroupcall(int groupbit)
{
extern int nCount_Missed[2], nCount_Messages, nCount_Groupcalls;
char szFile[MAX_PATH];
FILE *pFLEX_missed = NULL; // PH: file: "missed-groupcalls.txt"
sprintf(szFile, "%s\\missed-groupcalls.txt", szPath);
if (!FileExists(szFile))
{
if ((pFLEX_missed = fopen(szFile, "a")) != NULL)
{
fprintf(pFLEX_missed, " Missed Groupcalls:\n\n");
}
}
else if (pFLEX_missed == NULL) pFLEX_missed = fopen(szFile, "a");
if (pFLEX_missed)
{
Get_Date_Time();
fprintf(pFLEX_missed, " %s %s (%i-%03i) : ", szCurrentDate, szCurrentTime, groupbit+2029568, GroupFrame[groupbit]);
SortGroupCall(groupbit); // PH: Sort current groupcall in ascending order
for (int nCapcode=1; aGroupCodes[groupbit][nCapcode] > 0; nCapcode++)
{
if (aGroupCodes[groupbit][nCapcode] == 9999999) fprintf(pFLEX_missed, "??????? ");
else fprintf(pFLEX_missed, "%07i ", aGroupCodes[groupbit][nCapcode]);
}
memset(aGroupCodes[groupbit], 0, sizeof(int) * MAXIMUM_GROUPSIZE);
fwrite("\n", 1, 1, pFLEX_missed);
fclose(pFLEX_missed);
pFLEX_missed = NULL;
}
strcpy(szWindowText[5], "MISSED GROUPCALL!");
GroupFrame[groupbit] = -1;
nCount_Missed[0]++;
CountBiterrors(10);
}
void ShowMessage()
{
int pos, i, j, k, tmp_pos, iSepfile, pane;
int panepos; // PH: Temp line positions, used by Wordwrap
int iMOBITEX=0; // PH: Set if converting a Mobitex message
int BlockOnlyMsg =((Profile.BlockDuplicate & BLOCK_OPTION) == BLOCK_ONLYMSG);
bool bMONITOR=true; // PH: To indicate if current message has to be written to Pane1
bool bBlock=false, bSkip_character=false;
bool bMATCH=false, bMONITOR_ONLY=false, bFILTERED=false;
bool bShowMessage=true, bFragment=false, bGroupcode;
bool bNumeric=false;
bool bNewFile, bNewLine; // PH: To indicate if the logfile is new / already exists
bool bSeparator[2] = { true, true }; // PH: Set if a separator is needed
bool bCombine = false; // PH: Used for grouping not-group messages
static bool bPlayWaveFile, bPreviousDoubleDisplay=false;
static bool bPreviousNumeric[2]= { false, false }; // PH: Was prev.MSG numeric?
// ([MONITOR] / [FILTER])
char szFilename[MAX_PATH]; // Buffer for filenames
char szFragment[50]=""; // Buffer for fragment text
char temp[MAX_STR_LEN]; // Temp buffer
char ch; // Buffer for current character (message_buffer[pos])
char szLabelspacing[100]; // PH: Spaces before label
char szCurrentLabel[2][FILTER_LABEL_LEN+50] = { "", "" };
char aGroupnumbers[16][8]={"-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9", "10", "11", "12", "13", "14", "15", "16"};
extern bool bTrayed, bDoubleDisplay;
extern int nCount_Messages, nCount_Rejected, nCount_Blocked, nCount_Groupcalls;
DWORD dwColor;
PaneStruct *pPane;
if (!iConvertingGroupcall)
{
message_buffer[iMessageIndex]=0; // terminate the buffer string
message_color[iMessageIndex] = COLOR_UNUSED;
iMessageIndex = 0;
}
if (Profile.lang_mi_index)
{
if (Profile.reverse_msg)
{
reverse_msg_words(); // Reverse message words if language requires it.
}
for (pos=0; message_buffer[pos] != 0; pos++)
{
message_buffer[pos] = remap_ch(message_buffer[pos]);
}
}
memcpy(Current_MSG[MSG_MESSAGE], message_buffer, MAX_STR_LEN);
bMobitexReplace=false;
iMatch=Check_4_Filtermatch(); // PH: Check if current message matches a filter
bGroupcode = memcmp(Current_MSG[MSG_CAPCODE], "20295", 5) ? false : true;
if (!iConvertingGroupcall)
{
nCount_Messages++;
}
else if (bGroupcode)
{
nCount_Groupcalls++;
nCount_Messages++;
if (Profile.FlexGroupMode & FLEXGROUPMODE_HIDEGROUPCODES)
{
bShowMessage=false;
if (!bShown[MONITOR] && (Profile.BlockDuplicate & BLOCK_OPTION) == BLOCK_TIMER) // Nothing shown + using timer
{
BlockChecker(0, 0, Current_MSG[MSG_MESSAGE], true); // Current message might me in block-buffer
}
}
}
if (bShowMessage)
{
if ((strstr(Current_MSG[MSG_TYPE], "NUM")) ||
(strstr(Current_MSG[MSG_TYPE], "TONE")))
{
bNumeric = true; // This is a numeric / tone-only message
}
if (iMatch != -1)
{
Profile.filters[iMatch].hitcounter++; // Update hitcounter
memcpy(Profile.filters[iMatch].lasthit_time, Current_MSG[MSG_TIME], 8);// Update last time
memcpy(Profile.filters[iMatch].lasthit_date, Current_MSG[MSG_DATE], 8);// Update last date
bUpdateFilters = true; // Update filters.ini in UpdateFilters()
bMATCH=true;
if (Profile.filters[iMatch].monitor_only || bMobitexReplace)
{
bMONITOR_ONLY=true;
}
else
{
bFILTERED=true;
if (Profile.filterwindowonly) bMONITOR=false; // Don't display filtered messages in monitor pane
}
if (Profile.filters[iMatch].reject)
{
if (Profile.show_rejectblocked)
{
sprintf(szWindowText[5], "Rejected Message : %s %s", Current_MSG[MSG_CAPCODE], Current_MSG[MSG_MESSAGE]);
}
if (bGroupcode)
{
LogFileHandling(NULL, NULL, CLOSE_FILES);
if (bPlayWaveFile)
{
PlayWaveFile(NULL, NULL, true);
bPlayWaveFile = false;
}
if (iConvertingGroupcall)
{
ResetBools();
}
}
nCount_Rejected++;
return;
}
}
else if ((strstr(Current_MSG[MSG_MODE], "POCSAG")) &&
(memcmp(Current_MSG[MSG_MESSAGE], "WHC+", 4) == 0))
{
return;
}
if (Profile.BlockDuplicate && !iConvertingGroupcall) // Do we want to block duplicate messages?
{
bBlock = BlockChecker(Current_MSG[MSG_CAPCODE], strstr(Current_MSG[MSG_MODE], "POCSAG") ? atoi(&Current_MSG[MSG_MODE][7]) : 0, Current_MSG[MSG_MESSAGE], false);
if (bBlock)
{
if (Profile.show_rejectblocked) // Show in title bar?
{
sprintf(szWindowText[5], "Blocked Duplicate Message : %s %s", Current_MSG[MSG_CAPCODE], (Profile.monitor_mobitex && !Current_MSG[MSG_MESSAGE][0]) ? Current_MSG[MSG_TYPE] : Current_MSG[MSG_MESSAGE]);
}
if (Profile.BlockDuplicate & BLOCK_LOGFILE)
{
sprintf(szFilename, "%s\\blocked.txt", szPath); // Add to blocked.txt
if ((pBlocked = fopen(szFilename, "a")) != NULL)
{
fprintf(pBlocked, "%s %s %s %s\n", Current_MSG[MSG_CAPCODE],
Current_MSG[MSG_TIME],
Current_MSG[MSG_DATE],
Current_MSG[MSG_MESSAGE]);
fclose(pBlocked);
pBlocked = NULL;
}
}
nCount_Blocked++;
return;
}
else if (bFILTERED && !(Profile.BlockDuplicate >> 4)) // Block duplicate FILTERED messages
{
if (CompareMessage(MSG_CAPCODE, FILTER) || // Compare capcodes/addresses
(BlockOnlyMsg)) // or ignore if only comparing message
{
if (CompareMessage(MSG_MESSAGE, FILTER) && // Compare messages
CompareMessage(MSG_TYPE, FILTER)) // Compare types (mostly for Mobitex)
{
bFILTERED=false;
bMONITOR_ONLY=true;
}
}
}
}
if (bTrayed && Profile.SystemTrayRestore)
{
switch (Profile.SystemTrayRestore)
{
default:
case 1:
SystemTrayWindow(false);
break;
case 2:
if (bMONITOR_ONLY || bFILTERED) SystemTrayWindow(false);
break;
case 3:
if (bFILTERED) SystemTrayWindow(false);
break;
}
}
if (Profile.FlexGroupMode)
{
if (!iConvertingGroupcall && (Profile.FlexGroupMode & FLEXGROUPMODE_COMBINE))
{
if (CompareMessage(MSG_MESSAGE, MONITOR) && !CompareMessage(MSG_CAPCODE, MONITOR))
{
if (memcmp(Current_MSG[MSG_CAPCODE], Previous_MSG[MONITOR][MSG_CAPCODE], 2) == 0)
{
bCombine=true;
}
}
}
}
if (!bShown[MONITOR] && !bCombine) memset(szSepfilenames, 0, sizeof(szSepfilenames));
for (pane=0; pane<2; pane++) // Loop trough messageitems, first show MONITOR,
{ // then show FILTER
if (pane == MONITOR)
{
if (!bMONITOR || bCombine) continue;
else
{
pPane = &Pane1; // Show message in Pane1
}
}
else if (pane == FILTER)
{
if (!bFILTERED || bCombine) break;
else
{
pPane = &Pane2; // Show message in Pane2
}
}
if (Profile.Separator || Profile.FlexGroupMode)
{
if (bShown[pane]) // Already shown? (groupcall)
{
bSeparator[pane] = false;
}
else if (bDoubleDisplay)
{
if (strcmp(Current_MSG[MSG_TYPE], "NUMERIC") == 0)
{
bSeparator[pane] = false;
bPreviousNumeric[pane] = false;
}
}
else if (bNumeric && bPreviousNumeric[pane] && !Profile.FlexGroupMode) // If prev+current messages are numeric
{
bSeparator[pane] = false;
}
else if (CompareMessage(MSG_MESSAGE, MONITOR) && !Profile.FlexGroupMode) // Compare messages
{
bSeparator[pane] = false;
}
}
else bSeparator[pane] = false;
if (!bDoubleDisplay) bPreviousNumeric[pane] = bNumeric;
if (Profile.FlexGroupMode && bShown[pane])
{
bSeparator[pane] = false;
continue;
}
if (strstr(Current_MSG[MSG_MODE], "FLEX") && (Current_MSG[MSG_BITRATE][3] != '0'))
{
if (Profile.FlexGroupMode)
{
sprintf(szFragment, " [Fragment #%c]", char(Current_MSG[MSG_BITRATE][3])+1);
}
else sprintf(szFragment, "[Continued message - Fragment #%c]", char(Current_MSG[MSG_BITRATE][3])+1);
bFragment=true;
}
if (bSeparator[pane] && pPane->Bottom) // If pane is not empty, add an empty line
{
display_show_strV2(pPane, " ");
display_line(pPane); // Ensure last line is displayed.
}
memcpy(Previous_MSG[pane], Current_MSG, (MAX_STR_LEN * 9));
display_show_strV2(pPane, " ");
// Display&log message
for (i=0; i<7; i++)
{
if (Profile.ScreenColumns[i] == 0) break;
for (j=iPanePos; j<iItemPositions[Profile.ScreenColumns[i]]; j++)
{
display_show_strV2(pPane, " ");
}
if (Profile.ScreenColumns[i] == MSG_MESSAGE)
{
if (!Profile.FlexGroupMode && bFragment)
{
display_color(pPane, COLOR_INSTRUCTIONS);
display_show_strV2(pPane, szFragment);
display_line(pPane);
for (j=iPanePos; j<iItemPositions[MSG_MESSAGE]; j++)
{
display_show_strV2(pPane, " ");
}
}
for (pos=0; message_buffer[pos] != 0; pos++, bSkip_character=false)
{
ch = message_buffer[pos];
display_color(pPane, message_color[pos]);
if (iTextMatch != -1) // Do we (also) have a text iMatch?
{
if (iTextLengths[0] && !Profile.FlexGroupMode)
{
for (k=0; k<10 && iTextPositions[k]; k++)
{
if (pos >= iTextPositions[k] && pos < (iTextPositions[k] + iTextLengths[k]))
{
display_color(pPane, COLOR_FILTERMATCH);
}
}
}
else if (pos >= iTextMatch && pos < (iTextMatch+iTextLength))
{
display_color(pPane, COLOR_FILTERMATCH);
}
}
if (Profile.monitor_acars) // ACARS.CPP adds ATB-character
{ // to mark the end of a line.
if (ch == char(23))
{
build_show_line(pPane, ' ', BUILDSHOWLINE_LINEFEED);
bSkip_character=true;
}
}
else if (ch == ' ') // PH: If character is a space
{
if (iPanePos == iItemPositions[MSG_MESSAGE])
{
bSkip_character=true; // PH: If first char is a space, skip it
}
else if (!Profile.monitor_mobitex) // PH: Check for wordwrap
{
tmp_pos = pos;
panepos=iPanePos;
while (message_buffer[tmp_pos+1] != ' ' && message_buffer[tmp_pos] != 0)
{
tmp_pos++;
panepos++;
}
if (panepos > NewLinePoint) // PH: Move to new line
{
build_show_line(pPane, ' ', BUILDSHOWLINE_LINEFEED);
bSkip_character=true;
}
}
}
else if (ch == '»') // Check for linefeed character '»'
{
if (Profile.Linefeed)
{
if (iPanePos == iItemPositions[MSG_MESSAGE]) bSkip_character=true;
else
{
build_show_line(pPane, ' ', BUILDSHOWLINE_LINEFEED);
bSkip_character=true;
}
}
}
if (!bSkip_character) // Show current character on screen
{
build_show_line(pPane, ch, (message_buffer[pos+1] == 0) ? BUILDSHOWLINE_LASTCHAR : 0);
}
}
if (Profile.FlexGroupMode)
{
display_line(pPane); // Display first group line (time/message)
}
}
else
{
display_color(pPane, messageitems_colors[Profile.ScreenColumns[i]]);
if (Profile.ScreenColumns[i] == MSG_CAPCODE)
{
if (Profile.FlexGroupMode)
{
if (iConvertingGroupcall)
{
sprintf(temp, "GROUP%s", aGroupnumbers[iConvertingGroupcall-1]);
}
display_color(pPane, messageitems_colors[MSG_TYPE]);
display_show_strV2(pPane, iConvertingGroupcall? temp : Current_MSG[MSG_TYPE]);
if (Profile.FlexGroupMode & FLEXGROUPMODE_LOGGING)
{
sprintf(szLogFileLine, "%s %s %s %s\n",