Exemple #1
0
function ArcadeSaveScore($game, $score, $start_time, $end_time, $score_status, $tour = 0, $round = 0)
{
    global $txt, $smcFunc, $user_info, $arcSettings, $modSettings;
    //dump the cache file were away to change something..probably!!
    if (file_exists($arcSettings['cacheDirectory'] . 'arcadeinfopanel.cache')) {
        unlink($arcSettings['cacheDirectory'] . 'arcadeinfopanel.cache');
    }
    //delete temp scores for unfinished games older than 4 hours - keep the database free of carp!!
    $smcFunc['db_query']('', '
		DELETE FROM {db_prefix}arcade_v3temp
		WHERE starttime < {float:dt}', array('dt' => time() - 14400));
    //sort out some vars we need..
    $id_member = $user_info['id'];
    $id_game = $game['id'];
    $duration = $end_time - $start_time;
    $ip = $user_info['ip'];
    $ownbest = false;
    $reverse = $game['score_type'] == 0 ? '>=' : '<=';
    $score_status = $score_status ? 0 : 1;
    //if its a tournament we'll save the score there as well.
    if ($tour != 0) {
        $smcFunc['db_insert']('', '{db_prefix}arcade_tournament_scores', array('id_member' => 'int', 'id_tour' => 'int', 'id_game' => 'int', 'score' => 'float', 'time' => 'int', 'round_number' => 'int'), array($id_member, $tour, $id_game, $score, $end_time, $round), array('id_tour_score'));
    }
    // Get position
    $result = $smcFunc['db_query']('', '
		SELECT count(*) AS position
		FROM {db_prefix}arcade_scores
		WHERE score ' . $reverse . ' {float:score} AND id_game = {int:game}', array('game' => $id_game, 'score' => $score));
    $row = $smcFunc['db_fetch_row']($result);
    $smcFunc['db_free_result']($result);
    $newPosition = $row[0] + 1;
    // If theres max socres limit  then let's check whatever to save or not to save
    if ($game['maxScores'] >= 1) {
        //do we have a previous score?
        $result = $smcFunc['db_query']('', '
			SELECT count(*) AS count
			FROM {db_prefix}arcade_scores
			WHERE id_game = {int:game} AND id_member = {int:member}', array('game' => $id_game, 'member' => $id_member));
        list($my_count) = $smcFunc['db_fetch_row']($result);
        $smcFunc['db_free_result']($result);
        if ($my_count < $game['maxScores']) {
            $save = true;
        } else {
            // Clear out worst scores to maintain maximum number of scores
            // so if it has been changed it will update now
            $to_remove = $my_count - $game['maxScores'] + 1;
            $result = $smcFunc['db_query']('', '
			SELECT id_score, position, score
			FROM {db_prefix}arcade_scores
			WHERE id_game = {int:game} AND id_member = {int:member}', array('game' => $id_game, 'member' => $id_member));
            $remove_id = array();
            while ($myscore = $smcFunc['db_fetch_assoc']($result)) {
                if ($myscore['position'] > $newPosition && $to_remove > 0 || $myscore['position'] == $newPosition && $to_remove > 0 && ($score > $myscore['score'] && $game['score_type'] == 0 || $score < $myscore['score'] && $game['score_type'] == 1) || $to_remove > 1) {
                    $remove_id[] = $myscore['id_score'];
                    $to_remove--;
                }
            }
            $removed = count($remove_id);
            // Were there scores to be removed?
            if ($removed > 0) {
                $smcFunc['db_query']('', '
					DELETE FROM {db_prefix}arcade_scores
					WHERE id_score IN(' . implode(',', $remove_id) . ')', array());
            }
            // Can we add more scores?
            if ($my_count - $removed < $game['maxScores']) {
                $save = true;
            } else {
                //if we cant save because of too many scores, still update plays and duration
                $smcFunc['db_query']('', '
				UPDATE {db_prefix}arcade_personalbest
				SET
				my_plays = my_plays+1,
				playing_time = playing_time+ {int:dur}
				WHERE id_game = {int:game} AND id_member = {int:member}', array('dur' => $duration, 'game' => $id_game, 'member' => $id_member));
                $save = false;
                $error = 'arcade_scores_limit';
                //echo sprintf($txt['arcade_latest_score'],$score);
                $shout = $txt['arcade_shout_scored'] . $score . $txt['arcade_shout_on'] . '<a href="' . $game['url']['play'] . '">' . $game['name'] . '</a>';
            }
        }
    } else {
        $save = true;
    }
    // Can't save, sorry!
    if (!$save) {
        if ($arcSettings['enable_shout_box_scores'] == 1) {
            add_to_arcade_shoutbox($shout);
        }
        return array('id_score' => false, 'error' => $error);
    }
    if ($newPosition == 1) {
        $champion_from = $end_time;
    } else {
        $champion_from = 0;
    }
    //Time to insert the score if we are going to.
    $smcFunc['db_insert']('', '{db_prefix}arcade_scores', array('id_game' => 'int', 'id_member' => 'int', 'game_duration' => 'int', 'member_ip' => 'string-15', 'comment' => 'string-255', 'position' => 'int', 'score' => 'float', 'start_time' => 'int', 'end_time' => 'int', 'champion_from' => 'int', 'champion_to' => 'int', 'score_status' => 'int'), array($id_game, $id_member, $duration, $ip, '', $newPosition, $score, $start_time, $end_time, $champion_from, 0, $score_status), array('id_score'));
    $id_score = $smcFunc['db_insert_id']('{db_prefix}arcade_scores', 'id_score');
    $ownbest = false;
    ArcadeUpdatePositions($id_game, $id_score, $newPosition);
    // Update personal best and number of plays
    // Get position
    $result = $smcFunc['db_query']('', '
		SELECT score, atbscore
		FROM {db_prefix}arcade_personalbest
		WHERE id_game = {int:game} AND id_member = {int:member}', array('game' => $id_game, 'member' => $id_member));
    $request = $smcFunc['db_fetch_assoc']($result);
    $smcFunc['db_free_result']($result);
    if (!$request) {
        // No Personal best? Then we just insert this score
        $smcFunc['db_insert']('', '{db_prefix}arcade_personalbest', array('id_game' => 'int', 'id_member' => 'int', 'score' => 'float', 'atbscore' => 'float', 'my_plays' => 'int', 'playing_time' => 'int', 'time_gained' => 'int'), array($id_game, $id_member, $score, $score, '1', $duration, $end_time), array('id_best'));
        $shout = $txt['arcade_shout_pb'] . '<a href="' . $game['url']['play'] . '">' . $game['name'] . '</a> ' . $txt['arcade_b3pb_2'] . ' ' . $score;
        $ownbest = true;
    } else {
        // Update score if its better :>
        if ($game['score_type'] == 0 && $request['score'] < $score) {
            $smcFunc['db_query']('', '
				UPDATE {db_prefix}arcade_personalbest
				SET
				score = {float:score},
				my_plays = my_plays+1,
				playing_time = playing_time+{int:dur},
				time_gained = {int:time}
				WHERE id_game = {int:game} AND id_member = {int:member}', array('score' => $score, 'dur' => $duration, 'time' => $end_time, 'game' => $id_game, 'member' => $id_member));
            if ($request['atbscore'] < $score) {
                $smcFunc['db_query']('', '
				UPDATE {db_prefix}arcade_personalbest
				SET
				atbscore = {float:score}
				WHERE id_game = {int:game} AND id_member = {int:member}', array('score' => $score, 'game' => $id_game, 'member' => $id_member));
            }
            $shout = $txt['arcade_shout_pb'] . '<a href="' . $game['url']['play'] . '">' . $game['name'] . '</a> ' . $txt['arcade_b3pb_2'] . ' ' . $score;
            $ownbest = true;
        } elseif ($game['score_type'] == 1 && $request['score'] > $score) {
            $smcFunc['db_query']('', '
				UPDATE {db_prefix}arcade_personalbest
				SET
				score = {float:score},
				my_plays = my_plays+1,
				playing_time = playing_time+{int:dur},
				time_gained = {float:time}
				WHERE id_game = {int:game} AND id_member = {int:member}', array('score' => $score, 'dur' => $duration, 'time' => $end_time, 'game' => $id_game, 'member' => $id_member));
            if ($request['atbscore'] > $score) {
                $smcFunc['db_query']('', '
				UPDATE {db_prefix}arcade_personalbest
				SET
				atbscore = {float:score}
				WHERE id_game = {int:game} AND id_member = {int:member}', array('score' => $score, 'game' => $id_game, 'member' => $id_member));
            }
            $shout = $txt['arcade_shout_pb'] . '<a href="' . $game['url']['play'] . '">' . $game['name'] . '</a> ' . $txt['arcade_b3pb_2'] . ' ' . $score;
            $ownbest = true;
        } else {
            $smcFunc['db_query']('', '
				UPDATE {db_prefix}arcade_personalbest
				SET
				my_plays = my_plays+1,
				playing_time = playing_time+{int:dur}
				WHERE id_game = {int:game} AND id_member = {int:member}', array('dur' => $duration, 'game' => $id_game, 'member' => $id_member));
            $shout = $txt['arcade_shout_scored'] . $score . $txt['arcade_shout_on'] . '<a href="' . $game['url']['play'] . '">' . $game['name'] . '</a>';
        }
    }
    //now we shout if were going to..
    if ($arcSettings['enable_shout_box_best'] == 1 && $newPosition > 3) {
        add_to_arcade_shoutbox($shout);
    }
    // end Update personal best and number of plays
    //if first, second or third update shop if installed and call champs/cups update
    if ($newPosition == 1) {
        // Arcade & Shop mod - if shop mod installed then update the points
        if (isset($modSettings['shopPointsPerHighscore']) && $modSettings['shopPointsPerHighscore'] > 0) {
            $points = $modSettings['shopPointsPerHighscore'];
            // Give the user their points
            $smcFunc['db_query']('', '
			UPDATE {db_prefix}members
			SET money = money + {int:points}
			WHERE id_member = {int:id_member}
			LIMIT 1', array('points' => $points, 'id_member' => $id_member));
        }
        // Update the cups
        //If there was a champ - update their champTo time and send a PM if its turned on
        if ($game['isChampion']) {
            $smcFunc['db_query']('', '
				UPDATE {db_prefix}arcade_scores
				SET
				champion_to = {int:endtime}
				WHERE id_score = {int:game}', array('endtime' => $end_time, 'game' => $game['champion']['score_id']));
            if (isset($arcSettings['arcadePMsystem']) && $arcSettings['arcadePMsystem'] == 1) {
                arcadesendPM('new_champion', $game['champion']['member_id'], $game, array('score' => $score, 'time' => time()));
            }
        }
        update_champ_cups($id_game);
        $shout = $txt['arcade_champions_cho'] . ' <a href="' . $game['url']['play'] . '">' . $game['name'] . '</a> ' . $txt['arcade_b3pb_2'] . ' ' . $score;
    }
    if ($newPosition == 2) {
        //if shop mod installed then give half points for silver
        if (isset($modSettings['shopPointsPerHighscore']) && $modSettings['shopPointsPerHighscore'] > 0) {
            $points = $modSettings['shopPointsPerHighscore'] / 2;
            // Give the user their points
            $smcFunc['db_query']('', '
			UPDATE {db_prefix}members
			SET money = money + {int:points}
			WHERE id_member = {int:id_member}
			LIMIT 1', array('points' => $points, 'id_member' => $id_member));
        }
        // Update the cups
        update_champ_cups($id_game);
        $shout = $txt['arcade_second'] . $txt['arcade_shout_on'] . '<a href="' . $game['url']['play'] . '">' . $game['name'] . '</a> with ' . $score;
    }
    if ($newPosition == 3) {
        //if shop mod installed then give quarter points for bronze
        if (isset($modSettings['shopPointsPerHighscore']) && $modSettings['shopPointsPerHighscore'] > 0) {
            $points = $modSettings['shopPointsPerHighscore'] / 4;
            // Give the user their points
            $smcFunc['db_query']('', '
			UPDATE {db_prefix}members
			SET money = money + {int:points}
			WHERE id_member = {int:id_member}
			LIMIT 1', array('points' => $points, 'id_member' => $id_member));
        }
        // Update the cups
        update_champ_cups($id_game);
        $shout = $txt['arcade_third'] . $txt['arcade_shout_on'] . '<a href="' . $game['url']['play'] . '">' . $game['name'] . '</a> with ' . $score;
    }
    //end if first, second or third update shop if installed and call cups update
    //now we shout if were going to..
    if ($arcSettings['enable_shout_box_champ'] == 1) {
        add_to_arcade_shoutbox($shout);
    }
    // Where should we start?
    $scoresPerPage = isset($arcSettings['scoresPerPage']) ? $arcSettings['scoresPerPage'] : 50;
    $start = floor($newPosition / $scoresPerPage) * $scoresPerPage;
    // Return array with id_score and later maybe something more
    return array('id_score' => $id_score, 'position' => $newPosition, 'new_champion' => $newPosition == 1 ? true : false, 'start' => $start, 'ownbest' => $ownbest);
}
Exemple #2
0
function ArcadeShout()
{
    global $smcFunc, $txt, $arcSettings, $user_info;
    if (isset($_REQUEST['del'])) {
        // Only allow admins to delete shouts
        if (allowedTo('arcade_admin')) {
            $id = (int) $_REQUEST['del'];
            $smcFunc['db_query']('', '
				DELETE FROM {db_prefix}arcade_shouts
				WHERE id_shout = {int:ids}', array('ids' => $id));
            if (file_exists($arcSettings['cacheDirectory'] . 'shout.cache')) {
                unlink($arcSettings['cacheDirectory'] . 'shout.cache');
            }
        }
    } elseif (!$user_info['is_guest']) {
        $shout = $txt['arcade_shouted'] . $smcFunc['htmlspecialchars']($_REQUEST['the_shout'], ENT_QUOTES);
        add_to_arcade_shoutbox($shout);
    }
    redirectexit('action=arcade');
}