Clone of UAS2 @ https://github.com/drudgedance/uas2

WinMain.cpp 45KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390
  1. /*
  2. * This file is part of UAS2.
  3. *
  4. * UAS2 is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * UAS2 is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. * You should have received a copy of the GNU General Public License
  14. * along with UASv1; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. /**
  18. * @file WinMain.cpp
  19. * Implements functionality for the application GUI and console.
  20. */
  21. #include <winsock2.h>
  22. #include "resource.h"
  23. #include <windowsx.h>
  24. #include <commctrl.h>
  25. #include <tchar.h>
  26. #include "VersionNo.h"
  27. #include "calc_funcs.h"
  28. //
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32. //
  33. #include "MasterServer.h"
  34. #include "WorldManager.h"
  35. #include "Status.h"
  36. #define MYWM_NOTIFYICON (WM_APP+100)
  37. #define CONSOLE_WIDTH_NORM 218
  38. #define CONSOLE_WIDTH_OPT 610
  39. #define CONSOLE_HEIGHT_NORM 535
  40. #define CONSOLE_HEIGHT_OPT 535
  41. HINSTANCE g_hInstance;
  42. HWND g_hWndMain;
  43. HWND g_hWndConsole;
  44. HWND g_hWndHelpTitle;
  45. HWND g_hWndHelp;
  46. BOOL g_fStarted;
  47. BOOL g_fConfig;
  48. BOOL g_fClients;
  49. short g_nWorldPort;
  50. short g_nCharPort;
  51. char g_szLocalIP[16];
  52. char g_szDBIP[16];
  53. char g_szDBNAME[20];
  54. char g_szDBUSER[20];
  55. char g_szDBPASSWORD[20];
  56. int g_DBType;
  57. int GetLocalAddress( LPSTR lpStr, LPDWORD lpdwStrLen )
  58. {
  59. struct in_addr *pinAddr;
  60. LPHOSTENT lpHostEnt;
  61. int iRet;
  62. int iLen;
  63. iRet = gethostname( lpStr, *lpdwStrLen );
  64. if ( iRet == SOCKET_ERROR )
  65. {
  66. lpStr[0] = '\0';
  67. return SOCKET_ERROR;
  68. }
  69. lpHostEnt = gethostbyname( lpStr );
  70. if ( lpHostEnt == NULL )
  71. {
  72. lpStr[0] = '\0';
  73. return SOCKET_ERROR;
  74. }
  75. pinAddr = ((LPIN_ADDR)lpHostEnt->h_addr);
  76. iLen = lstrlen( inet_ntoa( *pinAddr ) );
  77. if ( (DWORD)iLen > *lpdwStrLen )
  78. {
  79. *lpdwStrLen = iLen;
  80. WSASetLastError( WSAEINVAL );
  81. return SOCKET_ERROR;
  82. }
  83. *lpdwStrLen = iLen;
  84. lstrcpy( lpStr, inet_ntoa( *pinAddr ) );
  85. return 0;
  86. }
  87. void UpdateConsole( const char *szBuff )
  88. {
  89. int iLength = SendMessage( g_hWndConsole, WM_GETTEXTLENGTH, 0, 0 );
  90. // SendMessage( g_hWndConsole, EM_SETSEL, iLength, iLength );
  91. // SendMessage( g_hWndConsole, EM_REPLACESEL, FALSE, (LPARAM)szBuff );
  92. if(iLength < 5000){
  93. SendMessage( g_hWndConsole, EM_SETSEL, iLength, iLength );
  94. SendMessage( g_hWndConsole, EM_REPLACESEL, FALSE, (LPARAM)szBuff );
  95. }
  96. else
  97. {
  98. iLength = 0;
  99. SendMessage( g_hWndConsole, WM_SETTEXT, iLength, iLength );
  100. SendMessage( g_hWndConsole, EM_SETSEL, iLength, iLength );
  101. SendMessage( g_hWndConsole, EM_REPLACESEL, FALSE, (LPARAM)szBuff );
  102. }
  103. }
  104. long UpdateConsole( char *szBuff, long nErr )
  105. {
  106. UpdateConsole( szBuff );
  107. if ( !nErr )
  108. {
  109. char *lpMsgBuf;
  110. FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, nErr, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), (LPTSTR) &lpMsgBuf, 0, NULL );
  111. UpdateConsole( lpMsgBuf );
  112. LocalFree( lpMsgBuf );
  113. }
  114. else
  115. UpdateConsole( "success.\r\n\r\n" );
  116. return nErr;
  117. }
  118. void UpdateConsole( char *szMessage, ... )
  119. {
  120. char szBuffer[1024];
  121. va_list valMaker;
  122. va_start( valMaker, szMessage );
  123. wvsprintf( (char *)szBuffer, (const char *)szMessage, valMaker );
  124. int iLength = SendMessage( g_hWndConsole, WM_GETTEXTLENGTH, 0, 0 );
  125. if(iLength < 5000){
  126. SendMessage( g_hWndConsole, EM_SETSEL, iLength, iLength );
  127. SendMessage( g_hWndConsole, EM_REPLACESEL, FALSE, (LPARAM)szBuffer );
  128. }
  129. else
  130. {
  131. iLength = 0;
  132. SendMessage( g_hWndConsole, WM_SETTEXT, iLength, iLength );
  133. SendMessage( g_hWndConsole, EM_SETSEL, iLength, iLength );
  134. SendMessage( g_hWndConsole, EM_REPLACESEL, FALSE, (LPARAM)szBuffer );
  135. }
  136. }
  137. void UpdateHelpTitle( char *szMessage, ... )
  138. {
  139. char szBuffer[1024];
  140. va_list valMaker;
  141. va_start( valMaker, szMessage );
  142. wvsprintf( (char *)szBuffer, (const char *)szMessage, valMaker );
  143. int iLength = SendMessage( g_hWndHelpTitle, WM_GETTEXTLENGTH, 0, 0 );
  144. iLength = 0;
  145. //BUGGY
  146. // SendMessage( g_hWndHelpTitle, WM_SETTEXT, iLength, iLength );
  147. // SendMessage( g_hWndHelpTitle, EM_SETSEL, iLength, iLength );
  148. // SendMessage( g_hWndHelpTitle, EM_REPLACESEL, FALSE, (LPARAM)szBuffer );
  149. }
  150. void UpdateHelp( char *szMessage, ... )
  151. {
  152. char szBuffer[1024];
  153. va_list valMaker;
  154. va_start( valMaker, szMessage );
  155. wvsprintf( (char *)szBuffer, (const char *)szMessage, valMaker );
  156. int iLength = SendMessage( g_hWndHelp, WM_GETTEXTLENGTH, 0, 0 );
  157. iLength = 0;
  158. SendMessage( g_hWndHelp, WM_SETTEXT, iLength, iLength );
  159. SendMessage( g_hWndHelp, EM_SETSEL, iLength, iLength );
  160. SendMessage( g_hWndHelp, EM_REPLACESEL, FALSE, (LPARAM)szBuffer );
  161. }
  162. void SystrayAdd( HWND hWnd )
  163. {
  164. NOTIFYICONDATA nid;
  165. memset( &nid, 0, sizeof( NOTIFYICONDATA ) );
  166. nid.cbSize = sizeof( NOTIFYICONDATA );
  167. nid.hWnd = hWnd;
  168. nid.uID = ID_SYSTRAY;
  169. nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  170. nid.uCallbackMessage = MYWM_NOTIFYICON;
  171. nid.hIcon = LoadIcon( g_hInstance, MAKEINTRESOURCE( IDI_ICON ) );
  172. _tcscpy( nid.szTip, "UAS2 Server" );
  173. Shell_NotifyIcon( NIM_ADD, &nid );
  174. DestroyIcon( nid.hIcon );
  175. }
  176. void SystrayDelete( HWND hWnd )
  177. {
  178. NOTIFYICONDATA nid;
  179. memset( &nid, 0, sizeof( NOTIFYICONDATA ) );
  180. nid.cbSize = sizeof( NOTIFYICONDATA );
  181. nid.hWnd = hWnd;
  182. nid.uID = ID_SYSTRAY;
  183. Shell_NotifyIcon( NIM_DELETE, &nid );
  184. }
  185. int CALLBACK MainWindowProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
  186. {
  187. static HWND hWndStart;
  188. static HWND hWndClearObjs;
  189. static HWND hWndDiscAll;
  190. static HWND hWndDBTYPE;
  191. static HWND hWndDBIP;
  192. static HWND hWndDBNAME;
  193. static HWND hWndDBUSER;
  194. static HWND hWndDBPASSWORD;
  195. static HWND hWndCONFIG;
  196. static HWND hWndACCESSFILE;
  197. static HWND hWndPrivate;
  198. static HWND hWndUpdate;
  199. static HWND hWndSettings[30];
  200. static BOOL fExit = FALSE;
  201. static HWND hWndExit;
  202. static UINT s_uTaskbarRestart;
  203. static BOOL fMinimized = FALSE;
  204. switch ( msg )
  205. {
  206. case WM_INITDIALOG:
  207. {
  208. HICON hIcon;
  209. hIcon = LoadIcon( g_hInstance, MAKEINTRESOURCE( IDI_ICON ) );
  210. SendMessage( hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon );
  211. SendMessage( hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon );
  212. DeleteObject( hIcon );
  213. s_uTaskbarRestart = RegisterWindowMessage( TEXT( "TaskbarCreated" ) );
  214. g_hWndConsole = GetDlgItem( hWnd, IDC_CONSOLE );
  215. g_hWndHelpTitle = GetDlgItem( hWnd, IDC_HELP_TITLE );
  216. g_hWndHelp = GetDlgItem( hWnd, IDC_HELP_TEXT );
  217. hWndDBTYPE = GetDlgItem( hWnd, IDC_DBTYPE );
  218. hWndDBIP = GetDlgItem( hWnd, IDC_DBIP );
  219. hWndDBNAME = GetDlgItem( hWnd, IDC_DBNAME );
  220. hWndDBUSER = GetDlgItem( hWnd, IDC_DBUSER );
  221. hWndDBPASSWORD = GetDlgItem( hWnd, IDC_DBPASSWORD );
  222. hWndACCESSFILE = GetDlgItem( hWnd, IDC_ACCESS_FILE );
  223. hWndCONFIG = GetDlgItem( hWnd, IDC_CONFIG );
  224. hWndPrivate = GetDlgItem( hWnd, IDC_SERVER );
  225. hWndUpdate = GetDlgItem( hWnd, IDC_BTN_UPDATE );
  226. hWndSettings[0] = GetDlgItem( hWnd, IDC_STATIP );
  227. hWndSettings[1] = GetDlgItem( hWnd, IDC_STATCP );
  228. hWndSettings[2] = GetDlgItem( hWnd, IDC_STATWP );
  229. hWndSettings[3] = GetDlgItem( hWnd, IDC_STATDBIP );
  230. hWndSettings[4] = GetDlgItem( hWnd, IDC_STATDBN );
  231. hWndSettings[5] = GetDlgItem( hWnd, IDC_STATDBU );
  232. hWndSettings[6] = GetDlgItem( hWnd, IDC_STATDBPASS );
  233. hWndSettings[7] = GetDlgItem( hWnd, IDC_LOCALIP );
  234. hWndSettings[8] = GetDlgItem( hWnd, IDC_CHARPORT );
  235. hWndSettings[9] = GetDlgItem( hWnd, IDC_WORLDPORT );
  236. hWndSettings[10] = GetDlgItem( hWnd, IDC_MYSQL_DB );
  237. hWndSettings[11] = GetDlgItem( hWnd, IDC_MSSQL_DB );
  238. hWndSettings[12] = GetDlgItem( hWnd, IDC_ACCESS_DB );
  239. hWndSettings[13] = GetDlgItem( hWnd, IDC_SETTING_FRAME );
  240. hWndSettings[14] = GetDlgItem( hWnd, IDC_FRAME_DB );
  241. hWndSettings[15] = GetDlgItem( hWnd, IDC_STAT_MAXUSERS );
  242. hWndSettings[16] = GetDlgItem( hWnd, IDC_MAX_USERS );
  243. hWndSettings[17] = GetDlgItem( hWnd, IDC_STAT_SNAME );
  244. hWndSettings[18] = GetDlgItem( hWnd, IDC_ED_SNAME );
  245. WSADATA wsaData;
  246. struct hostent *host;
  247. USHORT wVersionRequested = 0x0202;
  248. UpdateConsole( " Initializing Winsock 2.0 ... ", !WSAStartup( wVersionRequested, &wsaData ) );
  249. host = NULL;
  250. /*
  251. ////////// Read in Data
  252. FILE *pcStatConfig = fopen( "status.ini","rt" );
  253. if ( pcStatConfig )
  254. {
  255. char line[100];
  256. while ( !feof( pcStatConfig ) )
  257. {
  258. fgets( line, 100, pcStatConfig );
  259. char temp[100];
  260. char strData[50];
  261. char value[50];
  262. memcpy(temp,line,sizeof(line));
  263. char* pszSepTemp = strchr(temp, (int)'=');
  264. if(pszSepTemp == NULL)
  265. {
  266. }
  267. else
  268. {
  269. *pszSepTemp = '\0';
  270. sprintf(strData,"%s",temp);
  271. }
  272. char* pszSep = strchr(line, (int)'=');
  273. if(pszSep == NULL)
  274. {
  275. // No data
  276. }
  277. else
  278. {
  279. *pszSep = '\0';
  280. ++pszSep;
  281. char* pszValue = strchr(pszSep, (int)';');
  282. if(pszValue == NULL){
  283. }
  284. else
  285. {
  286. *pszValue = '\0';
  287. }
  288. sprintf(value,"%s",pszSep);
  289. if (lstrcmpi(strData,"Server") == 0)
  290. {
  291. if( lstrcmpi(value,"Private") == 0)
  292. {
  293. UpdateConsole(" Server: Private\r\n");
  294. cMasterServer::cStatus->m_fPrivate = 1;
  295. }
  296. else
  297. {
  298. UpdateConsole(" Server: Public\r\n");
  299. cMasterServer::cStatus->m_fPrivate = 0;
  300. }
  301. }
  302. else if(lstrcmpi(strData,"Host") == 0)
  303. {
  304. if(isalpha(value[0]))
  305. {
  306. //Do DNS Lookup for IP
  307. host = gethostbyname(value);
  308. memcpy(cMasterServer::cStatus->m_strHost,inet_ntoa(*(struct in_addr *) host->h_addr_list[0]),16);
  309. }
  310. else
  311. {
  312. memcpy(cMasterServer::cStatus->m_strHost,value,sizeof(value));
  313. }
  314. }
  315. else if(lstrcmpi(strData,"Port") == 0)
  316. {
  317. cMasterServer::cStatus->m_sPort = atoi(value);
  318. }
  319. else if(lstrcmpi(strData,"Path") == 0)
  320. {
  321. memcpy(cMasterServer::cStatus->m_strHTTP,value,sizeof(value));
  322. }
  323. else if(lstrcmpi(strData,"ID") == 0)
  324. {
  325. cMasterServer::cStatus->m_sID = atol(value);
  326. }
  327. else if(lstrcmpi(strData,"Serial") == 0)
  328. {
  329. memcpy(cMasterServer::cStatus->m_sSer,value,sizeof(value));
  330. }
  331. else if(lstrcmpi(strData,"Key") == 0)
  332. {
  333. memcpy(cMasterServer::cStatus->m_sKey,value,sizeof(value));
  334. }
  335. else if(lstrcmpi(strData,"Client") == 0)
  336. {
  337. memcpy(cMasterServer::cStatus->m_cVersion,value,sizeof(value));
  338. }
  339. else if(lstrcmpi(strData,"MaxUsers") == 0)
  340. {
  341. cMasterServer::cStatus->m_dwMax = atol(value);
  342. }
  343. else
  344. {
  345. // UpdateConsole("Error in status.ini %s\r\n", strData);
  346. }
  347. }
  348. }
  349. fclose( pcStatConfig );
  350. }
  351. else
  352. {
  353. cMasterServer::cStatus->m_fPrivate = true;
  354. }
  355. */
  356. cMasterServer::cStatus->m_fPrivate = true;
  357. //////////////////
  358. SetDlgItemText( hWnd, IDC_VERSIONTEXT, SERVERVERSION);
  359. SetDlgItemText( hWnd, IDC_VERSIONTEXT2, STRFILEVER);
  360. DWORD dwLength;
  361. DWORD dwType = REG_SZ;
  362. char szTemp[5];
  363. char szDBType[2];
  364. char szStatusTemp[20];
  365. char szHostTemp[64];
  366. HKEY hKey;
  367. RegCreateKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\UAS", NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL );
  368. ////////////////////////
  369. // Server Status Settings
  370. dwLength = sizeof( szStatusTemp );
  371. if ( ( RegQueryValueEx( hKey, "Private", NULL, &dwType, (BYTE*)&szStatusTemp, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
  372. {
  373. cMasterServer::cStatus->m_fPrivate = atoi(szStatusTemp);
  374. CheckDlgButton( hWnd, IDC_SERVER, cMasterServer::cStatus->m_fPrivate );
  375. }
  376. else
  377. {
  378. CheckDlgButton( hWnd, IDC_SERVER, 1 );
  379. cMasterServer::cStatus->m_fPrivate = 1;
  380. }
  381. dwLength = sizeof( szHostTemp );
  382. if ( ( RegQueryValueEx( hKey, "Status Host", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
  383. {
  384. if(isalpha(szHostTemp[0]))
  385. {
  386. //Do DNS Lookup for IP
  387. host = gethostbyname(szHostTemp);
  388. memcpy(cMasterServer::cStatus->m_strHost,inet_ntoa(*(struct in_addr *) host->h_addr_list[0]),16);
  389. SetDlgItemText( hWnd, IDC_ED_HOST, szHostTemp );
  390. }
  391. else
  392. {
  393. memcpy(cMasterServer::cStatus->m_strHost,szHostTemp,sizeof(szHostTemp));
  394. SetDlgItemText( hWnd, IDC_ED_HOST, szHostTemp );
  395. }
  396. }
  397. else
  398. {
  399. SetDlgItemText( hWnd, IDC_ED_HOST, "127.0.0.1" );
  400. memcpy(cMasterServer::cStatus->m_strHost,"127.0.0.1",10);
  401. }
  402. dwLength = sizeof( szTemp );
  403. if ( ( RegQueryValueEx( hKey, "HTTP Port", NULL, &dwType, (BYTE*)&szTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
  404. {
  405. SetDlgItemText( hWnd, IDC_ED_PORT, szTemp );
  406. cMasterServer::cStatus->m_sPort = atoi(szTemp);
  407. }
  408. else
  409. {
  410. SetDlgItemText( hWnd, IDC_ED_PORT, "80" );
  411. cMasterServer::cStatus->m_sPort = 80;
  412. }
  413. dwLength = sizeof( szTemp );
  414. if ( ( RegQueryValueEx( hKey, "Server ID", NULL, &dwType, (BYTE*)&szTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
  415. {
  416. SetDlgItemText( hWnd, IDC_ED_ID, szTemp );
  417. cMasterServer::cStatus->m_sID = atol(szTemp);
  418. }
  419. else
  420. {
  421. SetDlgItemText( hWnd, IDC_ED_ID, "0" );
  422. cMasterServer::cStatus->m_sID = 0;
  423. }
  424. dwLength = sizeof( szHostTemp );
  425. if ( ( RegQueryValueEx( hKey, "Server Serial", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
  426. {
  427. SetDlgItemText( hWnd, IDC_ED_SERIAL, szHostTemp );
  428. memcpy(cMasterServer::cStatus->m_sSer,szHostTemp,sizeof(szHostTemp));
  429. }
  430. else
  431. {
  432. SetDlgItemText( hWnd, IDC_ED_SERIAL, "0" );
  433. memcpy(cMasterServer::cStatus->m_sSer,"0",2);
  434. }
  435. dwLength = sizeof( szHostTemp );
  436. if ( ( RegQueryValueEx( hKey, "Server Key", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
  437. {
  438. SetDlgItemText( hWnd, IDC_ED_KEY, szHostTemp );
  439. memcpy(cMasterServer::cStatus->m_sKey,szHostTemp,sizeof(szHostTemp));
  440. }
  441. else
  442. {
  443. SetDlgItemText( hWnd, IDC_ED_KEY, "000000" );
  444. memcpy(cMasterServer::cStatus->m_sKey,"000000",7);
  445. }
  446. dwLength = sizeof( szHostTemp );
  447. if ( ( RegQueryValueEx( hKey, "Client Support", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
  448. {
  449. SetDlgItemText( hWnd, IDC_ED_CLIENT, szHostTemp );
  450. memcpy(cMasterServer::cStatus->m_cVersion,szHostTemp,sizeof(szHostTemp));
  451. }
  452. else
  453. {
  454. SetDlgItemText( hWnd, IDC_ED_CLIENT, "53" );
  455. memcpy(cMasterServer::cStatus->m_cVersion,"53",3);
  456. }
  457. dwLength = sizeof( szHostTemp );
  458. if ( ( RegQueryValueEx( hKey, "HTTP Path", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
  459. {
  460. SetDlgItemText( hWnd, IDC_ED_URL, szHostTemp );
  461. memcpy(cMasterServer::cStatus->m_strHTTP,szHostTemp,sizeof(szHostTemp));
  462. }
  463. else
  464. {
  465. SetDlgItemText( hWnd, IDC_ED_URL, "/" );
  466. memcpy(cMasterServer::cStatus->m_strHTTP,"/",2);
  467. }
  468. ////////////////////////
  469. // Server Settings
  470. // Server Name
  471. dwLength = sizeof( szHostTemp );
  472. if ( ( RegQueryValueEx( hKey, "Server Name", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
  473. {
  474. SetDlgItemText( hWnd, IDC_STAT_NAME, szHostTemp );
  475. SetDlgItemText( hWnd, IDC_ED_SNAME, szHostTemp );
  476. memcpy(cMasterServer::m_szServerName,szHostTemp,sizeof(szHostTemp));
  477. }
  478. else
  479. {
  480. SetDlgItemText( hWnd, IDC_ED_SNAME, "World Name" );
  481. SetDlgItemText( hWnd, IDC_STAT_NAME, "World Name" );
  482. sprintf(cMasterServer::m_szServerName,"World Name" );
  483. }
  484. dwLength = sizeof( szHostTemp );
  485. if ( ( RegQueryValueEx( hKey, "Max Clients", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
  486. {
  487. SetDlgItemText( hWnd, IDC_MAX_USERS, szHostTemp );
  488. cMasterServer::cStatus->m_dwMax = atol(szHostTemp);
  489. }
  490. else
  491. {
  492. SetDlgItemText( hWnd, IDC_MAX_USERS, "0" );
  493. cMasterServer::cStatus->m_dwMax = 0x0L;
  494. }
  495. //Character Server Port
  496. dwLength = sizeof( szTemp );
  497. if ( ( RegQueryValueEx( hKey, "CharPort", NULL, &dwType, (BYTE*)&szTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
  498. SetDlgItemText( hWnd, IDC_CHARPORT, szTemp );
  499. else
  500. SetDlgItemText( hWnd, IDC_CHARPORT, "9002" );
  501. // World Server Port
  502. dwLength = sizeof( szTemp );
  503. if ( ( RegQueryValueEx( hKey, "WorldPort", NULL, &dwType, (BYTE*)&szTemp, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
  504. SetDlgItemText( hWnd, IDC_WORLDPORT, szTemp );
  505. else
  506. SetDlgItemText( hWnd, IDC_WORLDPORT, "9004" );
  507. /////////////
  508. // Database Settings
  509. dwLength = sizeof( szDBType );
  510. if ( ( RegQueryValueEx( hKey, "DBType", NULL, &dwType, (BYTE*)&szDBType, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
  511. { // Set Radio button depending on Value
  512. SetDlgItemText( hWnd, IDC_DBTYPE, szDBType );
  513. g_DBType = szDBType[0] - 0x30;
  514. switch(g_DBType)
  515. {
  516. case 1:
  517. {
  518. CheckDlgButton( hWnd, IDC_ACCESS_DB, 1 );
  519. CheckDlgButton( hWnd, IDC_MSSQL_DB, 0 );
  520. CheckDlgButton( hWnd, IDC_MYSQL_DB, 0 );
  521. // Disable dialog boxes
  522. EnableWindow( hWndDBIP, FALSE );
  523. EnableWindow( hWndDBNAME, FALSE );
  524. EnableWindow( hWndDBUSER, FALSE );
  525. EnableWindow( hWndDBPASSWORD, FALSE );
  526. break;
  527. }
  528. case 2:
  529. {
  530. CheckDlgButton( hWnd, IDC_ACCESS_DB, 0 );
  531. CheckDlgButton( hWnd, IDC_MSSQL_DB, 1 );
  532. CheckDlgButton( hWnd, IDC_MYSQL_DB, 0 );
  533. // Enable dialog boxes
  534. EnableWindow( hWndDBIP, TRUE );
  535. EnableWindow( hWndDBNAME, TRUE );
  536. EnableWindow( hWndDBUSER, TRUE );
  537. EnableWindow( hWndDBPASSWORD, TRUE );
  538. break;
  539. }
  540. case 3:
  541. {
  542. CheckDlgButton( hWnd, IDC_ACCESS_DB, 0 );
  543. CheckDlgButton( hWnd, IDC_MSSQL_DB, 0 );
  544. CheckDlgButton( hWnd, IDC_MYSQL_DB, 1 );
  545. // Enable dialog boxes
  546. EnableWindow( hWndDBIP, TRUE );
  547. EnableWindow( hWndDBNAME, TRUE );
  548. EnableWindow( hWndDBUSER, TRUE );
  549. EnableWindow( hWndDBPASSWORD, TRUE );
  550. break;
  551. }
  552. default:
  553. {
  554. CheckDlgButton( hWnd, IDC_ACCESS_DB, 0 );
  555. CheckDlgButton( hWnd, IDC_MSSQL_DB, 0 );
  556. CheckDlgButton( hWnd, IDC_MYSQL_DB, 1 );
  557. // Enable dialog boxes
  558. EnableWindow( hWndDBIP, TRUE );
  559. EnableWindow( hWndDBNAME, TRUE );
  560. EnableWindow( hWndDBUSER, TRUE );
  561. EnableWindow( hWndDBPASSWORD, TRUE );
  562. break;
  563. }
  564. }
  565. }
  566. else
  567. {
  568. // DBType = Default -- MySQL db
  569. CheckDlgButton( hWnd, IDC_ACCESS_DB, 0 );
  570. CheckDlgButton( hWnd, IDC_MSSQL_DB, 0 );
  571. CheckDlgButton( hWnd, IDC_MYSQL_DB, 1 );
  572. }
  573. dwLength = sizeof( g_szDBIP );
  574. if ( ( RegQueryValueEx( hKey, "DBIP", NULL, &dwType, (BYTE*)&g_szDBIP, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
  575. SetDlgItemText( hWnd, IDC_DBIP, g_szDBIP );
  576. else
  577. SetDlgItemText( hWnd, IDC_DBIP, "0.0.0.0" );
  578. dwLength = sizeof( g_szDBNAME );
  579. if ( ( RegQueryValueEx( hKey, "DBNAME", NULL, &dwType, (BYTE*)&g_szDBNAME, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
  580. SetDlgItemText( hWnd, IDC_DBNAME, g_szDBNAME );
  581. else
  582. SetDlgItemText( hWnd, IDC_DBNAME, "uas2" );
  583. dwLength = sizeof( g_szDBUSER );
  584. if ( ( RegQueryValueEx( hKey, "DBUSER", NULL, &dwType, (BYTE*)&g_szDBUSER, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
  585. SetDlgItemText( hWnd, IDC_DBUSER, g_szDBUSER );
  586. else
  587. SetDlgItemText( hWnd, IDC_DBUSER, "uas2" );
  588. dwLength = sizeof( g_szDBPASSWORD );
  589. if ( ( RegQueryValueEx( hKey, "DBPASSWORD", NULL, &dwType, (BYTE*)&g_szDBPASSWORD, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
  590. SetDlgItemText( hWnd, IDC_DBPASSWORD, g_szDBPASSWORD );
  591. else
  592. SetDlgItemText( hWnd, IDC_DBPASSWORD, "" );
  593. //////////////////////////////////////////////////////////////////
  594. // Local IP
  595. dwLength = sizeof( g_szLocalIP );
  596. if ( ( RegQueryValueEx( hKey, "LocalIP", NULL, &dwType, (BYTE*)&g_szLocalIP, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
  597. SetDlgItemText( hWnd, IDC_LOCALIP, g_szLocalIP );
  598. else
  599. {
  600. char szLocalHostName[80];
  601. DWORD dwSize = sizeof( szLocalHostName );
  602. if ( GetLocalAddress( szLocalHostName, &dwSize ) == 0 )
  603. SetDlgItemText( hWnd, IDC_LOCALIP, szLocalHostName );
  604. else
  605. SetDlgItemText( hWnd, IDC_LOCALIP, "127.0.0.1" );
  606. }
  607. // Access Database
  608. char szDirBuff[MAX_PATH+1];
  609. dwLength = sizeof( cWorldManager::g_szAccessFile );
  610. if ( ( RegQueryValueEx( hKey, "ACCESSMDB", NULL, &dwType, (BYTE*)&cWorldManager::g_szAccessFile, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
  611. {
  612. SetDlgItemText( hWnd, IDC_ACCESS_FILE, cWorldManager::g_szAccessFile );
  613. }
  614. else
  615. {
  616. int index = GetCurrentDirectory(MAX_PATH, szDirBuff);
  617. sprintf(cWorldManager::g_szAccessFile,"%s\\UAS2.mdb", szDirBuff );
  618. SetDlgItemText( hWnd, IDC_ACCESS_FILE,cWorldManager::g_szAccessFile );
  619. }
  620. RegCloseKey( hKey );
  621. hWndStart = GetDlgItem( hWnd, IDB_START );
  622. hWndClearObjs = GetDlgItem( hWnd, IDB_CLEAROBJECTS );
  623. hWndDiscAll = GetDlgItem( hWnd, IDB_DISC_ALL );
  624. hWndExit = GetDlgItem( hWnd, IDB_EXIT );
  625. /////// Server Status Data ///////////////////////////////////////////////
  626. char szPort[5];
  627. char szTempIP[16];
  628. SOCKADDR_IN saServer;
  629. GetDlgItemText( hWnd, IDC_LOCALIP, szTempIP, sizeof( szTempIP ) );
  630. saServer.sin_addr.s_addr = inet_addr( szTempIP );
  631. cMasterServer::cStatus->m_bServer[0] = saServer.sin_addr.S_un.S_un_b.s_b1;
  632. cMasterServer::cStatus->m_bServer[1] = saServer.sin_addr.S_un.S_un_b.s_b2;
  633. cMasterServer::cStatus->m_bServer[2] = saServer.sin_addr.S_un.S_un_b.s_b3;
  634. cMasterServer::cStatus->m_bServer[3] = saServer.sin_addr.S_un.S_un_b.s_b4;
  635. GetDlgItemText( hWnd, IDC_CHARPORT, szPort, sizeof( szPort ) );
  636. cMasterServer::cStatus->m_ServerPort = atoi( szPort );
  637. ///////////////////////////////////////////////////////////////////////////
  638. MoveWindow( hWnd,0 , 0 , CONSOLE_WIDTH_NORM ,CONSOLE_HEIGHT_NORM , TRUE );
  639. cMasterServer::cStatus->ServerLoad();
  640. break; // case WM_INITDIALOG
  641. }
  642. case WM_GETMINMAXINFO:
  643. {
  644. LPMINMAXINFO( lParam )->ptMinTrackSize.x = 340;
  645. LPMINMAXINFO( lParam )->ptMinTrackSize.y = CONSOLE_HEIGHT_NORM;//150
  646. break; // case WM_GETMINMAXINFO
  647. }
  648. case WM_SIZE:
  649. {
  650. MoveWindow( g_hWndConsole, 8, 95, LOWORD( lParam ) - 15, HIWORD( lParam ) - 100, TRUE );
  651. if( wParam == SIZE_MINIMIZED )
  652. {
  653. SystrayAdd( hWnd );
  654. ShowWindow( hWnd, SW_HIDE );
  655. fMinimized = TRUE;
  656. }
  657. else if( wParam == SIZE_RESTORED )
  658. {
  659. SystrayDelete( hWnd );
  660. fMinimized = FALSE;
  661. }
  662. break; // case WM_SIZE
  663. }
  664. case WM_NOTIFY:
  665. {
  666. break; // case WM_NOTIFY
  667. }
  668. case WM_COMMAND:
  669. {
  670. switch ( GET_WM_COMMAND_ID( wParam, lParam ) )
  671. {
  672. case IDC_LOCALIP:
  673. {
  674. UpdateHelpTitle( "Local IP:\r\n");
  675. UpdateHelp( "The IP address or DNS name of the hosting server. The default value is the IP address 127.0.0.1 (the loopback IP address).\r\n");
  676. break;
  677. }
  678. case IDC_SERVER:
  679. {
  680. UpdateHelpTitle( "Private Server Checkbox:\r\n");
  681. UpdateHelp( "When checked, server will not send updates to the status website. The option does not affect how the server operates.\r\n");
  682. break;
  683. }
  684. case IDC_CHARPORT:
  685. {
  686. UpdateHelpTitle( "Character Server Port:\r\n");
  687. UpdateHelp( "The number of the TCP or UDP port used to connect to the Character Server. The default value is 9002.\r\n");
  688. break;
  689. }
  690. case IDC_MAX_USERS:
  691. {
  692. UpdateHelpTitle( "Maximum Clients:\r\n");
  693. UpdateHelp( "The maximum number of clients the server allows. Not implemented.\r\n");
  694. break;
  695. }
  696. case IDC_WORLDPORT:
  697. {
  698. UpdateHelpTitle( "World Server Port:\r\n");
  699. UpdateHelp( "The number of the TCP or UDP port used to connect to the World Server. The default value is 9004.\r\n");
  700. break;
  701. }
  702. case IDC_ED_SNAME:
  703. {
  704. UpdateHelpTitle( "World Name:\r\n");
  705. UpdateHelp( "The name used to identify the world hosted by this server. Appears in the MOTD during login process.\r\n");
  706. break;
  707. }
  708. case IDC_ACCESS_FILE:
  709. {
  710. UpdateHelpTitle( "Microsoft Access File:\r\n");
  711. UpdateHelp( "The full path to the UAS2 Microsoft Access (.mdb) database file. The default path is the working directory.\r\n");
  712. break;
  713. }
  714. case IDC_DBIP:
  715. {
  716. UpdateHelpTitle( "Database IP:\r\n");
  717. UpdateHelp( "The IP address of the database server. The value must be an IP address and not a DNS name.\r\n");
  718. break;
  719. }
  720. case IDC_DBNAME:
  721. {
  722. UpdateHelpTitle( "Database Name:\r\n");
  723. UpdateHelp( "The name of the UAS2 database.\r\n");
  724. break;
  725. }
  726. case IDC_DBUSER:
  727. {
  728. UpdateHelpTitle( "Database User:\r\n");
  729. UpdateHelp( "A username with permission to access the database.\r\n");
  730. break;
  731. }
  732. case IDC_DBPASSWORD:
  733. {
  734. UpdateHelpTitle( "Database Password:\r\n");
  735. UpdateHelp( "The password for the corresponding username.\r\n");
  736. break;
  737. }
  738. case IDC_ED_HOST:
  739. {
  740. UpdateHelpTitle( "State Website Host:\r\n");
  741. UpdateHelp( "The IP address or DNS name of the website hosting the server status pages.\r\n");
  742. break;
  743. }
  744. case IDC_ED_URL:
  745. {
  746. UpdateHelpTitle( "URL Path:\r\n");
  747. UpdateHelp( "The URL path to the server status webpage. Must start with '/' and end with '/'.\r\n");
  748. break;
  749. }
  750. case IDC_ED_PORT:
  751. {
  752. UpdateHelpTitle( "Access Port:\r\n");
  753. UpdateHelp( "The number of the TCP or UDP port used to access the server status website. The default port number is 80 (HTTP).\r\n");
  754. break;
  755. }
  756. case IDC_ED_ID:
  757. {
  758. UpdateHelpTitle( "Server ID:\r\n");
  759. UpdateHelp( "The server ID for the server status listing. Supplied by the host website during registration.\r\n");
  760. break;
  761. }
  762. case IDC_ED_KEY:
  763. {
  764. UpdateHelpTitle( "Key ID:\r\n");
  765. UpdateHelp( "The key ID for the server status listing. Supplied by the host website during registration.\r\n");
  766. break;
  767. }
  768. case IDC_ED_CLIENT:
  769. {
  770. UpdateHelpTitle( "Client Version:\r\n");
  771. UpdateHelp( "Specifies which client(s) are supported with this server. Supplied by the host website during registration.\r\n");
  772. break;
  773. }
  774. case IDC_ED_SERIAL:
  775. {
  776. UpdateHelpTitle( "Serial Code:\r\n");
  777. UpdateHelp( "The serial code for your server to use when connecting to the server status host website. Supplied by the host website during registration.\r\n");
  778. break;
  779. }
  780. case IDC_WBBOX:
  781. {
  782. UpdateHelpTitle( "World Broadcast:\r\n");
  783. UpdateHelp( "A message that may be sent to all users presently connected to the world.\r\n");
  784. break;
  785. }
  786. case IDB_EXIT:
  787. {
  788. UpdateConsole( "\r\n Exiting server. Please wait ...\r\n" );
  789. cMasterServer::cStatus->ServerOffline();
  790. PostMessage( hWnd, WM_CLOSE, 0, 0 );
  791. EnableWindow( hWndExit, FALSE );
  792. break; // case IDB_EXIT
  793. }
  794. case IDB_CLEAROBJECTS:
  795. if ( g_fStarted )
  796. {
  797. cMasterServer::ClearAllObjects( );
  798. UpdateConsole( " All spawned objects cleared!\r\n" );
  799. break;
  800. }
  801. break;
  802. case IDB_DISC_ALL:
  803. {
  804. if( g_fStarted )
  805. {
  806. cMasterServer::DisconnectAllClients( );
  807. UpdateConsole( " All clients disconnected!\r\n" );
  808. break;
  809. }
  810. break;
  811. }
  812. //Karki
  813. case IDC_WB:
  814. if ( g_fStarted )
  815. {
  816. UpdateConsole( " World broadcast sent!\r\n" );
  817. char szWBTemp[255];
  818. GetDlgItemText( hWnd, IDC_WBBOX, szWBTemp, sizeof( szWBTemp ) );
  819. cMasterServer::ServerMessage( ColorGreen, NULL, "%s", szWBTemp );
  820. }
  821. break;
  822. case IDB_START:
  823. {
  824. if ( g_fStarted )
  825. {
  826. EnableWindow( hWndStart, FALSE );
  827. EnableWindow( hWndClearObjs, FALSE );
  828. EnableWindow( hWndDiscAll, FALSE );
  829. g_fStarted = !cMasterServer::Unload( );
  830. if( ( fExit ) && ( !g_fStarted ) )
  831. {
  832. SystrayDelete( hWnd );
  833. DestroyWindow( hWnd );
  834. PostQuitMessage( 0 );
  835. }
  836. SetWindowText( hWndStart, "&Start Server" );
  837. EnableWindow( hWndStart, TRUE );
  838. }
  839. else
  840. {
  841. g_fStarted = TRUE;
  842. char szTemp[5];
  843. GetDlgItemText( hWnd, IDC_LOCALIP, g_szLocalIP, sizeof( g_szLocalIP ) );
  844. GetDlgItemText( hWnd, IDC_DBTYPE, szTemp, sizeof( szTemp ) );
  845. g_DBType = szTemp[0] - 0x30;
  846. GetDlgItemText( hWnd, IDC_DBIP, g_szDBIP, sizeof( g_szDBIP ) );
  847. GetDlgItemText( hWnd, IDC_DBNAME, g_szDBNAME, sizeof( g_szDBNAME ) );
  848. GetDlgItemText( hWnd, IDC_DBUSER, g_szDBUSER, sizeof( g_szDBUSER ) );
  849. GetDlgItemText( hWnd, IDC_DBPASSWORD, g_szDBPASSWORD, sizeof( g_szDBPASSWORD ) );
  850. GetDlgItemText( hWnd, IDC_ACCESS_FILE, cWorldManager::g_szAccessFile, sizeof( cWorldManager::g_szAccessFile ) );
  851. SetDlgItemText( hWnd, IDB_START, "&Stop Server");
  852. GetDlgItemText( hWnd, IDC_CHARPORT, szTemp, sizeof( szTemp ) );
  853. g_nCharPort = atoi( szTemp );
  854. GetDlgItemText( hWnd, IDC_WORLDPORT, szTemp, sizeof( szTemp ) );
  855. g_nWorldPort = atoi( szTemp );
  856. cDatabase::SetupDB(g_DBType,g_szDBIP,g_szDBNAME,g_szDBUSER,g_szDBPASSWORD);
  857. cMasterServer::Load( );
  858. EnableWindow( hWndClearObjs, TRUE );
  859. EnableWindow( hWndDiscAll, TRUE );
  860. }
  861. break; // case IDB_START
  862. }
  863. case ID_SYSTRAY_ACE:
  864. {
  865. ShowWindow( hWnd, SW_RESTORE );
  866. SetForegroundWindow( hWnd );
  867. SendMessage( hWnd, WM_ACTIVATEAPP, ( WPARAM )TRUE, ( LPARAM )NULL );
  868. break;
  869. }
  870. case ID_SYSTRAY_EXIT:
  871. {
  872. PostMessage( hWnd, WM_CLOSE, 0, 0 );
  873. break;
  874. }
  875. case IDC_CONFIG:
  876. {
  877. if(g_fConfig == FALSE)
  878. {
  879. UpdateHelpTitle("Configuration Settings:\r\n");
  880. UpdateHelp("Changes will not take effect until the server program is restarted.\r\n");
  881. MoveWindow( hWnd,0 , 0 , CONSOLE_WIDTH_OPT ,CONSOLE_HEIGHT_OPT , TRUE );
  882. ShowWindow( hWndDBIP, SW_SHOW );
  883. ShowWindow( hWndDBNAME, SW_SHOW );
  884. ShowWindow( hWndDBUSER, SW_SHOW );
  885. ShowWindow( hWndDBPASSWORD, SW_SHOW );
  886. ShowWindow( hWndACCESSFILE, SW_SHOW );
  887. ShowWindow( hWndPrivate, SW_SHOW );
  888. SetWindowText( hWndCONFIG, "Status" );
  889. for(int i = 0; i< 30;i++)
  890. {
  891. ShowWindow( hWndSettings[i], SW_SHOW );
  892. }
  893. ShowWindow( g_hWndConsole, SW_HIDE );
  894. g_fConfig = TRUE;
  895. }
  896. else
  897. {
  898. MoveWindow( hWnd,0 , 0 , CONSOLE_WIDTH_NORM ,CONSOLE_HEIGHT_NORM , TRUE );
  899. ShowWindow( hWndDBIP, SW_HIDE );
  900. ShowWindow( hWndDBNAME, SW_HIDE );
  901. ShowWindow( hWndDBUSER, SW_HIDE );
  902. ShowWindow( hWndDBPASSWORD, SW_HIDE );
  903. ShowWindow( hWndACCESSFILE, SW_HIDE );
  904. ShowWindow( hWndPrivate, SW_HIDE );
  905. SetWindowText( hWndCONFIG, "Settings" );
  906. for(int i = 0; i< 30;i++)
  907. {
  908. ShowWindow( hWndSettings[i], SW_HIDE );
  909. }
  910. ShowWindow( g_hWndConsole, SW_SHOW );
  911. g_fConfig = FALSE;
  912. }
  913. break;
  914. }
  915. case IDC_ACCESS_DB:
  916. {
  917. // Disable Dialog boxes
  918. EnableWindow( hWndDBIP, FALSE );
  919. EnableWindow( hWndDBNAME, FALSE );
  920. EnableWindow( hWndDBUSER, FALSE );
  921. EnableWindow( hWndDBPASSWORD, FALSE );
  922. EnableWindow( hWndACCESSFILE, TRUE );
  923. CheckDlgButton( hWnd, IDC_ACCESS_DB, 1 );
  924. CheckDlgButton( hWnd, IDC_MSSQL_DB, 0 );
  925. CheckDlgButton( hWnd, IDC_MYSQL_DB, 0 );
  926. SetDlgItemText( hWnd, IDC_DBTYPE, "1" );
  927. UpdateHelpTitle( "Microsoft Access:\r\n");
  928. UpdateHelp( "A relational database management system supported by the server. Requires the use of a Microsoft Access (.mdb) database file.\r\n");
  929. break;
  930. }
  931. case IDC_MSSQL_DB:
  932. {
  933. // Enable Dialog boxes
  934. EnableWindow( hWndDBIP, TRUE );
  935. EnableWindow( hWndDBNAME, TRUE );
  936. EnableWindow( hWndDBUSER, TRUE );
  937. EnableWindow( hWndDBPASSWORD, TRUE );
  938. EnableWindow( hWndACCESSFILE, FALSE );
  939. CheckDlgButton( hWnd, IDC_ACCESS_DB, 0 );
  940. CheckDlgButton( hWnd, IDC_MSSQL_DB, 1 );
  941. CheckDlgButton( hWnd, IDC_MYSQL_DB, 0 );
  942. SetDlgItemText( hWnd, IDC_DBTYPE, "2" );
  943. UpdateHelpTitle( "MS SQL:\r\n");
  944. UpdateHelp( "A relational database management system supported by the server. Requires access to an MS SQL database.\r\n");
  945. break;
  946. }
  947. case IDC_MYSQL_DB:
  948. {
  949. // Enable Dialog boxes
  950. EnableWindow( hWndDBIP, TRUE );
  951. EnableWindow( hWndDBNAME, TRUE );
  952. EnableWindow( hWndDBUSER, TRUE );
  953. EnableWindow( hWndDBPASSWORD, TRUE );
  954. EnableWindow( hWndACCESSFILE, FALSE );
  955. CheckDlgButton( hWnd, IDC_ACCESS_DB, 0 );
  956. CheckDlgButton( hWnd, IDC_MSSQL_DB, 0 );
  957. CheckDlgButton( hWnd, IDC_MYSQL_DB, 1 );
  958. SetDlgItemText( hWnd, IDC_DBTYPE, "3" );
  959. UpdateHelpTitle( "MySQL:\r\n");
  960. UpdateHelp( "A relational database management system supported by the server. Requires access to a MySQL database.\r\n");
  961. break;
  962. }
  963. case IDC_BTN_UPDATE:
  964. {
  965. char szTemp[5];
  966. char szDBType[2];
  967. char szDBTemp[20];
  968. HKEY hKey;
  969. RegCreateKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\UAS", NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
  970. GetDlgItemText( hWnd, IDC_LOCALIP, g_szLocalIP, sizeof( g_szLocalIP ) );
  971. RegSetValueEx( hKey, "LocalIP", NULL, REG_SZ, (BYTE*)g_szLocalIP, lstrlen( g_szLocalIP ) );
  972. GetDlgItemText( hWnd, IDC_CHARPORT, szTemp, sizeof( szTemp ) );
  973. RegSetValueEx( hKey, "CharPort", NULL, REG_SZ, (BYTE*)szTemp, lstrlen( szTemp ) );
  974. GetDlgItemText( hWnd, IDC_WORLDPORT, szTemp, sizeof( szTemp ) );
  975. RegSetValueEx( hKey, "WorldPort", NULL, REG_SZ, (BYTE*)szTemp, lstrlen( szTemp ) );
  976. // Database Settings //////////////////////////////////////////////////////////////
  977. GetDlgItemText( hWnd, IDC_DBTYPE, szDBType, sizeof( szDBType ) );
  978. RegSetValueEx( hKey, "DBTYPE", NULL, REG_SZ, (BYTE*)szDBType, lstrlen( szDBType ) );
  979. GetDlgItemText( hWnd, IDC_DBIP, szDBTemp, sizeof( szDBTemp ) );
  980. RegSetValueEx( hKey, "DBIP", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
  981. GetDlgItemText( hWnd, IDC_DBNAME, szDBTemp, sizeof( szDBTemp ) );
  982. RegSetValueEx( hKey, "DBNAME", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
  983. GetDlgItemText( hWnd, IDC_DBUSER, szDBTemp, sizeof( szDBTemp ) );
  984. RegSetValueEx( hKey, "DBUSER", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
  985. GetDlgItemText( hWnd, IDC_DBPASSWORD, szDBTemp, sizeof( szDBTemp ) );
  986. RegSetValueEx( hKey, "DBPASSWORD", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
  987. char szAccessTemp[MAX_PATH+20];
  988. GetDlgItemText( hWnd, IDC_ACCESS_FILE, szAccessTemp, sizeof( szAccessTemp ) );
  989. RegSetValueEx( hKey, "ACCESSMDB", NULL, REG_SZ, (BYTE*)szAccessTemp, lstrlen( szAccessTemp ) );
  990. ///////////////////////////////////////////////////////////////////////////////////
  991. // Status Server Settings
  992. char szHostTemp[64];
  993. int nState;
  994. nState = IsDlgButtonChecked( hWnd, IDC_SERVER);
  995. sprintf(szDBTemp,"%d",nState);
  996. RegSetValueEx( hKey, "Private", NULL, REG_SZ, (BYTE*)szDBTemp, sizeof(szDBTemp) );
  997. GetDlgItemText( hWnd, IDC_ED_HOST, szHostTemp, sizeof( szHostTemp ) );
  998. RegSetValueEx( hKey, "Status Host", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
  999. GetDlgItemText( hWnd, IDC_ED_PORT, szDBTemp, sizeof( szDBTemp ) );
  1000. RegSetValueEx( hKey, "HTTP Port", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
  1001. GetDlgItemText( hWnd, IDC_ED_ID, szDBTemp, sizeof( szDBTemp ) );
  1002. RegSetValueEx( hKey, "Server ID", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
  1003. GetDlgItemText( hWnd, IDC_ED_SNAME, szHostTemp, sizeof( szHostTemp ) );
  1004. RegSetValueEx( hKey, "Server Name", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
  1005. memcpy(cMasterServer::m_szServerName,szHostTemp,sizeof(szHostTemp));
  1006. GetDlgItemText( hWnd, IDC_ED_SERIAL, szHostTemp, sizeof( szHostTemp ) );
  1007. RegSetValueEx( hKey, "Server Serial", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
  1008. GetDlgItemText( hWnd, IDC_ED_KEY, szHostTemp, sizeof( szHostTemp ) );
  1009. RegSetValueEx( hKey, "Server Key", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
  1010. GetDlgItemText( hWnd, IDC_ED_URL, szHostTemp, sizeof( szHostTemp ) );
  1011. RegSetValueEx( hKey, "HTTP Path", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
  1012. GetDlgItemText( hWnd, IDC_ED_CLIENT, szHostTemp, sizeof( szHostTemp ) );
  1013. RegSetValueEx( hKey, "Client Support", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
  1014. GetDlgItemText( hWnd, IDC_MAX_USERS, szHostTemp, sizeof( szHostTemp ) );
  1015. RegSetValueEx( hKey, "Max Clients", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
  1016. /////////////////////////////////////////////////////////////////////////////////////
  1017. RegCloseKey( hKey );
  1018. break;
  1019. }
  1020. default:
  1021. break; // case default
  1022. }
  1023. break; // case WM_COMMAND
  1024. }
  1025. case MYWM_NOTIFYICON:
  1026. {
  1027. switch (lParam)
  1028. {
  1029. case WM_LBUTTONDOWN:
  1030. {
  1031. ShowWindow( hWnd, SW_RESTORE );
  1032. SetForegroundWindow( hWnd );
  1033. SendMessage( hWnd, WM_ACTIVATEAPP, ( WPARAM )TRUE, ( LPARAM )NULL );
  1034. break;
  1035. }
  1036. case WM_RBUTTONUP:
  1037. {
  1038. HMENU hTrayMenu;
  1039. HMENU hMenu;
  1040. POINT point;
  1041. SetForegroundWindow( hWnd );
  1042. hTrayMenu = LoadMenu( g_hInstance, MAKEINTRESOURCE( ID_SYSTRAY ) );
  1043. hMenu = GetSubMenu( hTrayMenu, 0 );
  1044. GetCursorPos( &point );
  1045. TrackPopupMenu( hMenu, TPM_RIGHTBUTTON, point.x, point.y, 0, hWnd, NULL );
  1046. DestroyMenu( hMenu );
  1047. DestroyMenu( hTrayMenu );
  1048. PostMessage( hWnd, WM_NULL, 0, 0 );
  1049. break;
  1050. }
  1051. }
  1052. break;
  1053. }
  1054. case WM_CLOSE:
  1055. {
  1056. char szTemp[5];
  1057. HKEY hKey;
  1058. RegCreateKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\UAS", NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
  1059. GetDlgItemText( hWnd, IDC_LOCALIP, g_szLocalIP, sizeof( g_szLocalIP ) );
  1060. RegSetValueEx( hKey, "LocalIP", NULL, REG_SZ, (BYTE*)g_szLocalIP, lstrlen( g_szLocalIP ) );
  1061. GetDlgItemText( hWnd, IDC_CHARPORT, szTemp, sizeof( szTemp ) );
  1062. RegSetValueEx( hKey, "CharPort", NULL, REG_SZ, (BYTE*)szTemp, lstrlen( szTemp ) );
  1063. GetDlgItemText( hWnd, IDC_WORLDPORT, szTemp, sizeof( szTemp ) );
  1064. RegSetValueEx( hKey, "WorldPort", NULL, REG_SZ, (BYTE*)szTemp, lstrlen( szTemp ) );
  1065. // Database Settings //////////////////////////////////////////////////////////////
  1066. char szDBType[2];
  1067. char szDBTemp[20];
  1068. GetDlgItemText( hWnd, IDC_DBTYPE, szDBType, sizeof( szDBType ) );
  1069. RegSetValueEx( hKey, "DBTYPE", NULL, REG_SZ, (BYTE*)szDBType, lstrlen( szDBType ) );
  1070. GetDlgItemText( hWnd, IDC_DBIP, szDBTemp, sizeof( szDBTemp ) );
  1071. RegSetValueEx( hKey, "DBIP", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
  1072. GetDlgItemText( hWnd, IDC_DBNAME, szDBTemp, sizeof( szDBTemp ) );
  1073. RegSetValueEx( hKey, "DBNAME", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
  1074. GetDlgItemText( hWnd, IDC_DBUSER, szDBTemp, sizeof( szDBTemp ) );
  1075. RegSetValueEx( hKey, "DBUSER", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
  1076. GetDlgItemText( hWnd, IDC_DBPASSWORD, szDBTemp, sizeof( szDBTemp ) );
  1077. RegSetValueEx( hKey, "DBPASSWORD", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
  1078. char szAccessTemp[MAX_PATH+20];
  1079. GetDlgItemText( hWnd, IDC_ACCESS_FILE, szAccessTemp, sizeof( szAccessTemp ) );
  1080. RegSetValueEx( hKey, "ACCESSMDB", NULL, REG_SZ, (BYTE*)szAccessTemp, lstrlen( szAccessTemp ) );
  1081. ///////////////////////////////////////////////////////////////////////////////////
  1082. // Status Server Settings
  1083. char szHostTemp[64];
  1084. int nState;
  1085. nState = IsDlgButtonChecked( hWnd, IDC_SERVER);
  1086. sprintf(szDBTemp,"%d",nState);
  1087. RegSetValueEx( hKey, "Private", NULL, REG_SZ, (BYTE*)szDBTemp, sizeof(szDBTemp) );
  1088. GetDlgItemText( hWnd, IDC_ED_HOST, szHostTemp, sizeof( szHostTemp ) );
  1089. RegSetValueEx( hKey, "Status Host", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
  1090. GetDlgItemText( hWnd, IDC_ED_PORT, szDBTemp, sizeof( szDBTemp ) );
  1091. RegSetValueEx( hKey, "HTTP Port", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
  1092. GetDlgItemText( hWnd, IDC_ED_ID, szDBTemp, sizeof( szDBTemp ) );
  1093. RegSetValueEx( hKey, "Server ID", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
  1094. GetDlgItemText( hWnd, IDC_ED_SNAME, szHostTemp, sizeof( szHostTemp ) );
  1095. RegSetValueEx( hKey, "Server Name", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
  1096. GetDlgItemText( hWnd, IDC_ED_SERIAL, szHostTemp, sizeof( szHostTemp ) );
  1097. RegSetValueEx( hKey, "Server Serial", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
  1098. GetDlgItemText( hWnd, IDC_ED_KEY, szHostTemp, sizeof( szHostTemp ) );
  1099. RegSetValueEx( hKey, "Server Key", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
  1100. GetDlgItemText( hWnd, IDC_ED_URL, szHostTemp, sizeof( szHostTemp ) );
  1101. RegSetValueEx( hKey, "HTTP Path", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
  1102. GetDlgItemText( hWnd, IDC_ED_CLIENT, szHostTemp, sizeof( szHostTemp ) );
  1103. RegSetValueEx( hKey, "Client Support", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
  1104. GetDlgItemText( hWnd, IDC_MAX_USERS, szHostTemp, sizeof( szHostTemp ) );
  1105. RegSetValueEx( hKey, "Max Clients", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
  1106. /////////////////////////////////////////////////////////////////////////////////////
  1107. RegCloseKey( hKey );
  1108. if ( g_fStarted )
  1109. {
  1110. fExit = TRUE;
  1111. SendMessage( hWnd, WM_COMMAND, IDB_START, TRUE );
  1112. }
  1113. else
  1114. {
  1115. WSACleanup();
  1116. SystrayDelete( hWnd );
  1117. DestroyWindow( hWnd );
  1118. PostQuitMessage( 0 );
  1119. }
  1120. break; // case WM_CLOSE
  1121. }
  1122. default:
  1123. if( ( msg == s_uTaskbarRestart ) && ( fMinimized ) )
  1124. {
  1125. SystrayDelete( hWnd );
  1126. SystrayAdd( hWnd );
  1127. break;
  1128. }
  1129. }
  1130. return FALSE;
  1131. }
  1132. WORD g_wAvatarTexturesList[Race][Gender][TexType][TexIndex];
  1133. WORD g_wAvatarTexturesBaldList[Race][Gender][TexIndex];
  1134. void LoadAvatarTextureList()
  1135. {
  1136. char *pbuf;
  1137. DWORD dwSize;
  1138. HRSRC hRSRC;
  1139. HGLOBAL hGlobal;
  1140. hRSRC = FindResource( g_hInstance, MAKEINTRESOURCE( IDR_BINDATA ), "BINARY" );
  1141. if( hRSRC == NULL )
  1142. UpdateConsole( " FindResource", GetLastError( ) );
  1143. dwSize = SizeofResource( g_hInstance, hRSRC );
  1144. hGlobal = LoadResource( g_hInstance, hRSRC );
  1145. if( hGlobal == NULL )
  1146. UpdateConsole( " LoadResource", GetLastError( ) );
  1147. pbuf = (char*)LockResource( hGlobal );
  1148. if( pbuf == NULL )
  1149. UpdateConsole( " LockResource", GetLastError( ) );
  1150. CopyMemory(g_wAvatarTexturesList, pbuf, sizeof( g_wAvatarTexturesList ) );
  1151. CopyMemory(g_wAvatarTexturesBaldList, pbuf + sizeof( g_wAvatarTexturesList ), sizeof( g_wAvatarTexturesBaldList ) );
  1152. }
  1153. /**
  1154. * The entry point of the application.
  1155. *
  1156. * @param hInstance - Handle to the current instance of the application.
  1157. * @param hPrevInstance - Handle to the previous instance of the application (always NULL).
  1158. * @param lpCmdLine - Pointer to a null-terminated string specifying the command line for the application, excluding the program name.
  1159. * @param iCmdShow - Specifies how the window is to be shown.
  1160. */
  1161. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow )
  1162. {
  1163. g_hInstance = hInstance;
  1164. InitCommonControls( );
  1165. cDatabase::InitializeSQLEnvironment();
  1166. LoadAvatarTextureList();
  1167. g_hWndMain = CreateDialog( hInstance, MAKEINTRESOURCE( IDD_MAIN ), NULL, MainWindowProc );
  1168. if ( !g_hWndMain )
  1169. return -1;
  1170. g_fStarted = FALSE;
  1171. ShowWindow( g_hWndMain, iCmdShow );
  1172. MSG msg;
  1173. while ( GetMessage( &msg, NULL, 0, 0 ) )
  1174. {
  1175. if( IsDialogMessage( g_hWndMain, &msg ) )
  1176. continue;
  1177. TranslateMessage( &msg );
  1178. DispatchMessage( &msg );
  1179. }
  1180. WSACleanup( );
  1181. cDatabase::FreeSQLEnvironment();
  1182. return msg.wParam;
  1183. }