Jump to content

Some help please?


Huntey

Recommended Posts

Hi everybody,

 

I am trying to do a couple of things using an online datafeed.

 

Parse the data file and determine a way of getting only information from the CLIENTS section and determining if theyre connected as ATC or Pilot

 

So, lets say the datafeed is www.datafeed.com/data.txt to simply things. This datafile has information about the network. The network is in this case a place where people can connect using flight simulator to be a pilot, or a different program to be an Air Traffic Controller. Then pilots and controllers can see and interact.

 

The datafile has information about the different servers available on the network, and the clients (the section we need to get) connected to the network.

 

This is a quote from the datafile.

 

; Sections are:

; !GENERAL contains general settings

; !CLIENTS contains informations about all connected clients

; !PREFILE contains informations about all prefiled flight plans

; !SERVERS contains a list of all FSD running servers to which clients can connect

 

That is the sections included in the datafile - the clients section is what we need to get.

 

!CLIENTS:

username:memberID:John Smith:PILOT::49.85923:4.50782:4242:140::0::::Server 1:100:1:7000::::::::::::::::::::20111203153935:331:29.681:1005:

username:memberID:Harry Potter:ATC:119.000:54.73228:60.61887:0:::0::::Server 1:100:1::0:150:::::::::::::::::20111203154912:20111203151850::::

 

this is an extract of the clients section, its basicly got loads of these, you can see that all fields are seperated by a : - it goes username, followed by the clients unique ID, followed by there name, then if they are connected as ATC or Pilot, then the rest of the data is of no interest to us as its co-ordinates etc.

 

So, my first task is to get the clients section, I have done this by making a .php file on my server named datagrab.php (my server is seperate the the server hosting the datafeed.) and in datagrab I put:

 

<html>

<body>

 

<?php list(, $clients) = explode('CLIENTS:', file_get_contents('http://www.datafeed.com/data.txt')); 

 

echo $clients

?>

 

 

</body>

</html>

 

and it has successfully displayed only the clients. I dont know if there is a better way of doing this?

 

So having that I know need to add something to that page, or make a new page and include or use that file to determine if the client is connected as ATC or PILOT. Look at the quote above to see where it tells you if they're a ATC or PILOT.

 

Does anybody have any ideas on how I can do this?

 

thanks.

Link to comment
Share on other sites

Looking at the data that you posted it seems to me that this will accomplish what you are trying to do giving you all of the information:

 

//get the data
$data = file_get_contents('http://www.datafeed.com/data.txt');

//first of all explode them on new lines to get all of the info
$lines = explode("\r\n",$data); // you must use double quotes and it might just need to be \r or just \n test it until you get a full array of all the lines as there own entry

//setup a holder for the type of data you are getting - (general, clients, prefile, servers)
$type = '';

//setup a holder for all of the data
$content = array();

//go through each line and explode the data
if(is_array($lines)){
foreach($lines as $line){
	//setup holder for line data
	$line_data = explode(':',$line);

	//check to make sure there is data
	if(is_array($line_data)){
		//if there is only one item it is a type so change the type and continue
		if(count($line_data) == 1){
			$type = $line_data[0];	
		} else {
			$content[$type][] = $line_data;
		}
	} else {
		continue;
	}
}
}

//now you can print out the data to make sure that you have it in the way you need
print_r($content);

 

When you run this code it should give you back a multi-dimensional array with the type of data as the key for the array and all of the fields with numeric indexes based on there position. Here is an ex.

 

[!GENERAL]
[0] => [some data]

[!CLIENTS]
[0] => array()
	[0] => username
	[1] => memberID
	[2] => John Smith
	[3] => PILOT
[2] => array()
	[0] => username
	[1] => memberID
	[2] => Harry Potter
	[3] => ATC

 

So you can then just do a loop on the data that you need and check its type

 

if(is_array($content['!CLIENTS'])){
foreach($content['!CLIENTS'] as $client){
	if($client[3] == 'PILOT'){
		//do something here	
	}
}
}

 

Hopefully that is not too confusing and will solve your problem.

Link to comment
Share on other sites

Ok so I'm now using this:

//get the data
$data = file_get_contents('http://www.datafeed.com/data.txt');

//first of all explode them on new lines to get all of the info
$lines = explode("CLIENTS:",$data); // you must use double quotes and it might just need to be \r or just \n test it until you get a full array of all the lines as there own entry

explode("\r\n",$data);

//setup a holder for the type of data you are getting - (general, clients, prefile, servers)
$type = 'CLIENTS:';

//setup a holder for all of the data
$content = array();

//go through each line and explode the data
if(is_array($lines)){
foreach($lines as $line){
	//setup holder for line data
	$line_data = explode(':',$line);

	//check to make sure there is data
	if(is_array($line_data)){
		//if there is only one item it is a type so change the type and continue
		if(count($line_data) == 1){
			$type = $line_data[0];	
		} else {
			$content[$type][] = $line_data;
		}
	} else {
		continue;
	}
}
}

//now you can print out the data to make sure that you have it in the way you need
print_r($line_data)

 

and it seems to have all worked except on the array, the numbers dont reset for each connected client it counts all the way from 0 - 24483. How can I correct this?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.