Adblock breaks this site

Question regarding a redirect...

Discussion in 'Web Programming' started by Laurie, Feb 12, 2013.

  1. Laurie

    Laurie
    Retired Sectional Moderator Pirate $50 USD Donor

    Joined:
    Nov 26, 2007
    Posts:
    7,630
    Referrals:
    0
    Sythe Gold:
    1,197
    M
    Two Factor Authentication User SytheSteamer
    Question regarding a redirect...

    http://forums.sonicretro.org/index.php?

    If you type in:

    19 65 09 17

    and then press A+Enter simultaneously, it redirects to a new page.

    http://forums.sonicretro.org/cheats/

    (for those that don't know 19 65 09 17 is the level select cheat in Sonic the Hedgehog 2)

    I was wondering if anyone could explain how that works, as it's damn interesting and i'd like to know how to code something like that!

    Thanks!

    Ame
     
  2. Jazz00006

    Jazz00006 Apprentice
    Visual Basic Programmers

    Joined:
    Aug 26, 2005
    Posts:
    807
    Referrals:
    0
    Sythe Gold:
    0
    Question regarding a redirect...

    You'll notice that there is a file http://forums.sonicretro.org/cheats/cheatEngine.js in this file, you have javascript.

    The main part of this javascript is
    Code:
    jQuery(document).ready(function () {
        jQuery("body").keydown(function (e) {
            var kc = (e.keyCode == 0) ? e.which : e.keyCode;
            for (var i = 0; i < cheatCodes_C.length; i++) if (cheatCodes_E[i] == 1) {
                if (kc == cheatCodes_C[i][cheatCodes_P[i]][0] || kc == cheatCodes_C[i][cheatCodes_P[i]][1]) {
                    cheatCodes_P[i]++;
                } else {
                    cheatCodes_P[i] = 0;
                }
                if (cheatCodes_P[i] == cheatCodes_R[i]) playRing();
                if (cheatCodes_P[i] == cheatCodes_C[i].length) {
                    cheatCodes_F[i]();
                    cheatCodes_E[i] = 0;
                    cheatCodes_P[i] = 0;
                }
            }
        });
    });
    Which translates to: every time a button is pushed on this web page, add it to an array.
    Check that array against another, which is a list of the keys you need to press to activate a 'cheat code'



    To create a cheat code, first add in an array of character keys and the callback function.
    Code:
        addCheat([k1, k9, k6, k5, k0, k9, k1, k7, kA, kS], function () {
            window.location.href = 'http://forums.sonicretro.org/cheats/';
        }, 8);
    I hope this helps you understand the javascript behind it.
     
  3. Laurie

    Laurie
    Retired Sectional Moderator Pirate $50 USD Donor

    Joined:
    Nov 26, 2007
    Posts:
    7,630
    Referrals:
    0
    Sythe Gold:
    1,197
    M
    Two Factor Authentication User SytheSteamer
    Question regarding a redirect...

    Thanks for the response Jazz, very helpful. Cheers.
     
< Javascript Help v2.0 | HTML Web developer wanted! >


 
 
Adblock breaks this site