Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
G
gameauth
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
sucssite
gameauth
Commits
7c601967
Commit
7c601967
authored
Jan 20, 2016
by
Stuart John Watson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed game ping code
parent
86259b6f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
17 deletions
+40
-17
games/minecraft.php
games/minecraft.php
+19
-5
games/sauerbraten.php
games/sauerbraten.php
+21
-12
No files found.
games/minecraft.php
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());
?>
games/sauerbraten.php
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());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment