MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / MultiDoFileData

Function MultiDoFileData

Descent3/multi.cpp:7766–7841  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7764}
7765
7766void MultiDoFileData(uint8_t *data) {
7767 // File data. We asked for it, now the server is sending it to us.
7768 uint32_t total_len; // Length of the entire file
7769 uint32_t curr_len; // Length of file sent so far
7770 uint16_t file_id; // Defines which file this is
7771 uint16_t playernum; // Who is sending us the file
7772 uint16_t data_len; // between 1-450 bytes
7773 // uint16_t file_who;
7774 int count = 0;
7775 uint8_t outdata[MAX_GAME_DATA_SIZE];
7776 int outcount = 0;
7777 int size;
7778
7779 SKIP_HEADER(data, &count);
7780 total_len = MultiGetUint(data, &count);
7781 curr_len = MultiGetUint(data, &count); // Length of the file after before this data chunk
7782 file_id = MultiGetUshort(data, &count);
7783 playernum = MultiGetUshort(data, &count);
7784 // file_who = MultiGetUshort (data,&count);
7785 data_len = MultiGetUshort(data, &count);
7786 // mprintf(0,"Got a data packet from %d\n",playernum);
7787 if ((NetPlayers[playernum].file_xfer_flags == NETFILE_RECEIVING) ||
7788 (NetPlayers[playernum].file_xfer_flags == NETFILE_ASKING)) {
7789
7790 // Find out if this is the first packet of this file. if so, create and open the file
7791 if (NetPlayers[playernum].file_xfer_pos == 0) {
7792 mprintf(0, "Creating file...\n");
7793 CFILE *cfp;
7794 // char filename[_MAX_PATH];
7795 char filewithpath[_MAX_PATH * 2];
7796 strcpy(filewithpath, GetFileNameFromPlayerAndID(playernum, file_id));
7797
7798 cfp = cfopen(filewithpath, "wb");
7799 if (!cfp) {
7800 mprintf(0, "Can't create file %s\n", filewithpath);
7801 // We couldn't create the file, so cancel the attempt to transfer it.
7802 MultiCancelFile(playernum, file_id, NetPlayers[playernum].file_xfer_who);
7803 return;
7804 }
7805 NetPlayers[playernum].file_xfer_cfile = cfp;
7806 NetPlayers[playernum].file_xfer_flags = NETFILE_RECEIVING;
7807 }
7808
7809 MULTI_ASSERT_NOMESSAGE(NetPlayers[playernum].file_xfer_cfile);
7810 // Write the data to the file
7811 int data_wrote = cf_WriteBytes(data + count, data_len, NetPlayers[playernum].file_xfer_cfile);
7812 if (data_wrote != data_len) {
7813 mprintf(0, "cf_WriteBytes() should have written %d bytes, but only wrote %d!\n", data_len, data_wrote);
7814 Int3();
7815 }
7816
7817 NetPlayers[playernum].file_xfer_pos += data_len;
7818 // See if this is the last data chunk
7819 if (NetPlayers[playernum].file_xfer_pos >= total_len) {
7820 // We got the whole thing baby!
7821 cfclose(NetPlayers[playernum].file_xfer_cfile);
7822 NetPlayers[playernum].file_xfer_cfile = NULL;
7823 NetPlayers[playernum].file_xfer_pos = 0;

Callers 1

MultiProcessDataFunction · 0.85

Calls 14

SKIP_HEADERFunction · 0.85
MultiGetUintFunction · 0.85
MultiGetUshortFunction · 0.85
cfopenFunction · 0.85
MultiCancelFileFunction · 0.85
cf_WriteBytesFunction · 0.85
cfcloseFunction · 0.85
DoNextPlayerFileFunction · 0.85
START_DATAFunction · 0.85
MultiAddUshortFunction · 0.85
MultiAddUintFunction · 0.85

Tested by

no test coverage detected