Get content of directory

Discuss the Dedicated Server Tools developed by Nadeo Live such as ManiaLive, Trust Circles, Dedicated Manager, Competition Manager and Lobbies

Moderator: NADEO

Post Reply
MuNgLo
Posts: 314
Joined: 12 Jul 2012, 03:37

Get content of directory

Post by MuNgLo »

Is there any way to get a filelisting of a directory?

What I want is to get a list of all map files in a specific folder to be able to put them in playlist. Is there any way to do so now? I cant find it so for now I'm kinda stuck. :(

--EDIT--

Sry for not being idiotproof :P

Of course i want this to be possible on remote trough the manialive interface.

On a side not I must point out the "painting into a corner" mentality of coding any plugin to be only working if hosted on same host as the server.
Last edited by MuNgLo on 13 Aug 2012, 18:15, edited 1 time in total.
User avatar
Xymph
Posts: 1399
Joined: 15 Jun 2010, 20:35
Contact:

Re: Get content of directory

Post by Xymph »

Developer of XASECO for TMF/TMN ESWC & XASECO2 for TM²: see XAseco.org
Find your way around the Mania community from the TMN ESWC hub, TMF hub, TM² hub, and SM hub
User avatar
askuri
Posts: 156
Joined: 18 Oct 2011, 15:01
Location: Germany

Re: Get content of directory

Post by askuri »

or glob() http://php.net/manual/de/function.glob.php
I think this is ab bit easier to understand ;)
MuNgLo
Posts: 314
Joined: 12 Jul 2012, 03:37

Re: Get content of directory

Post by MuNgLo »

why are you assuming I'm hosting manialive on same wm as the servers?
User avatar
askuri
Posts: 156
Joined: 18 Oct 2011, 15:01
Location: Germany

Re: Get content of directory

Post by askuri »

Ok, you need a small API, that runs the glob() function and returns the result. Smal example (not tested)

Client (ManiaLive):

Code: Select all

<?php
$api_url = http://api.example.com/get_tracklist.php?param=someparam&moreparam=param2;
$response = file_get_contents($api_url); // this will open the script, execute it and save the result in $response
$response = json_decode($response); // Decode the Json code
print_r($response); // Just an output for testing
?>
Server (DedicatedServer - get_tracklist.php):

Code: Select all

<?php
$param = $_GET["param"]; // This is the first prameter from the URL (?param=someparam)
$moreparam = $_GET["moreparam"]; // This is the second prameter from the URL (?moreparam=param2)

// Get a list of files in the current directory
$filelist = array(); // Initialize ...
foreach (glob("*.*") as $filename) {
$filelist[] = $filename; // Adds the current filename to the filelist
}

echo json_encode($filelist); // Arrays can´t be echot, so we json encode it
?>
I hope you understand that.
Note: Untested
Note2: Unsecure because data is not hashed
Note3: For a very good tutorial, click here: http://net.tutsplus.com/tutorials/php/c ... plication/
Note4: the clientfile mus not be on a webserver but the Serverfile
Note5: JSON (on client and server) and PHP 5.3 (only client) required
Note6: The same is also possible with cURL but for that you should read the tutorial from tutsplus.

PS: Many Notes, I know ^^
MuNgLo
Posts: 314
Joined: 12 Jul 2012, 03:37

Re: Get content of directory

Post by MuNgLo »

But that's still just a workaround. Im running servers on a small linux wm. I won't set up a webbserver just to run a single jsonfeed like that.

So I guess there isn't a way to actually use the servers api to get what maps it has access to. Just gonna run it with a static array for now then i guess. :cry:
User avatar
askuri
Posts: 156
Joined: 18 Oct 2011, 15:01
Location: Germany

Re: Get content of directory

Post by askuri »

With Webserver is the easyiest way. You can also set up a php comamndlien script that provides a XML-RPC Server but thats nearly the same like just running manialive on that server.
But here's a fact: it's not possible to get that list without a clientsite script. How should the scripts from the manialive server get access to the other servers filesystem, without providing a server for that?

The easiest way would be, just running manialive on the dedicated servers server.
MuNgLo
Posts: 314
Joined: 12 Jul 2012, 03:37

Re: Get content of directory

Post by MuNgLo »

askuri wrote:How should the scripts from the manialive server get access to the other servers filesystem, without providing a server for that?
By asking the gameserver what maps/files it has in its folder. It asks stuff and tells server to do stuff all the time. As it is now you only have what's already in the playlist to manipulate. That's really very restrictive. After all, other gameservers have had such features like listing available maps.
Not really to much to expect is it?
Post Reply

Return to “Dedicated Server Tools”

Who is online

Users browsing this forum: No registered users and 2 guests