Ich habe mal vor laaaaaanger Zeit
eine Arcade Mod für das Forum PUNBB geshrieben. Die Ergebnisse der Spiele wurden in einen Datenbank geschrieben und per Highscoretabelle ausgegeben.
Spiele bekomme ich eingebunden in ILCH. Wenn man einen Spielstand speichern möchte wird eine Datei NEWSCORE.PHP aufgerufen die die HTTP_POST_VARS ausliest und in die DB schreiben sollte, was natürlich mit der original PUNBB Datei nicht geht.
Hier der Inhalt newscore.php:
<?php
define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';
if ($pun_user['g_id'] == PUN_GUEST)
error($lang_common['No permission']);
// Recover the game name and the score
$game_name = $HTTP_POST_VARS['game_name'];
// str_replace strips all spaces present in the score string
$score = str_replace(" ", "", $HTTP_POST_VARS['score']);
$topscore = 0;
$now = time();
// This is a fix for var "score" wich is send as "Score" and not as "score" like in game "Easter Egg Catch"
if(empty($score))
{
$score = $HTTP_POST_VARS['Score'];
}
if(!empty($game_name) && !empty($score))
{
// Find Topscore
$sql = 'SELECT rank_topscore, rank_score FROM '.$db->prefix.'arcade_ranking, '.$db->prefix.'users WHERE rank_player = '.$db->prefix.'users.id AND rank_game = "'.$game_name.'" ORDER BY rank_score DESC LIMIT 1';
$query = $db->query($sql) or error("Impossible to select topscore.", __FILE__, __LINE__, $db->error());
$line = $db->fetch_assoc($query);
if($line['rank_topscore'] = 1 && $line['rank_score'] < $score)
{
$sql = 'UPDATE '.$db->prefix.'arcade_ranking SET rank_topscore = '.$topscore.' WHERE rank_game = "'.$game_name.'"';
$query = $db->query($sql) or error("Impossible to update the topscore", __FILE__, __LINE__, $db->error());
$topscore = 1;
}
elseif($line['rank_topscore'] >= 0 && $line['rank_score'] <= $score)
{
$topscore = 1;
}
else
{
$topscore = 0;
}
$sql = 'SELECT * FROM '.$db->prefix.'arcade_ranking WHERE rank_player = '.$pun_user['id'].' AND rank_game = "'.$game_name.'"';
$query = $db->query($sql) or error("Impossible to select the user and game", __FILE__, __LINE__, $db->error());
if(mysql_num_rows($query) > 0)
{
$line = $db->fetch_assoc($query);
if($line['rank_score'] <= $score)
{
// Update new highscore
$sql = 'UPDATE '.$db->prefix.'arcade_ranking SET rank_score = '.$score.', rank_date = '.$now.' , rank_topscore = '.$topscore.' WHERE rank_player = '.$pun_user['id'].' AND rank_game = "'.$game_name.'"';
$query = $db->query($sql) or error("Impossible to update new highscore", __FILE__, __LINE__, $db->error());
$sql = 'SELECT game_id FROM '.$db->prefix.'arcade_games WHERE game_filename = "'.$game_name.'"';
$query = $db->query($sql) or error("Impossible to select the game", __FILE__, __LINE__, $db->error());
$gameid = $db->fetch_assoc($query);
echo '<script type="text/javascript">window.location= "arcade_ranking.php?id='.$gameid['game_id'].'"</script>';
}
else
{
// No new highscore
$sql = 'SELECT game_id FROM '.$db->prefix.'arcade_games WHERE game_filename = "'.$game_name.'"';
$query = $db->query($sql) or error("Impossible to select the game", __FILE__, __LINE__, $db->error());
$gameid = $db->fetch_assoc($query);
echo '<script type="text/javascript">window.location= "arcade_play.php?id='.$gameid['game_id'].'"</script>';
}
}
else
{
// Is there a score?
$sql = 'SELECT rank_score, rank_topscore FROM '.$db->prefix.'arcade_ranking WHERE rank_game = "'.$game_name.'" ORDER BY rank_score DESC, rank_topscore DESC';
$query = $db->query($sql) or error("Impossible to select the topscore", __FILE__, __LINE__, $db->error());
$line = $db->fetch_assoc($query);
if($line['rank_score'] <= 0 && $line['rank_topscore'] <= 0)
{
$topscore = 1;
}
// Add new Highscore
$sql = 'INSERT INTO '.$db->prefix.'arcade_ranking (rank_game, rank_player, rank_score, rank_topscore, rank_date) VALUES ("'.$game_name.'", '.$pun_user['id'].', '.$score.', '.$topscore.', '.$now.')';
$query = $db->query($sql) or error("Impossible to insert the new score", __FILE__, __LINE__, $db->error());
$sql = 'SELECT game_id FROM '.$db->prefix.'arcade_games WHERE game_filename = "'.$game_name.'"';
$query = $db->query($sql) or error("Impossible to select the game", __FILE__, __LINE__, $db->error());
$gameid = $db->fetch_assoc($query);
echo '<script type="text/javascript">window.location= "arcade_ranking.php?id='.$gameid['game_id'].'"</script>';
}
}
else
{
error($lang_common['No permission']);
}
?>
Leider bin ich nicht mehr so fit in PHP um die PUNBB Scripte nach ILCH zu konvertieren. Würde mich über Hilfe von Euch freuen ...