Files

> > CS2D > Misc. > PHP: Viewing server data
Files overviewCS2D overviewMisc. overview

English PHP: Viewing server data >

21 comments4 kb, 904 Downloads

old PHP: Viewing server data

Apache uwu
User Off Offline

Updated for CS2D 1.0.0.6 and PHP >= 5.4.

Methods

> CS2D::getInfo($ip, $port);

Returns an associative array with the format

1
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
)

> CS2D::getPlayers($ip, $port)

Returns an associative array with the format

1
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)
        )
    ...
)
edited 8×, last 29.01.18 05:44:17 pm
Approved by Seekay

Download Download

4 kb, 904 Downloads

Comments

21 comments
Page
To the start Previous 1 2 Next To the start

Log in!

You need to log in to be able to write comments!Log in

old

Hajt
User On Online

Nice script
I like it!
edited 2×, last 20.07.15 02:02:25 am

old

Lee
Moderator Off Offline

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

old

Apache uwu
User Off Offline

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.

old

Lee
Moderator Off Offline

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

1
01 00 fb status len sv_name len sv_map online sv_max sv_gamemode?:nothing bot_count

Where status goes something like
1
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
So, to find out if the server supports lua, simply and with 2^6 or 0x40

1
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

old

Apache uwu
User Off Offline

It's a script, since it's not compiled. You hacked save file? o.o careful don't use that word too often.

old

Ultimate programmer
BANNED Off Offline

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!
I like it!

old

Apache uwu
User Off Offline

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?

old

Lee
Moderator Off Offline

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.

old

Apache uwu
User Off Offline

@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

old

DC
Admin Off Offline

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.
I like it!

old

kalis
User Off Offline

make script give rcon too :))
I like it!

old

tom282f3
User Off Offline

Great PHP app! cool! I lov it
I like it!

old

buraxia3
User Off Offline

I agree with Ax3 its excellent!
I like it!

old

Ax3
User Off Offline

Excellent! Thank you, man, i wanted it! 5/5
I like it!

old

maPmaKer
User Off Offline

This is so great. Very good man
I like it!

old

ULtiMa
User Off Offline

Wow, nice koss..err.. Textual Context.
I like it!

old

Andrez
User Off Offline

waw


gj i like it...?

5/5,Awesome
I like it!

old

Starkkz
Moderator Off Offline

Nice script. Btw, Make one that gives you the password and the rcon password xD.
I like it!
To the start Previous 1 2 Next To the start