Partial PHP port of CyberMistress

This is the place for general discussions on fetishes, sexuality and anything else. What's on your mind right now?
Post Reply
enoch
Explorer
Explorer
Posts: 46
Joined: Wed Jan 24, 2007 8:31 am
Gender: Male
Sexual Orientation: Straight
I am a: Slave
Dom/me(s): Goddess Maya Loux
Contact:

Partial PHP port of CyberMistress

Post by enoch »

Here's the deal. Cyber Mistress gives me hell under Wine on Linux. About two weeks ago I got tired of having to mess with Windows and started trying to do a simple port of cybermistress to Linux. What I have so far is a PHP script which will run a good portion of routines.

It requires php-gtk2 to be installed, as well as php. If you use a distro with decent package management that should be easy to install. If not, PM me and I'll explain it.

Anyway, here is what I have. It is far from a fully functional program and I know the code is a bit crappy, but I'm posting this here so anybody who wants to work from what I've done so far can. If I have time in the future I may actually get around to doing a full port.

This script does not currently support sounds, anything dealing with setValue, and some minor things like that. Most routines which don't use those will run fine.

I'm not going to explain much more. I'll just let the code speak for itself.

Code: Select all

<?php

//runs the routine file specified as the first argument
$routine = $argv[1];

//set this to what you want #slave to be transformed into
$slave = 'slave name goes here';

//turn debug output off by setting to false
$GLOBALS['debug'] = TRUE;

//open routine
$mroutine = file($routine);
$count = count($mroutine);
$x = 0;
$flags = array();

while ($x < $count) {
    $line = rtrim($mroutine[$x]);
    
    if ($line{0} == '[') {
        //we're beginning a new action
        $action_name = str_replace(array(']', '['), '', $line);

        $actions["$action_name"] = array();
        $actions["$action_name"]['name'] = $action_name;
        
        $y = $x + 1;

        //get the next line and make sure it's not the beginning of another action
        while (strpos($mroutine[$y], '[') !== 0 && $y < $count) {
            $line = explode('=', $mroutine[$y], 2);
            $line[1] = rtrim($line[1]);
            switch ($line[0]) {
                case 'message':
                    $actions["$action_name"]['message'] = str_replace(array('#slave', '
'), array($slave, "
"), $line[1]); break;
                case 'delay':
                    $actions["$action_name"]['delay'] = $line[1]; break;
                case 'picture':
                    $actions["$action_name"]['picture'] = str_replace('\', '/', $line[1]); break;
                case 'next':
                    $actions["$action_name"]['next'] = $line[1]; break;
                case 'flag':
                    $actions["$action_name"]['flags'] = $line[1]; break;
                case 'unflag':
                    $actions["$action_name"]['unflag'] = $line[1]; break;
                case 'requires-flag':
                    $actions["$action_name"]['required-flag'] = $line[1]; break;
                case 'else':
                    $actions["$action_name"]['else'][] = $line[1]; break;
                case 'mindelay':
                    $actions["$action_name"]['mindelay'] = $line[1]; break;
                case 'maxdelay':
                    $actions["$action_name"]['maxdelay'] = $line[1]; break;
                case 'askYN':
                    $actions["$action_name"]['askYN'] = $line[1]; break;
                case 'yes':
                    $actions["$action_name"]['yes'] = $line[1]; break;
                case 'no':
                    $actions["$action_name"]['no'] = $line[1]; break;
                case 'start':
                    $start_action = $line[1]; break;
                case 'end':
                    $end_action = $line[1]; break;
            }
            $y++;
        }
        $x = $y - 1;
    }
    else {
        $x++;
    }
}

if (isset($start_action)) {
    //do actual startup

    $gui = array();
    $gui['win'] = new GtkWindow();
    $gui['win']->maximize();
    $gui['message'] = new GtkLabel('Testing');
    $gui['message']->set_justify(Gtk::JUSTIFY_LEFT);
    $gui['vbox'] = new GtkVbox();
    $gui['win']->add($gui['vbox']);
    $gui['image'] = new GtkImage();
    $gui['vbox']->pack_start($gui['image']);
    $gui['vbox']->pack_start($gui['message']);
    $gui['win']->show_all();



    $next = do_action($start_action);
    while ($next !== FALSE) {
        $next = do_action($next);
    }


}
else {
    die("This script has no starting action.
");
}


function do_action($name) {
    global $actions, $flags, $gui;
    echo "Running $name
";
    if (isset($actions["$name"])) {
        $action = $actions["$name"];
        if (isset($sleep)) { unset($sleep); }


        //Handle flags and pre-requisites
        if (isset($action['required-flag'])) {
            $flag = $action['required-flag'];
            if (!isset($flags[$flag])) {
                echo "Required flag $flag is not set. Jumping to ". $action['else']. " instead.
";
                return $action['else'];
            }
        }
        if (isset($action['unflag'])) {
            unset($flags[$action['unflag']]);
        }
        if (isset($action['flag'])) {
            $flags[$action['flag']] = TRUE;
        }

        if (isset($action['picture'])) {
            $pic = $action['picture'];
        }

        if (isset($action['message'])) {
            $message = $action['message'];
            $gui['message']->set_text($message);
        }

        if (isset($action['picture'])) {
            echo "Setting picture to ". 'pics/'. $action['picture']. "
";
            $gui['image']->set_from_file('pics/'. $action['picture']);
        }

        $gui['win']->show_all();
        while (Gtk::events_pending()) {
            Gtk::main_iteration();
        }

        if (isset($action['delay'])) {
            if (is_numeric($action['delay'])) {
                $sleep = $action['delay'];
            }
            elseif (strpos($action['delay'], '|')) {
                $explode = explode('|', $action['delay'], '2');
                $dialog = new GtkMessageDialog(NULL, 1, Gtk::MESSAGE_INFO, Gtk::BUTTONS_OK, $explode[1]);

                sleep(2);
                $dialog->run();
                debug("Dialog finished
");
                    while (Gtk::events_pending()) {
                        Gtk::main_iteration_do();
                    echo "loop
";
                     }

                $dialog->destroy();
                    while (Gtk::events_pending()) {
                        Gtk::main_iteration_do();
                    echo "loop
";
                     }
            }

        }
        elseif (isset($action['mindelay'])) {
            $min = $action['mindelay'];
            $max = $action['maxdelay'];
            $sleep = rand($min, $max);

        }


        if (isset($sleep)) { 
            debug("Sleeping $sleep seconds.
");

            $x = 0;

            while ($x < $sleep) {
                echo "	$x
";
                sleep(1);
                $x++;
            }

/*            while ($x < $sleep) {
                Gtk::main_iteration();
                sleep(1); $x++;
            }
*/

        }


        if (isset($action['askYN'])) {
                                $dialog = new GtkMessageDialog(NULL, 1, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO, $action['askYN']);
                                sleep(2);
                                $response = $dialog->run();
                                while (Gtk::events_pending()) {
                                        Gtk::main_iteration_do();
                                }
                                $dialog->destroy();
                                while (Gtk::events_pending()) {
                                        Gtk::main_iteration_do();
                                }
                if ($response == -9) {
                    debug("Answer was no");
                    return $action['no'];
                }
                elseif ($response == -8) {
                    debug("Answer was yes");
                    return $action['yes'];
                }
                else {
                    die("Undefined answer
");
                }
        }
        elseif (isset($action['next'])) {
            $next = explode('|', $action['next']);
            shuffle($next);
            return $next[0];
        }
        else {
            return FALSE;
        }



/*
            $next = explode('|', $actions["$name"]['next']);
            shuffle($next);
            echo "Doing ". $next[0]. " next.
";
            do_action($next[0]);

        }
*/
    }
    else {
        die("Action $name does not exist.
");
    }
}

function show_message($message) { }
function show_picture($picture) { }

function debug($msg) {
    if (isset($GLOBALS['debug'])) {
        echo "$msg
";
    }
}
?>
bdp514
Curious Newbie
Curious Newbie
Posts: 3
Joined: Mon Mar 10, 2008 3:36 am

Re: Partial PHP port of CyberMistress

Post by bdp514 »

Hey enoch,

I've written a pretty complete port in realbasic that runs just fine under most linux distros - I'll be happy to send it to you If you want to check it out.
Post Reply