-
Notifications
You must be signed in to change notification settings - Fork 76
/
ProcessPreviousLine.cpp
1529 lines (1227 loc) · 53.7 KB
/
ProcessPreviousLine.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
// ProcessPreviousLine.cpp : called when a line ends with a newline
//
#include "stdafx.h"
#include "MUSHclient.h"
#include "doc.h"
#include "MUSHview.h"
#include "mxp\mxp.h"
#include "scripting\errors.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
static inline unsigned short get_foreground (int style)
{
return (style >> 4) & 0x07;
} // end of get_foreground
static inline unsigned short get_background (int style)
{
return (style >> 8) & 0x07;
} // end of get_background
static inline unsigned short get_style (int style)
{
return style & 0x0F;
} // end of get_style
// shared stuff for logging in colour
void CMUSHclientDoc::LogLineInHTMLcolour (POSITION startpos)
{
COLORREF prevcolour = NO_COLOUR;
bool bInSpan = false;
COLORREF lastforecolour = 0;
COLORREF lastbackcolour = 0;
for (POSITION pos = startpos; pos; )
{
CLine * pLine = m_LineList.GetNext (pos);
if (!pLine->styleList.IsEmpty ())
{
int iCol = 0;
CString strLine = CString (pLine->text, pLine->len);
for (POSITION style_pos = pLine->styleList.GetHeadPosition(); style_pos; )
{
COLORREF colour1,
colour2;
CStyle * pStyle = pLine->styleList.GetNext (style_pos);
int iLength = pStyle->iLength;
// ignore zero length styles
if (iLength <= 0)
continue;
GetStyleRGB (pStyle, colour1, colour2); // find what colour this style is
if (colour1 != lastforecolour || colour2 != lastbackcolour)
{
// cancel earlier span
if (bInSpan)
{
WriteToLog ("</span>");
bInSpan = false;
}
// wrap up last colour change
if (prevcolour != NO_COLOUR)
WriteToLog ("</font>");
WriteToLog (CFormat ("<font color=\"#%02X%02X%02X\">",
GetRValue (colour1),
GetGValue (colour1),
GetBValue (colour1)
));
prevcolour = colour1;
// for efficiency we will only use <span> if we need to change the
// background colour
if (colour2 != 0) // ie. not black
{
WriteToLog (CFormat ("<span style=\"color: #%02X%02X%02X; "
"background: #%02X%02X%02X\">",
GetRValue (colour1),
GetGValue (colour1),
GetBValue (colour1),
GetRValue (colour2),
GetGValue (colour2),
GetBValue (colour2)
));
bInSpan = true;
}
lastforecolour = colour1;
lastbackcolour = colour2;
}
if (pStyle->iFlags & UNDERLINE)
WriteToLog ("<u>");
WriteToLog (FixHTMLString (strLine.Mid (iCol, iLength)));
if (pStyle->iFlags & UNDERLINE)
WriteToLog ("</u>");
iCol += iLength; // new column
} // end of doing each style
} // end of having at least one style
WriteToLog ("\n", 1);
if (pLine->hard_return) // just in case we erroneously end up at start of file
break;
} // end of each line in the paragraph
if (bInSpan)
WriteToLog ("</span>");
// wrap up last colour change
if (prevcolour != NO_COLOUR)
WriteToLog ("</font>");
} // end of CMUSHclientDoc::LogLineInHTMLcolour
// here when a newline is reached - process triggers etc. for the previous line
// (ie. the current one, the one just ended)
// returns true if omitting from output
bool CMUSHclientDoc::ProcessPreviousLine (void)
{
POSITION pos,
prevpos = NULL;
int flags = NOTE_OR_COMMAND;
int iLineCount = 0;
CString strCurrentLine; // we will assemble the full line here
CPaneLine StyledLine; // and here, with style information
/*
New technique - we are going to scan *completed* lines for triggers. We know
we have a completed line (because we are here in the first place) because the
current line (m_pCurrentLine) ends with a newline.
Now, we will scan backwards until we get a line with a hard return on it (excluding this
one of course), which will be the end of the *previous* line, then work forwards and
assemble the full text of the original line.
eg.
22. AAAAAA \n
23. BBBBBB
24. CCCCCC
25. DDDDDD \n <- current line
Thus our assembled line will be "BBBBBB CCCCCC DDDDDD"
*/
// if we *do* have a hard return then we must be being called recursively
// (eg. because a trigger sent something to the world) - better bail out
// now before we get a stack overflow.
if (m_pCurrentLine->hard_return)
return false;
// get tail of list
flags = m_pCurrentLine->flags;
// we haven't yet recorded a hard return on *this* line so this is safe
for (pos = m_LineList.GetTailPosition (); pos; )
{
prevpos = pos; // remember line which did have a hard return
CLine * pLine = m_LineList.GetPrev (pos);
if (pLine->hard_return || pLine->flags != flags)
break;
}
// if prevpos is non-null it is now the position of the last line with a hard return
// so, get the next one, that is the one which starts *our* sequence
if (prevpos)
m_LineList.GetNext (prevpos);
else // must be the only line in the buffer
prevpos = m_LineList.GetHeadPosition ();
// if no prevpos, we must be at the start of the buffer (ie. no previous line
// to this one, so we'll just take the current line)
if (!prevpos)
prevpos = m_LineList.GetHeadPosition ();
// prevpos now points to the first line from the previous batch of lines
for (pos = prevpos; pos; )
{
CLine * pLine = m_LineList.GetNext (pos);
CString strLine = CString (pLine->text, pLine->len);
strCurrentLine += strLine;
// assemble styled line information
int iCol = 0;
for (POSITION stylepos = pLine->styleList.GetHeadPosition(); stylepos; )
{
CStyle * pStyle = pLine->styleList.GetNext (stylepos);
COLORREF cText,
cBack;
// find actual RGB colour of style
GetStyleRGB (pStyle, cText, cBack);
StyledLine.AddStyle (CPaneStyle ((const char *)
strLine.Mid (iCol, pStyle->iLength),
cText, cBack,
pStyle->iFlags & 7));
iCol += pStyle->iLength; // new column
}
flags = pLine->flags; // flags should be the same for all lines
iLineCount++; // count lines in this batch
if (pLine->hard_return) // just in case we erroneously end up at start of file
break;
}
// *this* line ends with a hard break
m_pCurrentLine->hard_return = true;
// for people with screen-readers
if (flags & COMMENT)
Screendraw (COMMENT, m_bLogNotes, strCurrentLine);
else if (flags & USER_INPUT)
Screendraw (USER_INPUT, m_log_input, strCurrentLine);
// if this is a world.note, and we want to log it, do so
if ((flags & COMMENT) && m_bLogNotes) // this is a note and we want it
{
// remember that we want to log it (them), for retrospective logging
for (pos = prevpos; pos; )
(m_LineList.GetNext (pos))->flags |= LOG_LINE;
// log it now?
if (m_logfile && !m_bLogRaw)
{
// get appropriate preamble
CString strPreamble = m_strLogLinePreambleNotes;
// allow %n for newline
strPreamble.Replace ("%n", "\n");
if (strPreamble.Find ('%') != -1)
strPreamble = FormatTime (CTime::GetCurrentTime(), strPreamble, m_bLogHTML);
// get appropriate Postamble
CString strPostamble = m_strLogLinePostambleNotes;
// allow %n for newline
strPostamble.Replace ("%n", "\n");
if (strPostamble.Find ('%') != -1)
strPostamble = FormatTime (CTime::GetCurrentTime(), strPostamble, m_bLogHTML);
// line preamble
WriteToLog (strPreamble);
// line itself
CString strMessage = strCurrentLine;
// output as HTML if required
if (m_bLogHTML && m_bLogInColour)
LogLineInHTMLcolour (prevpos);
// not colour - just straight HTML?
else if (m_bLogHTML)
WriteToLog (FixHTMLString (strMessage));
else
// just straight text
WriteToLog (strMessage);
// line Postamble
WriteToLog (strPostamble);
if (!(m_bLogHTML && m_bLogInColour)) // colour logging has already got a newline
WriteToLog ("\n", 1);
} // end of having a log file and logging a comment
} // end of logging wanted
// do chat snooping now :)
// I won't snoop notes because if you snoop yourself you would probably
// get into a big loop
if (!(flags & COMMENT))
for (POSITION chatpos = m_ChatList.GetHeadPosition (); chatpos; )
{
CChatSocket * pSocket = m_ChatList.GetNext (chatpos);
if (pSocket->m_iChatStatus == eChatConnected)
{
// if we turned "can snoop" flag off recently, turn snooping off
// - in the process tell him and us
if (!pSocket->m_bCanSnoop && pSocket->m_bHeIsSnooping)
pSocket->Process_Snoop (""); // dummy up "stop snooping" message
else if (pSocket->m_bHeIsSnooping)
{
// uncoloured lines
// pSocket->SendChatMessage (CHAT_SNOOP_DATA,
// CFormat ("1500%s", (LPCTSTR) strCurrentLine));
// prevpos now points to the first line from the previous batch of lines
bool bBold = false,
bUnderline = false,
bBlink = false,
bInverse = false;
unsigned int iForeground = NO_COLOUR;
unsigned int iBackground = NO_COLOUR;
CString str;
CString strRun;
for (pos = prevpos; pos; )
{
CLine * pLine = m_LineList.GetNext (pos);
int iCol = 0;
for (POSITION stylepos = pLine->styleList.GetHeadPosition(); stylepos; )
{
CStyle * pStyle = pLine->styleList.GetNext (stylepos);
strRun = CString (pLine->text, pLine->len).Mid (iCol, pStyle->iLength);
iCol += pStyle->iLength; // new column
if ((pStyle->iFlags & COLOURTYPE) == COLOUR_ANSI)
{
// do style changes
// change to bold
if ((pStyle->iFlags & HILITE) == HILITE &&
!bBold)
{
str += AnsiCode (ANSI_BOLD);
bBold = true;
}
// change to not bold
if ((pStyle->iFlags & HILITE) != HILITE &&
bBold)
{
str += AnsiCode (ANSI_CANCEL_BOLD);
bBold = false;
}
// change to blink
if ((pStyle->iFlags & BLINK) == BLINK &&
!bBlink)
{
str += AnsiCode (ANSI_BLINK);
bBlink = true;
}
// change to not blink
if ((pStyle->iFlags & BLINK) != BLINK &&
bBlink)
{
str += AnsiCode (ANSI_CANCEL_BLINK);
bBlink = false;
}
// change to underline
if ((pStyle->iFlags & UNDERLINE) == UNDERLINE &&
!bUnderline)
{
str += AnsiCode (ANSI_UNDERLINE);
bUnderline = true;
}
// change to not underline
if ((pStyle->iFlags & UNDERLINE) != UNDERLINE &&
bUnderline)
{
str += AnsiCode (ANSI_CANCEL_UNDERLINE);
bUnderline = false;
}
// change to inverse
if ((pStyle->iFlags & INVERSE) == INVERSE &&
!bInverse)
{
str += AnsiCode (ANSI_INVERSE);
bInverse = true;
}
// change to not inverse
if ((pStyle->iFlags & INVERSE) != INVERSE &&
bInverse)
{
str += AnsiCode (ANSI_CANCEL_INVERSE);
bInverse = false;
}
// change foreground
if (pStyle->iForeColour != iForeground)
{
iForeground = pStyle->iForeColour;
str += AnsiCode (iForeground + ANSI_TEXT_BLACK);
}
// change background
if (pStyle->iBackColour != iBackground)
{
iBackground = pStyle->iBackColour;
str += AnsiCode (iBackground + ANSI_BACK_BLACK);
}
} // end of ANSI colour
str += strRun;
} // end of doing each style
if (pLine->hard_return) // just in case we erroneously end up at start of file
break;
} // end of each line
pSocket->SendChatMessage (CHAT_SNOOP_DATA,
CFormat ("1500%s", (LPCTSTR) str));
} // end of snooping
} // end of being connected
} // end of all chat sessions
// if a world.note or an input line, do *not* process triggers
// nb. if you get tempted to you will get a stack overflow when
// a trigger does a world.note
if (flags & (NOTE_OR_COMMAND | HORIZ_RULE))
return false; // done all we need to do, unless input from MUD
// We can be in a plugin if we had a prompt, which was not terminated, then
// user input. The user input calls an alias, the alias does a world.note
// inside a plugin, however we are here right now because we are terminating the
// *previous* line (the prompt line).
// So, we save and restore the current plugin pointer.
CPlugin * pSavedPlugin = m_CurrentPlugin;
m_CurrentPlugin = NULL;
// triggers might set these
bool bNoLog = !m_bLogOutput;
m_bLineOmittedFromOutput = false;
bool bChangedColour = false;
m_iCurrentActionSource = eInputFromServer;
if (!SendToAllPluginCallbacks (ON_PLUGIN_LINE_RECEIVED, strCurrentLine))
m_bLineOmittedFromOutput = true;
m_iCurrentActionSource = eUnknownActionSource;
// next! see if we have a "mapping failure" line. If so, remove from map list
if (m_bMapping && !m_strMappingFailure.IsEmpty ())
{
if (( m_bMapFailureRegexp && regexec (m_MapFailureRegexp, strCurrentLine)) ||
(!m_bMapFailureRegexp && (strCurrentLine == m_strMappingFailure)))
if (!m_strMapList.IsEmpty ()) // only if we have one
{
m_strMapList.RemoveTail (); // last direction didn't work
// update status line
DrawMappingStatusLine ();
} // end of having something to remove
} // end of mapping active
// next! look for Pueblo announce string
if (strCurrentLine.Left (strlen (PUEBLO_ID_STRING1)). // and we have the string
CompareNoCase (PUEBLO_ID_STRING1) == 0 ||
strCurrentLine.Left (strlen (PUEBLO_ID_STRING2)). // and we have the string
CompareNoCase (PUEBLO_ID_STRING2) == 0 ||
strCurrentLine.Left (strlen (PUEBLO_ID_STRING3)). // and we have the string
CompareNoCase (PUEBLO_ID_STRING3) == 0)
{
if (!m_bPueblo)
MXP_error (DBG_WARNING, wrnMXP_NotStartingPueblo,
"Pueblo initiation string received, however Pueblo detection not enabled.");
else
if (m_iUseMXP == eNoMXP)
MXP_error (DBG_WARNING, wrnMXP_NotStartingPueblo,
"Pueblo initiation string received, however \"Use MXP/Pueblo\" set to \"No\".");
else
if (m_bPuebloActive)
MXP_error (DBG_WARNING, wrnMXP_NotStartingPueblo,
"Pueblo initiation string received, however Pueblo already active.");
else
{
// so turn it on :)
if (strCurrentLine.Left (strlen (PUEBLO_ID_STRING1)). // and we have the string
CompareNoCase (PUEBLO_ID_STRING1) == 0)
m_iPuebloLevel = "1.10";
else if (strCurrentLine.Left (strlen (PUEBLO_ID_STRING3)). // and we have the string
CompareNoCase (PUEBLO_ID_STRING3) == 0)
m_iPuebloLevel = "2.50";
else
m_iPuebloLevel = "1.0";
if (m_iPuebloLevel == "1.10" || m_iPuebloLevel == "2.50")
{
// first make a hash for the md5 field which hopefully others won't guess
// in a hurry :)
SHS_INFO shsInfo;
MakeRandomNumber (this, shsInfo);
// convert into 32 characters of hex
m_strPuebloMD5 = CFormat ("%08x", shsInfo.digest [0]);
m_strPuebloMD5 += CFormat ("%08x", shsInfo.digest [1]);
m_strPuebloMD5 += CFormat ("%08x", shsInfo.digest [2]);
m_strPuebloMD5 += CFormat ("%08x", shsInfo.digest [3]);
// tell the server we are ready
SendMsg (CFormat (PUEBLO_REPLY1,
(LPCTSTR) m_iPuebloLevel,
(LPCTSTR) m_strPuebloMD5), false, false, false);
}
else
SendMsg (CFormat (PUEBLO_REPLY2), false, false, false);
MXP_Off (true); // turn MXP off so the initialisation string will be accepted
} // end of Pueblo not active yet
} // end of getting Pueblo initiation string
// process any trigger
// first (first? lol) add to our recent triggers for multi-line triggers.
m_sRecentLines.push_back ((const char *) strCurrentLine);
m_newlines_received++;
// too many? remove oldest one
if (m_sRecentLines.size () > MAX_RECENT_LINES)
m_sRecentLines.pop_front ();
CString strResponse;
CTrigger * trigger_item;
CTriggerList triggerList;
CString strExtraOutput; // for sending to output
ScriptItemMap mapDeferredScripts;
OneShotItemMap mapOneShotItems;
int iBad = -1; // default to good, if not using UTF-8
// check for bad UTF8 in the line - otherwise all triggers will fail
if (m_bUTF_8)
{
int erroroffset;
iBad = _pcre_valid_utf ((const unsigned char *) (const char *) strCurrentLine,
strCurrentLine.GetLength (), &erroroffset);
if (iBad > 0)
{
m_iUTF8ErrorCount++;
// every 128 lines, warn them
if ((m_iUTF8ErrorCount & 0x7F) == 1)
ColourNote ("white", "red",
TFormat ("Previous line had a bad UTF-8 sequence at column %i, and was not evaluated for trigger matches",
iBad + 1));
}
}
// only evaluate if can process them
if (iBad <= 0)
{
// timer t ("Process all triggers");
m_CurrentPlugin = NULL;
// allow trigger evaluation for the moment
m_iStopTriggerEvaluation = eKeepEvaluatingTriggers;
PluginListIterator pit;
// Do plugins (stop if one stops trigger evaluation).
// Do only negative sequence number plugins at this point
// Suggested by Fiendish. Added in version 4.97.
for (pit = m_PluginList.begin ();
pit != m_PluginList.end () &&
(*pit)->m_iSequence < 0 &&
m_iStopTriggerEvaluation != eStopEvaluatingTriggersInAllPlugins;
++pit)
{
m_CurrentPlugin = *pit;
// allow trigger evaluation for the moment (ie. the next plugin)
m_iStopTriggerEvaluation = eKeepEvaluatingTriggers;
if (m_CurrentPlugin->m_bEnabled)
ProcessOneTriggerSequence (strCurrentLine,
StyledLine,
strResponse,
prevpos,
bNoLog,
m_bLineOmittedFromOutput,
bChangedColour,
triggerList,
strExtraOutput,
mapDeferredScripts,
mapOneShotItems);
} // end of doing each plugin
m_CurrentPlugin = NULL; // not in a plugin any more
// do main triggers
if (m_iStopTriggerEvaluation != eStopEvaluatingTriggersInAllPlugins)
{
m_iStopTriggerEvaluation = eKeepEvaluatingTriggers;
ProcessOneTriggerSequence (strCurrentLine,
StyledLine,
strResponse,
prevpos,
bNoLog,
m_bLineOmittedFromOutput,
bChangedColour,
triggerList,
strExtraOutput,
mapDeferredScripts,
mapOneShotItems);
} // end of trigger evaluation not stopped
// do plugins (stop if one stops trigger evaluation, or if it was stopped by the main world triggers)
for (pit = m_PluginList.begin ();
pit != m_PluginList.end () &&
m_iStopTriggerEvaluation != eStopEvaluatingTriggersInAllPlugins;
++pit)
{
// skip past negative sequence numbers
if ((*pit)->m_iSequence < 0)
continue;
m_CurrentPlugin = *pit;
// allow trigger evaluation for the moment (ie. the next plugin)
m_iStopTriggerEvaluation = eKeepEvaluatingTriggers;
if (m_CurrentPlugin->m_bEnabled)
ProcessOneTriggerSequence (strCurrentLine,
StyledLine,
strResponse,
prevpos,
bNoLog,
m_bLineOmittedFromOutput,
bChangedColour,
triggerList,
strExtraOutput,
mapDeferredScripts,
mapOneShotItems);
} // end of doing each plugin
m_CurrentPlugin = NULL; // not in a plugin any more
} // if iBad <= 0
// if we have changed the colour of this trigger, or omitted it from output,
// we must force an update or they won't see it
if (m_bLineOmittedFromOutput || bChangedColour)
{
// notify view to update their selection ranges
for(pos = GetFirstViewPosition(); pos != NULL; )
{
CView* pView = GetNextView(pos);
if (pView->IsKindOf(RUNTIME_CLASS(CMUSHView)))
{
CMUSHView* pmyView = (CMUSHView*)pView;
pmyView->Invalidate ();
} // end of being an output view
} // end of doing each view
} // end of colour change or output omission
// logging wanted?
if (!bNoLog)
{
// remember that we want to log it (them), for retrospective logging
for (pos = prevpos; pos; )
(m_LineList.GetNext (pos))->flags |= LOG_LINE;
// log it now?
if (m_logfile && !m_bLogRaw)
{
// get appropriate preamble
CString strPreamble = m_strLogLinePreambleOutput;
// allow %n for newline
strPreamble.Replace ("%n", "\n");
if (strPreamble.Find ('%') != -1)
strPreamble = FormatTime (m_pCurrentLine->m_theTime, strPreamble, m_bLogHTML);
// get appropriate Postamble
CString strPostamble = m_strLogLinePostambleOutput;
// allow %n for newline
strPostamble.Replace ("%n", "\n");
if (strPostamble.Find ('%') != -1)
strPostamble = FormatTime (m_pCurrentLine->m_theTime, strPostamble, m_bLogHTML);
// line preamble
WriteToLog (strPreamble);
// line itself
CString strMessage = strCurrentLine;
// fix up HTML sequences
if (m_bLogHTML && m_bLogInColour)
LogLineInHTMLcolour (prevpos);
// not colour - just straight HTML?
else if (m_bLogHTML)
WriteToLog (FixHTMLString (strMessage));
else
// straight text
WriteToLog (strMessage);
// line Postamble
WriteToLog (strPostamble);
if (!(m_bLogHTML && m_bLogInColour)) // colour logging has already got a newline
WriteToLog ("\n", 1);
} // end of having a log file
}
// if omitting from output do that now
if (m_bLineOmittedFromOutput)
{
// delete all lines in this set
for (pos = m_LineList.GetTailPosition (); pos; )
{
// if this particular line was added to the line positions array, then make it null
if (m_LineList.GetCount () % JUMP_SIZE == 1)
m_pLinePositions [m_LineList.GetCount () / JUMP_SIZE] = NULL;
// version 4.54 - keep notes, even if omitted from output ;)
// version 4.72 - also player input
// we have to push_front because we are going through the lines backwards
// this means the newline goes first. Also we process the styles in reverse order.
CLine* pLine = m_LineList.GetTail ();
if (pLine->flags & NOTE_OR_COMMAND)
{
CString strLine = CString (pLine->text, pLine->len);
int iCol = 0;
// throw in the newline if required
if (pLine->hard_return)
m_OutstandingLines.push_front (CPaneStyle (ENDLINE, 0, 0, 0));
for (POSITION stylepos = pLine->styleList.GetTailPosition(); stylepos; )
{
CStyle * pStyle = pLine->styleList.GetPrev (stylepos);
COLORREF cText,
cBack;
// find actual RGB colour of style
GetStyleRGB (pStyle, cText, cBack);
m_OutstandingLines.push_front (CPaneStyle ((const char *)
strLine.Mid (pLine->len - pStyle->iLength - iCol, pStyle->iLength),
cText, cBack, pStyle->iFlags & 7));
iCol += pStyle->iLength; // new column
} // end of each style
} // end of coming across a note or command line
else
{ // must be an output line
// consider that this line is no longer a "recent line"
// if a trigger stopped all trigger evaluation.
// Suggested by Fiendish - version 5.06
if (m_iStopTriggerEvaluation == eStopEvaluatingTriggersInAllPlugins)
if (!m_sRecentLines.empty ()) // if sane to do so
m_sRecentLines.pop_back ();
}
delete pLine; // delete contents of tail iten -- version 3.85
m_LineList.RemoveTail (); // get rid of the line
m_total_lines--; // don't count as received
// if this was the first line, we have done enough
if (pos == prevpos)
break;
m_LineList.GetPrev (pos);
}
// try to allow world.tells to span omitted lines
if (!m_LineList.IsEmpty ())
{
m_pCurrentLine = m_LineList.GetTail ();
if (((m_pCurrentLine->flags & COMMENT) == 0) ||
m_pCurrentLine->hard_return)
m_pCurrentLine = NULL;
}
else
m_pCurrentLine = NULL;
if (!m_pCurrentLine)
{
// restart with a blank line at the end of the list
m_pCurrentLine = new CLine (++m_total_lines,
m_nWrapColumn,
m_iFlags,
m_iForeColour,
m_iBackColour,
m_bUTF_8);
pos = m_LineList.AddTail (m_pCurrentLine);
if (m_LineList.GetCount () % JUMP_SIZE == 1)
m_pLinePositions [m_LineList.GetCount () / JUMP_SIZE] = pos;
}
}
else
Screendraw (0, !bNoLog, strCurrentLine);
// put note lines back
OutputOutstandingLines ();
// display any stuff sent to output window
if (!strExtraOutput.IsEmpty ())
DisplayMsg (strExtraOutput, strExtraOutput.GetLength (), COMMENT);
// execute scripts now *after* we have done our omitting from output
m_bInSendToScript = false; // they can do DeleteLines here
// now that lines have been omitted run scripts now that wanted to be deferred
for (ScriptItemMap::const_iterator deferred_it = mapDeferredScripts.begin ();
deferred_it != mapDeferredScripts.end ();
deferred_it++)
{
int iSavedDepth = m_iExecutionDepth;
m_iExecutionDepth = 0; // no execution depth yet
m_iCurrentActionSource = eTriggerFired;
m_CurrentPlugin = deferred_it->pWhichPlugin; // set back to correct plugin
// if Lua, add style info to script space
if (GetScriptEngine () && GetScriptEngine ()->L)
{
lua_State * L = GetScriptEngine ()->L;
lua_newtable(L);
int i = 1; // style run number
for (CPaneStyleVector::iterator style_it = StyledLine.m_vStyles.begin ();
style_it != StyledLine.m_vStyles.end ();
style_it++, i++)
{
lua_newtable(L);
MakeTableItem (L, "text", (*style_it)->m_sText);
MakeTableItem (L, "length", (*style_it)->m_sText.length ());
MakeTableItem (L, "textcolour", (*style_it)->m_cText);
MakeTableItem (L, "backcolour", (*style_it)->m_cBack);
MakeTableItem (L, "style", (*style_it)->m_iStyle);
lua_rawseti (L, -2, i); // set table item as number of style
}
lua_setglobal (L, "TriggerStyleRuns");
}
SendTo (eSendToScriptAfterOmit,
deferred_it->sScriptText.c_str (), // text to execute
false, // omit from output flag
false, // omit from log flag
deferred_it->sScriptSource.c_str (), // eg. 'Trigger xyz'
"", // variable to set
strExtraOutput // won't use this anyway
);
m_iCurrentActionSource = eUnknownActionSource;
m_iExecutionDepth = iSavedDepth;
} // end of doing each deferred script
// now do scripts in the script file (ie. script name in the "script" box)
m_CurrentPlugin = NULL;
bool bFoundIt;
int iItem;
for (pos = triggerList.GetHeadPosition (); pos; )
{
trigger_item = triggerList.GetNext (pos);
bFoundIt = false;
// check that trigger still exists, in case a script deleted it - and also
// to work out which plugin it is in
m_CurrentPlugin = NULL;
// main triggers
for (iItem = 0; !bFoundIt && iItem < GetTriggerArray ().GetSize (); iItem++)
if (GetTriggerArray () [iItem] == trigger_item)
{
bFoundIt = true;
// execute trigger script
ExecuteTriggerScript (trigger_item, strCurrentLine, StyledLine);
}
// do plugins
for (PluginListIterator pit = m_PluginList.begin ();
!bFoundIt && pit != m_PluginList.end ();
++pit)
{
m_CurrentPlugin = *pit;
if (m_CurrentPlugin->m_bEnabled)
for (iItem = 0; !bFoundIt && iItem < GetTriggerArray ().GetSize (); iItem++)
if (GetTriggerArray () [iItem] == trigger_item)
{
bFoundIt = true;
// execute trigger script
ExecuteTriggerScript (trigger_item, strCurrentLine, StyledLine);
}
} // end of doing each plugin
} // end of doing each trigger that had a script
m_bInSendToScript = true;
// now that we have run all scripts etc., delete one-shot triggers
int iDeletedCount = 0;
int iDeletedNonTemporaryCount = 0;
set<CPlugin *> pluginsWithDeletions;
for (OneShotItemMap::const_iterator one_shot_it = mapOneShotItems.begin ();
one_shot_it != mapOneShotItems.end ();
one_shot_it++)
{
CTrigger * trigger_item;
CString strTriggerName = one_shot_it->sItemKey.c_str ();
m_CurrentPlugin = one_shot_it->pWhichPlugin; // set back to correct plugin
if (!GetTriggerMap ().Lookup (strTriggerName, trigger_item))
continue;
// can't if executing a script
if (trigger_item->bExecutingScript)
continue;
if (!m_CurrentPlugin && !trigger_item->bTemporary)
iDeletedNonTemporaryCount++;
iDeletedCount++;
// the trigger seems to exist - delete its pointer
delete trigger_item;
// now delete its entry
GetTriggerMap ().RemoveKey (strTriggerName);
pluginsWithDeletions.insert (m_CurrentPlugin);
} // end of deleting one-shot items
if (iDeletedCount > 0)
{
// make sure we sort the correct plugin(s)
for ( set<CPlugin *>::iterator i = pluginsWithDeletions.begin (); i != pluginsWithDeletions.end (); i++)
{
m_CurrentPlugin = *i;
SortTriggers ();
}
if (iDeletedNonTemporaryCount > 0) // plugin mods don't really count
SetModifiedFlag (TRUE); // document has changed
}
// go back to current plugin
m_CurrentPlugin = pSavedPlugin;
// check memory still OK
// _ASSERTE( _CrtCheckMemory( ) );
return m_bLineOmittedFromOutput;
} // end of CMUSHclientDoc::ProcessPreviousLine