Understanding MochiAds Publisher Bridge


Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2026

Warning: Invalid argument supplied for foreach() in /home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2026

Warning: Invalid argument supplied for foreach() in /home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2398

Warning: implode() [function.implode]: Argument must be an array in /home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3351

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3374

Warning: Invalid argument supplied for foreach() in /home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3374

Warning: Invalid argument supplied for foreach() in /home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3415

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3467

Warning: Invalid argument supplied for foreach() in /home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3467

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3612

Warning: Invalid argument supplied for foreach() in /home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3612

Now that you have a WordPress theme and plugin in order to set uo your own MochiAds arcade site like triqui.com, let’s see how we can add some interesting features with the Publisher Bridge.

Every step explained in this tutorial will be included in the next upgrade of Triqui MochiAds Arcade theme, but it’s very interesting to see how does it work in order to custom it or install it in your own arcade site.

First, let me explain why you should use the Publisher Bridge… the reasons are listed in the official page:

  1. Leverage the hundreds of MochiAds leaderboard enabled games to attract new players.
  2. Receive new traffic – MochiAds’ Challenges feature will drive new players back to your site to compete in top scores.
  3. Build exciting site features – Save player scoring info for all MochiAds leaderboard-enabled games.
  4. Encourage competition – In-game scores are listed for your community only.
  5. Maintain consistency – Display your own community usernames when players post scores.
  6. Promote your brand – Put your site logo directly in the game.

but, as usual, it’s up to your creativity finding the best way to use them.

Cross-domain policy

From the Cross-domain policy file specification you cana cross-domain policy file is an XML document that grants a web client – such as Adobe Flash Player (though not necessarily limited to it) – permission to handle data across multiple domains. When a client hosts content from a particular source domain and that content makes requests directed towards a domain other than its own, the remote domain would need to host a cross-domain policy file that grants access to the source domain, allowing the client to continue with the transaction.

So the first thing you should do is to create a file called crossdomain.xml in your root, with this content:

1
2
3
4
5
6
7
8
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
     <site-control permitted-cross-domain-policies="master-only"/>
     <allow-access-from domain="x.mochiads.com"/>
     <allow-access-from domain="www.mochiads.com"/>
</cross-domain-policy>

This will allow Mochi client to communicate with your server.

Javascript call

Once your server is able to communicate, you need to insert the javascript provided by Mochi in the same page where you host (or leech) a game.

You don’t need to know if the game has a leaderboard, if the game does not support highscores, nothing will happen.

This is the one I used:

1
2
<script src="http://xs.mochiads.com/static/pub/swf/leaderboard.js" type="text/javascript"></script>
               <script type="text/javascript">var options = {partnerID: "3b7a2ab2368e1d2d", id: "leaderboard_bridge",globalScores:"true",gateway : "http://www.triqui.com/wp-content/themes/triqui/postscores.php",callback : function (params) {document.getElementById('latest').innerHTML="Your latest score: "+params.score;}}; Mochi.addLeaderboardIntegration(options);</script>

I used only a few options among the ones provided by Mochi, let me explain them:

partnerID: this is the ID MochiAds gave you when you signed up as a publisher. Remember: the Publisher ID, not the Publisher Secret Key!!!

id: The id of the HTML element you want to place the Bridge SWF into. Place such element wherever you want, it’s not important since it does not contain anything.

globalScores: Set to true if you wish to display global scores and not just those submitted from your site. I recommend to set it to true if your portal does not have that much visits per day (under 10,000).

gateway: the absolute path of a file that will receive posted data with POST method. I’ll explain how to use such data in next tutorial

callback: a JavaScript function which will be called when the player submits a score. In my case, I simply display in the page the latest score the player got, but obviously you can use Ajax to improve the interactivity.

Try to see it in action playing a leaderboard enabled game on Triqui.com, such as Mazeroll and see what happens when you submit a score.

But the most exciting feature lies in the gateway: having all score data in the POST array will allow you to create custom leaderboards and some other interesting things I’ll explain during next tutorial.

Meanwhile, look at the variables the bridge passes to postscores.php page when I submit a score, obtained with a simple var_dump:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
array(14) {
  ["signature"]=>
  string(32) "(had to omit it)"
  ["sessionID"]=>
  string(0) ""
  ["userID"]=>
  string(0) ""
  ["username"]=>
  string(0) ""
  ["scoreLabel"]=>
  string(6) "Points"
  ["sortOrder"]=>
  string(4) "desc"
  ["datatype"]=>
  string(6) "number"
  ["description"]=>
  string(0) ""
  ["title"]=>
  string(10) "Highscores"
  ["gameID"]=>
  string(16) "98c536dbf70a1cbc"
  ["boardID"]=>
  string(32) "4b2ac948de239f8853a3bc6a1b771d9d"
  ["name"]=>
  string(4) "ququ"
  ["score"]=>
  string(3) "520"
  ["lcId"]=>
  string(1) "1"
}

Next time I’ll show you how to use these values.

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (20 votes, average: 4.10 out of 5)
Loading ... Loading ...
WordPress themes are designs for WordPress - one of the most popular blogging software nowadays.
You will be pleasantly surprised by WordPress Themes provided by Template Monster. All of them are of professional design and high quality.
Be my fan on Facebook and follow me on Twitter! Exclusive content for my Facebook fans and Twitter followers

This post has 16 comments

  1. Josh of Cubicle Ninjas

    on July 16, 2009 at 8:01 pm

    Just as an FYI – I’m seeing a bunch or errors in my RSS feed where your ad is. Happy to send these along if they’d help debug.

    Btw, very excited about the Box2D powered platformer. You might enjoy this similar engine as an example:
    http://citrusengine.com/

  2. SJG

    on July 17, 2009 at 4:23 pm

    Absolutely awesome beginning… looking forward to the next post very much as I am about to start to attempt to integrate.

    Not only are you teaching flash, but you are teaching PHP and WordPress… What more can someone want :)

    Any idea’s when the next version will come out?
    And did my fix’s make any sense?

  3. Guest

    on July 18, 2009 at 8:17 am

    mmm… can’t be this used to cheat?

  4. Games

    on August 2, 2009 at 8:42 am

    nice post …. Thanks

  5. öykü

    on August 2, 2009 at 6:06 pm

    Good solution, thanks

  6. SJG

    on August 6, 2009 at 6:52 pm

    Eagerly awaiting part 2….

  7. Understanding MochiAds Publisher Bridge – Part 2 : Emanuele Feronato

    on August 17, 2009 at 11:06 pm

    [...] This is the second part of Understanding MochiAds Publisher Bridge. [...]

  8. Understanding MochiAds Publisher Bridge – Part 3 : Emanuele Feronato

    on August 24, 2009 at 4:20 pm

    [...] part 1 we saw how to configure a cross-domain policy file, calling the javascript and send the results to [...]

  9. Old Man

    on September 19, 2009 at 9:38 pm

    OK managed to sort the previous issue. Got 20 games yet when I go to Add games to blog it says No new games to add.

    When I clich Manage game files I get:

    Warning: Invalid argument supplied for foreach() in /home/himitsu/public_html/wp-content/plugins/mochi/mochi.php on line 63

  10. Harack

    on November 7, 2009 at 2:55 am

    i was unable to get it to print the scores when submitted. Can’t seem to find the problem i followed the tutorial from the start and added the code to the posts. Nothing was being written to my postscores.php.

    var options = {partnerID: “32c56bcde8981861″, id: “leaderboard_bridge”,globalScores:”true”,gateway : “http://www.harack.co.nz/wordpress/wp-content/themes/triqui/postscores.php”,callback : function (params) {document.getElementById(‘latest’).innerHTML=”Your latest score: “+params.score;}}; Mochi.addLeaderboardIntegration(options);

  11. skuvy

    on January 28, 2010 at 9:28 pm

    hello i have installed this plugin but i am getting 2 errors:

    at ‘New Games’

    Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 47 bytes) in /home/awzombox/public_html/wp-content/plugins/mochi/mochi.php on line 148
    ———-
    tried raising memory_limit = 64M but no luck..
    also tried adding the following lines at wp-config.php without any luck either..
    define(‘WP_MEMORY_LIMIT’, ’64M’);
    @ini_set(‘memory_limit’,’64M’);

    —————————————
    at ‘Manage Game Files’
    Warning: Invalid argument supplied for foreach() in /home/awzombox/public_html/wp-content/plugins/mochi/mochi.php on line 63

    —-

    I would really appreciate your help on this.

    Thanks in advanced.

  12. skuvy

    on January 29, 2010 at 1:02 pm

    fixed the previous errors :)

    now i am having the following:

    I am having the Add Games to blog ‘No new games to add’ issue..
    i have tried changing json limit on line 291 but no luck..
    also checked and url_fopen is enable on my host.

    has someone find any solution to this?
    I would really appreciate a little help here :)

    sK.

  13. alifuatexe

    on February 7, 2010 at 8:59 pm

    how did you fix can you explain pls

    at ‘Manage Game Files’
    Warning: Invalid argument supplied for foreach() in /home/awzombox/public_html/wp-content/plugins/mochi/mochi.php on line 63

  14. Ankit Saini

    on February 13, 2010 at 3:06 am

    is there any way that my logged in user score automatically saved in leaderboard and also in my site..

    thanks

  15. just me

    on June 26, 2010 at 1:58 am

    The worst theme, I had never seen.

    It’s better to make a theme from the begining than trying to understand what you have in yours.

    at least you have to put a readme.txt file to provide the basic about the theme and ask for a price .

  16. popokolok

    on October 15, 2010 at 6:14 pm

    Hello, doesn’t seem to anymore – I am using WP 3.0.1 and nothing is being written to the database from the gateway… Any help is appreciated!