Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Users can exit a function early. There needs to be a method that prevents this. #375

Open
ghost opened this issue Feb 21, 2016 · 2 comments

Comments

@ghost
Copy link

ghost commented Feb 21, 2016

Oh, just that I did find a clever hack, but it's complicated.

var stuff = function() {
        // Separate the definitions so you can't exit the function
        var behaviorFn = function(me) {
            // <edit>

            // </edit>
            // END
            // ***
        };

        map.defineObject('startDrone', {•••});
        // just some security in case you exit the behaviorFn
        var check1 = behaviorFn.toString().replace(/\n/g, ' ');
        var check2 = stuff.toString().replace(/\n/g, ' ');
        if (!(/E(N)D(.*)\*\*\*/.test(check1))) {
            throw "Function ends too early";
        }
        if (/(\*\*\*).*(E(N)D)/.test(check2)) {
            throw "You can't trick my code into exiting early";
        }

    };
    stuff();

behaviorFn is the code I'm trying to protect. It is used in the definition of startDrone.

But since startLevel is protected, perhaps we level creators could have #START_OF_PROTECTED_FUNCTION# and #END_OF_PROTECTED_FUNCTION# in our levels?

Oh yeah, two AWESOME levels coming up when this is resolved. One is called droneRelay.jsx, you will have to pass the key through four drones before finishing.

@zhykzhykzhyk
Copy link

No, not really.

var behaviorFn = function(me) {
            // <edit>
}
// GET OUT OF THE FUNCTION!!!
behaviorFn = function (me) {
            // </edit>
            // END
            // ***
};

@pppery
Copy link
Contributor

pppery commented Jul 20, 2019

The protection of startLevel is only security through obscurity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants