PHP: Viewing server data 
21 comments Updated for CS2D 1.0.0.6 and PHP >= 5.4.
Methods
CS2D::getInfo($ip, $port);
Returns an associative array with the format
CS2D::getPlayers($ip, $port)
Returns an associative array with the format
Methods

Returns an associative array with the format
Code:
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
Array (
[Name] => Server Name
[Map] => de_dust
[Players] => 14 / 32 (Bots: 0)
[Password] => None
[U.S.G.N. only] => Off
[Fog of War] => Off
[Friendly Fire] => Off
[Lua] => Uses Lua Scripts!
[Game Mode] => Deathmatch
)
[Name] => Server Name
[Map] => de_dust
[Players] => 14 / 32 (Bots: 0)
[Password] => None
[U.S.G.N. only] => Off
[Fog of War] => Off
[Friendly Fire] => Off
[Lua] => Uses Lua Scripts!
[Game Mode] => Deathmatch
)

Returns an associative array with the format
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Array (
[3] => Array
(
[name] => Player
[score] => 7
[deaths] => 0
[team] => Counter-Terrorist
)
[another_id] => Array
(
[name] => Player 2
[score] => 9
[deaths] => 8
[team] => Terrorist (or Spectator)
)
...
)
[3] => Array
(
[name] => Player
[score] => 7
[deaths] => 0
[team] => Counter-Terrorist
)
[another_id] => Array
(
[name] => Player 2
[score] => 9
[deaths] => 8
[team] => Terrorist (or Spectator)
)
...
)
edited 8×, last 29.01.18 05:44:17 pm

Comments
21 commentsLog in!
You need to log in to be able to write comments!Log in
11.10.11 08:50:51 pm
ok to fix , you need edit with notepad ,
search
$players=hexdec(substr($v_temp,-8,2));
and change for this:
$players=hexdec(substr($v_temp,-4,2));
is only this. Thanks
search
$players=hexdec(substr($v_temp,-8,2));
and change for this:
$players=hexdec(substr($v_temp,-4,2));
is only this. Thanks
15.08.11 04:53:33 pm

http://94.228.211.23/server.php?ip=94.228.211.23&port=36965
The amount of players is not always shown correctly.
The amount of players is not always shown correctly.
as far as I can recall, if gamemode is standard, then the next to last byte of the packet is omitted, otherwise the byte corresponding to the gamemode is added in right before the last byte.
On the other hand, if you're curious about how cs2d's network works, jermuk, flood, and I worked on a clone this past year at https://github.com/FloooD/custom_cs2dsrv/tree/master/src
On the other hand, if you're curious about how cs2d's network works, jermuk, flood, and I worked on a clone this past year at https://github.com/FloooD/custom_cs2dsrv/tree/master/src
Omg nice--I wouldn't never have thought of that.
Standard gamemode is different from the other games modes btw.
That :nothing becomes 2 zeros when it's standard which is weird.
Standard gamemode is different from the other games modes btw.
That :nothing becomes 2 zeros when it's standard which is weird.
Quote:
So this would be the same idea as 'modding'. I'm not understanding your post, how could I get those bools without using my current method?
Hmm, if I recall, the server info response looks something like
Code:
1
01 00 fb status len sv_name len sv_map online sv_max sv_gamemode?:nothing bot_count
Where status goes something like
Code:
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
bit position
1 - has password
2 - usgnonly
3 - fow
4 - ff
5 - version
6 - not standard mode
7 - lua
8 - dedicated
1 - has password
2 - usgnonly
3 - fow
4 - ff
5 - version
6 - not standard mode
7 - lua
8 - dedicated
So, to find out if the server supports lua, simply and with 2^6 or 0x40
Code:
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
pass = status&0x01
usgn = status&0x02
fow = status&0x04
ff = status&0x08
sver = status&0x10
gm = status&0x20
lua = status&0x40
dedi = status&0x80
usgn = status&0x02
fow = status&0x04
ff = status&0x08
sver = status&0x10
gm = status&0x20
lua = status&0x40
dedi = status&0x80
It's a script, since it's not compiled. You hacked save file? o.o careful don't use that word too often.

Nice! I think It is awesome program. I have made program to read and edit files for bytes.I have hacked save file of one game and made it done!
So this would be the same idea as 'modding'. I'm not understanding your post, how could I get those bools without using my current method?

In case you're curious, the O(1) (constant time in all modern ALU at least) way of retrieving whether a certain bit has been set in a number that DC is suggesting is to create a number (the mask) with all other bits set to zero, and then bitwise and the mask to the number. Since these masks are just numerical constants, and since they only have one bit set, they will always be an exponent of base two (which makes allocating them on the fly very fast and easy). Anyways, here's an idiomatic example. Say we want to retrieve the third bit of a number, we simply ask for the value of num&(2^(3-1)) or num&4.
@DC how is it done in CS2D? I find it easier just to "mod" it, which is dividing the hexdec by 2 every time until the number reaches 1--recording if the mod returns 1 (true) or 0 (false)...
What I don't understand is why you decided to use 128, 64, 8, 4, 1 for all the bool values.
You could have made it , 1, 2, 4, 8, 16, 32, etc so the bit would be smaller.
Very good programming on your half
What I don't understand is why you decided to use 128, 64, 8, 4, 1 for all the bool values.
You could have made it , 1, 2, 4, 8, 16, 32, etc so the bit would be smaller.

Very good programming on your half


step 5 would have been much easier and faster with some binary/bitwise ANDs (& in php) but I still like it because it's working and there are comments and tabs in it.
