Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

Engine.GameStats


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
// ====================================================================
//  Class:  Engine.GameStats
//  Parent: Engine.Info
//
//  the GameStats object is used to send individual stat events to the
//  stats server.  Each game should spawn a GameStats object if it
//  wishes to have stat logging.
//
// ====================================================================

class GameStats extends Info
		Native Config;

var FileLog TempLog;
var GameReplicationInfo GRI;
var bool bShowBots;

var string Tab;

/** create local stat logs */
var globalconfig bool bLocalLog;
/** filename to use, check GetLogFilename() for replacements */
var globalconfig string LogFileName;

native final function string GetStatsIdentifier( Controller C );
native final function string GetMapFileName();	// Returns the name of the current map

/////////////////////////////////////
// GameStats interface

function Init()
{
	if (bLocalLog)
	{
		TempLog = spawn(class 'FileLog');
		if (TempLog != None)
		{
			TempLog.OpenLog(GetLogFilename());
		}
		else {
			Warn("Could not create output file");
		}
	}
}
function Shutdown()
{
	if (TempLog!=None)
		TempLog.Destroy();
}
function Logf(string LogString)
{
	if (TempLog!=None)
		TempLog.Logf(LogString);
}

/////////////////////////////////////
// Internals

event PostBeginPlay()
{
	Super.PostBeginPlay();

	Tab = Chr(9);
	Init();
}

event Destroyed()
{
	Shutdown();
	Super.Destroyed();
}

function string TimeStamp()
{
	local string seconds;
	seconds = string(Level.TimeSeconds);

	// Remove the centiseconds
	if( InStr(seconds,".") != -1 )
		seconds = Left( seconds, InStr(seconds,".") );

	return seconds;
}

function string Header()
{
	return TimeStamp()$Tab;
}

function String FullTimeDate()		// Date/Time in MYSQL format
{
	return Level.Year$"-"$Level.Month$"-"$Level.Day$" "$Level.Hour$":"$Level.Minute$":"$Level.Second;
}

function String TimeZone()			// Timezone (offset) of game server's local time to GTM, e.g. -4 or +5
{
	return "0";						// FIXME Jack - currently pretending GMT
}

function String MapName()
{
	local string mapname;

	mapname = GetMapFileName();

	// Remove the file name extention .ut2
	if( InStr(mapname,".ut2") != -1 )
		mapname = Left( mapname, InStr(mapname,".ut2") );

	ReplaceText(mapname, tab, "_");

	return mapname;
}


// Stat Logging functions
function NewGame()
{
	local string out, tmp;
	local string ngTitle, ngAuthor, ngGameGameName;
	local int i;
	local mutator MyMutie;
	local GameRules MyRules;

	ngTitle			= Level.Title;			// Making local copies
	ngAuthor		= Level.Author;
	ngGameGameName	= Level.Game.GameName;
	ReplaceText(ngTitle,		tab, "_");	// Replacing tabs with _
	ReplaceText(ngAuthor,		tab, "_");
	ReplaceText(ngGameGameName, tab, "_");

	GRI = Level.Game.GameReplicationInfo;
	out = Header()$"NG"$Tab;				// "NewGame"
	out $= FullTimeDate()$Tab;		// Game server's local time
	out $= TimeZone()$Tab;			// Game server's time zone (offset to GMT)
	out $= MapName()$Tab;				// Map file name without map extention .ut2
	out $= ngTitle$Tab;
	out $= ngAuthor$Tab;
	out $= Level.Game.Class$Tab;
	out $= ngGameGameName;

	tmp = "";
	i = 0;
	foreach AllActors(class'Mutator',MyMutie)
	{
		if (tmp != "")
			tmp $= "|" $ MyMutie.Class;
		else
	 		tmp $= MyMutie.Class;

		i++;
	}
	foreach AllActors(class'GameRules',MyRules)
	{
		if (tmp!="")
			tmp $= "|"$MyRules.Class;
		else
			tmp $= MyRules.Class;

		i++;
	}

	if (i>0)
	{
		ReplaceText(tmp, tab, "_");
		out $= Tab $ "Mutators=" $ tmp;
	}
	Logf(out);
}

function ServerInfo()
{
	local string out, flags;
	local string siServerName, siAdminName, siAdminEmail;
	local GameInfo.ServerResponseLine ServerState;
	local int i;

	siServerName	= GRI.ServerName;	// Making local copies
	siAdminName		= GRI.AdminName;
	siAdminEmail	= GRI.AdminEmail;
	ReplaceText(siServerName,	tab, "_");
	ReplaceText(siAdminName,	tab, "_");
	ReplaceText(siAdminEmail,	tab, "_");

	out = Header() $ "SI" $ Tab;	// "SeverInfo"
	out  $= siServerName $ Tab;		// Server name
	out $= TimeZone()$Tab;			// Timezone
	out $= siAdminName$Tab;			// Admin name
	out $= siAdminEmail$Tab;		// Admin email
	out $= Tab;						// IP:port (filled in by Master Server)

	flags = "";							// Server flag / key combos
	Level.Game.GetServerDetails( ServerState );
	for( i=0;i<ServerState.ServerInfo.Length;i++ )
		flags $= "\\"$ServerState.ServerInfo[i].Key$"\\"$ServerState.ServerInfo[i].Value;

	ReplaceText(flags, tab, "_");
	out	$= flags;
	Logf(out);
}

function StartGame()
{
	Logf( Header()$"SG" );			// "StartGame"
}


// Send stats for the end of the game
function EndGame(string Reason)
{
	local string out;
	local int i,j;
	local array<PlayerReplicationInfo> PRIs;
	local PlayerReplicationInfo PRI,t;

	out = Header()$"EG"$Tab$Reason;	// "EndGame"

	// Quick cascade sort.
	for (i=0;i<GRI.PRIArray.Length;i++)
	{
		PRI = GRI.PRIArray[i];
		if ( !PRI.bOnlySpectator && !PRI.bBot )
		{
			PRIs.Length = PRIs.Length+1;
			for (j=0;j<Pris.Length-1;j++)
			{
				if (PRIs[j].Score < PRI.Score ||
				   (PRIs[j].Score == PRI.Score && PRIs[j].Deaths > PRI.Deaths) )
				{
					t = PRIs[j];
					PRIs[j] = PRI;
					PRI = t;
				}
			}
			PRIs[j] = PRI;
		}
	}

	// Minimal scoreboard, shows Playernumbers in order of Score
	for (i=0;i<PRIs.Length;i++)
		out $= Tab$Controller(PRIs[i].Owner).PlayerNum;

	Logf(out);
}


// Connect Events get fired every time a player connects to a server
function ConnectEvent(PlayerReplicationInfo Who)
{
	local string out;
	if ( Who.bBot || Who.bOnlySpectator )			// Spectators should never show up in stats!
		return;

	// C	0	11d8944d9e138a5aa688d503e0e4c3e0
	out = Header()$"C"$Tab$Controller(Who.Owner).PlayerNum$Tab;

	// Login identifier
	out $= GetStatsIdentifier(Controller(Who.Owner));

	Logf(out);
}

// Connect Events get fired every time a player connects or leaves from a server
function DisconnectEvent(PlayerReplicationInfo Who)
{
	local string out;
	if ( Who.bBot || Who.bOnlySpectator )			// Spectators should never show up in stats!
		return;

	// D	0
	out = Header()$"D"$Tab$Controller(Who.Owner).PlayerNum;	//"Disconnect"

	Logf(out);
}


// Scoring Events occur when a player's score changes
function ScoreEvent(PlayerReplicationInfo Who, float Points, string Desc)
{
	if ( Who.bBot || Who.bOnlySpectator )			// Just to be totally safe Spectators sends nothing
		return;
	Logf( Header()$"S"$Tab$Controller(Who.Owner).PlayerNum$Tab$Points$Tab$Desc );	//"Score"
}


function TeamScoreEvent(int Team, float Points, string Desc)
{
	Logf( Header()$"T"$Tab$Team$Tab$Points$Tab$Desc );	//"TeamScore"
}


// KillEvents occur when a player kills, is killed, suicides
function KillEvent(string Killtype, PlayerReplicationInfo Killer, PlayerReplicationInfo Victim, class<DamageType> Damage)
{
	local string out;

	if ( Victim.bBot || Victim.bOnlySpectator || ((Killer != None) && Killer.bBot) )
		return;

	out = Header()$Killtype$Tab;

	// KillerNumber and KillerDamagetype
	if (Killer!=None)
	{
		out $= Controller(Killer.Owner).PlayerNum$Tab;
		// KillerWeapon no longer used, using damagetype
		out $= GetItemName(string(Damage))$Tab;
	}
	else
		out $= "-1"$Tab$GetItemName(string(Damage))$Tab;	// No PlayerNum -> -1, Environment "deaths"

	// VictimNumber and VictimWeapon
	out $= Controller(Victim.Owner).PlayerNum$Tab$GetItemName(string(Controller(Victim.Owner).GetLastWeapon()));

	// Type killers tracked as player event (redundant Typing, removed from kill line)
	if ( PlayerController(Victim.Owner)!= None && PlayerController(Victim.Owner).bIsTyping)
	{
		if ( PlayerController(Killer.Owner) != PlayerController(Victim.Owner) )
			SpecialEvent(Killer, "type_kill");						// Killer killed typing victim
	}

	Logf(out);
}


// Special Events are everything else regarding the player
function SpecialEvent(PlayerReplicationInfo Who, string Desc)
{
	local string out;
	if (Who != None)
	{
		if ( Who.bBot || Who.bOnlySpectator )		// Avoid spectator suicide on console "type_kill"
			return;
		out = string(Controller(Who.Owner).PlayerNum);
	}
	else
		out = "-1";

	Logf( Header()$"P"$Tab$out$Tab$Desc );					//"PSpecial"
}


// Special events regarding the game
function GameEvent(string GEvent, string Desc, PlayerReplicationInfo Who)
{
	local string out, geDesc;

	if (Who != None)
	{
		if ( Who.bBot || Who.bOnlySpectator )		// Specator could cause NameChange, TeamChange! No longer.
			return;
		out = string(Controller(Who.Owner).PlayerNum);
	}
	else
		out = "-1";

	geDesc	= Desc;
	ReplaceText(geDesc, tab, "_");									// geDesc, can be the nickname!

	Logf( Header()$"G"$Tab$GEvent$Tab$out$Tab$geDesc );	//"GSpecial"
}

/**
	return the filename to use for the log file. The following formatting rules are accepted:
	%P		server port
	%Y		year
	%M		month
	%D		day
	%H		hour
	%I		minute
	%S		second
	%W		day of the week
*/
function string GetLogFilename()
{
  local string result;
  result = LogFileName;
  ReplaceText(result, "%P", string(Level.Game.GetServerPort()));
  ReplaceText(result, "%N", Level.Game.GameReplicationInfo.ServerName);
  ReplaceText(result, "%Y", Right("0000"$string(Level.Year), 4));
  ReplaceText(result, "%M", Right("00"$string(Level.Month), 2));
  ReplaceText(result, "%D", Right("00"$string(Level.Day), 2));
  ReplaceText(result, "%H", Right("00"$string(Level.Hour), 2));
  ReplaceText(result, "%I", Right("00"$string(Level.Minute), 2));
  ReplaceText(result, "%W", Right("0"$string(Level.DayOfWeek), 1));
  ReplaceText(result, "%S", Right("00"$string(Level.Second), 2));
  return result;
}

defaultproperties
{
	bLocalLog=false
	LogFileName="Stats_%P_%Y_%M_%D_%H_%I_%S"
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Di 5.9.2006 22:28:40.000 - Creation time: Do 14.8.2014 09:58:39.503 - Created with UnCodeX