Minecraft 1.8 Trailer

Categories: Games, Videos | Tags: , | Leave a comment

CaptainSparklez – Revenge

Categories: Videos | Tags: , | Leave a comment

The games I play is done

My Games page works, so there’s not much left to do with it. My next step is to clean up some of the code and put it up for grabs somewhere.

I ended up having a servers.php file and a gameplay.php. One for each part of my Games page, with the added feature of favorite servers. A future update might include the ability to add more servers manually, but I won’t be bothered with it at the moment. My main goal was to have the page update automatically, which it kind of does. The favorites list requires manual attention, but this is all done within the Xfire client with a mere point and two clicks.

These files are sharing my CrazeDownload class and a config file. One bonus feature is that files downloaded to cache by one of the pages can be accessed locally from the other one as well. In this particular case it can be useful for icons. More of a proof of concept really, as icons are tiny enough anyway.

Categories: Development | Tags: , , , | Leave a comment

The games I play lasted one day

I had my games list running for almost a whole day, before something went wrong. One of my arrays wasn’t detected as an array, resulting in unexpected errors. So a check was added to verify array and rather display a message instead of technical stuff. Then I started the troubleshooting process.

Upon examining the XML cache, I found it to contain a message saying my IP wasn’t allowed for the account I used. My first thought was that my script somehow triggered Xfire flood protection and the IP ended up suspended. To sort it out, I wrote an email to Xfire asking for assistance in resolving my issue. Just before I sent it, I noticed the XML system was off the grid completely moments before the entire Xfire.com website went down. Head of support over at Xfire confirms that they just suffered an outage of some kind. Because of this, I assume the XML system just hasn’t returned to a working state yet.

Confident that the issue is all on Xfire’s end, I prettied up some of my new error checks and went about with business as usual. The games page will now show a non-tech message until Xfire returns.

Categories: Development | Tags: , , , | Leave a comment

PHP Class: CrazeDownload

First posted as part of the games I play project. I don’t think there will be major changes to this file, so here it is. My Xfire page, Games,  is using this class to download the XML data and the game icons to go with it.

To use this class, include it in your script and create a new CrazeDownload instance with remote resource location as parameter. Optional parameters are minimum time before redownload and local cache filename.

object CrazeDownload(String $remote_url [,int $ttl [,String $local_filename]])

  // We need to include the file to use the features in it
  include "classes/CrazeDownload.class.php";

  // Creating a CrazeDownload will copy remote resource to local cache
  $resource = new CrazeDownload('http://example.net/feed.xml');

  // We can now ask which file to use instead of the URL
  $filename = $resource->cachefile();

The class itself:

<?php
/*
 * CrazeDownload copies remote data to local cache
 *
 * @package Craze
 * @author Geir Andre Halle
 * @version v11.8.3
 * @copyright 2009,2011 Geir Andre Halle
 * @license http://www.gnu.org/licenses/gpl.txt
 */
class CrazeDownload {
    // Initializing variables
    private $cachepath = 'cache/' ;    // Local folder for temporary storage
    private $cachefile = '' ;          // Filename variable for use later

    /*
     * @param string $url uniform resource locator/identifier
     * @param int $ttl Time-to-live, in seconds between refresh
     * @param string $filename For occasions you don't want an encoded string
     */
    function __construct($url, $ttl = 300, $filename = "") {

        // Generated filename is encoded from url to avoid slashes and colons in the filesystem
        if ("" != $filename) {
                $this->cachefile = $this->cachepath . $filename;
        } else {
                $this->cachefile = $this->cachepath . str_replace("/","-",base64_encode($url));
        }

        // Folders are not created automatically (by design choice). Tell user where to make one.
        if (!is_dir($this->cachepath)) {
            die ("Cache folder not found! Try to create manually: $this->cachepath");
        } elseif(!is_writable($this->cachepath)) {
            die ("Cache folder $this->cachepath not writable!");
        }

        // If local file does not exist or is too old, retrieve remote data.
        if ( (!file_exists($this->cachefile)) || ((time() - filemtime($this->cachefile)) > $ttl) ) {

            // File transfer
            $remoteio = curl_init() ;
            curl_setopt($remoteio, CURLOPT_URL, $url) ;
            curl_setopt($remoteio, CURLOPT_HEADER, 0) ;
            curl_setopt($remoteio, CURLOPT_RETURNTRANSFER, true) ;
            $remotecontent = curl_exec($remoteio) ;
            curl_close($remoteio) ;

            // Save resource to local file
            $cacheio = fopen($this->cachefile, 'w');
            fwrite($cacheio, $remotecontent);

            // Clean up
            fclose($cacheio);
        }
    }

    /*
     * @return string Local filename
     */
    public function cachefile() {
        return "$this->cachefile" ;
    }
}
?>
Categories: Development | Tags: , , | Leave a comment