<commit_before><?php
require_once("module.php");
require_once("media.php");
require_once("quests.php");

class Games extends Module
{	
	
	/**
     * Fetch all games
     * @returns Object Recordset for each Game.
     */
	public function getGames()
	{
	    $query = "SELECT * FROM games";
		$rs = @mysql_query($query);
		if (mysql_error())  return new returnData(3, NULL, 'SQL error');
		return new returnData(0, $rs, NULL);		
	}

	/**
     * Fetch one game
     * @returns Object Recordset for each Game.
     */
	public function getGame($intGameID)
	{
	    $query = "SELECT * FROM games WHERE game_id = {$intGameID} LIMIT 1";
		$rs = @mysql_query($query);
		if (mysql_error())  return new returnData(3, NULL, 'SQL error');

		$game = @mysql_fetch_object($rs);
		if (!$game) return new returnData(2, NULL, "invalid game id");
		
		return new returnData(0, $game);

	}

	/**
     * Fetch all game info needed for the game list
     * @param integer The player identifier
     * @param float The player's current latitude
     * @param float The player's current longitude
     * @param float The max distance in Meters  
     * @param bool Include locational or non-locational games  
     * @param bool Include Games in Development 
     * @return returnData
     * @returns a returnData object containing an array of games
     * @see returnData
     */

	public function getGamesForPlayerAtLocation($playerId, $latitude, $longitude, $maxDistance=99999999, $locational, $includeGamesinDevelopment)
	{
		if ($includeGamesinDevelopment) $query = "SELECT game_id FROM games WHERE is_locational = $locational";
        else $query = "SELECT game_id FROM games WHERE is_locational = $locational AND ready_for_public = TRUE ";
        
		$gamesRs = @mysql_query($query);
		NetDebug::trace(mysql_error());
        
		$games = array();
		
		while ($game = @mysql_fetch_object($gamesRs)) {
			$gameObj = new stdClass;
			$gameObj = Games::getFullGameObject($game->game_id, $playerId, 1, $maxDistance, $latitude, $longitude);
			if($gameObj != NULL){//->distance <= $maxDistance) {
				NetDebug::trace("Select");
				$games[] = $gameObj;
			}
			else NetDebug::trace("Skip");
		}
		return new returnData(0, $games, NULL);
		
    }		
    
    
	/**
	 * Returns:
	 * A single game in the same format as though an array of games was being searched
	 * @param integer The Game to get info for
	 * @param integer The Id of the player requesting the info
	 * @param boolean If true, get all information relating to location. Otherwise, don't bother- saves time.
	 * @param integer Distance at which games further than should be ignored. Not necessary if 'boolGetLocationalInfo' = 0
	 * @param float Not necessary if 'boolGetLocationalInfo' = 0
	 * @param float Not necessary if 'boolGetLocationalInfo' = 0
	 * @returns a whole bunch of stuff. Returns NULL if $boolGetLocationalInfo is set (1) and game is at a distance further than $intSkipAtDistance.
	 */
    
	public function getOneGame($intGameId, $intPlayerId, $boolGetLocationalInfo = 0, $intSkipAtDistance = 99999999, $latitude = 0, $longitude = 0)
	{
		$games = array();
		
        $gameObj = new stdClass;
        $gameObj = Games::getFullGameObject($intGameId, $intPlayerId, $boolGetLocationalInfo, $intSkipAtDistance, $latitude, $longitude);
        if($gameObj != NULL){//->distance <= $maxDistance) {
            NetDebug::trace("Select");
            $games[] = $gameObj;
        }
    
        return new returnData(0, $games, NULL);
		
    }	
    
    
	
	/**
	 * Returns:
	 * a 'game' object consisting of Game's name, id, description, editors, location(lat/lon), distance, is_locational,
	 * ready_for_public, comments, rating, allow_player_created_locations, delete_player_locations_on_reset, numCompletedQuests, 
	 * totalQuests, on_launch_node_id, game_complete_node_id, game_icon_media_id, icon_media_id, icon_media_url, numPlayers, pc_media_id,
	 * lastUpdated, prefix 
	 * @param integer The Game to get info for
	 * @param integer The Id of the player requesting the info
	 * @param boolean If true, get all information relating to location. Otherwise, don't bother- saves time.
	 * @param integer Distance at which games further than should be ignored. Not necessary if 'boolGetLocationalInfo' = 0
	 * @param float Not necessary if 'boolGetLocationalInfo' = 0
	 * @param float Not necessary if 'boolGetLocationalInfo' = 0
	 * @returns a whole bunch of stuff. Returns NULL if $boolGetLocationalInfo is set (1) and game is at a distance further than $intSkipAtDistance.
	 */
	
	public function getFullGameObject($intGameId, $intPlayerId, $boolGetLocationalInfo = 0, $intSkipAtDistance = 99999999, $latitude = 0, $longitude = 0){
		$query = "SELECT * FROM games WHERE game_id = '{$intGameId}'";
		$result = mysql_query($query);
		$gameObj = mysql_fetch_object($result);
		
		//Get Locational Stuff
		if($boolGetLocationalInfo){
			$nearestLocation = Games::getNearestLocationOfGameToUser($latitude, $longitude, $intGameId);
			$gameObj->latitude = $nearestLocation->latitude;
			$gameObj->longitude = $nearestLocation->longitude;
			$gameObj->distance = $nearestLocation->distance;
			if($gameObj->distance == NULL || $gameObj->distance > $intSkipAtDistance) return NULL;
		}<commit_msg>nonlocational games needed at least one location to work previously. that is no longer the case.<commit_after><?php
require_once("module.php");
require_once("media.php");
require_once("quests.php");

class Games extends Module
{	
	
	/**
     * Fetch all games
     * @returns Object Recordset for each Game.
     */
	public function getGames()
	{
	    $query = "SELECT * FROM games";
		$rs = @mysql_query($query);
		if (mysql_error())  return new returnData(3, NULL, 'SQL error');
		return new returnData(0, $rs, NULL);		
	}

	/**
     * Fetch one game
     * @returns Object Recordset for each Game.
     */
	public function getGame($intGameID)
	{
	    $query = "SELECT * FROM games WHERE game_id = {$intGameID} LIMIT 1";
		$rs = @mysql_query($query);
		if (mysql_error())  return new returnData(3, NULL, 'SQL error');

		$game = @mysql_fetch_object($rs);
		if (!$game) return new returnData(2, NULL, "invalid game id");
		
		return new returnData(0, $game);

	}

	/**
     * Fetch all game info needed for the game list
     * @param integer The player identifier
     * @param float The player's current latitude
     * @param float The player's current longitude
     * @param float The max distance in Meters  
     * @param bool Include locational or non-locational games  
     * @param bool Include Games in Development 
     * @return returnData
     * @returns a returnData object containing an array of games
     * @see returnData
     */

	public function getGamesForPlayerAtLocation($playerId, $latitude, $longitude, $maxDistance=99999999, $locational, $includeGamesinDevelopment)
	{
		if ($includeGamesinDevelopment) $query = "SELECT game_id FROM games WHERE is_locational = '{$locational}'";
        else $query = "SELECT game_id FROM games WHERE is_locational = '{$locational}' AND ready_for_public = TRUE ";
        
		$gamesRs = @mysql_query($query);
		NetDebug::trace(mysql_error());
        
		$games = array();
		
		while ($game = @mysql_fetch_object($gamesRs)) {
			$gameObj = new stdClass;
			$gameObj = Games::getFullGameObject($game->game_id, $playerId, 1, $maxDistance, $latitude, $longitude);
			if($gameObj != NULL){//->distance <= $maxDistance) {
				NetDebug::trace("Select");
				$games[] = $gameObj;
			}
			else NetDebug::trace("Skip");
		}
		return new returnData(0, $games, NULL);
		
    }		
    
    
	/**
	 * Returns:
	 * A single game in the same format as though an array of games was being searched
	 * @param integer The Game to get info for
	 * @param integer The Id of the player requesting the info
	 * @param boolean If true, get all information relating to location. Otherwise, don't bother- saves time.
	 * @param integer Distance at which games further than should be ignored. Not necessary if 'boolGetLocationalInfo' = 0
	 * @param float Not necessary if 'boolGetLocationalInfo' = 0
	 * @param float Not necessary if 'boolGetLocationalInfo' = 0
	 * @returns a whole bunch of stuff. Returns NULL if $boolGetLocationalInfo is set (1) and game is at a distance further than $intSkipAtDistance.
	 */
    
	public function getOneGame($intGameId, $intPlayerId, $boolGetLocationalInfo = 0, $intSkipAtDistance = 99999999, $latitude = 0, $longitude = 0)
	{
		$games = array();
		
        $gameObj = new stdClass;
        $gameObj = Games::getFullGameObject($intGameId, $intPlayerId, $boolGetLocationalInfo, $intSkipAtDistance, $latitude, $longitude);
        if($gameObj != NULL){//->distance <= $maxDistance) {
            NetDebug::trace("Select");
            $games[] = $gameObj;
        }
    
        return new returnData(0, $games, NULL);
		
    }	
    
    
	
	/**
	 * Returns:
	 * a 'game' object consisting of Game's name, id, description, editors, location(lat/lon), distance, is_locational,
	 * ready_for_public, comments, rating, allow_player_created_locations, delete_player_locations_on_reset, numCompletedQuests, 
	 * totalQuests, on_launch_node_id, game_complete_node_id, game_icon_media_id, icon_media_id, icon_media_url, numPlayers, pc_media_id,
	 * lastUpdated, prefix 
	 * @param integer The Game to get info for
	 * @param integer The Id of the player requesting the info
	 * @param boolean If true, get all information relating to location. Otherwise, don't bother- saves time.
	 * @param integer Distance at which games further than should be ignored. Not necessary if 'boolGetLocationalInfo' = 0
	 * @param float Not necessary if 'boolGetLocationalInfo' = 0
	 * @param float Not necessary if 'boolGetLocationalInfo' = 0
	 * @returns a whole bunch of stuff. Returns NULL if $boolGetLocationalInfo is set (1) and game is at a distance further than $intSkipAtDistance.
	 */
	
	public function getFullGameObject($intGameId, $intPlayerId, $boolGetLocationalInfo = 0, $intSkipAtDistance = 99999999, $latitude = 0, $longitude = 0){
		$query = "SELECT * FROM games WHERE game_id = '{$intGameId}'";
		$result = mysql_query($query);
		$gameObj = mysql_fetch_object($result);
		
		//Get Locational Stuff
		if($boolGetLocationalInfo){
            if($gameObj->locational == true){
                $nearestLocation = Games::getNearestLocationOfGameToUser($latitude, $longitude, $intGameId);
                $gameObj->latitude = $nearestLocation->latitude;
                $gameObj->longitude = $nearestLocation->longitude;
                $gameObj->distance = $nearestLocation->distance;
                if($gameObj->distance == NULL || $gameObj->distance > $intSkipAtDistance) return NULL;
            }
            else{
                $gameObj->latitude = 0;
                $gameObj->longitude = 0;
                $gameObj->distance = 0;
            }
		}
{'fraction_non_alphanumeric': 0.11103949912531075, 'fraction_numerical': 0.008931037657674248, 'mean_word_length': 3.6379163108454313, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3280121', 'n_tokens_mistral': 3502, 'n_tokens_neox': 3163, 'n_words': 1024}