Archived copy of war3source.com, the War3Source forum (2009–2020), rebuilt from the Internet Archive by wc3mods.net. This page was captured on 2013-01-25 (original capture). Forum · All archived topics · Wiki · Bug tracker · Blog
Chat

War3:Source
January 24, 2013, 10:55:51 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Download: http://war3source.com/index.php?board=9.0
What is War3Source?: http://war3source.com/index.php?topic=200.0
Sample Stats: http://war3source.com/war3stats
Steam Community Group: http://steamcommunity.com/groups/war3source
War3Source SVN Checkout: http://ownageclan.com/svn/war3source/
War3Source servers: http://www.game-monitor.com/search.php?vars=war3_version=
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [REQUEST] - changerace log  (Read 159 times)
Remy Lebeau
Full Member
***
Posts: 172


View Profile
« on: November 10, 2012, 04:16:55 PM »

So I've been doing quite a lot of debugging recently, and thought of some logging that should be pretty easy to implement, but also very helpful.

The idea here is that every time someone changes race, it simply writes a line to a log file.  Also, when the server first starts, the plugin writes a line to the file.  This would allow you to see the last few races chosen before a server crash.  An example might look something like:

L 11/09/2012 - 22:17:40: [SM] -  Changerace log session started (Server Start)
L 11/09/2012 - 22:17:43: [SM] - Player: [player1] changed race to - human - while - ALIVE -
L 11/09/2012 - 22:20:30: [SM] - Player: [player2] changed race to - undead - while - DEAD -
L 11/09/2012 - 23:17:40: [SM] -  Changerace log session started (Server Start)
L 11/09/2012 - 23:18:40: [SM] - Player: [player3] changed race to - orc - while - ALIVE -


The above result would suggest to me that either human or undead where the cause of the server crash, making it much easier to troubleshoot.

Thoughts?  I don't really know enough about the inner workings of the mod yet to code this myself, but it would seem to be reasonably straight forward to me (just add another line into where ever the changerace control happens that checks for a log cvar and appends to the log file if it's enabled, and a line when the plugin is first loaded to add the session start line)
Logged
Revan
Sr. Member
****
Posts: 346



View Profile
« Reply #1 on: November 10, 2012, 05:00:28 PM »

Yeah indeed it is pretty easy to do that
just create a empty plugin, include war3source interface and listen for race changes
public OnRaceSelected(client,oldrace,newrace)

in that function just add LogMessage and do your magic.
like for example:
LogMessage("%s : %s changed race from %s to %s(%s)",IsFakeClient(client)==true?"Bot":"Player",szPlayerNameVar,szOldRace,szNewRace,IsPlayerAlive(client)==true?"alive":"death");

edit
for the "server started" message I would just do a
public OnMapStart() (or similar) and then LogMessage("Map has been started");

so yeah thats the idea Smiley
« Last Edit: November 10, 2012, 05:09:16 PM by Revan » Logged

#war3source
Remy Lebeau
Full Member
***
Posts: 172


View Profile
« Reply #2 on: November 10, 2012, 08:57:07 PM »

Fantastic! Thanks for the help.

For anyone who wants it, here's my plugin (very simple, but seems to work):

Set war3_changerace_log 1 to enable

Code:
#pragma semicolon 1

#include "W3SIncs/War3Source_Interface"

new Handle:changeraceLogEnableCvar;

public Plugin:myinfo =
{
name = "War3Source - Addon - Changerace Log",
author = "Remy Lebeau",
description = "Writes to sourcemod console log each time someone changes race.  Use war3_changerace_log 1 to enable",
version = "1.0",
};
public W3ONLY(){}

public OnPluginStart()
{
// ########################## PLUGIN ENABLE ################################
changeraceLogEnableCvar = CreateConVar("war3_changerace_log","0","Enable / Disable the plugin");

}

public OnRaceChanged( client,oldrace,newrace )
{
if ( GetConVarBool(changeraceLogEnableCvar) )
{
new String:szPlayerName[64];
new String:szOldRace[64];
new String:szNewRace[64];
GetClientName( client, szPlayerName, 64 );
War3_GetRaceShortname(oldrace,szOldRace , 64);
War3_GetRaceShortname(newrace,szNewRace , 64);
LogMessage("%s : %s changed race from %s to %s(%s)",IsFakeClient(client)==true?"Bot":"Player",szPlayerName,szOldRace,szNewRace,IsPlayerAlive(client)==true?"alive":"dead");
}

}
Logged
Ownz
Developer
Administrator
Hero Member
*****
Posts: 2169



View Profile WWW
« Reply #3 on: November 10, 2012, 09:50:24 PM »

believe logging writes are slow (it could momentarily freeze the game ), thats why we avoid it

if you know SVN you can try committing this to SVN
Logged

DarkEnergy
Remy Lebeau
Full Member
***
Posts: 172


View Profile
« Reply #4 on: November 10, 2012, 10:07:22 PM »

believe logging writes are slow (it could momentarily freeze the game ), thats why we avoid it

if you know SVN you can try committing this to SVN


Is there a better way of doing it?

I'll look into committing it.  I may add more logging abilities into it over time.
Logged
Ownz
Developer
Administrator
Hero Member
*****
Posts: 2169



View Profile WWW
« Reply #5 on: November 10, 2012, 10:29:30 PM »

not really. "debugging code" is essentially expensive. if i turn on sourcemod built in profiler, the server will basically lag out because of all the keeping track of data overhead
Logged

DarkEnergy
Necavi
Sr. Member
****
Posts: 297


View Profile
« Reply #6 on: November 11, 2012, 03:43:15 PM »

Also, unless something is SEVERELY messed up, logging writes will be a LOT faster than console writes, due to the general lack of buffering in the console, and extremely high amount of buffering in the filesystem.
Logged

Ownz
Developer
Administrator
Hero Member
*****
Posts: 2169



View Profile WWW
« Reply #7 on: November 11, 2012, 04:15:05 PM »

yea they are both IO operations. who knows, trial and error or just benchmark it

ur statement is true assuming writes are cached and not forced commit.
Logged

DarkEnergy
Necavi
Sr. Member
****
Posts: 297


View Profile
« Reply #8 on: November 11, 2012, 05:06:11 PM »

Which, in MOST circumstances they will be.
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!