Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gameauth
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sucssite
gameauth
Commits
7c601967
Commit
7c601967
authored
9 years ago
by
Stuart John Watson
Browse files
Options
Downloads
Patches
Plain Diff
Fixed game ping code
parent
86259b6f
No related branches found
Branches containing commit
No related tags found
1 merge request
!1
Major Rebuild: AJAX and working game info
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
games/minecraft.php
+19
-5
19 additions, 5 deletions
games/minecraft.php
games/sauerbraten.php
+21
-12
21 additions, 12 deletions
games/sauerbraten.php
with
40 additions
and
17 deletions
games/minecraft.php
+
19
−
5
View file @
7c601967
...
...
@@ -13,20 +13,36 @@ function getInfo(){
return
[
"online"
=>
false
,
"error"
=>
socket_strerror
(
socket_last_error
(
$sock
))];
}
$input
=
"
\x0f\x00\x2f\x09
127.0.0.1c
\xdd\x01\x01\x00
"
;
//Documentation on the ping protcol: http://wiki.vg/Server_List_Ping
// Size Protcol Version Next State
// _|_ Id_ _|_ _Address____ _Port__ _|_ _Request Packet
$input
=
"
\x0f\x00\x2f\x09
127.0.0.1
\x63\xdd\x01\x01\x00
"
;
socket_write
(
$sock
,
$input
,
strlen
(
$input
));
$out
=
socket_read
(
$sock
,
2048
);
socket_close
(
$sock
);
//Read an inital response from the socket
//This will let us get an initial size.
$out
=
socket_read
(
$sock
,
8
);
//Get the length of the packet
$t
=
readVarint
(
$out
);
$out
=
$t
[
"data"
];
$len
=
$t
[
"res"
];
//Keep reading from the socket
$toRead
=
$len
-
strlen
(
$out
);
while
(
$toRead
){
$out
.
=
socket_read
(
$sock
,
$toRead
);
$toRead
=
$len
-
strlen
(
$out
);
}
socket_close
(
$sock
);
if
(
substr
(
$out
,
0
,
1
)
!==
"
\x00
"
){
return
[
"online"
=>
false
,
"error"
=>
"server sent unexpected result"
];
}
$t
=
readVarint
(
substr
(
$out
,
1
));
$out
=
$t
[
"data"
];
$len
=
$t
[
"res"
];
...
...
@@ -62,6 +78,4 @@ function readVarint($data){
}
return
[
"res"
=>
$result
,
"data"
=>
substr
(
$data
,
$i
+
1
)];
}
#echo json_encode(minecraft());
?>
This diff is collapsed.
Click to expand it.
games/sauerbraten.php
+
21
−
12
View file @
7c601967
...
...
@@ -19,32 +19,41 @@ function getInfo(){
$out
=
socket_read
(
$sock
,
2048
);
socket_close
(
$sock
);
if
(
substr
(
$out
,
0
,
3
)
!==
$reqId
){
//Check the response starts with the request Id
if
(
substr
(
$out
,
0
,
strlen
(
$reqId
))
!==
$reqId
){
return
[
"online"
=>
false
,
"error"
=>
"server sent unexpected response"
];
}
$out
=
substr
(
$out
,
3
);
//Chop off request Id
$out
=
substr
(
$out
,
strlen
(
$reqId
));
//Read players & number of attributes
$numPlayers
=
readInt
(
$out
);
$numAttrs
=
readInt
(
$out
);
//Rad the basic version
$protcolVersion
=
readInt
(
$out
);
$gameMode
=
readInt
(
$out
);
$timeLeft
=
readInt
(
$out
);
$maxClients
=
readInt
(
$out
);
$masterMode
=
readInt
(
$out
);
//Check if we have 7 attributes
if
(
$numAttrs
==
7
){
//If we do we know if the game is paused and the speed
$gamePaused
=
readInt
(
$out
);
$gameSpeed
=
readInt
(
$out
);
}
else
{
$gamePaused
=
0
;
$gameSpeed
=
100
;
}
//Everything else is strings, take the reminder and explode on null
$tmp
=
explode
(
"
\x00
"
,
$out
);
$mapName
=
$tmp
[
1
];
$serverDesc
=
$tmp
[
2
];
//The first part is the map, the second is the desc
$mapName
=
$tmp
[
0
];
$serverDesc
=
$tmp
[
1
];
//Conversion from game mode id to string
$nnn
=
[
"Free for all"
,
"Coop Edit"
,
...
...
@@ -84,16 +93,16 @@ function getInfo(){
function
readInt
(
&
$out
){
$c
=
ord
(
substr
(
$out
,
0
,
1
));
if
(
$c
==
-
128
){
if
(
$c
==
128
){
//Number that follows is a unsigned sort (2 bytes)
$c
=
unpack
(
"v"
,
substr
(
$out
,
1
,
2
))[
1
];
$out
=
substr
(
$out
,
3
);
}
elseif
(
$c
==
-
127
){
//Number that follows is a unsigned int (4 bytes)
$c
=
unpack
(
"V"
,
substr
(
$out
,
1
,
4
))[
1
];
$out
=
substr
(
$out
,
3
);
}
else
{
//Number is just a byte
$out
=
substr
(
$out
,
1
);
return
unpack
(
"v"
,
substr
(
$out
,
1
,
2
));
}
elseif
(
$c
==
-
127
){
$out
=
substr
(
$out
,
1
);
return
unpack
(
"V"
,
substr
(
$out
,
1
,
4
));
}
else
{
$out
=
substr
(
$out
,
1
);
return
$c
;
}
return
$c
;
}
#echo json_encode(sauerbraten());
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment