/
methods.cpp
14707 lines (11176 loc) · 403 KB
/
methods.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
#include "stdafx.h"
#include "..\MUSHclient.h"
//=============================================================
// IMPORTANT - when adding methods here remember to add the 'glue'
// routine in lua_methods.cpp and add it to the library table
//=============================================================
#include "..\doc.h"
#include "..\MUSHview.h"
#include "..\mainfrm.h"
#include "..\childfrm.h"
#include "..\sendvw.h"
#include "..\TextView.h"
#include "..\TextDocument.h"
#include "..\dialogs\ChooseNotepadDlg.h"
#include "..\dialogs\ColourPickerDlg.h"
#include "..\MakeWindowTransparent.h"
#include "errors.h"
#include "..\flags.h"
#include "..\mxp\mxp.h"
#include "..\color.h"
#include "..\winplace.h"
#include "..\UDPsocket.h"
#include <direct.h>
#include "..\dmetaph.h"
#include "..\png\png.h"
#ifdef _DEBUG
//#define new DEBUG_NEW
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
extern bool bNamesRead;
extern tConfigurationNumericOption OptionsTable [];
extern tConfigurationAlphaOption AlphaOptionsTable [];
extern tCommandIDMapping CommandIDs [];
extern CString strMacroDescriptions [MACRO_COUNT];
extern CString strKeypadNames [eKeypad_Max_Items];
extern char working_dir [_MAX_PATH];
extern char file_browsing_dir [_MAX_PATH];
extern set<string> LuaFunctionsSet;
// ==============================================================================
// These are the methods exposed to external programs
// ******************************************************************************
// **************************** WORLDS ******************************************
// ******************************************************************************
// world.Send - sends the text to the world
long CMUSHclientDoc::Send(LPCTSTR Message)
{
if (m_iConnectPhase != eConnectConnectedToMud)
return eWorldClosed;
// cannot change what we are sending in OnPluginSent
if (m_bPluginProcessingSent)
return eItemInUse;
SendMsg (Message, m_display_my_input, false, false); // don't queue it
return eOK;
}
// send disregarding the queue (ie. queue jump)
long CMUSHclientDoc::SendImmediate(LPCTSTR Message)
{
if (m_iConnectPhase != eConnectConnectedToMud)
return eWorldClosed;
// cannot change what we are sending in OnPluginSent
if (m_bPluginProcessingSent)
return eItemInUse;
DoSendMsg (Message, m_display_my_input, m_log_input);
return eOK;
}
long CMUSHclientDoc::SendNoEcho(LPCTSTR Message)
{
if (m_iConnectPhase != eConnectConnectedToMud)
return eWorldClosed;
// cannot change what we are sending in OnPluginSent
if (m_bPluginProcessingSent)
return eItemInUse;
SendMsg (Message, false, false, false); // don't queue it, don't echo it
return eOK;
}
void CMUSHclientDoc::AddToCommandHistory (LPCTSTR Message)
{
for(POSITION pos = GetFirstViewPosition(); pos != NULL; )
{
CView* pView = GetNextView(pos);
if (pView->IsKindOf(RUNTIME_CLASS(CSendView)))
{
CSendView* pmyView = (CSendView*)pView;
if (strlen (Message) > 0 && strcmp (Message, pmyView->m_last_command) != 0)
{
if (pmyView->m_inputcount >= m_nHistoryLines)
{
pmyView->m_msgList.RemoveHead (); // keep max of "m_nHistoryLines" previous commands
pmyView->m_HistoryFindInfo.m_nCurrentLine--; // adjust for a "find again"
if (pmyView->m_HistoryFindInfo.m_nCurrentLine < 0)
pmyView->m_HistoryFindInfo.m_nCurrentLine = 0;
} // end of buffer full
else
pmyView->m_inputcount++;
pmyView->m_msgList.AddTail (Message);
pmyView->m_last_command = Message;
} // end of different from last one
break;
} // end of being a CSendView
} // end of loop through views
} // end of CMUSHclientDoc::AddToCommandHistory
long CMUSHclientDoc::SendPush(LPCTSTR Message)
{
if (m_iConnectPhase != eConnectConnectedToMud)
return eWorldClosed;
// cannot change what we are sending in OnPluginSent
if (m_bPluginProcessingSent)
return eItemInUse;
SendMsg (Message, m_display_my_input, false, false); // don't queue it
AddToCommandHistory (Message);
return eOK;
} // end of SendPush
long CMUSHclientDoc::SendSpecial(LPCTSTR Message, BOOL Echo, BOOL Queue, BOOL Log, BOOL History)
{
if (m_iConnectPhase != eConnectConnectedToMud)
return eWorldClosed;
// cannot change what we are sending in OnPluginSent
if (m_bPluginProcessingSent)
return eItemInUse;
// send with appropriate options
SendMsg (Message, Echo, Queue, Log);
if (History)
AddToCommandHistory (Message);
return eOK;
}
long CMUSHclientDoc::LogSend(LPCTSTR Message)
{
long iResult = Send (Message); // send it
if (iResult == eOK)
LogCommand (Message); // and log it
return iResult;
}
// world.GetLineCount - returns the count of lines received by this world
long CMUSHclientDoc::GetLineCount()
{
return m_total_lines;
}
// world.IsConnected - returns true if the world is open
BOOL CMUSHclientDoc::IsConnected()
{
return m_iConnectPhase == eConnectConnectedToMud;
}
// world.worldname - returns the name of the current world
BSTR CMUSHclientDoc::WorldName()
{
CString strResult;
strResult = m_mush_name;
return strResult.AllocSysString();
}
// world.version - returns MUSHclient version
BSTR CMUSHclientDoc::Version()
{
CString strResult = MUSHCLIENT_VERSION;
return strResult.AllocSysString();
}
// world.note - makes a comment in the output buffer (with newline)
void CMUSHclientDoc::Note(LPCTSTR Message)
{
CString strMsg = Message;
if (strMsg.Right (2) != ENDLINE)
strMsg += ENDLINE; // add a new line if necessary
Tell (strMsg);
}
// world.tell - makes a comment in the output buffer (without newline)
void CMUSHclientDoc::Tell(LPCTSTR Message)
{
// return if attempt to do tell (or note) before output buffer exists
if (m_pCurrentLine == NULL)
return;
// don't muck around if empty message
if (Message [0] == 0)
return;
// If current line is not a note line, force a line change (by displaying
// an empty string), so that the style change is on the note line and not
// the back of the previous line. This has various implications, including
// the way that "bleed colour to edge" will work. Otherwise it bleeds the
// forthcoming note colour to the edge of the previous (mud) line.
if ((m_pCurrentLine->flags & NOTE_OR_COMMAND) != COMMENT)
DisplayMsg ("", 0, COMMENT);
CStyle * pOldStyle = NULL;
if (!m_pCurrentLine->styleList.IsEmpty ())
pOldStyle = m_pCurrentLine->styleList.GetTail ();
if (m_bNotesInRGB)
{
// change style if we need to
if (!(pOldStyle &&
(pOldStyle->iFlags & COLOURTYPE) == COLOUR_RGB &&
pOldStyle->iForeColour == m_iNoteColourFore &&
pOldStyle->iBackColour == m_iNoteColourBack &&
(pOldStyle->iFlags & TEXT_STYLE) == m_iNoteStyle
))
AddStyle (COLOUR_RGB | m_iNoteStyle,
m_iNoteColourFore, m_iNoteColourBack, 0, NULL);
} // end or RGB notes
else
{
// finally found Poremenos's bug - he was doing a world.colournote
// with the note colour as -1 (65535) which gave an access violation
if (m_iNoteTextColour == SAMECOLOUR)
{
// change style if we need to
if (!(pOldStyle &&
(pOldStyle->iFlags & COLOURTYPE) == COLOUR_ANSI &&
pOldStyle->iForeColour == WHITE &&
pOldStyle->iBackColour == BLACK &&
(pOldStyle->iFlags & TEXT_STYLE) == m_iNoteStyle
))
AddStyle (COLOUR_ANSI | m_iNoteStyle,
WHITE, BLACK, 0, NULL);
}
else
{
// change style if we need to
if (!(pOldStyle &&
(pOldStyle->iFlags & COLOURTYPE) == COLOUR_CUSTOM &&
pOldStyle->iForeColour == m_iNoteTextColour &&
pOldStyle->iBackColour == BLACK &&
(pOldStyle->iFlags & TEXT_STYLE) == m_iNoteStyle
))
AddStyle (COLOUR_CUSTOM | m_iNoteStyle,
m_iNoteTextColour, BLACK, 0, NULL);
} // not samecolour
} // end of palette notes
DisplayMsg (Message, strlen (Message), COMMENT);
}
// world.Sound - plays a sound
long CMUSHclientDoc::Sound(LPCTSTR SoundFileName)
{
if (SoundFileName [0] == 0)
return eNoNameSpecified;
if (!PlaySoundFile (SoundFileName))
return eCannotPlaySound;
return eOK;
}
// world.Connect - connects the current world
long CMUSHclientDoc::Connect()
{
if (m_iConnectPhase == eConnectNotConnected)
{
OnConnectionConnect ();
return eOK;
}
else
return eWorldOpen; // cannot connect, already open
}
// world.Disconnect - disconnects from the current world
long CMUSHclientDoc::Disconnect()
{
if (m_iConnectPhase != eConnectNotConnected &&
m_iConnectPhase != eConnectDisconnecting)
{
OnConnectionDisconnect ();
return eOK;
}
else
return eWorldClosed; // cannot disconnect, already closed
}
// world.Save - saves the current world - under a new name if supplied
// returns zero if no error
BOOL CMUSHclientDoc::Save(LPCTSTR Name)
{
CString strName = Name;
// if empty, take document default path name [#459]
if (strName.IsEmpty ())
strName = m_strPathName;
return !DoSave (strName, TRUE);
}
long CMUSHclientDoc::OpenLog(LPCTSTR LogFileName, BOOL Append)
{
if (m_logfile)
return eLogFileAlreadyOpen;
m_logfile_name = LogFileName;
// if no log file name, use auto-log file name if we can
if (m_logfile_name.IsEmpty ())
{
CTime theTime;
theTime = CTime::GetCurrentTime();
m_logfile_name = FormatTime (theTime, m_strAutoLogFileName, false);
}
// no file name? can't open it then
if (m_logfile_name.IsEmpty ())
return eCouldNotOpenFile;
m_logfile = fopen (m_logfile_name, Append ? "a+" : "w");
// close and re-open to make sure it is in the disk directory
if (m_logfile)
{
fclose (m_logfile);
m_logfile = fopen (m_logfile_name, Append ? "a+" : "w");
}
if (m_logfile)
return eOK;
else
return eCouldNotOpenFile;
}
long CMUSHclientDoc::CloseLog()
{
if (m_logfile)
{
// write log file Postamble if wanted
if (!m_strLogFilePostamble.IsEmpty () && !m_bLogRaw)
{
CTime theTime;
theTime = CTime::GetCurrentTime();
// allow %n for newline
CString strPostamble = ::Replace (m_strLogFilePostamble, "%n", "\n");
// allow for time-substitution strings
strPostamble = FormatTime (theTime, strPostamble, m_bLogHTML);
// this is open in text mode, don't want \r\r\n
strPostamble.Replace (ENDLINE, "\n");
WriteToLog (strPostamble);
WriteToLog ("\n", 1);
}
fclose (m_logfile);
m_logfile = NULL;
return eOK;
}
return eLogFileNotOpen;
}
long CMUSHclientDoc::WriteLog(LPCTSTR Message)
{
if (m_logfile)
{
CString strMessage = Message;
// append newline if there isn't one already
if (strMessage.Right (2) != "\n")
strMessage += "\n";
size_t count;
size_t len = strMessage.GetLength ();
count = fwrite (strMessage, 1, len, m_logfile);
if (count != len)
return eLogFileBadWrite;
return eOK;
}
return eLogFileNotOpen;
}
BOOL CMUSHclientDoc::IsLogOpen()
{
return m_logfile != NULL;
}
// ******************************************************************************
// **************************** TRIGGERS ****************************************
// ******************************************************************************
// world.DeleteTrigger (trigger_name) - deletes the named trigger
long CMUSHclientDoc::DeleteTrigger(LPCTSTR TriggerName)
{
CString strTriggerName = TriggerName;
CTrigger * trigger_item;
long nStatus;
// return if bad name
if (nStatus = CheckObjectName (strTriggerName, false))
return nStatus;
if (!GetTriggerMap ().Lookup (strTriggerName, trigger_item))
return eTriggerNotFound;
// can't if executing a script
if (trigger_item->bExecutingScript)
return eItemInUse;
bool bTemporary = trigger_item->bTemporary;
// the trigger seems to exist - delete its pointer
delete trigger_item;
// now delete its entry
if (!GetTriggerMap ().RemoveKey (strTriggerName))
return eTriggerNotFound;
SortTriggers ();
if (!m_CurrentPlugin && !bTemporary) // plugin mods don't really count
SetModifiedFlag (TRUE); // document has changed
return eOK;
}
// world.AddTriggerEx (trigger_name, ...) - adds the named trigger
long CMUSHclientDoc::AddTriggerEx(LPCTSTR TriggerName,
LPCTSTR MatchText,
LPCTSTR ResponseText,
long Flags,
short Colour,
short Wildcard,
LPCTSTR SoundFileName,
LPCTSTR ScriptName,
short SendTo,
short Sequence)
{
CString strTriggerName = TriggerName;
CTrigger * trigger_item;
DISPID dispid = DISPID_UNKNOWN;
long nStatus;
bool bReplace = false;
// allow blank names, assign one :)
if (strTriggerName.IsEmpty ())
strTriggerName.Format ("*trigger%s", (LPCTSTR) App.GetUniqueString ());
else
// return if bad name
if (nStatus = CheckObjectName (strTriggerName))
return nStatus;
// if it already exists, error
if (GetTriggerMap ().Lookup (strTriggerName, trigger_item))
if (Flags & eReplace)
bReplace = true;
else
return eTriggerAlreadyExists;
// cannot have null match text
if (strlen (MatchText) == 0)
return eTriggerCannotBeEmpty;
// check sequence
if (Sequence < 0 || Sequence > 10000)
return eTriggerSequenceOutOfRange;
// check send to
if (SendTo < 0 || SendTo >= eSendToLast)
return eTriggerSendToInvalid;
// must have a label for 'send to label'
if (SendTo == eSendToVariable)
if (CheckObjectName (strTriggerName))
return eTriggerLabelNotSpecified;
// get trigger dispatch ID
if (GetScriptEngine () && strlen (ScriptName) != 0)
{
CString strMessage;
dispid = GetProcedureDispid (ScriptName, "trigger", TriggerName, strMessage);
if (dispid == DISPID_UNKNOWN)
return eScriptNameNotLocated;
}
t_regexp * regexp = NULL;
CString strRegexp;
if (Flags & eTriggerRegularExpression)
strRegexp = MatchText;
else
strRegexp = ConvertToRegularExpression (MatchText);
// compile regular expression
try
{
regexp = regcomp (strRegexp, (Flags & eIgnoreCase ? PCRE_CASELESS : 0) | (m_bUTF_8 ? PCRE_UTF8 : 0));
} // end of try
catch(CException* e)
{
e->Delete ();
return eBadRegularExpression;
} // end of catch
// trigger replacement wanted
if (bReplace)
{
// the trigger seems to exist - delete its pointer
delete trigger_item;
// now delete its entry
GetTriggerMap ().RemoveKey (strTriggerName);
}
// create new trigger item and insert in trigger map
GetTriggerMap ().SetAt (strTriggerName, trigger_item = new CTrigger);
if ((Flags & eTemporary) == 0)
if (!m_CurrentPlugin) // plugin mods don't really count
SetModifiedFlag (TRUE);
trigger_item->nUpdateNumber = App.GetUniqueNumber (); // for concurrency checks
trigger_item->strInternalName = strTriggerName; // for deleting one-shot triggers
trigger_item->trigger = MatchText;
trigger_item->contents = ResponseText;
trigger_item->colour = Colour;
trigger_item->ignore_case = (Flags & eIgnoreCase) != 0;
trigger_item->bOmitFromOutput = (Flags & eOmitFromOutput) != 0;
trigger_item->bKeepEvaluating = (Flags & eKeepEvaluating) != 0;
trigger_item->omit_from_log = (Flags & eOmitFromLog) != 0;
trigger_item->bEnabled = (Flags & eEnabled) != 0;
trigger_item->bRegexp = (Flags & eTriggerRegularExpression) != 0;
trigger_item->bExpandVariables = (Flags & eExpandVariables) != 0;
trigger_item->bTemporary = (Flags & eTemporary) != 0;
trigger_item->bLowercaseWildcard = (Flags & eLowercaseWildcard) != 0;
trigger_item->bOneShot = (Flags & eTriggerOneShot) != 0;
trigger_item->strProcedure = ScriptName;
trigger_item->strLabel = TriggerName;
trigger_item->iClipboardArg = Wildcard;
trigger_item->sound_to_play = SoundFileName;
trigger_item->dispid = dispid;
trigger_item->regexp = regexp;
trigger_item->iSendTo = SendTo;
trigger_item->iSequence = Sequence;
trigger_item->strVariable = TriggerName; // kludge
if (Colour < 0 || Colour >= MAX_CUSTOM)
trigger_item->colour = SAMECOLOUR;
if (Wildcard < 0 || Wildcard > 10)
trigger_item->iClipboardArg = 0;
SortTriggers ();
return eOK;
}
// world.AddTrigger (trigger_name, ...) - adds the named trigger
long CMUSHclientDoc::AddTrigger(LPCTSTR TriggerName,
LPCTSTR MatchText,
LPCTSTR ResponseText,
long Flags,
short Colour,
short Wildcard,
LPCTSTR SoundFileName,
LPCTSTR ScriptName)
{
return AddTriggerEx (TriggerName,
MatchText,
ResponseText,
Flags,
Colour,
Wildcard,
SoundFileName,
ScriptName,
eSendToWorld,
DEFAULT_TRIGGER_SEQUENCE);
}
// world.EnableTrigger (trigger_name, bEnableFlag) - enables or disables the named trigger
long CMUSHclientDoc::EnableTrigger(LPCTSTR TriggerName, BOOL Enabled)
{
CString strTriggerName = TriggerName;
CTrigger * trigger_item;
long nStatus;
// return if bad name
if (nStatus = CheckObjectName (strTriggerName, false))
return nStatus;
if (!GetTriggerMap ().Lookup (strTriggerName, trigger_item))
return eTriggerNotFound;
if (trigger_item->bEnabled && Enabled)
return eOK; // already enabled, document hasn't changed
if (!trigger_item->bEnabled && !Enabled)
return eOK; // already not enabled, document hasn't changed
trigger_item->bEnabled = Enabled != 0; // set enabled flag
trigger_item->nUpdateNumber = App.GetUniqueNumber (); // for concurrency checks
if (!m_CurrentPlugin) // plugin mods don't really count
SetModifiedFlag (TRUE); // document has changed
return eOK;
}
// world.GetTrigger (trigger_name, ...) - gets details about the named trigger
long CMUSHclientDoc::GetTrigger(LPCTSTR TriggerName,
VARIANT FAR* MatchText,
VARIANT FAR* ResponseText,
VARIANT FAR* Flags,
VARIANT FAR* Colour,
VARIANT FAR* Wildcard,
VARIANT FAR* SoundFileName,
VARIANT FAR* ScriptName)
{
CString strTriggerName = TriggerName;
CTrigger * trigger_item;
long nStatus;
// return if bad name
if (nStatus = CheckObjectName (strTriggerName, false))
return nStatus;
if (!GetTriggerMap ().Lookup (strTriggerName, trigger_item))
return eTriggerNotFound;
SetUpVariantString (*MatchText, trigger_item->trigger);
SetUpVariantString (*ResponseText, trigger_item->contents);
SetUpVariantString (*ScriptName, trigger_item->strProcedure);
SetUpVariantString (*SoundFileName, trigger_item->sound_to_play);
SetUpVariantShort (*Colour, trigger_item->colour);
if (trigger_item->colour == SAMECOLOUR)
SetUpVariantShort (*Colour, -1);
short iFlags = 0;
if (trigger_item->ignore_case)
iFlags |= eIgnoreCase;
if (trigger_item->bOmitFromOutput)
iFlags |= eOmitFromOutput;
if (trigger_item->bKeepEvaluating)
iFlags |= eKeepEvaluating;
if (trigger_item->omit_from_log)
iFlags |= eOmitFromOutput;
if (trigger_item->bEnabled)
iFlags |= eEnabled;
if (trigger_item->bRegexp)
iFlags |= eTriggerRegularExpression;
if (trigger_item->bLowercaseWildcard)
iFlags |= eLowercaseWildcard;
if (trigger_item->bOneShot)
iFlags |= eTriggerOneShot;
SetUpVariantShort (*Flags, iFlags);
SetUpVariantShort (*Wildcard, trigger_item->iClipboardArg);
return eOK;
}
// world.IsTrigger (trigger_name) - returns eOK if the trigger exists
long CMUSHclientDoc::IsTrigger(LPCTSTR TriggerName)
{
CString strTriggerName = TriggerName;
CTrigger * trigger_item;
long nStatus;
// return if bad name
if (nStatus = CheckObjectName (strTriggerName, false))
return nStatus;
if (!GetTriggerMap ().Lookup (strTriggerName, trigger_item))
return eTriggerNotFound;
return eOK;
}
// world.GetTriggerList - returns a variant array which is a list of trigger names
VARIANT CMUSHclientDoc::GetTriggerList()
{
COleSafeArray sa; // for wildcard list
CString strTriggerName;
CTrigger * trigger_item;
long iCount = 0;
POSITION pos;
iCount = GetTriggerMap ().GetCount ();
if (iCount) // cannot create empty array dimension
{
sa.CreateOneDim (VT_VARIANT, iCount);
for (iCount = 0, pos = GetTriggerMap ().GetStartPosition(); pos; iCount++)
{
GetTriggerMap ().GetNextAssoc (pos, strTriggerName, trigger_item);
// the array must be a bloody array of variants, or VBscript kicks up
COleVariant v (strTriggerName);
sa.PutElement (&iCount, &v);
} // end of looping through each trigger
} // end of having at least one
return sa.Detach ();
}
// ******************************************************************************
// **************************** VARIABLES ***************************************
// ******************************************************************************
// world.SetVariable (variable_name, new_contents) - sets the named variable's contents
// - creating it if necessary
long CMUSHclientDoc::SetVariable(LPCTSTR VariableName, LPCTSTR Contents)
{
CString strVariableName = VariableName;
CVariable * variable_item;
long nStatus;
// return if bad name
if (nStatus = CheckObjectName (strVariableName))
return nStatus;
// get rid of old variable, if any
if (GetVariableMap ().Lookup (strVariableName, variable_item))
delete variable_item;
// create new variable item and insert in variable map
GetVariableMap ().SetAt (strVariableName, variable_item = new CVariable);
m_bVariablesChanged = true;
// SetModifiedFlag (TRUE); // set flag instead now
variable_item->nUpdateNumber = App.GetUniqueNumber (); // for concurrency checks
// set up variable item contents
variable_item->strLabel = VariableName;
variable_item->strContents = Contents;
return eOK;
}
// world.GetVariable (variable_name) - gets details about the named variable
// returns "EMPTY" variable if not there
// returns "NULL" variable if a bad name
VARIANT CMUSHclientDoc::GetVariable(LPCTSTR VariableName)
{
CString strVariableName = VariableName;
CVariable * variable_item;
VARIANT vaResult;
VariantInit(&vaResult);
vaResult.vt = VT_NULL;
// return if bad name, if so return NULL
if (CheckObjectName (strVariableName))
return vaResult;
vaResult.vt = VT_EMPTY;
// see if variable exists, if not return EMPTY
if (!GetVariableMap ().Lookup (strVariableName, variable_item))
return vaResult;
SetUpVariantString (vaResult, variable_item->strContents);
return vaResult;
}
// world.GetVariableList - returns a variant array which is a list of variable names
VARIANT CMUSHclientDoc::GetVariableList()
{
COleSafeArray sa; // for variable list
CString strVariableName;
CVariable * variable_item;
POSITION pos;
long iCount;
// put the Variables into the array
if (!GetVariableMap ().IsEmpty ()) // cannot create empty dimension
{
sa.CreateOneDim (VT_VARIANT, GetVariableMap ().GetCount ());
for (iCount = 0, pos = GetVariableMap ().GetStartPosition(); pos; )
{
GetVariableMap ().GetNextAssoc (pos, strVariableName, variable_item);
// the array must be a bloody array of variants, or VBscript kicks up
COleVariant v (strVariableName);
sa.PutElement (&iCount, &v);
iCount++;
} // end of looping through each Variable
} // end of having at least one
return sa.Detach ();
}
// world.DeleteVariable (variable_name) - deletes the named variable
long CMUSHclientDoc::DeleteVariable(LPCTSTR VariableName)
{
CString strVariableName = VariableName;
CVariable * variable_item;
long nStatus;
// return if bad name
if (nStatus = CheckObjectName (strVariableName))
return nStatus;
if (!GetVariableMap ().Lookup (strVariableName, variable_item))
return eVariableNotFound;
// the variable seems to exist - delete its pointer
delete variable_item;
// now delete its entry
if (!GetVariableMap ().RemoveKey (strVariableName))
return eVariableNotFound;
if (!m_CurrentPlugin) // plugin mods don't really count
SetModifiedFlag (TRUE); // document has changed
return eOK;
} // end of DeleteVariable
// ******************************************************************************
// **************************** ALIASES ****************************************
// ******************************************************************************
// world.DeleteAlias (alias_name) - deletes the named alias
long CMUSHclientDoc::DeleteAlias(LPCTSTR AliasName)
{
CString strAliasName = AliasName;
CAlias * alias_item;
long nStatus;
// return if bad name
if (nStatus = CheckObjectName (strAliasName, false))
return nStatus;
if (!GetAliasMap ().Lookup (strAliasName, alias_item))
return eAliasNotFound;
// can't if executing a script
if (alias_item->bExecutingScript)
return eItemInUse;
bool bTemporary = alias_item->bTemporary;
// the alias seems to exist - delete its pointer
delete alias_item;
// now delete its entry
if (!GetAliasMap ().RemoveKey (strAliasName))
return eAliasNotFound;
SortAliases ();
if (!m_CurrentPlugin && !bTemporary) // plugin mods don't really count
SetModifiedFlag (TRUE); // document has changed
return eOK;
}
// world.AddAlias (alias_name, ...) - adds the named alias
long CMUSHclientDoc::AddAlias(LPCTSTR AliasName,
LPCTSTR MatchText,
LPCTSTR ResponseText,
long Flags,
LPCTSTR ScriptName)
{
CString strAliasName = AliasName;
CAlias * alias_item;
DISPID dispid = DISPID_UNKNOWN;
long nStatus;
bool bReplace = false;
// allow blank name, allocate one
if (strAliasName.IsEmpty ())
strAliasName.Format ("*alias%s", (LPCTSTR) App.GetUniqueString ());
else
// return if bad name
if (nStatus = CheckObjectName (strAliasName))
return nStatus;
// if it already exists, error
if (GetAliasMap ().Lookup (strAliasName, alias_item))
if (Flags & eReplace)
bReplace = true;
else
return eAliasAlreadyExists;
// cannot have null match text
if (strlen (MatchText) == 0)
return eAliasCannotBeEmpty;
// get alias dispatch ID