Fix '+set tls_provider foo' not working properly. Fixes https://github.com/fte-team/fteqw/issues/162

This commit is contained in:
Shpoike 2023-01-26 07:12:51 +00:00
parent f8962b6c47
commit d97fd1bfc9
2 changed files with 31 additions and 32 deletions

View file

@ -897,6 +897,7 @@ Cvar_Set
static cvar_t *Cvar_SetCore (cvar_t *var, const char *value, qboolean force) static cvar_t *Cvar_SetCore (cvar_t *var, const char *value, qboolean force)
{ //fixme: force should probably be a latch bitmask { //fixme: force should probably be a latch bitmask
char *latch=NULL; char *latch=NULL;
qboolean changed;
COM_AssertMainThread("Cvar_SetCore"); COM_AssertMainThread("Cvar_SetCore");
@ -1002,33 +1003,33 @@ static cvar_t *Cvar_SetCore (cvar_t *var, const char *value, qboolean force)
latch = var->string;//save off the old value (so cvar_set(var, var->string) works) latch = var->string;//save off the old value (so cvar_set(var, var->string) works)
var->string = (char*)Z_Malloc (Q_strlen(value)+1); changed = (!latch) || strcmp(latch, value);
Q_strcpy (var->string, value);
var->value = Q_atof (var->string);
var->ival = Q_atoi (var->string);
var->flags &= ~CVAR_TEAMPLAYTAINT; var->flags &= ~CVAR_TEAMPLAYTAINT;
if (changed)
{ {
char *str = COM_Parse(var->string); var->string = Z_StrDup (value);
var->vec4[0] = atof(com_token); var->value = Q_atof (var->string);
str = COM_Parse(str); var->ival = Q_atoi (var->string);
var->vec4[1] = atof(com_token);
str = COM_Parse(str);
var->vec4[2] = atof(com_token);
if (!str || !*str)
var->vec4[3] = 1;
else
{ {
char *str = COM_Parse(var->string);
var->vec4[0] = atof(com_token);
str = COM_Parse(str); str = COM_Parse(str);
var->vec4[3] = atof(com_token); var->vec4[1] = atof(com_token);
str = COM_Parse(str);
var->vec4[2] = atof(com_token);
if (!str || !*str)
var->vec4[3] = 1;
else
{
str = COM_Parse(str);
var->vec4[3] = atof(com_token);
}
} }
}
if (latch) if (latch)
{ { //don't do this on registration.
if (strcmp(latch, value))
{
var->modified=true; //only modified if it changed. var->modified=true; //only modified if it changed.
var->modifiedcount++; var->modifiedcount++;
if (var->callback) if (var->callback)
@ -1049,6 +1050,7 @@ static cvar_t *Cvar_SetCore (cvar_t *var, const char *value, qboolean force)
#endif #endif
} }
} }
if ((var->flags & CVAR_ARCHIVE) && !(var->flags & CVAR_SERVEROVERRIDE) && cl_warncmd.ival) if ((var->flags & CVAR_ARCHIVE) && !(var->flags & CVAR_SERVEROVERRIDE) && cl_warncmd.ival)
{ {
if (var->latched_string) if (var->latched_string)
@ -1058,12 +1060,11 @@ static cvar_t *Cvar_SetCore (cvar_t *var, const char *value, qboolean force)
} }
else else
{ {
if (strcmp(latch, value)) if (!latch || strcmp(latch, value))
Cvar_ConfigChanged(); Cvar_ConfigChanged();
} }
} }
Z_Free (latch); // free the old value string Z_Free (latch); // free the old value string
} }

View file

@ -160,16 +160,11 @@ static void QDECL NET_Enable_DTLS_Changed(struct cvar_s *var, char *oldvalue)
if (!*var->string) if (!*var->string)
var->ival = 0; //FIXME: change to 1 then 2 when better tested. var->ival = 0; //FIXME: change to 1 then 2 when better tested.
if (var->ival && svs.sockets) if (svs.sockets)
{ {
if (!svs.sockets->dtlsfuncs) svs.sockets->dtlsfuncs = (var->ival)?DTLS_InitServer():NULL;
svs.sockets->dtlsfuncs = DTLS_InitServer(); if (!svs.sockets->dtlsfuncs && var->ival >= 2)
if (!svs.sockets->dtlsfuncs) Con_Printf("%sUnable to set %s to \"%s\", no DTLS provider available.\n", (var->ival >= 2)?CON_ERROR:CON_WARNING, var->name, var->string);
{
if (var->ival >= 2)
Con_Printf("%sUnable to set %s to \"%s\", no DTLS provider available.\n", (var->ival >= 2)?CON_ERROR:CON_WARNING, var->name, var->string);
var->ival = 0; //disable the cvar (internally) if we don't have a usable certificate. this allows us to default the cvar to enabled without it breaking otherwise.
}
} }
} }
cvar_t net_enable_dtls = CVARAFCD("net_enable_dtls", "", "sv_listen_dtls", 0, NET_Enable_DTLS_Changed, "Controls serverside dtls support.\n0: dtls blocked, not advertised.\n1: clientside choice.\n2: used where possible (recommended setting).\n3: disallow non-dtls clients (sv_port_tcp should be eg tls://[::]:27500 to also disallow unencrypted tcp connections)."); cvar_t net_enable_dtls = CVARAFCD("net_enable_dtls", "", "sv_listen_dtls", 0, NET_Enable_DTLS_Changed, "Controls serverside dtls support.\n0: dtls blocked, not advertised.\n1: clientside choice.\n2: used where possible (recommended setting).\n3: disallow non-dtls clients (sv_port_tcp should be eg tls://[::]:27500 to also disallow unencrypted tcp connections).");
@ -253,7 +248,8 @@ static void NET_TLS_Provider_Changed(struct cvar_s *var, char *oldvalue)
} }
#if defined(HAVE_DTLS) && defined(HAVE_SERVER) #if defined(HAVE_DTLS) && defined(HAVE_SERVER)
Cvar_ForceCallback(&net_enable_dtls); if (net_enable_dtls.string) //might not be registered yet...
Cvar_ForceCallback(&net_enable_dtls);
#endif #endif
} }
#endif #endif
@ -2133,6 +2129,8 @@ qboolean NET_StringToAdrMasked (const char *s, qboolean allowdns, netadr_t *a, n
qboolean NET_IsEncrypted(netadr_t *adr) qboolean NET_IsEncrypted(netadr_t *adr)
{ {
if (adr->type == NA_LOOPBACK)
return true; //might as well claim it, others can't snoop on it so...
#ifdef SUPPORT_ICE #ifdef SUPPORT_ICE
if (adr->type == NA_ICE && ICE_IsEncrypted(adr)) if (adr->type == NA_ICE && ICE_IsEncrypted(adr))
return true; return true;