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

Function MultiDoFileReq

Descent3/multi.cpp:7674–7712  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7672}
7673
7674void MultiDoFileReq(uint8_t *data) {
7675 int count = 0;
7676 SKIP_HEADER(data, &count);
7677 uint16_t filenum = MultiGetUshort(data, &count);
7678 uint16_t filewho = MultiGetUshort(data, &count);
7679 uint16_t playernum = MultiGetUshort(data, &count);
7680 // If we are the server, someone want's a file. Either start sending it to them, or deny the request
7681 if (NetPlayers[playernum].file_xfer_flags == NETFILE_NONE) {
7682 // FIXME!! Figure out what file to open
7683 CFILE *cfp;
7684 // char filename[_MAX_PATH];
7685 char filewithpath[_MAX_PATH * 2];
7686 strcpy(filewithpath, GetFileNameFromPlayerAndID(filewho, filenum));
7687 if (filewithpath[0] == 0) {
7688 mprintf(0, "Got a file request for a file that doesn't exist (%s).\n", filewithpath);
7689 DenyFile(playernum, filenum, NetPlayers[playernum].file_xfer_who);
7690 } else {
7691 cfp = cfopen(filewithpath, "rb");
7692 if (!cfp) {
7693 mprintf(0, "Couldn't open a file (%s) for transfer.\n", filewithpath);
7694 DenyFile(playernum, filenum, NetPlayers[playernum].file_xfer_who);
7695 return;
7696 // We couldn't create the file, so cancel the attempt to transfer it.
7697 }
7698 mprintf(0, "Sending first data chunk!\n");
7699 NetPlayers[playernum].file_xfer_who = filewho;
7700 NetPlayers[playernum].file_xfer_cfile = cfp;
7701 NetPlayers[playernum].file_xfer_pos = 0;
7702 NetPlayers[playernum].file_xfer_flags = NETFILE_SENDING;
7703 NetPlayers[playernum].file_xfer_total_len = cfp->size;
7704 NetPlayers[playernum].file_xfer_id = filenum;
7705 mprintf(0, "File size = %d\n", cfp->size);
7706 SendDataChunk(playernum);
7707 }
7708 } else {
7709 mprintf(0, "Got a file request while one was already in progress!\n");
7710 DenyFile(playernum, filenum, NetPlayers[playernum].file_xfer_who);
7711 }
7712}
7713
7714void DenyFile(int playernum, int filenum, int file_who) {
7715 int size = 0;

Callers 1

MultiProcessDataFunction · 0.85

Calls 6

SKIP_HEADERFunction · 0.85
MultiGetUshortFunction · 0.85
DenyFileFunction · 0.85
cfopenFunction · 0.85
SendDataChunkFunction · 0.85

Tested by

no test coverage detected