CS2D
General
Server Statistics in PHP
Server Statistics in PHP
20 replies Does anyone have php script for CS2D server statistics?
If anyone has, give me the link please.
Thank You Lee Moderator
Offline
Define server statistic... so your question is answered. (FOW doesn't work for 100 % atm) K.O.G can give script, can you? Lee Moderator
Offline
The idea is to just send 3 bytes to each server found in the server list. (You can do this by connecting to the usgn UDP (new in max, took me a while to trace it) @ 36963 and send the request)
IP: 85.214.77.150
Any programming language will do, as long as they support sockets. To create the byte char in php you can just get them directly by encoding 1, 0, 250 or just save the ascii characters in a string and send that. I never worked on socket before so im trying to understand. So leegao, your answer didnt help me much. I just used fsockopen connect the server that you give. I think i made it work, it connects but i still dont know what to do now.
Im looking valve counter-strike server stat script to get it right. But they didnt help me much. Time is 5.56 am, im working like 2 hours.
If you can write small script, everyone will be happy. Because its just a script, asked somepeople to get it, they rejected it like its PRIVATE. But theres a already script made for HL,CS,BF etc. etc.
In these days im getting into this game but meanwhile i want to develop and make the game better and more specific and more fun. If you guys dont help me now (dont percieve this like threat), someday i will make it work, but if you guys do help me now, it will be good for everyone who is searching for this.
This is enough, i hope you understand me. From now on its up to you. Lee Moderator
Offline
eh... I'm actually sort of busy right now, anyways here's what you need to do...
like I said before, declare a socket with an identifier (ie: $socket), connect using dgram connection to the ip and port I gave to you (just add udp: in front of the ip), build a string from chr(1)+chr(0)+chr(250) and then 6 more bytes, then on the same identifier do a readline() and echo the output. From there on you can format it however you want to. DC didnt answer...
Seems like no ones helping me with code.
So im stopping for now.
Someday someone will want the script like me but no code...
<?
$host = "85.214.77.150";
$port = 36963;
// don't timeout!
set_time_limit(0);
// create socket
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP) or die("Could not create socket\n");
// bind socket to port
$result = socket_bind($socket, "udp://$host", $port) or die("Could not bind to socket\n");
// start listening for connections
$result = socket_listen($socket, 3) or die("Could not set up socket listener\n");
// accept incoming connections
// spawn another socket to handle communication
$spawn = socket_accept($socket) or die("Could not accept incoming connection\n");
// read client input
$input = socket_read($spawn, 1024) or die("Could not read input\n");
// clean up input string
$input = trim($input);
// reverse client input and send back
$output = strrev($input) . "\n";
socket_write($spawn, $output, strlen ($output)) or die("Could not write output\n");
// close sockets
socket_close($spawn);
socket_close($socket);
?>
i got these from examples i found on net.
i edited like you said and giving error on binding.
and the second one -- same found on php.net
<?php
//The Client
error_reporting(E_ALL);
$address = "85.214.77.150";
$port = 36963;
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if ($socket === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
} else {
echo "socket successfully created.\n";
}
echo "Attempting to connect to '$address' on port '$port'...";
$result = socket_connect($socket,"udp://$address", $port);
if ($result === false) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
} else {
echo "successfully connected to $address.\n";
}
$i = 0;
while (true == true)
{
$i++;
echo "Sending $i to server.\n";
socket_write($socket, $i, strlen($i));
$input = socket_read($socket, 2048);
echo "Response from server is: $input\n";
sleep(5);
}
echo "Closing socket...";
socket_close($socket);
?>
And this is last -- they should work but they stuck at binding.
Also im not writing here, have tried fsockopen & stream_socket_server.. DC Admin
Offline
I can't help you with this. I never wrote a script for this. You wrote this site and you made 4 games why you cant write this? Ah im *ing tired. Ok i drop this. DC Admin
Offline
I just said I never wrote something like this. I don't write stuff that I don't need. that is the point. Lee Moderator
Offline
<?php
$fp = fsockopen("udp://127.0.0.1", 2008, $errno, $errstr, 10);
if (!$fp) {
echo "ERROR: $errno - $errstr<br />\n";
} else {
$data = chr(1).chr(0).chr($_GET['cmd']);
fwrite($fp, $data);
echo fgets($fp, 3072);
fclose($fp);
}
?> I didnt think this way. I hope it works -- thank you leegao for your help. Sorry for the double posting but i inserted to my web page and it didnt work. And i dont have list of commands for $_GET cmd. Where are the commands?
My server is opened and i inserted to my ip's mainpage so its not working.
Both way 127.0.0.1 and my net ip. Lee Moderator
Offline
oh, sorry, $_Get['cmd'] basically retrieves a get parameter from the URI. eg, if this file is named server.php, the you have to use the following link:
server.php?cmd=250
btw, replace the 127.0.0.1 and 2008 with IP and Port. (This came from an old server_console script I made.) I changed everything before you said.
It gives timeout error
Fatal error: Maximum execution time of 30 seconds exceeded in C:\AppServ\www\index.php on line 41
<?php
$fp = fsockopen("udp://127.0.0.1", 36963, $errno, $errstr, 5);
if (!$fp) {
echo "ERROR: $errno - $errstr<br />\n";
} else {
$data = chr(1).chr(0).chr($_GET['cmd']);
fwrite($fp, $data);
echo fgets($fp, 3072);
fclose($fp);
}
?>
Try yourself if you want but it didnt work here. If you make it work, write here please. Lee Moderator
Offline
The server pinged out. The IP 127.0.0.1 is the local host, to connect to a real server you'll have to change it.
If you would like to have a url structured as the following:
server.php?cmd=250&ip=xxx.xxx.xxx.xxx&port=36963
then change the first line to $fp = fsockopen("udp://".$_GET['ip'], $_GET['port'], $errno, $errstr, 5); You dont have to use that. It only makes the script more specific. I wrote my net ip as before, it return null string.