Missions API

Got an idea on how things should be done? A problem with something on the site? Voice your opinion!

Missions API

Post by comperr on Wed Apr 30, 2008 6:18 pm
([msg=1770]see Missions API[/msg])

The missions API used for the logics, extended basics, and other missions is very simple. The realistic missions API is quite similar though it uses a different 'control' file and a different 'win' file.

First some basic terms (as called by me, they are not in the API files themselves but since I am the one that wrote PnP and I had these terms in mind I'll just publish em here).
PnP - Plug and Play - the name for the API
PnPS - PnP Strict - the type of system where the template and mission loading is done by a middle man
PnPL - PnP Lite the template is controlled by the mission itself (like the realistic missions), and it only calls the 'win' file if you actually won.

Controlled by a few distinct files PnP is very easy to use and create missions with.

The CONTROL file is the file that gets the input, verifies it for security problems, and ensures that the level you requested is available.
It works in one of two ways:
PnPS - This file is included by template.php and is ignored after that
PnPL - This file is included by the mission and is barely used, it can be ignored.

The TEMPLATE file only exists for PnPS and it looks something like this:
This is being rewritten in PnP 1.3 or PnP 2.0; the particular variable names will change though the concept is similar.
Code: Select all
<?php
    $plug['type']='category'; //the name in the database or the category (basic/extbasic/stego)
    $require_basic = FALSE; //Require the user to have done the basic missions
    $require_order = FALSE; //Require the user to do all the missions in order
    $showform=TRUE; //Show the standard input form, this variable will be changed soon to be based on whether you chose PnPL or PnPS
    $win_mode = 'normal'; //this is very important though will be addressed in the lvl.php file below
    $helptext = 'show stuff '; //this text is shown on every mission.
...//Auth stuff
    require_once('../plugplay.php'); //include the CONTROL file
    require_once 'lvl/'.$lvl.'.php'; //in PnPS all levels are kept in a folder called lvl and in a file called lvl#.php
    require_once ('../plugplaywin.php'); //include the WIN file\
?>

This file is only shown to show which variables you can override in your level file. We don't recommend you override any of them but if you need special requirements you can.

The WIN file is mainly verification (and the file that displays the standard input) and I will paste the important parts
Code: Select all
        switch ($win_mode)
        {
            case 'win':
                $plug['win']=TRUE;
                break;
            case 'text':
                if ($pass != '') {$plug['win']=TRUE;}
                break;
            case 'empty':
                if (isset($_GET['pass']) && empty($_GET['pass'])) {$plug['win']=TRUE;}
                break;
            case 'normal':
                if ($pass == $submit_correct) {$plug['win']=TRUE;}
                break;
            case 'regex':
                if (preg_match($submit_correct,$pass)) {$plug['win']=TRUE;}
                break;
        }
//if $plug['win']=TRUE you will see the go on button
/* $pass is the input text
$submit_correct is the answer supplied by the mission.  I will assume you have some knowledge of PHP and will let you figure out what each one does.  Note that if none of them suit you you can always change $win_ mode to 'no' and let the mission change it to 'win' if need be.
*/


As for the most important file and the one that you will be creating you get the simplest of them all:
Code: Select all
What is 1+1?
<?php
$submit_correct='4';
?>

Thats it. If you want to attach a file you can do so by using <img> tags or such.

I think I pretty much covered this and guaranteed I am not as clear as I should be. Please let me know in this thread and I will update it.


Please note:'
This is ONLY for PnP 1.2.
Version 1.3 will fix most of the variable name problems as well as allow for a bit more control over template. It should also fix the code duplication (some of which you don't see).
Version 2.0 will create a mission class which will be more in line with OOP and such.
Version 2.1 will be dropable namely that the particular file names and such will be unimportant and that missions will be self unaware.
User avatar
comperr
Poster
Poster
 
Posts: 373
Joined: Mon Apr 07, 2008 6:52 pm
Location: /dev/null
Blog: View Blog (0)


Return to Comments & Suggestions

Who is online

Users browsing this forum: No registered users and 0 guests