-
Notifications
You must be signed in to change notification settings - Fork 76
/
MUSHclient.cpp
2229 lines (1630 loc) · 58.5 KB
/
MUSHclient.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
// MUSHclient.cpp : Defines the class behaviors for the application.
//
// xgettext -kTMessageBox -kTranslate -o mushclient_static.po *.cpp
// xgettext -kTranslateFormat -o mushclient_formatted.po *.cpp
#include "stdafx.h"
#include "MUSHclient.h"
#include "doc.h"
#include "ActivityDoc.h"
#include "TextDocument.h"
#include "mainfrm.h"
#include "childfrm.h"
#include "activitychildfrm.h"
#include "textchildfrm.h"
#include "MUSHview.h"
#include "ActivityView.h"
#include "TextView.h"
#include "winplace.h"
#include "StatLink.h"
#include "dialogs\welcome.h"
#include "dialogs\welcome1.h"
#include "dialogs\TipDlg.h"
#include "dialogs\CreditsDlg.h"
#include "dialogs\ColourPickerDlg.h"
#include "dialogs\Splash.h"
#include "direct.h"
extern "C"
{
#include "scripting\number.h"
void bc_free_numbers ();
}
COLORREF xterm_256_colours [256];
// Lua 5.1
#ifdef LUA_52
#pragma comment( lib, "lua52.lib" )
#else
#pragma comment( lib, "lua5.1.lib" )
#endif
// library needed for timers
#pragma comment( lib, "winmm.lib")
// Winsock library
#pragma comment( lib, "ws2_32.lib ")
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
static TCHAR BASED_CODE szCtrlBars[] = _T("CtrlBars");
// working directory at login time
char working_dir [_MAX_PATH];
char file_browsing_dir [_MAX_PATH];
bool bWinNT;
bool bWin95;
bool bWin98;
bool bWine;
OSVERSIONINFO os_version;
// memory state tracking
#ifdef _DEBUG
CMemoryState oldMemState, newMemState, diffMemState;
#endif
extern tConfigurationNumericOption OptionsTable [];
extern tConfigurationAlphaOption AlphaOptionsTable [];
void LoadMapDirections (void);
void Generate256colours (void);
extern const struct luaL_Reg *ptr_xmllib;
extern "C"
{
LUALIB_API int luaopen_rex(lua_State *L);
LUALIB_API int luaopen_bits(lua_State *L);
LUALIB_API int luaopen_compress(lua_State *L);
LUALIB_API int luaopen_bc(lua_State *L);
LUALIB_API int luaopen_lsqlite3(lua_State *L);
LUALIB_API int luaopen_lpeg (lua_State *L);
}
/////////////////////////////////////////////////////////////////////////////
// CMUSHclientApp
//IMPLEMENT_DYNCREATE(CMUSHclientApp, CWinApp)
BEGIN_MESSAGE_MAP(CMUSHclientApp, CWinApp)
ON_COMMAND(CG_IDS_TIPOFTHEDAY, ShowTipOfTheDay)
//{{AFX_MSG_MAP(CMUSHclientApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_GAME_MINIMISEPROGRAM, OnGameMinimiseprogram)
ON_COMMAND(ID_CONNECTION_QUICK_CONNECT, OnConnectionQuickConnect)
ON_COMMAND(ID_FILE_NEW, OnFileNew)
ON_COMMAND(ID_HELP_GETTINGSTARTED, OnHelpGettingstarted)
ON_COMMAND(ID_EDIT_COLOURPICKER, OnEditColourpicker)
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/*
See: http://www.codeproject.com/com/mfc_autom.asp
BEGIN_DISPATCH_MAP(CMUSHclientApp, CWinApp)
DISP_FUNCTION_ID(CMUSHclientApp, "Test", dispidTest, Test, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()
static const IID IID_IMUSHclient =
{ 0xE594883F, 0x0CC4, 0x491a, { 0xA2, 0x8C, 0xB5,0x07, 0x1E, 0x53, 0xAE, 0x2C } };
BEGIN_INTERFACE_MAP(CMUSHclientApp, CWinApp)
// INTERFACE_PART(CMUSHclientApp, IID_IMUSHclient, LocalClass)
INTERFACE_PART(CMUSHclientApp, IID_IMUSHclient, Dispatch)
END_INTERFACE_MAP()
*/
/*
BEGIN_DISPATCH_MAP(CMUSHclientApp, CWinApp)
//{{AFX_DISPATCH_MAP(CMUSHclientApp)
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
// Note: we add support for IID_IMUSHclient to support typesafe binding
// from VBA. This IID must match the GUID that is attached to the
// dispinterface in the .ODL file.
// {11DFC5E8-AD6F-11D0-8EAE-00A0247B3BFD}
static const IID IID_IMUSHclient =
{ 0x11dfc5e8, 0xad6f, 0x11d0, { 0x8e, 0xae, 0x0, 0xa0, 0x24, 0x7b, 0x3b, 0xfd } };
BEGIN_INTERFACE_MAP(CMUSHclientApp, CWinApp)
INTERFACE_PART(CMUSHclientApp, IID_IMUSHclient, Dispatch)
END_INTERFACE_MAP()
*/
/*
BEGIN_INTERFACE_PART(LocalClass, IMUSHclient)
STDMETHOD(GetTypeInfoCount)(UINT FAR* pctinfo);
STDMETHOD(GetTypeInfo)(
UINT itinfo,
LCID lcid,
ITypeInfo FAR* FAR* pptinfo);
STDMETHOD(GetIDsOfNames)(
REFIID riid,
OLECHAR FAR* FAR* rgszNames,
UINT cNames,
LCID lcid,
DISPID FAR* rgdispid);
STDMETHOD(Invoke)(
DISPID dispidMember,
REFIID riid,
LCID lcid,
WORD wFlags,
DISPPARAMS FAR* pdispparams,
VARIANT FAR* pvarResult,
EXCEPINFO FAR* pexcepinfo,
UINT FAR* puArgErr);
STDMETHOD(Test)(THIS);
END_INTERFACE_PART(LocalClass)
IMPLEMENT_OLECREATE(CMUSHclientApp, "MUSHclient.Application",
0x14FE63AB, 0x691A, 0x11DB, 0x99, 0x8B, 0x00, 0x00, 0x8C, 0x01, 0x27, 0x85 )
*/
/////////////////////////////////////////////////////////////////////////////
// CMUSHclientApp construction
CMUSHclientApp::CMUSHclientApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
EnableAutomation();
//::AfxOleLockApp();
}
CMUSHclientApp::~CMUSHclientApp()
{
//::AfxOleUnlockApp();
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMUSHclientApp object
CMUSHclientApp theApp;
// This identifier was generated to be statistically unique for your app.
// You may change it if you prefer to choose a specific identifier.
// {11DFC5E6-AD6F-11D0-8EAE-00A0247B3BFD}
static const CLSID clsid =
{ 0x11dfc5e6, 0xad6f, 0x11d0, { 0x8e, 0xae, 0x0, 0xa0, 0x24, 0x7b, 0x3b, 0xfd } };
CString MUSHCLIENT_VERSION;
/////////////////////////////////////////////////////////////////////////////
// CMUSHclientApp initialization
BOOL CMUSHclientApp::InitInstance()
{
m_whenClientStarted = CTime::GetCurrentTime();
char fullfilename [MAX_PATH];
MUSHCLIENT_VERSION = VERSION_STRING;
#ifdef PRE_RELEASE
MUSHCLIENT_VERSION += "-pre";
#endif
if (GetModuleFileName (NULL, fullfilename, sizeof (fullfilename)))
m_strMUSHclientFileName = ExtractDirectory (CString (fullfilename));
else
m_strMUSHclientFileName = ".\\MUSHclient.exe";
// stupid cursor disappears under Parallels
g_hCursorIbeam = CopyCursor(AfxGetApp()->LoadCursor (IDC_MY_IBEAM));
// find the working directory at startup time
_getdcwd (0, working_dir, sizeof (working_dir) - 1);
// make sure directory name ends in a slash
working_dir [sizeof (working_dir) - 2] = 0;
if (working_dir [strlen (working_dir) - 1] != '\\')
strcat (working_dir, "\\");
// where we do file browsing from
strcpy (file_browsing_dir, working_dir);
bc_init_numbers();
// First free the string that was allocated by MFC in the startup
// of CWinApp. The string is allocated before InitInstance is
// called.
free((void*)m_pszProfileName);
// Change the name of the .INI file--CWinApp destructor will free
// the memory.
CString strIniFile (working_dir);
strIniFile += "MUSHclient.ini";
m_pszProfileName=_tcsdup(strIniFile);
WorkOutFixedFont (); // FixedSys or whatever
// open SQLite database for preferences
int rc;
CFileStatus status;
// initially look in MUSHclient working directory for database
m_PreferencesDatabaseName = working_dir;
m_PreferencesDatabaseName += PREFERENCES_DATABASE_FILE;
// if not there, try application directory
if (!CFile::GetStatus(m_PreferencesDatabaseName.c_str (), status))
{
CString strTemp;
strTemp = ExtractDirectory (App.m_strMUSHclientFileName);
strTemp += PREFERENCES_DATABASE_FILE;
// if actually in the application directory, switch to using that
if (CFile::GetStatus(strTemp, status))
m_PreferencesDatabaseName = strTemp;
// if not, leave in the working directory
}
db = NULL;
rc = sqlite3_open(m_PreferencesDatabaseName.c_str (), &db);
if( rc )
{
::AfxMessageBox ((LPCTSTR) CFormat ("Can't open global preferences database at: %s"
"\r\n(Error was: \"%s\")"
"\r\nCheck you have write-access to that file.",
m_PreferencesDatabaseName.c_str (),
sqlite3_errmsg(db)));
sqlite3_close(db);
return FALSE;
}
if (sqlite3_db_readonly (db, "main"))
{
::AfxMessageBox ((LPCTSTR) CFormat ("The global preferences database at: <%s> is read-only."
"\r\nPlease ensure that you have write-access to that file.",
m_PreferencesDatabaseName.c_str ()
));
sqlite3_close(db);
return FALSE;
}
#define CURRENT_DB_VERSION 1
string db_version;
int db_rc;
db_rc = db_simple_query ("SELECT value FROM control WHERE name = 'database_version'", db_version, false);
// no version or out of date, make database
if (db_version.empty () || atoi (db_version.c_str ()) < CURRENT_DB_VERSION)
{
db_execute ("BEGIN TRANSACTION", true);
db_rc = db_execute (
// general control information
"DROP TABLE IF EXISTS control;"
"CREATE TABLE control (name VARCHAR(10) NOT NULL PRIMARY KEY, value INT NOT NULL );",
true);
if (db_rc != SQLITE_OK)
{
db_execute ("ROLLBACK", true);
return FALSE; // SQL error
}
db_write_int ("control", "database_version", CURRENT_DB_VERSION);
db_rc = db_execute (
// global preferences
"DROP TABLE IF EXISTS prefs;"
"CREATE TABLE prefs (name VARCHAR(50) NOT NULL PRIMARY KEY, value TEXT NOT NULL ); "
// world window positions
"DROP TABLE IF EXISTS worlds;"
"CREATE TABLE worlds (name VARCHAR(50) NOT NULL PRIMARY KEY, value TEXT NOT NULL ); "
,true
);
if (db_rc != SQLITE_OK)
{
db_execute ("ROLLBACK", true);
return FALSE; // SQL error
}
// copy from registry to database for legacy support
if (PopulateDatabase () != SQLITE_OK)
{
db_execute ("ROLLBACK", true);
return FALSE; // SQL error
}
db_execute ("COMMIT", true);
} // end database empty
// i18n setup -------------------------------
if (!I18N_Setup ())
return FALSE; // no resources, or Lua won't start up
// as at version 3.13
// {
// int i = sizeof (CLine); // 80 bytes
// int j = sizeof (CStyle); // 20 bytes
// int k = sizeof (CAction); // 28 bytes
// }
// memory state tracking
#ifdef _DEBUG
oldMemState.Checkpoint();
#endif
if (strstr (m_lpCmdLine, "/wine"))
bWine = true;
else
bWine = false;
LoadMapDirections ();
Generate256colours ();
// UMessageBox ("\xC9\xB3\xC9\xA8\xC9\x95\xC9\xAE");
// set the current locale
setlocale (LC_ALL, "" );
// Set the debug-heap flag so that freed blocks are kept on the
// linked list, to catch any inadvertent use of freed memory
SET_CRT_DEBUG_FIELD( _CRTDBG_DELAY_FREE_MEM_DF );
SET_CRT_DEBUG_FIELD( _CRTDBG_LEAK_CHECK_DF );
// SET_CRT_DEBUG_FIELD( _CRTDBG_CHECK_ALWAYS_DF );
// speed warning: see: _ASSERTE( _CrtCheckMemory( ) );
// in ProcessPreviousLine.cpp
m_SpellChecker_Lua = NULL;
m_bShowInitialDelay = true;
m_TypeOfNewDocument = eNormalNewDocument;
m_bSpellCheckOK = false;
m_bEnableSpellCheck = true;
m_bEchoSendToAll = true;
m_nUniqueNumber = 0;
// for string.gsub dialog
m_bEachLine = true;
m_bEscapeSequences = false;
m_bCallFunction = false;
m_pDirectSoundObject = NULL;
m_pDirectSoundPrimaryBuffer = NULL;
// Initialize OLE libraries
if (!bWine)
if (!AfxOleInit()) // not needed?
{
TMessageBox("OLE initialization failed", MB_ICONSTOP);
return FALSE;
}
AfxInitRichEdit ();
LARGE_INTEGER large_int_frequency;
if (QueryPerformanceFrequency (&large_int_frequency))
m_iCounterFrequency = large_int_frequency.QuadPart;
else
m_iCounterFrequency = 0; // no performance counter
// CG: The following block was added by the Splash Screen component.
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
CSplashWnd::EnableSplashScreen(true);
TRACE ("MUSHclient starting up ...\n");
if (!AfxSocketInit(&m_wsadata))
{
::AfxMessageBox(IDP_SOCKETS_INIT_FAILED, MB_ICONSTOP);
return FALSE;
}
// Standard initialization
#if _MSC_VER == 1200
Enable3dControls();
#endif
//Make sure this is here so you can use XP Styles
InitCommonControls();
LoadStdProfileSettings(10); // Load standard INI file options (including MRU)
if (!bWine)
AfxEnableControlContainer (); // not needed?
m_pActivityDoc = NULL;
m_pActivityView = NULL;
m_bUpdateActivity = FALSE;
// seed the random number generator
time_t timer;
time (&timer);
srand (timer);
// Marsenne Twister generator
init_genrand (timer);
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
// put this first so unknown extensions default to text (eg. mush)
// the normal document (*.txt)
m_pNormalDocTemplate = new CMultiDocTemplate(
IDR_NORMALTYPE,
RUNTIME_CLASS(CTextDocument),
RUNTIME_CLASS(CTextChildFrame), // custom MDI child frame
RUNTIME_CLASS(CTextView));
AddDocTemplate(m_pNormalDocTemplate);
// normal worlds
m_pWorldDocTemplate = new CMultiDocTemplate(
IDR_MUSHCLTYPE,
RUNTIME_CLASS(CMUSHclientDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CMUSHView));
AddDocTemplate(m_pWorldDocTemplate);
#ifdef PANE
// normal worlds - extra pane windows
m_pPaneTemplate = new CMultiDocTemplate(
IDR_PANETYPE,
RUNTIME_CLASS(CMUSHclientDoc),
RUNTIME_CLASS(CPaneChildWnd), // custom MDI child frame
RUNTIME_CLASS(CPaneView));
AddDocTemplate(m_pPaneTemplate);
#endif
// the activity window
m_pActivityDocTemplate = new CMultiDocTemplate(
IDR_ACTIVITYTYPE,
RUNTIME_CLASS(CActivityDoc),
RUNTIME_CLASS(CActivityChildFrame), // custom MDI child frame
RUNTIME_CLASS(CActivityView));
AddDocTemplate(m_pActivityDocTemplate);
if (!bWine)
{
// Connect the COleTemplateServer to the document template.
// The COleTemplateServer creates new documents on behalf
// of requesting OLE containers by using information
// specified in the document template.
m_server.ConnectTemplate(clsid, m_pWorldDocTemplate, FALSE);
// Register all OLE server factories as running. This enables the
// OLE libraries to create objects from other applications.
COleTemplateServer::RegisterAll();
// Note: MDI applications register all server objects without regard
// to the /Embedding or /Automation on the command line.
}
// read global prefs from the database
LoadGlobalsFromDatabase ();
// check for configuration name collisions
#ifdef _DEBUG
int i;
for (i = 0; AlphaOptionsTable [i].pName; i++)
for (int j = 0; OptionsTable [j].pName; j++)
if (strcmp (AlphaOptionsTable [i].pName, OptionsTable [j].pName) == 0)
::UMessageBox (TFormat ("Internal MUSHclient error, config name collision: %s",
(LPCTSTR) OptionsTable [j].pName), MB_ICONEXCLAMATION);
#endif
CWnd * extraWnd = NULL;
// if *only* tray wanted, hide icon from task bar
if (m_iIconPlacement == ICON_PLACEMENT_TRAY)
{
extraWnd = new CWnd;
// MUSHclient icon for hidden window, so Alt+Tab will look OK
HICON hIcon =
(HICON)LoadImage( AfxGetResourceHandle(),
MAKEINTRESOURCE(IDR_MUSHCLTYPE),
IMAGE_ICON,
GetSystemMetrics(SM_CXICON),
GetSystemMetrics(SM_CYICON),
LR_DEFAULTCOLOR);
// for hiding main window from taskbar
VERIFY(extraWnd->CreateEx
( 0, AfxRegisterWndClass(CS_CLASSDC | CS_GLOBALCLASS, 0, 0, hIcon),
_T("MUSHclient"), WS_OVERLAPPEDWINDOW | WS_EX_TOOLWINDOW,
0, 0, 0, 0, NULL, NULL ));
} // end of tray wanted
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME,
WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE ,
extraWnd)) // owner is hidden window
{
TMessageBox ("Unable to load main frame window", MB_ICONSTOP);
return FALSE;
}
m_pMainWnd = pMainFrame;
if (m_iIconPlacement == ICON_PLACEMENT_TRAY ||
m_iIconPlacement == ICON_PLACEMENT_BOTH)
Frame.AddTrayIcon ();
// Enable DDE Execute open
if (strstr (m_lpCmdLine, "/noregister") == NULL)
{
EnableShellOpen();
RegisterShellFileTypes();
}
// initialise COM
if (!bWine)
CoInitialize (NULL);
// check direct sound available
FARPROC pDirectSoundCreate = NULL;
if (strstr (m_lpCmdLine, "/nodirectsound") == NULL)
{
HMODULE hDLL = LoadLibrary ("dsound");
if (hDLL)
pDirectSoundCreate = GetProcAddress(hDLL, "DirectSoundCreate");
if (pDirectSoundCreate)
{
// try to set up for DirectSound
if (FAILED (DirectSoundCreate (NULL, &m_pDirectSoundObject, NULL)))
m_pDirectSoundObject = NULL;
// set sound cooperation level
if (m_pDirectSoundObject)
if (FAILED (m_pDirectSoundObject->SetCooperativeLevel (pMainFrame->m_hWnd, DSSCL_NORMAL)))
m_pDirectSoundObject = NULL; // no DirectSound
}
} // if DirectSound wanted
if (m_pDirectSoundObject)
{
DSBUFFERDESC bd;
memset (&bd, 0, sizeof (DSBUFFERDESC));
bd.dwSize = sizeof (DSBUFFERDESC);
bd.dwFlags = DSBCAPS_PRIMARYBUFFER;
bd.dwBufferBytes = 0; //must be 0 for primary buffer
bd.lpwfxFormat = NULL; //must be null for primary buffer
if (FAILED (m_pDirectSoundObject->CreateSoundBuffer (&bd, &m_pDirectSoundPrimaryBuffer, NULL)))
m_pDirectSoundObject = NULL; // no DirectSound
}
// see which OS we are using
memset(&os_version, 0, sizeof(os_version));
os_version.dwOSVersionInfoSize = sizeof(os_version);
VERIFY(::GetVersionEx(&os_version));
bWinNT = (os_version.dwPlatformId == VER_PLATFORM_WIN32_NT);
bWin95 = (os_version.dwPlatformId ==
VER_PLATFORM_WIN32_WINDOWS) && (os_version.dwMinorVersion == 0);
bWin98 = (os_version.dwPlatformId ==
VER_PLATFORM_WIN32_WINDOWS) && (os_version.dwMinorVersion > 0);
// MXP initialisation
MXP_LoadElements (); // elements like <b>
MXP_LoadEntities (); // entities like >
MXP_LoadColours (); // colours like blue
// show the main window
pMainFrame->ShowWindow(m_nCmdShow);
// get main window position from last time
CWindowPlacement wp;
pMainFrame->GetWindowPlacement(&wp); // default if no registry entry
wp.Restore ("Main window", pMainFrame, true);
pMainFrame->LoadBarState(szCtrlBars);
if (m_bAlwaysOnTop)
pMainFrame->SetWindowPos(&CWnd::wndTopMost, 0, 0, 0, 0, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE);
// get finger cursor
CStaticLink::g_hCursorLink = AfxGetApp()->LoadCursor (ID_FINGER_CURSOR);
bool bAutoOpen = true;
// simple command line parsing
if (m_lpCmdLine[0] == '\0')
{
// create a new (empty) document
// OnFileNew(); // do nothing
}
else
{
CString strTemp = m_lpCmdLine;
strTemp.MakeLower ();
strTemp.TrimLeft ();
// look for /noauto command-line option
if (strTemp == "/noauto")
bAutoOpen = false;
else if (strTemp == "/wine")
{ } // do nothing else, checked further up
else if (strTemp == "/noregister")
{ } // do nothing else, checked further up
else if (strTemp == "/nodirectsound")
{ } // do nothing else, checked further up
else if (strstr (strTemp, ".mcl"))
// open an existing document
OpenDocumentFile(m_lpCmdLine);
else
{
// switch to "telnet from netscape" mode
m_TypeOfNewDocument = eTelnetFromNetscape;
App.m_pWorldDocTemplate->OpenDocumentFile(NULL);
// back to normal
m_TypeOfNewDocument = eNormalNewDocument;
bAutoOpen = false; // and cancel auto-open
} // end of world and port supplied
}
// enable spell checker, if wanted in prefs
if (m_bEnableSpellCheck)
InitSpellCheck ();
// open all worlds specified in global preferences if no shift key is down
if ((GetKeyState (VK_LSHIFT) & 0x8000) == 0 &&
(GetKeyState (VK_RSHIFT) & 0x8000) == 0 &&
bAutoOpen)
{
vector<string> v;
StringToVector ((const char *) m_strWorldList, v, "*");
for (vector<string>::const_iterator i = v.begin (); i != v.end (); i++)
m_pWorldDocTemplate->OpenDocumentFile (i->c_str ());
}
// The main window has been initialized, so update it.
pMainFrame->UpdateWindow();
// Enable drag/drop open
m_pMainWnd->DragAcceptFiles();
// When a server application is launched stand-alone, it is a good idea
// to update the system registry in case it has been damaged.
/*
Ah, bollocks. It just raises an error on Windows XP guest accounts.
// NJG - version 4.03
if (!bWine)
{
m_server.UpdateRegistry(OAT_DISPATCH_OBJECT);
COleObjectFactory::UpdateRegistryAll();
}
*/
// Show first welcome
BOOL firsttime = db_get_int ("control", "First time", 1);
UINT version = 0;
if (firsttime)
{
// fix up tool bars
Frame.RecalcLayout(TRUE);
CRect rectBar;
CMyToolBar * pToolBar;
// main toolbar
pToolBar = &Frame.m_wndToolBar;
if (pToolBar) // assuming we can find it
{
pToolBar->GetWindowRect(&rectBar);
CRect rect (0, 0, rectBar.right - rectBar.left, rectBar.bottom - rectBar.top);
Frame.ClientToScreen (rect);
Frame.DockControlBar (pToolBar, AFX_IDW_DOCKBAR_TOP, rect);
// put game toolbar next to it
Frame.ScreenToClient (rect);
OffsetRect (rect, 265, 0);
pToolBar = &Frame.m_wndGameToolBar;
if (pToolBar) // assuming we can find it
{
pToolBar->GetWindowRect(&rectBar);
Frame.ClientToScreen (rect);
Frame.DockControlBar (pToolBar, AFX_IDW_DOCKBAR_TOP, rect);
} // toolbar found
// float the activity bar
pToolBar = &Frame.m_wndActivityToolBar;
if (pToolBar) // assuming we can find it
{
pToolBar->GetWindowRect(&rectBar);
CPoint point (500, 70);
Frame.ClientToScreen (&point);
Frame.FloatControlBar (pToolBar, point, CBRS_ALIGN_LEFT);
} // toolbar found
} // toolbar found
CWelcomeDlg dlg;
dlg.m_strMessage.Format (Translate ("I notice that this is the first time you have used"
" MUSHclient on this PC."));
dlg.DoModal ();
db_write_int ("control", "First time", 0);
} // end of first time
else // not the first time they have used this program
{
version = db_get_int ("control", "Version", 0);
if (version < THISVERSION) // THISVERSION is defined in version.h
{
CWelcome1Dlg dlg; // Welcome to this version dialog
dlg.m_strMessage1 = TFormat ("Welcome to MUSHclient, version %s", MUSHCLIENT_VERSION);
dlg.m_strMessage2 = TFormat ("Thank you for upgrading MUSHclient to version %s",
MUSHCLIENT_VERSION);
dlg.DoModal ();
} // end of having lower version than THISVERSION
} // end of not first time
// Write out the new version number if necessary
if (version != THISVERSION)
db_write_int ("control", "Version", THISVERSION);
// Find which version of Windows we are using.
OSVERSIONINFO VersionInformation;
VersionInformation.dwOSVersionInfoSize = sizeof (VersionInformation);
GetVersionEx(&VersionInformation);
platform = VersionInformation.dwPlatformId;
// open activity window if wanted
if (m_bOpenActivityWindow)
App.m_pActivityDocTemplate->OpenDocumentFile(NULL);
// activate first world, if any (so activity world doesn't have the focus)
pMainFrame->SendMessage (WM_COMMAND, ID_WORLDS_WORLD1, 0);
if (firsttime && !bWine && HelpAvailable (false))
App.HelpHelper(ID_GETTING_STARTED + HID_BASE_COMMAND);
App.ShowTipAtStartup();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
protected:
// static controls with hyperlinks
CStaticLink m_EmailLink;
CStaticLink m_WebLink;
CStaticLink m_ChangesLink;
CStaticLink m_RegcodeLink;
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CString m_strVersion;
CString m_strEmail;
CString m_strWebAddress;
CString m_strChangeHistoryAddress;
//}}AFX_DATA
// Implementation
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//{{AFX_MSG(CAboutDlg)
virtual BOOL OnInitDialog();
afx_msg void OnCredits();
afx_msg void OnLicense();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
m_strVersion = _T("");
m_strEmail = _T("");
m_strWebAddress = _T("");
m_strChangeHistoryAddress = _T("");
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
DDX_Text(pDX, IDC_VERSION_LABEL, m_strVersion);
DDX_Text(pDX, IDC_EMAIL_ADDRESS, m_strEmail);
DDX_Text(pDX, IDC_WEB_ADDRESS, m_strWebAddress);
DDX_Text(pDX, IDC_CHANGES_ADDRESS, m_strChangeHistoryAddress);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_BN_CLICKED(IDC_CREDITS, OnCredits)
ON_BN_CLICKED(IDC_LICENSE, OnLicense)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CMUSHclientApp::OnAppAbout()
{
static CAboutDlg aboutDlg;
aboutDlg.m_strVersion = "Version ";
aboutDlg.m_strVersion += MUSHCLIENT_VERSION;
aboutDlg.m_strWebAddress = MY_WEB_PAGE;
aboutDlg.m_strChangeHistoryAddress = CHANGES_WEB_PAGE;
aboutDlg.DoModal();
}
BOOL CAboutDlg::OnInitDialog()
{
// subclass static controls.
m_WebLink.SubclassDlgItem(IDC_WEB_ADDRESS, this);
m_ChangesLink.SubclassDlgItem(IDC_CHANGES_ADDRESS, this);
m_RegcodeLink.SubclassDlgItem(IDC_REGCODE, this);
return CDialog::OnInitDialog();
}
/////////////////////////////////////////////////////////////////////////////
// CMUSHclientApp commands
extern int gdoccount;
BOOL CMUSHclientApp::SaveAllModified()
{
// warn them, if they have sessions open.
if (gdoccount > 0 && App.m_bConfirmBeforeClosingMushclient)
if (::TMessageBox ("This will end your MUSHclient session.",
MB_OKCANCEL | MB_ICONINFORMATION)
== IDCANCEL)