From: Mario Date: Sat, 15 Jul 2017 15:12:08 +0000 (+1000) Subject: Rewrite PlayerInIDList and allow partial IPs in forced team lists X-Git-Tag: xonotic-v0.8.5~2638 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=03ad91be14289755fee5873208001b1c7a1ab00b;p=xonotic%2Fxonotic-data.pk3dir.git Rewrite PlayerInIDList and allow partial IPs in forced team lists --- diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index bbfe2eacd..db62a801f 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -1053,25 +1053,38 @@ void FixClientCvars(entity e) MUTATOR_CALLHOOK(FixClientCvars, e); } -float PlayerInIDList(entity p, string idlist) +bool findinlist_abbrev(string tofind, string list) { - float n, i; - string s; + // this function allows abbreviated strings! + FOREACH_WORD(list, it == substring(tofind, 0, strlen(it)), + { + return true; + }); + + return false; +} +bool PlayerInIPList(entity p, string iplist) +{ + // some safety checks (never allow local?) + if(p.netaddress == "local" || p.netaddress == "" || !IS_REAL_CLIENT(p)) + return false; + + return findinlist_abbrev(p.netaddress, iplist); +} + +bool PlayerInIDList(entity p, string idlist) +{ // NOTE: we do NOT check crypto_idfp_signed here, an unsigned ID is fine too for this - if (!p.crypto_idfp) - return 0; + if(!p.crypto_idfp) + return false; - // this function allows abbreviated player IDs too! - n = tokenize_console(idlist); - for(i = 0; i < n; ++i) - { - s = argv(i); - if(s == substring(p.crypto_idfp, 0, strlen(s))) - return 1; - } + return findinlist_abbrev(p.crypto_idfp, idlist); +} - return 0; +bool PlayerInList(entity player, string list) +{ + return PlayerInIDList(player, list) || PlayerInIPList(player, list); } #ifdef DP_EXT_PRECONNECT @@ -1130,10 +1143,10 @@ void ClientConnect(entity this) } } } - else if (PlayerInIDList(this, autocvar_g_forced_team_red)) this.team_forced = NUM_TEAM_1; - else if (PlayerInIDList(this, autocvar_g_forced_team_blue)) this.team_forced = NUM_TEAM_2; - else if (PlayerInIDList(this, autocvar_g_forced_team_yellow)) this.team_forced = NUM_TEAM_3; - else if (PlayerInIDList(this, autocvar_g_forced_team_pink)) this.team_forced = NUM_TEAM_4; + else if (PlayerInList(this, autocvar_g_forced_team_red)) this.team_forced = NUM_TEAM_1; + else if (PlayerInList(this, autocvar_g_forced_team_blue)) this.team_forced = NUM_TEAM_2; + else if (PlayerInList(this, autocvar_g_forced_team_yellow)) this.team_forced = NUM_TEAM_3; + else if (PlayerInList(this, autocvar_g_forced_team_pink)) this.team_forced = NUM_TEAM_4; else switch (autocvar_g_forced_team_otherwise) { default: this.team_forced = 0; break;