Skip to content

Commit

Permalink
First untested shot at loading/pushing game tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jul 1, 2010
1 parent 6e1f082 commit 2f3c98b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
47 changes: 47 additions & 0 deletions makedb.php
@@ -0,0 +1,47 @@
<?php

require_once 'database.php';

// !!! FIXME: absolutely don't let this script run on a production site!

if (isset($_SERVER['REMOTE_ADDR']))
{
header('Content-type: text/plain; charset=UTF-8');
print("\n\nThis isn't allowed over the web anymore.\n\n");
exit(0);
} // if

if ((!isset($argv[1])) || ($argv[1] != '--confirm'))
{
echo "You have to run this with --confirm to do anything.\n";
echo "...BECAUSE DOING SO DESTROYS ANY EXISTING DATABASE!!!\n";
exit(0);
} // if


echo "Nuking any existing database (too late to go back, now!)...\n";
do_dbquery("drop database if exists $dbname");

echo "Creating new database from scratch...\n";
do_dbquery("create database $dbname");

close_dblink(); // force it to reselect the new database.

echo "Building gametags table...\n";
do_dbquery(
"create table gametags (" .
" id int unsigned not null auto_increment," .
" steamid bigint not null," .
" appid int unsigned not null," .
" tag varchar(64) not null," .
" index steamid_index (steamid)," .
" primary key (id)" .
" ) character set utf8"
);

echo "...all done!\n\n";

echo "If there were no errors, you're good to go.\n";
echo "\n\n\n";

?>
26 changes: 24 additions & 2 deletions steamtags.php
Expand Up @@ -33,6 +33,21 @@ function url_to_simplexml($url)
return simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA);
} // url_to_simplexml

function load_profile_game_tags($profile)
{
$gamelist = $profile['gamelist'];
$id = $profile['steamid'];
$sql = "select appid, tag from gametags where steamid=$id order by appid";
$query = do_dbquery($sql);
while ( ($row = db_fetch_array($query)) != false )
{
$game = $gamelist[$row['appid']];
if (!isset($game))
continue; // maybe it was a free weekend game they don't own now?
$game['tags'][] = $row['tag'];
} // while
} // load_profile_game_tags

function load_steam_profile($user)
{
$sxe = url_to_simplexml(steam_profile_url($user));
Expand Down Expand Up @@ -93,16 +108,23 @@ function load_steam_profile($user)

foreach ($sxe->games->game as $g)
{
$gamelist[] = array(
$gamelist[(int) $g->appID] = array(
'appid' => (int) $g->appID,
'title' => (string) $g->name,
'logourl' => (string) $g->logo,
'storeurl' => (string) $g->storeLink
'storeurl' => (string) $g->storeLink,
'tags' => array(),
);
} // foreach

$profile['gamelist'] = $gamelist;

if (!load_profile_game_tags($profile))
{
//write_error("Couldn't load user gametags from our database");
return NULL;
} // if

return $profile;
} // load_steam_profile

Expand Down

0 comments on commit 2f3c98b

Please sign in to comment.