Location: PHPKode > scripts > MetaBB > metabb/pnFlashGames.php
<?php
/*************************************************************************** 
 * 
 *                              newscore.php 
 *                            ------------------ 
 *   begin                : Sunday, November 13, 2005 
 *   copyright            : (c)2005 www.phpbb-amod.co.uk 
 *   email                : hide@address.com 
 * 
 *   $Id: newscore.php, v3.0.0 2005/11/13 12:59:59 dEfEndEr Exp $ 
 * 
 ***************************************************************************
 *
 * pnFlashGames Support for the phpBB Arcade Mod (c) 2005 dEfEndEr
 *
 * Based on information from the pnFlashGames mod (c) Lee Easton
 *
 **************************************************************************/

define('IN_PHPBB', true);
$phpbb_root_path = './';
include_once($phpbb_root_path . 'extension.inc');
include_once($phpbb_root_path . 'common.'.$phpEx);
include_once($phpbb_root_path . 'includes/functions_arcade.'.$phpEx);

// Start session management 
$userdata			= session_pagestart($user_ip, PAGE_ACTIVITY); 
init_userprefs($userdata); 
// End session management 

if($userdata['user_id'] == 2147)
  exit;

//
//  TEST DATA, INSERT ALL RESULTS TO THE DB.
//
$sql = "INSERT INTO `phpbb_ina_log` VALUES ('****** ".$userdata['username']." ******','****** pnFlashGames ******')";
if (!$result = $db->sql_query($sql))
{ 
  message_die(GENERAL_ERROR, 'Could not obtain forums information', '', __LINE__, __FILE__, $sql);
}

foreach ($_POST as $key => $value) 
{ 
  $sql = "INSERT INTO `phpbb_ina_log` VALUES ('" . $key ."','" . addslashes(htmlspecialchars($value)) . "')";
  $db->sql_query($sql);
} 

//
//  Build the required information from what we have received.
//
$mode = trim(htmlspecialchars($HTTP_POST_VARS['func']));
$arcade->score = doubleval($HTTP_POST_VARS['score']);
//$gameData = $_POST['gameData'];
$game_id = intval($HTTP_POST_VARS['gid']);


switch($mode)
{
  case "storeScore":
//
//  pnFlashGames Score save routine
//
    if($userdata['user_id'] > 0 && $arcade->score > 0)
    {
      $sql = "SELECT * FROM " . iNA_SESSIONS . "
        WHERE user_id = '" . $userdata['user_id'] . "'
          LIMIT 1";
      $session_info = $db->sql_fetchrow($db->sql_query($sql));
      if($session_info)
      {
        $sql = "DELETE FROM " . iNA_SESSIONS . "
          WHERE user_id = " . $userdata['user_id'];
        $db->sql_query($sql);

        $arcade->game_name  = $session_info['game_name'];
        $arcade->time_taken = time() - $session_info['start_time'];
        $arcade->score_type = ARCADE_pnFlashGames;
        $arcade->newscore();

        print "&opSuccess=true&endvar=1";

        $sql = "INSERT INTO " . iNA_SESSIONS . " (game_name, arcade_hash, user_id, start_time)
    			VALUES ('".$arcade->game_name."', '".$session_info['arcade_hash']."', ".$userdata['user_id'].", '".$session_info['start_time']."')";          
        $db->sql_query($sql);
      }
      else
      {
        print "&opSuccess=Missing info&endvar=1";
      }
    }
    
    break;

  case "loadGame":
//
//  Load a Saved Game (allows for continue option)
//

//				  gid int(11) NOT NULL default '0',
//				  uname varchar(40) NOT NULL default '',
//			  gameData text NOT NULL,
//				  savedate datetime NOT NULL default '0000-00-00 00:00:00'
//  It seems that the field gamedata holds what we need to send back.
//
//	        $gameData = urlencode(($data['gameData']));
//  $gameData=  "&opSuccess=true&endvar=1";	
//  urlencode($gameData);

      print "&opSuccess=true&endvar=1";  

    break;
    
  case "saveGame":
//
//  Save a part, NOT THE SCORE, But the users position etc.
//
      print "&opSuccess=true&endvar=1";  

    break;
  
  default:
    print "&opSuccess=Missing info&endvar=1";
    
    break;

}

$sql = "INSERT INTO `phpbb_ina_log` VALUES ('****** ".$mode." ******','****** pnFlashGames ******')";
$db->sql_query($sql);

?>
Return current item: MetaBB