2
0
mirror of https://github.com/rehlds/rehlds.git synced 2025-01-01 01:25:38 +03:00

Merge pull request #246 from WPMGPRoSToTeMa/master

Fixed typo in condition in Netchan_CopyFileFragments
This commit is contained in:
theAsmodai 2016-10-17 15:15:21 +03:00 committed by GitHub
commit 22ba13a53b

View File

@ -38,13 +38,13 @@ char gDownloadFile[256];
*/ */
#ifndef HOOK_ENGINE #ifndef HOOK_ENGINE
cvar_t net_log = { "net_log", "0", 0, 0.0f, NULL }; cvar_t net_log = { "net_log", "0", 0, 0.0f, nullptr};
cvar_t net_showpackets = { "net_showpackets", "0", 0, 0.0f, NULL }; cvar_t net_showpackets = { "net_showpackets", "0", 0, 0.0f, nullptr};
cvar_t net_showdrop = { "net_showdrop", "0", 0, 0.0f, NULL }; cvar_t net_showdrop = { "net_showdrop", "0", 0, 0.0f, nullptr};
cvar_t net_drawslider = { "net_drawslider", "0", 0, 0.0f, NULL }; cvar_t net_drawslider = { "net_drawslider", "0", 0, 0.0f, nullptr};
cvar_t net_chokeloopback = { "net_chokeloop", "0", 0, 0.0f, NULL }; cvar_t net_chokeloopback = { "net_chokeloop", "0", 0, 0.0f, nullptr};
cvar_t sv_filetransfercompression = { "sv_filetransfercompression", "1", 0, 0.0f, NULL }; cvar_t sv_filetransfercompression = { "sv_filetransfercompression", "1", 0, 0.0f, nullptr};
cvar_t sv_filetransfermaxsize = { "sv_filetransfermaxsize", "10485760", 0, 0.0f, NULL }; cvar_t sv_filetransfermaxsize = { "sv_filetransfermaxsize", "10485760", 0, 0.0f, nullptr};
#else //HOOK_ENGINE #else //HOOK_ENGINE
@ -63,7 +63,7 @@ void Netchan_UnlinkFragment(fragbuf_t *buf, fragbuf_t **list)
{ {
fragbuf_t *search; fragbuf_t *search;
if (list == NULL) if (list == nullptr)
{ {
Con_Printf(__FUNCTION__ ": Asked to unlink fragment from empty list, ignored\n"); Con_Printf(__FUNCTION__ ": Asked to unlink fragment from empty list, ignored\n");
return; return;
@ -144,7 +144,7 @@ void Netchan_ClearFragbufs(fragbuf_t **ppbuf)
Mem_Free(buf); Mem_Free(buf);
buf = n; buf = n;
} }
*ppbuf = NULL; *ppbuf = nullptr;
} }
/* <65810> ../engine/net_chan.c:220 */ /* <65810> ../engine/net_chan.c:220 */
@ -161,7 +161,7 @@ void Netchan_ClearFragments(netchan_t *chan)
Mem_Free(wait); Mem_Free(wait);
wait = next; wait = next;
} }
chan->waitlist[i] = NULL; chan->waitlist[i] = nullptr;
Netchan_ClearFragbufs(&chan->fragbufs[i]); Netchan_ClearFragbufs(&chan->fragbufs[i]);
Netchan_FlushIncoming(chan, i); Netchan_FlushIncoming(chan, i);
@ -195,7 +195,7 @@ void Netchan_Clear(netchan_t *chan)
if (chan->tempbuffer) if (chan->tempbuffer)
{ {
Mem_Free(chan->tempbuffer); Mem_Free(chan->tempbuffer);
chan->tempbuffer = NULL; chan->tempbuffer = nullptr;
} }
chan->tempbuffersize = 0; chan->tempbuffersize = 0;
} }
@ -537,9 +537,8 @@ void Netchan_Transmit(netchan_t *chan, int length, byte *data)
// Deal with packets that are too small for some networks // Deal with packets that are too small for some networks
if (sb_send.cursize < 16) // Packet too small for some networks if (sb_send.cursize < 16) // Packet too small for some networks
{ {
int i;
// Go ahead and pad a full 16 extra bytes -- this only happens during authentication / signon // Go ahead and pad a full 16 extra bytes -- this only happens during authentication / signon
for (i = sb_send.cursize; i < 16; i++) for (int i = sb_send.cursize; i < 16; i++)
{ {
// Note that the server can parse svc_nop, too. // Note that the server can parse svc_nop, too.
MSG_WriteByte(&sb_send, svc_nop); MSG_WriteByte(&sb_send, svc_nop);
@ -601,7 +600,7 @@ fragbuf_t *Netchan_FindBufferById(fragbuf_t **pplist, int id, qboolean allocate)
} }
if (!allocate) if (!allocate)
return NULL; return nullptr;
// Create new entry // Create new entry
pnewbuf = Netchan_AllocFragbuf(); pnewbuf = Netchan_AllocFragbuf();
@ -981,7 +980,7 @@ void Netchan_FragSend(netchan_t *chan)
} }
#endif // REHLDS_FIXES #endif // REHLDS_FIXES
wait->next = NULL; wait->next = nullptr;
// Copy in to fragbuf // Copy in to fragbuf
chan->fragbufs[i] = wait->fragbufs; chan->fragbufs[i] = wait->fragbufs;
@ -999,7 +998,7 @@ void Netchan_AddBufferToList(fragbuf_t **pplist, fragbuf_t *pbuf)
fragbuf_t *pprev, *n; fragbuf_t *pprev, *n;
int id1, id2; int id1, id2;
pbuf->next = NULL; pbuf->next = nullptr;
if (!pplist) if (!pplist)
return; return;
@ -1044,7 +1043,7 @@ fragbuf_t *Netchan_AllocFragbuf(void)
buf->frag_message.data = buf->frag_message_buf; buf->frag_message.data = buf->frag_message_buf;
buf->frag_message.maxsize = sizeof(buf->frag_message_buf); buf->frag_message.maxsize = sizeof(buf->frag_message_buf);
buf->frag_message.buffername = "Frag Buffer Alloc'd"; buf->frag_message.buffername = "Frag Buffer Alloc'd";
buf->next = 0; buf->next = nullptr;
return buf; return buf;
} }
@ -1054,7 +1053,7 @@ void Netchan_AddFragbufToTail(fragbufwaiting_t *wait, fragbuf_t *buf)
{ {
fragbuf_t *p; fragbuf_t *p;
buf->next = 0; buf->next = nullptr;
wait->fragbufcount++; wait->fragbufcount++;
p = wait->fragbufs; p = wait->fragbufs;
@ -1475,7 +1474,7 @@ void Netchan_FlushIncoming(netchan_t *chan, int stream)
p = n; p = n;
}; };
chan->incomingbufs[stream] = NULL; chan->incomingbufs[stream] = nullptr;
chan->incomingready[stream] = FALSE; chan->incomingready[stream] = FALSE;
} }
@ -1527,8 +1526,8 @@ qboolean Netchan_CopyNormalFragments(netchan_t *chan)
SZ_Clear(&net_message); SZ_Clear(&net_message);
chan->incomingbufs[FRAG_NORMAL_STREAM] = NULL; chan->incomingbufs[FRAG_NORMAL_STREAM] = nullptr;
chan->incomingready[FRAG_NORMAL_STREAM] = false; chan->incomingready[FRAG_NORMAL_STREAM] = FALSE;
return FALSE; return FALSE;
} }
@ -1543,8 +1542,8 @@ qboolean Netchan_CopyNormalFragments(netchan_t *chan)
net_message.cursize = uncompressedSize; net_message.cursize = uncompressedSize;
} }
chan->incomingbufs[FRAG_NORMAL_STREAM] = NULL; chan->incomingbufs[FRAG_NORMAL_STREAM] = nullptr;
chan->incomingready[FRAG_NORMAL_STREAM] = false; chan->incomingready[FRAG_NORMAL_STREAM] = FALSE;
return TRUE; return TRUE;
} }
@ -1617,8 +1616,8 @@ qboolean Netchan_CopyFileFragments(netchan_t *chan)
Netchan_FlushIncoming(chan, 1); Netchan_FlushIncoming(chan, 1);
return FALSE; return FALSE;
} }
// This prohibits to write files to FS on server
if (g_pcls.state != ca_dedicated && filename[0] != '!') if (g_pcls.state == ca_dedicated && filename[0] != '!')
{ {
Con_Printf("File fragment received with bad path, ignoring (2)\n"); Con_Printf("File fragment received with bad path, ignoring (2)\n");
Netchan_FlushIncoming(chan, 1); Netchan_FlushIncoming(chan, 1);
@ -1699,58 +1698,51 @@ qboolean Netchan_CopyFileFragments(netchan_t *chan)
} }
else else
{ {
char filedir[MAX_PATH];
#ifdef REHLDS_FIXES char *pszFileName;
//Don't allow to write files to FS on server FileHandle_t handle;
if (chan == &g_pcls.netchan)
#endif // REHLDS_FIXES
{
char filedir[MAX_PATH];
char *pszFileName;
FileHandle_t handle;
#ifdef REHLDS_CHECKS #ifdef REHLDS_CHECKS
Q_strncpy(filedir, filename, sizeof(filedir) - 1); Q_strncpy(filedir, filename, sizeof(filedir) - 1);
filedir[sizeof(filedir) - 1] = 0; filedir[sizeof(filedir) - 1] = 0;
#else #else
Q_strncpy(filedir, filename, sizeof(filedir)); Q_strncpy(filedir, filename, sizeof(filedir));
#endif // REHLDS_CHECKS #endif // REHLDS_CHECKS
COM_FixSlashes(filedir); COM_FixSlashes(filedir);
pszFileName = Q_strrchr(filedir, '\\'); pszFileName = Q_strrchr(filedir, '\\');
if (pszFileName) if (pszFileName)
{ {
*pszFileName = 0; *pszFileName = 0;
#ifdef REHLDS_FIXES #ifdef REHLDS_FIXES
FS_CreateDirHierarchy(filedir, "GAMEDOWNLOAD");
#endif
}
#ifndef REHLDS_FIXES
FS_CreateDirHierarchy(filedir, "GAMEDOWNLOAD"); FS_CreateDirHierarchy(filedir, "GAMEDOWNLOAD");
#endif #endif
handle = FS_OpenPathID(filename, "wb", "GAMEDOWNLOAD"); }
if (!handle)
{ #ifndef REHLDS_FIXES
Con_Printf("File open failed %s\n", filename); FS_CreateDirHierarchy(filedir, "GAMEDOWNLOAD");
Netchan_FlushIncoming(chan, 1); #endif
handle = FS_OpenPathID(filename, "wb", "GAMEDOWNLOAD");
if (!handle)
{
Con_Printf("File open failed %s\n", filename);
Netchan_FlushIncoming(chan, 1);
#ifdef REHLDS_FIXES #ifdef REHLDS_FIXES
Mem_Free(buffer); Mem_Free(buffer);
#endif #endif
return FALSE; return FALSE;
}
Sys_Printf("COM_WriteFile: %s\n", filename);
FS_Write(buffer, pos, 1, handle);
FS_Close(handle);
} }
Sys_Printf("COM_WriteFile: %s\n", filename);
FS_Write(buffer, pos, 1, handle);
FS_Close(handle);
Mem_Free(buffer); Mem_Free(buffer);
} }
SZ_Clear(&net_message); SZ_Clear(&net_message);
chan->incomingbufs[FRAG_FILE_STREAM] = 0; chan->incomingbufs[FRAG_FILE_STREAM] = nullptr;
chan->incomingready[FRAG_FILE_STREAM] = 0; chan->incomingready[FRAG_FILE_STREAM] = FALSE;
msg_readcount = 0; msg_readcount = 0;
return TRUE; return TRUE;
} }