Code: Alles auswählen
<?php
/***************************************************************************
*
* newscore.php
* ------------------
* begin : Thursday, August 1, 2002
* copyright : (c)2002 iNetAngel
* email : support@inetangel.com
*
* $Id: newscore.php, v1.0.0 2003/12/18 12:59:59 Napoleon Exp $
*
***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************
*
* This is a MOD for phpbb v2+. The phpbb group has all rights to the
* phpbb source. They can be contacted at :
*
* I-Net : www.phpbb.com
* E-Mail: support@phpbb.com
*
* If you have made any changes then please notify me so they can be added
* if they are improvments. You of course will get the credit for helping
* out. If you would like to see other MODs that I have made then check
* out my forum at : www.iNetAngel.com and click on the community button.
*
***************************************************************************/
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_activity.' . $phpEx);
if($board_config['use_rewards_mod'])
{
if($board_config['use_point_system'])
{
include($phpbb_root_path . 'includes/functions_points.'.$phpEx);
}
if($board_config['use_cash_system'] || $board_config['use_allowance_system'])
{
include($phpbb_root_path . 'includes/rewards_api.'.$phpEx);
}
}
// Start session management
$userdata = session_pagestart($user_ip, PAGE_PLAYING_SCORE);
init_userprefs($userdata);
// End session management
if (isset($HTTP_GET_VARS['mode']) || isset($HTTP_POST_VARS['mode']))
{
$mode = (isset($HTTP_GET_VARS['mode'])) ? $HTTP_GET_VARS['mode'] : $HTTP_POST_VARS['mode'];
}
else
{
if( isset($HTTP_POST_VARS['check_score']) )
{
$mode = "check_score";
}
else if( isset($HTTP_POST_VARS['highscore']) )
{
$mode = "highscore";
}
else
{
$mode = "";
}
}
if( $mode != "" )
{
if (($mode == "check_score") && ($userdata['user_session_page'] == PAGE_PLAYING_GAMES))
{
$name = (!empty($HTTP_POST_VARS['name'])) ? $HTTP_POST_VARS['name'] : $HTTP_GET_VARS['name'];
$game_name = (!empty($HTTP_POST_VARS['game_name'])) ? $HTTP_POST_VARS['game_name'] : $HTTP_GET_VARS['game_name'];
$score = (!empty($HTTP_POST_VARS['score'])) ? $HTTP_POST_VARS['score'] : $HTTP_GET_VARS['score'];
$gen_simple_header = TRUE;
if ($score)
{
if (empty($name))
{
$name = $userdata['username'];
}
$sql = "SELECT * FROM " . iNA_GAMES . "
WHERE game_name = '" . $game_name . "'";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, $lang['no_game_data'], "", __LINE__, __FILE__, $sql);
}
$game_info = $db->sql_fetchrow($result);
// Check for Highscore
$sql = "SELECT * FROM " . iNA_SCORES . "
WHERE game_name = '" . $game_name . "'
ORDER BY score DESC";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, $lang['no_score_data'], "", __LINE__, __FILE__, $sql);
}
$score_info = $db->sql_fetchrow($result);
$bonus = 0;
if ($score > $score_info['score'])
{
$bonus = $game_info['game_bonus'];
}
//
// BEGIN Highscore - Mod
// by ChriChra
// Check if an Score exist
if ($game_info['reverse_list']) {
$list_type = 'ASC';
} else {
$list_type = 'DESC';
}
$sql = "SELECT highscore_id, highscore_score FROM " . iNA_HIGHSCORES . "
WHERE highscore_year = '".date(Y)."'
AND highscore_mon = '".date(m)."'
AND highscore_game = '" . $game_name . "'
ORDER BY highscore_score ".$list_type."
LIMIT 1";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, $lang['no_score_data'], "", __LINE__, __FILE__, $sql);
}
$highscore = $db->sql_fetchrow($result);
if ($highscore['highscore_score'] == "") {
// Add to Highscores list
$sql = "INSERT INTO " . iNA_HIGHSCORES . " (highscore_year, highscore_mon, highscore_game, highscore_player, highscore_score, highscore_date)
VALUES ('".date(Y)."', '".date(m)."', '$game_name', '$name', '$score', '" . time() . "')";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, $lang['no_score_insert'], "", __LINE__, __FILE__, $sql);
}
$new_highscore = "1";
$message_highscore = $lang['highscore_new_mon_score'];
} else {
// Update Highscores list
if ((($score > $highscore['highscore_score']) && (!$game_info['reverse_list'])) || (($score < $highscore['highscore_score']) && ($game_info['reverse_list'])))
{
$sql = "UPDATE " . iNA_HIGHSCORES . "
SET highscore_player = '$name', highscore_score = '$score', highscore_date = '" . time() . "'
WHERE highscore_id = ".$highscore['highscore_id'];
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, $lang['no_score_update'], "", __LINE__, __FILE__, $sql);
}
$new_highscore = "1";
$message_highscore = $lang['highscore_new_mon_score'];
} else {
$message_highscore = $lang['highscore_no_new_mon_score'];
}
}
$template->assign_vars(array('HIGHSCORSAVED' => $message_highscore));
//
// END Highscore - Mod
// by ChriChra
//
// BEGIN Score - Update - Mod
// by ChriChra
// Original:
/*
// Add to scores list
$sql = "INSERT INTO " . iNA_SCORES . " (game_name, player, score, date)
VALUES ('$game_name', '$name', '$score', '" . time() . "')";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, $lang['no_score_insert'], "", __LINE__, __FILE__, $sql);
}
//Update Users Money
$user_id = $userdata['user_id'];
if($board_config['use_point_system'] && $board_config['use_rewards_mod'] && ($game_info['game_reward'] > 0))
{
$reward = (intval($score) / intval($game_info['game_reward']) + $bonus);
add_points($user_id,$reward);
}
if(($board_config['use_cash_system'] || $board_config['use_allowance_system']) && $board_config['use_rewards_mod'] && ($game_info['game_reward'] > 0))
{
$reward = (intval($score) / intval($game_info['game_reward']) + $bonus);
add_reward($user_id,$reward);
}
$template->set_filenames(array('body' => 'saved_body.tpl'));
$template->assign_vars(array('SAVED' => $lang['game_score_saved'],
'GAME_NAME' => $game_name,
'U_CLOSE' => "javascript:parent.window.close();",
'L_CLOSE' => $lang['game_score_close'])
);
*/
// New:
// Check if an Score exist
if ($game_info['reverse_list']) {
$list_type = 'ASC';
} else {
$list_type = 'DESC';
}
$sql = "SELECT * FROM " . iNA_SCORES . "
WHERE game_name = '" . $game_name . "'
AND player = '".$name."'
ORDER BY score ".$list_type."
LIMIT 1";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, $lang['no_score_data'], "", __LINE__, __FILE__, $sql);
}
$personal_highscore = $db->sql_fetchrow($result);
if ($personal_highscore['score'] == "") {
// Add to scores list
$sql = "INSERT INTO " . iNA_SCORES . " (game_name, player, score, date)
VALUES ('$game_name', '$name', '$score', '" . time() . "')";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, $lang['no_score_insert'], "", __LINE__, __FILE__, $sql);
}
$template->set_filenames(array('body' => 'saved_body.tpl'));
$template->assign_vars(array('SAVED' => $lang['game_score_saved'],
'GAME_NAME' => $game_name,
'U_CLOSE' => "javascript:parent.window.close();",
'L_CLOSE' => $lang['game_score_close'])
);
} else {
// Update scores list
if ((($score > $personal_highscore['score']) && (!$game_info['reverse_list'])) || (($score < $personal_highscore['score']) && ($game_info['reverse_list'])))
{
$sql = "UPDATE " . iNA_SCORES . "
SET score = '$score', date = '" . time() . "'
WHERE score_id = ".$personal_highscore['score_id'];
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, $lang['no_score_update'], "", __LINE__, __FILE__, $sql);
}
$template->set_filenames(array('body' => 'saved_body.tpl'));
$template->assign_vars(array('SAVED' => $lang['game_score_updated'],
'GAME_NAME' => $game_name,
'U_CLOSE' => "javascript:parent.window.close();",
'L_CLOSE' => $lang['game_score_close'])
);
} else {
$template->set_filenames(array('body' => 'saved_body.tpl'));
$template->assign_vars(array('SAVED' => $lang['game_score_not_updated'],
'GAME_NAME' => $game_name,
'U_CLOSE' => "javascript:parent.window.close();",
'L_CLOSE' => $lang['game_score_close'])
);
}
}
//Update Users Money
$user_id = $userdata['user_id'];
if($board_config['use_point_system'] && $board_config['use_rewards_mod'] && ($game_info['game_reward'] > 0))
{
$reward = (intval($score) / intval($game_info['game_reward']) + $bonus);
add_points($user_id,$reward);
}
if(($board_config['use_cash_system'] || $board_config['use_allowance_system']) && $board_config['use_rewards_mod'] && ($game_info['game_reward'] > 0))
{
$reward = (intval($score) / intval($game_info['game_reward']) + $bonus);
add_reward($user_id,$reward);
}
//
// END Score - Update - Mod
// by ChriChra
}
else
{
$template->set_filenames(array('body' => 'saved_body.tpl'));
$template->assign_vars(array('SAVED' => $lang['game_no_score_saved'],
'GAME_NAME' => $game_name,
'U_CLOSE' => "javascript:parent.window.close();",
'L_CLOSE' => $lang['game_score_close'])
);
}
// This may have been set by game.php so if it is, then we'll
// put it back the way it was.
if ($userdata['user_session_page'] == PAGE_PLAYING_GAMES)
{
$sql = "UPDATE " . USERS_TABLE . "
SET user_session_page = '" . PAGE_ACTIVITY . "'
WHERE user_id = " . $userdata['user_id'];
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, $lang['no_user_update'], '', __LINE__, __FILE__, $sql);
}
}
}
else if (($mode == "check_score") && ($userdata['user_session_page'] != PAGE_PLAYING_GAMES) && ($board_config['warn_cheater'] || $board_config['report_cheater']))
{
$name = (!empty($HTTP_POST_VARS['name'])) ? $HTTP_POST_VARS['name'] : $HTTP_GET_VARS['name'];
if (empty($name))
{
$name = $userdata['username'];
}
$game_name = (!empty($HTTP_POST_VARS['game_name'])) ? $HTTP_POST_VARS['game_name'] : $HTTP_GET_VARS['game_name'];
$ip_num = gethostbyname($_SERVER['REMOTE_ADDR']);
$ip_nam = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$ip_line = " [ NAME : " . $ip_nam . " ]--[ IP# : " . $ip_num . " ]--[USERNAME : " . $name . "][GAME : " . $game_name . "]";
if ($board_config['report_cheater'])
{
mail($board_config['board_email'], $game_name, $ip_line);
}
if ($board_config['warn_cheater'])
{
die($lang['admin_cheater_warning']);
} else {
echo '<html>
<HEAD>
<TITLE></TITLE>
</HEAD>
<body>
<script language="JavaScript">
<!--
window.close();
-->
</script>
</body>
</html>';
}
}
else if ($mode == "highscore")
{
$game_name = (!empty($HTTP_POST_VARS['game_name'])) ? $HTTP_POST_VARS['game_name'] : $HTTP_GET_VARS['game_name'];
$sql = "SELECT * FROM " . iNA_GAMES . "
WHERE game_name = '" . $game_name . "'";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, $lang['no_game_data'], "", __LINE__, __FILE__, $sql);
}
$game_info = $db->sql_fetchrow($result);
$highscore_limit = $game_info['highscore_limit'];
$template->set_filenames(array('body' => 'activity_scores.tpl') );
$template->assign_vars(array("TITLE" => $game_name,
"L_HIGHSCORE" => $lang['game_highscores'],
"L_SCORE" => $lang['game_score'],
"L_PLAYED" => $lang['game_played'],
"DASH" => $lang['game_dash']));
if ($game_info['reverse_list'])
{
$list_type = 'ASC';
}
else
{
$list_type = 'DESC';
}
if (!empty($highscore_limit))
{
$sql = "SELECT * FROM " . iNA_SCORES . "
WHERE game_name = '" . $game_name . "'
ORDER BY score $list_type LIMIT 0,$highscore_limit";
}
else
{
$sql = "SELECT * FROM " . iNA_SCORES . "
WHERE game_name = '" . $game_name . "'
ORDER BY score $list_type";
}
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, $lang['no_score_data'], "", __LINE__, __FILE__, $sql);
}
if ($row = $db->sql_fetchrow($result))
{
$i = 1;
do
{
$row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
$row_class = ( !($i % 2) ) ? "row1" : "row2";
$template->assign_block_vars("scores", array("ROW_COLOR" => $lang['game_number'] . $row_color,
"ROW_CLASS" => $row_class,
"POS" => $i,
"NAME" => $row['player'],
"SCORE" => $row['score'],
"DATE" => create_date($board_config['default_dateformat'], $row['date'], $board_config['board_timezone']))
);
$i++;
}
while ($row = $db->sql_fetchrow($result));
}
}
}
// This may have been set by game.php so if it is, then we'll
// put it back the way it was.
if ($userdata['user_session_page'] == PAGE_PLAYING_GAMES)
{
$sql = "UPDATE " . USERS_TABLE . "
SET user_session_page = '" . PAGE_ACTIVITY . "'
WHERE user_id = " . $userdata['user_id'];
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, $lang['no_user_update'], '', __LINE__, __FILE__, $sql);
}
}
// Generate page
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
$template->pparse('body');
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
?>