Forum

> > CS2D > Scripts > php script for read userstats.dat
Forums overviewCS2D overview Scripts overviewLog in to reply

English php script for read userstats.dat

15 replies
To the start Previous 1 Next To the start

old Re: php script for read userstats.dat

MikuAuahDark
User Off Offline

Quote
From thread cs2d Server rank issue(score is altered)
user DC has written
It only seems to affect the first two players and their score value. All other values seem to be legit (the third guy played over 30 days on your server. omg!). You may consider to edit sys/stats/userstats.dat with a hexeditor or with a tool for stats editing (I think there was one somewhere but I can't find it). Just set the wrong scores to the same values as the kill values. Those two values are quite equal in most cases because only special actions like defusing a bomb gives you additional score points besides killing.

!!!Make a backup before editing!!!

The userstats.dat format is very simple:
1
2
3
4
5
6
username (string, linebreak afterwards)
usgn id (32 bit signed integer)
score (32 bit signed integer)
frags (32 bit signed integer)
deaths (32 bit signed integer)
time on server in seconds (32 bit signed integer)
this data set for each saved user

So when using a hex editor you have to
• find the username which has a wrong score
• skip 4 bytes (characters) in the line right after that username
• and copy&paste the 4 bytes right after that back to the first 4 bytes in that line

you could also simply remove the "damaged" users from the file.


You may need to skip the first 17 Bytes on it

old Re: php script for read userstats.dat

RoDioN1322
BANNED Off Offline

Quote
A little self made​​, I can not continue.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php

function inte($a, $b, $c, $d){
return $a*16777216+$b*65536+$c*256+$d;
}

function StatsRank($usgn){
$t = fopen('userstats.dat', 'rb');
$line = fread($t, filesize('userstats.dat'));
fclose($t);
$line = substr($line, 17);

}
?>

old Re: php script for read userstats.dat

Marcell
Super User Off Offline

Quote
http://www.laruence.com/lua/
maybe with this

You need to download this package.. then
use it like this! good luck.

test.lua
Spoiler >


test.php
Spoiler >

old Re: php script for read userstats.dat

MikuAuahDark
User Off Offline

Quote
user RoDioN1322 has written
string.byte in lua, how will this function in php?

string.byte in lua = ord in php
string.char in lua = chr in php

EDIT: I write some PHP script that read files from userstats.dat. The code is same as file cs2d [UNUSED] Get Player Rank v1.4 with some fixed bugs and converted to PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php

$filename="dir/to/stats/userstats.dat";

function to_intl($lpstr) {
	return ord($lpstr[0])+ord($lpstr[1])*256+ord($lpstr[2])*65536+ord($lpstr[3])*16777216;
}

function GetUserStatRank($usgn) {
	global $filename;
	$t=fopen($filename,"rb");
	if(!$t) die("Cannot open userstats.dat");
	$a=fread($t,filesize($filename));
	fclose($t);
	$a=substr($a,18);
	$temp=[
		"isexists" => false,
		"score" => 0,
		"frags" => 0,
		"deaths" => 0,
		"time" => 0
	];
	while(true) {
		$newline=strpos($a,"\n");
		if($newline===false) break;
		$a=substr($a,$newline+1);
		if(to_intl($a)==$usgn) {
			$temp["isexists"]=true;
			$a=substr($a,4);
			$temp["score"]=to_intl($a);
			$a=substr($a,4);
			$temp["frags"]=to_intl($a);
			$a=substr($a,4);
			$temp["deaths"]=to_intl($a);
			$a=substr($a,4);
			$temp["time"]=to_intl($a);
			break;
		} else {
			$a=substr($a,21);
		}
	}
	return $temp;
}

?>
It returns array which contain information that same as my file above.
edited 1×, last 31.03.14 05:30:35 am
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview