2
0
mirror of https://github.com/rehlds/rehlds.git synced 2024-12-28 15:45:46 +03:00

Reworked SV_CheckChallenge_api function

This commit is contained in:
Asmodai 2018-09-15 12:21:01 +03:00
parent 469908f5c5
commit 834c5a9eda
3 changed files with 15 additions and 8 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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)