From: terencehill Date: Wed, 24 Aug 2016 23:40:38 +0000 (+0200) Subject: Enhance LeaveSpectatorMode code so it can handle the join command too (called by... X-Git-Tag: xonotic-v0.8.2~620^2~14 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=commitdiff_plain;h=561b5e1c20958312253a8478d71bdcdd7ddff0df Enhance LeaveSpectatorMode code so it can handle the join command too (called by the teamselect dialog) allowing to remove some duplicated code --- diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index 0c48324254..c9a8dd5d85 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -1861,11 +1861,12 @@ void ShowRespawnCountdown(entity this) } } +.int team_selected; void LeaveSpectatorMode(entity this) { if(nJoinAllowed(this, this)) { - if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || (this.wasplayer && autocvar_g_changeteam_banned) || this.team_forced > 0) + if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || this.team_selected || (this.wasplayer && autocvar_g_changeteam_banned) || this.team_forced > 0) { TRANSMUTE(Player, this); @@ -1880,8 +1881,10 @@ void LeaveSpectatorMode(entity this) Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_PREVENT_JOIN); PutClientInServer(this); + PlayerScore_Clear(this); if(IS_PLAYER(this)) { Send_Notification(NOTIF_ALL, NULL, MSG_INFO, ((teamplay && this.team != -1) ? APP_TEAM_ENT(this, INFO_JOIN_PLAY_TEAM) : INFO_JOIN_PLAY), this.netname); } + this.team_selected = false; } else stuffcmd(this, "menu_showteamselect\n"); @@ -1998,6 +2001,14 @@ void PrintWelcomeMessage(entity this) } } +bool spawnAllowed(entity this) +{ + if (this.version_mismatch) return false; + if (teamplay && lockteams) return false; + if (MUTATOR_CALLHOOK(ForbidSpawn, this)) return false; + return true; +} + void ObserverThink(entity this) { if ( this.impulse ) @@ -2007,7 +2018,7 @@ void ObserverThink(entity this) } if (this.flags & FL_JUMPRELEASED) { - if (PHYS_INPUT_BUTTON_JUMP(this) && !this.version_mismatch && !MUTATOR_CALLHOOK(ForbidSpawn, this)) { + if (PHYS_INPUT_BUTTON_JUMP(this) && spawnAllowed(this)) { this.flags &= ~FL_JUMPRELEASED; this.flags |= FL_SPAWNING; } else if(PHYS_INPUT_BUTTON_ATCK(this) && !this.version_mismatch) { @@ -2048,7 +2059,7 @@ void SpectatorThink(entity this) } if (this.flags & FL_JUMPRELEASED) { - if (PHYS_INPUT_BUTTON_JUMP(this) && !this.version_mismatch && !MUTATOR_CALLHOOK(ForbidSpawn, this)) { + if (PHYS_INPUT_BUTTON_JUMP(this) && spawnAllowed(this)) { this.flags &= ~FL_JUMPRELEASED; this.flags |= FL_SPAWNING; } else if(PHYS_INPUT_BUTTON_ATCK(this) || this.impulse == 10 || this.impulse == 15 || this.impulse == 18 || (this.impulse >= 200 && this.impulse <= 209)) { diff --git a/qcsrc/server/command/cmd.qc b/qcsrc/server/command/cmd.qc index e23f9bc989..5d6ad3adab 100644 --- a/qcsrc/server/command/cmd.qc +++ b/qcsrc/server/command/cmd.qc @@ -159,33 +159,19 @@ void ClientCommand_mv_getpicture(entity caller, float request, float argc) // i } } +bool spawnAllowed(entity this); +void LeaveSpectatorMode(entity this); void ClientCommand_join(entity caller, float request) { switch (request) { case CMD_REQUEST_COMMAND: { - if (IS_CLIENT(caller)) - { - if (!IS_PLAYER(caller) && !lockteams && !gameover) - { - if (caller.caplayer) return; - if (nJoinAllowed(caller, caller)) - { - if (autocvar_g_campaign) campaign_bots_may_start = true; - TRANSMUTE(Player, caller); - PlayerScore_Clear(caller); - Kill_Notification(NOTIF_ONE_ONLY, caller, MSG_CENTER, CPID_PREVENT_JOIN); - Send_Notification(NOTIF_ALL, NULL, MSG_INFO, ((teamplay && caller.team != -1) ? APP_TEAM_ENT(caller, INFO_JOIN_PLAY_TEAM) : INFO_JOIN_PLAY), caller.netname); - PutClientInServer(caller); - } - else - { - // player may not join because of g_maxplayers is set - Send_Notification(NOTIF_ONE_ONLY, caller, MSG_CENTER, CENTER_JOIN_PREVENT); - } - } - } + if (!gameover) + if (IS_CLIENT(caller) && !IS_PLAYER(caller)) + if (spawnAllowed(caller)) + LeaveSpectatorMode(caller); + return; // never fall through to usage } @@ -326,6 +312,7 @@ void ClientCommand_say_team(entity caller, float request, float argc, string com } } +.int selectedteam; void ClientCommand_selectteam(entity caller, float request, float argc) { switch (request) @@ -363,7 +350,7 @@ void ClientCommand_selectteam(entity caller, float request, float argc) if (selection) { - if (caller.team == selection && !IS_DEAD(caller)) + if (caller.team == selection && selection != -1 && !IS_DEAD(caller)) { sprint(caller, "^7You already are on that team.\n"); } @@ -385,6 +372,8 @@ void ClientCommand_selectteam(entity caller, float request, float argc) } ClientKill_TeamChange(caller, selection); } + if(!IS_PLAYER(caller)) + caller.team_selected = true; // avoids asking again for team selection on join } } else