2012-08-04 10:54:37 +00:00
|
|
|
// Copyright (C) 1999-2000 Id Software, Inc.
|
2012-01-22 21:34:33 +00:00
|
|
|
//
|
|
|
|
#include "g_local.h"
|
2013-05-16 21:54:40 +00:00
|
|
|
#include "g_main.h"
|
2012-01-22 21:34:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=======================================================================
|
|
|
|
|
|
|
|
SESSION DATA
|
|
|
|
|
|
|
|
Session data is the only data that stays persistant across level loads
|
|
|
|
and tournament restarts.
|
|
|
|
=======================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
G_WriteClientSessionData
|
|
|
|
|
|
|
|
Called on game shutdown
|
|
|
|
================
|
|
|
|
*/
|
2012-11-12 20:53:18 +00:00
|
|
|
static void G_WriteClientSessionData( gclient_t *client ) {
|
2012-01-22 21:34:33 +00:00
|
|
|
const char *s;
|
|
|
|
const char *var;
|
|
|
|
|
|
|
|
s = va("%i %i %i %i %i %i %i",
|
|
|
|
client->sess.sessionTeam,
|
2012-08-04 10:54:37 +00:00
|
|
|
client->sess.sessionClass,
|
|
|
|
client->sess.spectatorTime,
|
2012-01-22 21:34:33 +00:00
|
|
|
client->sess.spectatorState,
|
|
|
|
client->sess.spectatorClient,
|
|
|
|
client->sess.wins,
|
2012-08-04 10:54:37 +00:00
|
|
|
client->sess.losses
|
2012-01-22 21:34:33 +00:00
|
|
|
);
|
|
|
|
|
2012-08-04 10:54:37 +00:00
|
|
|
var = va( "session%i", client - level.clients );
|
2012-01-22 21:34:33 +00:00
|
|
|
|
|
|
|
trap_Cvar_Set( var, s );
|
|
|
|
}
|
|
|
|
|
|
|
|
void G_ReadSessionData( gclient_t *client ) {
|
|
|
|
char s[MAX_STRING_CHARS];
|
|
|
|
const char *var;
|
2012-08-04 10:54:37 +00:00
|
|
|
int team, spec;
|
2012-01-22 21:34:33 +00:00
|
|
|
|
2012-08-04 10:54:37 +00:00
|
|
|
var = va( "session%i", client - level.clients );
|
2012-01-22 21:34:33 +00:00
|
|
|
trap_Cvar_VariableStringBuffer( var, s, sizeof(s) );
|
|
|
|
|
2012-09-10 10:55:24 +00:00
|
|
|
sscanf( s, "%i %i %i %i %i %i %i",
|
2012-08-04 10:54:37 +00:00
|
|
|
&team,
|
|
|
|
&client->sess.sessionClass,
|
|
|
|
&client->sess.spectatorTime,
|
|
|
|
&spec,
|
2012-01-22 21:34:33 +00:00
|
|
|
&client->sess.spectatorClient,
|
|
|
|
&client->sess.wins,
|
2012-08-04 10:54:37 +00:00
|
|
|
&client->sess.losses
|
2012-01-22 21:34:33 +00:00
|
|
|
);
|
2012-11-12 20:53:18 +00:00
|
|
|
client->sess.sessionTeam = (team_t)team;
|
|
|
|
client->sess.spectatorState = (spectatorState_t)spec;
|
2012-01-22 21:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void G_InitSessionData( gclient_t *client, char *userinfo ) {
|
|
|
|
clientSession_t *sess;
|
|
|
|
const char *value;
|
|
|
|
|
|
|
|
sess = &client->sess;
|
|
|
|
|
2012-08-04 10:54:37 +00:00
|
|
|
value = Info_ValueForKey( userinfo, "team" );
|
|
|
|
if ( value[0] == 's' ) {
|
|
|
|
// a willing spectator, not a waiting-in-line
|
|
|
|
sess->sessionTeam = TEAM_SPECTATOR;
|
2012-01-22 21:34:33 +00:00
|
|
|
} else {
|
2012-08-04 10:54:37 +00:00
|
|
|
switch ( g_gametype.integer ) {
|
|
|
|
default:
|
|
|
|
case GT_FFA:
|
|
|
|
sess->sessionTeam = TEAM_FREE;
|
|
|
|
break;
|
|
|
|
case GT_SINGLE_PLAYER:
|
|
|
|
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;
|
2012-01-22 21:34:33 +00:00
|
|
|
}
|
2012-08-04 10:54:37 +00:00
|
|
|
break;
|
2012-01-22 21:34:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-04 10:54:37 +00:00
|
|
|
sess->sessionClass = 0; //PC_NOCLASS; //TiM: Default Class
|
2012-01-22 21:34:33 +00:00
|
|
|
sess->spectatorState = SPECTATOR_FREE;
|
2012-08-04 10:54:37 +00:00
|
|
|
sess->spectatorTime = level.time;
|
2012-01-22 21:34:33 +00:00
|
|
|
|
|
|
|
G_WriteClientSessionData( client );
|
|
|
|
}
|
|
|
|
|
|
|
|
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" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|