mirror of
https://github.com/DrBeef/ioq3quest.git
synced 2024-11-27 06:13:01 +00:00
f7c3276fe8
There are various issues caused by not knowing the initial team for the local client and bots when they connect. This is can be reproduced by starting a team game from the main menu. When g_teamAutoJoin is enabled, bots and local client join a random team at connect and then execute their team command a few frames later. This may result in the player being killed if they specify a different team. In Team Arena's Harvester mode this causes harvester skulls to be spawned at the beginning of the game. When g_teamForceBalance is enabled, the local client and bots may not be able to join their desired team. This may result in them being spectators. If g_teamAutoJoin is also enabled they may be left on the opposite (red/blue) team they were meant to join. There is a hack for including bot's team in their player info string (used by cgame for which team skin to use) before the bot joins their desired team. Bots aren't guaranteed to join their desired team (as may happen when both g_teamAutoJoin and g_teamForceBalance are enabled) so clients may see them as being on the wrong team! ---- Add teampref userinfo option for team preference. If teampref is set it will be used for attempting to join the team immediately at connect. Bots now join team at connect using teampref userinfo. So remove the hack for setting bot's team in player info string before the bot joins the team. To avoid the client sending teampref userinfo to all network servers, the local client uses a g_localTeamPref cvar. The g_localTeamPref cvar is cleared after it's used so it doesn't get used when starting another server later. Another reason not to use a teampref userinfo cvar is there isn't a reliable way to clear it in CGame/UI which are likely loaded from baseq3 pk3. Make it so g_teamAutoJoin doesn't affect clients who specify teampref. If teampref is invalid, the client will join a random team like g_teamAutoJoin. Don't apply g_teamForceBalance to the local client or bots. Otherwise they may be left as spectators when starting team game from menu. The start server menus use team command and g_localTeamPref to set the human player's team. This way it's compatible with vanilla Q3 game VMs and the new setting team at connect feature.
201 lines
4.8 KiB
C
201 lines
4.8 KiB
C
/*
|
|
===========================================================================
|
|
Copyright (C) 1999-2005 Id Software, Inc.
|
|
|
|
This file is part of Quake III Arena source code.
|
|
|
|
Quake III Arena source code is free software; you can redistribute it
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
published by the Free Software Foundation; either version 2 of the License,
|
|
or (at your option) any later version.
|
|
|
|
Quake III Arena source code is distributed in the hope that it will be
|
|
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with Quake III Arena source code; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
===========================================================================
|
|
*/
|
|
//
|
|
#include "g_local.h"
|
|
|
|
|
|
/*
|
|
=======================================================================
|
|
|
|
SESSION DATA
|
|
|
|
Session data is the only data that stays persistant across level loads
|
|
and tournament restarts.
|
|
=======================================================================
|
|
*/
|
|
|
|
/*
|
|
================
|
|
G_WriteClientSessionData
|
|
|
|
Called on game shutdown
|
|
================
|
|
*/
|
|
void G_WriteClientSessionData( gclient_t *client ) {
|
|
const char *s;
|
|
const char *var;
|
|
|
|
s = va("%i %i %i %i %i %i %i",
|
|
client->sess.sessionTeam,
|
|
client->sess.spectatorNum,
|
|
client->sess.spectatorState,
|
|
client->sess.spectatorClient,
|
|
client->sess.wins,
|
|
client->sess.losses,
|
|
client->sess.teamLeader
|
|
);
|
|
|
|
var = va( "session%i", (int)(client - level.clients) );
|
|
|
|
trap_Cvar_Set( var, s );
|
|
}
|
|
|
|
/*
|
|
================
|
|
G_ReadSessionData
|
|
|
|
Called on a reconnect
|
|
================
|
|
*/
|
|
void G_ReadSessionData( gclient_t *client ) {
|
|
char s[MAX_STRING_CHARS];
|
|
const char *var;
|
|
int teamLeader;
|
|
int spectatorState;
|
|
int sessionTeam;
|
|
|
|
var = va( "session%i", (int)(client - level.clients) );
|
|
trap_Cvar_VariableStringBuffer( var, s, sizeof(s) );
|
|
|
|
sscanf( s, "%i %i %i %i %i %i %i",
|
|
&sessionTeam,
|
|
&client->sess.spectatorNum,
|
|
&spectatorState,
|
|
&client->sess.spectatorClient,
|
|
&client->sess.wins,
|
|
&client->sess.losses,
|
|
&teamLeader
|
|
);
|
|
|
|
client->sess.sessionTeam = (team_t)sessionTeam;
|
|
client->sess.spectatorState = (spectatorState_t)spectatorState;
|
|
client->sess.teamLeader = (qboolean)teamLeader;
|
|
}
|
|
|
|
|
|
/*
|
|
================
|
|
G_InitSessionData
|
|
|
|
Called on a first-time connect
|
|
================
|
|
*/
|
|
void G_InitSessionData( gclient_t *client, char *userinfo ) {
|
|
clientSession_t *sess;
|
|
const char *value;
|
|
|
|
sess = &client->sess;
|
|
|
|
// check for team preference, mainly for bots
|
|
value = Info_ValueForKey( userinfo, "teampref" );
|
|
|
|
// check for human's team preference set by start server menu
|
|
if ( !value[0] && g_localTeamPref.string[0] && client->pers.localClient ) {
|
|
value = g_localTeamPref.string;
|
|
|
|
// clear team so it's only used once
|
|
trap_Cvar_Set( "g_localTeamPref", "" );
|
|
}
|
|
|
|
// initial team determination
|
|
if ( g_gametype.integer >= GT_TEAM ) {
|
|
// always spawn as spectator in team games
|
|
sess->sessionTeam = TEAM_SPECTATOR;
|
|
sess->spectatorState = SPECTATOR_FREE;
|
|
|
|
if ( value[0] || g_teamAutoJoin.integer ) {
|
|
SetTeam( &g_entities[client - level.clients], value );
|
|
}
|
|
} else {
|
|
if ( value[0] == 's' ) {
|
|
// a willing spectator, not a waiting-in-line
|
|
sess->sessionTeam = TEAM_SPECTATOR;
|
|
} else {
|
|
switch ( g_gametype.integer ) {
|
|
default:
|
|
case GT_FFA:
|
|
case GT_SINGLE_PLAYER:
|
|
if ( g_maxGameClients.integer > 0 &&
|
|
level.numNonSpectatorClients >= g_maxGameClients.integer ) {
|
|
sess->sessionTeam = TEAM_SPECTATOR;
|
|
} else {
|
|
sess->sessionTeam = TEAM_FREE;
|
|
}
|
|
break;
|
|
case GT_TOURNAMENT:
|
|
// if the game is full, go into a waiting mode
|
|
if ( level.numNonSpectatorClients >= 2 ) {
|
|
sess->sessionTeam = TEAM_SPECTATOR;
|
|
} else {
|
|
sess->sessionTeam = TEAM_FREE;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
sess->spectatorState = SPECTATOR_FREE;
|
|
}
|
|
|
|
AddTournamentQueue(client);
|
|
|
|
G_WriteClientSessionData( client );
|
|
}
|
|
|
|
|
|
/*
|
|
==================
|
|
G_InitWorldSession
|
|
|
|
==================
|
|
*/
|
|
void G_InitWorldSession( void ) {
|
|
char s[MAX_STRING_CHARS];
|
|
int gt;
|
|
|
|
trap_Cvar_VariableStringBuffer( "session", s, sizeof(s) );
|
|
gt = atoi( s );
|
|
|
|
// if the gametype changed since the last session, don't use any
|
|
// client sessions
|
|
if ( g_gametype.integer != gt ) {
|
|
level.newSession = qtrue;
|
|
G_Printf( "Gametype changed, clearing session data.\n" );
|
|
}
|
|
}
|
|
|
|
/*
|
|
==================
|
|
G_WriteSessionData
|
|
|
|
==================
|
|
*/
|
|
void G_WriteSessionData( void ) {
|
|
int i;
|
|
|
|
trap_Cvar_Set( "session", va("%i", g_gametype.integer) );
|
|
|
|
for ( i = 0 ; i < level.maxclients ; i++ ) {
|
|
if ( level.clients[i].pers.connected == CON_CONNECTED ) {
|
|
G_WriteClientSessionData( &level.clients[i] );
|
|
}
|
|
}
|
|
}
|