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
// ====================================================================
//  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;

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

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

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

function Init()
{
	TempLog = spawn(class 'FileLog');
	if (TempLog!=None)
	{
		TempLog.OpenLog("Stats");
		Log("Output Game stats to: STATS.TXT");
	}
	else
	{
		Log("Could not spawn Temporary Stats Log");
		Destroy();
	}
}
function Shutdown()
{
	if (TempLog!=None) 
		TempLog.Destroy();
}
function Logf(string LogString)
{
	if (TempLog!=None)
		TempLog.Logf(LogString);
} 

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

event PostBeginPlay()
{
	Super.PostBeginPlay();
	Init();
}

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

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

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

	return seconds;
}

function string Header()
{
	return ""$TimeStamp()$Chr(9);
}

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;
	local string tab;
	tab = ""$Chr(9);
	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 tab, ngTitle, ngAuthor, ngGameGameName;
	local int i;
	local mutator MyMutie;
	local GameRules MyRules;

	tab				= ""$Chr(9);
	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"$Chr(9);				// "NewGame"
	out = out$FullTimeDate()$Chr(9);		// Game server's local time
	out = out$TimeZone()$Chr(9);			// Game server's time zone (offset to GMT)
	out = out$MapName()$Chr(9);				// Map file name without map extention .ut2
	out = out$ngTitle$Chr(9);
	out = out$ngAuthor$Chr(9);
	out = out$Level.Game.Class$Chr(9);
	out = out$ngGameGameName;

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

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

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

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

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

	out = Header()$"SI"$Chr(9);			// "SeverInfo"
	out = out$siServerName$Chr(9);		// Server name
	out = out$TimeZone()$Chr(9);		// Timezone
	out = out$siAdminName$Chr(9);		// Admin name
	out = out$siAdminEmail$Chr(9);		// Admin email
	out = out$Chr(9);					// 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 = flags$"\\"$ServerState.ServerInfo[i].Key$"\\"$ServerState.ServerInfo[i].Value;

	ReplaceText(flags, tab, "_");
	out	= 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 GameReplicationInfo GRI;
	local array<PlayerReplicationInfo> PRIs;
	local PlayerReplicationInfo PRI,t;

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

	GRI = Level.Game.GameReplicationInfo;

	// 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 = out$Chr(9)$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"$Chr(9)$Controller(Who.Owner).PlayerNum$Chr(9);

	// Login identifier
	out = 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"$Chr(9)$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"$Chr(9)$Controller(Who.Owner).PlayerNum$Chr(9)$Points$Chr(9)$Desc );	//"Score"
}


function TeamScoreEvent(int Team, float Points, string Desc)
{
	Logf( ""$Header()$"T"$Chr(9)$Team$Chr(9)$Points$Chr(9)$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$Chr(9);

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

	// VictimNumber and VictimWeapon
	//out = out$Controller(Victim.Owner).PlayerNum$Chr(9)$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 = ""$Controller(Who.Owner).PlayerNum;			
	}
	else
		out = "-1";

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


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

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

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

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

defaultproperties
{
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: ne 5.9.2004 16:01:22.000 - Creation time: st 23.5.2018 00:10:43.543 - Created with UnCodeX