SENDFILE.CPP 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  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 : SENDFILE.CPP *
  21. * *
  22. * Programmer : Steve Tall *
  23. * *
  24. * Start Date : Audust 20th, 1996 *
  25. * *
  26. * Last Update : August 20th, 1996 [ST] *
  27. * *
  28. *-----------------------------------------------------------------------------------*
  29. * Overview: *
  30. * *
  31. * Functions for scenario file transfer between machines *
  32. * *
  33. *-----------------------------------------------------------------------------------*
  34. * Functions: *
  35. * *
  36. * *
  37. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  38. #if (0)//PG
  39. #include "function.h"
  40. //#include "WolDebug.h"
  41. #ifdef WINSOCK_IPX
  42. #include "WSProto.h"
  43. #else
  44. #ifdef WIN32
  45. #include "tcpip.h"
  46. #else
  47. #include "fakesock.h"
  48. #endif //WIN32
  49. #endif //WINSOCK_IPX
  50. bool Receive_Remote_File ( char *file_name, unsigned int file_length, int gametype);
  51. bool Send_Remote_File ( char *file_name, int gametype );
  52. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  53. extern bool Is_Mission_Counterstrike (char *file_name);
  54. extern bool Is_Mission_Aftermath (char *file_name);
  55. #endif
  56. #define RESPONSE_TIMEOUT 60*60
  57. #ifdef WOLAPI_INTEGRATION
  58. #include "WolapiOb.h"
  59. extern WolapiObject* pWolapi;
  60. #endif
  61. /***********************************************************************************************
  62. * Get_Scenario_File_From_Host -- Initiates download of scenario file from game host *
  63. * *
  64. * *
  65. * *
  66. * INPUT: ptr to buffer to copy file name into *
  67. * game type - 0 for modem/null modem, 1 otherwise *
  68. * *
  69. * OUTPUT: true if file sucessfully downloaded *
  70. * *
  71. * WARNINGS: None *
  72. * *
  73. * HISTORY: *
  74. * 8/22/96 3:06PM ST : Created *
  75. *=============================================================================================*/
  76. bool Get_Scenario_File_From_Host(char *return_name, int gametype)
  77. {
  78. //WWDebugString ("RA95 - In Get_Scenario_From_Host\n");
  79. unsigned int file_length;
  80. SerialPacketType send_packet;
  81. SerialPacketType receive_packet;
  82. GlobalPacketType net_send_packet;
  83. GlobalPacketType net_receive_packet;
  84. unsigned int packet_len;
  85. unsigned short product_id;
  86. IPXAddressClass sender_address;
  87. CDTimerClass<SystemTimerClass> response_timer; // timeout timer for waiting for responses
  88. /*
  89. ** Send the scenario request using guaranteed delivery.
  90. */
  91. if (!gametype) {
  92. memset ((void*)&send_packet, 0, sizeof (send_packet));
  93. send_packet.Command = SERIAL_REQ_SCENARIO;
  94. NullModem.Send_Message (&send_packet, sizeof(send_packet), 1);
  95. } else {
  96. memset ((void*)&net_send_packet, 0, sizeof (net_send_packet));
  97. net_send_packet.Command = NET_REQ_SCENARIO;
  98. Ipx.Send_Global_Message (&net_send_packet, sizeof (net_send_packet),
  99. 1, &(Session.HostAddress) );
  100. }
  101. //WWDebugString ("RA95 - Waiting for response from host\n");
  102. /*
  103. ** Wait for host to respond with a file info packet
  104. */
  105. response_timer = RESPONSE_TIMEOUT;
  106. if (!gametype){
  107. do {
  108. NullModem.Service();
  109. if (NullModem.Get_Message ((void*)&receive_packet, (int*)&packet_len) > 0) {
  110. if (receive_packet.Command == SERIAL_FILE_INFO){
  111. strcpy (return_name, receive_packet.ScenarioInfo.ShortFileName);
  112. file_length = receive_packet.ScenarioInfo.FileLength;
  113. break;
  114. }
  115. }
  116. } while ( response_timer );
  117. }else{
  118. do {
  119. Ipx.Service();
  120. int receive_packet_length = sizeof (net_receive_packet);
  121. if (Ipx.Get_Global_Message (&net_receive_packet, &receive_packet_length,
  122. &sender_address, &product_id)){
  123. //WWDebugString ("RA95 - Got packet from host\n");
  124. #ifdef WINSOCK_IPX
  125. if (net_receive_packet.Command == NET_FILE_INFO && sender_address == Session.HostAddress) {
  126. #else //WINSOCK_IPX
  127. if (net_receive_packet.Command == NET_FILE_INFO &&
  128. (Winsock.Get_Connected() || sender_address == Session.HostAddress)){
  129. #endif //WINSOCK_IPX
  130. strcpy (return_name, net_receive_packet.ScenarioInfo.ShortFileName);
  131. file_length = net_receive_packet.ScenarioInfo.FileLength;
  132. //WWDebugString ("RA95 - Got file info packet from host\n");
  133. break;
  134. }
  135. }
  136. #ifdef WOLAPI_INTEGRATION
  137. if( Session.Type == GAME_INTERNET && pWolapi && ( ::timeGetTime() > pWolapi->dwTimeNextWolapiPump ) )
  138. {
  139. pWolapi->pChat->PumpMessages();
  140. pWolapi->dwTimeNextWolapiPump = ::timeGetTime() + WOLAPIPUMPWAIT;
  141. }
  142. #endif
  143. } while ( response_timer );
  144. }
  145. //char rt[80];
  146. //sprintf (rt, "RA95 - response_timer = %d\n", response_timer );
  147. //WWDebugString (rt);
  148. /*
  149. ** If we timed out then something horrible has happened to the other player so just
  150. ** return failure.
  151. */
  152. if (!response_timer) return (false);
  153. // debugprint( "about to download '%s'\n", return_name );
  154. /*
  155. ** Receive the file from the host
  156. */
  157. return (Receive_Remote_File ( return_name, file_length, gametype));
  158. }
  159. /***********************************************************************************************
  160. * Receive_Remote_File -- Handles incoming file download packets from the game host *
  161. * *
  162. * *
  163. * *
  164. * INPUT: file name to save as *
  165. * length of file to expect *
  166. * game type - 0 for modem/null modem, 1 otherwise *
  167. * *
  168. * OUTPUT: true if file downloaded was completed *
  169. * *
  170. * WARNINGS: This fuction can modify the file name passed in *
  171. * *
  172. * HISTORY: *
  173. * 8/22/96 3:07PM ST : Created *
  174. *=============================================================================================*/
  175. bool Receive_Remote_File ( char *file_name, unsigned int file_length, int gametype)
  176. {
  177. //WWDebugString ("RA95 - In Receive_Remote_File\n");
  178. unsigned short product_id;
  179. IPXAddressClass sender_address;
  180. /*
  181. ** Dialog & button dimensions
  182. */
  183. int d_dialog_w = 200 *RESFACTOR; // dialog width
  184. int d_dialog_h = 90*RESFACTOR; // dialog height
  185. int d_dialog_x = ((320*RESFACTOR - d_dialog_w) / 2); // dialog x-coord
  186. int d_dialog_y = ((200*RESFACTOR - d_dialog_h) / 2); // centered y-coord
  187. int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
  188. int d_margin1=10;
  189. int d_txt6_h=15;
  190. #if (GERMAN | FRENCH)
  191. int d_cancel_w = 50*RESFACTOR;
  192. #else
  193. int d_cancel_w = 40*RESFACTOR;
  194. #endif
  195. int d_cancel_h = 9*RESFACTOR;
  196. int d_cancel_x = d_dialog_cx - d_cancel_w / 2;
  197. int d_cancel_y = d_dialog_y + d_dialog_h - 20*RESFACTOR;
  198. int d_progress_w = 100*RESFACTOR;
  199. int d_progress_h = 10*RESFACTOR;
  200. int d_progress_x = (SeenBuff.Get_Width()/2) - d_progress_w/2;
  201. int d_progress_y = d_dialog_y + 45*RESFACTOR;
  202. int width;
  203. int height;
  204. char *info_string = (char*)Text_String (TXT_RECEIVING_SCENARIO);
  205. Fancy_Text_Print(TXT_NONE, 0, 0, GadgetClass::Get_Color_Scheme(),
  206. TBLACK, TPF_CENTER|TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_NOSHADOW);
  207. Format_Window_String(info_string, SeenBuff.Get_Height(), width, height);
  208. /*
  209. ** Button Enumerations
  210. */
  211. enum {
  212. BUTTON_CANCEL = 100,
  213. BUTTON_PROGRESS
  214. };
  215. /*
  216. ** Buttons
  217. */
  218. //TextButtonClass *buttons; // button list
  219. TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL,
  220. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  221. #if (GERMAN | FRENCH)
  222. d_cancel_x, d_cancel_y);
  223. #else
  224. d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h);
  225. #endif
  226. GaugeClass progress_meter (BUTTON_PROGRESS,
  227. d_progress_x, d_progress_y, d_progress_w, d_progress_h);
  228. Fancy_Text_Print(TXT_NONE, 0, 0, GadgetClass::Get_Color_Scheme(),
  229. TBLACK, TPF_CENTER|TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_NOSHADOW);
  230. typedef enum {
  231. REDRAW_NONE = 0,
  232. REDRAW_PROGRESS,
  233. REDRAW_BUTTONS,
  234. REDRAW_BACKGROUND,
  235. REDRAW_ALL = REDRAW_BACKGROUND
  236. } RedrawType;
  237. bool process = true;
  238. RedrawType display = REDRAW_ALL; // redraw level
  239. KeyNumType input;
  240. GadgetClass *commands; // button list
  241. bool return_code;
  242. int update_time = 0;
  243. RemoteFileTransferType receive_packet;
  244. int last_received_block = -1; //No blocks received yet
  245. unsigned int total_length = 0;
  246. unsigned int packet_len;
  247. /*
  248. ** If the file name is already in use, use the temp file name
  249. */
  250. CCFileClass test_file (file_name);
  251. if (test_file.Is_Available()){
  252. strcpy (file_name, "DOWNLOAD.TMP");
  253. }
  254. RawFileClass save_file (file_name);
  255. /*
  256. ** If the file already exists then delete it and re-create it.
  257. */
  258. if (save_file.Is_Available()) save_file.Delete();
  259. /*
  260. ** Open the file for write
  261. */
  262. save_file.Open ( WRITE );
  263. commands = &cancelbtn;
  264. commands->Add_Tail (progress_meter);
  265. progress_meter.Set_Maximum(100); // Max is 100%
  266. progress_meter.Set_Value(0); // Current is 0%
  267. /*
  268. ** Wait for all the blocks to arrive
  269. */
  270. do {
  271. #ifdef WIN32
  272. /*
  273. ** If we have just received input focus again after running in the background then
  274. ** we need to redraw.
  275. */
  276. if (AllSurfaces.SurfacesRestored) {
  277. AllSurfaces.SurfacesRestored=FALSE;
  278. display = REDRAW_ALL;
  279. }
  280. #endif
  281. #ifdef WOLAPI_INTEGRATION
  282. if( Session.Type == GAME_INTERNET && pWolapi && ( ::timeGetTime() > pWolapi->dwTimeNextWolapiPump ) )
  283. {
  284. pWolapi->pChat->PumpMessages();
  285. pWolapi->dwTimeNextWolapiPump = ::timeGetTime() + WOLAPIPUMPWAIT;
  286. }
  287. #endif
  288. if (display){
  289. if (display >= REDRAW_BACKGROUND){
  290. Hide_Mouse();
  291. /*
  292. ** Redraw backgound & dialog box
  293. */
  294. Load_Title_Page(true);
  295. Set_Palette(CCPalette);
  296. Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
  297. /*
  298. ** Dialog & Field labels
  299. */
  300. Draw_Caption (TXT_NONE, d_dialog_x, d_dialog_y, d_dialog_w);
  301. Fancy_Text_Print(info_string, d_dialog_cx-width/2, d_dialog_y + 25*RESFACTOR,
  302. GadgetClass::Get_Color_Scheme(), TBLACK,
  303. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  304. Show_Mouse();
  305. }
  306. if (display >= REDRAW_BUTTONS){
  307. commands->Draw_All();
  308. }
  309. if (display >= REDRAW_PROGRESS){
  310. progress_meter.Draw_Me(true);
  311. }
  312. display = REDRAW_NONE;
  313. }
  314. if (!gametype){
  315. NullModem.Service();
  316. if (NullModem.Get_Message ((void*)&receive_packet, (int*)&packet_len) > 0) {
  317. if (receive_packet.Command == NET_FILE_CHUNK){
  318. if (receive_packet.BlockNumber == last_received_block + 1){
  319. save_file.Write ( receive_packet.RawData, receive_packet.BlockLength );
  320. total_length += receive_packet.BlockLength;
  321. last_received_block ++;
  322. update_time++;
  323. if (update_time >7){
  324. progress_meter.Set_Value ( (total_length*100) / file_length );
  325. display = REDRAW_PROGRESS;
  326. update_time = 0;;
  327. }
  328. if (total_length >= file_length){
  329. process = false;
  330. return_code = true;
  331. progress_meter.Set_Value ( 100 );
  332. progress_meter.Draw_Me(true);
  333. }
  334. }
  335. }
  336. }
  337. }else{
  338. Ipx.Service();
  339. int receive_packet_len = sizeof (receive_packet);
  340. if (Ipx.Get_Global_Message (&receive_packet, &receive_packet_len,
  341. &sender_address, &product_id)){
  342. #ifdef WINSOCK_IPX
  343. if (receive_packet.Command == NET_FILE_CHUNK && sender_address == Session.HostAddress){
  344. #else //WINSOCK_IPX
  345. if (receive_packet.Command == NET_FILE_CHUNK &&
  346. (Winsock.Get_Connected() || sender_address == Session.HostAddress)){
  347. #endif //WINSOCK_IPX
  348. if (receive_packet.BlockNumber == last_received_block + 1){
  349. save_file.Write ( receive_packet.RawData, receive_packet.BlockLength );
  350. total_length += receive_packet.BlockLength;
  351. last_received_block ++;
  352. update_time++;
  353. if (update_time >7){
  354. progress_meter.Set_Value ( (total_length*100) / file_length );
  355. display = REDRAW_PROGRESS;
  356. update_time = 0;;
  357. }
  358. if (total_length >= file_length){
  359. process = false;
  360. return_code = true;
  361. progress_meter.Set_Value ( 100 );
  362. progress_meter.Draw_Me(true);
  363. }
  364. }
  365. }
  366. }
  367. }
  368. if (process){
  369. input = cancelbtn.Input();
  370. /*
  371. ---------------------------- Process input ----------------------------
  372. */
  373. switch (input) {
  374. /*
  375. ** Cancel. Just return to the main menu
  376. */
  377. case (KN_ESC):
  378. case (BUTTON_CANCEL | KN_BUTTON):
  379. process = false;
  380. return_code = false;
  381. break;
  382. }
  383. }
  384. } while ( process );
  385. save_file.Close();
  386. /*
  387. ** Update the internal list of scenarios to include the downloaded one so we know about it
  388. ** for the next game.
  389. */
  390. Session.Read_Scenario_Descriptions();
  391. return (return_code);
  392. }
  393. /***********************************************************************************************
  394. * Send_Remote_File -- Sends a file to game clients *
  395. * *
  396. * *
  397. * *
  398. * INPUT: File name *
  399. * *
  400. * OUTPUT: true if file transfer was successfully completed *
  401. * game type - 0 for modem/null modem, 1 otherwise *
  402. * *
  403. * WARNINGS: None *
  404. * *
  405. * HISTORY: *
  406. * 8/22/96 3:09PM ST : Created *
  407. *=============================================================================================*/
  408. bool Send_Remote_File ( char *file_name, int gametype )
  409. {
  410. //WWDebugString ("RA95 - In Send_Remote_File\n");
  411. /*
  412. ** Dialog & button dimensions
  413. */
  414. int factor = (SeenBuff.Get_Width() == 320) ? 1 : 2;
  415. int d_dialog_w = 240 *factor; // dialog width
  416. int d_dialog_h = 90*factor; // dialog height
  417. int d_dialog_x = ((320*factor - d_dialog_w) / 2); // dialog x-coord
  418. int d_dialog_y = ((200*factor - d_dialog_h) / 2); // centered y-coord
  419. int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
  420. int d_margin1=10;
  421. int d_txt6_h=15;
  422. #if (GERMAN | FRENCH)
  423. int d_cancel_w = 50*factor;
  424. #else
  425. int d_cancel_w = 40*factor;
  426. #endif
  427. int d_cancel_h = 9*factor;
  428. int d_cancel_x = d_dialog_cx - d_cancel_w / 2;
  429. int d_cancel_y = d_dialog_y + d_dialog_h - 20*factor;
  430. int d_progress_w = 100*factor;
  431. int d_progress_h = 10*factor;
  432. int d_progress_x = (SeenBuff.Get_Width()/2) - d_progress_w/2;
  433. int d_progress_y = d_dialog_y + 45*factor;
  434. int width;
  435. int height;
  436. char *info_string = (char*)Text_String (TXT_SENDING_SCENARIO);
  437. CDTimerClass<SystemTimerClass> response_timer; // timeout timer for waiting for responses
  438. Fancy_Text_Print(TXT_NONE, 0, 0, GadgetClass::Get_Color_Scheme(),
  439. TBLACK, TPF_CENTER|TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_NOSHADOW);
  440. Format_Window_String(info_string, SeenBuff.Get_Height(), width, height);
  441. /*
  442. ** Button Enumerations
  443. */
  444. enum {
  445. BUTTON_CANCEL = 100,
  446. BUTTON_PROGRESS
  447. };
  448. /*
  449. ** Buttons
  450. */
  451. //TextButtonClass *buttons; // button list
  452. TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL,
  453. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  454. #if (GERMAN | FRENCH)
  455. d_cancel_x, d_cancel_y);
  456. #else
  457. d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h);
  458. #endif
  459. GaugeClass progress_meter (BUTTON_PROGRESS,
  460. d_progress_x, d_progress_y, d_progress_w, d_progress_h);
  461. Fancy_Text_Print(TXT_NONE, 0, 0, GadgetClass::Get_Color_Scheme(),
  462. TBLACK, TPF_CENTER|TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_NOSHADOW);
  463. typedef enum {
  464. REDRAW_NONE = 0,
  465. REDRAW_PROGRESS,
  466. REDRAW_BUTTONS,
  467. REDRAW_BACKGROUND,
  468. REDRAW_ALL = REDRAW_BACKGROUND
  469. } RedrawType;
  470. bool process = true;
  471. RedrawType display = REDRAW_ALL; // redraw level
  472. KeyNumType input;
  473. GadgetClass *commands; // button list
  474. bool return_code;
  475. int update_time = 0;
  476. int file_length;
  477. int block_number;
  478. int max_chunk_size;
  479. int total_blocks;
  480. int bytes_left;
  481. void *read_ptr;
  482. RemoteFileTransferType send_packet;
  483. SerialPacketType file_info;
  484. GlobalPacketType net_file_info;
  485. CCFileClass send_file (file_name);
  486. if ( !send_file.Is_Available() ){
  487. //WWDebugString ("RA95 - Error - could not find file to send to client\n");
  488. // debugprint("RA95 - Error - could not find file to send to client\n");
  489. return (false);
  490. }
  491. file_length = send_file.Size();
  492. response_timer = RESPONSE_TIMEOUT;
  493. /*
  494. ** Send the file info to the remote machine(s)
  495. */
  496. if (!gametype){
  497. file_info.Command = SERIAL_FILE_INFO;
  498. strcpy (&file_info.ScenarioInfo.ShortFileName[0], file_name);
  499. #ifdef FIXIT_VERSION_3
  500. // If we're sending an official map, always send it to 'download.tmp'.
  501. if( Is_Mission_Counterstrike( file_name ) || Is_Mission_Aftermath( file_name ) ) {
  502. strcpy (&file_info.ScenarioInfo.ShortFileName[0], "DOWNLOAD.TMP");
  503. }
  504. #else
  505. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  506. // If we're sending an Aftermath map, always send it to 'download.tmp'.
  507. if (Is_Mission_Aftermath(file_name)) {
  508. strcpy (&file_info.ScenarioInfo.ShortFileName[0], "DOWNLOAD.TMP");
  509. }
  510. #endif
  511. #endif
  512. file_info.ScenarioInfo.FileLength = file_length;
  513. NullModem.Send_Message (&file_info, sizeof (file_info), 1);
  514. while (NullModem.Num_Send() > 0 && response_timer){
  515. NullModem.Service();
  516. }
  517. } else {
  518. net_file_info.Command = NET_FILE_INFO;
  519. strcpy (&net_file_info.ScenarioInfo.ShortFileName[0], file_name);
  520. // debugprint( "Uploading '%s'\n", file_name );
  521. #ifdef FIXIT_VERSION_3
  522. // If we're sending an official map, always send it to 'download.tmp'.
  523. if( Is_Mission_Counterstrike( file_name ) || Is_Mission_Aftermath( file_name ) ) {
  524. strcpy (&net_file_info.ScenarioInfo.ShortFileName[0], "DOWNLOAD.TMP");
  525. }
  526. #else
  527. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  528. // If we're sending an Aftermath map, always send it to 'download.tmp'.
  529. if (Is_Mission_Aftermath(file_name)) {
  530. strcpy (&file_info.ScenarioInfo.ShortFileName[0], "DOWNLOAD.TMP");
  531. // There was a bug here: s/b net_file_info. This means that players that don't have Aftermath could have been
  532. // accumulating Aftermath maps all this time!!! (File wasn't getting renamed to "DOWNLOAD.TMP".)
  533. }
  534. #endif
  535. #endif
  536. // debugprint( "ShortFileName is '%s'\n", net_file_info.ScenarioInfo.ShortFileName );
  537. net_file_info.ScenarioInfo.FileLength = file_length;
  538. for (int i=0 ; i<Session.RequestCount ; i++){
  539. Ipx.Send_Global_Message (&net_file_info, sizeof (GlobalPacketType),
  540. 1, &(Session.Players[Session.ScenarioRequests[i]]->Address) );
  541. }
  542. while (Ipx.Global_Num_Send() > 0 && response_timer) {
  543. Ipx.Service();
  544. }
  545. }
  546. max_chunk_size = MAX_SEND_FILE_PACKET_SIZE;
  547. total_blocks = (file_length + max_chunk_size-1) / max_chunk_size;
  548. bytes_left = file_length;
  549. send_file.Open ( READ );
  550. commands = &cancelbtn;
  551. commands->Add_Tail (progress_meter);
  552. progress_meter.Set_Maximum(100); // Max is 100%
  553. progress_meter.Set_Value(0); // Current is 0%
  554. block_number = 0;
  555. while ( process ){
  556. #ifdef WIN32
  557. /*
  558. ** If we have just received input focus again after running in the background then
  559. ** we need to redraw.
  560. */
  561. if (AllSurfaces.SurfacesRestored) {
  562. AllSurfaces.SurfacesRestored=FALSE;
  563. display = REDRAW_ALL;
  564. }
  565. #endif
  566. #ifdef WOLAPI_INTEGRATION
  567. if( Session.Type == GAME_INTERNET && pWolapi && ( ::timeGetTime() > pWolapi->dwTimeNextWolapiPump ) )
  568. {
  569. pWolapi->pChat->PumpMessages();
  570. pWolapi->dwTimeNextWolapiPump = ::timeGetTime() + WOLAPIPUMPWAIT;
  571. }
  572. #endif
  573. if (display){
  574. if (display >= REDRAW_BACKGROUND){
  575. Hide_Mouse();
  576. /*
  577. ** Redraw backgound & dialog box
  578. */
  579. Load_Title_Page(true);
  580. Set_Palette(CCPalette);
  581. Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
  582. /*
  583. ** Dialog & Field labels
  584. */
  585. Draw_Caption (TXT_NONE, d_dialog_x, d_dialog_y, d_dialog_w);
  586. Fancy_Text_Print(info_string, d_dialog_cx-width/2, d_dialog_y + 25*factor,
  587. GadgetClass::Get_Color_Scheme(), TBLACK,
  588. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  589. Show_Mouse();
  590. }
  591. if (display >= REDRAW_BUTTONS){
  592. commands->Draw_All();
  593. }
  594. if (display >= REDRAW_PROGRESS){
  595. progress_meter.Draw_Me(true);
  596. }
  597. display = REDRAW_NONE;
  598. }
  599. if (!gametype){
  600. NullModem.Service();
  601. if (block_number < total_blocks){
  602. if ( NullModem.Num_Send() <2 ){
  603. send_packet.Command = SERIAL_FILE_CHUNK;
  604. send_packet.BlockNumber = block_number;
  605. send_packet.BlockLength = MIN (file_length, max_chunk_size);
  606. file_length -= send_packet.BlockLength;
  607. read_ptr = &send_packet.RawData[0];
  608. if (send_file.Read (read_ptr , send_packet.BlockLength) == send_packet.BlockLength){
  609. NullModem.Send_Message ((void*)&send_packet, sizeof(send_packet), 1);
  610. }
  611. block_number++;
  612. update_time++;
  613. if (update_time >7){
  614. progress_meter.Set_Value ( (block_number*100) / total_blocks );
  615. display = REDRAW_PROGRESS;
  616. update_time = 0;;
  617. }
  618. }
  619. }else{
  620. if (NullModem.Num_Send() == 0){
  621. process = false;
  622. return_code = true;
  623. progress_meter.Set_Value ( 100 );
  624. progress_meter.Draw_Me(true);
  625. }
  626. }
  627. }else{
  628. Ipx.Service();
  629. if (block_number < total_blocks){
  630. if ( Ipx.Global_Num_Send() == 0 ){
  631. send_packet.Command = SERIAL_FILE_CHUNK;
  632. send_packet.BlockNumber = block_number;
  633. send_packet.BlockLength = MIN (file_length, max_chunk_size);
  634. file_length -= send_packet.BlockLength;
  635. read_ptr = &send_packet.RawData[0];
  636. if (send_file.Read (read_ptr , send_packet.BlockLength) == send_packet.BlockLength){
  637. for (int i=0 ; i<Session.RequestCount ; i++){
  638. Ipx.Send_Global_Message (&send_packet, sizeof (send_packet),
  639. 1, &(Session.Players[Session.ScenarioRequests[i]]->Address) );
  640. }
  641. }
  642. block_number++;
  643. update_time++;
  644. if (update_time >7){
  645. progress_meter.Set_Value ( (block_number*100) / total_blocks );
  646. display = REDRAW_PROGRESS;
  647. update_time = 0;;
  648. }
  649. }
  650. }else{
  651. if (Ipx.Global_Num_Send() == 0){
  652. process = false;
  653. return_code = true;
  654. progress_meter.Set_Value ( 100 );
  655. progress_meter.Draw_Me(true);
  656. }
  657. }
  658. }
  659. if (process){
  660. input = cancelbtn.Input();
  661. /*
  662. ---------------------------- Process input ----------------------------
  663. */
  664. switch (input) {
  665. /*
  666. ** Cancel. Just return to the main menu
  667. */
  668. case (KN_ESC):
  669. case (BUTTON_CANCEL | KN_BUTTON):
  670. process = false;
  671. return_code = false;
  672. break;
  673. }
  674. }
  675. }
  676. return (return_code);
  677. }
  678. #endif