FunTrackers Forum

Full Version: maniacode problem for horns
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I'm creating a Manialink for Trackmania United Forever. I'm currently adding horns to the manialink.
I have the following problem: Suppose you have 2 horns (in reality I have much more of them):

Crazy Frog Ding Ding.ogg and Doh.ogg

What I do now is create a maniacode for each horn and register it on the player page:

code1:

<?xml version='1.0' encoding='utf-8' ?>
<maniacode>
<install_skin>
<name>Crazy Frog Ding Ding</name>
<file>Skins/Horns/Crazy frog ding ding.ogg</file>
<url>http://jonasmanialink.freeiz.com/horns/sounds/Crazy_frog_ding_ding.ogg</url>
</install_skin>
</maniacode>

code2:

<?xml version='1.0' encoding='utf-8' ?>
<maniacode>
<install_skin>
<name>D'oh</name>
<file>Skins/Horns/Doh.ogg</file>
<url>http://jonasmanialink.freeiz.com/horns/sounds/Doh.ogg</url>
</install_skin>
</maniacode>

Is there a way to combine code1 and code2 into one maniacode file and select the
proper code when someone downloads one of the horns? That way I have to create only one
maniacode for all my horns and register only one code on the player page.

Plz some help.
You can put several actions (also install_skin) into one maniacode. But you cannot select one to only install this one with maniacodes only.


The following code will install both horns:


With a PHP file it is possible to only register one maniacode. You can add Parameters to the maniacode which can be accessed with php.

Excerpt from [ENG] ManiaLinks Forever.
Ok, thx for the reply. In the meanwhile I've installed PHP 5.2 and Apache. It's been about 10 years that I learned PHP, so I hope you can help me out a bit here. I think I'm gonna give every horn an id and call the maniacode like this: nameCode?id=1 for the first horn and so on. I know that I can access that id with $_GET['id'] in PHP.
So suppose I have
code1:

<?xml version='1.0' encoding='utf-8' ?>
<maniacode>
<install_skin>
<name>Crazy Frog Ding Ding</name>
<file>Skins/Horns/Crazy frog ding ding.ogg</file>
<url>http://jonasmanialink.freeiz.com/horns/sounds/Crazy_frog_ding_ding.ogg</url>
</install_skin>
</maniacode>

and code2:

<?xml version='1.0' encoding='utf-8' ?>
<maniacode>
<install_skin>
<name>D'oh</name>
<file>Skins/Horns/Doh.ogg</file>
<url>http://jonasmanialink.freeiz.com/horns/sounds/Doh.ogg</url>
</install_skin>
</maniacode>

how do I select the right code given the id parameter? is the maniacode file a *.xml file or a *.php file and how do I mix xml with php?
The file has to be *.php.

Maybe you first have a look to this Advanced Example of Entry and FileEntry, there is an example of how to use XML in a php file.

For beginners an array with the filenames is the easiest solution:


With $files[$id]['name'] and so on you can write the values into the XML part. (Note: you have to set a value for $id before)

But you should first validate if the submitted id exists, and if not you can send an error message instead of a horn.
Thx, that should get me started. Is that what they call a multidimensional array?
Ok, this is what I created:

<?php
//declare and initialize variables
$name = "";
$file = "";
$url = "";
$id = $_GET['id'];
$idIsValid = True;

switch ($id) {
case 1:
$name = "Crazy Frog Ding Ding";
$file = "Skins/Horns/Crazy frog ding ding.ogg";
$url = "http://jonasmanialink.freeiz.com/horns/sounds/Crazy_frog_ding_ding.ogg";
break;
case 2:
$name = "D'oh";
$file = "Skins/Horns/Doh.ogg";
$url = "http://jonasmanialink.freeiz.com/horns/sounds/Doh.ogg";
break;
default:
$idIsValid = False;
}

// Output the ManiaCode
header('Content-Type: text/xml');
if ($idIsValid) {
echo <<<EOT
<?xml version='1.0' encoding='utf-8' ?>
<maniacode>
<install_skin>
<name>{$name}</name>
<file>{$file}</file>
<url>{$url}</url>
</install_skin>
</maniacode>
EOT;
} else {
echo <<<EOT
<?xml version='1.0' encoding='utf-8' ?>
<maniacode>
<show_message>
<message>The horn doesn't exist. Please choose another one.</message>
</show_message>
</maniacode>
EOT;
}
?>

It seems to work, but could you recheck my code, please?
I used a switch instead of an array because storage is smaller.
I have a few questions though:
- I don't understand why the variable in for eg <file>{$file}</file> has curled brackets?
- You suggested: "But you should first validate if the submitted id exists, and if not you can send an error message instead of a horn."
I don't know if I have done this properly?

Another issue is that a *.loc file is installed in the horns directory of TrackMania. When someone downloads a horn he could open that file, go to my url and download all the other horns for free...
So I password protected them, but then TrackMania couldn't access the file anymore... Any idea?

Thx a lot for the help so far. I really helped me a lot!!
Please use php BB code next time Smile

One reason for the brackts is the human redability, but they are needed in some special cases. (Google will be more detailed)

For the method you chose the validation works.
I googled a lot, but can't find anything, so i'll ask again:

Another issue is that a *.loc file is installed in the horns directory of TrackMania. When someone downloads a horn he could open that file, go to my url and download all the other horns for free...
So I password protected the horns on the server, but then TrackMania couldn't access the file anymore... Any idea how to solve this? Can you disable the creation of a *.loc file when someone downloads a horn?

What's php BB code?
Maybe it is possible to password protect the files only for explorer UserAgents, so trackmania can access without limitations. But I can't test if the file gets downloaded if you enter the URL in the manialink explorer.

MyCodes (or BBCodes) for php simply php in the brackets.
Reference URL's