]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_client.qc
fix cvar use of electro bounce params
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_client.qc
index c269ce50288ff4c6969aa51f4d795b674aae595a..e3507d6413a8e54b4e57a4fd4fba36104916fa47 100644 (file)
@@ -6,6 +6,13 @@ void send_CSQC_teamnagger() {
        WriteByte(0, TE_CSQC_TEAMNAGGER);
 }
 
+void send_CSQC_cr_maxbullets(entity e) {
+       msg_entity = e;
+       WriteByte(MSG_ONE, SVC_TEMPENTITY);
+       WriteByte(MSG_ONE, TE_CSQC_CR_MAXBULLETS);
+       WriteByte(MSG_ONE, cvar("g_balance_campingrifle_magazinecapacity"));
+}
+
 void Announce(string snd) {
        WriteByte(MSG_ALL, SVC_TEMPENTITY);
        WriteByte(MSG_ALL, TE_CSQC_ANNOUNCE);
@@ -882,6 +889,8 @@ void PutClientInServer (void)
                        self.effects = 0;
                self.air_finished = time + 12;
                self.dmg = 2;
+               if(cvar("g_balance_nex_charge"))
+                       self.nex_charge = cvar("g_balance_nex_charge_start");
 
                if(inWarmupStage)
                {
@@ -907,7 +916,13 @@ void PutClientInServer (void)
                }
 
                if(g_weaponarena_random)
+               {
+                       if(g_weaponarena_random_with_laser)
+                               self.weapons &~= WEPBIT_LASER;
                        self.weapons = randombits(self.weapons, g_weaponarena_random, FALSE);
+                       if(g_weaponarena_random_with_laser)
+                               self.weapons |= WEPBIT_LASER;
+               }
 
                self.items = start_items;
                self.jump_interval = time;
@@ -1060,6 +1075,9 @@ void PutClientInServer (void)
        //      ctf_playerchanged();
 }
 
+.float ebouncefactor, ebouncestop; // electro's values
+// TODO do we need all these fields, or should we stop autodetecting runtime
+// changes and just have a console command to update this?
 float ClientInit_SendEntity(entity to, float sf)
 {
        WriteByte(MSG_ENTITY, ENT_CLIENT_INIT);
@@ -1082,10 +1100,13 @@ float ClientInit_SendEntity(entity to, float sf)
                WriteString(MSG_ENTITY, "");
        WriteByte(MSG_ENTITY, self.count * 255.0); // g_balance_armor_blockpercent
        WriteByte(MSG_ENTITY, self.cnt * 255.0); // g_balance_weaponswitchdelay
-       WriteCoord(MSG_ENTITY, self.bouncefactor); // g_balance_grenadelauncher_secondary_bouncefactor
-       WriteCoord(MSG_ENTITY, self.bouncestop); // g_balance_grenadelauncher_secondary_bouncestop
+       WriteCoord(MSG_ENTITY, self.bouncefactor); // g_balance_grenadelauncher_bouncefactor
+       WriteCoord(MSG_ENTITY, self.bouncestop); // g_balance_grenadelauncher_bouncestop
+       WriteCoord(MSG_ENTITY, self.ebouncefactor); // g_balance_grenadelauncher_bouncefactor
+       WriteCoord(MSG_ENTITY, self.ebouncestop); // g_balance_grenadelauncher_bouncestop
        WriteByte(MSG_ENTITY, cvar("g_balance_nex_secondary")); // client has to know if it should zoom or not
        WriteByte(MSG_ENTITY, cvar("g_balance_campingrifle_secondary")); // client has to know if it should zoom or not
+       WriteByte(MSG_ENTITY, serverflags); // client has to know if it should zoom or not
        return TRUE;
 }
 
@@ -1102,14 +1123,24 @@ void ClientInit_CheckUpdate()
                self.cnt = cvar("g_balance_weaponswitchdelay");
                self.SendFlags |= 1;
        }
-       if(self.bouncefactor != cvar("g_balance_grenadelauncher_secondary_bouncefactor"))
+       if(self.bouncefactor != cvar("g_balance_grenadelauncher_bouncefactor"))
+       {
+               self.bouncefactor = cvar("g_balance_grenadelauncher_bouncefactor");
+               self.SendFlags |= 1;
+       }
+       if(self.bouncestop != cvar("g_balance_grenadelauncher_bouncestop"))
+       {
+               self.bouncestop = cvar("g_balance_grenadelauncher_bouncestop");
+               self.SendFlags |= 1;
+       }
+       if(self.ebouncefactor != cvar("g_balance_electro_secondary_bouncefactor"))
        {
-               self.bouncefactor = cvar("g_balance_grenadelauncher_secondary_bouncefactor");
+               self.ebouncefactor = cvar("g_balance_electro_secondary_bouncefactor");
                self.SendFlags |= 1;
        }
-       if(self.bouncestop != cvar("g_balance_grenadelauncher_secondary_bouncestop"))
+       if(self.ebouncestop != cvar("g_balance_electro_secondary_bouncestop"))
        {
-               self.bouncestop = cvar("g_balance_grenadelauncher_secondary_bouncestop");
+               self.ebouncestop = cvar("g_balance_electro_secondary_bouncestop");
                self.SendFlags |= 1;
        }
 }
@@ -1296,7 +1327,28 @@ void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto
 
 void ClientKill (void)
 {
-       ClientKill_TeamChange(0);
+       if((g_arena || g_ca) && ((champion && champion.classname == "player" && player_count > 1) || player_count == 1)) // don't allow a kill in this case either
+       {
+               // do nothing
+       }
+       else
+               ClientKill_TeamChange(0);
+}
+
+void CTS_ClientKill_Think (void)
+{
+       self = self.owner; // set self to the player to be killed
+       sprint(self, "^1You were killed in order to prevent cheating!");
+       ClientKill_Now();
+}
+
+void CTS_ClientKill (float t) // silent version of ClientKill
+{
+       entity e;
+       e = spawn();
+       e.owner = self;
+       e.think = CTS_ClientKill_Think;
+       e.nextthink = t;
 }
 
 void DoTeamChange(float destteam)
@@ -1377,6 +1429,27 @@ void FixClientCvars(entity e)
         */
 }
 
+float PlayerInIDList(entity p, string idlist)
+{
+       float n, i;
+       string s;
+
+       // NOTE: we do NOT check crypto_keyfp here, an unsigned ID is fine too for this
+       if not(p.crypto_idfp)
+               return 0;
+
+       // 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 0;
+}
+
 /*
 =============
 ClientConnect
@@ -1388,10 +1461,6 @@ Called when a client connects to the server
 string ColoredTeamName(float t);
 void DecodeLevelParms (void);
 //void dom_player_join_team(entity pl);
-#ifdef UID
-.float uid_kicktime;
-.string uid;
-#endif
 void ClientConnect (void)
 {
        float t;
@@ -1436,9 +1505,37 @@ void ClientConnect (void)
        //if(g_domination)
        //      dom_player_join_team(self);
 
+       // identify the right forced team
+       if(PlayerInIDList(self, cvar_string("g_forced_team_red")))
+               self.team_forced = COLOR_TEAM1;
+       else if(PlayerInIDList(self, cvar_string("g_forced_team_blue")))
+               self.team_forced = COLOR_TEAM2;
+       else if(PlayerInIDList(self, cvar_string("g_forced_team_yellow")))
+               self.team_forced = COLOR_TEAM3;
+       else if(PlayerInIDList(self, cvar_string("g_forced_team_pink")))
+               self.team_forced = COLOR_TEAM4;
+       else if(cvar_string("g_forced_team_otherwise") == "red")
+               self.team_forced = COLOR_TEAM1;
+       else if(cvar_string("g_forced_team_otherwise") == "blue")
+               self.team_forced = COLOR_TEAM2;
+       else if(cvar_string("g_forced_team_otherwise") == "yellow")
+               self.team_forced = COLOR_TEAM3;
+       else if(cvar_string("g_forced_team_otherwise") == "pink")
+               self.team_forced = COLOR_TEAM4;
+       else if(cvar_string("g_forced_team_otherwise") == "spectate")
+               self.team_forced = -1;
+       else if(cvar_string("g_forced_team_otherwise") == "spectator")
+               self.team_forced = -1;
+       else
+               self.team_forced = 0;
+
+       if(!teams_matter)
+               if(self.team_forced > 0)
+                       self.team_forced = 0;
+
        JoinBestTeam(self, FALSE, FALSE); // if the team number is valid, keep it
 
-       if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
+       if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign") || self.team_forced < 0) {
                self.classname = "observer";
        } else {
                if(teams_matter)
@@ -1569,12 +1666,6 @@ void ClientConnect (void)
        else
                self.hitplotfh = -1;
 
-#ifdef UID
-       if(clienttype(self) == CLIENTTYPE_REAL)
-       if not(self.uid)
-               self.uid_kicktime = time + 60;
-#endif
-
        if(g_race || g_cts) {
                string rr;
                if(g_cts)
@@ -1583,11 +1674,12 @@ void ClientConnect (void)
                        rr = RACE_RECORD;
                t = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "time")));
 
+               msg_entity = self;
                race_send_recordtime(MSG_ONE);
                race_send_speedaward(MSG_ONE);
 
                speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));
-               speedaward_alltimebest_holder = db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/netname"));
+               speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp")));
                race_send_speedaward_alltimebest(MSG_ONE);
 
                float i;
@@ -1598,6 +1690,8 @@ void ClientConnect (void)
        else if(cvar("sv_teamnagger") && !(cvar("bot_vs_human") && (c3==-1 && c4==-1)) && !g_ca) // teamnagger is currently bad for ca
                send_CSQC_teamnagger();
 
+       send_CSQC_cr_maxbullets(self);
+
        CheatInitClient();
 }
 
@@ -1671,11 +1765,6 @@ void ClientDisconnect (void)
 
        bot_relinkplayerlist();
 
-       // remove laserdot
-       if(self.weaponentity)
-               if(self.weaponentity.lasertarget)
-                       remove(self.weaponentity.lasertarget);
-
        if(g_arena)
        {
                Spawnqueue_Unmark(self);
@@ -1689,6 +1778,8 @@ void ClientDisconnect (void)
                strunzone(self.netname_previous);
        if(self.clientstatus)
                strunzone(self.clientstatus);
+       if(self.weaponorder_byimpulse)
+               strunzone(self.weaponorder_byimpulse);
 
        ClearPlayerSounds();
 
@@ -2217,6 +2308,7 @@ void SpectateCopy(entity spectatee) {
        self.health = spectatee.health;
        self.impulse = 0;
        self.items = spectatee.items;
+       self.last_pickup = spectatee.last_pickup;
        self.metertime = spectatee.metertime;
        self.strength_finished = spectatee.strength_finished;
        self.invincible_finished = spectatee.invincible_finished;
@@ -2311,7 +2403,7 @@ void ShowRespawnCountdown()
 void LeaveSpectatorMode()
 {
        if(isJoinAllowed()) {
-               if(!teams_matter || cvar("g_campaign") || cvar("g_balance_teams") || (self.wasplayer && cvar("g_changeteam_banned"))) {
+               if(!teams_matter || cvar("g_campaign") || cvar("g_balance_teams") || (self.wasplayer && cvar("g_changeteam_banned")) || self.team_forced > 0) {
                        self.classname = "player";
 
                        if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force"))
@@ -2352,6 +2444,9 @@ void LeaveSpectatorMode()
  * @return bool TRUE if the player is allowed to join, false otherwise
  */
 float isJoinAllowed() {
+       if(self.team_forced < 0)
+               return FALSE; // forced spectators can never join
+
        if (!cvar("g_maxplayers"))
                return TRUE;
 
@@ -2380,50 +2475,6 @@ void checkSpectatorBlock() {
        }
 }
 
-float vercmp_recursive(string v1, string v2)
-{
-       float dot1, dot2;
-       string s1, s2;
-       float r;
-
-       dot1 = strstrofs(v1, ".", 0);
-       dot2 = strstrofs(v2, ".", 0);
-       if(dot1 == -1)
-               s1 = v1;
-       else
-               s1 = substring(v1, 0, dot1);
-       if(dot2 == -1)
-               s2 = v2;
-       else
-               s2 = substring(v2, 0, dot2);
-
-       r = stof(s1) - stof(s2);
-       if(r != 0)
-               return r;
-
-       r = strcasecmp(s1, s2);
-       if(r != 0)
-               return r;
-
-       if(dot1 == -1)
-               if(dot2 == -1)
-                       return 0;
-               else
-                       return -1;
-       else
-               if(dot2 == -1)
-                       return 1;
-               else
-                       return vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));
-}
-
-float vercmp(string v1, string v2)
-{
-       if(strcasecmp(v1, v2) == 0) // early out check
-               return 0;
-       return vercmp_recursive(v1, v2);
-}
-
 void ObserverThink()
 {
        if (self.flags & FL_JUMPRELEASED) {
@@ -2782,6 +2833,11 @@ void PlayerPreThink (void)
                }
 
                player_regen();
+
+               // rot nex charge to the charge limit
+               if(cvar("g_balance_nex_charge_rot_rate") && self.nex_charge > cvar("g_balance_nex_charge_limit") && self.nex_charge_rottime < time)
+                       self.nex_charge = bound(cvar("g_balance_nex_charge_limit"), self.nex_charge - cvar("g_balance_nex_charge_rot_rate") * frametime / W_TICSPERFRAME, 1);
+
                if(frametime)
                        player_anim();
 
@@ -2912,16 +2968,6 @@ void PlayerPostThink (void)
                self.stat_count -= 1;
        }
 
-#ifdef UID
-       if(self.uid_kicktime)
-       if(time > self.uid_kicktime)
-       {
-               bprint("^3", self.netname, "^3 was kicked for missing UID.\n");
-               dropclient(self);
-               return;
-       }
-#endif
-
        if(sv_maxidle && frametime)
        {
                // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
@@ -3018,6 +3064,18 @@ void PlayerPostThink (void)
 
        playerdemo_write();
 
+       if((g_cts || g_race) && self.cvar_cl_allow_uid2name)
+       {
+               if(!self.stored_netname)
+                       self.stored_netname = strzone(uid2name(self.crypto_idfp));
+               if(self.stored_netname != self.netname)
+               {
+                       db_put(ServerProgsDB, strcat("uid2name", self.crypto_idfp), self.netname);
+                       strunzone(self.stored_netname);
+                       self.stored_netname = strzone(self.netname);
+               }
+       }
+
        /*
        if(g_race)
                dprint(sprintf("%f %.6f\n", time, race_GetFractionalLapCount(self)));