From: terencehill Date: Sat, 13 Feb 2021 11:13:11 +0000 (+0100) Subject: Move the code that stores player name into the server db into its own function X-Git-Tag: xonotic-v0.8.5~512^2~6 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=093002e05eba9244783d60b958dbbaf98965c876;p=xonotic%2Fxonotic-data.pk3dir.git Move the code that stores player name into the server db into its own function --- diff --git a/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc b/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc index 83f9d2fb6..7ec85cdaf 100644 --- a/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc +++ b/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc @@ -2318,16 +2318,7 @@ MUTATOR_HOOKFUNCTION(ctf, GetPressedKeys) entity player = M_ARGV(0, entity); - if(CS_CVAR(player).cvar_cl_allow_uidtracking == 1 && CS_CVAR(player).cvar_cl_allow_uid2name == 1) - { - if (!player.stored_netname) - player.stored_netname = strzone(uid2name(player.crypto_idfp)); - if(player.stored_netname != player.netname) - { - db_put(ServerProgsDB, strcat("/uid2name/", player.crypto_idfp), player.netname); - strcpy(player.stored_netname, player.netname); - } - } + race_checkAndWriteName(player); } MUTATOR_HOOKFUNCTION(ctf, PortalTeleport) diff --git a/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc b/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc index bca0d1077..9861ab887 100644 --- a/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc +++ b/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc @@ -282,16 +282,7 @@ MUTATOR_HOOKFUNCTION(cts, GetPressedKeys) { entity player = M_ARGV(0, entity); - if(CS_CVAR(player).cvar_cl_allow_uidtracking == 1 && CS_CVAR(player).cvar_cl_allow_uid2name == 1) - { - if (!player.stored_netname) - player.stored_netname = strzone(uid2name(player.crypto_idfp)); - if(player.stored_netname != player.netname) - { - db_put(ServerProgsDB, strcat("/uid2name/", player.crypto_idfp), player.netname); - strcpy(player.stored_netname, player.netname); - } - } + race_checkAndWriteName(player); if (!IS_OBSERVER(player)) { diff --git a/qcsrc/common/gamemodes/gamemode/race/sv_race.qc b/qcsrc/common/gamemodes/gamemode/race/sv_race.qc index 8148dda2d..e092c91f1 100644 --- a/qcsrc/common/gamemodes/gamemode/race/sv_race.qc +++ b/qcsrc/common/gamemodes/gamemode/race/sv_race.qc @@ -328,16 +328,7 @@ MUTATOR_HOOKFUNCTION(rc, GetPressedKeys) { entity player = M_ARGV(0, entity); - if(CS_CVAR(player).cvar_cl_allow_uidtracking == 1 && CS_CVAR(player).cvar_cl_allow_uid2name == 1) - { - if (!player.stored_netname) - player.stored_netname = strzone(uid2name(player.crypto_idfp)); - if(player.stored_netname != player.netname) - { - db_put(ServerProgsDB, strcat("/uid2name/", player.crypto_idfp), player.netname); - strcpy(player.stored_netname, player.netname); - } - } + race_checkAndWriteName(player); if (!IS_OBSERVER(player)) { diff --git a/qcsrc/server/race.qc b/qcsrc/server/race.qc index 70a98083e..40b2ca148 100644 --- a/qcsrc/server/race.qc +++ b/qcsrc/server/race.qc @@ -30,6 +30,8 @@ #include #include +.string stored_netname; // TODO: store this information independently of race-based gamemodes + string uid2name(string myuid) { string s = db_get(ServerProgsDB, strcat("/uid2name/", myuid)); @@ -150,6 +152,20 @@ string race_readName(string map, float pos) return uid2name(db_get(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(pos)))); } +void race_checkAndWriteName(entity player) +{ + if(CS_CVAR(player).cvar_cl_allow_uidtracking == 1 && CS_CVAR(player).cvar_cl_allow_uid2name == 1) + { + if (!player.stored_netname) + player.stored_netname = strzone(uid2name(player.crypto_idfp)); + if(player.stored_netname != player.netname) + { + db_put(ServerProgsDB, strcat("/uid2name/", player.crypto_idfp), player.netname); + strcpy(player.stored_netname, player.netname); + } + } +} + const float MAX_CHECKPOINTS = 255; diff --git a/qcsrc/server/race.qh b/qcsrc/server/race.qh index 0bef0b59a..09aec8823 100644 --- a/qcsrc/server/race.qh +++ b/qcsrc/server/race.qh @@ -2,8 +2,6 @@ bool autocvar_g_allow_checkpoints; -.string stored_netname; // TODO: store this information independently of race-based gamemodes - float race_teams; // scores @@ -47,6 +45,7 @@ float race_GetFractionalLapCount(entity e); float race_readTime(string map, float pos); string race_readUID(string map, float pos); string race_readName(string map, float pos); +void race_checkAndWriteName(entity player); void race_ClearRecords(); void race_SendNextCheckpoint(entity e, float spec); void race_PreparePlayer(entity this);