NS2 player statistics
Lazer
Join Date: 2003-03-11 Member: 14406Members, Contributor, Constellation, NS2 Playtester
<div class="IPBDescription">something like an hlstats</div>Check out stats and be part of the tests at:
<a href="http://devin-afshin.com/default.aspx" target="_blank">http://devin-afshin.com/default.aspx</a> Australia - Pure NS2 (<a href="http://steam://connect/203.12.139.127:27015" target="_blank">203.12.139.127</a>) -thanks Endar
===== Update (3/15/2011) =====
Site has been updated some more. A couple stylesheet improvements and a few more stats on the main page. Endar's server is up to date with the mod as well. I will be trying to make a complete package for server ops to download soon but am not quite to that point yet (need to add a couple more admin customization settings first).
===== Update (2/21/2011) =====
Stats are now up for testing and new features are being added. Feel free to make requests I'm trying to make this a useful tool for server admins to make their servers feel more community oriented and to help bring back returning players.
some ideas:
-individual weapon kill tracking
-in game rank request
-more web admin tools?
== Original Post (2/11/2011) =====
Hey guys I was tossing around the idea of making a game stats tracking web package for server ops to link up with their servers (something like hlstats from back in the day). I realize there are a bunch of stat tracking programs tracking NS2 stats, but they don't quite seem to be doing what I'm trying to do (please correct me if there is already). I would like to track individual player stats to allow server ops to put on their community pages and not just be tracking general anonymous statistics.
I have no problem setting up the web package and database to hold and display all the data, but I have yet to play around with LUA code so I'm unsure if something like this is currently implementable? What I would need is at the end of a round (at least for now) to output a file holding statistics in a format something along the lines of the following:
<steamid> <nickname> <kills> <deaths> <points> <shots fired> <hits made> (+/- any other useful information each line being a different player, there should also be a header with the map name at the top of the file along with winning team)
A small program can parse the file and post the stats to the web server's database for viewing online. I remember most of the best NS1 community servers had pages like this and it might also encourage people to play more. Assuming I can retrieve at least the steamid/nickname/kills/deaths/points, the first version is planned to have pages for general server stats (such as top players), individual player stats, and basic map stats. A page for basic admin settings such as colors etc is planned too of course.
It would be helpful if someone could give me some input on this especially with the LUA side of things and if outputting a file like this is yet possible? (it seems simple enough..) Right now I'm just trying to develop the proof of concept but once working will provide for any server ops to use. If another programmer would like to help with the LUA to do so please speak up your efforts will not go unnoticed ;)
Also looking for a server op who would like to be the first to test with a dedicated server but I'm not quite to that point yet.
Thoughts?
<a href="http://devin-afshin.com/default.aspx" target="_blank">http://devin-afshin.com/default.aspx</a> Australia - Pure NS2 (<a href="http://steam://connect/203.12.139.127:27015" target="_blank">203.12.139.127</a>) -thanks Endar
===== Update (3/15/2011) =====
Site has been updated some more. A couple stylesheet improvements and a few more stats on the main page. Endar's server is up to date with the mod as well. I will be trying to make a complete package for server ops to download soon but am not quite to that point yet (need to add a couple more admin customization settings first).
===== Update (2/21/2011) =====
Stats are now up for testing and new features are being added. Feel free to make requests I'm trying to make this a useful tool for server admins to make their servers feel more community oriented and to help bring back returning players.
some ideas:
-individual weapon kill tracking
-in game rank request
-more web admin tools?
== Original Post (2/11/2011) =====
Hey guys I was tossing around the idea of making a game stats tracking web package for server ops to link up with their servers (something like hlstats from back in the day). I realize there are a bunch of stat tracking programs tracking NS2 stats, but they don't quite seem to be doing what I'm trying to do (please correct me if there is already). I would like to track individual player stats to allow server ops to put on their community pages and not just be tracking general anonymous statistics.
I have no problem setting up the web package and database to hold and display all the data, but I have yet to play around with LUA code so I'm unsure if something like this is currently implementable? What I would need is at the end of a round (at least for now) to output a file holding statistics in a format something along the lines of the following:
<steamid> <nickname> <kills> <deaths> <points> <shots fired> <hits made> (+/- any other useful information each line being a different player, there should also be a header with the map name at the top of the file along with winning team)
A small program can parse the file and post the stats to the web server's database for viewing online. I remember most of the best NS1 community servers had pages like this and it might also encourage people to play more. Assuming I can retrieve at least the steamid/nickname/kills/deaths/points, the first version is planned to have pages for general server stats (such as top players), individual player stats, and basic map stats. A page for basic admin settings such as colors etc is planned too of course.
It would be helpful if someone could give me some input on this especially with the LUA side of things and if outputting a file like this is yet possible? (it seems simple enough..) Right now I'm just trying to develop the proof of concept but once working will provide for any server ops to use. If another programmer would like to help with the LUA to do so please speak up your efforts will not go unnoticed ;)
Also looking for a server op who would like to be the first to test with a dedicated server but I'm not quite to that point yet.
Thoughts?
Comments
Just looked through the game code in NS2GameRules.lua and what you described is already in place. It's being used by UWE at the moment for stats tracking and displaying map annotations but there's no reason it can't be appropriated for stuff like "hl2stats-style" running game stats.
It looks like only HTTP GET is supported at the moment, so you might have to use a "for" loop and make a number of hits to your page otherwise you could run into some kind of max URL size limit.
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> local gameLengthString = string.format("%.2f", Shared.GetTime() - self.gameStartTime)
local urlString = "http://unknownworldsstats.appspot.com/statendgame?version=" .. ToString(Shared.GetBuildNumber()) .. "&winner=" .. ToString(winningTeam:GetTeamType()) .. "&length=" .. gameLengthString .. "&map=" .. Shared.GetMapName()
Shared.GetWebpage(urlString, function (data) end)<!--c2--></div><!--ec2-->
As you can see, you can use the Shared.GetWebpage function to do an HTTP GET request - you just have to put the data you want to send out of the NS2 server at the end of the request URL. If you can write a PHP web page to handle the data, store it in a database backend and return it in an appropriate format (JSON?) then that's probably the hardest part.
I haven't looked at how returned data is handled by Spark yet (but I know this is possible, again the map annotations already make use of data returned by a page).
If I can get the return data working I can display back a players rank ingame if they request it too. Lot's of possibilities :)
There are two ways to get data. Shared.GetWebpage can either block and return the requested page as a string, or if you pass in a function, it will call that function with the string when the data is available.
Also, for receiving and parsing complex data there is a JSON lua parser available here (free as in beer):
<a href="http://www.chipmunkav.com/downloads/Json.lua" target="_blank">http://www.chipmunkav.com/downloads/Json.lua</a>
P.S. Gameplay mods might accidentally distort UWE's end-game stats if the mod authors don't comment out the relevant lines for end-game stats etc. To address this, I have disabled all the Shared.GetWebpage calls in the Combat Mode mod for now as well as redirecting the "feedback" page.
Good point, mod authors might want to take this into consideration for their mods. I played around a bit this morning setting up a database with a little fake dummy data and a page to access and see top players descending by kills. Next I'll be setting up the page to receive the stats/update the database, then I'll be giving the LUA side of things a shot.
Once I can get this working locally I'm going to stick it up on my webhost and hopefully have this available with minimal functionality right after b163. If there are any server owners who would like a free stats page while I develop this please let me know! I can't guarantee keeping it up in the same place forever but the database will stay intact and can always be moved around if necessary.
I really appreciate the help guys it's looking like I might have this working sooner than I had initially thought. Such a flexible engine to work with!
**************
EDITS (2/14/11): Setup a stored procedure to increment kills and deaths for a player, a receiving page for queries, and a test page posting to it. Played around with the LUA, familiarized myself with the syntax and got the gameserver to post to the webserver at the end of each round. On the web side it also now handles recognizing and updating players through steamid and reflects the top players on the web page. Need to add a few more stat views, player pages, and going to take some screenshots for use on the website. Example link will be up in a couple days. Found a server op to work with too. Check back after b163 goes up and I should have an address of a stats page for Endar's server (he had offered to help run my LUA for some real live data). Thanks!
you win the internet. (#)(#)(#)(#)
<a href="http://devin-afshin.com/default.aspx" target="_blank">http://devin-afshin.com/default.aspx</a>
playing on: Australia - Pure NS2 (203.12.139.127)
I assume the web page request is happening in the main loop thread of the game, so pausing/blocking in there would make players receive lag.
Could be wrong though, but thats certainly what happens in Source plugins.
edit: Actually reverting now, as when I copied the lua files and overwrote the modified ones, it seems the server.exe picked up on this process and tried to relink them? I just killed it, started again.
Is this the asynchronous one? Either way I was very careful not to have this script interfere with gameplay. It is only called when a round ends (so a hitch doesn't matter) and is also called on a player disconnected (but it's not properly retrieving disconnected player steamid and instead updating playerid=0 in the databasse) which could maybe cause a hitch but it only calls once per disconnect versus once per player at the end of each round.
So no, I highly doubt this script had anything to do with slowing down the server. That tends to happen anyway when a server has been up for a while there is still some memory leak problems it would seem and over time causes tick rate to drop. I was actually quite surprised how well the server was playing when I hopped on earlier.
Brings up a question though. Am I able to implement this for say.. every kill a player makes? (or maybe have it update stats every 30s/minute etc) I had tried to avoid doing so to prevent blocking when calling the function but if it doesn't matter I have some ideas which become much easier being able to call this more often mid game.
Also endar, your stats did get put in the list:
<a href="http://devin-afshin.com/ns2s_players.aspx" target="_blank">http://devin-afshin.com/ns2s_players.aspx</a>
Says you played 2 rounds but had 0 kills/deaths. You mentioned crashing did you ever finish a round still having kills or deaths? From the looks of the stats you caught a couple endgames and if you had been playing midgame and had any score must have crashed? Also any mid game disconnect loses your score for the round (well technically doesn't but is updating steamid 0 adding score and changing last used player name which I'm trying to fix: <a href="http://devin-afshin.com/ns2s_Player.aspx?id=0" target="_blank">http://devin-afshin.com/ns2s_Player.aspx?id=0</a> )
Also marines are currently winning 2:1 on tram <a href="http://devin-afshin.com/ns2s_map.aspx?map=ns2_tram" target="_blank">http://devin-afshin.com/ns2s_map.aspx?map=ns2_tram</a> (random stat :p)
I'll leave it off for another day and get some games in tonight just so i can get another feel for the game (build) and the tickrate.
I'll try and explain it a bit more, using my preferred method, mspaint.exe.
<a href="http://img222.imageshack.us/i/tickrate.png/" target="_blank"><img src="http://img222.imageshack.us/img222/3333/tickrate.png" border="0" class="linked-image" /></a>
This is tickrate of game length. This is not real, this is my feeling of what i normally get watching net_stats tickrate (i always have it open).
The top graph shows tick rate steadily decreasing after a certain amount into the game, with very steady and predictable jumps down of 1-2 ticks at a time, as more buildings get in, DI etc etc.
The second graph showed what it felt like last night, while it still had the same steady decrease over a game, there were periods of up to 30 seconds? (didn't time) where the tickrate was hitting 10-15, people talked about the lag and I saw the connection problems detected screen appear. A couple more times it happened, becoming more frequent towards the end of the game (probably should have drawn one more in to the graph).
Does that make sense? I'll leave it off today, and just make sure that its not a 164 thing doing this, and if it feels like the top graph, tomorrow i'll try with the lua files back in.
Does anyone know if calling web requests mid-game causes lag? I'm deliberately avoiding doing this as much as possible but if it isn't a problem I might want to report game status using 1-2 minute intervals to show what/who's currently playing on the server. Right now the only web request that could happen mid game is when a player disconnects and their current stats get saved.
On player disconnect I cannot seem to receive steamid (called in player disconnect of Gamerules.lua). Is this a bug or is there another place to get steamid when a client is disconnecting? I could always add a variable to the playerdata and set it when they first connect but that seems redundant if there is another way to do it? Would really like to get this fixed as many player records are not being saved for the user and steamid 0 now has a score of 3500+ lol
Also I forget is there a way to have a website launch NS2 to a specific server url? I want to add this to the website so people can hop right in if they want.
Thanks everyone really appreciate the help!
I can confirm this behaviour. I have Ovrmind do complete gamestate-syncs continuously, so I always have a copy of the Steam-ID in memory. Whenever a client-disconnect event occurs, I simply retrieve the last known Steam-ID from memory. I actually didn't know about this little problem you ran into because of it (I had to force a state-update on disconnects to see Steam-IDs weren't returned properly anymore). It's a temp-fix, and it looks as if you've already thought to do the same.
<!--quoteo--><div class='quotetop'>QUOTE </div><div class='quotemain'><!--quotec-->Also I forget is there a way to have a website launch NS2 to a specific server url? I want to add this to the website so people can hop right in if they want.<!--QuoteEnd--></div><!--QuoteEEnd-->
steam://connect/ip:port
[EDIT]
Though I should mention that connect-links aren't working for NS2 yet. Using the connect port in that URL will have it hanging in the query-stage, same as using the Spark query-port (connectport+1). It seems to work with the GmOvrmind-queryresponder port (connectport+2), but it isn't able to complete the connection ingame.
Also when it comes to making midgame stat queries unless someone happens to know I'll have to run some tests to see if the game slows down at all. It doesn't seem to get jerky on round end (the time I would expect this the most since stats always update then) so making time interval based requests might be ok (if I can do this then many more features are possible).
-Would it require access to the game server (run a dedicated server vs renting a managed server)?
-Anything more than the average LAMP stack on the web server end?
-A web server capable of asp .net.
-An SQL server.
-A game server running the modded LUA.
They do not have to run on the same machine.
Installation will be very straightforward for the LUA. Basically I will write a little installer that will let you specify the webserver's address and once run the mod files can just be dropped on the game server.
The webserver/sql side will be a little trickier. It will require an SQL database be created and proper connection string obtained (still pretty simple for someone who has done this before). I will provide the necessary procedures to run and create the tables. All this leaves is for the web app to be dropped on the webserver and the SQL server connection string + game server address specified (so received stats don't get rejected). Everything beyond that will be customizable via the web interface.
That is roughly what would be required, although I'm still deciding how to make it as simple as possible and haven't even begun on putting together an installation package yet as I still have some development to make before feeling comfortable enough to have others try running the web server side of things.
When i get some free time i will see if i can set one up to see how it works out.
EDIT: will this be sufficient?
Php 5.2.13
Httpd 2.2.15
PhpMyAdmin 3.3.1-rc1
MySQL 5.1.44