SRB2/src/d_netfil.h

161 lines
4.3 KiB
C
Raw Normal View History

2014-03-15 16:59:03 +00:00
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 1998-2000 by DooM Legacy Team.
2022-03-03 19:24:46 +00:00
// Copyright (C) 1999-2022 by Sonic Team Junior.
2014-03-15 16:59:03 +00:00
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file d_netfil.h
/// \brief File transferring related structs and functions.
#ifndef __D_NETFIL__
#define __D_NETFIL__
2020-01-22 22:08:57 +00:00
#include "d_net.h"
#include "d_clisrv.h"
2014-03-15 16:59:03 +00:00
#include "w_wad.h"
typedef enum
{
SF_FILE,
SF_Z_RAM,
SF_RAM,
SF_NOFREERAM
} freemethod_t;
typedef enum
{
2021-12-02 22:50:44 +00:00
FS_NOTCHECKED,
2014-03-15 16:59:03 +00:00
FS_NOTFOUND,
FS_FOUND,
FS_REQUESTED,
FS_DOWNLOADING,
2016-12-31 18:26:33 +00:00
FS_OPEN, // Is opened and used in w_wad
2014-03-15 16:59:03 +00:00
FS_MD5SUMBAD
} filestatus_t;
2021-12-02 22:50:44 +00:00
typedef enum
{
FILENEEDED_WAD,
FILENEEDED_SAVEGAME,
FILENEEDED_LUAFILE
} fileneededtype_t;
2014-03-15 16:59:03 +00:00
typedef struct
{
char filename[MAX_WADPATH];
UINT8 md5sum[16];
filestatus_t status; // The value returned by recsearch
2021-12-02 22:50:44 +00:00
UINT8 willsend; // Is the server willing to send it?
UINT8 folder; // File is a folder
fileneededtype_t type;
boolean justdownloaded; // To prevent late fragments from causing an I_Error
2016-12-31 18:26:33 +00:00
// Used only for download
FILE *file;
boolean *receivedfragments;
UINT32 fragmentsize;
UINT8 iteration;
fileack_pak *ackpacket;
2014-03-15 16:59:03 +00:00
UINT32 currentsize;
UINT32 totalsize;
UINT32 ackresendposition; // Used when resuming downloads
2014-03-15 16:59:03 +00:00
} fileneeded_t;
2021-03-23 02:56:55 +00:00
#define FILENEEDEDSIZE 23
2014-03-15 16:59:03 +00:00
extern INT32 fileneedednum;
2021-12-02 22:50:44 +00:00
extern fileneeded_t *fileneeded;
extern char downloaddir[512];
2014-03-15 16:59:03 +00:00
extern INT32 lastfilenum;
2021-12-02 22:50:44 +00:00
extern INT32 downloadcompletednum;
extern UINT32 downloadcompletedsize;
extern INT32 totalfilesrequestednum;
extern UINT32 totalfilesrequestedsize;
2014-03-15 16:59:03 +00:00
2021-12-02 22:50:44 +00:00
void AllocFileNeeded(INT32 size);
void FreeFileNeeded(void);
UINT8 *PutFileNeeded(UINT16 firstfile);
void D_ParseFileneeded(INT32 fileneedednum_parm, UINT8 *fileneededstr, UINT16 firstfile);
2014-03-15 16:59:03 +00:00
void CL_PrepareDownloadSaveGame(const char *tmpsave);
INT32 CL_CheckFiles(void);
2021-12-02 22:50:44 +00:00
boolean CL_LoadServerFiles(void);
2020-05-12 17:06:40 +00:00
void AddRamToSendQueue(INT32 node, void *data, size_t size, freemethod_t freemethod,
2014-03-15 16:59:03 +00:00
UINT8 fileid);
2020-05-12 17:06:40 +00:00
void FileSendTicker(void);
void PT_FileAck(SINT8 node);
void PT_FileReceived(SINT8 node);
2020-05-12 17:06:40 +00:00
boolean SendingFile(INT32 node);
2014-03-15 16:59:03 +00:00
void FileReceiveTicker(void);
void PT_FileFragment(SINT8 node, INT32 netconsole);
2014-03-15 16:59:03 +00:00
boolean CL_CheckDownloadable(void);
2020-05-12 17:06:40 +00:00
boolean CL_SendFileRequest(void);
void PT_RequestFile(SINT8 node);
2014-03-15 16:59:03 +00:00
2020-01-22 22:08:57 +00:00
typedef enum
{
LFTNS_NONE, // This node is not connected
2020-01-22 22:08:57 +00:00
LFTNS_WAITING, // This node is waiting for the server to send the file
LFTNS_ASKED, // The server has told the node they're ready to send the file
2020-01-22 22:08:57 +00:00
LFTNS_SENDING, // The server is sending the file to this node
LFTNS_SENT // The node already has the file
2020-01-22 22:08:57 +00:00
} luafiletransfernodestatus_t;
typedef struct luafiletransfer_s
{
char *filename;
char *realfilename;
char mode[4]; // rb+/wb+/ab+ + null character
INT32 id; // Callback ID
boolean ongoing;
2020-01-22 22:08:57 +00:00
luafiletransfernodestatus_t nodestatus[MAXNETNODES];
tic_t nodetimeouts[MAXNETNODES];
2020-01-22 22:08:57 +00:00
struct luafiletransfer_s *next;
} luafiletransfer_t;
extern luafiletransfer_t *luafiletransfers;
extern boolean waitingforluafiletransfer;
extern boolean waitingforluafilecommand;
extern char luafiledir[256 + 16];
2020-01-22 22:08:57 +00:00
void AddLuaFileTransfer(const char *filename, const char *mode);
2020-05-19 19:36:21 +00:00
void SV_PrepareSendLuaFile(void);
boolean AddLuaFileToSendQueue(INT32 node, const char *filename);
2020-01-22 22:08:57 +00:00
void SV_HandleLuaFileSent(UINT8 node);
void RemoveLuaFileTransfer(void);
2020-02-19 21:37:30 +00:00
void RemoveAllLuaFileTransfers(void);
2020-01-22 22:08:57 +00:00
void SV_AbortLuaFileTransfer(INT32 node);
void CL_PrepareDownloadLuaFile(void);
void Got_LuaFile(UINT8 **cp, INT32 playernum);
void StoreLuaFileCallback(INT32 id);
void RemoveLuaFileCallback(INT32 id);
void MakePathDirs(char *path);
2016-12-31 18:26:33 +00:00
void SV_AbortSendFiles(INT32 node);
2014-03-15 16:59:03 +00:00
void CloseNetFile(void);
void CL_AbortDownloadResume(void);
2014-03-15 16:59:03 +00:00
void Command_Downloads_f(void);
2014-03-15 16:59:03 +00:00
boolean fileexist(char *filename, time_t ptime);
2016-12-31 18:26:33 +00:00
// Search a file in the wadpath, return FS_FOUND when found
2014-03-15 16:59:03 +00:00
filestatus_t findfile(char *filename, const UINT8 *wantedmd5sum,
boolean completepath);
filestatus_t checkfilemd5(char *filename, const UINT8 *wantedmd5sum);
2021-03-23 02:56:55 +00:00
// Searches for a folder
filestatus_t findfolder(const char *path);
2014-03-15 16:59:03 +00:00
void nameonly(char *s);
size_t nameonlylength(const char *s);
#endif // __D_NETFIL__