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

Function MultiAskForFile

Descent3/multi.cpp:7607–7672  ·  view source on GitHub ↗

Ask for a file from the client if you are the server Or, if you are the server, ask a client file_id = NETFILE_ID_???? type file_who = If you are the client who's file you want from the server who = player number of who you are asking for the file

Source from the content-addressed store, hash-verified

7605// file_who = If you are the client who's file you want from the server
7606// who = player number of who you are asking for the file
7607void MultiAskForFile(uint16_t file_id, uint16_t file_who, uint16_t who) {
7608 int size = 0;
7609 uint8_t data[MAX_GAME_DATA_SIZE];
7610 int count = 0;
7611 //@@mprintf(0,"Asking player %d for a file (%d) from player %d\n",who,file_id,file_who);
7612 if (NetPlayers[who].file_xfer_flags != NETFILE_NONE) {
7613 mprintf(0, "File already in progress, can't start another one!\n");
7614 Int3();
7615 return; // Make sure a file isn't in progress
7616 }
7617 if (who == Player_num) {
7618 mprintf(0, "Can't send a file to myself!\n");
7619 return;
7620 }
7621 // Check to see if this file exists already
7622 char *p = GetFileNameFromPlayerAndID(file_who, file_id);
7623 if (*p) {
7624 if (CFES_ON_DISK == cfexist(p)) {
7625 char szcrc[_MAX_PATH];
7626 char path[_MAX_PATH];
7627 char ext[_MAX_PATH];
7628 char file[_MAX_PATH];
7629
7630 ddio_SplitPath(p, path, file, ext);
7631 snprintf(szcrc, sizeof(szcrc), "_%.8x", cf_GetfileCRC(p));
7632 // See if the the CRC is already in the filename
7633 if (strnicmp(szcrc, file + (strlen(file) - 9), 9) != 0) {
7634 mprintf(0, "Bad CRC on file %s! It must be corrupt! File will not be used, and is being deleted!\n", p);
7635 ddio_DeleteFile(p);
7636 } else {
7637 // Hey hey, we already have this file
7638 mprintf(0, "Using existing file: %s\n", p);
7639 DoNextPlayerFile(file_who);
7640 return;
7641 }
7642 }
7643 } else {
7644 // No file
7645 mprintf(0, "No custom file %d for player %d\n", file_id, file_who);
7646 DoNextPlayerFile(file_who);
7647 return;
7648 }
7649
7650 size = START_DATA(MP_FILE_REQ, data, &count);
7651 MultiAddUshort(file_id, data, &count);
7652 MultiAddUshort(file_who, data, &count);
7653 MultiAddUshort(Player_num, data, &count);
7654 END_DATA(count, data, size);
7655 if (Netgame.local_role == LR_SERVER) {
7656 // If we are a server, send a request to the client asking for a file of theirs
7657 mprintf(0, "Asking client %d for a file.\n", who);
7658 nw_SendReliable(NetPlayers[who].reliable_socket, data, count);
7659 NetPlayers[who].file_xfer_flags = NETFILE_ASKING;
7660 NetPlayers[who].file_xfer_pos = 0;
7661 NetPlayers[who].file_xfer_cfile = NULL;
7662 NetPlayers[who].file_xfer_who = file_who;
7663 } else {
7664 // If we are a client, ask the server for a file

Callers 2

MultiDoServerFrameFunction · 0.85
MultiDoClientFrameFunction · 0.85

Calls 10

cfexistFunction · 0.85
cf_GetfileCRCFunction · 0.85
DoNextPlayerFileFunction · 0.85
START_DATAFunction · 0.85
MultiAddUshortFunction · 0.85
END_DATAFunction · 0.85
nw_SendReliableFunction · 0.85
ddio_SplitPathFunction · 0.50
ddio_DeleteFileFunction · 0.50

Tested by

no test coverage detected