diff --git a/rehlds/engine/net_ws.cpp b/rehlds/engine/net_ws.cpp index 3a27e9c..ed2aa55 100644 --- a/rehlds/engine/net_ws.cpp +++ b/rehlds/engine/net_ws.cpp @@ -435,7 +435,7 @@ qboolean NET_StringToAdr(const char *s, netadr_t *a) return TRUE; } -qboolean NET_IsLocalAddress(netadr_t& adr) +qboolean NET_IsLocalAddress(const netadr_t& adr) { return adr.type == NA_LOOPBACK ? TRUE : FALSE; } diff --git a/rehlds/engine/net_ws.h b/rehlds/engine/net_ws.h index 70b42ab..6277935 100644 --- a/rehlds/engine/net_ws.h +++ b/rehlds/engine/net_ws.h @@ -175,7 +175,7 @@ char *NET_AdrToString(const netadr_t& a); char *NET_BaseAdrToString(netadr_t& a); qboolean NET_StringToSockaddr(const char *s, struct sockaddr *sadr); qboolean NET_StringToAdr(const char *s, netadr_t *a); -qboolean NET_IsLocalAddress(netadr_t& adr); +qboolean NET_IsLocalAddress(const netadr_t& adr); char *NET_ErrorString(int code); void NET_TransferRawData(sizebuf_t *msg, unsigned char *pStart, int nSize); qboolean NET_GetLoopPacket(netsrc_t sock, netadr_t *in_from_, sizebuf_t *msg); diff --git a/rehlds/engine/sv_main.cpp b/rehlds/engine/sv_main.cpp index 00520a3..c22a672 100644 --- a/rehlds/engine/sv_main.cpp +++ b/rehlds/engine/sv_main.cpp @@ -1803,8 +1803,15 @@ int g_oldest_challenge = 0; #endif bool EXT_FUNC SV_CheckChallenge_api(const netadr_t &adr, int nChallengeValue) { - netadr_t localAdr = adr; - return SV_CheckChallenge(&localAdr, nChallengeValue) != 0; + if (NET_IsLocalAddress(adr)) + return TRUE; + + for (int i = 0; i < MAX_CHALLENGES; i++) { + if (NET_CompareBaseAdr(adr, g_rg_sv_challenges[i].adr)) + return nChallengeValue == g_rg_sv_challenges[i].challenge; + } + + return FALSE; } int SV_CheckChallenge(netadr_t *adr, int nChallengeValue) @@ -1813,7 +1820,7 @@ int SV_CheckChallenge(netadr_t *adr, int nChallengeValue) Sys_Error("%s: Null address\n", __func__); if (NET_IsLocalAddress(*adr)) - return 1; + return TRUE; for (int i = 0; i < MAX_CHALLENGES; i++) { @@ -1822,13 +1829,13 @@ int SV_CheckChallenge(netadr_t *adr, int nChallengeValue) if (nChallengeValue != g_rg_sv_challenges[i].challenge) { SV_RejectConnection(adr, "Bad challenge.\n"); - return 0; + return FALSE; } - return 1; + return TRUE; } } SV_RejectConnection(adr, "No challenge for your address.\n"); - return 0; + return FALSE; } int SV_CheckIPRestrictions(netadr_t *adr, int nAuthProtocol)