/
xml_load_world.cpp
2522 lines (1936 loc) · 80 KB
/
xml_load_world.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
// xml_load_world.cpp : XML world serialization (loading)
//
#include "stdafx.h"
#include "..\MUSHclient.h"
#include "..\doc.h"
#include "..\MUSHview.h"
#include "..\genprint.h"
#include "..\mainfrm.h"
/*
Basic expected document structure ...
<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE muclient>
<muclient>
<world
... world single-line attributes (eg. ip address) ...
>
... world multi-line tags (eg. <connect_text> ... </connect_text> ...
</world>
<triggers>
... individual triggers here ... (eg. <trigger> ... </trigger> )
</triggers>
<aliases>
... individual aliases here ... (eg. <alias> ... </alias> )
</aliases>
<timers>
... individual timers here ... (eg. <timer> ... </timer> )
</timers>
<macros>
... individual macros here ... (eg. <macro> ... </macro> )
</macros>
<variables>
... individual variables here ... (eg. <variable name="blah">contents</variable> )
</variables>
<colours>
<ansi>
<normal>
... individual colours here ... (eg. <colour ... /> )
</normal
<bold>
... individual colours here ... (eg. <colour ... /> )
</bold
</ansi>
<custom>
... individual colours here ... (eg. <colour ... /> )
</custom>
</colours>
<keypad>
... individual keys here ... (eg. <keys> ... </keys> )
</keypad>
<printing>
<ansi>
<normal>
... individual styles here ... (eg. <style ... /> )
</normal
<bold>
... individual styles here ... (eg. <style ... /> )
</bold
</ansi>
</printing>
</muclient>
The order isn't important, as long as everything stays well-formed (XML-wise).
Sections can be omitted, and if no <muclient> tag is found we start looking at
the root level. ie.
You can start like this: <triggers> blah blah </triggers>
*/
extern tConfigurationNumericOption OptionsTable [];
extern tConfigurationAlphaOption AlphaOptionsTable [];
extern UINT iLineLastItemFound;
UINT iErrorCount;
#define DEFAULTS_LIT "defaults"
#define CLIPBOARD_NAME "Clipboard"
// helper macros for getting values and passing down whether we want defaults or not
#define GET_BOOL_USHORT(name, var) \
Get_XML_boolean_ushort (node, name, var, bUseDefault)
#define GET_BOOL(name, var) \
Get_XML_boolean (node, name, var, bUseDefault)
#define GET_BOOL_BOOL(name, var) \
Get_XML_boolean_BOOL (node, name, var, bUseDefault)
#define GET_BOOL_USHORT_MASK(name, var, mask) \
Get_XML_boolean_ushort_mask (node, name, var, mask, bUseDefault)
#define GET_BOOL_INT_MASK(name, var, mask) \
Get_XML_boolean_int_mask (node, name, var, mask, bUseDefault)
#define GET_STRING(name, var) \
Get_XML_string (node, name, var, bUseDefault)
#define GET_STRING_TRIM(name, var) \
Get_XML_string (node, name, var, bUseDefault, true)
#define GET_USHORT(name, var, lo, hi) \
Get_XML_ushort (node, name, var, bUseDefault, lo, hi)
#define GET_INT(name, var, lo, hi) \
Get_XML_int (node, name, var, bUseDefault, lo, hi)
#define GET_LONG(name, var, lo, hi) \
Get_XML_long (node, name, var, bUseDefault, lo, hi)
#define GET_DOUBLE(name, var, lo, hi) \
Get_XML_double (node, name, var, bUseDefault, lo, hi)
#define GET_COLOUR(name, var) \
Get_XML_colour (node, name, var, bUseDefault)
// these load loops are to reduce tedium in doing loops within loops
// eg. for triggers we might have multiple <triggers> tags, and inside
// each one, multiple <trigger> tags.
#define LOAD_LOOP(parent, type, node) \
for (POSITION pos = (parent).ChildrenList.GetHeadPosition (); pos; ) \
{ \
CXMLelement * node = (parent).ChildrenList.GetNext (pos); \
if (node->strName == type && !node->bUsed) \
{ \
node->bUsed = true; \
iLineLastItemFound = node->iLine;
#define END_LOAD_LOOP } }
#define GET_VERSION_AND_DEFAULTS(node) \
long iVersion = GetDateAndVersion (*node); \
bool bUseDefault; \
Get_XML_boolean (*node, DEFAULTS_LIT, bUseDefault, false); \
if (iFlags & LOAD_INCLUDE) \
bUseDefault = true;
#ifdef _DEBUG
//#define new DEBUG_NEW
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
static CString strFileName;
// get date and version to avoid "not used" warnings
long GetDateAndVersion (CXMLelement & node)
{
CString strVersion,
strDate;
long iVersion = VERSION; // default version is current one
Get_XML_number (node, "world_file_version", iVersion, true, 0); // lower limit zero
Get_XML_string (node, "muclient_version", strVersion, true);
Get_XML_string (node, "date_saved", strDate, true);
return iVersion;
} // end of GetDateAndVersion
void CMUSHclientDoc::HandleLoadException (const char * sComment, CException* e)
{
char sMessage [1000];
e->GetErrorMessage (sMessage, sizeof sMessage);
e->Delete ();
LoadError (sComment, sMessage);
}
#define TIMER_TEST 0
#if TIMER_TEST
#define START_TIMING QueryPerformanceCounter (&start)
#define STOP_TIMING(what) \
do { \
LONGLONG iTimeTaken; \
QueryPerformanceCounter (&finish); \
iTimeTaken = finish.QuadPart - start.QuadPart; \
double fTime = ((double) iTimeTaken) / \
((double) iCounterFrequency); \
::UMessageBox (TFormat ("Time taken to %s = %15.8f seconds\n", what, fTime)); \
} while (false)
#endif
UINT CMUSHclientDoc::Load_World_XML (CArchive& ar,
const unsigned long iMask,
const unsigned long iFlags,
UINT * piTriggers,
UINT * piAliases,
UINT * piTimers,
UINT * piMacros,
UINT * piVariables,
UINT * piColours,
UINT * piKeypad,
UINT * piPrinting)
{
CXMLparser parser;
CXMLelement * pMuClientElement = NULL;
UINT count = 0;
UINT iTriggers = 0;
UINT iAliases = 0;
UINT iTimers = 0;
UINT iMacros = 0;
UINT iVariables = 0;
UINT iColours = 0;
UINT iKeypad = 0;
UINT iPrinting = 0;
CPlugin * pCurrentPlugin = m_CurrentPlugin;
iErrorCount = 0;
#if TIMER_TEST
LARGE_INTEGER start,
finish;
LARGE_INTEGER large_int_frequency;
QueryPerformanceFrequency (&large_int_frequency);
LONGLONG iCounterFrequency = large_int_frequency.QuadPart;
#endif
try
{
strFileName = ar.GetFile ()->GetFilePath ();
if (strFileName.IsEmpty ())
strFileName = CLIPBOARD_NAME;
iLineLastItemFound = 0;
#if TIMER_TEST
START_TIMING;
#endif
parser.BuildStructure (ar.GetFile ());
#if TIMER_TEST
STOP_TIMING (CFormat ("parse XML for %s", (LPCTSTR) strFileName));
#endif
// find <?xml> tag so we don't get a warning
FindNode (parser.m_xmlRoot, "?xml");
// if we have a <muclient> tag, use contents of that
pMuClientElement = FindNode (parser.m_xmlRoot, "muclient");
if (pMuClientElement)
CheckUsed (parser.m_xmlRoot); // check no tags outside <muclient>
else
pMuClientElement = &parser.m_xmlRoot;
if ((iFlags & LOAD_INCLUDE) == 0)
{ // not include file
// if not doing an include, we don't have a tree of include files yet
m_strCurrentIncludeFileList.RemoveAll ();
// root document is at head of tree
m_strCurrentIncludeFileList.AddTail (strFileName);
}
if (iMask & XML_NO_PLUGINS)
{
if (FindNode (*pMuClientElement, "plugin"))
ThrowErrorException ("Plugin not expected here. Use File -> Plugins to load plugins");
}
if (iMask & XML_PLUGINS)
if (!(iMask & XML_NO_PLUGINS))
{ // plugin expected now
Load_Plugin_XML (*pMuClientElement); // get <plugin> details
}
// if they really wanted a plugin, warn them if none found
if ((iMask & XML_PLUGINS) && !m_CurrentPlugin)
ThrowErrorException ("No plugin found");
// load include files first (however not from clipboard)
if (!ar.GetFile ()->GetFilePath ().IsEmpty ())
Load_Includes_XML (*pMuClientElement,
iMask,
iFlags,
false, // except plugins
piTriggers,
piAliases,
piTimers,
piMacros,
piVariables,
piColours,
piKeypad,
piPrinting);
if (iMask & XML_GENERAL)
Load_General_XML (*pMuClientElement, iFlags);
if (iMask & XML_TRIGGERS)
count += iTriggers = Load_Triggers_XML (*pMuClientElement, iMask, iFlags);
if (iMask & XML_ALIASES)
count += iAliases = Load_Aliases_XML (*pMuClientElement, iMask, iFlags);
if (iMask & XML_TIMERS)
count += iTimers = Load_Timers_XML (*pMuClientElement, iMask, iFlags);
if (iMask & XML_MACROS)
count += iMacros = Load_Macros_XML (*pMuClientElement, iFlags);
if (iMask & XML_VARIABLES)
count += iVariables = Load_Variables_XML (*pMuClientElement, iMask, iFlags);
if (iMask & XML_COLOURS)
count += iColours = Load_Colours_XML (*pMuClientElement, iFlags);
if (iMask & XML_KEYPAD)
count += iKeypad = Load_Keypad_XML (*pMuClientElement, iFlags);
if (iMask & XML_PRINTING)
count += iPrinting = Load_Printing_XML (*pMuClientElement, iFlags);
// get scripts belonging to this plugin
if (m_CurrentPlugin)
{
ResetAllTimers (GetTimerMap ()); // and reset plugin timers
Load_Scripts_XML (*pMuClientElement);
}
else // can't have plugins inside a plugin
{
// we have to do plugins later, so that we know the world ID, amongst other things
// now load include files that include plugins
if (!ar.GetFile ()->GetFilePath ().IsEmpty ())
Load_Includes_XML (*pMuClientElement,
iMask,
iFlags,
true, // only plugins
piTriggers,
piAliases,
piTimers,
piMacros,
piVariables,
piColours,
piKeypad,
piPrinting);
// tell all plugins the world has now loaded all plugins
PluginListChanged ();
} // not inside a plugin
CheckUsed (*pMuClientElement); // check we used all attributes
// return totals to caller
if (piTriggers)
*piTriggers += iTriggers;
if (piAliases)
*piAliases += iAliases;
if (piTimers)
*piTimers += iTimers;
if (piMacros)
*piMacros += iMacros;
if (piVariables)
*piVariables += iVariables;
if (piColours)
*piColours += iColours;
if (piKeypad)
*piKeypad += iKeypad;
if (piPrinting)
*piPrinting += iPrinting;
// now that triggers, etc. are loaded, try to find entry points for plugins
if (m_CurrentPlugin && !pCurrentPlugin) // *this* file had a plugin
{
m_CurrentPlugin->m_strScript.TrimLeft ();
m_CurrentPlugin->m_strScript.TrimRight ();
if (!m_CurrentPlugin->m_strScript.IsEmpty () || m_CurrentPlugin->m_bSendToScriptUsed)
{
m_CurrentPlugin->m_ScriptEngine = new CScriptEngine (this, m_CurrentPlugin->m_strLanguage);
if (m_CurrentPlugin->m_ScriptEngine->CreateScriptEngine ())
ThrowErrorException ("Could not initialise script engine");
if (m_CurrentPlugin->m_ScriptEngine->Parse (m_CurrentPlugin->m_strScript, "Plugin"))
ThrowErrorException ("Error parsing script");
if (FindAllEntryPoints ())
ThrowErrorException ("Could not find all required script routines");
m_CurrentPlugin->m_dispid_plugin_install
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_INSTALL );
m_CurrentPlugin->m_dispid_plugin_connect
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_CONNECT );
m_CurrentPlugin->m_dispid_plugin_disconnect
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_DISCONNECT);
m_CurrentPlugin->m_dispid_plugin_close
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_CLOSE );
m_CurrentPlugin->m_dispid_plugin_save_state
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_SAVE_STATE);
m_CurrentPlugin->m_dispid_plugin_enable
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_ENABLE );
m_CurrentPlugin->m_dispid_plugin_disable
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_DISABLE );
m_CurrentPlugin->m_dispid_plugin_command
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_COMMAND );
m_CurrentPlugin->m_dispid_plugin_command_entered
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_COMMAND_ENTERED );
m_CurrentPlugin->m_dispid_plugin_get_focus
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_GETFOCUS );
m_CurrentPlugin->m_dispid_plugin_lose_focus
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_LOSEFOCUS );
m_CurrentPlugin->m_dispid_plugin_trace
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_TRACE );
m_CurrentPlugin->m_dispid_plugin_broadcast
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_BROADCAST );
m_CurrentPlugin->m_dispid_plugin_screendraw
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_SCREENDRAW );
m_CurrentPlugin->m_dispid_plugin_playsound
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_PLAYSOUND );
m_CurrentPlugin->m_dispid_plugin_tabcomplete
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_TABCOMPLETE );
// m_CurrentPlugin->m_dispid_plugin_tooltip
// = m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_TOOLTIP );
m_CurrentPlugin->m_dispid_plugin_list_changed
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_LIST_CHANGED );
m_CurrentPlugin->m_dispid_plugin_tick
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_TICK );
m_CurrentPlugin->m_dispid_plugin_mouse_moved
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_MOUSE_MOVED );
m_CurrentPlugin->m_dispid_plugin_send
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_SEND );
m_CurrentPlugin->m_dispid_plugin_sent
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_SENT );
m_CurrentPlugin->m_dispid_plugin_line_received
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_LINE_RECEIVED);
m_CurrentPlugin->m_dispid_plugin_packet_received
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_PACKET_RECEIVED);
m_CurrentPlugin->m_dispid_plugin_partial_line
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_PARTIAL_LINE);
m_CurrentPlugin->m_dispid_plugin_telnet_option
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_TELNET_OPTION);
m_CurrentPlugin->m_dispid_plugin_telnet_request
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_TELNET_REQUEST);
m_CurrentPlugin->m_dispid_plugin_telnet_subnegotiation
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_TELNET_SUBNEGOTIATION);
m_CurrentPlugin->m_dispid_plugin_IAC_GA
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_IAC_GA);
m_CurrentPlugin->m_dispid_plugin_on_world_output_resized
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_WORLD_OUTPUT_RESIZED);
m_CurrentPlugin->m_dispid_plugin_on_command_changed
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_COMMAND_CHANGED);
m_CurrentPlugin->m_dispid_plugin_OnMXP_Start
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_MXP_START );
m_CurrentPlugin->m_dispid_plugin_OnMXP_Stop
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_MXP_STOP );
m_CurrentPlugin->m_dispid_plugin_OnMXP_OpenTag
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_MXP_OPENTAG );
m_CurrentPlugin->m_dispid_plugin_OnMXP_CloseTag
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_MXP_CLOSETAG );
m_CurrentPlugin->m_dispid_plugin_OnMXP_SetVariable
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_MXP_SETVARIABLE);
m_CurrentPlugin->m_dispid_plugin_OnMXP_SetEntity
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_MXP_SETENTITY);
m_CurrentPlugin->m_dispid_plugin_OnMXP_Error
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_MXP_ERROR);
m_CurrentPlugin->m_dispid_plugin_On_Chat_Accept
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_CHAT_ACCEPT );
m_CurrentPlugin->m_dispid_plugin_On_Chat_Message
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_CHAT_MESSAGE);
m_CurrentPlugin->m_dispid_plugin_On_Chat_MessageOut
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_CHAT_MESSAGE_OUT);
m_CurrentPlugin->m_dispid_plugin_On_Chat_Display
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_CHAT_DISPLAY);
m_CurrentPlugin->m_dispid_plugin_On_Chat_NewUser
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_CHAT_NEWUSER);
m_CurrentPlugin->m_dispid_plugin_On_Chat_UserDisconnect
= m_CurrentPlugin->GetPluginDispid (ON_PLUGIN_CHAT_USERDISCONNECT);
// note if we need to call these routines
if (m_CurrentPlugin->m_dispid_plugin_OnMXP_OpenTag != DISPID_UNKNOWN)
m_bPluginProcessesOpenTag = true;
if (m_CurrentPlugin->m_dispid_plugin_OnMXP_CloseTag != DISPID_UNKNOWN)
m_bPluginProcessesCloseTag = true;
if (m_CurrentPlugin->m_dispid_plugin_OnMXP_SetVariable != DISPID_UNKNOWN)
m_bPluginProcessesSetVariable = true;
if (m_CurrentPlugin->m_dispid_plugin_OnMXP_SetEntity != DISPID_UNKNOWN)
m_bPluginProcessesSetEntity = true;
if (m_CurrentPlugin->m_dispid_plugin_OnMXP_Error != DISPID_UNKNOWN)
m_bPluginProcessesError = true;
} // end of having a script
// add to world plugins
m_PluginList.AddTail (m_CurrentPlugin);
// now call the OnInstall routine (once it is in the list)
// ::TMessageBox ("Plugin OnInstall");
m_CurrentPlugin->ExecutePluginScript (ON_PLUGIN_INSTALL, m_CurrentPlugin->m_dispid_plugin_install);
} // end of having a plugin
m_CurrentPlugin = pCurrentPlugin; // finished processing this plugin, if it was one
/*
if (iErrorCount)
{
CString strWarning = TFormat ("%lu warning%s %s generated. See warning window for details.",
PLURAL (iErrorCount),
iErrorCount == 1 ? "was" : "were");
::UMessageBox (strWarning, MB_ICONEXCLAMATION);
}
*/
}
catch(CException* e)
{
if (m_CurrentPlugin && !pCurrentPlugin) // *this* file had a plugin
delete m_CurrentPlugin; // throw away plugin, if parsing problem in it
m_CurrentPlugin = pCurrentPlugin;
if (iLineLastItemFound == 0)
iLineLastItemFound = parser.m_xmlLine;
HandleLoadException ("problem in this file", e);
AfxThrowArchiveException (CArchiveException::badSchema);
}
return count;
} // end of CMUSHclientDoc::Load_World_XML
void CMUSHclientDoc::LoadError (const char * sType, const char * sMessage, UINT iLine)
{
CString strTitle = "XML import warnings - ";
strTitle += strFileName;
ColourNote (SCRIPTERRORFORECOLOUR, SCRIPTERRORBACKCOLOUR, strTitle);
// line defaults to last attribute line
if (iLine == 0)
iLine = iLineLastItemFound;
CString str = TFormat ("Line %4i: %s (%s)%s",
iLine, // which line
sMessage, // what message
sType, // type of thing (eg, trigger)
ENDLINE);
ColourNote (SCRIPTERRORCONTEXTFORECOLOUR, SCRIPTERRORBACKCOLOUR, str);
iErrorCount++;
} // end of CMUSHclientDoc::LoadError
// warns of unused attributes
/*
Checking unused attributes/nodes is partly to help me debug,
and partly to help world-file writers to know if they slipped in
an attribute (eg. misspelt) that wasn't processed.
There are two parts to it ...
1. Checking attributes are used, eg. <node blah="6"> ... </node>
This checks that "blah" was used somewhere.
2. Checking children were used, eg. <node> <child> ... </child> </node>
This checks that "<child>" was used somewhere.
*/
void CMUSHclientDoc::CheckUsed (CXMLelement & node)
{
POSITION pos;
CString strName;
CAttribute * attribute;
/*
Each tag can have comments as a child
*/
Load_Comments_XML (node);
// check attributes of this tag
for (pos = node.AttributeMap.GetStartPosition(); pos; )
{
node.AttributeMap.GetNextAssoc (pos, strName, attribute);
if (attribute->bUsed)
continue;
LoadError (node.strName,
TFormat ("Attribute not used: %s=\"%s\"",
(LPCTSTR) strName,
(LPCTSTR) attribute->strValue),
attribute->iLine);
} // end of checking each attribute
// look for unused children
for (pos = node.ChildrenList.GetHeadPosition (); pos; )
{
CXMLelement * pElement = node.ChildrenList.GetNext (pos);
if (pElement->bUsed)
continue;
LoadError (node.strName,
TFormat ("Tag not used: <%s>",
(LPCTSTR) pElement->strName),
pElement->iLine);
} // end of checking each tag
} // end of CMUSHclientDoc::CheckUsed
void CMUSHclientDoc::Load_Includes_XML (CXMLelement & parent,
const unsigned long iMask,
const unsigned long iFlags,
const bool bPlugins, // only if plugin="y"
UINT * piTriggers,
UINT * piAliases,
UINT * piTimers,
UINT * piMacros,
UINT * piVariables,
UINT * piColours,
UINT * piKeypad,
UINT * piPrinting)
{
CStringList strIncludeList;
POSITION lpos;
// save current hierarchy
for (lpos = m_strCurrentIncludeFileList.GetHeadPosition (); lpos; )
strIncludeList.AddTail (m_strCurrentIncludeFileList.GetNext (lpos));
// see if we have "include" tag(s)
LOAD_LOOP (parent, "include", pIncludeElement);
try
{
Load_One_Include_XML (*pIncludeElement,
iMask,
iFlags,
bPlugins,
piTriggers,
piAliases,
piTimers,
piMacros,
piVariables,
piColours,
piKeypad,
piPrinting);
}
catch (CException* e)
{
HandleLoadException ("include file not loaded", e);
} // end of catch
CheckUsed (*pIncludeElement);
END_LOAD_LOOP;
// restore current include list tree
m_strCurrentIncludeFileList.RemoveAll ();
for (lpos = strIncludeList.GetHeadPosition (); lpos; )
m_strCurrentIncludeFileList.AddTail (strIncludeList.GetNext (lpos));
} // end of CMUSHclientDoc::Load_Includes_XML
void CMUSHclientDoc::Load_One_Include_XML (CXMLelement & node,
const unsigned long iMask,
const unsigned long iFlags,
const bool bPlugins, // only if plugin="y"
UINT * piTriggers,
UINT * piAliases,
UINT * piTimers,
UINT * piMacros,
UINT * piVariables,
UINT * piColours,
UINT * piKeypad,
UINT * piPrinting)
{
CString strSavedFileName = strFileName;
int iSavedLineLastItemFound = iLineLastItemFound;
int iSavedErrorCount = iErrorCount;
CString strOriginalName;
bool bUseDefault = false;
CFile * f = NULL;
CArchive * ar = NULL;
CXMLparser parser;
bool bPlugin;
try
{
GET_STRING_TRIM ("name", strFileName);
GET_BOOL ("plugin", bPlugin);
// make sure they specified something
if (strFileName.IsEmpty ())
ThrowErrorException ("Name of include file not specified");
// don't want the name "clipboard"
if (strFileName.CompareNoCase (CLIPBOARD_NAME) == 0)
ThrowErrorException ("Name of include file cannot be \"%s\"",
(LPCTSTR) CLIPBOARD_NAME);
strOriginalName = strFileName;
strFileName = ::Replace (strFileName, "$PLUGINSDEFAULTDIR", RemoveFinalSlash (Make_Absolute_Path (App.m_strPluginsDirectory)));
strFileName = ::Replace (strFileName, "$PROGRAMDIR",
RemoveFinalSlash (ExtractDirectory (App.m_strMUSHclientFileName)));
strFileName = ::Replace (strFileName, "$WORLDDIR",
RemoveFinalSlash (ExtractDirectory (GetPathName ())));
if (m_CurrentPlugin)
strFileName = ::Replace (strFileName, "$PLUGINDIR",
RemoveFinalSlash (ExtractDirectory (m_CurrentPlugin->m_strSource)));
// use relative path if required ...
if (!(
isalpha ((unsigned char) strFileName [0]) &&
strFileName [1] == ':' // eg. c: blah
) &&
strFileName [0] != '\\' && // eg. \mydir\blah or \\server\blah
strFileName [0] != '/' && // eg. /mydir/blah or //server/blah
strFileName.Left (3) != "..\\" && // eg. ..\blah\blah
strFileName.Left (3) != "../" && // eg. ../blah/blah
strFileName.Left (2) != "./" && // eg. ./blah
strFileName.Left (2) != ".\\") // eg. .\blah
if (m_CurrentPlugin || bPlugins)
strFileName = CString (Make_Absolute_Path (App.m_strPluginsDirectory)) + strFileName;
else
strFileName = CString (Make_Absolute_Path (App.m_strDefaultWorldFileDirectory)) + strFileName;
// do plugins and non-plugins at different times
if (bPlugin == bPlugins)
{
if (!bPlugin && !m_CurrentPlugin)
{
// don't include it twice
if (m_strCurrentIncludeFileList.Find (strFileName))
ThrowErrorException ("Include file \"%s\" has already been included.",
(LPCTSTR) strFileName);
m_strCurrentIncludeFileList.AddTail (strFileName);
// if root level include, remember in world document
if (!(iFlags & LOAD_INCLUDE))
m_strIncludeFileList.AddTail (strOriginalName);
} // plugins are in a different list
f = new CFile (strFileName, CFile::modeRead | CFile::shareDenyWrite);
ar = new CArchive(f, CArchive::load);
if (IsArchiveXML (*ar))
{
try
{
Load_World_XML (*ar,
iMask | (bPlugin ? XML_PLUGINS : XML_INCLUDES),
iFlags | (bPlugin ? 0 : LOAD_INCLUDE),
piTriggers,
piAliases,
piTimers,
piMacros,
piVariables,
piColours,
piKeypad,
piPrinting);
}
catch (CArchiveException* e)
{
e->Delete ();
ThrowErrorException ("Error processing include file \"%s\"",
(LPCTSTR) strFileName);
} // end of catch
}
else
ThrowErrorException ("File \"%s\" is not an XML file",
(LPCTSTR) strFileName);
} // end of plugin flag being what we want
else
if (!bPlugins)
node.bUsed = false; // so we get it next time
} // end of try
catch(CException*)
{
strFileName = strSavedFileName;
iLineLastItemFound = iSavedLineLastItemFound;
iErrorCount = iSavedErrorCount;
delete ar;
delete f;
throw;
}
strFileName = strSavedFileName;
iLineLastItemFound = iSavedLineLastItemFound;
iErrorCount = iSavedErrorCount;
delete ar;
delete f;
} // end of CMUSHclientDoc::Load_One_Include_XML
void CMUSHclientDoc::Load_General_XML (CXMLelement & parent,
const unsigned long iFlags)
{
// see if we have "world" tag(s)
LOAD_LOOP (parent, "world", pWorldElement);
GET_VERSION_AND_DEFAULTS (pWorldElement);
// worlds consist of:
// 1. single-line alpha attributes, eg. script_language="VBscript"
// 2. numeric attributes, eg. wrap_column="80"
// 3. multi-line alpha children, eg. <notes>blah</notes>
if (m_CurrentPlugin)
ThrowErrorException ("<world> tag cannot be used inside a plugin");
// get numeric ones first, so we know if various options are enabled
Load_World_Numeric_Options_XML (*pWorldElement, bUseDefault, iFlags);
Load_World_Single_Line_Alpha_Options_XML (*pWorldElement, bUseDefault, iFlags);
Load_World_Multi_Line_Alpha_Options_XML (*pWorldElement, bUseDefault, iFlags);
CheckUsed (*pWorldElement);
// check world ID is unique (maybe they duplicated a disk file)
for (POSITION pos = App.m_pWorldDocTemplate->GetFirstDocPosition(); pos != NULL; )
{
CMUSHclientDoc * pDoc = (CMUSHclientDoc *) App.m_pWorldDocTemplate->GetNextDoc(pos);
if (pDoc == this)
continue; // don't compare to ourselves
if (pDoc->m_strWorldID == m_strWorldID)
{
m_strWorldID = GetUniqueID (); // so change it ;)
SetModifiedFlag ();
}
} // end of looping through each world
END_LOAD_LOOP;
} // end of CMUSHclientDoc::Load_General_XML
void CMUSHclientDoc::Load_World_Numeric_Options_XML (CXMLelement & parent,
bool bUseDefault,
const unsigned long iFlags)
{
for (int i = 0; OptionsTable [i].pName; i++)
{
try
{
COLORREF cValue;
if (OptionsTable [i].iFlags & OPT_RGB_COLOUR)
{
if (Get_XML_colour (parent,
OptionsTable [i].pName,
cValue,
// version 3.83 bUseDefault || m_NumericConfiguration [i]->bInclude,
TRUE // version 3.83
))
SetOptionItem (i, cValue, true, (iFlags & LOAD_INCLUDE) != 0);
/* version 3.83
else // not found, use default?
if (!(bUseDefault || m_NumericConfiguration [i]->bInclude))
SetOptionItem (i, 0, true, false); // then take zero
*/
} // end of RGB colour
else
if (OptionsTable [i].iMinimum == 0 &&
OptionsTable [i].iMaximum == 0)
{
bool bValue;
if (Get_XML_boolean (parent,
OptionsTable [i].pName,
bValue,
bUseDefault || m_NumericConfiguration [i]->bInclude
))
SetOptionItem (i, bValue, true, (iFlags & LOAD_INCLUDE) != 0);
else // not found, use default?
if (!(bUseDefault || m_NumericConfiguration [i]->bInclude))
SetOptionItem (i, 0, true, false); // then take zero
} // end of boolean
else
{ // not RGB colour or boolean
long iValue;
if (Get_XML_number (parent,
OptionsTable [i].pName,
iValue,
// version 4.30 bUseDefault || m_NumericConfiguration [i]->bInclude,
TRUE, // version 4.30
OptionsTable [i].iMinimum,
OptionsTable [i].iMaximum))
SetOptionItem (i, iValue, true, (iFlags & LOAD_INCLUDE) != 0);
/* version 4.30
else // not found, use default?
if (!(bUseDefault || m_NumericConfiguration [i]->bInclude))
{ // then take zero, if we can
if (0 < OptionsTable [i].iMinimum ||
0 > OptionsTable [i].iMaximum)
ThrowErrorException ("Value of zero not acceptable here");
SetOptionItem (i, 0, true, false);
} // end of taking zero for unspecified variables
*/
} // end of not RGB colour or boolean
}
catch (CException* e)
{
HandleLoadException (TFormat ("option '%s' not set", (LPCTSTR) OptionsTable [i].pName), e);
} // end of catch
}
} // end of CMUSHclientDoc::Load_World_Numeric_Options_XML
void CMUSHclientDoc::Load_World_Single_Line_Alpha_Options_XML (CXMLelement & parent,
bool bUseDefault,
const unsigned long iFlags)
{
CString strValue;
for (int i = 0; AlphaOptionsTable [i].pName; i++)
if (!(AlphaOptionsTable [i].iFlags & OPT_MULTLINE))
{
try
{
if (Get_XML_string (parent,
AlphaOptionsTable [i].pName,
strValue,
bUseDefault || m_AlphaConfiguration [i]->bInclude,
!(AlphaOptionsTable [i].iFlags & OPT_KEEP_SPACES)))
{
if (AlphaOptionsTable [i].iFlags & OPT_PASSWORD)
{
bool bEncoded;
Get_XML_boolean (parent,
CFormat ("%s_base64", (LPCTSTR) AlphaOptionsTable [i].pName),
bEncoded, false);
if (bEncoded)
{
strValue.TrimLeft ();
strValue.TrimRight ();
strValue = decodeBase64 (strValue); // base 64 decoding
} // end of being base 64 encoded