diff --git a/KongregatePlatform.php b/KongregatePlatform.php index 62b968a..4f5bc29 100644 --- a/KongregatePlatform.php +++ b/KongregatePlatform.php @@ -29,6 +29,13 @@ public function loadLibraries() { echo ""; } + public function displayHeader() { + } + + public function displayFooter() { + + } + public function getFlashHeight() { return 580; } @@ -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']; diff --git a/README b/README index a042389..451649c 100644 --- a/README +++ b/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///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'] = ""; + $config['app_secret'] = ""; + $config['app_root'] = ""; + $config['server_root'] = ""; + $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. diff --git a/index.php b/index.php index dd219df..468f2fc 100644 --- a/index.php +++ b/index.php @@ -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); } diff --git a/kongregate_login.php b/kongregate_login.php index 71458cf..b64d564 100644 --- a/kongregate_login.php +++ b/kongregate_login.php @@ -61,4 +61,4 @@ function startLoginRefreshTimer() { kongregateAPI.loadAPI(onLoadCompleted); - \ No newline at end of file +