View Full Version : Commentary on the "getstat" LFS World script
martinh
16th August 2005, 13:51
Hi!
I guess this question came up earlier in the old forum, but I do it again:
Will there be any possibility to get the race results history stats in the future?
This would be very interesting for people like me, who are responsible for the rankings in a racing league.
Thanks,
Martin
narcis
16th August 2005, 19:58
It would be possible to put an extra option in the script to get the team list amb their members?? (the team list in lfsworld)
It would be very useful for a project that we (lfs-spain) have about a international competitions web page focused in teams.
Thanks :)
DeXteRrBDN
17th August 2005, 12:53
Hi!
I guess this question came up earlier in the old forum, but I do it again:
Will there be any possibility to get the race results history stats in the future?
This would be very interesting for people like me, who are responsible for the rankings in a racing league.
Thanks,
Martin
you can parse replays and get all the results you want, we (lfs-spain) do it without using lfsworld, it's easy
Victor
17th August 2005, 13:16
race history will never be part of the pubstats. Pubstats is already cause for 1/3 of all LFS World traffic and the races information would increase that heavily because there is so much information.
Best to take Dexter's advice and parse replays.
Kegetys
17th August 2005, 13:42
Is there some way to get the ip address of a host, so it could be pinged?
the_angry_angel
17th August 2005, 14:37
Unfortunately, not with the current system - we're always locked out of knowing the ip.
Viperius
17th August 2005, 21:14
Would there be any way to give a query of a certain user (or even better - users (to reduce the connections made)) to see if he's online or not, and if he is the server info (or name, and then a seperate query for the server info)?
Atm i'm using the hosts script to get this info, but when refreshing every 60s it is still a rather big burden on the server i think (25kB/query). Atm i'm the only one using the program, but if i'd distribute it i'd imagine this becoming a problem... (systray program which gives a notice when a buddy comes online, and gives the server info, lets you join etc.)
Anarchi-H
18th August 2005, 00:07
Would there be any way to give a query of a certain user (or even better - users (to reduce the connections made)) to see if he's online or not, and if he is the server info (or name, and then a seperate query for the server info)?
Atm i'm using the hosts script to get this info, but when refreshing every 60s it is still a rather big burden on the server i think (25kB/query). Atm i'm the only one using the program, but if i'd distribute it i'd imagine this becoming a problem... (systray program which gives a notice when a buddy comes online, and gives the server info, lets you join etc.)
Only the way you are using. There used to be a racer list for S1, but Victor decided not to make the same script available for S2.
IMO, for your app, you should have a 'proxy' that your application connects to. This could be a simple web script that fetches and caches lfsworld data every 60 seconds. Given 100 concurrent users, this would result in ~25k every 60 seconds from the lfsworld servers as opposed to 250k.
Obviously it's another stage to go wrong, but it creates an adhoc kind of distributed network which will allow the lfsworld servers to go a little further.
Viperius
18th August 2005, 11:51
Only the way you are using. There used to be a racer list for S1, but Victor decided not to make the same script available for S2.
IMO, for your app, you should have a 'proxy' that your application connects to. This could be a simple web script that fetches and caches lfsworld data every 60 seconds. Given 100 concurrent users, this would result in ~25k every 60 seconds from the lfsworld servers as opposed to 250k.
Obviously it's another stage to go wrong, but it creates an adhoc kind of distributed network which will allow the lfsworld servers to go a little further.
Good idea, the proxy could provide an interface with the stuff i want, so there wouldn't have to go 25k/60s from the proxy to every user. Only problem is, i don't have a webserver (which allows that kind of scripting) available. And since its something i think multiple apps could benifit of i'd rather have that at the side of lfsworld.
Bruce314
18th August 2005, 12:05
Another solution would be to put this in a local database : geting data can be automatised (say twice a day for example) and you local users connect to the database.
As open source fan, mySQL for db, and perl to fetch data could match perfectly together, even for a someone not expert in computers. Documentation is really very clear...
the_angry_angel
18th August 2005, 12:10
Which is effectively what Anarchi suggested, however its impractical for an "is my buddy online" system to only update twice a day.
My suggestion, would be to contact someone who maybe interested in having their logo on the application (i.e. In associate with X), and they provide web hosting for the "proxied cache". The proxied cache could then be modified so that only specific racer information is passed back down to the user. This cuts down on the information from LFSW, and from your proxied cache.
Perhaps lfs.fr or ocr, etc. maybe interested in this.
PaulC2K
20th August 2005, 04:28
Meh, if someone needs a hosting package with the tipical stuff on there, all the bells & whistles etc, then i dont mind helping out.
assuming a ton of storage/bandwidth isnt going to be required then i see no reason why not, im currently only using what i have for testing purposes and theres about 95gb b/w going unused this month hehe (would be 25gb next month, relocating to a much faster & reliable datacenter/server).
As i say, i've plenty of bandwidth going unused, theres a shop going on there in about a months time and another sometime before xmas or whenever i get change to move it onto my server, and then the rest of it is usually un-used as what little im doing is tipically only seen by myself so not much traffic there.
Anyone else who might be interested in something like this can gimmi a shout if you wish, either PM or probably quicker via email to PChapman@Qazwert.com
if theres some way of creating a 2nd source for the data we all want access to, then maybe its possible to organise this?
certainly would make more sense to all use out-sourced data rather than all attacking the same server.
Maybe im missing something, i guess i'd take the traffic hit on it rather than the lfs server, but if it was shared over multiple locations rather than each team attacking 1 location then maybe additional info could be made available if we free up the data line.
Paul
Anarchi-H
20th August 2005, 17:24
if theres some way of creating a 2nd source for the data we all want access to, then maybe its possible to organise this?
certainly would make more sense to all use out-sourced data rather than all attacking the same server.
Maybe im missing something, i guess i'd take the traffic hit on it rather than the lfs server, but if it was shared over multiple locations rather than each team attacking 1 location then maybe additional info could be made available if we free up the data line.
Very possible; I've thought about it myself, but we'd need to make sure that all of the sub-ordinate data sources were kept up to date with lfsworld, and that they all fetched from lfsworld, from which the 'clients' would use for a datasource instead of directly requesting from lfsworld.
ATM though, I'm not sure there is a need for a mirror service for LFSWorld stats, because I can't see many more sites requesting the data. Obviously only Victor really knows though. Maybe your thoughts on this Victor?
If it were to be implemented, we'd either need a cooperating standard, or a byte for byte mirror to ensure compatibility across the sources.
rustico
23rd August 2005, 19:02
Hi,
Could someone clarify me a bit how to parse replays? I made 'Output lap data', but I didn't find the .raf usable. Do I have to decode the .raf or is there another way to parse replays? Thanks in advance.
-rustico
Victor
23rd August 2005, 22:31
Very possible; I've thought about it myself, but we'd need to make sure that all of the sub-ordinate data sources were kept up to date with lfsworld, and that they all fetched from lfsworld, from which the 'clients' would use for a datasource instead of directly requesting from lfsworld.
ATM though, I'm not sure there is a need for a mirror service for LFSWorld stats, because I can't see many more sites requesting the data. Obviously only Victor really knows though. Maybe your thoughts on this Victor?
If it were to be implemented, we'd either need a cooperating standard, or a byte for byte mirror to ensure compatibility across the sources.
there's not really a need for a mirror so far. we can handle it and will be able to for a while :)
If it would really come to mirrors being needed, it should not be actually mirrored by downloading db-data. That would require huge downloading all the time (mirroring everything) and it wouldn't even be up to date to the minute. So I'm thinking more along the lines of that a mirror would process it's own stats like we do. The mirror would get a copy of the real-time statistics in binary format as they come in at our server. This data stream is very small so would be much more efficient and very real-time than mirroring a remote db by downloading it on intervals.
But as said, not really needed to worry about atm.
PaulC2K
25th August 2005, 02:04
My thinking behind the mirrored data was so that the information that people would like to be able to access would be possible to get hold of, rather than the current 'would increase traffic too much' problem which is stopping us being able to access it.
If the data was updated at a minimum of every 15sec, and only when requested, then that wouldnt be too far from being live data. It'd just be nice to be able to use some 'live' stats.
I thought splitting the load so LFSW gets less of a hammering could possibly mean that making more information available wouldnt be such a problem, compared to every man and his dog heading to 1 source.
Victor
25th August 2005, 04:02
It would be possible to put an extra option in the script to get the team list amb their members?? (the team list in lfsworld)
It would be very useful for a project that we (lfs-spain) have about a international competitions web page focused in teams.
Thanks :)
I've added the teams part.
Please can you (or someone else who's interested) test this:
-------------
?action=teams
-------------
(get the entire teams database stored on lfs world)
requires: -
optional: -
returns: TEAM STRUCT:
TEAM [64]
TAG [6]
COUNTRY [32]
URL [64]
BITS [4]
INFO_LEN [2]
INFO [INFO_LEN] (Note : urlencoded)
NR_MEMBERS [2]
MEMBERS [24] * NR_MEMBERS
BITS :
// 1 : race
// 2 : drift
// 4 : drag
// 8 : can apply
// 16 : has host
// 32 : Demo
// 64 : S1
// 128 : S2
// 256 : S3
ikkah
25th August 2005, 10:29
Uhm, says "no output". Am I doing something wrong?
Victor
25th August 2005, 15:38
err right - forgot to copy the edited script to the live one. Works now.
the_angry_angel
25th August 2005, 16:16
there's not really a need for a mirror so far. we can handle it and will be able to for a while :)
If it would really come to mirrors being needed, it should not be actually mirrored by downloading db-data. That would require huge downloading all the time (mirroring everything) and it wouldn't even be up to date to the minute. So I'm thinking more along the lines of that a mirror would process it's own stats like we do. The mirror would get a copy of the real-time statistics in binary format as they come in at our server. This data stream is very small so would be much more efficient and very real-time than mirroring a remote db by downloading it on intervals.
But as said, not really needed to worry about atm.
As a suggestion (in the unlikely case you've not thought of it); Database replication doesnt take much bandwidth - once the initial mirroring is done. I know it isnt very good at the moment within MySQL (no idea about Postgre either tbh), but I do have experience with it in the mighty and proprietory MSSQL (its the one thing MS have got right, along with AD), and its amazing. Assuming that MySQL / whatever you're using catches up / already supports it, it maybe something worth looking into if it is ever needed, perhaps?
Also, is it really a good idea to dump the entire list of teams to the user? Perhaps optional specifics maybe handy?
Anarchi-H
25th August 2005, 21:25
I've added the teams part.
Please can you (or someone else who's interested) test this:
I've created an lfsw-ppf provider for the teams listing based on your spec, and it works great.
The only thing I'd suggest changing is the tarpit behaviour. ATM it's 5 seconds, sharing an access list with the hosts listing.
I think it would be more suitable to have something like 180 seconds, and having it's own access list.
mr Orange
29th September 2005, 17:31
Hello, we had a little who-is-online list on owr team's website. As I understand it http://www.lfsworld.net/pubstat/s1_racers_online.php can no longer be used for that. Instead we have to use http://www.lfsworld.net/pubstat/get_stat2.php?action=hosts
but there is a lot of data in there we don't use. Aren't you bothered by the extra bandwith it takes?
And is there a required cache time for this action?
Tnx!
the_angry_angel
2nd October 2005, 22:41
Theres not really a cache time requirement, although lets be nice to the devs and give them a reasonable timeout before downloading new content, eh?
Going back to your original question (about bandwidth), I'm afraid I'd have to agree :)
Victor
3rd October 2005, 10:20
i'm not bothered by that extra bandwidth - are you? :) (apart from taa)
I don't think it's really a _problem_ is it? It's just for the sake of simplicity that i keep it like this - you just get the whole hostlist and then you have all the info and you can do with it what you want. If that means throw away half the data, then so be it.
If there's someone having a real problem with it, write it down, but i can't imagine tbh.
the_angry_angel
3rd October 2005, 10:53
We're just thinking about it from your point of view victor - especially if LFS gets really really big :P
mr Orange
3rd October 2005, 14:13
Haha ok, no I'm not bothered. Tnx. In S1 there seemed to be a lot of effort in avoiding the stats to be used more than they had to. With restricted access time, etc. So I just wanted to be sure.
In our website (mrnl.net) the who-is-online list is visible on all pages so in some cases we would need the LFSstat feed twice. Tempting for a less gifted programmer - like my self - to just call LFSworld when ever we need it and just hamer the feed.
Anyway, I'll go the extra mile and cache as many things a possible.
mr Orange
8th October 2005, 15:54
I'm having trouble in getting all the allowed cars from the host information (?action=hosts)
When I process the 4 bytes that hold the CARS information I only get the S1 cars (upto the MRT). Is there anyone who did sucseed in getting all the cars out?
Tnx
Anarchi-H
8th October 2005, 16:26
I'm having trouble in getting all the allowed cars from the host information (?action=hosts)
When I process the 4 bytes that hold the CARS information I only get the S1 cars (upto the MRT). Is there anyone who did sucseed in getting all the cars out?
Tnx
By the sounds of it you are only processing the first byte of the 4 bytes. You need to process them all because you can only get 8 cars in a byte.
The cars are in game order (i.e. the order they appear in the server list, left to right)
Pootie
8th October 2005, 19:28
what would be the link just to see if my user name is online?
Guess I am just lost here :S
Victor
8th October 2005, 23:25
what would be the link just to see if my user name is online?
Guess I am just lost here :S
http://lfsworld.net/pubstat/get_stat2.php?action=hosts is the link you should use. It'll return detailed host & racer info, so it requires some parsing. Here's an example of parsing just the racers and the host they are on :
<?
// function to safely trim null-terminated strings
// could just use trim () in this example though
function trim_c_string ($string) {
$new = "";
$len = strlen ($string);
for ($x=0; $x<$len; $x++) {
if ($string[$x] != "\0") $new .= $string[$x];
else break;
}
return $new;
}
// init some vars
$users = array ();
$x = 0;
$hostlist = "";
// get the hostlist
$hostlist = file_get_contents ("http://lfsworld.net/pubstat/get_stat2.php?action=hosts");
$len = strlen ($hostlist);
if ($len < 52) exit ("Couldn't get hostlist. Quitting...");
// parse the data
while ($x < $len) {
$hostname = "";
$nr_racers = 0;
for ($y=0; $y<32; $y++) $hostname .= $hostlist[$x++];
$hostname = trim_c_string ($hostname);
$x += 20; // skip some host-data
$nr_racers = ord ($hostlist[$x++]);
for ($w=0; $w<$nr_racers; $w++) {
$username = "";
for ($y=0; $y<24; $y++) $username .= $hostlist[$x++];
$users[trim_c_string ($username)] = $hostname;
}
}
// printout of gathered data
foreach ($users as $user => $host) {
echo $user." -> ".$host."<br />\n";
}
?>
mr Orange
9th October 2005, 12:06
By the sounds of it you are only processing the first byte of the 4 bytes. You need to process them all because you can only get 8 cars in a byte.
The cars are in game order (i.e. the order they appear in the server list, left to right)
I processed each byte separately and that did the trick. Tnx!
Just because I'm curious, is it also possible to join the 4 bytes into one long string of bits?
Anarchi-H
9th October 2005, 15:01
Just because I'm curious, is it also possible to join the 4 bytes into one long string of bits?
Yes, but it's treated as a 4byte integer ;)
The reason for this is bitwise operations are performed with integers.
Once (if) the amount of cars in LFS exceeds 32, we'll need to use multiple integers if they are still transmitted bit-encoded.
$cars = ord($byte0) | (ord($byte1) >> 8) | (ord($byte2) >> 16);
This will get you all of the cars in a single integer :)
Victor
9th October 2005, 15:23
just a tiny note about that that line won't work reliably when all 32 bits are used, since php doesn't do unsigned 32 bit integers. But yes, for now with S2 that'll work just dandy :)
FOG_tufferal
9th October 2005, 18:12
right, can anyone help me at all,
i want to be able to show each racers profile in my own site, but i have absolutley no idea how to implement this script so it shows up on my site.
I want to be able to click the racers name and bring their profile details into the website.
can anyone help me out or at least point me in the right direction!
thanks in advance
aLexusPro
10th October 2005, 08:51
I can't find one thing... Need a little help. Can somebody show me query for showing racer's status - offline/online and if it possible name of server when online.
D34N0
10th October 2005, 10:28
Thanks for the php code Victor it works a treat.
I have amended the variable names as one or two conflicted with variables aready used in my code. I have added a function to remove the colour code data and created a formatted table that will fill with team members if they are listed in the data file.
I hope this will be of some use to someone.
Dean
Note : New code below
Dizzy74
10th October 2005, 11:31
Little error on line 67:
case "team member" LFS Name:
should be:
case "team member LFS Name":
Works great so far, thanks :)
Pootie
10th October 2005, 23:31
Would this be right? Cause its not showing my online status?
foreach ($LfsUsers as $LfsUser => $LfsHost) {
switch (strtolower($LfsUser)) {
case "[M.B]Budman Pootie":
case "team member LFS Name":
case "team member elecc":
case "team member LFS Name":
case "team member LFS Name":
case "team member LFS Name":
$LfsUser = remove_colour_codes($LfsUser);
$LfsHost = remove_colour_codes($LfsHost);
echo "<tr bgcolor='#FFFFFF'>";
echo "<td>$LfsUser</td>";
echo"<td>$LfsHost</td></tr>";
$TeamMembers + 1;
Full not much changed,just so that someone with knowledge can have a look see :)
<?
// function to safely trim null-terminated strings
// could just use trim () in this example though
function trim_c_string ($string) {
$new = "";
$len = strlen ($string);
for ($x=0; $x<$len; $x++) {
if ($string[$x] != "\0") $new .= $string[$x];
else break;
}
return $new;
}
/* Function to remove the colour code data from a string */
function remove_colour_codes($String){
$ColCodes = array("^0","^1","^2","^3","^4","^5","^6","^7","^8","^9");
$NewString = str_replace($ColCodes, "",$String);
return $NewString;
}
// init some vars
$LfsUsers = array ();
$x = 0;
$LfsHostList = "";
// get the hostlist
$LfsHostList = file_get_contents ("http://lfsworld.net/pubstat/get_stat2.php?action=hosts");
$len = strlen ($LfsHostList);
if ($len < 52) exit ("Couldn't get hostlist. Quitting...");
// parse the data
while ($x < $len) {
$LfsHostName = "";
$nr_racers = 0;
for ($y=0; $y<32; $y++) $LfsHostName .= $LfsHostList[$x++];
$LfsHostName = trim_c_string ($LfsHostName);
$x += 20; // skip some host-data
$nr_racers = ord ($LfsHostList[$x++]);
for ($w=0; $w<$nr_racers; $w++) {
$LfsUserName = "";
for ($y=0; $y<24; $y++) $LfsUserName .= $LfsHostList[$x++];
$LfsUsers[trim_c_string ($LfsUserName)] = $LfsHostName;
}
}
/* Set the variable to count the members online */
$TeamMembers = 0;
/* Create table to hold data */
echo "<center><br>";
echo "<table border='1' bordercolor='C0C0C0' cellpadding='4' cellspacing='0' style='border-collapse: collapse' style='font-family: Verdana; font-size: 10pt'>";
echo "<tr bgcolor='#CCCCCC' align='center'><th>Team Racer</th><th>On Server</th></tr>";
/* search through the file for Team Members and add a row to the */
/* table showing the name and server they are on */
foreach ($LfsUsers as $LfsUser => $LfsHost) {
switch (strtolower($LfsUser)) {
case "[M.B]Budman Pootie":
case "team member LFS Name":
case "team member LFS Name":
case "team member LFS Name":
case "team member LFS Name":
case "team member LFS Name":
$LfsUser = remove_colour_codes($LfsUser);
$LfsHost = remove_colour_codes($LfsHost);
echo "<tr bgcolor='#FFFFFF'>";
echo "<td>$LfsUser</td>";
echo"<td>$LfsHost</td></tr>";
$TeamMembers + 1;
break;
}
}
/* Display this row only if no members are online */
if($TeamMembers == 0){
echo "<tr bgcolor='#FFFFFF' align='center'><td>No Members</td><td>Are Online</td></tr>";
}
/* Close the table */
echo "</table></center><br>";
?>
Victor
10th October 2005, 23:35
prolly something like: (note the two comments as well)
foreach ($LfsUsers as $LfsUser => $LfsHost) {
switch ($LfsUser) { // don't strtolower ()
case "Pootie": // use only your LFS username
case "team member LFS Name":
case "team member elecc":
case "team member LFS Name":
case "team member LFS Name":
case "team member LFS Name":
$LfsUser = remove_colour_codes($LfsUser);
$LfsHost = remove_colour_codes($LfsHost);
echo "<tr bgcolor='#FFFFFF'>";
echo "<td>$LfsUser</td>";
echo"<td>$LfsHost</td></tr>";
$TeamMembers + 1;
Pootie
10th October 2005, 23:46
What can I say :shy: thanks,that fixed it :P
D34N0
11th October 2005, 10:17
:doh: I should have said to put the "team member LFS Name": in lower case. :)
The reason for using strtolower in the switch statement was to try and stop any mistyping of Upper and Lowercase characters in the LFS Name. The ouput though is in the case as defined in the data file.
Dean
aLexusPro
13th October 2005, 18:39
Thanks a lot guys!!!
finnerss
14th October 2005, 06:06
:shrug: Embarrassed here but I guess that's what happens when you don't know almost anything about coding.
Any help will be appreciated
We have started a remote dedicated host, running 3 lfs servers. I would be interested only in knowing if some of our users are online (The users from our website), or simply to show "This user left the pits" etc... in our website.
We would like to display all possible stats from LFS World as well, but I can't find the way just yet. What Victor talks about is completely above my understanding and I can't find a simple file to download to query lfsworld, or if there is a way only to query a limited amount of users that we could enter ourselves so the queries aren't as big.
If someone who knows more about this could actually help us out, we'll give full credit, our site has not gone public yet but it already has a lot of users.
Thanks in advance.
Best wishes
Sergio
Tooby
26th October 2005, 20:57
I have just started to try to learn PHP. Perhaps a big start but I tried to recive some data from lfsworld and the result goes like this
"Fatal error: Call to undefined function: file_get_contents() in c:\phpdev\www\lfsdata.php on line 16"
I got phpdev423 installed. Is the problem that the function file_get_contents() don't exist or...I would be glad if someone could point me in the right direction.
Thanx
Tooby
D34N0
27th October 2005, 14:23
This is a link to the function file_get_contents http://uk2.php.net/manual/en/function.file-get-contents.php
It is only available in PHP 4 >= 4.3.0, PHP 5 as stated in the above link.
Heres a link to the PHP Quick Manual Reference http://www.php.net/quickref.php
Also if learning PHP I found the tutorials on this site very helpful http://www.tizag.com they gave me a good understanding and it's just the tip of the iceberg :)
tristancliffe
27th October 2005, 18:11
Cheers for that Dean :D
I've got a rudimentary version running now, with the table that expands and contracts as members join and leave. GREAT!!!
What I'd really like though is a fixed table with members in it, and the words Online or Offline to appear as required. Or even images :D
Anyone know how to do this (I guess someone does, cos most team websites seem to be like it :D).
Ta ta for now...
Anarchi-H
27th October 2005, 18:21
Since there is no racerlist for S2 stats, you have to fetch the full server detail listing and scan each servers racer list for the names you are looking for. If you find them, they are online, if not then they are offline.
:)
tristancliffe
27th October 2005, 18:34
In noobspeak? Oh, nvm :D :D :D
PM's saving the day again!
Tooby
27th October 2005, 21:55
This is a link to the function file_get_contents http://uk2.php.net/manual/en/function.file-get-contents.php
It is only available in PHP 4 >= 4.3.0, PHP 5 as stated in the above link.
Heres a link to the PHP Quick Manual Reference http://www.php.net/quickref.php
Also if learning PHP I found the tutorials on this site very helpful http://www.tizag.com they gave me a good understanding and it's just the tip of the iceberg :)
Thanx! I thought I was a total looser. I've started to look at the tutorials and uppdated my php install. Se if that makes any difference
/Tooby
D34N0
29th October 2005, 09:26
I have updated the code to show the server name in the correct colours (except white which is set to dark grey as it shows better on a white background :) ).
The team Members are now entered into an array at the beginning of the code, use lowercase in the array as this helps to minimise the chances of mistyping the name. If you want to use the name in the correct case you will need to remove strtolower used in the display table functions. At the end are two lines that allow you to display the online status in an expandable table with columns Name and Server or a fixed table showing all team members with the columns Name, Status and Server. Comment out the one you do not want to use.
Hope this will be of use.
Dean
Note : The code has been updated and is in the message below :)
D34N0
4th November 2005, 14:45
The code has once again been updated.
1) Fixed an error in the Host Name Colour conversion that caused text following the table to be the incorrect colour. Thanks to Tristancliffe for spotting that one. :)
2) Added second array to contain the In Game Name or name you wish to show in the table in the letter case you type, but must be in the same sequence as the Team Members array. Thanks to Tristancliffe for that idea. :thumb:
3) Added a link to refresh the screen if hosts file not found. Thanks to Tristancliffe for the code :thumb:
Dean
<?
//******************************************
// Add Team Member names to$TeamMembers
// LFS User Name and in lowercase
// Lowercase used to reduce typos
// in the username
//
// Also add the team Members In Game
// Name in $InGameName (any case will do)
// MUST be in the same order as $TeamMembers
//******************************************
$TeamMembers = array("lfs name","lfs name","lfs name","lfs name","lfs name");
$InGameName = array("lfs name","lfs name","lfs name","lfs name","lfs name");
//**********************************
// function to safely trim null-terminated strings
// could just use trim () in this example though
function trim_c_string ($string) {
$new = "";
$len = strlen ($string);
for ($x=0; $x<$len; $x++) {
if ($string[$x] != "\0") $new .= $string[$x];
else break;
}
return $new;
}
// Function to remove the colour code data from a string
function remove_colour_codes($String){
$ColCodes = array("^0","^1","^2","^3","^4","^5","^6","^7","^8","^9");
$NewString = str_replace($ColCodes, "",$String);
return $NewString;
}
// Function used by format_host_colours function to display correct colour value in html format
function get_colour($ColourNum){
switch ($ColourNum) {
case "0";
$ColourName = "#000000"; //Black
break;
case "1";
$ColourName = "#FF0000"; //Red
break;
case "2";
$ColourName = "#00FF00"; //Pastel Green
break;
case "3";
$ColourName = "#FFFF00"; //Yellow
break;
case "4";
$ColourName = "#0000FF"; //Light Blue
break;
case "5";
$ColourName = "#FF0080"; //Light Purple
break;
case "6";
$ColourName = "#00FFFF"; //Turquoise
break;
case "7";
// Remove comment marks on next line if not a white background
//$ColourName = "#FFFFFF"; //White
// Add Comment marks to next line if not a white background
$ColourName = "#808080"; //Dark Grey
break;
case "8";
$ColourName = "#00FF00"; //Pastel Green
break;
}
return $ColourName;
}
// Function to replace the ^x codes in the Host name to show correct colours on the screen
function format_host_colours($HostName){
for($i = 0; $i < strlen($HostName); $i++){
if(substr($HostName, $i, 1) == "^"){
$CharPos = strpos($HostName, "^", $i);
$ColNum = substr($HostName, strpos($HostName, "^", $i) + 1,1);
$ColourString = get_colour(substr($HostName, strpos($HostName, "^", $i) + 1,1));
if($i == "0"){
// If ^ found at the start of the host string remove the ^[num]
$TmpString = substr($HostName,$i+2);
// Add the html font code to the start of the string and append the
// variable $TmpString with the ^[num] removed
$HostName = "<font color='$ColourString'>".$TmpString;
}
else{
// Get the left part of the string to the next ^[num]
$LTmpString = substr($HostName,0,$i);
// Get the right part of the string after the ^[num]
$RTmpString = substr($HostName,$i+2);
// Add the html close font and add the new html colour to the end of the
// Left part of the string then add the right part of the string
$HostName = $LTmpString."</font><font color='$ColourString'>".$RTmpString;
}
}
}
// Close any html font tag left open in the above
$HostName = $HostName."</font>";
Return $HostName;
}
// Function to display Team Members online in a dynamic table
function display_expandable_table($TeamMembers, $LfsUsers, $InGameName){
// Set the variable to count the members online
$MembersOnline = 0;
// Count the number of members
$TotalMembers = count($TeamMembers);
// Create Header row for the table
echo "<tr bgcolor='#CCCCCC' align='center'><th>Team Racer</th><th>On Server</th></tr>";
// search through the file for Team Members and add a row to the
// table showing the name and server they are on
foreach ($LfsUsers as $LfsUser => $LfsHost) {
for($i = 0; $i < $TotalMembers; $i++){
if(strtolower($LfsUser) == $TeamMembers[$i]){
$LfsUser = remove_colour_codes($LfsUser);
$LfsHost = format_host_colours($LfsHost);
echo "<tr bgcolor='#FFFFFF'>";
echo "<td>$InGameName[$i]</td>";
echo"<td>$LfsHost</td></tr>";
$MembersOnline =+ 1;
}
}
}
// Display this row only if no members are online
if($MembersOnline == 0){
echo "<tr bgcolor='#FFFFFF' align='center'><td>No Members</td><td>Are Online</td></tr>";
}
}
// Function to display all Team Member Status
function display_fixed_table($TeamMembers, $LfsUsers, $InGameName){
/// Count the number of members
$TotalMembers = count($TeamMembers);
// Create Header row for the table
echo "<tr bgcolor='#CCCCCC' align='center'><th>Team Racer</th><th>Status</th><th>On Server</th></tr>";
for($i = 0; $i < $TotalMembers; $i++){
echo "<tr bgcolor='#FFFFFF'>";
foreach ($LfsUsers as $LfsUser => $LfsHost) {
if(strtolower($LfsUser) == $TeamMembers[$i]){
$LfsHost = format_host_colours($LfsHost);
echo "<td>$InGameName[$i]</td>";
echo "<td>Online</td>";
echo"<td>$LfsHost</td></tr>";
$Found = "True";
break;
}
else{
$Found = "False";
}
}
if($Found == "False"){
echo "<td>$InGameName[$i]</td>";
echo "<td>Offline</td>";
echo"<td> </td></tr>";
}
}
}
// init some vars
$LfsUsers = array ();
$x = 0;
$LfsHostList = "";
// get the hostlist
$LfsHostList = file_get_contents ("http://lfsworld.net/pubstat/get_stat2.php?action=hosts");
$len = strlen ($LfsHostList);
// Thanks to Tristiancliffe for this line. It is a refresh link
if ($len < 52) exit ("<a href='javascript:document.location.reload();'>Couldn't get hostlist. Click to retry...</a>");
// parse the data
while ($x < $len) {
$LfsHostName = "";
$nr_racers = 0;
for ($y=0; $y<32; $y++) $LfsHostName .= $LfsHostList[$x++];
$LfsHostName = trim_c_string ($LfsHostName);
$x += 20; // skip some host-data
$nr_racers = ord ($LfsHostList[$x++]);
for ($w=0; $w<$nr_racers; $w++) {
$LfsUserName = "";
for ($y=0; $y<24; $y++) $LfsUserName .= $LfsHostList[$x++];
$LfsUsers[trim_c_string ($LfsUserName)] = $LfsHostName;
}
}
// Create table to hold data
echo "<center><br>";
echo "<table border='1' bordercolor='C0C0C0' cellpadding='4' cellspacing='0' style='border-collapse: collapse' style='font-family: Verdana; font-size: 10pt'>";
//*************************************************
// Comment and Uncomment the type of table you want
//*************************************************
display_expandable_table($TeamMembers, $LfsUsers, $InGameName);
display_fixed_table($TeamMembers, $LfsUsers, $InGameName);
/* Close the table */
echo "</table></center><br>";
?>
Note : 4/11/05 18:18GMT For those who have already downloaded this code today there was a small error inside one of the functions, you may need to download it again. Inside one of the functions [$i] was missing from $InGameName when writing the data into the table. Corrected in the above code. Sorry :)
tristancliffe
4th November 2005, 15:32
:shy: I can't code, but I'm not short of crazy ideas (most of which don't work anyway)...
Cheers D34NO
Sven Menkhoff
5th November 2005, 10:11
This Script is great.
But i have a lil Problem with it.
I only wanna use the upper part of it, cause the lower part is too wide for our Page.
How can i remove the lower part?
greez S.Menkhoff
D34N0
5th November 2005, 10:30
This Script is great.
But i have a lil Problem with it.
I only wanna use the upper part of it, cause the lower part is too wide for our Page.
How can i remove the lower part?
greez S.Menkhoff
Please explain what you mean by upper an lower parts..
The script just creates a table so there is no upper and lower part.. There are 2 options at the bottom to display either a expandable or fixed table? (as listed below), to comment out either of the rows as described in the comments place // at the start of the line you do not want
//*************************************************
// Comment and Uncomment the type of table you want
//*************************************************
display_expandable_table($TeamMembers, $LfsUsers, $InGameName);
display_fixed_table($TeamMembers, $LfsUsers, $InGameName);
Regards
Dean
Sven Menkhoff
5th November 2005, 11:21
Thank you very much.
This was want i wanted to get off:
display_fixed_table($TeamMembers, $LfsUsers, $InGameName);
Now it works like i want to have it :)
Tooby
8th November 2005, 19:29
Hi!
A small and perhaps dumb question...
I have used the function ch (chart) and recived this (and more).
What character is used after the name, I tried to search for ' ' but strpos() miss. I think it should be something like "\\n" but that don't work either. I hope there is something else than ' ' or how do you solve names with a space 'Nisse Hult"?
135260 517 biggie
135370 513 Flotch
135590 517 RMachucaA
135670 517 fab
...
Would be glad for a answer
/Tooby the noob :)
the_angry_angel
8th November 2005, 19:38
The name *should* be terminated with a \0 (thats how it comes directly from LFSWorld).
But I've not looked over the rest of this thread to see if its being stripped.
Victor
8th November 2005, 19:57
the _text_ results (which is everything except the hosts and teams-query) just have basic Linux line-endings "\n" and don't contain any null-strings
From the first post:
-------------------------------------------------------------------------------------
Legend: (all output is in plain text, except the hosts and teams output, which have binary data)
-------------------------------------------------------------------------------------
Tooby
8th November 2005, 20:08
:shy: oops, just to read then. I did not manage to get it to work but after some more tries it did.
Thanx
/Tooby
tehkahless
8th November 2005, 20:57
is there a way to resolve a LFS username to the Player name used inside the game ? (when i ask for the server list i get the usernames .. but i would like to display the player names) .. any ideas ?
Victor
8th November 2005, 21:06
not via lfsworld - i just don't have player names stored, so i can't display them.
the_angry_angel
8th November 2005, 22:10
whoops. my mistake :s Sorry tooby
/me bows down to Victor
Tooby
8th November 2005, 23:54
whoops. my mistake :s Sorry tooby
/me bows down to Victor
No problems. Your "mistake" showed me the way :D
/Tooby
Eldarion
15th November 2005, 19:02
Hi Victor,
I come here to make a small suggestion in connection with the statistics from the LFS statistics server. I am currently under development of a small code PHP to generate me a .jpg signature (in end of this post) including my principal statistics (statute on LFS, distance, fuel, laps, victories, points). The problem is as follows :
- No problem to obtain distance, fuel, laps, victories and points, by using "http://www.lfsworld.net/pubstat/get_stat2.php?action=pst"
- No problem either with the statute of the pilot thanks to a script which will see whether the pilot is on line among the results of the statistics for hosts : "http://www.lfsworld.net/pubstat/get_stat2.php?action=hosts"
The problem is when i want to mix both of them. The statistics server do not accept two requests one just after the other. I then obtain result only for the first of those. This is why I think that it would be very interesting to obtain the statute of the pilot with the other statistics of the concern pilot, by call of this the page : "http://www.lfsworld.net/pubstat/get_stat2.php?action=pst" by adding for example this statute in first line which would take "1" as value if the pilot is online and "0" if this one is offline. This is only one proposition that I hope you will soon consider. I wait your response impatiently. :)
P.S. : My current signature which not show my correct status in LFS (always offline = "Hors Ligne" here). It's in french because i'm. :)
http://eldarion.eurower.net/lfs/signature/eldariondroite.jpg
I apologize for my poor english but i'm only a young french of 16 years old which always is on school system. I hope you this will be undertandable...
Victor
16th November 2005, 07:57
well there is a problem with just adding a value. I think a lot of parse scripts will then fail to work, so that's not a good idea.
If you have a php install at home, or if you have access to cron or other scheduling software on your current provider, then I'd suggest you make a script that gets the PST-info and your online status and then saves that data to a file. Then the script that generates your signature image can simply read the needed data from that file.
Then schedule that script via cron (or whatever scheduler) to update that data file, say every 2 minutes.
This way you will always have the data available instantly for your signature image and it will always be quite up to date and it doesn't have to access LFS World every time you need to generate your signature image.
Caching is lovely :)
Eldarion
16th November 2005, 12:02
Not a bad idea ! I will have a look at this. But are sure that it can't be possible to add the statuts of a pilot at the end of his statistics. I think it will be much easy to use for everyone. The script i use to get my personnal LFS status wasn't written by me because i've a very limited level in PHP. I successed to get my stats from the stats page by myself and it's already a little victory for me. So you can imagine that i havn't idea for the schedule's question. I will see what it is with my Host, but after i don't know to manipulate it.
Even if it's not the answer i expected, i want to thank you for your interest ;). I think we will talk about it again. :)
Victor
16th November 2005, 12:13
ohyea hmm, PST displays only one racer's information at a time, so a 0 or 1 on a new line at the end of the results might not disrupt people's stats-processing. Let me think about it
Eldarion
16th November 2005, 12:53
Thank's a lot ! It will help me a lot if you could do that ! And many people at the same time i think ! And as you sayed, at the end, it might not disrupt people's stats because it's at the the end, so it's an additional ID... :)
CrazyICE
16th November 2005, 13:36
ohyea hmm, PST displays only one racer's information at a time, so a 0 or 1 on a new line at the end of the results might not disrupt people's stats-processing. Let me think about it
this would be really helpful...
great idea Eldarion :thumb:
Anarchi-H
16th November 2005, 14:36
ohyea hmm, PST displays only one racer's information at a time, so a 0 or 1 on a new line at the end of the results might not disrupt people's stats-processing. Let me think about it
An optional 'version' arg on the URL would solve any expansion issues. Say you post Version 1 of PST (the current version), this would be the default version in case no version is specified.
Then a minor addition like the online/offline status could be made version 1.1, and unless version >= 1.1 then don't echo the extra data.
Then as revisions & bugfixes are made, you don't have to worry about busting existing code.
the_angry_angel
16th November 2005, 14:57
Which is fine, until you get to the stage where it will take a weeks to even understand whats going on, because of a huge amount of if, or switch, statements in a script; instantly becoming unmanagable.
But at least it would work :)
Anarchi-H
17th November 2005, 13:10
Which is fine, until you get to the stage where it will take a weeks to even understand whats going on, because of a huge amount of if, or switch, statements in a script; instantly becoming unmanagable.
But at least it would work :)
Depends on how you architecture it.
If get_stat.php was just a facade with a switch block....
switch($version)
{
case 1.1:
include('get_stat/1.1.php');
break;
case 1.0:
default:
include('get_stat/1.0.php');
}
It would probably be more elegant using an OO abstract factory approach, i.e.
$statGen = AbstractStatGen::factory($action, $version);
But from what I gather, Vic has a more procedural approach :)
the_angry_angel
17th November 2005, 13:16
I'm gradually going off object orientated approaches, in PHP. I've found a lot of OOP code (tested under 5.0.5) is about 10% slower in general. Much nicer to code and alter though, I must agree. But I suppose thats the main reason we're getting updated OOP and PDO in 5.1.
Victor
17th November 2005, 14:42
for small scripts, I just use a very straight forward approach. I have the feeling that if you'd setup classes and what not, then by the time php has parsed the classes, it could already have processed the request, had a straight forward approach been used :)
But for the bigger programs / scripts, classes are great to keep things organised.
Anyway, about that new feature, I do think I'll use version numbers. I'm just thinking about how to keep things organised and simple (from both programming and documentation pov).
Anarchi-H
17th November 2005, 15:06
Same here; unless there is a good reason to create a class (i.e. a unified API like LFSWPPF)
To keep docs organised, I'd suggest only keeping the current version info in the first post, and attaching older version docs as text documents.
That way new developers coming to lfs will be using the latest version, which is usually what you'd want.
Programatically, I'd suggest a directory structure similar to
*action*/*version*.php
Then you simply include the appropriate file after parsing action and version. (I'd recommend a whitelist of values for action, and a (float) force type for version to ensure system security)
You may want to keep an include that defines the versions that exist for each action, so that you don't have to keep polling the file system to make sure the files exist too.
If the version is not specified, fall back to version 1.0... if an incorrect version is specified, fall back to current version.
The idea being that you want maximum backward compatibility, but encouraging developers to use the latest version.
All of this could be totally impractical depending on how you currently have the stat generation structured, but this is how I would do it. :)
Victor
17th November 2005, 15:56
about to rewrite the whole thing hehe - great suggestion Eldarion ;)
Victor
17th November 2005, 16:01
wow, talking about versions - I see there are still massive amounts of requests using the get_stat.php from the S1 era :Looking_a
hummmm some folks need to update their scripts you'd think
Victor
17th November 2005, 17:10
ok there you go:
script url: http://www.lfsworld.net/pubstat/get_stat2.php?version=1.1&action=...
and
-----------
?action=pst
-----------
(online statistics of one racer)
requires: &racer=<racer>
optional: -
returns: distance in metres
fuel burnt in dl
laps
hosts joined
wins
second
third
finished
quals
pole
online credits
drags
drag wins
**NEW** online or not (0 = no, 1 = yes)
**NEW** hostname (or blank line if not online or on hidden host)
See the first post of this thread for all the details
Eldarion
17th November 2005, 17:23
Thank you Victor ! It will be great helpufll ! Thank's again !!!! :D xD
BadFox
17th November 2005, 18:16
yeah!
thanks a lot Victor
NFR power ;)
Tooby
18th November 2005, 23:17
Hi!
Just wanted to show my first little php script and it works. This is so fun :thumb: (php I mean)
nikka
21st November 2005, 00:36
Hey folks!
What are the possible error messages the '?action=hl', '?action=pb' and '?action=pst' may return?
I need to know because I'm working on a script that needs to know if I have to retry or not.
The ones I got:
'can't reload this page that quickly after another'
'hl: no hotlaps found'
'pb: racer has no pbs'
'pb: no valid username'
'pst: no valid username'
Guess there also are some messages indicating problems with the lfsworld server/database or something.
Victor? Anyone?
Anarchi-H
21st November 2005, 01:33
These are the only ones I've ever encountered, but that isn't to say there aren't more should something catastrophic happen like gerbils in the stat server or something.
Pulled straight from ppf.
function isLFSWorldError($string)
{
switch(trim(substr($string, 0, 50)))
{
case 'hl: no hotlaps found':
case 'hl: no racer':
case 'ch: invalid track':
case 'ch: invalid car':
case 'pst: no valid username':
case 'pb: racer has no pbs':
case 'no output':
case 'can\'t reload this page that quickly after another':
case '':
return true;
}
return false;
}
These were obtained by just throwing random crap at the stat server to see how it would respond.
nikka
21st November 2005, 01:52
Thanks for your reply!
case 'no output':
Do you remember how and why you got this one?
Anarchi-H
21st November 2005, 03:01
According to my notes ...
Invalid action (http://www.lfsworld.net/pubstat/get_stat2.php?action=moo)
No entries for car/track/control on chart (http://www.lfsworld.net/pubstat/get_stat2.php?action=ch&track=010&car=ufr)
--==Gogo==--
24th November 2005, 17:53
?action=hosts
As I found out, the Demo-Hosts are not send by lfsworld. Am i right here?
How do I get the Demo Hosts?
Thanx.
the_angry_angel
27th November 2005, 16:33
Yo Victor! Quick question, as I'm sure I read somewhere about LFSW being altered with regards to the new codepages in LFS; but I cant see it anywhere in the readme's, or this forum. Was it my imagination?
Victor
27th November 2005, 17:12
this ? http://www.lfsforum.net/showthread.php?t=3304
the_angry_angel
27th November 2005, 17:33
:doh: Right under my nose! Yes, thats the bugger :) Cheers Victor :s
tristancliffe
1st December 2005, 18:41
Big Edit:
If you are using D34N0's code above, but want to turn the hostnames into working links for Join2LFS, then use the following code to replace the same sections in D34N0's code.
// Function to display Team Members online in a dynamic table
function display_expandable_table($TeamMembers, $LfsUsers, $InGameName){
// Set the variable to count the members online
$MembersOnline = 0;
// Count the number of members
$TotalMembers = count($TeamMembers);
// Create Header row for the table
echo "<tr bgcolor='#CCCCCC' align='center'><th>Team Racer</th><th>On Server</th></tr>";
// search through the file for Team Members and add a row to the
// table showing the name and server they are on
foreach ($LfsUsers as $LfsUser => $LfsHost) {
for($i = 0; $i < $TotalMembers; $i++){
if(strtolower($LfsUser) == $TeamMembers[$i]){
$LfsUser = remove_colour_codes($LfsUser);
$LfsLink = remove_colour_codes($LfsHost);
$LfsHost = format_host_colours($LfsHost);
echo "<tr bgcolor='#FFFFFF'>";
echo "<td>$InGameName[$i]</td>";
echo"<td><a href='lfs://|$LfsLink|0|S2|/'>$LfsHost</a></td></tr>";
$MembersOnline =+ 1;
}
}
}
// Display this row only if no members are online
if($MembersOnline == 0){
echo "<tr bgcolor='#FFFFFF' align='center'><td>No Members</td><td>Are Online</td></tr>";
}
}
// Function to display all Team Member Status in a fixed table
function display_fixed_table($TeamMembers, $LfsUsers, $InGameName){
/// Count the number of members
$TotalMembers = count($TeamMembers);
// Create Header row for the table
echo "<tr bgcolor='#CCCCCC' align='center'><th>Team Racer</th><th>Status</th><th>On Server</th></tr>";
for($i = 0; $i < $TotalMembers; $i++){
echo "<tr bgcolor='#FFFFFF'>";
foreach ($LfsUsers as $LfsUser => $LfsHost) {
if(strtolower($LfsUser) == $TeamMembers[$i]){
$LfsLink = remove_colour_codes($LfsHost);
$LfsHost = format_host_colours($LfsHost);
echo "<td>$InGameName[$i]</td>";
echo "<td>Online</td>";
echo"<td><a href='lfs://|$LfsLink|0|S2|/'>$LfsHost</a></td></tr>";
$Found = "True";
break;
}
else{
$Found = "False";
}
}
if($Found == "False"){
echo "<td>$InGameName[$i]</td>";
echo "<td>Offline</td>";
echo"<td> </td></tr>";
}
}
}
Anarchi-H
1st December 2005, 22:41
The lfs join link has the following anatomy;
lfs://|$hostname|$private|$type|/
Where $hostname is an urlencoded hostname with colour codes intact.
$private is 0 if the host is public, or 1 if the host is private.
$type is either S1, S2 or Demo.
As such, that code will only join a public S2 server, but other than that your code looks ok. :thumb:
Victor
1st December 2005, 22:44
to be completely precise - the urlencoding of the LFS:// url only has to be done for browsers other than IE. IE in turn needs only the '+' sign converted DOUBLE (to my knowledge there are no other characters that need conversion, but maybe there are - i haven't met any yet).
So:
IE:
$hostname = preg_replace ("'\+'", "%252B", $hostname);
ANY OTHER BROWSER:
$hostname = urlencode ($hostname);
tristancliffe
1st December 2005, 23:39
Damn you all (in a nice way).
Well, now I'm not going to be satisfied until it works properly for all servers people might join.
So, based on D34N0's code above, and my alterations, what should I use to find out if a host is:
S1/S2 (Demo doesn't use usernames, so not a problem in this case)?
Public or Private?
Then it should just be a case of assigning variables to those values, and sticking them in the link.
For what Victor said about IE being the perennial pain the arse it always is, can I use the preg_replace for all other browsers, or do I need to somehow add a check for which browser type is being used? Sorry for being a total b00n, but I am trying to learn :p
Edit: I noticed I'd editted my above post before you replied. Just tried my current implementation (above now, which doesn't use any urlencoding) and it works fine in IE and Firefox, so not touching that anymore.
Edit2: So I need to parse for the first byte of TMLT. Right okay. Reads more of Victors first post and starts the trial and error process... I've never done anything like this before, so bear with me...
Would this work? Then I have $HostType which will be either 0,1 or 2. And is the $x += 20; still right, or should that now be 19, as I've already moved one byte along?
// init some vars
$LfsUsers = array ();
$x = 0;
$LfsHostList = "";
// get the hostlist
$LfsHostList = file_get_contents ("http://lfsworld.net/pubstat/get_stat2.php?action=hosts");
$len = strlen ($LfsHostList);
if ($len < 52) exit ("<a href='javascript:document.location.reload();'>Couldn't get hostlist. Click to retry...</a>");
// parse the data
while ($x < $len) {
$LfsHostName = "";
$nr_racers = 0;
for ($y=0; $y<32; $y++) $LfsHostName .= $LfsHostList[$x++];
$LfsHostName = trim_c_string ($LfsHostName);
$x += 1; // skip some host-data
$HostType = ord ($LfsHostList[$x++]);
$x += 20; // skip some host-data
$nr_racers = ord ($LfsHostList[$x++]);
for ($w=0; $w<$nr_racers; $w++) {
$LfsUserName = "";
for ($y=0; $y<24; $y++) $LfsUserName .= $LfsHostList[$x++];
$LfsUsers[trim_c_string ($LfsUserName)] = $LfsHostName;
}
}
nikka
3rd December 2005, 15:14
hey!
It would be great if the action=hl also could return the position on chart.
Now I have to do a action=ch for each combo action=hl returnes to find the chart position. Obviously a lot of bandwith/scrip calls wasted.
Any chance this could be implemented?
Dygear
5th December 2005, 18:37
I was wondering if there is a LFSWorld SDK, or something like that, like a list of functions for parsing the information that the script's spew out. If there is not one, why not make one. I would be happy to donate some code to the LFSWorld SDK. It would be like the best toolkit for geting information to your website from LFSWorld. We would need to have a pretty good cache system, if this thing should be come main stream. Like, I'd said, I would be more then happy to head up the project, its just that my programing know how is not so good, but I can get around the most programing languages pretty well. I think that our angry angle would be the best one the head up the project. It would have to be open souce software, and it would most likey be GPL'ed. So, what do you say? Want to give this a shot? Oh, and it would have to be in PHP.
the_angry_angel
5th December 2005, 18:45
Anarchi recently rewrote his PHP classes to deal with LFSW: http://dsrc.digiserv.net/forum/forumdisplay.php?f=69
As for why more people dont use it, I really dont know. They;re good, and need pimping more.
With regards to an application version, I've been perpetually working on a C based version which will run on linux and windows. I've rewritten the code about 3 times now - but I'm fairly confident that I'll get it done this time (extra christmas holidays rock for this kind of stuff). I've got tomorrow off, and I'm planning on reintegrating libcURL support, and fixing the SQLite stuff so it perpetually updates properly. Other than that, I've just got to write some docs and stuff.
So in short, there are libraries out there, but no one seems to use them on websites. Plus the overridding issue is that not everyone uses PHP, C (running as CGI). There are nutters out there using perl, java, and .NET, and writing one more bloodly framework for each is a nutty idea. Plus most of the time, people dont need the entire overhead for LFSW PPF, for example.
Victor
5th December 2005, 18:52
hey!
It would be great if the action=hl also could return the position on chart.
Now I have to do a action=ch for each combo action=hl returnes to find the chart position. Obviously a lot of bandwith/scrip calls wasted.
Any chance this could be implemented?
i'll keep this in mind for a future update.
Anarchi-H
5th December 2005, 22:46
Anarchi recently rewrote his PHP classes to deal with LFSW: http://dsrc.digiserv.net/forum/forumdisplay.php?f=69
As for why more people dont use it, I really dont know. They;re good, and need pimping more.
Thanks :)
It's probably the same reason people are still coding their own database abstraction libs instead of using pear::db or adodb; they are lazy.
It may take more time to code than if they were to use the lib, but it takes less effort, unless the interface to the lib is extremely minimal, otherwise the coder is forced to read docs, which no one really likes doing.
LFSW-PPF is about due for an update, during which I may minimalize the required interface further, but still maintaing backwards compatibility and the modular structure.
Your closing comment about PPF actually made me realize how little I documented the structure of the classes. If you really wanted to, you could use your own cache & request mechanism and only include the actual 'provider' (which is just the parsing loop, and all of which take a string as input, and a reference to an array as output, returning true on success or false on failure).
Of course you'd have to do lfsworld error checking and decompression yourself.
Hmmm, I think I'll go minimalize and document now :D
the_angry_angel
5th December 2005, 22:59
I must admit Anarchi, that most people dont use existing solutions, if the documentation isnt there. Believe it or not, between things I'm still working on libLFSW, and I've hit a lot of issues - I want to keep it as portable as possible, but not so that it makes my life difficult. I've gone from writing my own little cache system, to eventually using SQLite (which could eventually be patched to using MySQL or PostgreSQL) - but the main issue I've found whilst looking into all existing packages to make my life easier, is that without some sound documentation behind it, you're pretty much on your own.
A perfect example is if you want to do anything GTK based with Python, you're shafted at the moment as theres literally no documentation, and you have to find a developer to drive nuts for a few hours before you can get anywhere. Now I'm not saying your docs are bad, but if you're not the one who wrote it sometimes things arent obvious i.e. I was pretty sure you could override things in LFSW-PPF (as with most PHP apps), but not to the extent and ease that you seem to be promoting. It all sounds very cool :D.
Shame documentation is the boring bit. LFSW-PPF definately needs pimping more though :)
Tooby
6th December 2005, 10:44
Hi!
Is there a way to recive data from lfsworld or direct from a host?
Exampel:
If I race on our team server is it possible to get the data from those races?
<track><laps>
<racer><car><time>
/Tooby
the_angry_angel
6th December 2005, 11:07
You can get some of that data from Vortex's Server Script (http://www.lfsforum.net/showthread.php?t=195). But with regards to times, that could only be retreived through InSim.
nikka
6th December 2005, 15:05
i'll keep this in mind for a future update.
excellentasticomente
Dygear
7th December 2005, 18:45
You can get some of that data from Vortex's Server Script (http://www.lfsforum.net/showthread.php?t=195). But with regards to times, that could only be retreived through InSim.
For me connecting to InSim with PHP is the holy grail. I would love to be able to get all of the laps times for the players on a server as they are going around. That would be soo awsome. And I don't think it would take so much time with some C programing on the back end of the LFS server and a query PHP script on the web sever. Sounds like a sick idea.
Tooby
7th December 2005, 22:36
You can get some of that data from Vortex's Server Script (http://www.lfsforum.net/showthread.php?t=195). But with regards to times, that could only be retreived through InSim.
Thanx! This goes above my skills at the moment.
/Tooby
Dygear
8th December 2005, 01:59
The script requires webspace with PHP functionality. Also access to the hostXXXXX.txt file of the gameserver is required. This can be either by FTP or HTTP.
That for me pretty much kills it, what if I should want to get information from a server I don't own. What if I am hosting a website from one end and the game server is on the other. It would seem that you would need FTP or HTTP access to the host file. That's just so . . . Ew. Victor, I want to be able to get stats from a server like so.
Webserver (PHP) -> (Internet) -> Gameserver (LFS)
Or if you'd like we could also do this.
Webserver (PHP) -> (Internet) -> LiveForSpeedWorld (HTTP) -> Gameserver (LFS)
The webserver running PHP connects to the Gameserver (Or LFSW) and gets information such as, Track, Mode (Practice / Quly / Race), Laps, Time, and Number of Players. Then information for each race would be as so, Racer's LFSW Name, Racers Nickname, Car, Lap, Time (For Current Lap), Split 1, Split 2, Split 3, Speed Trap, and Stats (DT, SG, 25, 45, DQed).
the_angry_angel
8th December 2005, 09:32
That for me pretty much kills it, what if I should want to get information from a server I don't own.Well first off you'll need the URL to get it from. Second, if the administrator is using his brain, it will be password protected. Yes, you could get this information by packet sniffing, but you'd need to get that onto the webhost - and lets face it if you can do that, then whats the point in just going for the hosts.txt file?
What if I am hosting a website from one end and the game server is on the other. It would seem that you would need FTP or HTTP access to the host file. That's just so . . . Ew. Victor, I want to be able to get stats from a server like so.You use HTTP to talk to LFSW's pubstats. Whats the problem.
The webserver running PHP connects to the Gameserver (Or LFSW) and gets information such as, Track, Mode (Practice / Quly / Race), Laps, Time, and Number of Players.You can already get this from LFS World, but...
Then information for each race would be as so, Racer's LFSW Name, Racers Nickname, Car, Lap, Time (For Current Lap), Split 1, Split 2, Split 3, Speed Trap, and Stats (DT, SG, 25, 45, DQed)....not in that level of detail though. There is a time limit of about 60 seconds between each LFS World pubstats query, if I remember correctly, so this level of detail is tricky without it being vastly irrelevant. If you want this much detail, write an InSim server to do it, and then query that - much better.
Software is all about choice. If you dont like it, dont use it. Simple.
Dygear
9th December 2005, 18:15
Thanks Angel, looks like I am going to do some InSim programming.
(Damn, now I need to teach myself struts in C++).
the_angry_angel
9th December 2005, 20:43
Dont forget, you're not restricted to using C or C++; anything capable of running sockets should work fine. Even a php script running as cgi (not that you'd want to do this).
Dygear
10th December 2005, 05:26
Dont forget, you're not restricted to using C or C++; anything capable of running sockets should work fine. Even a php script running as cgi (not that you'd want to do this).
I did not know that PHP had struts, if you could show me somewhere I could learn about them, that would be awsome. I am taking it that a strut is a datatype, and I can't really find anything on them.
Anarchi-H
10th December 2005, 07:18
I did not know that PHP had struts, if you could show me somewhere I could learn about them, that would be awsome. I am taking it that a strut is a datatype, and I can't really find anything on them.
I think you are confusing "struts" with "structs"; Struts is an MVC framework originally written in Java (but now with clones / ports to other languages), where as a struct is as you assumed a data type.
PHP doesn't have structs, but then you don't need a struct in PHP. An assoc array or a custom class (if it has a few functions tied to it) would be perfectly suitable.
Dygear
3rd January 2006, 10:18
fuel burnt in dl.
What is DL? Deciliters?
1 deciliter = 0.0264172051 US gallon . . .
martinh
4th January 2006, 00:58
Hmm it's Centiliters, so the dl seems to be wrong...
M@gneto
4th January 2006, 11:15
Hello all,
I want to startup a hotlap competition for our team, there for i want to display de hotlaptimes from our teammembers on our site. Can somebody help me?
I don't know anithing about programing, so it got to be simple.
If i can modify de teammembers, track and car in a file that displays it in a table and i can include on an other page. I'll be happy.
Display
Teammember - Track - tracklayout - time.
I hope somebody can help me with this, a code that i can copy is very welcome.
Tnx
Victor
6th January 2006, 18:13
UPDATE:
We're now at version 1.2. A new feature has been added, which is the hl_log (hotlap log). It comes with plenty of features to make it easy for everyone (see first post of this thread for all details).
Another update is that an id has been added to hotlaps and wr's. This id can be used to download the replay of any hotlap (again, for details, see the first post of this thread).
@nikka - I did not do the chart indication. This would cause a massive impact on our db, so I can't do that. Instead, if you really want to have chart positions, there is something you can do now that the hl_log has been added, namely, you can create your own exact copy of the entire hotlaps db, so you can calculate chart positions yourself.
You can do this by requesting all hotlap charts once and store those. Then all you have to do is make use of the new hl_log, which returns all the new hotlaps. You add these to your own db and you'll always be up to date.
Anarchi-H
7th January 2006, 13:21
*edit*Skip to the 'The point' bit if you can't be arsed to read all of my babble. There is a point. I promise :p*edit*
Excellent stuff Vic, although the 'format' parameter seems to deviate from your (up until now) 'I'll give you the data, you do what you like with it' mantra. :scratchch
I only have one 'gripe', if you like with the LFSWorld data now.
PBs and PSTs.
Anyone who has written a script to get these on a restricted server (especially if you want both of them because they share a tarpit) will tell you that the current method is a pain in the arse.
Consider a page with a team listing.
Each driver has basic information, car number, name, plate, plus a couple of stats and their best PB.
Lets assume that this team has 15 members.
Now, how to get the data?
The easy way around would be alter the max execution time & make the requests in a loop, sleeping for 5 seconds at the end of each iteration.
(15 * 5) * 2 = 150 seconds.
15 drivers, 5 second delays, once for PBs, again for PSTs.
But not everyone has permission (iirc safe_mode restricts this) to alter the max execution time. Some hosts even limit it to lower than default times.
So how to get it if you can't alter the execution time? A cyclic, or round robin cache mechanism, or alternatively a caching request chain.
The first involves picking a name from the top of the driver list, updating and putting them at the bottom, except each driver needs to appear twice. Once for PB, once for PST.
The second is a bit of a hack, but it gets the job done as quick as a for loop but with only a 5 second execution time required.
Basically, a root request is made that takes the same list a cyclic cache would use as an url parameter. The script takes the first one off the list, requests the data, sleeps for 5 seconds and then recurses by making a HTTP request for itself with the new list. This carries on until the list is empty, at which point the job is done.
IMO that is a very long way around, and incredibly wasteful.
The point
I think a separated list of usernames for PB and PST with separate tarpits of at least a minute would make a lot more sense, especially considering that the majority of users for the lfsworld data seem to be teams.
I don't know the request numbers, and I don't know the database schema, but taking our example above, 2 queries has to be better than 30, especially if there are any joins involved.
Of course thats just my opinion and could be total twaffle, but it makes sense to me.
Otherwise, keep up the good work :thumb:
nikka
7th January 2006, 13:59
I think a separated list of usernames for PB and PST with separate tarpits of at least a minute would make a lot more sense, especially considering that the majority of users for the lfsworld data seem to be teams.
Wow, was just writing a simular request when you beat me to it.. :)
The way I do it today (see http://noobs.vossmedia.de/stats.php (not finished btw, still working on it)) is quite... complex since I have to do one hl/pst/pb-request at a time with a 5 sec delay. Being able to retrieve hl/pb/pst for multiple racers in one request would make life waaaay easier.. :)
nikka
7th January 2006, 14:01
@nikka - I did not do the chart indication. This would cause a massive impact on our db, so I can't do that. Instead, if you really want to have chart positions, there is something you can do now that the hl_log has been added, namely, you can create your own exact copy of the entire hotlaps db, so you can calculate chart positions yourself.
You can do this by requesting all hotlap charts once and store those. Then all you have to do is make use of the new hl_log, which returns all the new hotlaps. You add these to your own db and you'll always be up to date.
BTW, thanks for the update! My goal was to minimize the number of db requests, so this should work just fine :thumb:
Tooby
8th January 2006, 00:13
Thanx Victor for giving us the hl_log.
:schwitz:I almost don't dare to ask but...Could some one explain the date stamp (
<entry uploaddate="1136678609">).
Thanx in advance
/Tooby
Edit: Is there any good (free) php editors where you can have auto complete on commands and easy to find help?
Anarchi-H
8th January 2006, 07:26
Thanx Victor for giving us the hl_log.
:schwitz:I almost don't dare to ask but...Could some one explain the date stamp (
<entry uploaddate="1136678609">).
Thanx in advance
/Tooby
Edit: Is there any good (free) php editors where you can have auto complete on commands and easy to find help?
It's a unix timestamp. For information on how to translate it in to an easier read format, see http://www.php.net/manual/en/function.date.php
As for auto completing editors, I can't help you. I gave up on 'em long ago, and now instead use gVIM and the reference manual.
biggie
8th January 2006, 09:34
A little addition to the XML hotlap log which Vic and I have been developing recently. I'm using the script's output for the WR log at the new LFS Files Setups page :)
<track> - The ids resolve as follows:
0 - Blackwood
1 - South City
2 - Fern Bay
3 - Autocross/Drag (should never occur in hotlap log)
4 - Kyoto Ring
5 - Westhill
6 - Aston
<config> - The ids refer to the number of the config, starting by 0 for each track.
<rev> - Boolean value 0 or 1 if rev or not.
For example:
BL GP: track = 0, config = 0, rev = 0
Kyoto National rev: track = 4, config = 1, rev = 1
Aston Grand Prix: track = 6, config = 4, rev = 0
<car> - The cars are listed in the exact order as they appear in LFSWorld:
0 - XF GTI
1 - XR GT
2 - XR GT Turbo
3 - RB4 GT
4 - FXO Turbo
5 - LX4
6 - LX6
7 - MRT5
8 - UF 1000
9 - Raceabout
10 - FZ50
11 - Formula XR
12 - XF GTR
13 - UF GTR
14 - Formula V8
15 - FXO GTR
16 - XR GTR
17 - FZ50 GTR
Anarchi-H
8th January 2006, 15:17
Small issue with the XML output when the list returned should be empty. The other two formats simply supply 'no output', but the XML one supplies only '</hotlaplog>' which is invalid xml and may throw some parsers, or at least cause bitching about mismatched tags or lack of xml declaration.
Example;
http://www.lfsworld.net/pubstat/get_stat2.php?version=1.2&action=hl_log&log_filter=1&control=ks&format=2
In addition, at least one new error message has been introduced. If 'version' is less than 1.2 when requesting 'hl_log', the script returns:
hl_log is only available since version 1.2 and later
*edit*
hl_log appears to be pretty bustified
First, it says 'had uploaded a new WR'. Shouldn't that be 'has' and 'HL'?
Second, the position does not have a value for format 1, and always appears as '1' in format 2.
And lastly, format 1 is missing data, namely track and position.
Unless I missed something and that is how it is supposed to be :s
*edit2*
Just confirmed, format 3 has the same position problem as format 2.
Victor
8th January 2006, 18:58
Small issue with the XML output when the list returned should be empty. The other two formats simply supply 'no output', but the XML one supplies only '</hotlaplog>' which is invalid xml and may throw some parsers, or at least cause bitching about mismatched tags or lack of xml declaration.
Example;
http://www.lfsworld.net/pubstat/get_stat2.php?version=1.2&action=hl_log&log_filter=1&control=ks&format=2
fixed
First, it says 'had uploaded a new WR'. Shouldn't that be 'has' and 'HL'?
fixed, but not HL - it's a WR :)
Second, the position does not have a value for format 1, and always appears as '1' in format 2.
wha?
And lastly, format 1 is missing data, namely track and position.
huh?
Unless I missed something and that is how it is supposed to be :s
*edit2*
Just confirmed, format 3 has the same position problem as format 2.
Sorry, I don't understand the problem. Could do with some more explanation or examples, because positions and all looks dandy here.
<entry uploaddate="1136746340">
<racer>vishnou7022</racer>
<country>Vietnam</country>
<track>0</track>
<config>0</config>
<rev>0</rev>
<car>2</car>
<split1>28450</split1>
<split2>59730</split2>
<split3>85030</split3>
<split4>0</split4>
<pos>126</pos>
<control>w</control>
<flags>517</flags>
<id_hl>31048</id_hl>
</entry>
<u>18:52 08-01-2006</u> <b>vishnou7022</b> had uploaded a new hotlap to 126th place: <b>1:25.030</b> on <b>BL gp</b> with the <b>XRT</b></a>
edit - maybe you meant the laptime was missing in format 1, in the case of a WR. I can't see anything wrong otherwise.
Tooby
8th January 2006, 21:01
It's a unix timestamp. For information on how to translate it in to an easier read format, see http://www.php.net/manual/en/function.date.php
As for auto completing editors, I can't help you. I gave up on 'em long ago, and now instead use gVIM and the reference manual.
Thanx for the information.
Edit: Question
Is hl_log gonna hold all uploaded hotlaps or just latest?
- (get latest entries from the hotlap upload log) compared to <log_filter> 1=WR's - 2=top10 - 3=top50 - 4=ALL
Why am I asking: earlier today I uploaded a spr and now I can't find it.(time of upload: 2006-01-08 01:03:29)
This is what I use:
http://www.lfsworld.net/pubstat/get_stat2.php?version=1.2&action=hl_log&log_filter=4&format=2
Victor
8th January 2006, 23:18
you'll always get the latest entries. The 'All' in the log_filter only means that it displays the entries no matter the chart-position they ended up in.
So, if you get a list with log_filter=1 , you get the 50 last uploaded wr's. If you get a list with log_filter=2, you get the 50 last uploaded hotlaps that ended up in the top10, but if you get a list with log_filter=4, you get the 50 last uploaded hotlaps - no matter their chart position.
You can set the amount of entries that it returns with the parameter &lines=50 (50 is default, 150 is max).
Tooby
8th January 2006, 23:46
you'll always get the latest entries. The 'All' in the log_filter only means that it displays the entries no matter the chart-position they ended up in.
So, if you get a list with log_filter=1 , you get the 50 last uploaded wr's. If you get a list with log_filter=2, you get the 50 last uploaded hotlaps that ended up in the top10, but if you get a list with log_filter=4, you get the 50 last uploaded hotlaps - no matter their chart position.
You can set the amount of entries that it returns with the parameter &lines=50 (50 is default, 150 is max).
Thanx for the info!
* Would it be possible to add <id_hl>38155</id_hl> too &action=hl,ch and wr? (It would be nice to be able to get the *.spr file)
* Would it be possible to get the format option (xml) to the other actions?
Alot of silly questions...:shy:
/tooby
Anarchi-H
9th January 2006, 03:03
<u>18:52 08-01-2006</u> <b>vishnou7022</b> had uploaded a new hotlap to 126th place: <b>1:25.030</b> on <b>BL gp</b> with the <b>XRT</b></a>
edit - maybe you meant the laptime was missing in format 1, in the case of a WR. I can't see anything wrong otherwise.
Doh! My bad. In my defence I was running purely on caffiene yesterday :doh:
Firstly, the position error isn't an error at all, but when log_filter=1 the position always becomes '1' because obviously a WR is always number 1 :p
Second thing (format 1 missing data) seems to have been fixed. Yesterday I was getting stuff like;
<u>14:58 08-01-2006</u> <b>RTOG Papafant</b> had uploaded a new WR to place: <b></b> on <a href="http://www.lfsworld.net/?win=hotlaps&whichTab=trackcharts&track=&config=&car=MRT&racer=RTOG Papafant" target="_blank"> <b></b> with the <b>MRT</b></a>
<u>13:34 08-01-2006</u> <b>Vince</b> had uploaded a new WR to place: <b></b> on <a href="http://www.lfsworld.net/?win=hotlaps&whichTab=trackcharts&track=&config=&car=XRR&racer=Vince" target="_blank"> <b></b> with the <b>XRR</b></a>
Today it seems ok though.
I'll keep checking to see if it was a particular param combo that did it, but IIRC it was doing it all of the time so it's probably fixed.
Good stuff :thumb:
*plug*
I'll be releasing PPF version 2 sometime shortly, as soon as I get PHPDoc to cooperate and finish up the usage docs.
In short, it is easier to install, easier to use, more robust, has more features & is more powerful.
Heres a sneak peek at the minimum code required to get a full hosts list.
require_once('lfsworld/lfsworldinterface.php');
$lfsw = new LFSWorldInterface();
$hosts = $lfsw->getHostsList();
However, the old API is there. It is just in a slightly different form. It will be backwards compatible through a wrapper.
In addition, an optional 'fallback' has been coded in so that if LFSWorld is unreachable, or givs you errors it will try to use old data instead of simply failing, and there are providers for all data sources, including highlights, which has a parsing option.
I don't think I could have made it more straight forward. In addtition, installation will be easier because I'll be distributing the required PEAR libs with it now. You can override that though.
There are lots of other things to mention, but I don't want to hijack the thread so I'll leave it there :)
the_angry_angel
9th January 2006, 10:19
Well done that man!
the_angry_angel
11th January 2006, 23:36
Has the data refresh limit changed recently Victor? I'm doing some testing for libLFSW and I'm pretty sure it used to be 60 seconds, but I seem to beable to do it roughly every 5-10 seconds.
Victor
12th January 2006, 02:35
yeah since s2 it's 5 seconds
the_angry_angel
12th January 2006, 11:23
Awesome. Its worryingly tempting to do away with a cache-ing facility.
Jos Belgium
13th January 2006, 14:56
Hi,
is it possible to add a timestamp to the highlights script? that way, i think that caching of the highlights is possible.
I'm asking this because I'm working on a stats page for my team, and i wish to get the highlights from the past week or month to be displayed on that website.
***edit:
I've uploaded an example of what i want to achieve to my webspace (http://josbelgium.mybesthost.com ).
If a timestamp is added, and the highlights can be qeuried with a starting timestamp, this script can be qeuried and the results can be written to a file or db on the host.
traxxion
14th January 2006, 01:34
Ive read through this whole thread as a php noob so I probably wasn't able to catch all of it, in other words; don't hit me if I ask something stupid now... ;)
Would it be possible in some way to get/calculate the amount of kilometers driven in the last week by a certain racer? I think it's only possible via the online race results (of which I know they won't be available publicly) but I might be underestimating the possibilities with the existing pubstats. Anyone got a trick for that?
Would appreciate any help,
TraXX
traxxion
14th January 2006, 13:00
Yeah! :D
I'd like to thank both D34N0 and TristanCliffe for their online/offline script template, Ive combined the two and it's running perfectly on our website now! :thumb:
the_angry_angel
14th January 2006, 14:34
Would it be possible in some way to get/calculate the amount of kilometers driven in the last week by a certain racer?You could do this by writing a script to parse the PST output of a racer. You then only update this once a week (or have a set of rolling results per team member). Once you have enough data you can just take last weeks value away from the current value and voila.
i.e. This weeks total miles driven for X - Last weeks total miles driven for X.
As the format for PST is fairly easy, you only need to do something like this to get that data (I've roughly written this, so I apologise if its not quite right):if (strpos($pstoutput, '\n') !== false)
{
$distancedriven = substr($pstoutput, 0, strpos($pstoutput, '\n')-1);
}
traxxion
17th January 2006, 11:26
Ok, thanks for the reply Angel. I have to conclude that (however simple it might be for you) my level of php programming is too basic to understand your post. No offense, not your fault at all, just my noobness for now :) I will for sure get back on this once I get more familiar with this stuff.. it's addictive :). Our website's now also got a hotlap competition :D
the_angry_angel
17th January 2006, 12:08
traxxion:
Ah, sorry if I wasnt clear :( As soon as Anarchi-H's finished LFSW-PPF v2, I'll write a little example using it, and I'll do one without shortly :)
Victor:
I presume that all integers in the hotlap log output are not allowed to be negative, and that they are checked before output? Specifically the timestamp, and splits?
traxxion
17th January 2006, 13:03
traxxion:
Ah, sorry if I wasnt clear :(
Again, not your fault :) Just me being too enthusiastic while not having the right skills yet ;)
As soon as Anarchi-H's finished LFSW-PPF v2, I'll write a little example using it, and I'll do one without shortly :)
That'd be awesome! I find the best way to learn is to look at other people's work. Ive also got LFW-PPF but Im not sure how to use it... :shy:
Jos Belgium
17th January 2006, 16:55
Hi again,
I see Victor hasn't responded (yet) to my previous question, so i'll wait on that one..
in post 52in this thread ( http://www.lfsforum.net/showthread.php?p=35947#post35947 ) there is a terrific working script to find who is online. I'm using this script and i love it. But there is one little problem with it i think. What about lfs users that have a space in their name? (e.g. like myself "Jos Belgium"). Is there a way to fix this? I've tried some things i could come up with (in the function trim_c_string in the if statement add something like " || $string[$x] == '(just a space here)'"
but i wasn't able to correct this...
Any help?
the_angry_angel
17th January 2006, 17:14
Whats bug do you have with racer names and spaces? I cant seem to see one from glancing at the code quickly.
tristancliffe
17th January 2006, 17:20
As far as I remember (it's been a while since I used those scripts when building a site) it shouldn't have any problems with spaces.
You have two arrays that deal with display name and username.
$TeamMembers = array("tristancliffe","d34n0","Jos Belgium","lfs name","lfs name");
$InGameName = array("Tristan Cliffe","T7R|D34N0","Jos Belgium"....
Because of the "" it should work, and iirc it did with the few people that had spaces in their names that I tried it with (ages back).
Victor
17th January 2006, 18:01
Victor:
I presume that all integers in the hotlap log output are not allowed to be negative, and that they are checked before output? Specifically the timestamp, and splits?
yep, they're all always positive. Not checked at output, but rather at input and all is stored as unsigned int's, so negative values can't be there.
Victor
17th January 2006, 18:11
Hi,
is it possible to add a timestamp to the highlights script? that way, i think that caching of the highlights is possible.
I'm asking this because I'm working on a stats page for my team, and i wish to get the highlights from the past week or month to be displayed on that website.
***edit:
I've uploaded an example of what i want to achieve to my webspace (http://josbelgium.mybesthost.com ).
If a timestamp is added, and the highlights can be qeuried with a starting timestamp, this script can be qeuried and the results can be written to a file or db on the host.
I can't just add a timestamp; I fear it could disrupt other people's scripts.
The querying you're refering to would have to be made for the pubstats script then, but tbh that's not a high priority for me. In other words, don't expect the highlights to change any time soon :x
Gai-Luron
28th January 2006, 22:39
Hello,
Just a little function in PHP for Trimming zero in string:
function strip_zero( $chaine )
{
list($chaine,$rien) = explode(chr(0),$chaine);
return $chaine;
}
To remove color
function strip_color( $chaine )
{
return ereg_replace( "\^[0-9]","",$chaine);
}
Bye
Der Abt
1st February 2006, 10:10
Is there a workaraound for the timeout?
I have a little teampage and want to have pb and pst infos for 5 players.
That means 10 requests to the server.
I found out, that my script has to do a 5 seconds brake in between the requests, not to get the error "can't reload this page that quickly after another".
(Or do I something wrong with the file_get_contents - function? I wonder, why nobody is complainig the same...)
So my php-Script loads 50 secs! That's much time...
Can't we get multible infos at one request (e.g. action=pst)? :schwitz:
Greetz from cold Germany!
the_angry_angel
1st February 2006, 10:29
Cache your results. Thats the only way around it. Then each time the page is loaded theres a roundrobin system on who gets updated. If thats not good enough, consider running a cron every X minutes to do the update.
Der Abt
1st February 2006, 11:13
Hi angry angel!
Caching would not ueseful, I expect, that our team-members only once a week would call my site - almost no traffic.
It just would be a nice-to-have for the pst-action a multiuser-call like:
...&action=pst&racer=racername1,racername2,racername3...
let's say limited to 20 racers.
The server-resonse shouldn't be much, because it's about ~70 bytes per racer. But would save much time for people, who wants to have data for a nuber of racers, like me.
pb-action - ok this can cause more traffic. I would be satisfied with the pst-multiuserupgrade ;)
Victor
1st February 2006, 11:45
I'll look into that soon. It seems to be a useful feature to request multiple racerstats in one go.
traxxion
1st February 2006, 12:34
I'll look into that soon. It seems to be a useful feature to request multiple racerstats in one go.
OMG, YAY! :thumb: :D
Der Abt
1st February 2006, 13:31
I'll look into that soon. It seems to be a useful feature to request multiple racerstats in one go.
YESSS!:D :D :D
That's what I call a junkie of a programmer - like me!:smileypul
CharlieP
4th February 2006, 01:21
I'll look into that soon. It seems to be a useful feature to request multiple racerstats in one go.
Great, will help a great deal :thumbsup:
Victor
6th February 2006, 13:29
Sorry guys for not having done that option yet, but I'm a bit worried where all this will end, so we've come up with another solution, but we're still checking the details involved. When we're done with that I'll explain it here.
Hang in there :)
Victor
6th February 2006, 19:33
IMPORTANT if you're making use of the pubstats, read the following :
NEW : Login
---------------------
The option to login has been introduced. For now this will be voluntary, but pretty near in the future it will become obligatory for logging purposes, so you best start using this option right now.
Your login (the same as your LFS account) can be passed onto the pubstats via the following two url-variables :
&user=<username>
&pass=<password>
<password> may be your password in plain text, or you can md5 it before sending (strongly recommended).
the_angry_angel
6th February 2006, 20:07
Victor is there any possibility of a set of "magic keys"? i.e. rather than LFS username and password, a key system similar to which google uses, which all transactions must provide? I'm a little wary of LFS account information being passed around...?
Anarchi-H
6th February 2006, 20:34
<stupid><question>Why?</question></stupid> I can see it might be useful for tracking who is using how much of what, but beyond that I don't see a great deal of point. Unless that is going to become the basis of a new tarpit / fair usage system?
the_angry_angel
6th February 2006, 20:49
fair usage system?Tracking and banning those who abuse the system, most likely.
Victor
6th February 2006, 21:30
Victor is there any possibility of a set of "magic keys"? i.e. rather than LFS username and password, a key system similar to which google uses, which all transactions must provide? I'm a little wary of LFS account information being passed around...?
If you explain how it works, it can be made. Wouldn't know what magic keys are.
Victor
6th February 2006, 21:39
<stupid><question>Why?</question></stupid> I can see it might be useful for tracking who is using how much of what, but beyond that I don't see a great deal of point. Unless that is going to become the basis of a new tarpit / fair usage system?
I want to remove the tarpitting for those who _really_ want to be able to use the pubstats without restrictions. But there still has to be some mechanism to prevent people from abusing this possibility and I want to do that with a pay-system.
You can eat out of our fridge all you want, but leave some cash behind so that we can stock it again. In reality that means that the funds will go towards expanding the servers in the future when it's needed.
This way you can get all the stats you want if you really want to, and at the same time contribute to making sure things can keep running in the far future. Additionally I don't think a pay system is very weird, because in the end you're using our resources for your own purposes.
The free pubstats will remain just as they are. You don't have to pay if you don't want to. But those who want to have the tarpitting removed can have it removed for a small fee, based on usage. I'm in the process of determining the fee - it'll be low - how low I don't know yet.
ohyeah, that does mean that I won't be doing the latest request for multiple racers in one go. Those who want bulk-stats can opt to have the tarpitting removed.
Anarchi-H
6th February 2006, 22:14
Ah, good idea! Most sites related to LFS that might want to use this are community resources, and as such are usually privately funded, but as long as it is reasonable I think it makes sense to charge for this as an additional / premium service. However, given that the login data passed on the url now has extra value, I think I'd be way more comfortable in either someway of seeing stats for the data requests made with my login data (so I can see requests made using a pinched login), or having a token (like google maps dev keys) that is tied to my server. The later would be preffered. The login data could be accidentally exposed a million and one ways, some of which are preventable, others less so.
Victor
6th February 2006, 22:21
there will be a page later on that will show monthly logs for everyone using pubstats.
And about the login info - I think I'll make a 'generate login-key' field or so, that will give you a unique code for identification purposes.
Dunno if that accidentally is the same as those magic keys?
nikka
6th February 2006, 22:24
I think this sounds like a great idea.
Do you know when this will be up and running?
the_angry_angel
6th February 2006, 22:30
And about the login info - I think I'll make a 'generate login-key' field or so, that will give you a unique code for identification purposes.Presumably you mean that each user needs to login to LFSworld, and hit the "generate me a pubstats key kthnxplz" button. This key you then use as your unique ID to query pubstats? Or are you thinking some kind of public and private key system?
I'm all for either to be honest :) Just as long as logon details arent directly involved, and you can regenerate the keys as often as needed :)
Victor
6th February 2006, 22:31
I've done most of the background work - now have to start thinking about the UI. Then there also has to be additional payment methods, so you can 'upload credits' to your account (like a pre-paid service). So all in all this will still take a couple of days up to a week or so. Also this prepaid idea will probably be used for other future services as well (but I won't be jumping ahead of myself here ;) ) so it needs to be thought through well. In other words, I'm working on it, but several things will be changing so it will take a bit.
Victor
6th February 2006, 22:34
Presumably you mean that each user needs to login to LFSworld, and hit the "generate me a pubstats key kthnxplz" button. This key you then use as your unique ID to query pubstats?
That, yes :)
32 digits - shouldn't be very easy for people to guess (and I can capture guessers who can btw only guess once every 5 seconds, so ..).
If someone knows a better system, speak now :)
Anarchi-H
6th February 2006, 22:50
That isn't far off the google maps 'magic key' idea. The only difference being is that the google maps API keys are generated from an URL. Any requests made from any other URL using that key just don't work.
Since you can't really rely on the referrer field using http requests (google have the advantage of their system being JS based, and can check the current location directly), may I suggest that multiple keys can be assigned to an account, and each key is tied to the server IP address. That still isn't 100% secure as people on vhost packages sharing a server would be able to use each others key if they got a hold of it, but it certainly does narrow the field down a bit.
Of course, you'd also want to generate it on username and/or password, and maybe have a bit of random junk thrown in there just to give anyone trying to create keys themselves (if they got hold of username / password & IP) a hard time.
I'm pretty sure most developers should be clued up enough to be able to figure out their servers IP address.
P.S Multiple keys might be required, because for instance my development server and hosting server are separate machines, but I'd like to be able to use both at the same time.
*edit* Unrelated note; with JS disabled all of my new lines get stripped, but enabled it's ok?!? Whats that about? */edit*
the_angry_angel
7th February 2006, 11:18
may I suggest that multiple keys can be assigned to an account, and each key is tied to the server IP address.I'm making a test *desktop* application with the barely working version of libLFSW. Do we really want a desktop user to have to work out their IP? Doubly so they're going to get pissed if they need to work it out everytime they connect to the intarweb (i.e. dynamic IPs). I'm fairly sure this might be a good idea for websites and such, but not other uses...
Anarchi-H
7th February 2006, 17:52
I'm making a test *desktop* application with the barely working version of libLFSW. Do we really want a desktop user to have to work out their IP? Doubly so they're going to get pissed if they need to work it out everytime they connect to the intarweb (i.e. dynamic IPs). I'm fairly sure this might be a good idea for websites and such, but not other uses... A special case "development key"? One that isn't tied to the IP. If I'm paying for this key, I want some assurance that if some gimp pinches it they aren't going to get far with it.
the_angry_angel
7th February 2006, 18:28
A special case "development key"? One that isn't tied to the IP. If I'm paying for this key, I want some assurance that if some gimp pinches it they aren't going to get far with it.Perhaps, but at the end of the day I want to release this for everyone, and I dont particularly want to use my own key, rather whatever one the user has..or doesnt have.
Victor
7th February 2006, 20:12
how about :
if (ident-key given)
*verify ident-key
*if (an IP linked to ident-key via setup page) do IP check
else if (username&password given)
*check if pwd is md5 or plaintext - make md5 if needed
*verify details
pick your fav.
the_angry_angel
7th February 2006, 21:43
Sounds brilliant Victor :D (p.s. sorry we're such fussy buggers)
Anarchi-H
8th February 2006, 00:06
Sounds good to me :)
Kleppa
8th February 2006, 08:58
Sorry if you've covered this already. I've made a ircbot which give feedback when a pb, wr or hotlap is requested by a trigger. Will this type of usage be covered by a fee, or will such information be available for free?
Thanks Victor for your work :)
Victor
8th February 2006, 12:50
if your bot already runs and it runs without problem, then I'd say, just leave it like it is.
If however, you want every request to be realtime for example, then you could choose to go for the premium option, so that you won't be bothered by tarpitting anymore.
To summarize;
*the current free tarpitted system remains - nothing changes, apart from that you'll have to add identification with every request so I know who makes a request. I'll let everyone know about the refined identification options later on.
*The pay system is just for those who want to have the tarpitting removed (the forced 5 seconds interval).
Full details will follow later.
Kleppa
8th February 2006, 16:15
Thank you, that cleared up everything :)
mr Orange
8th February 2006, 21:07
to be completely precise - the urlencoding of the LFS:// url only has to be done for browsers other than IE. IE in turn needs only the '+' sign converted DOUBLE (to my knowledge there are no other characters that need conversion, but maybe there are - i haven't met any yet).
So:
IE:
$hostname = preg_replace ("'\+'", "%252B", $hostname);
ANY OTHER BROWSER:
$hostname = urlencode ($hostname);
I am a bit confused at encoding the right LFS join path...
I wanted to use this like in the quote above:
function urlhost($hostname){
if (stristr($_SERVER['HTTP_USER_AGENT'], 'MSIE')){
// IE
$hostname = preg_replace ("'\+'", "%252B", $hostname);
return $hostname;
}else{
// Any other browser
$hostname = urlencode ($hostname);
return $hostname;
}
}
But in IE with a host that have a "|" like "T7R|Public 1" in the name, make the game won't start at all.
In Firefox 1.5 the game can't find the right host. A simple hostname like "OLD MEN RACING Public" gets encoded like "OLD+MEN+RACING+Public" which is also what I see in the game's Join Specific Game screen. But it gives a "Host not found on master server" message.
Edit:
As a matter of fact, all join links on LFSWorld give the same "Host not found on master server" message with Firefox. Or is that just me?
traxxion
9th February 2006, 13:30
Edit:
As a matter of fact, all join links on LFSWorld give the same "Host not found on master server" message with Firefox. Or is that just me?
I think only the host names with a space in it don't work properly. For example 1ST|Racing works fine (both IE and FF), though 1ST|Racing - FOX only works in IE, with this code:
<a href="lfs://|'.str_replace(" ","%20",$host).'|0|S2|" title="join '.$host.'">join</a>
Victor
9th February 2006, 15:52
As a matter of fact, all join links on LFSWorld give the same "Host not found on master server" message with Firefox. Or is that just me?
If no join links work at all, there's something wrongly setup maybe? Perhaps you need to update your join-utility to the latest? http://lfstools.crazyice.net/pafiledb/pafiledb.php?action=file&id=57
Wouldn't know otherwise why it doesn't work in firefox. I haven't met anyone else having that problem I think
Additionally, I just tested hostnames with the '|' character in them, they work without any additional encoding in IE. I'm really thinking you haven' tinstalled the latest join-utility now?
Pinto_PT
9th February 2006, 17:24
How is it possible to achieve something like this but for PB's ?
http://www.lfsforum.net/attachment.php?attachmentid=3462&d=1132355773
And with the scripts for online/offline all I can get is: Couldn't get hostlist. Click to retry...
I'm using this script
<?
//******************************************
// Add Team Member names to$TeamMembers
// LFS User Name and in lowercase
// Lowercase used to reduce typos
// in the username
//
// Also add the team Members In Game
// Name in $InGameName (any case will do)
// MUST be in the same order as $TeamMembers
//******************************************
$TeamMembers = array("pinto_pt","lfs name","lfs name","lfs name","lfs name");
$InGameName = array("pinto_pt","lfs name","lfs name","lfs name","lfs name");
//**********************************
// function to safely trim null-terminated strings
// could just use trim () in this example though
function trim_c_string ($string) {
$new = "";
$len = strlen ($string);
for ($x=0; $x<$len; $x++) {
if ($string[$x] != "\0") $new .= $string[$x];
else break;
}
return $new;
}
// Function to remove the colour code data from a string
function remove_colour_codes($String){
$ColCodes = array("^0","^1","^2","^3","^4","^5","^6","^7","^8","^9");
$NewString = str_replace($ColCodes, "",$String);
return $NewString;
}
// Function used by format_host_colours function to display correct colour value in html format
function get_colour($ColourNum){
switch ($ColourNum) {
case "0";
$ColourName = "#000000"; //Black
break;
case "1";
$ColourName = "#FF0000"; //Red
break;
case "2";
$ColourName = "#00FF00"; //Pastel Green
break;
case "3";
$ColourName = "#FFFF00"; //Yellow
break;
case "4";
$ColourName = "#0000FF"; //Light Blue
break;
case "5";
$ColourName = "#FF0080"; //Light Purple
break;
case "6";
$ColourName = "#00FFFF"; //Turquoise
break;
case "7";
// Remove comment marks on next line if not a white background
//$ColourName = "#FFFFFF"; //White
// Add Comment marks to next line if not a white background
$ColourName = "#808080"; //Dark Grey
break;
case "8";
$ColourName = "#00FF00"; //Pastel Green
break;
}
return $ColourName;
}
// Function to replace the ^x codes in the Host name to show correct colours on the screen
function format_host_colours($HostName){
for($i = 0; $i < strlen($HostName); $i++){
if(substr($HostName, $i, 1) == "^"){
$CharPos = strpos($HostName, "^", $i);
$ColNum = substr($HostName, strpos($HostName, "^", $i) + 1,1);
$ColourString = get_colour(substr($HostName, strpos($HostName, "^", $i) + 1,1));
if($i == "0"){
// If ^ found at the start of the host string remove the ^[num]
$TmpString = substr($HostName,$i+2);
// Add the html font code to the start of the string and append the
// variable $TmpString with the ^[num] removed
$HostName = "<font color='$ColourString'>".$TmpString;
}
else{
// Get the left part of the string to the next ^[num]
$LTmpString = substr($HostName,0,$i);
// Get the right part of the string after the ^[num]
$RTmpString = substr($HostName,$i+2);
// Add the html close font and add the new html colour to the end of the
// Left part of the string then add the right part of the string
$HostName = $LTmpString."</font><font color='$ColourString'>".$RTmpString;
}
}
}
// Close any html font tag left open in the above
$HostName = $HostName."</font>";
Return $HostName;
}
// Function to display Team Members online in a dynamic table
function display_expandable_table($TeamMembers, $LfsUsers, $InGameName){
// Set the variable to count the members online
$MembersOnline = 0;
// Count the number of members
$TotalMembers = count($TeamMembers);
// Create Header row for the table
echo "<tr bgcolor='#CCCCCC' align='center'><th>Team Racer</th><th>On Server</th></tr>";
// search through the file for Team Members and add a row to the
// table showing the name and server they are on
foreach ($LfsUsers as $LfsUser => $LfsHost) {
for($i = 0; $i < $TotalMembers; $i++){
if(strtolower($LfsUser) == $TeamMembers[$i]){
$LfsUser = remove_colour_codes($LfsUser);
$LfsHost = format_host_colours($LfsHost);
echo "<tr bgcolor='#FFFFFF'>";
echo "<td>$InGameName[$i]</td>";
echo"<td>$LfsHost</td></tr>";
$MembersOnline =+ 1;
}
}
}
// Display this row only if no members are online
if($MembersOnline == 0){
echo "<tr bgcolor='#FFFFFF' align='center'><td>No Members</td><td>Are Online</td></tr>";
}
}
// Function to display all Team Member Status
function display_fixed_table($TeamMembers, $LfsUsers, $InGameName){
/// Count the number of members
$TotalMembers = count($TeamMembers);
// Create Header row for the table
echo "<tr bgcolor='#CCCCCC' align='center'><th>Team Racer</th><th>Status</th><th>On Server</th></tr>";
for($i = 0; $i < $TotalMembers; $i++){
echo "<tr bgcolor='#FFFFFF'>";
foreach ($LfsUsers as $LfsUser => $LfsHost) {
if(strtolower($LfsUser) == $TeamMembers[$i]){
$LfsHost = format_host_colours($LfsHost);
echo "<td>$InGameName[$i]</td>";
echo "<td>Online</td>";
echo"<td>$LfsHost</td></tr>";
$Found = "True";
break;
}
else{
$Found = "False";
}
}
if($Found == "False"){
echo "<td>$InGameName[$i]</td>";
echo "<td>Offline</td>";
echo"<td> </td></tr>";
}
}
}
// init some vars
$LfsUsers = array ();
$x = 0;
$LfsHostList = "";
// get the hostlist
$LfsHostList = file_get_contents ("http://lfsworld.net/pubstat/get_stat2.php?action=hosts");
$len = strlen ($LfsHostList);
// Thanks to Tristiancliffe for this line. It is a refresh link
if ($len < 52) exit ("<a href='javascript:document.location.reload();'>Couldn't get hostlist. Click to retry...</a>");
// parse the data
while ($x < $len) {
$LfsHostName = "";
$nr_racers = 0;
for ($y=0; $y<32; $y++) $LfsHostName .= $LfsHostList[$x++];
$LfsHostName = trim_c_string ($LfsHostName);
$x += 20; // skip some host-data
$nr_racers = ord ($LfsHostList[$x++]);
for ($w=0; $w<$nr_racers; $w++) {
$LfsUserName = "";
for ($y=0; $y<24; $y++) $LfsUserName .= $LfsHostList[$x++];
$LfsUsers[trim_c_string ($LfsUserName)] = $LfsHostName;
}
}
// Create table to hold data
echo "<center><br>";
echo "<table border='1' bordercolor='C0C0C0' cellpadding='4' cellspacing='0' style='border-collapse: collapse' style='font-family: Verdana; font-size: 10pt'>";
//*************************************************
// Comment and Uncomment the type of table you want
//*************************************************
display_expandable_table($TeamMembers, $LfsUsers, $InGameName);
display_fixed_table($TeamMembers, $LfsUsers, $InGameName);
/* Close the table */
echo "</table></center><br>";
?>
the_angry_angel
9th February 2006, 17:32
Its possible that your host has disabled some settings which allow file_get_contents to open a socket to an externel website. Try putting the following into a file, and see if you can find "allow_url_fopen". If its set to false then you've got a fundamental problem and need to take it up with your host.
<?php phpinfo(); ?>
Pinto_PT
9th February 2006, 17:40
Its possible that your host has disabled some settings which allow file_get_contents to open a socket to an externel website. Try putting the following into a file, and see if you can find "allow_url_fopen". If its set to false then you've got a fundamental problem and need to take it up with your host.
<?php phpinfo(); ?>
This is what it says
allow_url_fopen | on | on
So I guess its ON
http://pitstop.mobstop.com/php.php
:shrug:
mr Orange
9th February 2006, 17:57
If no join links work at all, there's something wrongly setup maybe? Perhaps you need to update your join-utility to the latest? http://lfstools.crazyice.net/pafiledb/pafiledb.php?action=file&id=57
Wouldn't know otherwise why it doesn't work in firefox. I haven't met anyone else having that problem I think
Additionally, I just tested hostnames with the '|' character in them, they work without any additional encoding in IE. I'm really thinking you haven' tinstalled the latest join-utility now?
Thanks. I apologise, I should have tested a new join-version first. I used the original LFSJoin, maybe it ran out of date or got corrupted when I installed the new FF. Join2LFS works perfect.
Is there a reason you replaced all " " with "%20" on lfsworld.net for IE? As it seams Join2LFS works fine without.
For those interested: urlencode for FF seems to be necessary, else with a host like "ATC Team Public #1" the last space between Public and #1 gets lost.
Victor
9th February 2006, 19:33
Login / Identification UPDATE:
NEW : User-identification (login / Ident-Key)
--------------------------------------------
The option to identify yourself has been introduced. For now this will be voluntary, but in the future it will become obligatory for logging purposes, so you best start using this option right now.
There are two ways to identify yourself:
1) Using an Ident-Key which you can generate on behalf of your account on the LFS World settings pages (http://www.lfsworld.net/?win=settings&whichTab=pubstat)
You can feed an Ident-Key to the pubstat script via the following variable:
&idk=<Ident-Key>
If you bind an IP address to an Ident-Key, then pubstat will make sure that only that IP address can use that Ident-Key.
or
2) Using your normal login (the same as your LFS account), via the following two url-variables :
&user=<username>
&pass=<password>
<password> may be your password in plain text, or you can md5 it before sending (strongly recommended).
Please try it out
Victor
9th February 2006, 19:52
Is there a reason you replaced all " " with "%20" on lfsworld.net for IE? As it seams Join2LFS works fine without.
Hmm, I thought there was a reason, but I can't recall which one exactly (probably the difference between working and not working). But maybe crazyice made it so that it wasn't needed anymore. If it works it works :)
nikka
9th February 2006, 21:00
Please try it out
Well, I generated a ident-key and tried to call pubstat with a fake ident-key but didn't get any error msg? :shrug:
Victor
9th February 2006, 21:16
k, added a mesasge for that (your fake key probably didn't meet the basic requirements so the value never made it into the actual check - or at least I think)
nikka
9th February 2006, 22:47
seems fine now :thumb:
Anarchi-H
10th February 2006, 06:13
Appears to work ok. :) An invalid username / pass doesn't give any feedback though.
Victor
10th February 2006, 12:25
yeah but that's as long as it's voluntary. Later on it'll be more strict (and fail when wrong username and pass are used)
Leifde
11th February 2006, 18:27
I decided to try this to see if I could implement it into my league site, I've got the data and parsed it to some extent but I've come to a problem. I am using an array to get the names of the tracks but it only appears once for each person. This is my code:
<?
$TeamMembers = array("Leifde", "csimpok");
$trackValues = array( "000" => "Blackwood GP",
"001" => "Blackwood GP Rev",
"010" => "Blackwood Rallycross",
"011" => "Blackwood Rallycross Rev",
"100" => "South City Classic",
"101" => "South City Classic Rev",
"110" => "South City Sprint 1",
"111" => "South City Sprint 1 Rev",
"120" => "South City Sprint 2",
"121" => "South City Sprint 2 Rev",
"130" => "South City Long",
"131" => "South City Long Rev",
"140" => "South City Town",
"141" => "South City Town Rev",
"200" => "Fern Bay Club",
"201" => "Fern Bay Club Rev",
"210" => "Fern Bay Green",
"211" => "Fern Bay Green Rev",
"220" => "Fern Bay Gold",
"221" => "Fern Bay Gold Rev",
"230" => "Fern Bay Black",
"231" => "Fern Bay Black Rev",
"240" => "Fern Bay Rallycross",
"241" => "Fern Bay Rallycross Rev",
"250" => "Fern Bay Rallycross Green",
"251" => "Fern Bay Rallycross Green Rev",
"400" => "Kyoto Ring Oval",
"401" => "Kyoto Ring Oval Rev",
"410" => "Kyoto Ring National",
"411" => "Kyoto Ring National Rev",
"420" => "Kyoto Ring GP",
"421" => "Kyoto Ring GP Rev",
"500" => "Westhill International",
"501" => "Westhill International Rev",
"600" => "Aston Cadet",
"601" => "Aston Cadet Rev",
"610" => "Aston Club",
"611" => "Aston Club Rev",
"620" => "Aston National",
"621" => "Aston National Rev",
"630" => "Aston Historic",
"631" => "Aston Historic Rev",
"640" => "Aston GP",
"641" => "Aston GP Rev");
$x = 0;
$numMembers = count($TeamMembers);
$LFSRacerHL = array();
$LFSHotlap = "";
while ($x < $numMembers) {
$LFSHotlap = file_get_contents ("http://lfsworld.net/pubstat/get_stat2.php?action=hl&racer=".$TeamMembers[$x]);
if ($LFSHotlap == "no output" || $LFSHotlap == "can't reload this page that quickly after another") {
die("ERROR! LFSWORLD RETURNED:<br />".$LFSHotlap);
}
$LFSHotlap = nl2br($LFSHotlap);
$LFSHotlap = explode("<br />", $LFSHotlap);
$i = 0;
$LFSHotlapNum = count($LFSHotlap);
while ($i < $LFSHotlapNum) {
$LFSRacerHL[$x][$i] = explode(" ", $LFSHotlap[$i]);
$i++;
}
$x++;
sleep("5");
}
$x = 0;
$i = 0;
print "<center><table border=\"1\" cellspacing=\"0\" cellpadding=\"2\"><tr><td><b>Driver Name</b></td><td><b>Track</b></td><td><b>Car</b></td><td><b>Time</b></td></tr>";
foreach ($LFSRacerHL as $key => $value) {
foreach ($LFSRacerHL[$key] as $key2 => $value2) {
print "<tr><td>".$TeamMembers[$key]."</td>";
foreach ($LFSRacerHL[$key][$key2] as $key3 => $value3) {
if ($key3 == 0) {
$newValue3 = $trackValues[$value3];
print "<td>".$newValue3."</td>";
} else {
print "<td>".$value3."</td>";
}
}
print "</tr>";
}
}
print "</table></center>";
?>I'm using me and csimpok. (csimpok has a lot of hotlaps uploaded which is why I chose him)
The output is here. (http://www.lfskl.cjb.net/lfs.php)
Anarchi-H
11th February 2006, 20:24
You have a space at the start of $value3 for all but the first entries (presumably either \r, \n or both)
Solution?
if ($key3 == 0) {
$newValue3 = $trackValues[trim($value3)];
print "<td>".$newValue3."</td>";
} else {
Notice the 'trim($value3)'.
In addition to that though you have a blank entry in the table at the end of each player, but I'll let you solve that one :p
Victor
11th February 2006, 21:19
///Pubstat-updating update\\\
Added monthly usage log (if you have used pubstat with authentication) and some price info on http://www.lfsworld.net/?win=settings&whichTab=pubstat
Anarchi-H
11th February 2006, 21:55
I presume that the Per Request and Per MB add up to form the total?
So if I make 10000 requests (@£0.00001 per req), and in those 10000 requests I transfer 261Mb (@£0.0015 per Mb)
£0.10 (10000 requests)
+
£0.3915 (261Mb)
=
£0.50 (rounded up)
(Approximation of data transfer for 10000 hostslist requests)
Correct?
Victor
11th February 2006, 22:02
yup
and i'm too lazy to calculate if you used compression in your calculation, but just a general reminder that you can use compression (will make a big difference when getting a lot of hostlists)
Victor
11th February 2006, 22:07
ps, I have monthly approximations for the big users. If someone's interested in seeing his current approximation, just pm me and I'll pm back the results. But only the big users please (the majority won't even go beyond 1 pound a month).
Anarchi-H
12th February 2006, 05:32
It was without compression; I wanted to see how a relatively large output (although I suspect that chart is the largest) scales up in price.
I'll make sure I add idk and username / pass support to PPF when I get my lazy arse around to releasing it. Sorry to anyone who expected it when I said 'shortly'. I have an assload of lame excuses, but I'm sure no one cares :p
I have just had a thought that poses a problem to the current logisitcs of how this will work though....
ATM, the idea is that the tarpitted stats are free, and the untarpitted stats get charged for...
However, most of the stats will be cached anyway... the main use of untarpitted stats would be to make it easier to get pb, pst, hl data etc.
It is still possible to get that data untarpitted with a little extra code AND the premium members may be getting charged for data that everyone else is getting free just cos they have credit. (I.e. If Mr A requests a host list every 2 minutes, and has credit he may get charged. Mr B requests a host list every 60 seconds, doesn't have any credit & gets it free.)
Just wondering if you've accounted for this in your usage scheme, or if the tarpitted stats are going to have further sanctions imposed?
Leifde
12th February 2006, 13:01
I'm stuck again...
I'm trying to convert the milliseconds to minutes:seconds.milliseconds format but it won't work, here's my code (the relevant bit).
foreach ($LFSRacerHL[$key][$key2] as $key3 => $value3) {
if ($key3 == 0) {
$newValue3 = $trackValues[trim($value3)];
print "<td>".$newValue3."</td>";
} elseif ($key3 == 2) {
$newValue3 = round(trim($value3)/1000);
$newValue3_1 = round($newValue3/60);
$newValue3_2 = $newValue3_1*60;
$newValue3_3 = $newValue3 - $newValue3_2;
print "<td>".$newValue3_1.":".$newValue3_3."</td>";
} else {
print "<td>".$value3."</td>";
}
}The output is here. (http://www.lfskl.cjb.net/lfs.php)
Any ideas?
Victor
12th February 2006, 13:36
It was without compression; I wanted to see how a relatively large output (although I suspect that chart is the largest) scales up in price.
I'll make sure I add idk and username / pass support to PPF when I get my lazy arse around to releasing it. Sorry to anyone who expected it when I said 'shortly'. I have an assload of lame excuses, but I'm sure no one cares :p
I have just had a thought that poses a problem to the current logisitcs of how this will work though....
ATM, the idea is that the tarpitted stats are free, and the untarpitted stats get charged for...
However, most of the stats will be cached anyway... the main use of untarpitted stats would be to make it easier to get pb, pst, hl data etc.
It is still possible to get that data untarpitted with a little extra code AND the premium members may be getting charged for data that everyone else is getting free just cos they have credit. (I.e. If Mr A requests a host list every 2 minutes, and has credit he may get charged. Mr B requests a host list every 60 seconds, doesn't have any credit & gets it free.)
Just wondering if you've accounted for this in your usage scheme, or if the tarpitted stats are going to have further sanctions imposed?
there's the variable &free=1 that you can use if you have credit to avoid making use of the premium service (the default is 'have credit? use premium - if not, use free').
Obviously you will be tarpitted again when you throw in one free request right after you did a premium request. It won't work, because the tarpitting is still there - it just doesn't break your request when using premium.
Victor
12th February 2006, 13:49
I'm stuck again...
I'm trying to convert the milliseconds to minutes:seconds.milliseconds format but it won't work, here's my code (the relevant bit).
foreach ($LFSRacerHL[$key][$key2] as $key3 => $value3) {
if ($key3 == 0) {
$newValue3 = $trackValues[trim($value3)];
print "<td>".$newValue3."</td>";
} elseif ($key3 == 2) {
$newValue3 = round(trim($value3)/1000);
$newValue3_1 = round($newValue3/60);
$newValue3_2 = $newValue3_1*60;
$newValue3_3 = $newValue3 - $newValue3_2;
print "<td>".$newValue3_1.":".$newValue3_3."</td>";
} else {
print "<td>".$value3."</td>";
}
}The output is here. (http://www.lfskl.cjb.net/lfs.php)
Any ideas?
forgive me, but i get lost in your example.
I'll just paste my function for converting ms into msht:
function time2msht ($time) {
$div1 = (int) ($time / 1000);
$ms = ($time / 1000)-$div1;
$min = (int) ($div1 / 60);
$sec = $div1 - ($min * 60);
$msht = $min.":".substr ($sec + 100, -2).".".substr (round ($ms * 1000 + 1000), -3);
return $msht;
}
General tip for you beginner programmers - put things in functions. It's much nicer if you have one line in your main code block that says
$msht = time2msht ($milliseconds);
instead of writing the actual code to convert milliseconds to msht on the place of that line. You'll get lost in the end, when trying to find a bug or even just a variable.
Functions are there to make programming easier and more fun :) Use them.
EDIT - note that this function is just for positive values and doesn't indicate hours.
Anarchi-H
12th February 2006, 13:49
Fair enough. Mixing and matching free & premium requests on the same cache is going to present some fun, but it's good to know you've covered the bases :)
Leifde
12th February 2006, 17:35
forgive me, but i get lost in your example.
I'll just paste my function for converting ms into msht:
function time2msht ($time) {
$div1 = (int) ($time / 1000);
$ms = ($time / 1000)-$div1;
$min = (int) ($div1 / 60);
$sec = $div1 - ($min * 60);
$msht = $min.":".substr ($sec + 100, -2).".".substr (round ($ms * 1000 + 1000), -3);
return $msht;
}
General tip for you beginner programmers - put things in functions. It's much nicer if you have one line in your main code block that says
$msht = time2msht ($milliseconds);
instead of writing the actual code to convert milliseconds to msht on the place of that line. You'll get lost in the end, when trying to find a bug or even just a variable.
Functions are there to make programming easier and more fun :) Use them.
EDIT - note that this function is just for positive values and doesn't indicate hours.Thanks :D
P.S. Thanks Anarchi-H for solving my first problem :D
the_angry_angel
12th February 2006, 17:58
Quick question for you Victor, is the unique ident key always a fixed length?
Victor
12th February 2006, 19:53
always 32 digits yep
and [a-z][A-Z][0-9]
Anarchi-H
13th February 2006, 03:27
Eheh, yet one more question.....
How are you going to handle running out of credit?
Falling back to tarpitted stats? Giving an error?
In addition, here is a feature request before you've even launched the main feature :p
An email telling you you've run out of credit. (presuming you weren't going to do that already) :p
Victor
13th February 2006, 04:21
when you have run out of credit you'll fall back to tarpitting yep.
and yes I guess an email can be sent to warn.
Victor
26th February 2006, 09:17
actually it's going to be the other way around. You must explicitly indicate with &ps=1 that you want to use the premium service, provided you have a positive account balance of course. Any other request will be regarded as the normal free request.
traxxion
28th February 2006, 22:22
What's the use of creating two or more Ident-keys? You still can't make two requests within 5 seconds from the same host? (using 2 different ident-keys per request) :scratchch
Anarchi-H
28th February 2006, 23:45
What's the use of creating two or more Ident-keys? You still can't make two requests within 5 seconds from the same host? (using 2 different ident-keys per request) :scratchch
You don't have any credit, hence you aren't eligble for the premium untarpitted requests.
The purpose of the ident keys is to do exactly what their name suggests. IDENTify you, for purposes of deducting credit from you premium account and statistics tracking.
You may need more than one because, for instance, you may want an unteathered key for development (not tied to an IP), and you may run one or two sites on different servers that you would like to be teathered to the server because they could be accidentally exposed to the public. This creates the need for 2 or 3 keys.
Victor
1st March 2006, 00:23
yeah you can have an identkey with a bound to an ip for your live server and a 2nd identkey for your test server.
btw sorry it takes a while for the premium stuff to show up, but i've also been working on another new service / system, which will go online at the same time as the premium pubstats (not related to the pubstats though, apart from that it's another paid service).
It should go online in 2 weeks from now.
traxxion
1st March 2006, 10:12
You may need more than one because, for instance, you may want an unteathered key for development (not tied to an IP), and you may run one or two sites on different servers that you would like to be teathered to the server because they could be accidentally exposed to the public. This creates the need for 2 or 3 keys.
That's as clear as one could possibly bring it Anarchi, thanks. I hadn't thought of it working that way.
but i've also been working on another new service
Hmmmm... very curious what your next creation is about Victor...! :)
Victor
3rd April 2006, 22:02
well the update is done now. You can make use of the premium pubstat feature when you feel like it. Please read the settings page on LFS World and of course you must have a positive account balance for it to work.
Good luck!
traxxion
4th April 2006, 12:09
Well done Victor, it all seems to work very nicely! Still a shame there's no other payment method but the credit card option. You guys gonna make me request a credit card one day... :p
Kchrpm
5th April 2006, 18:06
Ok, I've skimmed the whole thread, and I'm still pretty confused :)
I just want to be able to post the results of http://www.lfsworld.net/pubstat/get_stat2.php?version=1.2&action=pst&racer=%3CKchrpm%3E in this format:
Laps Completed: 1292
Miles Driven: 5595
Gallons of Fuel Burned: 195,990
Races Completed: 116
Wins: 16
Podium Finishes: 45
Dygear
5th April 2006, 20:12
Ok, I've skimmed the whole thread, and I'm still pretty confused :)
I just want to be able to post the results of http://www.lfsworld.net/pubstat/get_stat2.php?version=1.2&action=pst&racer=%3CKchrpm%3E in this format:
Laps Completed: 1292
Miles Driven: 5595
Gallons of Fuel Burned: 195,990
Races Completed: 116
Wins: 16
Podium Finishes: 45
<?php
$ver = '1.2';
$act = 'pst';
$name = '%3CKchrpm%3E';
$host = 'http://www.lfsworld.net';
$path = '/pubstat/get_stat2.php';
$query = "?version=$ver&action=$act&racer=$name";
$url = $host . $path . $query;
$stream = file_get_contents( $url );
$stats = explode( "\n", $stream );
$wins = $stats[4];
$laps = $stats[2];
$miles= $stats[0] / 1600;
$fule = $stats[1];
$fin = $stats[4] + $stats[5] + $stats[6];
echo "Laps Completed: $laps\n";
echo "Miles Driven: $miles\n";
echo "Gallons of Fuel Burned: $fule\n";
echo "Races Completed: ${stats[7]}\n";
echo "Wins: $wins\n";
echo "Podium Finishes: $fin\n";
?>
Have not tested it, but that should do it.
Kchrpm
5th April 2006, 21:05
I'm just testing it by pasting that code into notepad and saving as .php and .html, neither are working, the resultant page is blank. Is there something else I need to do with it?
traxxion
5th April 2006, 23:01
I'm just testing it by pasting that code into notepad and saving as .php and .html, neither are working, the resultant page is blank. Is there something else I need to do with it?
You need to upload it somewhere online before it works ;). Or run a local webserver.
Dygear
6th April 2006, 00:16
For the local web server part, I really love WAMP (http://www.en.wampserver.com/), take alook at it. It's not hard to setup, and it does it's job. Also, I thuogh you were a new programmer, that's why I spewed out the code. As you seem to be just an end user, I would wait, or ask one of the guys who frequents here to make you the program, as I have showed, it's not hard to do.
abz1
19th April 2006, 19:10
Alot of people here using PHP for those of you who are using ASP I created this ASP file and you are more then welcome to use it on your own site.
Ive created 2 ASP files:
1. lfs5sec.asp - this has the 5 second limit
2. lfsCache.asp - this caches the data and renews the file every day.
- lfs_data.txt - just stores the data
heres an example http://www.abz.somee.com/lfs5sec.asp
Its only the PST data packet at the moment, but you can easily add the other data packets.
ps. just rename the appropriate files to asp.
abz1
21st April 2006, 15:50
Ive made an improvement which you will probably like.
Ive combined both the 5sec and cache into one file.
So basically what this new file does is. When you can refresh and get data it saves the data into the file and updates the table. If you refresh early and get the error message then it goes to the file and gets the data from when you last refreshed.
enjoy.
ps. rename the lfsboth.txt to .asp
gergo
21st April 2006, 22:13
Hi!
We are trying to retreive hotlap chart with pubstat, and works fine, except for the new car. I guess it must be named "BF1", but it doesn't work with it. For example http://www.lfsworld.net/pubstat/get_stat2.php?action=ch&track=661&car=BF1 gives an "invalid car" as an answer. Or do we have to use another name instead of BF1?
Forget it. Now it works. Sorry for being unpatient :)
nikka
22nd April 2006, 09:07
Hey,
It seems like "action=hosts" don't return hosts running on patch S and T.
Or is it just me? :)
eakew
22nd April 2006, 10:11
Hey,
It seems like "action=hosts" don't return hosts running on patch S and T.
Or is it just me? :)
Hi,
We have the same problem in LFS-SPAIN (http://www.lfs-spain.net) in our script to see hosts online, only return hosts runnig on patch Q ...and with "action=pb&racer=...", no times for BF1 or track 660, 661 ...:scratchch
traxxion
22nd April 2006, 10:42
Hi,
We have the same problem in LFS-SPAIN (http://www.lfs-spain.net) in our script to see hosts online, only return hosts runnig on patch Q ...and with "action=pb&racer=...", no times for BF1 or track 660, 661 ...:scratchch
Exactly the same problems on our team website! :nod: Would like to know what's changed so we can make the online scripts work again. :shy:
--==Gogo==--
22nd April 2006, 10:59
For all the guys that don't receive hosts that are running the new patch:
Set the version-Flag in your URL to 1.2 then it works fine.
Example: http://www.lfsworld.net/pubstat/get_stat2.php?version=1.2&action=hosts
:smileypul
paXton
22nd April 2006, 12:02
for me, the version=1.2 doesn't change anything.
paXton
traxxion
22nd April 2006, 12:06
For all the guys that don't receive hosts that are running the new patch:
Set the version-Flag in your URL to 1.2 then it works fine.
Example: http://www.lfsworld.net/pubstat/get_stat2.php?version=1.2&action=hosts
:smileypul
Thanks very much, that seems to work indeed :eclipsee_
paXton
22nd April 2006, 12:11
hmmm, now it works here, too.
Victor seems to work on it.
thx, paXton
nikka
22nd April 2006, 14:22
It seems like "action=hosts" don't return hosts running on patch S and T.
OK, works fine now... didn't have to change anything in my scripts either. Thanks Vic! :)
eakew
22nd April 2006, 14:50
mmm ...but "action=pb&racer=..." works with new car/tracks?
paXton
22nd April 2006, 14:55
no, not yet
CrazyICE
24th April 2006, 12:23
hey, what about the car bits?
what exactly are they?
is BF1 the last or between the big GTRs?
in the help file there are only those cars:
XFG = 1
XRG = 2
XRT = 4
RB4 = 8
FXO = 16
LX4 = 32
LX6 = 64
MRT = 128
UF1
RAC
FZ5
FOX
XFR
UFX
FO8
FXR
XRR
FZR
BF1
i really don't remember how it continues!
/EDIT: got it :)
looking onto LFSW helps :) hehehe
Der Abt
25th April 2006, 09:59
I would like to pay some money for the non-tarpitted stats.
But I don't have a credit-card.:schwitz:
Why don't You accept PayPal, what I used already to purchase the game???
Wouldn't be PayPal the easiest for those very small money-transactions?
:scratchch
Greetz
Sven
Victor
25th April 2006, 11:25
just make a manual paypal transfer to us for the moment.
Der Abt
25th April 2006, 13:20
:thumb: Oh, great! I will do it in a minute...
...done :)
Pablo.CZ
25th April 2006, 20:50
Is there chance to get race stat if raceID is known? I didnt find anything in get_stat2_1.2.txt
XML would be great with as much info as possible
bdshan
4th May 2006, 02:31
I am having trouble getting a join link to work where thehost has a double quote in the name. I am using ASP, can anyone help giude me to a solution?
<a href="lfs://|<%=replace(ol_srvr_nc, " ", "%20", 1, -1, 1)%>|0|s2|/">Join</a>
bdshan
4th May 2006, 02:35
Alot of people here using PHP for those of you who are using ASP I created this ASP file and you are more then welcome to use it on your own site.
Brillant :thumb: just what I have been looking for, thanks.
the_angry_angel
8th May 2006, 12:03
I am having trouble getting a join link to work where thehost has a double quote in the name. I am using ASP, can anyone help giude me to a solution?
<a href="lfs://|<%=replace(ol_srvr_nc, " ", "%20", 1, -1, 1)%>|0|s2|/">Join</a>
If I'm following, all you need to do is replace " with "". Standard ASP "escaping".
P2M-Unixseb
10th May 2006, 11:37
Hello world,
i would be verry interested in having the abilitie to retrieve the online pb of several users in just one query instead on severals one,
IE : http://www.lfsworld.net/pubstat/get_stat2.php?version=1.2&action=pb&racer=[usr1,usr2,usr3......]
Do you think this is possible ?
Anarchi-H
10th May 2006, 14:23
Hello world,
i would be verry interested in having the abilitie to retrieve the online pb of several users in just one query instead on severals one,
IE : http://www.lfsworld.net/pubstat/get_stat2.php?version=1.2&action=pb&racer=[usr1,usr2,usr3......]
Do you think this is possible ?
No. It's been asked before. However, you can pay for the premium service and get multiple pbs without the tarpit affecting you. It's best to do it in a script which doesn't render data to an end user though else they'll be faced with an apparently slow loading page.
P2M-Unixseb
10th May 2006, 15:34
thx for replying,
i did my script with a sleep(5) after each loop, not marvelous but working :)
you can see it result here (http://www.pedal2metal.com/TNCC/tncc.php?track=500&c1=BF1&c2=LX6)
traxxion
10th May 2006, 18:03
thx for replying,
i did my script with a sleep(5) after each loop, not marvelous but working :)
you can see it result here (http://www.pedal2metal.com/TNCC/tncc.php?track=500&c1=BF1&c2=LX6)
Nice script, though you might want to consider caching?
CrazyICE
11th May 2006, 10:22
thx for replying,
i did my script with a sleep(5) after each loop, not marvelous but working :)
you can see it result here (http://www.pedal2metal.com/TNCC/tncc.php?track=500&c1=BF1&c2=LX6)
nice one...
P2M-Unixseb
11th May 2006, 13:21
Nice script, though you might want to consider caching?
yep, next step is to run the script once or twice a day and store the results in a mysql db, so end users won't have to wait anymore, i don't really need the real time part :)
Dygear
11th May 2006, 16:19
Flat file is the best way if you ask me. That is how I do it at least. I infact have two flat files, one file has the seconds past unix epoch in it my system read that file and and askes if it is 300 seconds past last update. 300 seconds is equal to 5 minutes. if it is, then it sets the variable $file to the lfsworld URL that I would like to get the information from. If is is not past 300 seconds then $file points to the cache. It then reads the file ( or the information from LFSWorld ) and places that information into another generic variable called $data. The data is then parsed by my parse_ssv function. SSV is Space Separated Value. It returns an array and is ready for use.
Anarchi-H
11th May 2006, 21:01
Flat file is the best way if you ask me. That is how I do it at least. I infact have two flat files, one file has the seconds past unix epoch in it my system read that file and and askes if it is 300 seconds past last update. 300 seconds is equal to 5 minutes. if it is, then it sets the variable $file to the lfsworld URL that I would like to get the information from. If is is not past 300 seconds then $file points to the cache. It then reads the file ( or the information from LFSWorld ) and places that information into another generic variable called $data. The data is then parsed by my parse_ssv function. SSV is Space Separated Value. It returns an array and is ready for use.
Why use two files when you could just use filemtime on the cache file? :pillepall
If it is a simple display of details then flat file should suffice, but if you want to start comparing stuff you are better off investing time in making it an sql cache because it will save you writing your own comparison engine in your language of choice.
Dygear
11th May 2006, 22:22
Why use two files when you could just use filemtime on the cache file? :pillepall
If it is a simple display of details then flat file should suffice, but if you want to start comparing stuff you are better off investing time in making it an sql cache because it will save you writing your own comparison engine in your language of choice.
Good question. Some servers are so locked down they don't allow for PHP to read that variable. I know it seems odd that they would not allow for it, but that is the way it is.
the_angry_angel
12th May 2006, 00:08
Good question. Some servers are so locked down they don't allow for PHP to read that variable. I know it seems odd that they would not allow for it, but that is the way it is.
Sounds like the inappropriately named php "safe mode" is to blame. When this is in effect, unless you "own" the file / directory, php won't read it. [un]fortunately theres no way (without code hacking) to remove restrict individual functions.
As an aside, there was / is discussion regarding safe mode being removed completely in php 6 :D
The alternative is that the relevant base functions may not be available (i.e. sys/stat.h). I'm not sure what php's build does when a library isn't available (as I've never come across this), but sods law says it would probably just be defined but return some arbitrary value.
Anarchi-H
12th May 2006, 11:35
Sounds like the inappropriately named php "safe mode" is to blame. When this is in effect, unless you "own" the file / directory, php won't read it. [un]fortunately theres no way (without code hacking) to remove restrict individual functions.
If this is the case, simply set the cache folder to writable by PHP, and have PHP create the cache file (which I should imagine it does anyway), then it will be owned by PHP and therefore stat-able by php.... unless the server config is totally backwards of course :p
I had that problem with my first version of the server search which was hosted on f2s.
I can't say I've ever come across a server that has had filemtime put on the blacklist, but I guess that could be possible too.
the_angry_angel
12th May 2006, 12:07
Sadly that assumes that the credentials that php runs under has write access :( something which I've considering denying on certain personal servers and other projects. Certainly worth trying though :D
Anarchi-H
12th May 2006, 12:12
True... never considered anything that restricted before, but then PHP wouldn't be able to update a file either, hence making a file or sqlite based cache totally impossible on such a restrictive setup.
Unless of course you mangled up some kind of system to have read only directories, but writable files. Still, alot of work, for what?
I know if my host was that restrictive I'd have chucked them a long time ago :-p
the_angry_angel
12th May 2006, 12:19
Hmm, never said it was a hosting service ;) I'd probably be with you, and leave if I was subjected to those conditions. But its surprising that people still put up with safe mode; its a bit of a munge, and isnt really "safe". I guess what I;m trying to say is that people will put up with almost anything as long as you make the explanation as to why, sound reasonable (see any sales [wo]man ;)).
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.