forked from nickgammon/mushclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc_construct.cpp
808 lines (616 loc) · 23.2 KB
/
doc_construct.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
// doc_construct.cpp : CMUSHclientDoc constructor/destructor
//
#include "stdafx.h"
#include "MUSHclient.h"
#include "mainfrm.h"
#include "doc.h"
#include "genprint.h"
#include "dialogs\QuickConnectDlg.h"
#include "UDPsocket.h"
extern int gdoccount;
/////////////////////////////////////////////////////////////////////////////
// CMUSHclientDoc construction/destruction
CMUSHclientDoc::CMUSHclientDoc()
: m_eventScriptFileChanged(FALSE, TRUE)
{ // constructor
int i;
// each document will have a unique number
m_iUniqueDocumentNumber = App.GetUniqueNumber ();
m_whenWorldStarted = CTime::GetCurrentTime();
QueryPerformanceCounter (&m_whenWorldStartedHighPrecision);
AllocateConfigurationArrays ();
m_bTrace = false; // not tracing yet
// note - these initialisations merely make the hash lookup more efficient.
// until v 3.21 they were the default of 20, so this should help somewhat
// The number should be a prime number, hence the strange figures.
m_VariableMap.InitHashTable (997); // allow for 1000 variables (at least)
m_AliasMap.InitHashTable (293); // probably won't have many more than 300 aliases
m_TriggerMap.InitHashTable (293); // probably won't have many more than 300 triggers
m_TimerMap.InitHashTable (293); // probably won't have many more than 300 timers
SetDefaults (false); // set up numeric/boolean defaults
SetAlphaDefaults (false); // set up alpha defaults
m_strWorldID = GetUniqueID (); // default world ID
m_CurrentPlugin = NULL; // no plugin active right now
m_iBackgroundMode = 0;
m_iForegroundMode = 0;
m_iBackgroundColour = NO_COLOUR;
m_TextRectangle = CRect (0, 0, 0, 0);
m_TextRectangleBorderOffset = 0;
m_TextRectangleBorderColour = 0;
m_TextRectangleBorderWidth = 0;
m_TextRectangleOutsideFillColour = 0;
m_TextRectangleOutsideFillStyle = 0;
m_iCurrentActionSource = eUnknownActionSource;
m_nBytesIn = 0;
m_nBytesOut = 0;
m_bTabCompleteFunctions = true;
m_iTriggersEvaluatedCount = 0;
m_iTriggersMatchedCount = 0;
m_iAliasesEvaluatedCount = 0;
m_iAliasesMatchedCount = 0;
m_iTimersFiredCount = 0;
m_iTriggersMatchedThisSessionCount = 0;
m_iAliasesMatchedThisSessionCount = 0;
m_iTimersFiredThisSessionCount = 0;
m_bLoaded = false;
m_bMapping = false;
m_bRemoveMapReverses = true;
m_MapFailureRegexp = NULL;
m_bPluginProcessingCommand = false;
m_bPluginProcessingSend = false;
m_bPluginProcessingSent = false;
m_iLastCommandCount = 0;
m_iExecutionDepth = 0;
m_iNextChatID = 0;
m_tLastMessageTime = 0;
m_tLastGroupMessageTime = 0;
m_bOmitFromCommandHistory = false;
m_bUTF_8 = false;
m_bWorldClosing = false;
m_bInSendToScript = true;
m_bInPlaySoundFilePlugin = false;
m_bInCancelSoundFilePlugin = false;
m_strStatusMessage = Translate ("Ready");
m_bShowingMapperStatus = false;
m_iMCCP_type = 0;
m_bSupports_MCCP_2 = false;
m_bNoEcho = false;
m_bDebugIncomingPackets = false;
m_iInputPacketCount = 0;
m_iOutputPacketCount = 0;
m_iUTF8ErrorCount = 0;
m_lastGoTo = 1;
m_bNAWS_wanted = false;
m_bCHARSET_wanted = false;
m_bSuppressNewline = false;
m_echo_colour = SAMECOLOUR;
m_bAlwaysRecordCommandHistory = false;
m_bDoNotShowOutstandingLines = false;
m_bDoNotTranslateIACtoIACIAC = false;
m_bAutoResizeCommandWindow = false;
m_bLogScriptErrors = false;
m_bOmitSavedDateFromSaveFiles = false;
m_iAutoResizeMinimumLines = 1;
m_iAutoResizeMaximumLines = 20;
m_bDoNotAddMacrosToCommandHistory = false;
m_bCopySelectionToClipboard = false;
m_bCarriageReturnClearsLine = false;
m_bConvertGAtoNewline = false;
m_bSendMXP_AFK_Response = true;
m_bMudCanChangeOptions = true;
// m_bShowGridLinesInListViews = true; // NB - app-wide :P
m_bEnableSpamPrevention = false;
m_strSpamMessage = "look";
m_iSpamLineCount = 20;
m_iLastOutgoingChatPort = DEFAULT_CHAT_PORT;
m_bScrollBarWanted = TRUE;
m_iSocksProcessing = 0; // no socks processing wanted
m_iProxyServerPort = 1080; // default socks port
// deprecated options - set to zero for saving comparison (for XML testing)
m_page_colour = 0;
m_whisper_colour= 0;
m_mail_colour = 0;
m_game_colour = 0;
m_chat_colour = 0;
m_remove_channels1 = 0;
m_remove_channels2 = 0;
m_remove_pages= 0;
m_remove_whispers = 0;
m_remove_set= 0;
m_remove_mail = 0;
m_remove_game = 0;
// things I found to be not initialised in version 3.43
m_timestamps = 0;
m_iFlags1 = 0;
m_iFlags2 = 0;
m_iListMode = 0;
m_iListCount = 0;
m_iMXP_previousMode = eMXP_open;
m_code = 0;
// sound buffers
for (i = 0; i < MAX_SOUND_BUFFERS; i++)
m_pDirectSoundSecondaryBuffer [i] = NULL;
/*---------------------------------------------------------
I want to be able to time speed walking delays (for pulling things
out of the list, so I need a window that can take timer events, however
a CDocument isn't a window. Thus, I'll make a hidden window for this
specific purpose.
I previously had speed walking tied to the CSendView window but this was
pretty crappy, because you could have multiple send views, thus the timers
would be all over the shop, and it was very fiddly when firing a "send" from
a trigger, because a trigger is not related to a particular send view.
--------------------------------------------------------- */
// create window that we can use for firing timers
m_pTimerWnd = new CTimerWnd (this);
m_pTimerWnd->m_hWnd = NULL;
if (!m_pTimerWnd->CreateEx(0, AfxRegisterWndClass(0),
_T("Document timer window"),
WS_OVERLAPPED, 0, 0, 0, 0, NULL, NULL))
{
TRACE0("Warning: unable to create document timer window!\n");
AfxThrowResourceException();
}
ASSERT(m_pTimerWnd->m_hWnd != NULL);
ASSERT(CWnd::FromHandlePermanent(m_pTimerWnd->m_hWnd) == m_pTimerWnd);
for (i = 0; i < NUMITEMS (m_font); i++)
m_font [i] = NULL;
m_input_font = NULL;
m_FontHeight = 0;
m_FontWidth = 0;
m_InputFontHeight = 0;
m_InputFontWidth = 0;
m_total_lines = 0;
m_newlines_received = 0;
m_last_line_with_IAC_GA = 0;
m_nTotalLinesSent = 0;
m_nTotalLinesReceived = 0;
m_phase = NONE;
m_ttype_sequence = 0;
m_bVariablesChanged = false;
m_bNotesNotWantedNow = false;
m_bDoingSimulate = false;
m_bLineOmittedFromOutput = false;
m_view_number = 0;
m_LastFlushTime = CTime::GetCurrentTime();
m_bCompress = false; // no compression yet
m_bCompressInitOK = false;
m_CompressInput = NULL;
m_CompressOutput = NULL;
// initialise zlib decompression
m_zCompress.next_in = Z_NULL;
m_zCompress.avail_in = 0;
m_zCompress.zalloc = Z_NULL;
m_zCompress.zfree = Z_NULL;
m_zCompress.opaque = Z_NULL;
m_nTotalUncompressed = 0;
m_nTotalCompressed = 0;
m_iCompressionTimeTaken = 0;
m_nCompressionOutputBufferSize = COMPRESS_BUFFER_LENGTH; // initial value
// we will defer initialising zlib until we really have to
m_pSocket = NULL;
m_pChatListenSocket = NULL; // no listening socket
m_logfile = NULL;
m_match_width = 30;
m_bSelected = true;
m_bNotesInRGB = false; // notes are in palette colour right now
m_iNoteStyle = NORMAL; // notes are not bold right now
// MXP
m_bMXP = false; // no MXP yet
m_bPuebloActive = false; // no Pueblo yet either <evil grin>
m_bInParagraph = false;
m_bMXP_script = false;
m_bPreMode = false;
m_iMXP_defaultMode = eMXP_open;
m_iMXP_mode = m_iMXP_defaultMode;
m_cLastChar = 0;
// initial styles
m_iFlags = 0;
m_iForeColour = WHITE;
m_iBackColour = BLACK;
if (m_bCustom16isDefaultColour)
{
m_iForeColour = 15; // use custom colour 16
m_iBackColour = 15;
m_iFlags |= COLOUR_CUSTOM;
}
// m_normalcolour [BLACK] = RGB (192, 192, 192) | PALETTE; // black
// m_normalcolour [RED] = RGB (128, 0, 64) | PALETTE; // red
// m_normalcolour [GREEN] = RGB (128, 255, 128) | PALETTE; // green
// m_normalcolour [YELLOW] = RGB (255, 255, 128) | PALETTE; // yellow
// m_normalcolour [BLUE] = RGB ( 0, 255, 255) | PALETTE; // blue
// m_normalcolour [MAGENTA] = RGB (255, 0, 128) | PALETTE; // magenta
// m_normalcolour [CYAN] = RGB (128, 255, 255) | PALETTE; // cyan
// m_normalcolour [WHITE] = RGB ( 0, 128, 0) | PALETTE; // white
// m_boldcolour [BLACK] = RGB ( 0, 0, 0) | PALETTE; // black
// m_boldcolour [RED] = RGB (255, 0, 0) | PALETTE; // red
// m_boldcolour [GREEN] = RGB ( 0, 255, 0) | PALETTE; // green
// m_boldcolour [YELLOW] = RGB (255, 255, 0) | PALETTE; // yellow
// m_boldcolour [BLUE] = RGB ( 0, 64, 128) | PALETTE; // blue
// m_boldcolour [MAGENTA] = RGB (255, 0, 255) | PALETTE; // magenta
// m_boldcolour [CYAN] = RGB ( 0, 255, 255) | PALETTE; // cyan
// m_boldcolour [WHITE] = RGB (255, 255, 255) | PALETTE; // white
// better use ANSI colours as the default
SetDefaultAnsiColours (m_normalcolour, m_boldcolour);
// and some nice custom colours
SetDefaultCustomColours (m_customtext, m_customback);
// default custom colour names
for (i = 0; i < NUMITEMS (m_strCustomColourName); i++)
m_strCustomColourName [i].Format ("Custom%i", i + 1);
for (i = 0; i < NUMITEMS (m_macro_type); i++)
m_macro_type [i] = SEND_NOW;
// printer styles for printing from the screen
for (i = 0; i < 8; i++)
{
m_nNormalPrintStyle [i] = 0;
m_nBoldPrintStyle [i] = FONT_BOLD;
}
m_bUseDefaultOutputFont = !App.m_strDefaultOutputFont.IsEmpty ();
m_bUseDefaultColours = !App.m_strDefaultColoursFile.IsEmpty ();
m_bUseDefaultTriggers = !App.m_strDefaultTriggersFile.IsEmpty ();
m_bUseDefaultAliases = !App.m_strDefaultAliasesFile.IsEmpty ();
m_bUseDefaultMacros = !App.m_strDefaultMacrosFile.IsEmpty ();
m_bUseDefaultTimers = !App.m_strDefaultTimersFile.IsEmpty ();
m_bUseDefaultInputFont = !App.m_strDefaultInputFont.IsEmpty ();
setupstrings ();
m_tStatusTime = CTime::GetCurrentTime();
m_tConnectTime = CTime::GetCurrentTime();
m_tLastPlayerInput = CTime::GetCurrentTime();
m_timeScriptFileMod = 0;
m_tsConnectDuration = CTimeSpan (0, 0, 0, 0);
m_iConnectPhase = eConnectNotConnected;
gdoccount++;
m_pActiveCommandView = NULL;
m_pActiveOutputView = NULL;
m_new_lines = 0;
m_last_prefs_page = 1;
App.m_bUpdateActivity = TRUE;
// for looking up host names
ZeroMemory (&m_sockAddr, sizeof m_sockAddr);
ZeroMemory (&m_ProxyAddr, sizeof m_ProxyAddr);
m_hNameLookup = NULL;
m_pGetHostStruct = NULL;
m_pLinePositions = NULL;
m_pCurrentLine = NULL;
m_total_lines = 0;
// set up the dialog box headings for the finding dialogs
m_DisplayFindInfo.m_strTitle = "Find in output buffer...";
m_MacrosFindInfo.m_strTitle = "Find macro...";
m_AliasesFindInfo.m_strTitle = "Find alias...";
m_TriggersFindInfo.m_strTitle = "Find trigger...";
m_TimersFindInfo.m_strTitle = "Find timer...";
m_VariablesFindInfo.m_strTitle = "Find variable...";
m_NotesFindInfo.m_strTitle = "Find in notes...";
m_RecallFindInfo.m_strTitle = "Recall...";
m_bRecallCommands = true;
m_bRecallOutput = true;
m_bRecallNotes = true;
// set up column counts for use in the loading and saving of the column orders etc.
m_MacrosFindInfo.m_iControlColumns = CPrefsP6::eColumnCount;
m_AliasesFindInfo.m_iControlColumns = CPrefsP7::eColumnCount;
m_TriggersFindInfo.m_iControlColumns = CPrefsP8::eColumnCount;
m_TimersFindInfo.m_iControlColumns = CPrefsP16::eColumnCount;
m_VariablesFindInfo.m_iControlColumns = CPrefsP18::eColumnCount;
m_bDisconnectOK = true; // so we don't try to reconnect to prematurely
m_iMXPerrors = 0;
m_iMXPtags = 0;
m_iMXPentities = 0;
// scripting support
EnableAutomation(); // not needed?
if (!bWine)
AfxOleLockApp(); // not needed?
m_ScriptEngine = NULL;
m_bInScriptFileChanged = false;
m_pThread = NULL;
m_bSyntaxErrorOnly = false;
m_dispidWorldOpen = DISPID_UNKNOWN;
m_dispidWorldClose = DISPID_UNKNOWN;
m_dispidWorldSave = DISPID_UNKNOWN;
m_dispidWorldConnect = DISPID_UNKNOWN;
m_dispidWorldDisconnect = DISPID_UNKNOWN;
m_dispidWorldGetFocus = DISPID_UNKNOWN;
m_dispidWorldLoseFocus = DISPID_UNKNOWN;
m_dispidOnMXP_Start = DISPID_UNKNOWN;
m_dispidOnMXP_Stop = DISPID_UNKNOWN;
m_dispidOnMXP_OpenTag = DISPID_UNKNOWN;
m_dispidOnMXP_CloseTag = DISPID_UNKNOWN;
m_dispidOnMXP_SetVariable = DISPID_UNKNOWN;
m_dispidOnMXP_Error = DISPID_UNKNOWN;
m_iScriptTimeTaken = 0; // time taken on scripts
m_bPluginProcessesOpenTag = false;
m_bPluginProcessesCloseTag = false;
m_bPluginProcessesSetVariable = false;
m_bPluginProcessesSetEntity = false;
m_bPluginProcessesError = false;
ZeroMemory (&m_bClient_sent_IAC_DO, sizeof m_bClient_sent_IAC_DO);
ZeroMemory (&m_bClient_sent_IAC_DONT, sizeof m_bClient_sent_IAC_DONT);
ZeroMemory (&m_bClient_sent_IAC_WILL, sizeof m_bClient_sent_IAC_WILL);
ZeroMemory (&m_bClient_sent_IAC_WONT, sizeof m_bClient_sent_IAC_WONT);
ZeroMemory (&m_bClient_got_IAC_DO, sizeof m_bClient_got_IAC_DO);
ZeroMemory (&m_bClient_got_IAC_DONT, sizeof m_bClient_got_IAC_DONT);
ZeroMemory (&m_bClient_got_IAC_WILL, sizeof m_bClient_got_IAC_WILL);
ZeroMemory (&m_bClient_got_IAC_WONT, sizeof m_bClient_got_IAC_WONT);
m_nCount_IAC_DO = 0;
m_nCount_IAC_DONT = 0;
m_nCount_IAC_WILL = 0;
m_nCount_IAC_WONT = 0;
m_nCount_IAC_SB = 0;
m_iOutputWindowRedrawCount = 0;
m_bTreeviewTriggers = true;
m_bTreeviewAliases = true;
m_bTreeviewTimers = true;
// set up some default triggers for MUSHes
/*
The parameter are:
Trigger Name
Match Text
Response Text
Flags
Colour
Wildcard to copy to clipboard
Sound File Name
Script Name
*/
/* No, don't. It just confuses Diku MUD people
AddTrigger ("Game_messages", "GAME:*", "", eEnabled, 0, 0, "", "");
AddTrigger ("Page_poses", "From afar,*", "", eEnabled, 1, 0, "", "");
AddTrigger ("Pages", "^\\w+ pages.*$", "", eEnabled | eTriggerRegularExpression, 1, 0, "", "");
AddTrigger ("Whisper_poses", "You sense:*", "", eEnabled, 2, 0, "", "");
AddTrigger ("Whispers", "^\\w+ whispers.*$", "", eEnabled | eTriggerRegularExpression, 2, 0, "", "");
AddTrigger ("Mail_messages", "MAIL:*", "", eEnabled, 3, 0, "", "");
AddTrigger ("Chat_channel_1", "^\\<.+?\\>.*$", "", eEnabled | eTriggerRegularExpression, 4, 0, "", "");
AddTrigger ("Chat_channel_2", "^\\[.+?\\].*$", "", eEnabled | eTriggerRegularExpression, 4, 0, "", "");
*/
m_nextAcceleratorCommand = ACCELERATOR_FIRST_COMMAND;
m_accelerator = NULL;
} // end of CMUSHclientDoc::CMUSHclientDoc()
#ifdef PANE
void closepane (pair<string, CPaneView *> item)
{
item.second->GetParentFrame ()->SendMessage (WM_CLOSE);
}
#endif // PANE
CMUSHclientDoc::~CMUSHclientDoc()
{
int i;
// stop sounds playing, release sound buffers
for (i = 0; i < MAX_SOUND_BUFFERS; i++)
if (m_pDirectSoundSecondaryBuffer [i])
{
DWORD iStatus;
if (SUCCEEDED (m_pDirectSoundSecondaryBuffer [i]->GetStatus (&iStatus)) &&
(iStatus & DSBSTATUS_PLAYING))
m_pDirectSoundSecondaryBuffer [i]->Stop ();
m_pDirectSoundSecondaryBuffer [i]->Release ();
}
if (m_pTimerWnd)
{
m_pTimerWnd->DestroyWindow();
delete m_pTimerWnd;
m_pTimerWnd = NULL;
}
for (i = 0; i < NUMITEMS (m_font); i++)
delete m_font [i];
delete m_input_font;
if (m_hNameLookup)
WSACancelAsyncRequest (m_hNameLookup); // cancel host name lookup in progress
delete [] m_pGetHostStruct; // delete buffer used by host name lookup
delete m_MapFailureRegexp; // delete regexp structure for mapping failures
if (m_pSocket)
{
ShutDownSocket (*m_pSocket);
delete m_pSocket;
m_pSocket = NULL;
}
if (m_pChatListenSocket)
{
ShutDownSocket (*m_pChatListenSocket);
delete m_pChatListenSocket;
m_pChatListenSocket = NULL;
}
// UDP listening sockets
for (map<int, UDPsocket *>::iterator udpSocketIterator = m_UDPsocketMap.begin ();
udpSocketIterator != m_UDPsocketMap.end ();
udpSocketIterator++)
delete udpSocketIterator->second;
// delete chat sessions
DELETE_LIST (m_ChatList);
// delete plugins
// we have to do it this way, because otherwise if a plugin attempts to access the
// plugin list (eg. BroadcastPlugin, Trace) during the delete operation, then it
// may call a plugin that was deleted a moment ago, but is still in the list.
for (PluginListIterator pit = m_PluginList.begin ();
pit != m_PluginList.end ();
pit = m_PluginList.erase (pit)) // erase from list and get next one
delete *pit; // delete *this* one
CloseLog (); // this writes out the log file postamble as well
// delete triggers
DELETE_MAP (m_TriggerMap, CTrigger);
// delete aliass
DELETE_MAP (m_AliasMap, CAlias);
// delete lines list
DELETE_LIST (m_LineList);
// delete timer map
DELETE_MAP (m_TimerMap, CTimer);
// delete variables map
DELETE_MAP (m_VariableMap, CVariable);
// delete Element map
DELETE_MAP (m_CustomElementMap, CElement);
// delete active tags list
DELETE_LIST (m_ActiveTagList);
// delete actions list
DELETE_LIST (m_ActionList);
// get rid of our positions array
delete [] m_pLinePositions;
// one less document
gdoccount--;
// update activity window
App.m_bUpdateActivity = TRUE;
// ****************** release scripting stuff
DisableScripting ();
if (!bWine)
AfxOleUnlockApp(); // not needed?
// free compression stuff
if (m_CompressOutput)
free (m_CompressOutput);
if (m_CompressInput)
free (m_CompressInput);
// don't wrap up if not initialised
if (m_bCompressInitOK)
inflateEnd (&m_zCompress);
// don't need to know what the configuration was any more
DeleteConfigurationArrays ();
// delete our arrays
for (tStringMapOfMaps::iterator it = m_Arrays.begin ();
it != m_Arrays.end ();
it++)
{
tStringToStringMap * m = it->second;
m->clear ();
delete m;
}
// destroy accelerator table, if we had one
if (m_accelerator)
DestroyAcceleratorTable (m_accelerator);
// if they loaded a special font, get rid of it
RemoveSpecialFonts ();
#ifdef PANE
// get rid of owned panes
safe_for_each (m_PaneMap.begin (), m_PaneMap.end (), closepane);
#endif // PANE
// delete MiniWindow map
for (MiniWindowMapIterator mwit = m_MiniWindows.begin ();
mwit != m_MiniWindows.end ();
mwit++)
delete mwit->second;
m_MiniWindowsOrder.clear ();
// delete databases
for (tDatabaseMapIterator dbit = m_Databases.begin ();
dbit != m_Databases.end ();
dbit++)
{
if (dbit->second->pStmt) // finalize any outstanding statement
sqlite3_finalize(dbit->second->pStmt);
if (dbit->second->db) // and close the database
sqlite3_close(dbit->second->db);
delete dbit->second; // now delete memory used by it
}
} // end of CMUSHclientDoc::~CMUSHclientDoc
BOOL CMUSHclientDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
SetDefaults (false); // set up numeric/boolean defaults
SetAlphaDefaults (false); // set up alpha defaults
// if defaults are wanted, overwrite what we loaded with them :)
if (m_bLoaded)
OnFileReloaddefaults ();
else
{
if (!App.m_strDefaultColoursFile.IsEmpty ())
{
m_bUseDefaultColours = true;
Load_Set (COLOUR, App.m_strDefaultColoursFile, &Frame);
}
if (!App.m_strDefaultTriggersFile.IsEmpty ())
{
m_bUseDefaultTriggers = true;
Load_Set (TRIGGER, App.m_strDefaultTriggersFile, &Frame);
}
if (!App.m_strDefaultAliasesFile.IsEmpty ())
{
m_bUseDefaultAliases = true;
Load_Set (ALIAS, App.m_strDefaultAliasesFile, &Frame);
}
if (!App.m_strDefaultTimersFile.IsEmpty ())
{
m_bUseDefaultTimers = true;
Load_Set (TIMER, App.m_strDefaultTimersFile, &Frame);
}
if (!App.m_strDefaultMacrosFile.IsEmpty ())
{
m_bUseDefaultMacros = true;
Load_Set (MACRO, App.m_strDefaultMacrosFile, &Frame);
}
if (!App.m_strDefaultInputFont.IsEmpty ())
{
m_bUseDefaultInputFont = true;
m_input_font_height = App.m_iDefaultInputFontHeight;
m_input_font_name = App.m_strDefaultInputFont;
m_input_font_italic = App.m_iDefaultInputFontItalic;
m_input_font_weight = App.m_iDefaultInputFontWeight;
m_input_font_charset = App.m_iDefaultInputFontCharset;
} // end of input font override
if (!App.m_strDefaultOutputFont.IsEmpty ())
{
m_bUseDefaultOutputFont = true;
m_font_height = App.m_iDefaultOutputFontHeight;
m_font_name = App.m_strDefaultOutputFont;
m_font_weight = FW_NORMAL;
m_font_charset = App.m_iDefaultOutputFontCharset;
} // end of output font override
} // end of not loading an existing world
m_bLoaded = false; // not really loaded - effectively a new world
// get name and IP address, give up if cancelled
if (App.m_TypeOfNewDocument == App.eQuickConnect) // pop up nice simple dialog box
{
CQuickConnectDlg dlg;
dlg.m_iPort = 4000;
dlg.m_strWorldName = "Untitled world";
dlg.m_strAddress = "";
if (dlg.DoModal () != IDOK)
return FALSE;
m_server = dlg.m_strAddress;
m_port = dlg.m_iPort;
m_mush_name = dlg.m_strWorldName;
// save auto connect flag, then set to true, to make sure we connect
unsigned int savebAutoConnectWorlds = App.m_bAutoConnectWorlds;
App.m_bAutoConnectWorlds = TRUE;
SetUpOutputWindow ();
OpenSession ();
App.m_bAutoConnectWorlds = savebAutoConnectWorlds;
SetModifiedFlag ();
return TRUE;
} // end of quick connect
if (App.m_TypeOfNewDocument == App.eTelnetFromNetscape) // just do it
{
// get rid of telnet stuff
CString strCommandLine = ::Replace (App.m_lpCmdLine, "telnet://", "");
int iSpace = strCommandLine.FindOneOf (" :");
if (iSpace == -1)
{
m_server = strCommandLine;
m_mush_name = strCommandLine;
m_port = 23;
}
else
{
m_server = strCommandLine.Left (iSpace);
m_mush_name = m_server;
m_port = atoi (strCommandLine.Mid (iSpace + 1));
}
// save auto connect flag, then set to true, to make sure we connect
unsigned int savebAutoConnectWorlds = App.m_bAutoConnectWorlds;
App.m_bAutoConnectWorlds = TRUE;
SetUpOutputWindow ();
OpenSession ();
App.m_bAutoConnectWorlds = savebAutoConnectWorlds;
SetModifiedFlag ();
return TRUE;
} // end of telnet called from netscape navigator
// we have to do this *before* getting the preferences
SetUpOutputWindow ();
if (!GamePreferences (ePageGeneral))
return FALSE;
if(m_mush_name.IsEmpty ())
{
::TMessageBox("Your world name cannot be blank.", MB_ICONEXCLAMATION);
return FALSE;
}
if(m_server.IsEmpty ())
{
::TMessageBox("The world TCP/IP address cannot be blank.", MB_ICONEXCLAMATION);
return FALSE;
}
OpenSession ();
return TRUE;
}