]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'Mario/showspecs' into 'master'
authorTimePath <andrew.hardaker1995@gmail.com>
Sat, 6 Aug 2016 06:46:36 +0000 (06:46 +0000)
committerTimePath <andrew.hardaker1995@gmail.com>
Sat, 6 Aug 2016 06:46:36 +0000 (06:46 +0000)
Merge branch Mario/showspecs (M merge request)

Shows who's spectating you (disabled by default).

See merge request !340

defaultXonotic.cfg
qcsrc/client/autocvars.qh
qcsrc/client/hud/panel/infomessages.qc
qcsrc/client/main.qc
qcsrc/client/main.qh
qcsrc/server/autocvars.qh
qcsrc/server/cl_client.qc

index 11ba8e4ff3428a486bd95b67d71d032b77c63f4f..afa60ccf6a19488d963abc4165a04d9cb91f122c 100644 (file)
@@ -1452,6 +1452,9 @@ set cl_fullbright_items 0 "enable fullbright items (if server allows, controled
 set cl_weapon_stay_color "2 0.5 0.5" "Color of picked up weapons when g_weapon_stay > 0"
 set cl_weapon_stay_alpha 0.75 "Alpha of picked up weapons when g_weapon_stay > 0"
 
+set sv_showspectators 0 "Show who's spectating who in the player info panel. Shouldn't be used on competitive servers, also disable when watching a suspected cheater"
+seta cl_showspectators 1
+
 // Facility for config.cfg use ONLY.
 // Interpreted in post-config.cfg.
 seta menu_forced_saved_cvars "" "These cvars will always be saved, despite engine/Xonotic cvar saving status"
index d159cd3170e27426c5d40653f8f6141c463e6ccb..ec9ac10ae622f580953e8da23b52f165f127d4ab 100644 (file)
@@ -464,6 +464,7 @@ string autocvar__cl_playermodel;
 float autocvar_cl_deathglow;
 bool autocvar_developer_csqcentities;
 float autocvar_g_jetpack_attenuation;
+bool autocvar_cl_showspectators;
 string autocvar_crosshair_hmg = "";
 vector autocvar_crosshair_hmg_color = '0.2 1.0 0.2';
 float autocvar_crosshair_hmg_alpha = 1;
index 39c5bc64392526f637f2a3fd38c6c586b5b78bca..1839263a4563b7f1cd7a73bc3f2db8abad12c15e 100644 (file)
@@ -195,6 +195,24 @@ void HUD_InfoMessages()
                                }
                        }
                }
+
+               if(autocvar_cl_showspectators)
+               if(num_spectators)
+               //if(spectatee_status != -1)
+               {
+                       s = ((spectatee_status) ? _("^1Spectating this player:") : _("^1Spectating you:"));
+                       //drawInfoMessage(s)
+                       int limit = min(num_spectators, MAX_SPECTATORS);
+                       for(int i = 0; i < limit; ++i)
+                       {
+                               float slot = spectatorlist[i];
+                               if(i == 0)
+                                       s = strcat(s, " ^7", entcs_GetName(slot));
+                               else
+                                       s = strcat("^7", entcs_GetName(slot));
+                               drawInfoMessage(s);
+                       }
+               }
        }
        else
        {
index 1733008a5c5f6326ea03de2f5bb56de2b1b3bf14..2905b8b2da90e8ff51c6e135e6bac8206586a846 100644 (file)
@@ -516,6 +516,22 @@ NET_HANDLE(ENT_CLIENT_CLIENTDATA, bool isnew)
        else
                angles_held_status = 0;
 
+       if(f & 16)
+       {
+               num_spectators = ReadByte();
+
+               float i, slot;
+
+               for(i = 0; i < MAX_SPECTATORS; ++i)
+                       spectatorlist[i] = 0; // reset list first
+
+               for(i = 0; i < num_spectators; ++i)
+               {
+                       slot = ReadByte();
+                       spectatorlist[i] = slot - 1;
+               }
+       }
+
        return = true;
 
        if(newspectatee_status != spectatee_status)
index ffb853d2f8379d93d47bac930923b1813defb23e..b47836f23caca4f5ec4b3fb400d5f5e1034d5ee1 100644 (file)
@@ -151,6 +151,11 @@ float g_trueaim_minrange;
 
 float hud;
 float view_quality;
+
+int num_spectators;
+const int MAX_SPECTATORS = 7;
+int spectatorlist[MAX_SPECTATORS];
+
 int framecount;
 .float health;
 
index f66b77a068145eadb0460bfdd776d531aed6b454..188cc713137adff0ff81112ecc795719b4abe612 100644 (file)
@@ -574,3 +574,4 @@ float autocvar_sv_stopspeed;
 float autocvar_sv_airaccelerate;
 float autocvar_sv_airstopaccelerate;
 float autocvar_sv_track_canjump;
+bool autocvar_sv_showspectators;
index 4a86c936e9b653fb3b1096b85a2f7cb066e65df0..8de814507c39e53e16436826f921b30db1bea6b3 100644 (file)
@@ -75,6 +75,30 @@ void send_CSQC_teamnagger() {
        WriteHeader(MSG_BROADCAST, TE_CSQC_TEAMNAGGER);
 }
 
+int CountSpectators(entity player, entity to)
+{
+       if(!player) { return 0; } // not sure how, but best to be safe
+
+       int spec_count = 0;
+
+       FOREACH_CLIENT(IS_REAL_CLIENT(it) && IS_SPEC(it) && it != to && it.enemy == player,
+       {
+               spec_count++;
+       });
+
+       return spec_count;
+}
+
+void WriteSpectators(entity player, entity to)
+{
+       if(!player) { return; } // not sure how, but best to be safe
+
+       FOREACH_CLIENT(IS_REAL_CLIENT(it) && IS_SPEC(it) && it != to && it.enemy == player,
+       {
+               WriteByte(MSG_ENTITY, num_for_edict(it));
+       });
+}
+
 bool ClientData_Send(entity this, entity to, int sf)
 {
        assert(to == this.owner, return false);
@@ -87,6 +111,7 @@ bool ClientData_Send(entity this, entity to, int sf)
        if (to.spectatee_status)    sf |= 2; // spectator ent number follows
        if (e.zoomstate)            sf |= 4; // zoomed
        if (e.porto_v_angle_held)   sf |= 8; // angles held
+       if (autocvar_sv_showspectators) sf |= 16; // show spectators
 
        WriteHeader(MSG_ENTITY, ENT_CLIENT_CLIENTDATA);
        WriteByte(MSG_ENTITY, sf);
@@ -100,6 +125,14 @@ bool ClientData_Send(entity this, entity to, int sf)
                WriteAngle(MSG_ENTITY, e.v_angle.x);
                WriteAngle(MSG_ENTITY, e.v_angle.y);
        }
+
+       if(sf & 16)
+       {
+               float specs = CountSpectators(e, to);
+               WriteByte(MSG_ENTITY, specs);
+               WriteSpectators(e, to);
+       }
+
        return true;
 }
 
@@ -224,6 +257,7 @@ void PutObserverInServer(entity this)
     RemoveGrapplingHook(this);
        Portal_ClearAll(this);
        Unfreeze(this);
+       SetSpectatee(this, NULL);
 
        if (this.alivetime)
        {
@@ -1187,6 +1221,8 @@ void ClientDisconnect(entity this)
 
        Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_QUIT_DISCONNECT, this.netname);
 
+       SetSpectatee(this, NULL);
+
     MUTATOR_CALLHOOK(ClientDisconnect, this);
 
        ClientState_detach(this);
@@ -1672,6 +1708,8 @@ bool SpectateSet(entity this)
        if(!IS_PLAYER(this.enemy))
                return false;
 
+       ClientData_Touch(this.enemy);
+
        msg_entity = this;
        WriteByte(MSG_ONE, SVC_SETVIEW);
        WriteEntity(MSG_ONE, this.enemy);
@@ -1694,6 +1732,9 @@ void SetSpectatee(entity this, entity spectatee)
        // these are required to fix the spectator bug with arc
        if(old_spectatee && old_spectatee.arc_beam) { old_spectatee.arc_beam.SendFlags |= ARC_SF_SETTINGS; }
        if(this.enemy && this.enemy.arc_beam) { this.enemy.arc_beam.SendFlags |= ARC_SF_SETTINGS; }
+
+       // needed to update spectator list
+       if(old_spectatee) { ClientData_Touch(old_spectatee); }
 }
 
 bool Spectate(entity this, entity pl)
@@ -1791,6 +1832,8 @@ void LeaveSpectatorMode(entity this)
                {
                        TRANSMUTE(Player, this);
 
+                       SetSpectatee(this, NULL);
+
                        if(autocvar_g_campaign || autocvar_g_balance_teams)
                                { JoinBestTeam(this, false, true); }