]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_client.qc
Provisions for unit testing
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_client.qc
index 24d08a43cc69c67e609824a97c91dfbeb064ac69..8a6eefe86ce153670d8af307cdb9d594396852f7 100644 (file)
 
 #include "../lib/warpzone/server.qh"
 
+STATIC_METHOD(Client, Add, void(Client this, int _team))
+{
+    WITH(entity, self, this, ClientConnect());
+    TRANSMUTE(Player, this);
+    this.frame = 12; // 7
+    this.team = _team;
+    WITH(entity, self, this, PutClientInServer());
+}
+
+void PutObserverInServer();
+void ClientDisconnect();
+
+STATIC_METHOD(Client, Remove, void(Client this))
+{
+    TRANSMUTE(Observer, this);
+    WITH(entity, self, this, PutClientInServer(); ClientDisconnect());
+}
 
 void send_CSQC_teamnagger() {
        WriteHeader(MSG_BROADCAST, TE_CSQC_TEAMNAGGER);
@@ -89,14 +106,14 @@ bool ClientData_Send(entity this, entity to, int sf)
 void ClientData_Attach(entity this)
 {
        Net_LinkEntity(this.clientdata = new_pure(clientdata), false, 0, ClientData_Send);
-       self.clientdata.drawonlytoclient = this;
-       self.clientdata.owner = this;
+       this.clientdata.drawonlytoclient = this;
+       this.clientdata.owner = this;
 }
 
 void ClientData_Detach(entity this)
 {
        remove(this.clientdata);
-       self.clientdata = NULL;
+       this.clientdata = NULL;
 }
 
 void ClientData_Touch(entity e)
@@ -988,13 +1005,14 @@ void ClientConnect()
        SELFPARAM();
        if (Ban_MaybeEnforceBanOnce(this)) return;
        assert(!IS_CLIENT(this), return);
+       this.flags |= FL_CLIENT;
        assert(player_count >= 0, player_count = 0);
-       TRANSMUTE(Client, this);
 
 #ifdef WATERMARK
        Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_WATERMARK, WATERMARK);
 #endif
        this.version_nagtime = time + 10 + random() * 10;
+       TRANSMUTE(Client, this);
 
        // identify the right forced team
        if (autocvar_g_campaign)
@@ -1029,18 +1047,20 @@ void ClientConnect()
        }
        if (!teamplay && this.team_forced > 0) this.team_forced = 0;
 
-       JoinBestTeam(this, false, false); // if the team number is valid, keep it
+    {
+        int id = this.playerid;
+        this.playerid = 0; // silent
+           JoinBestTeam(this, false, false); // if the team number is valid, keep it
+           this.playerid = id;
+    }
 
        if (autocvar_sv_spectate || autocvar_g_campaign || this.team_forced < 0) {
                TRANSMUTE(Observer, this);
        } else {
-               if (!teamplay || autocvar_g_balance_teams)
-               {
+               if (!teamplay || autocvar_g_balance_teams) {
                        TRANSMUTE(Player, this);
-                       campaign_bots_may_start = 1;
-               }
-               else
-               {
+                       campaign_bots_may_start = true;
+               } else {
                        TRANSMUTE(Observer, this); // do it anyway
                }
        }
@@ -1755,7 +1775,7 @@ void LeaveSpectatorMode()
                                { JoinBestTeam(self, false, true); }
 
                        if(autocvar_g_campaign)
-                               { campaign_bots_may_start = 1; }
+                               { campaign_bots_may_start = true; }
 
                        Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CPID_PREVENT_JOIN);