SENDFILE.CPP 26 KB

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