Query Mechanism
#1

I am trying to show the server stats on my website.
Almost everything works, except the ping.

I get my info from the wiki: https://sampwiki.blast.hk/wiki/Query/Req...ng_the_packets
But there is no further explanation about the opcode: p

So i don't know how to receive/send those 4 pseudo-random characters.
I tried to experiment a little, but without success.

So my question is: does someone know how to do this?

I am dutch, so my English could be a little rubbish
Reply
#2

Quote:
Originally Posted by D00Mpy
I am trying to show the server stats on my website.
Almost everything works, except the ping.

I get my info from the wiki: https://sampwiki.blast.hk/wiki/Query/Req...ng_the_packets
But there is no further explanation about the opcode: p

So i don't know how to receive/send those 4 pseudo-random characters.
I tried to experiment a little, but without success.

So my question is: does someone know how to do this?

I am dutch, so my English could be a little rubbish
You can't ping udp connections.
Reply
#3

Yes you can, ping is the total amount of time to send a message to the server and receive a message back from the server.

And i know it's possible (The wiki says so), but the wiki didn't tell what message to send and receive.
Reply
#4

Quote:
Originally Posted by D00Mpy
Yes you can, ping is the total amount of time to send a message to the server and receive a message back from the server.

And i know it's possible (The wiki says so), but the wiki didn't tell what message to send and receive.
No you can't, you can't ping a UDP port as far as i'm aware. I needed this a week ago for my image script but didn't have any luck.
Reply
#5

lol, and how do you think, the SA:MP client displays ping?, that's UDP also.......
Reply
#6

Quote:
Originally Posted by D00Mpy
lol, and how do you think, the SA:MP client displays ping?, that's UDP also.......
Well i assumed because the developers of the server also created the client that they would know the proper way of pinging it.

As i have tried pinging the server many a times with no proper response, PM me if you find a solution
Reply
#7

Quote:
Originally Posted by Norn
Quote:
Originally Posted by D00Mpy
lol, and how do you think, the SA:MP client displays ping?, that's UDP also.......
Well i assumed because the developers of the server also created the client that they would know the proper way of pinging it.

As i have tried pinging the server many a times with no proper response, PM me if you find a solution
I'll do.

On the wiki https://sampwiki.blast.hk/wiki/Query/Req...e_packet_table check the p opcode..
Thats how sa-mp pings

But it isn't well explained
Reply
#8

Quote:
Originally Posted by D00Mpy
Quote:
Originally Posted by Norn
Quote:
Originally Posted by D00Mpy
lol, and how do you think, the SA:MP client displays ping?, that's UDP also.......
Well i assumed because the developers of the server also created the client that they would know the proper way of pinging it.

As i have tried pinging the server many a times with no proper response, PM me if you find a solution
I'll do.

On the wiki https://sampwiki.blast.hk/wiki/Query/Req...e_packet_table check the p opcode..
Thats how sa-mp pings

But it isn't well explained
The socket just lags out when i use the p opcode, is it the same for you?
Reply
#9

Quote:
Originally Posted by Norn
Quote:
Originally Posted by D00Mpy
Quote:
Originally Posted by Norn
Quote:
Originally Posted by D00Mpy
lol, and how do you think, the SA:MP client displays ping?, that's UDP also.......
Well i assumed because the developers of the server also created the client that they would know the proper way of pinging it.

As i have tried pinging the server many a times with no proper response, PM me if you find a solution
I'll do.

On the wiki https://sampwiki.blast.hk/wiki/Query/Req...e_packet_table check the p opcode..
Thats how sa-mp pings

But it isn't well explained
The socket just lags out when i use the p opcode, is it the same for you?
yeah..

But i found something:
Код:
<?php
		$sPacket = 'SAMP';
		$sPacket .= chr(strtok($this->aServer[0], '.'));
		$sPacket .= chr(strtok('.'));
		$sPacket .= chr(strtok('.'));
		$sPacket .= chr(strtok('.'));
		$sPacket .= chr($this->aServer[1] & 0xFF);
		$sPacket .= chr($this->aServer[1] >> 8 & 0xFF);
		$sPacket .= 'p4150';
?>
This is from Server Query and RCON API - Be an admin at ease! (16/02/2010)

this uses the p opcode, and then sends the 4 pseudo-random numbers.

and then checks if he gets the numbers back from the server. (not to check ping but to check if it's online)
but you can easaly make a ping function out of this.
Reply
#10

Quote:
Originally Posted by D00Mpy
Quote:
Originally Posted by Norn
Quote:
Originally Posted by D00Mpy
Quote:
Originally Posted by Norn
Quote:
Originally Posted by D00Mpy
lol, and how do you think, the SA:MP client displays ping?, that's UDP also.......
Well i assumed because the developers of the server also created the client that they would know the proper way of pinging it.

As i have tried pinging the server many a times with no proper response, PM me if you find a solution
I'll do.

On the wiki https://sampwiki.blast.hk/wiki/Query/Req...e_packet_table check the p opcode..
Thats how sa-mp pings

But it isn't well explained
The socket just lags out when i use the p opcode, is it the same for you?
yeah..

But i found something:
Код:
<?php
		$sPacket = 'SAMP';
		$sPacket .= chr(strtok($this->aServer[0], '.'));
		$sPacket .= chr(strtok('.'));
		$sPacket .= chr(strtok('.'));
		$sPacket .= chr(strtok('.'));
		$sPacket .= chr($this->aServer[1] & 0xFF);
		$sPacket .= chr($this->aServer[1] >> 8 & 0xFF);
		$sPacket .= 'p4150';
?>
This is from Server Query and RCON API - Be an admin at ease! (16/02/2010)

this uses the p opcode, and then sends the 4 pseudo-random numbers.

and then checks if he gets the numbers back from the server. (not to check ping but to check if it's online)
but you can easaly make a ping function out of this.
Have you tried microtime with it yet?
Reply
#11

Quote:
Originally Posted by Norn
Quote:
Originally Posted by D00Mpy
Quote:
Originally Posted by Norn
Quote:
Originally Posted by D00Mpy
Quote:
Originally Posted by Norn
Quote:
Originally Posted by D00Mpy
lol, and how do you think, the SA:MP client displays ping?, that's UDP also.......
Well i assumed because the developers of the server also created the client that they would know the proper way of pinging it.

As i have tried pinging the server many a times with no proper response, PM me if you find a solution
I'll do.

On the wiki https://sampwiki.blast.hk/wiki/Query/Req...e_packet_table check the p opcode..
Thats how sa-mp pings

But it isn't well explained
The socket just lags out when i use the p opcode, is it the same for you?
yeah..

But i found something:
Код:
<?php
		$sPacket = 'SAMP';
		$sPacket .= chr(strtok($this->aServer[0], '.'));
		$sPacket .= chr(strtok('.'));
		$sPacket .= chr(strtok('.'));
		$sPacket .= chr(strtok('.'));
		$sPacket .= chr($this->aServer[1] & 0xFF);
		$sPacket .= chr($this->aServer[1] >> 8 & 0xFF);
		$sPacket .= 'p4150';
?>
This is from Server Query and RCON API - Be an admin at ease! (16/02/2010)

this uses the p opcode, and then sends the 4 pseudo-random numbers.

and then checks if he gets the numbers back from the server. (not to check ping but to check if it's online)
but you can easaly make a ping function out of this.
Have you tried microtime with it yet?
I have got it working :P

I will PM you the code..
Reply
#12

Quote:
Originally Posted by D00Mpy
Quote:
Originally Posted by Norn
Quote:
Originally Posted by D00Mpy
Quote:
Originally Posted by Norn
Quote:
Originally Posted by D00Mpy
Quote:
Originally Posted by Norn
Quote:
Originally Posted by D00Mpy
lol, and how do you think, the SA:MP client displays ping?, that's UDP also.......
Well i assumed because the developers of the server also created the client that they would know the proper way of pinging it.

As i have tried pinging the server many a times with no proper response, PM me if you find a solution
I'll do.

On the wiki https://sampwiki.blast.hk/wiki/Query/Req...e_packet_table check the p opcode..
Thats how sa-mp pings

But it isn't well explained
The socket just lags out when i use the p opcode, is it the same for you?
yeah..

But i found something:
Код:
<?php
		$sPacket = 'SAMP';
		$sPacket .= chr(strtok($this->aServer[0], '.'));
		$sPacket .= chr(strtok('.'));
		$sPacket .= chr(strtok('.'));
		$sPacket .= chr(strtok('.'));
		$sPacket .= chr($this->aServer[1] & 0xFF);
		$sPacket .= chr($this->aServer[1] >> 8 & 0xFF);
		$sPacket .= 'p4150';
?>
This is from Server Query and RCON API - Be an admin at ease! (16/02/2010)

this uses the p opcode, and then sends the 4 pseudo-random numbers.

and then checks if he gets the numbers back from the server. (not to check ping but to check if it's online)
but you can easaly make a ping function out of this.
Have you tried microtime with it yet?
I have got it working :P

I will PM you the code..
Excellent work!
Reply
#13

For the people that are searching for this.
Here is the code that works:

I took GamerX as example, because it was the first in my favorite list :P

Makers: D00Mpy and Norn
Код:
<?php
$server = "217.18.70.90";   // GamerX
$port = 8800;

$socket = fsockopen('udp://'.$server, $port, $iError, $sError, 2);
if(!$socket)
{
  exit("Connection Failed");
}

stream_set_blocking($socket, 1);

$sPacket = 'SAMP';
$sPacket .= chr(strtok($server, '.'));
$sPacket .= chr(strtok('.'));
$sPacket .= chr(strtok('.'));
$sPacket .= chr(strtok('.'));
$sPacket .= chr($port & 0xFF);
$sPacket .= chr($port >> 8 & 0xFF);
$sPacket .= 'p4150';

$start = microtime(true);
fwrite($socket, $sPacket);
$data = fread($socket, 15);
$end = microtime(true);
$ping = ($end - $start) * 1000;
$ping = floor($ping);
echo $ping;

fclose($socket);
?>
Reply
#14

Quote:
Originally Posted by D00Mpy
For the people that are searching for this.
Here is the code that works:

I took GamerX as example, because it was the first in my favorite list :P

Makers: D00Mpy and Norn
Код:
<?php
$server = "217.18.70.90";  // GamerX
$port = 8800;

$socket = fsockopen('udp://'.$server, $port, $iError, $sError, 2);
if(!$socket)
{
  exit("Connection Failed");
}

stream_set_blocking($socket, 1);

$sPacket = 'SAMP';
$sPacket .= chr(strtok($server, '.'));
$sPacket .= chr(strtok('.'));
$sPacket .= chr(strtok('.'));
$sPacket .= chr(strtok('.'));
$sPacket .= chr($port & 0xFF);
$sPacket .= chr($port >> 8 & 0xFF);
$sPacket .= 'p4150';

$start = microtime(true);
fwrite($socket, $sPacket);
$data = fread($socket, 15);
$end = microtime(true);
$ping = ($end - $start) * 1000;
$ping = floor($ping);
echo $ping;

fclose($socket);
?>
Two heads are better than one!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)