NS2 player statistics

LazerLazer Join Date: 2003-03-11 Member: 14406Members, Contributor, Constellation, NS2 Playtester
edited March 2011 in Modding
<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?

Comments

  • MCMLXXXIVMCMLXXXIV Join Date: 2010-04-14 Member: 71400Members
    Hi Lazer!

    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).
  • LazerLazer Join Date: 2003-03-11 Member: 14406Members, Contributor, Constellation, NS2 Playtester
    edited February 2011
    Ok great this is even better than I expected. No need to mess around with parsing an output file if I can just post to the webserver itself. Thanks for the quick response this is exactly what I was looking for!

    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 :)
  • MaxMax Technical Director, Unknown Worlds Entertainment Join Date: 2002-03-15 Member: 318Super Administrators, Retired Developer, NS1 Playtester, Forum Moderators, NS2 Developer, Constellation, Subnautica Developer, Pistachionauts, Future Perfect Developer
    <!--quoteo(post=1831540:date=Feb 11 2011, 02:02 PM:name=MCMLXXXIV)--><div class='quotetop'>QUOTE (MCMLXXXIV @ Feb 11 2011, 02:02 PM) <a href="index.php?act=findpost&pid=1831540"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->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).<!--QuoteEnd--></div><!--QuoteEEnd-->
    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.
  • MCMLXXXIVMCMLXXXIV Join Date: 2010-04-14 Member: 71400Members
    edited February 2011
    Thanks for the clarification Max. I've put the details in the wiki: <a href="http://www.unknownworlds.com/ns2/wiki/index.php/Lua/Libraries/Shared/GetWebpage" target="_blank">NS2 Wiki: Shared.GetWebpage</a>

    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.
  • LazerLazer Join Date: 2003-03-11 Member: 14406Members, Contributor, Constellation, NS2 Playtester
    edited February 2011
    <!--quoteo(post=1831922:date=Feb 13 2011, 11:13 AM:name=MCMLXXXIV)--><div class='quotetop'>QUOTE (MCMLXXXIV @ Feb 13 2011, 11:13 AM) <a href="index.php?act=findpost&pid=1831922"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->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.<!--QuoteEnd--></div><!--QuoteEEnd-->
    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!
  • TigTig Join Date: 2010-05-08 Member: 71674Members, Reinforced - Shadow, WC 2013 - Silver
    <!--quoteo(post=1831969:date=Feb 13 2011, 04:38 PM:name=Lazer)--><div class='quotetop'>QUOTE (Lazer @ Feb 13 2011, 04:38 PM) <a href="index.php?act=findpost&pid=1831969"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->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!<!--QuoteEnd--></div><!--QuoteEEnd-->

    you win the internet. (#)(#)(#)(#)
  • LazerLazer Join Date: 2003-03-11 Member: 14406Members, Contributor, Constellation, NS2 Playtester
    stats up!

    <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)
  • PlasmaPlasma Join Date: 2003-04-26 Member: 15855Members, Constellation, Squad Five Blue
    Just a reminder to make sure you're using the asynchronous version (pass a callback function to GetWebpage) so that the server doesn't block waiting while uploading the stats data (and give players the impression the server has frozen / lagged).

    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.
  • endarendar Join Date: 2010-07-27 Member: 73256Members, Squad Five Blue
    edited February 2011
    Played a few games tonight, noticed that MY stats never got recorded :( I did crash a few times, but I also had a graceful exit too. Another thing, the tick rate was severely hit at times, dropping down to 15 at times, and sometimes down to 5-10, which is not usual behaviour for tram and that style of game (low amount of buildings, 6v7~). Got any ideas? For the mean time i'm reverting back to the original lua files (or I will when the server resets itself at 5am +11GMT).

    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.
  • LazerLazer Join Date: 2003-03-11 Member: 14406Members, Contributor, Constellation, NS2 Playtester
    I'm calling the method as follows: Shared.GetWebpage(ns2s_url, function (data) end)

    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)
  • endarendar Join Date: 2010-07-27 Member: 73256Members, Squad Five Blue
    I think I played a total of 5 rounds, but most of them I crashed out earlier. I also did successfully finish a round with a score, and then I did a proper exit from the ready room with no crash. The only thing I can think of was earlier that round I did crash, so when I rejoined I became endar(2) for a few minutes, then when endar left, i was back to endar. This was a good 10 minutes before the game ended.

    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.
  • LazerLazer Join Date: 2003-03-11 Member: 14406Members, Contributor, Constellation, NS2 Playtester
    edited February 2011
    Ok let me know how it goes. Those graphs do look similar to some others I have seen posted regarding performance and server crashing (starts with weird spikes then eventually crashes and has something to do with memory usage). There should be another patch coming out soon so I'll have updated lua files in case anything changes elsewhere in the code. I'm going to add some more debugging information server side so I can see if there are any requests being made that fail, but unless it has to do with the disconnect bug (not retrieving steamid properly on disconnect) I'm unsure why your stats didn't save. The games that I had played on the server saved my stats as well as all of the other players that were playing, but of course this is why we are testing :)
  • endarendar Join Date: 2010-07-27 Member: 73256Members, Squad Five Blue
    Is it anything to do with my stats being recorded before you did a reset? I remember instantly joining after modifying the files and getting some deaths (which i think counted), then you did a stats reset? Not exactly sure.
  • PlasmaPlasma Join Date: 2003-04-26 Member: 15855Members, Constellation, Squad Five Blue
    endar; actually that graph idea is neat. Maybe someone can write a plugin to just record the server tickrate to a log file every 10 seconds that can be graphed later?
  • playerplayer Join Date: 2010-09-12 Member: 73982Members
    I do believe that information is 'hidden' inside the engine, and not exposed to Lua (as are a great many other things unfortunatly). You can, however, implement a counter of sorts, that simply increments as each OnUpdate on a rudimentary class is called, alongside a timer to measure the amount of ticks that have occured during the last interval.
  • LazerLazer Join Date: 2003-03-11 Member: 14406Members, Contributor, Constellation, NS2 Playtester
    edited March 2011
    Hey guys there was some downtime with the stats between patches but with 167 running much better I've updated the mod again. Endar has the newest version on his server and it's been up running for a couple days now. I'm doing more work to the web side and also planning ways to add more features without causing too much overhead from page requests (if it does?). I've also got a few questions that maybe you guys would have some insight on:

    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!
  • playerplayer Join Date: 2010-09-12 Member: 73982Members
    edited March 2011
    <!--quoteo--><div class='quotetop'>QUOTE </div><div class='quotemain'><!--quotec-->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<!--QuoteEnd--></div><!--QuoteEEnd-->
    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.
  • LazerLazer Join Date: 2003-03-11 Member: 14406Members, Contributor, Constellation, NS2 Playtester
    Oh alright thanks for the info I added the link on the stats home page but I'll have to disable it until the connection launch behavior is fixed. Sounds like I'll need to do the same as you did with steamid too. Not saving players when they disconnect is the most annoying bug I'm dealing with right now since many people just casually connect and leave so I would really like to be recording these people too.

    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).
  • JmactheAttackJmactheAttack Join Date: 2011-04-20 Member: 94638Members, Reinforced - Shadow
    This mod looks pretty sick, I hope you open source it upon completion! I bet it will become very valuable for the NS2 clan pages.
  • LazerLazer Join Date: 2003-03-11 Member: 14406Members, Contributor, Constellation, NS2 Playtester
    Thanks Jmac I do plan to open source it once a few more fixes go in. I have barely had time to add much recently but have updated the code every few patches for endar to run (although it's currently not running at the moment). Once game performance stabilizes a bit further I will focus back more attention to the project. Glad to see this hasn't lost interest.
  • JmactheAttackJmactheAttack Join Date: 2011-04-20 Member: 94638Members, Reinforced - Shadow
    Once it is out, what would it take to run stats like that on my website:

    -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?
  • LazerLazer Join Date: 2003-03-11 Member: 14406Members, Contributor, Constellation, NS2 Playtester
    edited May 2011
    Sorry for the delayed reply. When I choose to release basically the requirements would be as follows:

    -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.
  • SN.WolfSN.Wolf Join Date: 2010-03-29 Member: 71115Members
    edited May 2011
    I think this would be great as a total package. You could bundle it ready to run (except config) with a portable web-server. I run all 5 of my trackmania servers including my records database and web server from a portable folder. I can run all of it on any system straight from a USB drive if i needed to (even web-server). All that the end user would need to do is set up a simple config, open ports, and change the PHPmyAdmin password, drop the mod in the game , since the database would already be built for them, they are ready to roll with minimal editing.

    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
  • JmactheAttackJmactheAttack Join Date: 2011-04-20 Member: 94638Members, Reinforced - Shadow
    It looks like he is using a Microsoft Stack instead of the good 'ol LAMP stack for the server-side.
Sign In or Register to comment.