INTERNET.CPP 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /*************************************************************************************
  15. ** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S **
  16. *************************************************************************************
  17. * *
  18. * Project Name : Command & Conquer - Red Alert *
  19. * *
  20. * File Name : INTERNET.CPP *
  21. * *
  22. * Programmer : Steve Tall *
  23. * *
  24. * Start Date : March 11th, 1996 *
  25. * *
  26. * Last Update : August 5th, 1996 [ST] *
  27. * *
  28. *-----------------------------------------------------------------------------------*
  29. * Overview: *
  30. * *
  31. * Miscellaneous junk related to H2H internet connection. *
  32. * *
  33. *-----------------------------------------------------------------------------------*
  34. * Functions: *
  35. * Check_From_WChat -- Interprets start game packet from WChat *
  36. * Read_Game_Options -- Read the game setup options from the wchat packet *
  37. * Is_User_WChat_Registered -- retrieve the users wchat entry from registry *
  38. * Spawn_WChat -- spawns or switches focus to wchat *
  39. * Spawn_Registration_App -- spawns the C&C/Planet westwood registration app *
  40. * Do_The_Internet_Menu_Thang -- Handle case where user clicks on 'Internet' button *
  41. * *
  42. * *
  43. * *
  44. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  45. #include "function.h"
  46. #include "tcpip.h"
  47. #include "ccdde.h"
  48. /***************************************************************************
  49. ** Internet specific globals
  50. */
  51. char PlanetWestwoodHandle[] = {"Handle"}; //Planet WW user name
  52. char PlanetWestwoodPassword[] = {"Password"}; //Planet WW password
  53. char PlanetWestwoodIPAddress[IP_ADDRESS_MAX] = {"206.154.108.87"}; //IP of server or other player
  54. long PlanetWestwoodPortNumber = 1234; //Port number to send to
  55. bool PlanetWestwoodIsHost = false; //Flag true if player has control of game options
  56. unsigned long PlanetWestwoodGameID; //Game ID
  57. unsigned long PlanetWestwoodStartTime; //Time that game was started
  58. HWND WChatHWND = 0; //Handle to Wchat window.
  59. bool UseVirtualSubnetServer;
  60. int InternetMaxPlayers;
  61. int WChatMaxAhead;
  62. int WChatSendRate;
  63. int Read_Game_Options(void);
  64. extern bool SpawnedFromWChat;
  65. /***********************************************************************************************
  66. * Check_From_WChat -- This function reads in C&CSPAWN.INI and interprets it *
  67. * C&CSPAWN.INI is now sent to us by WCHAT via DDE *
  68. * *
  69. * *
  70. * *
  71. * INPUT: Name of C&CSPAWN.INI file. If NULL then get file from DDE Server *
  72. * *
  73. * OUTPUT: Nothing *
  74. * *
  75. * WARNINGS: None *
  76. * *
  77. * HISTORY: *
  78. * 6/9/96 1:44PM ST : Created *
  79. *=============================================================================================*/
  80. void Check_From_WChat(char *wchat_name)
  81. {
  82. #ifndef DEMO
  83. char default_string[] = {"Error"};
  84. char key_string[256];
  85. char *ini_file;
  86. RawFileClass wchat_file;
  87. /*
  88. ** Get a pointer to C&CSPAWN.INI either by reading it from disk or getting it from
  89. ** the DDE server.
  90. */
  91. if (wchat_name){
  92. ini_file = new char [8192];
  93. }else{
  94. ini_file = DDEServer.Get_MPlayer_Game_Info();
  95. #if (0)
  96. /*
  97. ** Save it to disk as well so I can see it
  98. */
  99. RawFileClass anotherfile ("FROMCHAT.TXT");
  100. anotherfile.Write(ini_file, DDEServer.Get_MPlayer_Game_Info_Length());
  101. #endif //(0)
  102. }
  103. if (wchat_name){
  104. wchat_file.Set_Name(wchat_name);
  105. }
  106. if (!wchat_name || wchat_file.Is_Available()){
  107. /*
  108. ** Read the ini file from disk if we founf it there
  109. */
  110. if (wchat_name){
  111. wchat_file.Read(ini_file, wchat_file.Size());
  112. }
  113. /*
  114. ** Get the IP address
  115. */
  116. key_string[0] = 0;
  117. WWGetPrivateProfileString("Internet",
  118. "Address",
  119. default_string,
  120. key_string,
  121. sizeof(key_string),
  122. ini_file);
  123. if (!strcmp (key_string, default_string)) {
  124. if (wchat_name) delete ini_file;
  125. return;
  126. }
  127. strcpy (PlanetWestwoodIPAddress, key_string);
  128. /*
  129. ** Get the port number
  130. */
  131. key_string[0] = 0;
  132. WWGetPrivateProfileString("Internet",
  133. "Port",
  134. default_string,
  135. key_string,
  136. sizeof(key_string),
  137. ini_file);
  138. if (!strcmp (key_string, default_string)) {
  139. if (wchat_name) delete ini_file;
  140. return;
  141. }
  142. PlanetWestwoodPortNumber = atol(key_string);
  143. /*
  144. ** Get host or client
  145. */
  146. key_string[0] = 0;
  147. WWGetPrivateProfileString("Internet",
  148. "Host",
  149. default_string,
  150. key_string,
  151. sizeof(key_string),
  152. ini_file);
  153. if (!strcmp (key_string, default_string)) {
  154. if (wchat_name) delete ini_file;
  155. return;
  156. }
  157. if (strchr (key_string, '1')){
  158. PlanetWestwoodIsHost = true;
  159. }else{
  160. PlanetWestwoodIsHost = false;
  161. }
  162. UseVirtualSubnetServer = WWGetPrivateProfileInt("Internet", "UseVSS", 0, ini_file);
  163. Special.IsFromWChat = true;
  164. }
  165. if (wchat_name) delete ini_file;
  166. #else //DEMO
  167. wchat_name = wchat_name;
  168. #endif //DEMO
  169. }
  170. //EventClass Wibble;
  171. /***************************************************************************
  172. * Read_Game_Options -- reads multiplayer game options from disk *
  173. * *
  174. * This routine is used for multiplayer games which read the game options *
  175. * from disk, rather than through a connection dialog. *
  176. * *
  177. * INPUT: *
  178. * name of C&CSPAWN.INI file. Null if data should be got from DDE server* *
  179. * OUTPUT: *
  180. * 1 = OK, 0 = error *
  181. * *
  182. * WARNINGS: \ *
  183. * none. *
  184. * *
  185. * HISTORY: *
  186. * 01/11/1996 BRR : Created. *
  187. *=========================================================================*/
  188. int Read_Game_Options(char *name)
  189. {
  190. char *buffer;
  191. char filename[256] = {"INVALID.123"};
  192. if (name){
  193. strcpy (filename, name);
  194. }
  195. /*------------------------------------------------------------------------
  196. Create filename and read the file.
  197. ------------------------------------------------------------------------*/
  198. CCFileClass file (filename);
  199. if (name && !file.Is_Available()) {
  200. return(0);
  201. } else {
  202. if (name){
  203. buffer = new char [8192]; // INI staging buffer pointer.
  204. memset(buffer, '\0', 8192);
  205. file.Read(buffer, 8192-1);
  206. file.Close();
  207. }else{
  208. buffer = DDEServer.Get_MPlayer_Game_Info();
  209. }
  210. }
  211. /*------------------------------------------------------------------------
  212. Get the player's name
  213. ------------------------------------------------------------------------*/
  214. WWGetPrivateProfileString("Options", "Handle", "Noname", MPlayerName,
  215. sizeof(MPlayerName), buffer);
  216. strcpy(MPlayerGameName, MPlayerName);
  217. MPlayerColorIdx = WWGetPrivateProfileInt("Options", "Color", 0, buffer);
  218. MPlayerPrefColor = MPlayerColorIdx;
  219. MPlayerHouse = (HousesType)WWGetPrivateProfileInt("Options", "Side",
  220. HOUSE_GOOD, buffer);
  221. MPlayerCredits = WWGetPrivateProfileInt("Options", "Credits", 0, buffer);
  222. MPlayerBases = WWGetPrivateProfileInt("Options", "Bases", 0, buffer);
  223. MPlayerTiberium = WWGetPrivateProfileInt("Options", "Tiberium", 0, buffer);
  224. MPlayerGoodies = WWGetPrivateProfileInt("Options", "Crates", 0, buffer);
  225. MPlayerGhosts = WWGetPrivateProfileInt("Options", "AI", 0, buffer);
  226. BuildLevel = WWGetPrivateProfileInt("Options", "BuildLevel", 0, buffer);
  227. MPlayerUnitCount = WWGetPrivateProfileInt("Options", "UnitCount", 0, buffer);
  228. Seed = WWGetPrivateProfileInt("Options", "Seed", 0, buffer);
  229. Special.IsCaptureTheFlag = WWGetPrivateProfileInt("Options", "CaptureTheFlag", 0, buffer);
  230. PlanetWestwoodGameID = WWGetPrivateProfileInt("Internet", "GameID", 0, buffer);
  231. PlanetWestwoodStartTime = WWGetPrivateProfileInt ("Internet", "StartTime", 0, buffer);
  232. WChatHWND = (HWND) WWGetPrivateProfileInt("Internet", "HWND", (int)FindWindow("OWL_Window", "Westwood Chat"), buffer);
  233. InternetMaxPlayers = WWGetPrivateProfileInt("Internet", "MaxPlayers", 2, buffer);
  234. if (MPlayerTiberium) {
  235. Special.IsTGrowth = 1;
  236. Special.IsTSpread = 1;
  237. } else {
  238. Special.IsTGrowth = 0;
  239. Special.IsTSpread = 0;
  240. }
  241. ScenarioIdx = WWGetPrivateProfileInt("Options", "Scenario", 0, buffer);
  242. Scenario = ScenarioIdx; //MPlayerFilenum[ScenarioIdx];
  243. Options.GameSpeed = 0;
  244. MPlayerLocalID = Build_MPlayerID (MPlayerColorIdx, MPlayerHouse);
  245. MPlayerMaxAhead = WChatMaxAhead = WWGetPrivateProfileInt("Timing", "MaxAhead", 9, buffer);
  246. FrameSendRate = WChatSendRate = WWGetPrivateProfileInt("Timing", "SendRate", 3, buffer);
  247. if (name) delete buffer;
  248. return (1);
  249. }
  250. /***********************************************************************************************
  251. * Get_Registry_Sub_Key -- search a registry key for a sub-key *
  252. * *
  253. * *
  254. * *
  255. * INPUT: handle of key to search *
  256. * text to search for *
  257. * true if old key should be closed when new key opened *
  258. * *
  259. * OUTPUT: handle to the key we found or 0 *
  260. * *
  261. * WARNINGS: None *
  262. * *
  263. * HISTORY: *
  264. * 1/12/96 2:11PM ST : Created *
  265. *=============================================================================================*/
  266. extern HKEY Get_Registry_Sub_Key (HKEY base_key, char *search_key, BOOL close);
  267. void Just_Path(char *path, char *destpath)
  268. {
  269. char *terminator = NULL; //He'll be back.
  270. strcpy (destpath, path);
  271. terminator = strrchr (destpath, '\\');
  272. if (terminator){
  273. *terminator = 0;
  274. }
  275. }
  276. /***********************************************************************************************
  277. * Is_User_WChat_Registered -- retrieve the users wchat entry from the registry *
  278. * *
  279. * *
  280. * *
  281. * INPUT: Nothing *
  282. * *
  283. * OUTPUT: TRUE if users wchat entry was found in the registry *
  284. * *
  285. * WARNINGS: None *
  286. * *
  287. * HISTORY: *
  288. * 1/12/96 2:13PM ST : Created *
  289. *=============================================================================================*/
  290. bool Is_User_WChat_Registered(char *buffer, int buffer_len)
  291. {
  292. buffer;
  293. buffer_len;
  294. return false;
  295. #if (0) //ST - 1/2/2019 5:54PM
  296. HKEY key;
  297. char user_handle[256];
  298. DWORD user_handle_size = sizeof (user_handle);
  299. char user_pword[256];
  300. DWORD user_pword_size = sizeof (user_pword);
  301. /*
  302. ** Check HKEY_CLASSES_ROOT first. Old versions of Wchat register there
  303. */
  304. key = Get_Registry_Sub_Key (HKEY_CLASSES_ROOT, "Wchat", FALSE);
  305. if (key){
  306. key = Get_Registry_Sub_Key (key, "Nick1", TRUE);
  307. if (key){
  308. if (RegQueryValue(key, "Nick", user_handle, (long*)&user_handle_size) == ERROR_SUCCESS){
  309. if (RegQueryValue(key, "Pass", user_pword, (long*)&user_pword_size) == ERROR_SUCCESS){
  310. /*
  311. ** If the first char of the users name is non-numberic and there is a password
  312. ** then return success
  313. */
  314. if ((user_handle[0] < '0' || user_handle[0] > '9') && user_pword[0]){
  315. RegCloseKey( key );
  316. return (TRUE);
  317. }
  318. }
  319. }
  320. }
  321. RegCloseKey ( key );
  322. }
  323. /*
  324. ** Check HKEY_LOCAL_MACKINE/Software
  325. */
  326. user_handle_size = sizeof (user_handle);
  327. key = Get_Registry_Sub_Key (HKEY_LOCAL_MACHINE, "SOFTWARE", FALSE);
  328. if (!key) return (FALSE);
  329. key = Get_Registry_Sub_Key (key, "Westwood", TRUE);
  330. if (!key) return (FALSE);
  331. key = Get_Registry_Sub_Key (key, "InetReg", TRUE);
  332. if (!key) return (FALSE);
  333. //key = Get_Registry_Sub_Key (key, "UserName", TRUE);
  334. //if (!key) return (FALSE);
  335. //key = Get_Registry_Sub_Key (key, "Nick", TRUE);
  336. //if (!key) return (FALSE);
  337. if (RegQueryValueEx(key, "UserName", NULL, NULL, (unsigned char*)user_handle, &user_handle_size) != ERROR_SUCCESS){
  338. RegCloseKey(key);
  339. return (FALSE);
  340. }
  341. RegCloseKey(key);
  342. memcpy (buffer, user_handle, min((unsigned)buffer_len, user_handle_size));
  343. /*
  344. ** If the first char of the users name is non-numeric then return success
  345. */
  346. if (user_handle[0] < '0' || user_handle[0] > '9'){
  347. return (TRUE);
  348. }else{
  349. return (FALSE);
  350. }
  351. #endif
  352. }
  353. /***********************************************************************************************
  354. * Spawn_WChat -- spawns or switches focus to wchat *
  355. * *
  356. * *
  357. * *
  358. * INPUT: can launch. If set then we are allowed to launch WChat if not already running *
  359. * *
  360. * OUTPUT: True if wchat was spawned *
  361. * *
  362. * WARNINGS: None *
  363. * *
  364. * HISTORY: *
  365. * 6/8/96 12:33PM ST : Created *
  366. *=============================================================================================*/
  367. bool Poke_WChat(void);
  368. bool Spawn_WChat(bool can_launch)
  369. {
  370. can_launch;
  371. return false;
  372. #if (0)
  373. CCDebugString ("C&C95 - In Spawn_WChat.\n");
  374. char packet[10] = {"Hello"};
  375. HWND chat_window = NULL;
  376. /*
  377. ** See if WChat is already running...
  378. */
  379. if (WChatHWND && IsWindow (WChatHWND) ){
  380. chat_window = WChatHWND;
  381. }else{
  382. chat_window = FindWindow ( "OWL_Window", "Westwood Chat" );
  383. }
  384. if (chat_window){
  385. /*
  386. ** WChat is already running. Minimize myself then try to give it focus.
  387. */
  388. Set_Palette(BlackPalette);
  389. VisiblePage.Clear();
  390. ShowWindow (MainWindow, SW_MINIMIZE);
  391. /*
  392. ** Give windoze a couple of secs to sort itself out.
  393. */
  394. CountDownTimerClass wibble_timer;
  395. wibble_timer.Set ( 60 * 3, true);
  396. while (wibble_timer.Time()){
  397. /*
  398. ** Call our message loop to make sure we get all the messages that are sent to us
  399. ** when we minimise.
  400. */
  401. Keyboard::Check();
  402. }
  403. /*
  404. ** Send chat a tickle message so it knows to send the game stats to the server.
  405. */
  406. if (GameStatisticsPacketSent && !PlanetWestwoodIsHost) {
  407. Send_Data_To_DDE_Server (packet, strlen(packet), DDEServerClass::DDE_TICKLE);
  408. }
  409. /*
  410. ** Give the focus to WChat
  411. */
  412. SetForegroundWindow ( chat_window );
  413. ShowWindow ( chat_window, SW_RESTORE );
  414. return(true);
  415. }
  416. /*
  417. ** Fail if we aren't allowed to launch wchat and we couldnt find its window.
  418. */
  419. if (!can_launch) return (false);
  420. /*
  421. ** Find where WChat was installed to
  422. */
  423. HKEY key;
  424. char wchat_loc[256];
  425. DWORD wchat_loc_size = 256;
  426. key = Get_Registry_Sub_Key (HKEY_LOCAL_MACHINE, "SOFTWARE", FALSE);
  427. if (!key) return (FALSE);
  428. key = Get_Registry_Sub_Key (key, "Westwood", TRUE);
  429. if (!key) return (FALSE);
  430. key = Get_Registry_Sub_Key (key, "WChat", TRUE);
  431. if (!key) return (FALSE);
  432. //key = Get_Registry_Sub_Key (key, "UserName", TRUE);
  433. //if (!key) return (FALSE);
  434. //key = Get_Registry_Sub_Key (key, "Nick", TRUE);
  435. //if (!key) return (FALSE);
  436. if (RegQueryValueEx(key, "InstallPath", NULL, NULL, (unsigned char*)wchat_loc, &wchat_loc_size) != ERROR_SUCCESS){
  437. RegCloseKey(key);
  438. return (FALSE);
  439. }
  440. RegCloseKey(key);
  441. PROCESS_INFORMATION process_info;
  442. STARTUPINFO start_info;
  443. memset ((void*)&start_info, 0, sizeof(start_info));
  444. start_info.cb = sizeof(start_info);
  445. char justpath [256];
  446. Just_Path(wchat_loc, justpath);
  447. /*
  448. ** We found WChat in the registry. Minimize myself then try to spawn it.
  449. */
  450. Set_Palette(BlackPalette);
  451. VisiblePage.Clear();
  452. ShowWindow (MainWindow, SW_MINIMIZE);
  453. /*
  454. ** Give windoze a couple of secs to sort itself out.
  455. */
  456. CountDownTimerClass wibble_timer;
  457. wibble_timer.Set ( 60 * 3, true);
  458. while (wibble_timer.Time()){
  459. /*
  460. ** Call our message loop to make sure we get all the messages that are sent to us
  461. ** when we minimise.
  462. */
  463. Keyboard::Check();
  464. }
  465. bool success = CreateProcess (wchat_loc, NULL, NULL, NULL, false, 0, NULL, justpath, &start_info, &process_info);
  466. if (success){
  467. return (true);
  468. }else{
  469. ShowWindow (MainWindow, SW_RESTORE);
  470. while ( Keyboard::Check() ) {};
  471. return (false);
  472. }
  473. #endif
  474. }
  475. /***********************************************************************************************
  476. * Spawn_Registration_App -- spawns the C&C/Planet westwood registration app *
  477. * *
  478. * *
  479. * *
  480. * INPUT: Nothing *
  481. * *
  482. * OUTPUT: True if app was spawned *
  483. * *
  484. * WARNINGS: None *
  485. * *
  486. * HISTORY: *
  487. * 6/8/96 12:33PM ST : Created *
  488. *=============================================================================================*/
  489. bool Spawn_Registration_App(void)
  490. {
  491. return false;
  492. #if (0) //ST - 1/2/2019 5:53PM
  493. /*
  494. ** Find where inetreg was installed to
  495. */
  496. HKEY key;
  497. char inetreg_loc[256];
  498. DWORD inetreg_loc_size = 256;
  499. key = Get_Registry_Sub_Key (HKEY_LOCAL_MACHINE, "SOFTWARE", FALSE);
  500. if (!key) return (FALSE);
  501. key = Get_Registry_Sub_Key (key, "Westwood", TRUE);
  502. if (!key) return (FALSE);
  503. key = Get_Registry_Sub_Key (key, "InetReg", TRUE);
  504. if (!key) return (FALSE);
  505. if (RegQueryValueEx(key, "InstallPath", NULL, NULL, (unsigned char*)inetreg_loc, &inetreg_loc_size) != ERROR_SUCCESS){
  506. RegCloseKey(key);
  507. return (FALSE);
  508. }
  509. RegCloseKey(key);
  510. PROCESS_INFORMATION process_info;
  511. STARTUPINFO start_info;
  512. char justpath [256];
  513. memset ((void*)&start_info, 0, sizeof(start_info));
  514. start_info.cb = sizeof(start_info);
  515. Just_Path(inetreg_loc, justpath);
  516. BOOL success = CreateProcess (inetreg_loc, NULL, NULL, NULL, false, 0, NULL, justpath, &start_info, &process_info);
  517. if (success){
  518. //WaitForSingleObject (process_info.hProcess, 1000*10000);
  519. //SetForegroundWindow ( MainWindow );
  520. //ShowWindow ( MainWindow, SW_RESTORE );
  521. }
  522. return (success);
  523. #endif
  524. }
  525. /***********************************************************************************************
  526. * Do_The_Internet_Menu_Thang -- Handle case where user clicks on 'Internet' button *
  527. * *
  528. * *
  529. * *
  530. * INPUT: Nothing *
  531. * *
  532. * OUTPUT: Nothing *
  533. * *
  534. * WARNINGS: None *
  535. * *
  536. * HISTORY: *
  537. * 6/7/96 8:30PM ST : Created *
  538. *=============================================================================================*/
  539. bool Do_The_Internet_Menu_Thang(void)
  540. {
  541. #ifndef DEMO
  542. int factor = (SeenBuff.Get_Width() == 320) ? 1 : 2;
  543. /*
  544. ** Dialog & button dimensions
  545. */
  546. int d_dialog_w = 120 *factor; // dialog width
  547. int d_dialog_h = 80*factor; // dialog height
  548. int d_dialog_x = ((320*factor - d_dialog_w) / 2); // dialog x-coord
  549. int d_dialog_y = ((200*factor - d_dialog_h) / 2); // centered y-coord
  550. int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
  551. int d_margin1=10;
  552. int d_txt6_h=15;
  553. #if (GERMAN | FRENCH)
  554. int d_cancel_w = 50*factor;
  555. #else
  556. int d_cancel_w = 40*factor;
  557. #endif
  558. int d_cancel_h = 9*factor;
  559. int d_cancel_x = d_dialog_cx - d_cancel_w / 2;
  560. int d_cancel_y = d_dialog_y + d_dialog_h - 20*factor;
  561. char packet[10] = {"Hello"};
  562. #if (GERMAN | FRENCH)
  563. int width=160*factor;
  564. int height=80*factor;
  565. #else
  566. int width=120*factor;
  567. int height=80*factor;
  568. #endif //GERMAN | FRENCH
  569. Fancy_Text_Print(TXT_NONE,0,0,TBLACK,TBLACK,TPF_6PT_GRAD | TPF_NOSHADOW);
  570. Format_Window_String((char*)Text_String (TXT_CONNECTING), SeenBuff.Get_Height(), width, height);
  571. #if (GERMAN | FRENCH)
  572. d_dialog_w = width + 25*factor;
  573. d_dialog_x = ((320*factor - d_dialog_w) / 2); // dialog x-coord
  574. d_cancel_x = d_dialog_cx - (d_cancel_w / 2);
  575. #endif
  576. /*
  577. ** Button Enumerations
  578. */
  579. enum {
  580. BUTTON_CANCEL = 100,
  581. };
  582. /*
  583. ** Buttons
  584. */
  585. //TextButtonClass *buttons; // button list
  586. TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL,
  587. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  588. //#if (GERMAN | FRENCH)
  589. // d_cancel_x, d_cancel_y);
  590. //#else
  591. d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h);
  592. //#endif
  593. //buttons = &cancelbtn;
  594. Fancy_Text_Print(TXT_NONE, 0, 0, CC_GREEN, TBLACK,
  595. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  596. char users_name[256];
  597. int buffer_len = sizeof (users_name);
  598. bool process;
  599. bool display;
  600. KeyNumType input;
  601. if (!Special.IsFromWChat && !SpawnedFromWChat){
  602. /*
  603. ** If the user is registered with Planet Westwood then spawn WChat.
  604. */
  605. if (Is_User_WChat_Registered(users_name, buffer_len)){
  606. GameStatisticsPacketSent = false;
  607. if (!Spawn_WChat(true)){
  608. Set_Logic_Page(SeenBuff);
  609. Load_Title_Screen("HTITLE.PCX", &HidPage, Palette);
  610. Blit_Hid_Page_To_Seen_Buff();
  611. Set_Palette(Palette);
  612. CCMessageBox().Process(TXT_ERROR_UNABLE_TO_RUN_WCHAT, TXT_OK);
  613. LogicPage->Clear();
  614. return(false);
  615. }
  616. }else{
  617. Set_Logic_Page(SeenBuff);
  618. Load_Title_Screen("HTITLE.PCX", &HidPage, Palette);
  619. Blit_Hid_Page_To_Seen_Buff();
  620. Set_Palette(Palette);
  621. if (CCMessageBox().Process(TXT_EXPLAIN_REGISTRATION, TXT_REGISTER, TXT_CANCEL)){
  622. LogicPage->Clear();
  623. return(false);
  624. }else{
  625. LogicPage->Clear();
  626. Spawn_Registration_App();
  627. return(false);
  628. }
  629. }
  630. }
  631. /*
  632. **
  633. ** User is registered and we spawned WChat. Wait for a game start message from WChat.
  634. **
  635. */
  636. process = true;
  637. display = true;
  638. while (process){
  639. /*
  640. ** If we have just received input focus again after running in the background then
  641. ** we need to redraw.
  642. */
  643. if (AllSurfaces.SurfacesRestored){
  644. AllSurfaces.SurfacesRestored = FALSE;
  645. display = true;
  646. }
  647. if (display) {
  648. Set_Logic_Page(SeenBuff);
  649. Hide_Mouse();
  650. /*
  651. ** Redraw backgound & dialog box
  652. */
  653. Load_Title_Screen("HTITLE.PCX", &HidPage, Palette);
  654. Blit_Hid_Page_To_Seen_Buff();
  655. Set_Palette(Palette);
  656. Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
  657. /*
  658. ** Dialog & Field labels
  659. */
  660. Draw_Caption (TXT_NONE, d_dialog_x, d_dialog_y, d_dialog_w);
  661. Fancy_Text_Print(TXT_CONNECTING, d_dialog_cx-width/2, d_dialog_y + 25*factor, CC_GREEN, TBLACK,
  662. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  663. //cancelbtn.Zap();
  664. //buttons = &cancelbtn;
  665. /*
  666. .................... Rebuild the button list ....................
  667. */
  668. //buttons->Draw_All();
  669. cancelbtn.Draw_Me(true);
  670. Show_Mouse();
  671. display = false;
  672. }
  673. /*
  674. ** See if the game start packet has arrived from wchat yet.
  675. */
  676. if (DDEServer.Get_MPlayer_Game_Info()){
  677. //MessageBox (NULL, "About to restore focus to C&C95", "C&C95", MB_OK);
  678. //SetForegroundWindow ( MainWindow );
  679. //ShowWindow ( MainWindow, SW_SHOWMAXIMIZED );
  680. return(true);
  681. }
  682. //input = buttons->Input();
  683. input = cancelbtn.Input();
  684. /*
  685. ---------------------------- Process input ----------------------------
  686. */
  687. switch (input) {
  688. /*
  689. ** Cancel. Just return to the main menu
  690. */
  691. case (KN_ESC):
  692. case (BUTTON_CANCEL | KN_BUTTON):
  693. process = false;
  694. Send_Data_To_DDE_Server (packet, strlen(packet), DDEServerClass::DDE_CONNECTION_FAILED);
  695. GameStatisticsPacketSent = false;
  696. Spawn_WChat(false);
  697. break;
  698. }
  699. }
  700. #endif //DEMO
  701. return (false);
  702. }