Skip to content

Commit

Permalink
spice up the README
Browse files Browse the repository at this point in the history
  • Loading branch information
towski committed Mar 31, 2011
1 parent 5cf0d1e commit d0228ff
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 13 deletions.
12 changes: 11 additions & 1 deletion KongregatePlatform.php
Expand Up @@ -29,6 +29,13 @@ public function loadLibraries() {
echo "<script type='text/javascript' src='http://www.kongregate.com/javascripts/kongregate_api.js'></script>";
}

public function displayHeader() {
}

public function displayFooter() {

}

public function getFlashHeight() {
return 580;
}
Expand Down Expand Up @@ -180,12 +187,15 @@ public function getName($user_id) {
return $_REQUEST['kongregate_username'];
}

protected function getGameItems() {
return self::getRemoteData("{$this->config['api_host']}/items.json?api_key={$this->config['app_secret']}&game_id={$this->config['app_id']}");
}

protected function getKredsInventory() {
return self::getRemoteData("{$this->config['api_host']}/user_items.json?api_key={$this->config['app_secret']}&user_id={$this->user}");
}

protected function useKredItem($itemData) {

$app_secret = $this->config['app_secret'];
$item_id = $itemData['id'];
$item_ident = $itemData['identifier'];
Expand Down
35 changes: 34 additions & 1 deletion README
@@ -1 +1,34 @@
hello world!
Putting a Facebook game on Kongregate

Kongregate can serve games through your servers just like Facebook. Metal games, the producers of Tyrant, have given us some tips and code for handling both. With some small tweaks to your server, and some tweaks to your game, you can serve your game in both places.

The code examples in this demo are in php from https://github.com/jimgreer/synapse

Handling kongregate and facebook credentials:

First, create a Kongregate game in iframe mode, using the url of index.php from synapse. Then you can get your game credentials from kongregate at /games/<username>/<game>/api. For the demo, you can put them in the top of index.php.

if (isset($_REQUEST['platform']) && $_REQUEST['platform'] == "fb") {
} else {
require_once("KongregatePlatform.php");
$config['app_id'] = "<id>";
$config['app_secret'] = "<api_key>";
$config['app_root'] = "";
$config['server_root'] = "<wherever your server is>";
$platform = new KongregatePlatform($config);
}

Handling user login

The php api automatically shows a link to the kongregate login form if they aren’t logged in. You can change the content of this in kongregate_login.php. When they are successful, the example app just sends the user back to the main index.php.

From there, we can access $platform for kongregate and facebook, for getting the user name, or user items.

Handling microtransactions

The main example automatically requests the user item list from kongregate when the page loads with $platform->$getKredsInventory. On the server side, we are automatically marking all items as used when the user loads the page, in order to cash them in.

kreds_game example.

link to transaction api docs.
25 changes: 15 additions & 10 deletions index.php
Expand Up @@ -4,19 +4,24 @@
$config = array();
if (isset($_REQUEST['platform']) && $_REQUEST['platform'] == "fb") {
require_once("FacebookPlatform.php");
$config['app_id'] = "211399198872054";
$config['app_secret'] = "1ba40f64224da013c9b42a584d001dd8";
$config['app_root'] = "http://dev.tyrantonline.com/platformdemo/?platform=fb";
$config['server_root'] = "http://dev.tyrantonline.com/platformdemo";
$platform = new FacebookPlatform($config);
$config['app_id'] = "162536733803732";
$config['app_secret'] = "51405170f11b22c8231fbc2cbda4c163";
$config['app_root'] = "http://mrkongybot.doesntexist.com:4007/synapse/?platform=fb";
$config['server_root'] = "http://mrkongybot. .com:4007/synapse/";
$platform = new FacebookPlatform($config);

} else {
require_once("KongregatePlatform.php");
$config['app_id'] = "108711";
$config['app_secret'] = "5f58de78-c989-49cd-948a-af423ff222bf";
$config['app_root'] = "http://www.kongregate.com/games/freneticpixel/platform-demo_preview/";
$config['server_root'] = "http://dev.tyrantonline.com/platformdemo";

$config['app_id'] = "108822";
$config['app_secret'] = "9fe7bfa1-826e-4fd7-9747-f55769e85854";
$config['app_root'] = "http://www.kongregate.com/games/towski/facebook-example_preview?guest_access_key=ead63275767bc3adf7561672548da162c5e605f88fe3ce801d2e177e79135466";
$config['server_root'] = "http://localhost:4007/synapse/";
//$config['app_id'] = "72";
//$config['app_secret'] = "513d6ce3-b085-4974-af7b-ea8813afa105";
//$config['app_root'] = "http://www.kongregatedev.com:3000/games/jimgreer/facebook-example_preview?guest_access_key=656c10f76916679d17cdba7095107b3aa69a8fa193daa7d9a978e07c6f72097d";
//$config['server_root'] = "http://localhost:4007/synapse/";
//$config['api_host'] = 'http://www.kongregatedev.com:3000/api';
$config['api_host'] = 'http://www.kongregate.com/api';
$platform = new KongregatePlatform($config);
}

Expand Down
2 changes: 1 addition & 1 deletion kongregate_login.php
Expand Up @@ -61,4 +61,4 @@ function startLoginRefreshTimer() {
kongregateAPI.loadAPI(onLoadCompleted);
</script>
</body>
</html>
</html>

0 comments on commit d0228ff

Please sign in to comment.