INTERNET.CPP 29 KB

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