From: TimePath Date: Wed, 9 Mar 2016 22:50:18 +0000 (+1100) Subject: Move client setup to ClientState_attach X-Git-Tag: xonotic-v0.8.2~1137 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=cb4aa22c75acf740385ea29be1987b1b0768c880;p=xonotic%2Fxonotic-data.pk3dir.git Move client setup to ClientState_attach --- diff --git a/qcsrc/common/physics/player.qh b/qcsrc/common/physics/player.qh index ea318c5b0..252b157cd 100644 --- a/qcsrc/common/physics/player.qh +++ b/qcsrc/common/physics/player.qh @@ -99,6 +99,15 @@ bool IsFlying(entity a); #define PHYS_INPUT_BUTTON_ZOOM(s) PHYS_INPUT_BUTTON_BUTTON4(s) #define PHYS_INPUT_BUTTON_CROUCH(s) PHYS_INPUT_BUTTON_BUTTON5(s) #define PHYS_INPUT_BUTTON_HOOK(s) PHYS_INPUT_BUTTON_BUTTON6(s) + +#ifdef CSQC +STATIC_INIT(PHYS_INPUT_BUTTON_HOOK) +{ + localcmd("alias +hook +button6\n"); + localcmd("alias -hook -button6\n"); +} +#endif + #define PHYS_INPUT_BUTTON_INFO(s) PHYS_INPUT_BUTTON_BUTTON7(s) #define PHYS_INPUT_BUTTON_DRAG(s) PHYS_INPUT_BUTTON_BUTTON8(s) #define PHYS_INPUT_BUTTON_USE(s) PHYS_INPUT_BUTTON_BUTTON_USE(s) @@ -107,6 +116,14 @@ bool IsFlying(entity a); #define PHYS_INPUT_BUTTON_ZOOMSCRIPT(s) PHYS_INPUT_BUTTON_BUTTON9(s) #define PHYS_INPUT_BUTTON_JETPACK(s) PHYS_INPUT_BUTTON_BUTTON10(s) +#ifdef CSQC +STATIC_INIT(PHYS_INPUT_BUTTON_JETPACK) +{ + localcmd("alias +jetpack +button10\n"); + localcmd("alias -jetpack -button10\n"); +} +#endif + // if more buttons are needed, start using impulse bits as buttons #define PHYS_INPUT_BUTTON_BACKWARD(s) (PHYS_INPUT_MOVEVALUES(s).x < 0) diff --git a/qcsrc/common/state.qh b/qcsrc/common/state.qh index e2ba5f385..fcc3656b8 100644 --- a/qcsrc/common/state.qh +++ b/qcsrc/common/state.qh @@ -30,18 +30,25 @@ ENDCLASS(PlayerState) PlayerState PS(entity this) { assert(IS_CLIENT(this)); return this._ps; } #endif +void Inventory_new(entity this); +void Inventory_delete(entity this); + +// TODO: renew on death + void PlayerState_attach(entity this) { - // TODO: dynamic - // this._ps = NEW(PlayerState, this); + this._ps = NEW(PlayerState, this); + + Inventory_new(this); } void PlayerState_detach(entity this) { - // TODO: dynamic - // if (!PS(this)) return; // initial connect - // remove(PS(this)); - // this._ps = NULL; + if (!PS(this)) return; // initial connect + remove(PS(this)); + this._ps = NULL; + + Inventory_delete(self); } /** @@ -66,15 +73,64 @@ ENDCLASS(ClientState) ClientState CS(entity this) { assert(IS_CLIENT(this)); assert(this._cs); return this._cs; } #endif +void GetCvars(int); +void DecodeLevelParms(entity this); +void PlayerScore_Attach(entity this); +void ClientData_Attach(entity this); +void accuracy_init(entity this); +void entcs_attach(entity this); +void playerdemo_init(entity this); +void anticheat_init(entity this); +void W_HitPlotOpen(entity this); +void bot_clientconnect(entity this); + void ClientState_attach(entity this) { this._cs = NEW(ClientState, this); - this._ps = NEW(PlayerState, this); // TODO: dynamic + + GetCvars(0); // get other cvars from player + + // TODO: xonstat elo.txt support, until then just 404s + if (false && IS_REAL_CLIENT(this)) { PlayerStats_PlayerBasic_CheckUpdate(this); } + + // TODO: fold all of these into ClientState + + DecodeLevelParms(this); + + PlayerScore_Attach(this); + ClientData_Attach(this); + accuracy_init(this); + entcs_attach(this); + playerdemo_init(this); + anticheat_init(this); + W_HitPlotOpen(this); + + bot_clientconnect(this); } +void bot_clientdisconnect(); +void W_HitPlotClose(entity this); +void anticheat_report(); +void playerdemo_shutdown(); +void entcs_detach(entity this); +void accuracy_free(entity this); +void ClientData_Detach(entity this); +void PlayerScore_Detach(entity this); + void ClientState_detach(entity this) { remove(CS(this)); this._cs = NULL; - this._ps = NULL; // TODO: dynamic + + GetCvars(-1); // free cvars + + bot_clientdisconnect(); + + W_HitPlotClose(this); + anticheat_report(); + playerdemo_shutdown(); + entcs_detach(this); + accuracy_free(self); + ClientData_Detach(this); + PlayerScore_Detach(self); } diff --git a/qcsrc/server/anticheat.qc b/qcsrc/server/anticheat.qc index 865010ff5..982a42606 100644 --- a/qcsrc/server/anticheat.qc +++ b/qcsrc/server/anticheat.qc @@ -244,7 +244,3 @@ void anticheat_init(entity this) this.anticheat_speedhack_offset = 0; this.anticheat_jointime = servertime; } - -void anticheat_shutdown() -{ -} diff --git a/qcsrc/server/anticheat.qh b/qcsrc/server/anticheat.qh index 5e6599b7e..3bb5d251e 100644 --- a/qcsrc/server/anticheat.qh +++ b/qcsrc/server/anticheat.qh @@ -3,7 +3,6 @@ void anticheat_init(entity this); void anticheat_report(); -void anticheat_shutdown(); void anticheat_physics(entity this); void anticheat_spectatecopy(entity spectatee); diff --git a/qcsrc/server/cheats.qc b/qcsrc/server/cheats.qc index b6ed06d67..b82b19a4a 100644 --- a/qcsrc/server/cheats.qc +++ b/qcsrc/server/cheats.qc @@ -36,7 +36,6 @@ float CheatCommand(float argc) { return 0; } float CheatFrame() { return 0; } void CheatInit() { cheatcount_total = world.cheatcount; } void CheatShutdown() { } -void CheatShutdownClient() { } void Drag_MoveDrag(entity from, entity to) { } #else @@ -55,10 +54,6 @@ void CheatShutdown() { } -void CheatShutdownClient() -{ -} - float CheatsAllowed(float i, float argc, float fr) // the cheat gets passed as argument for possible future ACL checking {SELFPARAM(); // dead people cannot cheat diff --git a/qcsrc/server/cheats.qh b/qcsrc/server/cheats.qh index 7301df4a0..4ead519eb 100644 --- a/qcsrc/server/cheats.qh +++ b/qcsrc/server/cheats.qh @@ -9,7 +9,6 @@ float cheatcount_total; .float cheatcount; void CheatInit(); void CheatShutdown(); -void CheatShutdownClient(); float CheatImpulse(int imp); float CheatCommand(float argc); float CheatFrame(); diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index 67b1dbe99..3bc33a92c 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -285,9 +285,7 @@ void PutObserverInServer() setsize (self, STAT(PL_CROUCH_MIN, NULL), STAT(PL_CROUCH_MAX, NULL)); // give the spectator some space between walls for MOVETYPE_FLY_WORLDONLY self.view_ofs = '0 0 0'; // so that your view doesn't go into the ceiling with MOVETYPE_FLY_WORLDONLY, previously "PL_VIEW_OFS" - PS(self).m_weapon = WEP_Null; self.weaponname = ""; - PS(self).m_switchingweapon = WEP_Null; self.weaponmodel = ""; for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { @@ -996,22 +994,7 @@ void ClientConnect() #endif this.version_nagtime = time + 10 + random() * 10; - // TODO: xonstat elo.txt support, until then just 404s - if (false && IS_REAL_CLIENT(this)) { PlayerStats_PlayerBasic_CheckUpdate(this); } - ClientState_attach(this); - // TODO: fold all of these into ClientState - DecodeLevelParms(this); - PlayerScore_Attach(this); - ClientData_Attach(this); - accuracy_init(this); - Inventory_new(this); - playerdemo_init(this); - anticheat_init(this); - entcs_attach(this); - W_HitPlotOpen(this); - - bot_clientconnect(this); // identify the right forced team if (autocvar_g_campaign) @@ -1085,20 +1068,9 @@ void ClientConnect() FixClientCvars(this); - // Grappling hook - stuffcmd(this, "alias +hook +button6\n"); - stuffcmd(this, "alias -hook -button6\n"); - - // Jetpack binds - stuffcmd(this, "alias +jetpack +button10\n"); - stuffcmd(this, "alias -jetpack -button10\n"); - // get version info from player stuffcmd(this, "cmd clientversion $gameversion\n"); - // get other cvars from player - GetCvars(0); - // notify about available teams if (teamplay) { @@ -1167,45 +1139,24 @@ Called when a client disconnects from the server */ .entity chatbubbleentity; void ReadyCount(); -void ClientDisconnect () +void ClientDisconnect() { SELFPARAM(); - ClientState_detach(this); - if(self.vehicle) - vehicles_exit(VHEF_RELEASE); + assert(IS_CLIENT(this), return); - if (!IS_CLIENT(self)) - { - LOG_INFO("Warning: ClientDisconnect without ClientConnect\n"); - return; - } - - PlayerStats_GameReport_FinalizePlayer(self); - - if ( self.active_minigame ) - part_minigame(self); - - if(IS_PLAYER(self)) { Send_Effect(EFFECT_SPAWN_NEUTRAL, self.origin, '0 0 0', 1); } + PlayerStats_GameReport_FinalizePlayer(this); + if (this.vehicle) vehicles_exit(VHEF_RELEASE); + if (this.active_minigame) part_minigame(this); + if (IS_PLAYER(this)) Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1); - CheatShutdownClient(); - - W_HitPlotClose(self); - - anticheat_report(); - anticheat_shutdown(); - - playerdemo_shutdown(); - - bot_clientdisconnect(); - - entcs_detach(self); + if (autocvar_sv_eventlog) + GameLogEcho(strcat(":part:", ftos(this.playerid))); - if(autocvar_sv_eventlog) - GameLogEcho(strcat(":part:", ftos(self.playerid))); + Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_DISCONNECT, this.netname); - Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_DISCONNECT, self.netname); + MUTATOR_CALLHOOK(ClientDisconnect); - MUTATOR_CALLHOOK(ClientDisconnect); + ClientState_detach(this); Portal_ClearAll(self); @@ -1217,39 +1168,21 @@ void ClientDisconnect () self.flags &= ~FL_CLIENT; - if (self.chatbubbleentity) - remove (self.chatbubbleentity); - - if (self.killindicator) - remove (self.killindicator); + if (this.chatbubbleentity) remove(this.chatbubbleentity); + if (this.killindicator) remove(this.killindicator); WaypointSprite_PlayerGone(); bot_relinkplayerlist(); - accuracy_free(self); - Inventory_delete(self); - ClientData_Detach(this); - PlayerScore_Detach(self); - - if(self.netname_previous) - strunzone(self.netname_previous); - if(self.clientstatus) - strunzone(self.clientstatus); - if(self.weaponorder_byimpulse) - strunzone(self.weaponorder_byimpulse); + if (self.netname_previous) strunzone(self.netname_previous); + if (self.clientstatus) strunzone(self.clientstatus); + if (self.weaponorder_byimpulse) strunzone(self.weaponorder_byimpulse); + if (self.personal) remove(self.personal); - if(self.personal) - remove(self.personal); - - self.playerid = 0; + this.playerid = 0; ReadyCount(); - if(vote_called) - if(IS_REAL_CLIENT(self)) - VoteCount(false); - - // free cvars - GetCvars(-1); + if (vote_called && IS_REAL_CLIENT(this)) VoteCount(false); } void ChatBubbleThink() diff --git a/qcsrc/server/scores.qc b/qcsrc/server/scores.qc index e01a9904f..4e4d69b06 100644 --- a/qcsrc/server/scores.qc +++ b/qcsrc/server/scores.qc @@ -349,7 +349,7 @@ float PlayerScore_Add(entity player, float scorefield, float score) { if(gameover) return 0; - backtrace("Adding score to unknown player!"); + LOG_WARNING("Adding score to unknown player!"); return 0; } if(score)