Server Help

Misc User Apps - Is it possible to connect to SS via PHP?

Anonymous - Fri Mar 31, 2006 9:17 pm
Post subject: Is it possible to connect to SS via PHP?
If so, can anyone give me a quick insight on how it would be done?
CypherJF - Fri Mar 31, 2006 9:22 pm
Post subject:
Possible, maybe. Unlikely, yes.
Anonymous - Fri Mar 31, 2006 10:19 pm
Post subject:
I don't mean a continuous connection, but like connect then check messages maybe, or get a player count for a zone, or check for available squads/names. This seems feasible to me but I don't know the method of how it would be done.
Dr Brain - Fri Mar 31, 2006 11:08 pm
Post subject:
Possible in the same way that the sun could explode tomorrow. It could happen, but it probably wont.
Anonymous - Fri Mar 31, 2006 11:21 pm
Post subject:
You guys are amazingly helpful
Mine GO BOOM - Fri Mar 31, 2006 11:27 pm
Post subject:
PHP has Sockets which will let you connect with UDP. Just look at the source for some bot cores or on the Wiki for packet information. You can check player counts for a zone just by using the Ping Protocol which will tell you the current ping to a zone and the player count, just like on the main menu of Continuum.

Actually logging into a zone to do messaging is a lot more complex, and you'd need to look through a bot core for how to do that.
Anonymous - Fri Mar 31, 2006 11:36 pm
Post subject:
t.y. MGB, I'll give it a look
BDwinsAlt - Sat Apr 01, 2006 12:28 am
Post subject:
I have seen a Java Applet connect to an ASSS zone before. Maybe Java would be the way for you to go. It works a lot better and is easier for situations like this. TWCore and Hybrid are bot cores written in Java. So we know it will work.
Mine GO BOOM - Sat Apr 01, 2006 12:37 am
Post subject:
BDwinsAlt wrote:
TWCore and Hybrid are bot cores written in Java. So we know it will work.

Any language with sockets will work with Subspace. Its not like you are trying to mount a Ford motor in a VW Bug.
Smong - Sat Apr 01, 2006 6:20 am
Post subject:
I think for the java thing to work, the applet and zone must be on the same server.
Maverick - Sat Apr 01, 2006 10:07 am
Post subject:
Half wrote:
get a player count for a zone

http://stats.trenchwars.org/index.php?a=display
a dead fish - Sat Apr 01, 2006 12:04 pm
Post subject:
Mine GO BOOM wrote:
[..]


Any language with sockets will work with Subspace. Its not like you are trying to mount a Ford motor in a VW Bug.


ehhe, where there's a will, there's a way...

http://britishv8.org/swaps/vwv8ford.htm

icon_eek.gif
k0zy - Sat Apr 22, 2006 4:44 pm
Post subject:
Mine GO BOOM wrote:
PHP has Sockets which will let you connect with UDP. Just look at the source for some bot cores or on the Wiki for packet information. You can check player counts for a zone just by using the Ping Protocol which will tell you the current ping to a zone and the player count, just like on the main menu of Continuum.


I was bored today...

Code: Show/Hide
<?php

$host = "66.36.241.110";
$port = 5901;

$fp = fsockopen("udp://".$host, $port);

fwrite($fp, pack("V",time()), 4);
$total = fread($fp, 4);
$timestamp = fread($fp, 4);

fclose($fp);

echo array_pop(unpack("V", $total));

?>
Checks the current population of SSCU 17th Parallel

Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole....
Mine GO BOOM - Sat Apr 22, 2006 10:49 pm
Post subject:
Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole.... wrote:
Checks the current population of SSCU 17th Parallel

Might as well check the ping while you are at it, as it requires so little code.
D1st0rt - Sat Apr 22, 2006 11:40 pm
Post subject:
I think I recall Cypher had something that connected to a bot over PHP for viewing chat or something like that
Dr Brain - Sat Apr 22, 2006 11:58 pm
Post subject:
Mine GO BOOM wrote:
[..]


Might as well check the ping while you are at it, as it requires so little code.


Very few people care about the ping between the web server and the zone.
k0zy - Sun Apr 23, 2006 6:00 am
Post subject:
Here's the same code snippet in Ruby.
Just in case someone wants to use Ruby on Rails. icon_wink.gif

Code: Show/Hide
require 'socket'

ip = "66.36.241.110"
port = 5901

socket = UDPSocket.open
socket.connect ip, port
socket.send [Time.now.to_i].pack("V"), 4
data = socket.recvfrom 8

total,timestamp = data.first.unpack("VV")

puts "Population: #{total}\n"


Despite of what Dr. Brain said, could someone add the ping code?
It's like I don't to see the wood for the trees.

Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole....
Mine GO BOOM - Sun Apr 23, 2006 11:33 am
Post subject:
Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole.... wrote:
Despite of what Dr. Brain said, could someone add the ping code?

First problem is that time() only returns seconds. Need to create a 32bit timestamp with milliseconds (or if you want, could even go higher as microtime on unix gets pretty damn small). I know this works on unix, didn't test on windows. The bitwise AND keeps the number unsigned at least, but doesn't account for roll overs. So a better get_ms() function could be created.
Code: Show/Hide
<?php

function get_ms()
{
   list($msec, $sec) = explode(" ", microtime());
   return round(($sec + $msec) * 1000) & 0x7FFFFFFF;
}

$host = "66.36.241.110";
$port = 5901;

$fp = fsockopen("udp://".$host, $port);

fwrite($fp, pack("V", get_ms()), 4);
$total = fread($fp, 4);
$timestamp = fread($fp, 4);

fclose($fp);

$population = array_pop(unpack("V", $total));
$ping = get_ms() - array_pop(unpack("V", $timestamp));

echo "Population: " . $population . "<br>\n";
echo "Ping: " . $ping .  " ms<br>\n";

?>

k0zy - Sun Apr 23, 2006 11:54 am
Post subject:
Using the timestamp that the server sent back has no real advantage in such a small script, hasn't it?

The only advantage I see is when you ping multiple zones at once?

Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole....
Mine GO BOOM - Sun Apr 23, 2006 1:35 pm
Post subject:
Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole.... wrote:
Using the timestamp that the server sent back has no real advantage in such a small script, hasn't it?

The only advantage I see is when you ping multiple zones at once?

Correct. The above code would work fine if you set the socket to non-blocking and just have a timeout wait of a second or two. Technically, you should remember the timestamp you send out, so you know that the packet you got back was the last one you sent and not a previous one.
Donkano - Sun Apr 23, 2006 1:39 pm
Post subject:
MGB, that script does work on Windows. Tested it on a Windows 2003 Server computer.

I tried targetting it on SSDV Into the moat and STFU Anything Goes and both timed out. Do you know why?
k0zy - Sun Apr 23, 2006 2:18 pm
Post subject:
Donkano wrote:
MGB, that script does work on Windows. Tested it on a Windows 2003 Server computer.

I tried targetting it on SSDV Into the moat and STFU Anything Goes and both timed out. Do you know why?


Works fine on WinXP.
Make sure you have the port increased by one.

Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole....
Donkano - Sun Apr 23, 2006 3:23 pm
Post subject:
Here is something that I would like to see done:

PHP does the following:
Connects to a directory server.
Finds all zones starting with with a specific string (to target networks/groups)
Lists all those zones with their IP/Port, ping and population

Would look something like this for output:
SSDV Into the moat
- IP: 69.93.119.226
- Port: 3000
- Population: 4
- Ping: 90ms


If anyone has the time for this, I would appreciate it. I would like to put it on the SSDV website so that it can display zone information.
k0zy - Mon Apr 24, 2006 3:16 am
Post subject:
Donkano wrote:
Here is something that I would like to see done:

PHP does the following:
Connects to a directory server.
Finds all zones starting with with a specific string (to target networks/groups)
Lists all those zones with their IP/Port, ping and population

Would look something like this for output:
SSDV Into the moat
- IP: 69.93.119.226
- Port: 3000
- Population: 4
- Ping: 90ms


If anyone has the time for this, I would appreciate it. I would like to put it on the SSDV website so that it can display zone information.


I could try... I have no experience with sockets, packets and protocols though (except what's been posted in this thread)

But this should be a good variety to all the programming tasks at university.

Is http://wiki.minegoboom.com/index.php/Directory_Client_Protocol the only information available about the protocol?

Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole....
Smong - Mon Apr 24, 2006 3:23 am
Post subject:
Donkano wrote:
Here is something that I would like to see done:

PHP does the following:
Connects to a directory server.
I don't think that's a good idea. There's only one dirserv and a webpage that talks to it could easily be abused.
k0zy - Mon Apr 24, 2006 7:18 am
Post subject:
Smong wrote:
[..]

I don't think that's a good idea. There's only one dirserv and a webpage that talks to it could easily be abused.


How?
And last time I checked there were multiple dir servers...
Ok, I haven't been around for a while, but I don't think that changed.

Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole....
Mine GO BOOM - Mon Apr 24, 2006 10:18 am
Post subject:
Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole.... wrote:
Is http://wiki.minegoboom.com/index.php/Directory_Client_Protocol the only information available about the protocol?

You have to connect to the server by the Core Protocol first, then use the core protocol's reliable packets for the directory section. You cannot do this in a blocking mode, because with this many packets you might lose one or two and would cause the socket to time out.
Smong wrote:
I don't think that's a good idea. There's only one dirserv and a webpage that talks to it could easily be abused.

There is a feature called caching. If someone goes to the page, and it hasn't been updated in around 5 minutes, check the directory server for a new list. If hasn't been updated in a minute, check the zone's pings. Otherwise, use old cached data you have stored, which I'm assuming you might as well store so you could create pretty graphs of zone population/pings from a database. Or just cache directly to a text file.
k0zy - Mon Apr 24, 2006 10:51 am
Post subject:
Mine GO BOOM wrote:
There is a feature called caching. If someone goes to the page, and it hasn't been updated in around 5 minutes, check the directory server for a new list.


Exactly what I thought of.

Well, seeing as this is the first time I actually code something with sockets, it might take me a while to figure out.
What I'm looking forward to is, we'll learn about using sockets in C in our operating systems lesson at university. So this will be good practise icon_smile.gif

Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole....
Rog - Sat Oct 20, 2007 6:25 am
Post subject:
One note for this dated topic: If you are going to do anything with UDP you should set your sockets to a short time out (2 seconds should be more than enough). Otherwise, if your Subspace server is down and there is no answer at the ip+port your webpage will likely hang. Use: stream_set_timeout()

You could also extend it this way to indicate whether your server is online / offline.
Samapico - Sat Oct 20, 2007 11:21 am
Post subject:
dated?

over a year... that's not dated, that's ancient
CypherJF - Sat Oct 20, 2007 4:40 pm
Post subject:
I would never let my webpage script's directly make a call to the directory server. When I did begin playing around with it I created PHP scripts which were executed by a scheduler (CRON) which pulled down current population, ip, and port.
Doc Flabby - Sun Oct 21, 2007 12:17 pm
Post subject:
a webpage that links directly to my directory server would get ip banned. (ie request to dir server made for every page refresh)

I only update the cache on my server of the main dir server every 30 - 60 mins, to minimize the bandwidth, whilst making it useful. If people have my server directry entered they get instant updates.

Cached queries as cypherJF says are the only acceptable and polite way, anything else is just abuse.
k0zy - Sun Oct 21, 2007 2:28 pm
Post subject:
Why would someone ever not cache the results?
It's just stupid do query the directory server with every page refresh.
Not only because it creates unnecessary load on the dir server, but the page will also take longer to load.
Plus, if the dir server goes down, the page is useless.
Goldeye - Wed Dec 26, 2007 8:24 am
Post subject:
I made a PHP class to use the new ping protocol to report playing/total players for either the server or individual arenas. Requires minimal customization (IP,Port,and arena names).

I put it on the wiki: http://wiki.minegoboom.com/index.php/PHP_ping_client
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group