From e2be6491ba9c2616a23ab9cefd4a201b5db8221e Mon Sep 17 00:00:00 2001 From: WPMGPRoSToTeMa Date: Wed, 19 Oct 2016 20:32:05 +0300 Subject: [PATCH] Replaced Con_Printf to Con_DPrintf for net messages that can be used for flood (related to #247) Added player name and print to client for some net messages (not for all, need finish this in future) echo -> svc_print --- rehlds/engine/net.h | 6 ++++++ rehlds/engine/net_chan.cpp | 12 +++++++++++- rehlds/engine/net_ws.cpp | 18 +++++++----------- rehlds/engine/pr_cmds.cpp | 4 ++++ rehlds/engine/sv_main.cpp | 10 +++++----- rehlds/engine/sv_user.cpp | 5 +++++ 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/rehlds/engine/net.h b/rehlds/engine/net.h index 3557f11..d38615d 100644 --- a/rehlds/engine/net.h +++ b/rehlds/engine/net.h @@ -404,4 +404,10 @@ typedef struct netchan_s flow_t flow[MAX_FLOWS]; } netchan_t; +#ifdef REHLDS_FIXES +#define Con_NetPrintf Con_DPrintf +#else // REHLDS_FIXES +#define Con_NetPrintf Con_Printf +#endif // REHLDS_FIXES + #endif // GS_NET_H diff --git a/rehlds/engine/net_chan.cpp b/rehlds/engine/net_chan.cpp index 53a0228..a3637c2 100644 --- a/rehlds/engine/net_chan.cpp +++ b/rehlds/engine/net_chan.cpp @@ -1522,7 +1522,14 @@ qboolean Netchan_CopyNormalFragments(netchan_t *chan) #ifdef REHLDS_FIXES if (overflowed) { - Con_Printf("Netchan_CopyNormalFragments: Overflowed\n"); + if (chan->player_slot == 0) + { + Con_Printf("Netchan_CopyNormalFragments: Incoming overflowed\n"); + } + else + { + Con_Printf("Netchan_CopyNormalFragments: Incoming overflowed from %s\n", g_psvs.clients[chan->player_slot - 1].name); + } SZ_Clear(&net_message); @@ -1589,6 +1596,9 @@ qboolean Netchan_CopyFileFragments(netchan_t *chan) uncompressedSize = (unsigned int)MSG_ReadLong(); #ifdef REHLDS_FIXES + // TODO: this condition is invalid for server->client + // TODO: add console message for client + // TODO: add client name to message if (uncompressedSize > 1024 * 64) { Con_Printf("Received too large file (size=%u)\nFlushing input queue\n", uncompressedSize); Netchan_FlushIncoming(chan, 1); diff --git a/rehlds/engine/net_ws.cpp b/rehlds/engine/net_ws.cpp index 17e6c07..b14f7a8 100644 --- a/rehlds/engine/net_ws.cpp +++ b/rehlds/engine/net_ws.cpp @@ -881,7 +881,7 @@ qboolean NET_GetLong(unsigned char *pData, int size, int *outSize) if (packetNumber >= NET_WS_MAX_FRAGMENTS || packetCount > NET_WS_MAX_FRAGMENTS) { - Con_Printf("Malformed packet number (%i/%i)\n", packetNumber + 1, packetCount); + Con_NetPrintf("Malformed packet number (%i/%i)\n", packetNumber + 1, packetCount); return FALSE; } if (gNetSplit.currentSequence == -1 || sequenceNumber != gNetSplit.currentSequence) @@ -904,7 +904,7 @@ qboolean NET_GetLong(unsigned char *pData, int size, int *outSize) unsigned int packetPayloadSize = size - sizeof(SPLITPACKET); if (gNetSplitFlags[packetNumber] == sequenceNumber) { - Con_Printf( "NET_GetLong: Ignoring duplicated split packet %i of %i ( %i bytes )\n", + Con_NetPrintf( "NET_GetLong: Ignoring duplicated split packet %i of %i ( %i bytes )\n", packetNumber + 1, packetCount, packetPayloadSize ); } @@ -925,7 +925,7 @@ qboolean NET_GetLong(unsigned char *pData, int size, int *outSize) if (SPLIT_SIZE * packetNumber + packetPayloadSize > MAX_UDP_PACKET) { - Con_Printf("Malformed packet size (%i, %i)\n", SPLIT_SIZE * packetNumber, packetPayloadSize); + Con_NetPrintf("Malformed packet size (%i, %i)\n", SPLIT_SIZE * packetNumber, packetPayloadSize); #ifdef REHLDS_FIXES gNetSplit.currentSequence = -1; #endif @@ -944,7 +944,7 @@ qboolean NET_GetLong(unsigned char *pData, int size, int *outSize) { if (gNetSplitFlags[i] != gNetSplit.currentSequence) { - Con_Printf( + Con_NetPrintf( "Split packet without all %i parts, part %i had wrong sequence %i/%i\n", packetCount, i + 1, @@ -970,7 +970,7 @@ qboolean NET_GetLong(unsigned char *pData, int size, int *outSize) #ifdef REHLDS_FIXES *outSize = 0; #endif - Con_Printf("Split packet too large! %d bytes\n", gNetSplit.totalSize); + Con_NetPrintf("Split packet too large! %d bytes\n", gNetSplit.totalSize); return FALSE; } } @@ -1044,7 +1044,7 @@ qboolean NET_QueuePacket(netsrc_t sock) if (ret != MAX_UDP_PACKET) break; - Con_Printf("NET_QueuePacket: Oversize packet from %s\n", NET_AdrToString(in_from)); + Con_NetPrintf("NET_QueuePacket: Oversize packet from %s\n", NET_AdrToString(in_from)); } if (ret == -1 || ret == MAX_UDP_PACKET) { @@ -1060,11 +1060,7 @@ qboolean NET_QueuePacket(netsrc_t sock) } else { -#ifdef REHLDS_FIXES - Con_DPrintf("Invalid split packet length %i\n", in_message.cursize); -#else - Con_Printf("Invalid split packet length %i\n", in_message.cursize); -#endif + Con_NetPrintf("Invalid split packet length %i\n", in_message.cursize); return FALSE; } } diff --git a/rehlds/engine/pr_cmds.cpp b/rehlds/engine/pr_cmds.cpp index af83080..ebb6e9a 100644 --- a/rehlds/engine/pr_cmds.cpp +++ b/rehlds/engine/pr_cmds.cpp @@ -207,7 +207,11 @@ void EXT_FUNC PF_sprint(char *s, int entnum) client_t* client = &g_psvs.clients[entnum - 1]; if (!client->fakeclient) { +#ifdef REHLDS_FIXES + MSG_WriteByte(&client->netchan.message, svc_print); +#else // REHLDS_FIXES MSG_WriteChar(&client->netchan.message, svc_print); +#endif // REHLDS_FIXES MSG_WriteString(&client->netchan.message, s); } } diff --git a/rehlds/engine/sv_main.cpp b/rehlds/engine/sv_main.cpp index 1208ddd..88eb1b1 100644 --- a/rehlds/engine/sv_main.cpp +++ b/rehlds/engine/sv_main.cpp @@ -1624,8 +1624,12 @@ void SV_New_f(void) if (!gEntityInterface.pfnClientConnect(ent, szName, szAddress, szRejectReason)) { // Reject the connection and drop the client. +#ifdef REHLDS_FIXES + SV_ClientPrintf("%s\n", szRejectReason); +#else // REHLDS_FIXES MSG_WriteByte(&host_client->netchan.message, svc_stufftext); MSG_WriteString(&host_client->netchan.message, va("echo %s\n", szRejectReason)); +#endif // REHLDS_FIXES SV_DropClient(host_client, FALSE, "Server refused connection because: %s", szRejectReason); return; } @@ -3492,11 +3496,7 @@ void SV_ConnectionlessPacket(void) } else if (c[0] == A2A_ACK && (c[1] == 0 || c[1] == '\n')) { -#ifdef REHLDS_FIXES - Con_DPrintf("A2A_ACK from %s\n", NET_AdrToString(net_from)); -#else // REHLDS_FIXES - Con_Printf("A2A_ACK from %s\n", NET_AdrToString(net_from)); -#endif // REHLDS_FIXES + Con_NetPrintf("A2A_ACK from %s\n", NET_AdrToString(net_from)); } else if (c[0] == A2A_GETCHALLENGE || c[0] == A2S_INFO || c[0] == A2S_PLAYER || c[0] == A2S_RULES || c[0] == S2A_LOGSTRING || c[0] == M2S_REQUESTRESTART || c[0] == M2A_CHALLENGE) diff --git a/rehlds/engine/sv_user.cpp b/rehlds/engine/sv_user.cpp index 3a85708..c61ad45 100644 --- a/rehlds/engine/sv_user.cpp +++ b/rehlds/engine/sv_user.cpp @@ -1778,7 +1778,12 @@ void SV_ExecuteClientMessage(client_t *cl) { if (msg_badread) { +#ifdef REHLDS_FIXES + Con_Printf("SV_ReadClientMessage: badread on %s\n", host_client->name); + SV_ClientPrintf("Badread\n"); +#else // REHLDS_FIXES Con_Printf("SV_ReadClientMessage: badread\n"); +#endif // REHLDS_FIXES return; }