Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (!defined('IN_PHPBB')) {
- exit;
- }
- class score {
- var $user_id;
- var $games_sql;
- var $games_nbr;
- function score($user_id = 0, $games = array()) {
- $this->games_sql = array();
- $this->games_sql[0] = array();
- $this->games_sql[1] = array();
- if ($user_id < 0) {
- $redirect = append_sid("{$phpbb_root_path}arcadeoa.$phpEx");
- $l_redirect = $user->lang['RETURN_ARCADEOA'];
- meta_refresh(5, $redirect);
- trigger_error($user->lang['NO_USER'] . '<br /><br />' . sprintf($l_redirect, '<a href="' . $redirect . '">', '</a>', E_USER_ERROR));
- }
- $this->user_id = (int)$user_id;
- $this->games_nbr = sizeof($games);
- for ($i = 0; $i < $this->games_nbr; $i++) {
- if (!(int)$games[$i]['best']) {
- $this->games_sql[0][] = (int)$games[$i]['id'];
- } else {
- $this->games_sql[1][] = (int)$games[$i]['id'];
- }
- }
- }
- //DoneArk Invaders
- function is_valid_score($game_score, $variable_name, $game_ssid, $game_id) {
- global $db, $phpbb_root_path, $phpEx, $user;
- if (!is_numeric($game_score)) {
- $redirect = append_sid("{$phpbb_root_path}arcadeoa.$phpEx");
- $l_redirect = $user->lang['RETURN_ARCADEOA'];
- meta_refresh(5, $redirect);
- trigger_error($user->lang['ERROR_SAVE_GAME'] . '<br /><br />' . sprintf($l_redirect, '<a href="arcadeoa.php?mode=game&id=' . $game_id . '">', '</a>', E_USER_ERROR));
- }
- if ($game_score < 1) {
- $redirect = append_sid("{$phpbb_root_path}arcadeoa.$phpEx");
- $l_redirect = $user->lang['RETURN_ARCADEOA'];
- meta_refresh(5, $redirect);
- trigger_error('your score is zero, please replay<br /><br />' . sprintf($l_redirect, '<a href="arcadeoa.php?mode=game&id=' . $game_id . '">', '</a>', E_USER_ERROR));
- }
- $game_score = (double)$game_score;
- $check_session = true;
- if (($game_ssid != $user->data['session_id']) && ($check_session)) {
- $redirect = append_sid("{$phpbb_root_path}arcadeoa.$phpEx");
- $l_redirect = $user->lang['RETURN_ARCADEOA'];
- meta_refresh(5, $redirect);
- trigger_error(($user->lang['ERROR_SAVE_GAME']) . '<br /><br />' . sprintf($l_redirect, '<a href="arcadeoa.php?mode=game&id=' . $game_id . '">', '</a>', E_USER_ERROR));
- }
- $sql_array = array(
- 'SELECT' => 's.session_id, s.session_forum_id, s.start_time',
- 'FROM' => array(
- SESSIONS_ARCADE_TABLE => 's'
- ),
- 'WHERE' => 'game_id = ' . $game_id . ' AND gamer_id = ' . (int)$user->data['user_id']
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- $sess = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
- if (!$sess) {
- $redirect = append_sid("{$phpbb_root_path}arcadeoa.$phpEx");
- $l_redirect = $user->lang['RETURN_ARCADEOA'];
- meta_refresh(5, $redirect);
- trigger_error($user->lang['NO_SESSION'] . '<br /><br />' . sprintf($l_redirect, '<a href="arcadeoa.php?mode=game&id=' . $game_id . '">', '</a>', E_USER_ERROR));
- }
- if ((md5($user->ip) != $sess['session_id']) || ($user->data['session_id'] != $sess['session_forum_id'])) {
- $redirect = append_sid("{$phpbb_root_path}arcadeoa.$phpEx");
- $l_redirect = $user->lang['RETURN_ARCADEOA'];
- meta_refresh(5, $redirect);
- trigger_error($user->lang['DIFFERENT_SESSION'] . '<br /><br />' . sprintf($l_redirect, '<a href="arcadeoa.php?mode=game&id=' . $game_id . '">', '</a>', E_USER_ERROR));
- }
- $sql_array = array(
- 'SELECT' => 'g.variable_name, g.cat_id, g.name, g.best_score_first',
- 'FROM' => array(
- GAMES_TABLE => 'g'
- ),
- 'WHERE' => 'g.id = ' . (int)$game_id
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- $game_data = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
- if (!$game_data) {
- $redirect = append_sid("{$phpbb_root_path}arcadeoa.$phpEx");
- $l_redirect = $user->lang['RETURN_ARCADEOA'];
- meta_refresh(5, $redirect);
- trigger_error($user->lang['NO_GAME'] . '<br /><br />' . sprintf($l_redirect, '<a href="arcadeoa.php?mode=game&id=' . $game_id . '">', '</a>', E_USER_ERROR));
- }
- if ($game_data['variable_name'] != $variable_name) {
- $redirect = append_sid("{$phpbb_root_path}arcadeoa.$phpEx");
- $l_redirect = $user->lang['RETURN_ARCADEOA'];
- meta_refresh(5, $redirect);
- trigger_error($user->lang['ERROR_VARIABLE_GAME'] . '<br /><br />' . sprintf($l_redirect, '<a href="arcadeoa.php?mode=game&id=' . $game_id . '">', '</a>', E_USER_ERROR));
- }
- }
- function send_challenge_pm($from, $to, $subject, $text) {
- global $db, $phpEx, $phpbb_root_path, $user;
- if (!class_exists('parse_message')) {
- include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
- }
- $time = time();
- $message_parser = new parse_message();
- $message_parser->parse(true, true, true, false, false, true, true);
- $uid = $message_parser->bbcode_uid;
- $db->sql_query('INSERT INTO phpbb_privmsgs (author_id,message_time,message_subject,`message_text`,to_address,bcc_address,bbcode_uid) VALUES (' . $from . ',' . $time . ',"' . $subject . '","' . addslashes($text) . '","u_' . $to . '",0,"' . $uid . '")');
- $lastid = $db->sql_nextid();
- $db->sql_query('INSERT INTO phpbb_privmsgs_to (msg_id,user_id,author_id,folder_id) VALUES (' . $lastid . ',' . $to . ',' . $from . ',-3)');
- $db->sql_query('UPDATE phpbb_users SET user_new_privmsg = user_new_privmsg+1,user_unread_privmsg = user_unread_privmsg+1,user_last_privmsg = ' . $time . ' WHERE user_id = ' . $to);
- }
- function challenges_check($gid, $gamename) {
- global $db, $user;
- $check = $db->sql_query('SELECT * FROM phpbb_oa_challenges WHERE gid = ' . $gid . ' and challenger = ' . $user->data['user_id'] . ' or `user` = ' . $user->data['user_id']);
- if (mysqli_num_rows($check) > 0) {
- $row = $db->sql_fetchrow($check);
- $losttext = 'Vous avez perdu le défi dans le jeu <a href="arcadeoa.php?mode=game&id=' . $gid . '" style="font-weight:bold;">' . $gamename . '</a>.';
- $wintext = 'Vous avez gagné le défi dans le jeu <a href="arcadeoa.php?mode=game&id=' . $gid . '" style="font-weight:bold;">' . $gamename . '</a>.<br>Félicitations!';
- if ($row['challenger'] == $user->data['user_id'] && $row['user_score'] > 0) {
- if ($row['challenger_score'] > $row['user_score']) {
- $this->send_challenge_pm($user->data['user_id'], $row['user'], 'Défi perdu', $losttext);
- $this->send_challenge_pm($row['user'], $row['challenger'], 'Défi gagné', $wintext);
- $db->sql_query('UPDATE phpbb_users SET user_points = user_points+' . $row['bet'] . ' WHERE user_id = ' . $row['challenger']);
- } else {
- $this->send_challenge_pm($user->data['user_id'], $row['user'], 'Défi gagné', $wintext);
- $this->send_challenge_pm($row['user'], $row['challenger'], 'Défi perdu', $losttext);
- $db->sql_query('UPDATE phpbb_users SET user_points = user_points+' . $row['bet'] . ' WHERE user_id = ' . $row['user']);
- }
- $db->sql_query('DELETE FROM phpbb_oa_challenges WHERE id = ' . $row['id']);
- } elseif ($row['user'] == $user->data['user_id'] && $row['challenger_score'] > 0) {
- if ($row['user_score'] > $row['challenger_score']) {
- $this->send_challenge_pm($user->data['user_id'], $row['challenger'], 'Challenge lost', $losttext);
- $this->send_challenge_pm($row['challenger'], $row['user'], 'Challenge won', $wintext);
- $db->sql_query('UPDATE phpbb_users SET user_points = user_points+' . $row['bet'] . ' WHERE user_id = ' . $row['user']);
- } else {
- $this->send_challenge_pm($user->data['user_id'], $row['challenger'], 'Challenge won', $wintext);
- $this->send_challenge_pm($row['challenger'], $row['user'], 'Challenge lost', $losttext);
- $db->sql_query('UPDATE phpbb_users SET user_points = user_points+' . $row['bet'] . ' WHERE user_id = ' . $row['challenger']);
- }
- $db->sql_query('DELETE FROM phpbb_oa_challenges WHERE id = ' . $row['id']);
- }
- }
- }
- function challenges_save($gid, $score) {
- global $db, $user, $phpEx, $arcadeoa;
- $check = $db->sql_query('SELECT * FROM phpbb_oa_challenges WHERE gid = ' . $gid . ' and challenger = ' . $user->data['user_id'] . ' or `user` = ' . $user->data['user_id']);
- if (mysqli_num_rows($check) > 0) {
- $row = $db->sql_fetchrow($check);
- if ($row['challenger'] == $user->data['user_id']) {
- $db->sql_query('UPDATE phpbb_oa_challenges SET challenger_score = ' . $score . ' WHERE id = ' . $row['id']);
- } elseif ($row['user'] == $user->data['user_id']) {
- $db->sql_query('UPDATE phpbb_oa_challenges SET user_score = ' . $score . ' WHERE id = ' . $row['id']);
- }
- }
- }
- //Done
- function save_score($game_score, $game_id) {
- global $db, $user, $phpEx, $arcadeoa;
- $sql_array = array(
- 'SELECT' => 'g.variable_name, g.cat_id, g.name, g.best_score_first',
- 'FROM' => array(
- GAMES_TABLE => 'g'
- ),
- 'WHERE' => 'g.id = ' . (int)$game_id
- );
- $playtime = time() - $_COOKIE['startplay'];
- unset($_COOKIE['startplay']);
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- $game_data = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
- $game_name = $game_data['name'];
- $this->challenges_save($game_id, $game_score);
- $this->challenges_check((int)$game_id, $game_name);
- //Si $bscore_first = true(1) -> Le plus gros score est le mieux pay�
- //Si $bscore_first = false(0) -> Le plus petit score est le mieux pay�
- $bscore_first = ((int)$game_data['best_score_first'] == 0) ? true : false;
- //Select first score for the game
- $sql_array = array(
- 'SELECT' => 's.id, s.score_date, s.points, s.gamer_id',
- 'FROM' => array(
- SCORES_TABLE => 's'
- ),
- 'WHERE' => 's.is_first = 1 AND s.game_id = ' . (int)$game_id,
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- $row = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
- $first_score = 0;
- $first_user = 0;
- $first_date = 0;//V4
- $sid = 0;
- $games = $db->sql_query('SELECT * FROM phpbb_games WHERE id = ' . $game_id);
- $game = $db->sql_fetchrow($games);
- if ($row) {
- $first_score = $row['points']; //Meilleur score du jeu
- $first_user = (int)$row['gamer_id'];
- $first_date = $row['score_date'];//V4
- $sid = (int)$row['id'];
- } else {
- //No score for this game, user will be the first, no need to check the score of other gamers
- $sql_ary = array(
- 'points' => $game_score,
- 'is_first' => 1,
- 'cat_id' => (int)$game_data['cat_id'],
- 'score_comment' => '',
- 'game_id' => (int)$game_id,
- 'gamer_id' => (int)$user->data['user_id'],
- 'score_date' => (int)time(),
- 'playtime' => $playtime,
- 'playcount' => 1
- );
- $db->sql_query('INSERT INTO ' . SCORES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
- $db->sql_query('UPDATE phpbb_games SET jackpot = jackpot + ' . $game['costs'] . ' WHERE id = ' . $game_id);
- return true;
- }
- //Grab user score for this game
- $sql_array = array(
- 'SELECT' => 's.id, s.points',
- 'FROM' => array(
- SCORES_TABLE => 's'
- ),
- 'WHERE' => 's.game_id = ' . (int)$game_id . ' AND s.gamer_id = ' . (int)$user->data['user_id']
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- $row = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
- $is_first = false;
- if (!$row) //L'utilisateur n'a pas jou� � ce jeu
- {
- //No score for this game, insert one
- //Si jeu ou le plus gros score est le mieux pay� -> Si meilleur score SCORES_TABLE < nouveau score -> true
- //Si jeu ou le plus petit score est le mieux pay� -> Si meilleur score SCORES_TABLE > nouveau score -> true
- //$is_first = ($bscore_first ? ($first_score > $game_score ? false : true) : ($first_score < $game_score ? false : true));//V3
- $is_first = ($bscore_first ? ($game_score > $first_score ? true : false) : ($game_score < $first_score ? true : false));//V4
- if ($is_first) {
- $sql_ary = array(
- 'is_first' => 0,
- 'playcount' => 'playcount+1'
- );
- $sql = 'UPDATE ' . SCORES_TABLE . ' SET is_first = 0,playcount = playcount+1 WHERE id = ' . $sid;
- //$sql = 'UPDATE ' . SCORES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE id = ' . $sid;
- $db->sql_query($sql);
- $arcadeoa->send_pm_loser($first_user, $game_id, $game_name, 0, $user->data['user_id']);
- }
- $sql_ary = array(
- 'points' => $game_score,
- 'is_first' => $is_first,
- 'cat_id' => (int)$game_data['cat_id'],
- 'score_comment' => '',
- 'game_id' => (int)$game_id,
- 'gamer_id' => (int)$user->data['user_id'],
- 'score_date' => (int)time(),
- 'playtime' => $playtime,
- 'playcount' => 1
- );
- $db->sql_query('INSERT INTO ' . SCORES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
- } else {
- //User already played this game - L'utilisateur a d�j� jou� � ce jeu
- $old_score = $row['points'];
- $old_score_id = (int)$row['id'];
- $did_he_beat_his_score = ($bscore_first ? ($old_score > $game_score ? false : true) : ($old_score < $game_score ? false : true));
- //$is_first = ($bscore_first ? ($first_score > $game_score ? false : true) : ($first_score < $game_score ? false : true));//V3
- $is_first = ($bscore_first ? ($game_score > $first_score ? true : false) : ($game_score < $first_score ? true : false));//V4
- if ($is_first) {
- $sql_ary = array(
- 'is_first' => 0,
- );
- $sql = 'UPDATE ' . SCORES_TABLE . ' SET is_first = 0,playcount = playcount+1 WHERE id = ' . $sid;
- // $sql = 'UPDATE ' . SCORES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE id = ' . $sid;
- $db->sql_query($sql);
- $arcadeoa->send_pm_loser($first_user, $game_id, $game_name, 0, $user->data['user_id']);
- }
- if ($did_he_beat_his_score) {
- $sql_ary = array(
- 'points' => $game_score,
- 'score_date' => time(),
- 'is_first' => $is_first,
- 'playtime' => $playtime
- );
- if (!$is_first) {
- $is_first = 0;
- }
- $sql = 'UPDATE ' . SCORES_TABLE . ' SET points = ' . $game_score . ',score_date = ' . time() . ',is_first = ' . $is_first . ',playtime=' . $playtime . ',playcount = playcount+1 WHERE id = ' . $old_score_id;
- //$sql = 'UPDATE ' . SCORES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE id = ' . $old_score_id;
- $db->sql_query($sql);
- }
- }
- return $is_first;
- }
- //Done
- function save_championship_score($game_score, $game_id, $round_id, $championship_id) {
- global $db, $user, $phpEx, $arcadeoa;
- $sql_array = array(
- 'SELECT' => 'g.name, g.best_score_first',
- 'FROM' => array(
- GAMES_TABLE => 'g'
- ),
- 'WHERE' => 'g.id = ' . (int)$game_id
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- $game_data = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
- $game_name = $game_data['name'];
- $bscore_first = ((int)$game_data['best_score_first'] == 0) ? true : false;
- //Select first score for the game
- $sql_array = array(
- 'SELECT' => 's.id, s.gamer_id, s.points',
- 'FROM' => array(
- CHAMPIONSHIPS_SCORES_TABLE => 's'
- ),
- 'WHERE' => 's.is_first = 1 AND s.game_id = ' . (int)$game_id . '
- AND s.championship_id = ' . (int)$championship_id . '
- AND s.round_id = ' . (int)$round_id
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- $row = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
- $first_score = 0;
- $first_user = 0;
- $sid = 0;
- if ($row) {
- $first_user = $row['gamer_id'];
- $sid = $row['id'];
- $first_score = $row['points'];
- } else {
- //Nobody played this game, insert the score
- $sql_ary = array(
- 'points' => $game_score,
- 'round_id' => $round_id,
- 'is_first' => 1,
- 'score_comment' => '',
- 'championship_id' => $championship_id,
- 'game_id' => (int)$game_id,
- 'gamer_id' => (int)$user->data['user_id'],
- 'score_date' => (int)time()
- );
- $db->sql_query('INSERT INTO ' . CHAMPIONSHIPS_SCORES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
- return true;
- }
- //Grab user score for this game
- $sql_array = array(
- 'SELECT' => 's.id, s.points',
- 'FROM' => array(
- CHAMPIONSHIPS_SCORES_TABLE => 's'
- ),
- 'WHERE' => 's.game_id = ' . (int)$game_id . '
- AND s.championship_id = ' . $championship_id . '
- AND s.gamer_id = ' . (int)$user->data['user_id'] . '
- AND s.round_id = ' . (int)$round_id
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- $row = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
- if (!$row) {
- //No score for this game, insert one
- //$is_first = ($bscore_first ? ($first_score > $game_score ? 0 : 1) : ($first_score < $game_score ? 0 : 1));
- $is_first = ($bscore_first ? ($game_score > $first_score ? true : false) : ($game_score < $first_score ? true : false));//V4
- if ($is_first) {
- $sql_ary = array(
- 'is_first' => 0,
- );
- $sql = 'UPDATE ' . CHAMPIONSHIPS_SCORES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
- WHERE id = ' . (int)$sid;
- $db->sql_query($sql);
- $arcadeoa->send_pm_loser($first_user, $game_id, $game_name, $round_id, $user->data['user_id']);
- }
- $sql_ary = array(
- 'points' => $game_score,
- 'round_id' => $round_id,
- 'is_first' => $is_first,
- 'championship_id' => $championship_id,
- 'score_comment' => '',
- 'game_id' => (int)$game_id,
- 'gamer_id' => (int)$user->data['user_id'],
- 'score_date' => (int)time()
- );
- $db->sql_query('INSERT INTO ' . CHAMPIONSHIPS_SCORES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
- } else {
- //User already played this game
- $old_score = $row['points'];
- $old_score_id = (int)$row['id'];
- $did_he_beat_his_score = ($bscore_first ? ($old_score > $game_score ? 0 : 1) : ($old_score < $game_score ? 0 : 1));
- //$is_first = ($bscore_first ? ($first_score > $game_score ? 0 : 1) : ($first_score < $game_score ? 0 : 1));
- $is_first = ($bscore_first ? ($game_score > $first_score ? true : false) : ($game_score < $first_score ? true : false));//V4
- if ($is_first) {
- $sql_ary = array(
- 'is_first' => 0,
- );
- $sql = 'UPDATE ' . CHAMPIONSHIPS_SCORES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
- WHERE id = ' . (int)$sid;
- $db->sql_query($sql);
- $arcadeoa->send_pm_loser($first_user, $game_id, $game_name, $round_id, $user->data['user_id']);
- }
- if ($did_he_beat_his_score) {
- $sql_ary = array(
- 'points' => $game_score,
- 'score_date' => time(),
- 'is_first' => $is_first,
- );
- $sql = 'UPDATE ' . CHAMPIONSHIPS_SCORES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
- WHERE id = ' . (int)$old_score_id;
- $db->sql_query($sql);
- }
- }
- return $is_first;
- }
- //Done
- function save_ultim_score($game_score, $game_id) {
- global $db, $user, $phpEx;
- $sql_array = array(
- 'SELECT' => 'g.variable_name, g.cat_id, g.best_score_first',
- 'FROM' => array(
- GAMES_TABLE => 'g'
- ),
- 'WHERE' => 'g.id = ' . (int)$game_id
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- $game_data = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
- $bscore_first = ((int)$game_data['best_score_first'] == 0) ? true : false;
- //Check for the ultim record
- $sql_array = array(
- 'SELECT' => 's.id, s.points',
- 'FROM' => array(
- ULTIM_SCORES_TABLE => 's'
- ),
- 'WHERE' => 's.game_id = ' . (int)$game_id
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- $row = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
- $games = $db->sql_query('SELECT * FROM phpbb_games WHERE id = ' . $game_id);
- $game = $db->sql_fetchrow($games);
- if ($row) {
- $first_score = $row['points'];
- $sid = $row['id'];
- $beat_it = ($bscore_first ? ($first_score > $game_score ? 0 : 1) : ($first_score < $game_score ? 0 : 1));
- //There is an ultim score, check if we have beaten it
- if ($beat_it) {
- $sql_ary = array(
- 'points' => $game_score,
- 'score_date' => time(),
- 'gamer_id' => (int)$user->data['user_id']
- );
- $db->sql_query('UPDATE phpbb_users SET user_points = user_points + ' . $game['jackpot'] . ' WHERE user_id = ' . $user->data['user_id']);
- $db->sql_query('UPDATE phpbb_games SET jackpot = 40 WHERE id = ' . $game_id);
- $sql = 'UPDATE ' . ULTIM_SCORES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
- WHERE id = ' . (int)$sid;
- $db->sql_query($sql);
- }
- } else {
- //No ultim record, insert one
- $sql_ary = array(
- 'points' => $game_score,
- 'cat_id' => (int)$game_data['cat_id'],
- 'score_comment' => '',
- 'game_id' => (int)$game_id,
- 'gamer_id' => (int)$user->data['user_id'],
- 'score_date' => (int)time()
- );
- $db->sql_query('INSERT INTO ' . ULTIM_SCORES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
- $db->sql_query('UPDATE phpbb_users SET user_points = user_points + ' . $game['jackpot'] . ' WHERE user_id = ' . $user->data['user_id']);
- $db->sql_query('UPDATE phpbb_games SET jackpot = 40 WHERE id = ' . $game_id);
- }
- $settings = $db->sql_query('SELECT * FROM phpbb_arcade WHERE config_name = "chatmsg"');
- $cfg = $db->sql_fetchrow($settings);
- if ($cfg['config_value'] == 1) {
- $userrecord = getuser($user->data['user_id']);
- $text = $userrecord . ' a fait un score sur <a href="arcadeoa.php?mode=game&id=' . $game_id . '" style="color:red;">' . $game['name'] . '</a> avec ' . $game_score . ' points.';
- $db->sql_query('INSERT INTO phpbb_mchat (user_id,user_ip,message,message_time) VALUES (172,"' . $_SERVER['REMOTE_ADDR'] . '","' . addslashes($text) . '",' . time() . ')');
- }
- }
- //Get high scores for this games and all users in a championship - done
- function get_high_scores_games_championship($round_id, $champ_id) {
- global $db;
- $scores = array();
- $max_points = array();
- if ($this->games_nbr == 0) {
- return $scores;
- }
- if (sizeof($this->games_sql[0])) {
- $sql_array = array(
- 'SELECT' => 's.id',
- 'FROM' => array(
- CHAMPIONSHIPS_SCORES_TABLE => 's'
- ),
- 'WHERE' => 's.round_id = ' . $round_id . ' AND s.championship_id = ' . $champ_id . ' AND s.is_first = 1 AND ' . $db->sql_in_set('s.game_id', $this->games_sql[0])
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result)) {
- $max_points[] = $row['id'];
- }
- $db->sql_freeresult($result);
- }
- if (sizeof($this->games_sql[1])) {
- $sql_array = array(
- 'SELECT' => 's.id',
- 'FROM' => array(
- CHAMPIONSHIPS_SCORES_TABLE => 's'
- ),
- 'WHERE' => 's.round_id = ' . $round_id . ' AND s.championship_id = ' . $champ_id . ' AND s.is_first = 1 AND ' . $db->sql_in_set('s.game_id', $this->games_sql[1])
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result)) {
- $max_points[] = $row['id'];
- }
- $db->sql_freeresult($result);
- }
- if (sizeof($max_points) == 0) {
- return $scores;
- }
- $sql_array = array(
- 'SELECT' => 'u.username, u.user_colour, s.gamer_id, s.points, s.game_id',
- 'FROM' => array(
- CHAMPIONSHIPS_SCORES_TABLE => 's',
- USERS_TABLE => 'u'
- ),
- 'WHERE' => 'u.user_id = s.gamer_id AND ' . $db->sql_in_set('s.id', $max_points)
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result)) {
- $scores[$row['game_id']]['username'] = $row['username'];
- $scores[$row['game_id']]['user_colour'] = $row['user_colour'];
- $scores[$row['game_id']]['gamer_id'] = $row['gamer_id'];
- $scores[$row['game_id']]['points'] = $row['points'];
- }
- $db->sql_freeresult($result);
- return $scores;
- }
- //Get first scores for this games and all users - done
- function get_first_scores_games() {
- global $db;
- $scores = array();
- $max_points = array();
- if ($this->games_nbr == 0) {
- return $scores;
- }
- if (sizeof($this->games_sql[0])) {
- $sql_array = array(
- 'SELECT' => 's.id, MAX(s.points) AS max_points',
- 'FROM' => array(
- SCORES_TABLE => 's'
- ),
- 'WHERE' => 's.is_first = 1 AND ' . $db->sql_in_set('s.game_id', $this->games_sql[0]),
- 'GROUP_BY' => 's.game_id'
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result)) {
- $max_points[] = $row['id'];
- }
- $db->sql_freeresult($result);
- }
- if (sizeof($this->games_sql[1])) {
- $sql_array = array(
- 'SELECT' => 's.id, MIN(s.points) AS max_points',
- 'FROM' => array(
- SCORES_TABLE => 's'
- ),
- 'WHERE' => 's.is_first = 1 AND ' . $db->sql_in_set('s.game_id', $this->games_sql[1]),
- 'GROUP_BY' => 's.game_id'
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result)) {
- $max_points[] = $row['id'];
- }
- $db->sql_freeresult($result);
- }
- if (sizeof($max_points) == 0) {
- return $scores;
- }
- $sql_array = array(
- 'SELECT' => 'u.username, u.user_colour, s.gamer_id, s.points, s.game_id,s.score_date',
- 'FROM' => array(
- SCORES_TABLE => 's',
- USERS_TABLE => 'u'
- ),
- 'WHERE' => 'u.user_id = s.gamer_id AND ' . $db->sql_in_set('s.id', $max_points)
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result)) {
- $scores[$row['game_id']]['username'] = $row['username'];
- $scores[$row['game_id']]['user_colour'] = $row['user_colour'];
- $scores[$row['game_id']]['gamer_id'] = $row['gamer_id'];
- $scores[$row['game_id']]['points'] = $row['points'];
- $scores[$row['game_id']]['date'] = $row['score_date'];
- }
- $db->sql_freeresult($result);
- return $scores;
- }
- //Get ultim scores for this games and all users - done
- function get_high_scores_games() {
- global $db;
- $scores = array();
- $max_points = array();
- if ($this->games_nbr == 0) {
- return $scores;
- }
- if (sizeof($this->games_sql[0])) {
- $sql_array = array(
- 'SELECT' => 's.id',
- 'FROM' => array(
- ULTIM_SCORES_TABLE => 's'
- ),
- 'WHERE' => $db->sql_in_set('s.game_id', $this->games_sql[0]),
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result)) {
- $max_points[] = $row['id'];
- }
- $db->sql_freeresult($result);
- }
- if (sizeof($this->games_sql[1])) {
- $sql_array = array(
- 'SELECT' => 's.id',
- 'FROM' => array(
- ULTIM_SCORES_TABLE => 's'
- ),
- 'WHERE' => $db->sql_in_set('s.game_id', $this->games_sql[1]),
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result)) {
- $max_points[] = $row['id'];
- }
- $db->sql_freeresult($result);
- }
- if (sizeof($max_points) == 0) {
- return $scores;
- }
- $sql_array = array(
- 'SELECT' => 'u.username, u.user_colour, s.gamer_id, s.points, s.game_id,s.score_date',
- 'FROM' => array(
- ULTIM_SCORES_TABLE => 's',
- USERS_TABLE => 'u'
- ),
- 'WHERE' => 'u.user_id = s.gamer_id AND ' . $db->sql_in_set('s.id', $max_points)
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result)) {
- $scores[$row['game_id']]['username'] = $row['username'];
- $scores[$row['game_id']]['user_colour'] = $row['user_colour'];
- $scores[$row['game_id']]['gamer_id'] = $row['gamer_id'];
- $scores[$row['game_id']]['points'] = $row['points'];
- $scores[$row['game_id']]['date'] = $row['score_date'];
- }
- $db->sql_freeresult($result);
- return $scores;
- }
- //Get high scores for this games from specified user in a championship - done
- function get_high_scores_user_games_championship($round_id, $champ_id) {
- global $db;
- $high_scores = array();
- if ($this->games_nbr == 0 || $this->user_id == 0) {
- return $high_scores;
- }
- if (sizeof($this->games_sql[0])) {
- $sql_array = array(
- 'SELECT' => 's.points, s.game_id',
- 'FROM' => array(
- CHAMPIONSHIPS_SCORES_TABLE => 's'
- ),
- 'WHERE' => 's.championship_id = ' . (int)$champ_id . '
- AND s.round_id = ' . (int)$round_id . '
- AND ' . $db->sql_in_set('s.game_id', $this->games_sql[0]) . ' AND s.gamer_id = ' . (int)$this->user_id
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result)) {
- $high_scores[$row['game_id']] = $row['points'];
- }
- $db->sql_freeresult($result);
- }
- if (sizeof($this->games_sql[1])) {
- $sql_array = array(
- 'SELECT' => 's.points, s.game_id',
- 'FROM' => array(
- CHAMPIONSHIPS_SCORES_TABLE => 's'
- ),
- 'WHERE' => 's.championship_id = ' . (int)$champ_id . '
- AND s.round_id = ' . (int)$round_id . '
- AND ' . $db->sql_in_set('s.game_id', $this->games_sql[1]) . ' AND s.gamer_id = ' . (int)$this->user_id
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result)) {
- $high_scores[$row['game_id']] = $row['points'];
- }
- $db->sql_freeresult($result);
- }
- return $high_scores;
- }
- //Get high scores for this games from specified user - done
- function get_high_scores_user_games() {
- global $db;
- $high_scores = array();
- if ($this->games_nbr == 0 || $this->user_id == 0) {
- return $high_scores;
- }
- if (sizeof($this->games_sql[0])) {
- $sql_array = array(
- 'SELECT' => 's.points, s.game_id',
- 'FROM' => array(
- SCORES_TABLE => 's'
- ),
- 'WHERE' => $db->sql_in_set('s.game_id', $this->games_sql[0]) . ' AND gamer_id = ' . (int)$this->user_id
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result)) {
- $high_scores[$row['game_id']] = $row['points'];
- }
- $db->sql_freeresult($result);
- }
- if (sizeof($this->games_sql[1])) {
- $sql_array = array(
- 'SELECT' => 's.points, s.game_id',
- 'FROM' => array(
- SCORES_TABLE => 's'
- ),
- 'WHERE' => $db->sql_in_set('s.game_id', $this->games_sql[1]) . ' AND gamer_id = ' . (int)$this->user_id
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result)) {
- $high_scores[$row['game_id']] = $row['points'];
- }
- $db->sql_freeresult($result);
- }
- return $high_scores;
- }
- //Get high scores for all games and all users - done
- function display_stats_board($limit = 5) {
- global $template, $phpbb_root_path, $phpEx, $db, $arcadeoa;
- $cups = $this->get_cups($limit);
- $most_played = $this->get_most_played($limit);
- $last_games = array();
- $sql_array = array(
- 'SELECT' => 'g.id, g.name, g.picture, g.description',
- 'FROM' => array(
- GAMES_TABLE => 'g'
- ),
- 'ORDER_BY' => 'g.id DESC'
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query_limit($sql, (int)$limit, 0);
- while ($row = $db->sql_fetchrow($result)) {
- $last_games[] = $row;
- }
- $db->sql_freeresult($result);
- $rowsNbr = sizeof($last_games);
- $conf = $arcadeoa->get_config();
- if ($rowsNbr > 0) {
- for ($i = 0; $i < $rowsNbr; $i++) {
- $template->assign_block_vars('cups_top', array(
- 'LAST_GAME_NAME' => stripslashes($last_games[$i]['name']),
- 'LAST_GAME_PICTURE' => '<img src="' . $phpbb_root_path . 'pics/' . $last_games[$i]['picture'] . '" class="games_thumb" width="' . $conf['games_thumb_width'] . '" height="' . $conf['games_thumb_height'] . '" />',
- 'LAST_DESCRIPTION' => $last_games[$i]['description'],
- 'U_LAST_GAME' => append_sid("{$phpbb_root_path}arcadeoa.$phpEx", "mode=game&id=" . $last_games[$i]['id']),
- 'S_CUPS' => isset($cups[$i]) ? true : false,
- 'NBR_CUPS' => isset($cups[$i]) ? (int)$cups[$i]['cups_nbr'] : 0,
- 'USER_NAME' => isset($cups[$i]) ? get_username_string('full', $cups[$i]['gamer_id'], $cups[$i]['username'], $cups[$i]['user_colour'], $cups[$i]['username']) : '',
- 'TOP_PLAYED_NAME' => isset($most_played[$i]) ? stripslashes($most_played[$i]['name']) : '',
- 'TOP_PLAYED_URL' => isset($most_played[$i]) ? append_sid("{$phpbb_root_path}arcadeoa.$phpEx", "mode=game&id=" . $most_played[$i]['id']) : '',
- 'TOP_PLAYED_TIME' => isset($most_played[$i]) ? (int)$most_played[$i]['time_played'] : 0,
- 'S_TOP_PLAYED' => isset($most_played[$i]) ? true : false,
- 'TOP_PLAYED_PICTURE' => isset($most_played[$i]) ? '<img src="' . $phpbb_root_path . 'pics/' . $most_played[$i]['picture'] . '" class="games_thumb" width="' . $conf['games_thumb_width'] . '" height="' . $conf['games_thumb_height'] . '" />' : '',
- ));
- }
- }
- $top_5_user = $this->get_high_scores_user($limit);
- $top_5_ultim = $this->get_highest_scores_arcadeoa($limit);
- $top_5 = $this->get_high_scores_arcadeoa($limit);
- $rowsNbr = sizeof($top_5);
- if ($rowsNbr > 0) {
- $template->assign_vars(array(
- 'S_STATS' => true
- ));
- for ($i = 0; $i < $rowsNbr; $i++) {
- $template->assign_block_vars('top', array(
- 'TOP_5_PICTURE' => '<img src="' . $phpbb_root_path . 'pics/' . $top_5[$i]['picture'] . '" class="games_thumb" width="' . $conf['games_thumb_width'] . '" height="' . $conf['games_thumb_height'] . '" />',
- 'S_TOP_5_GAME' => (isset($top_5[$i]['name']) ? true : false),
- 'TOP_5_GAME_NAME' => isset($top_5[$i]['name']) ? stripslashes($top_5[$i]['name']) : '',
- 'TOP_5_GAME_SCORE' => isset($top_5[$i]['points']) ? $top_5[$i]['points'] : 0,
- 'TOP_5_GAME_USER' => get_username_string('full', $top_5[$i]['user_id'], $top_5[$i]['username'], $top_5[$i]['user_colour'], $top_5[$i]['username']),
- 'U_TOP_5' => append_sid("{$phpbb_root_path}arcadeoa.$phpEx", "mode=game&id=" . $top_5[$i]['game_id']),
- 'S_TOP_5_USER' => (isset($top_5_user[$i]['name']) ? true : false),
- 'TOP_5_USER_GAME_NAME' => isset($top_5_user[$i]['name']) ? stripslashes($top_5_user[$i]['name']) : '',
- 'TOP_5_USER_GAME_SCORE' => isset($top_5_user[$i]['points']) ? $top_5_user[$i]['points'] : 0,
- 'U_TOP_5_USER' => append_sid("{$phpbb_root_path}arcadeoa.$phpEx", "mode=game&id=" . (isset($top_5_user[$i]['game_id']) ? (int)$top_5_user[$i]['game_id'] : 0)),
- 'S_TOP_5_ULTIM' => (isset($top_5_ultim[$i]['name']) ? true : false),
- 'TOP_5_ULTIM_GAME_NAME' => isset($top_5_ultim[$i]['name']) ? stripslashes($top_5_ultim[$i]['name']) : '',
- 'TOP_5_ULTIM_GAME_SCORE' => isset($top_5_ultim[$i]['points']) ? $top_5_ultim[$i]['points'] : 0,
- 'TOP_5_ULTIM_USER' => isset($top_5_ultim[$i]) ? get_username_string('full', $top_5_ultim[$i]['user_id'], $top_5_ultim[$i]['username'], $top_5_ultim[$i]['user_colour'], $top_5_ultim[$i]['username']) : '',
- 'U_TOP_5_ULTIM' => append_sid("{$phpbb_root_path}arcadeoa.$phpEx", "mode=game&id=" . (isset($top_5_ultim[$i]['game_id']) ? (int)$top_5_ultim[$i]['game_id'] : 0)),
- 'TOP_5_ULTIM_PICTURE' => (isset($top_5_ultim[$i]['picture']) ? '<img src="' . $phpbb_root_path . 'pics/' . $top_5_ultim[$i]['picture'] . '" class="games_thumb" width="' . $conf['games_thumb_width'] . '" height="' . $conf['games_thumb_height'] . '" />' : ''),
- ));
- }
- }
- }
- //Get ultim scores for all games and all users - done
- function get_cups($limit = 5) {
- global $db;
- $cups = array();
- $sql_array = array(
- 'SELECT' => 's.gamer_id, COUNT(s.game_id) AS cups_nbr, u.username, u.user_colour',
- 'FROM' => array(
- SCORES_TABLE => 's',
- ),
- 'WHERE' => 's.is_first = 1',
- 'LEFT_JOIN' => array(
- array(
- 'FROM' => array(USERS_TABLE => 'u'),
- 'ON' => 'u.user_id = s.gamer_id'
- )
- ),
- 'GROUP_BY' => 's.gamer_id',
- 'ORDER_BY' => 'cups_nbr DESC'
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query_limit($sql, (int)$limit, 0);
- while ($row = $db->sql_fetchrow($result)) {
- $cups[] = $row;
- }
- $db->sql_freeresult($result);
- return $cups;
- }
- //Get high scores for all games from specified user - done
- function get_most_played($limit = 5) {
- global $db;
- $games = array();
- $sql_array = array(
- 'SELECT' => 'g.id, g.name, g.time_played, g.picture',
- 'FROM' => array(
- GAMES_TABLE => 'g'
- ),
- 'ORDER_BY' => 'g.time_played DESC'
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query_limit($sql, (int)$limit, 0);
- while ($row = $db->sql_fetchrow($result)) {
- $games[] = $row;
- }
- $db->sql_freeresult($result);
- return $games;
- }
- //Display stats panel - done
- function get_high_scores_user($limit = 5, $ultim = 0) {
- global $db;
- $scores = array();
- if ($this->user_id == 0) {
- return $scores;
- }
- $sql_array = array(
- 'SELECT' => 'g.name, g.picture, s.game_id, s.points, s.score_date',
- 'FROM' => array(
- ($ultim == 1 ? ULTIM_SCORES_TABLE : SCORES_TABLE) => 's',
- ),
- 'WHERE' => 'g.best_score_first = 0 AND u.user_id = ' . (int)$this->user_id,
- 'LEFT_JOIN' => array(
- array(
- 'FROM' => array(GAMES_TABLE => 'g'),
- 'ON' => 'g.id = s.game_id'
- ),
- array(
- 'FROM' => array(USERS_TABLE => 'u'),
- 'ON' => 'u.user_id = s.gamer_id'
- )
- ),
- 'ORDER_BY' => 's.points DESC',
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- if ($limit == -1) {
- $result = $db->sql_query($sql);
- } else {
- $result = $db->sql_query_limit($sql, (int)$limit, 0);
- }
- while ($row = $db->sql_fetchrow($result)) {
- $scores[] = $row;
- }
- $db->sql_freeresult($result);
- if (sizeof($scores) < $limit) {
- $sql_array = array(
- 'SELECT' => 'g.name, g.picture, s.game_id, s.points, s.score_date',
- 'FROM' => array(
- ($ultim == 1 ? ULTIM_SCORES_TABLE : SCORES_TABLE) => 's',
- ),
- 'WHERE' => 'g.best_score_first = 1 AND u.user_id = ' . (int)$this->user_id,
- 'LEFT_JOIN' => array(
- array(
- 'FROM' => array(GAMES_TABLE => 'g'),
- 'ON' => 'g.id = s.game_id'
- ),
- array(
- 'FROM' => array(USERS_TABLE => 'u'),
- 'ON' => 'u.user_id = s.gamer_id'
- )
- ),
- 'ORDER_BY' => 's.points ASC',
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- if ($limit == -1) {
- $result = $db->sql_query($sql);
- } else {
- $result = $db->sql_query_limit($sql, (int)$limit - sizeof($scores), 0);
- }
- while ($row = $db->sql_fetchrow($result)) {
- $scores[] = $row;
- }
- $db->sql_freeresult($result);
- }
- return $scores;
- }
- //Get games where user has the high score (non ultim) - done
- function get_highest_scores_arcadeoa($limit = 5) {
- global $db;
- $scores = array();
- $sql_array = array(
- 'SELECT' => 'u.username, u.user_id, u.user_colour, g.name, g.picture, s.game_id, s.points',
- 'FROM' => array(
- ULTIM_SCORES_TABLE => 's',
- ),
- 'WHERE' => 'g.best_score_first = 0',
- 'LEFT_JOIN' => array(
- array(
- 'FROM' => array(GAMES_TABLE => 'g'),
- 'ON' => 'g.id = s.game_id'
- ),
- array(
- 'FROM' => array(USERS_TABLE => 'u'),
- 'ON' => 'u.user_id = s.gamer_id'
- )
- ),
- 'ORDER_BY' => 's.points DESC'
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query_limit($sql, (int)$limit, 0);
- while ($row = $db->sql_fetchrow($result)) {
- $scores[] = $row;
- }
- $db->sql_freeresult($result);
- if (sizeof($scores) < $limit) {
- $sql_array = array(
- 'SELECT' => 'u.username, u.user_id, u.user_colour, g.name, g.picture, s.game_id, s.points',
- 'FROM' => array(
- ULTIM_SCORES_TABLE => 's'
- ),
- 'WHERE' => 'g.best_score_first = 1',
- 'LEFT_JOIN' => array(
- array(
- 'FROM' => array(GAMES_TABLE => 'g'),
- 'ON' => 'g.id = s.game_id'
- ),
- array(
- 'FROM' => array(USERS_TABLE => 'u'),
- 'ON' => 'u.user_id = s.gamer_id'
- )
- ),
- 'ORDER_BY' => 's.points ASC'
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query_limit($sql, (int)$limit - sizeof($scores), 0);
- while ($row = $db->sql_fetchrow($result)) {
- $scores[] = $row;
- }
- $db->sql_freeresult($result);
- }
- return $scores;
- }
- //Get infos on the user which has the most many cups, sorted by category - done
- function get_high_scores_arcadeoa($limit = 5) {
- global $db;
- $scores = array();
- if ($this->user_id == 0) {
- return $scores;
- }
- $sql_array = array(
- 'SELECT' => 'u.username, u.user_id, u.user_colour, g.name, g.picture, s.game_id, s.points',
- 'FROM' => array(
- SCORES_TABLE => 's',
- ),
- 'WHERE' => 'g.best_score_first = 0',
- 'LEFT_JOIN' => array(
- array(
- 'FROM' => array(GAMES_TABLE => 'g'),
- 'ON' => 'g.id = s.game_id'
- ),
- array(
- 'FROM' => array(USERS_TABLE => 'u'),
- 'ON' => 'u.user_id = s.gamer_id'
- )
- ),
- 'ORDER_BY' => 's.points DESC'
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query_limit($sql, (int)$limit, 0);
- while ($row = $db->sql_fetchrow($result)) {
- $scores[] = $row;
- }
- $db->sql_freeresult($result);
- if (sizeof($scores) < $limit) {
- $sql_array = array(
- 'SELECT' => 'u.username, u.user_id, u.user_colour, g.name, g.picture, s.game_id, s.points',
- 'FROM' => array(
- SCORES_TABLE => 's',
- ),
- 'WHERE' => 'g.best_score_first = 1',
- 'LEFT_JOIN' => array(
- array(
- 'FROM' => array(GAMES_TABLE => 'g'),
- 'ON' => 'g.id = s.game_id'
- ),
- array(
- 'FROM' => array(USERS_TABLE => 'u'),
- 'ON' => 'u.user_id = s.gamer_id'
- )
- ),
- 'ORDER_BY' => 's.points ASC'
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query_limit($sql, (int)$limit - sizeof($scores), 0);
- while ($row = $db->sql_fetchrow($result)) {
- $scores[] = $row;
- }
- $db->sql_freeresult($result);
- }
- return $scores;
- }
- //Get cups from all users - done
- function get_cups_user($user_id = 0) {
- global $db;
- $cups = array();
- if ($user_id == 0) {
- return $cups;
- }
- $sql_array = array(
- 'SELECT' => 's.game_id',
- 'FROM' => array(
- SCORES_TABLE => 's'
- ),
- 'WHERE' => 's.is_first = 1 AND s.gamer_id = ' . (int)$user_id,
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result)) {
- $cups[] = $row['game_id'];
- }
- $db->sql_freeresult($result);
- return $cups;
- }
- //Get most played games - done
- function get_cups_by_category($c_sql = array()) {
- global $db;
- $cups = array();
- if (!is_array($c_sql) || sizeof($c_sql) == 0) {
- return $cups;
- }
- $sql_array = array(
- 'SELECT' => 's.cat_id, s.gamer_id, COUNT(s.game_id) AS cups_nbr, u.username, u.user_colour, u.user_avatar, u.user_avatar_height, u.user_avatar_type, u.user_avatar_width',
- 'FROM' => array(
- SCORES_TABLE => 's',
- ),
- 'WHERE' => 's.is_first = 1 AND ' . $db->sql_in_set('s.cat_id', $c_sql),
- 'LEFT_JOIN' => array(
- array(
- 'FROM' => array(USERS_TABLE => 'u'),
- 'ON' => 'u.user_id = s.gamer_id'
- )
- ),
- 'GROUP_BY' => 's.cat_id, s.gamer_id',
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result)) {
- if (isset($cups[$row['cat_id']])) {
- if ($row['cups_nbr'] > $cups[$row['cat_id']]['cups_nbr']) {
- $cups[$row['cat_id']] = $row;
- }
- } else {
- $cups[$row['cat_id']] = $row;
- }
- }
- $db->sql_freeresult($result);
- return $cups;
- }
- //Display user stats panel - done
- function display_user_stats($limit = 10) {
- global $db, $template, $user, $phpbb_root_path, $phpEx;
- $template->assign_block_vars('navlinks', array(
- 'FORUM_NAME' => $user->lang['ARCADEOA'],
- 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}arcadeoa.$phpEx")
- )
- );
- $template->assign_block_vars('navlinks', array(
- 'FORUM_NAME' => $user->lang['STATS'],
- 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}arcadeoa.$phpEx", 'mode=stats&id=' . $this->user_id)
- )
- );
- $top_scores_user = $this->get_high_scores_user($limit, 0);
- $top_ultim_user = $this->get_high_scores_user($limit, 1);
- for ($i = 0; $i < sizeof($top_scores_user); $i++) {
- $template->assign_block_vars('top_record', array(
- 'GAME_NAME' => stripslashes($top_scores_user[$i]['name']),
- 'GAME_IMG' => $top_scores_user[$i]['picture'],
- 'GAME_POINTS' => $top_scores_user[$i]['points'],
- 'GAME_DATE' => $user->format_date($top_scores_user[$i]['score_date']),
- 'U_GAME' => append_sid("{$phpbb_root_path}arcadeoa.$phpEx", "mode=game&id=" . $top_scores_user[$i]['game_id']),
- ));
- }
- for ($i = 0; $i < sizeof($top_ultim_user); $i++) {
- $template->assign_block_vars('ultim_record', array(
- 'GAME_NAME' => stripslashes($top_ultim_user[$i]['name']),
- 'GAME_IMG' => $top_ultim_user[$i]['picture'],
- 'GAME_POINTS' => $top_ultim_user[$i]['points'],
- 'GAME_DATE' => $user->format_date($top_ultim_user[$i]['score_date']),
- 'U_GAME' => append_sid("{$phpbb_root_path}arcadeoa.$phpEx", "mode=game&id=" . $top_ultim_user[$i]['game_id']),
- ));
- }
- page_header($user->lang['STATS']);
- $template->set_filenames(array(
- 'body' => 'arcadeoa_stats_user.html'
- )
- );
- page_footer();
- }
- //
- function view_championship_results($champ_id = 0) {
- global $db, $template, $user, $phpbb_root_path, $phpEx;
- $sql_array = array(
- 'SELECT' => 'COUNT(ut.id) AS gamers_nbr',
- 'FROM' => array(
- USERS_TEAMS_TABLE => 'ut'
- ),
- 'WHERE' => 'ut.champ_id = ' . (int)$champ_id,
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- $row = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
- $gamers_nbr = (int)$row['gamers_nbr'];
- $sql_array = array(
- 'SELECT' => 's.points, s.game_id, s.round_id, s.gamer_id, u.username, u.user_colour, g.name, g.best_score_first',
- 'FROM' => array(
- CHAMPIONSHIPS_SCORES_TABLE => 's'
- ),
- 'WHERE' => 's.championship_id = ' . (int)$champ_id,
- 'LEFT_JOIN' => array(
- array(
- 'FROM' => array(GAMES_TABLE => 'g'),
- 'ON' => 'g.id = s.game_id'
- ),
- array(
- 'FROM' => array(USERS_TABLE => 'u'),
- 'ON' => 'u.user_id = s.gamer_id'
- )
- )
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- $games = array();
- $users = array();
- $rounds = array();
- $users_ranks = array();
- $users_team = array();
- $teams = array();
- while ($row = $db->sql_fetchrow($result)) {
- if (!isset($games[$row['game_id']])) {
- $games[$row['game_id']] = $row['best_score_first'];
- }
- $rounds[$row['round_id']][$row['game_id']][] = array('uid' => $row['gamer_id'],
- 'pts' => $row['points']
- );
- if (!isset($users[$row['gamer_id']])) {
- $users[$row['gamer_id']] = array('username' => $row['username'],
- 'user_colour' => $row['user_colour']
- );
- }
- }
- $db->sql_freeresult($result);
- $sql_array = array(
- 'SELECT' => 't.id, t.name, ut.user_id',
- 'FROM' => array(
- USERS_TEAMS_TABLE => 'ut'
- ),
- 'WHERE' => 'ut.champ_id = ' . (int)$champ_id,
- 'LEFT_JOIN' => array(
- array(
- 'FROM' => array(TEAMS_TABLE => 't'),
- 'ON' => 't.id = ut.team_id'
- )
- )
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result)) {
- if (!isset($teams[$row['id']])) {
- $teams[$row['id']] = $row['name'];
- }
- $users_team[$row['user_id']] = $row['id'];
- }
- $db->sql_freeresult($result);
- $r = 1;
- foreach ($rounds as $rid => $round) {
- $template->assign_block_vars('round', array(
- 'NUMBER' => $r,
- ));
- $user_scores = array();
- foreach ($round as $gid => $score) {
- for ($j = 0; $j < sizeof($score); $j++) {
- $user_scores[$score[$j]['uid']] = isset($user_scores[$score[$j]['uid']]) ? $user_scores[$score[$j]['uid']] + $score[$j]['pts'] : $score[$j]['pts'];
- }
- }
- if (!(int)$games[$gid]) {
- arsort($user_scores);
- } else {
- asort($user_scores);
- }
- $m = 0;
- foreach ($user_scores as $uid => $total) {
- $users_ranks[$uid] = isset($users_ranks[$uid]) ? ($users_ranks[$uid] + $gamers_nbr - $m) : ($gamers_nbr - $m);
- $m++;
- if ($m < 11) {
- $template->assign_block_vars('round.user', array(
- 'RANK' => $m,
- 'NAME' => get_username_string('full', $uid, $users[$uid]['username'], $users[$uid]['user_colour'], $users[$uid]['username']),
- 'POINTS' => $gamers_nbr - $m + 1
- ));
- }
- }
- $r++;
- }
- $top_teams = array();
- foreach ($teams as $id => $name) {
- $top_teams[$id] = 0;
- }
- arsort($users_ranks);
- $r = 1;
- //Top
- foreach ($users_ranks as $user_id => $points) {
- $top_teams[$users_team[$user_id]] += $points;
- $template->assign_block_vars('user_rank', array(
- 'RANK' => $r,
- 'U_GAMER' => append_sid("{$phpbb_root_path}memberlist." . $phpEx, "mode=viewprofile&u=" . $user_id),
- 'GAMER_NAME' => get_username_string('full', $user_id, $users[$user_id]['username'], $users[$user_id]['user_colour'], $users[$user_id]['username']),
- 'POINTS' => $points
- ));
- $r++;
- if ($r == 11) {
- break;
- }
- }
- $r = 1;
- arsort($top_teams);
- foreach ($top_teams as $id => $points) {
- $template->assign_block_vars('team', array(
- 'RANK' => $r,
- 'NAME' => stripslashes($teams[$id]),
- 'POINTS' => $points
- ));
- $r++;
- if ($r == 11) {
- break;
- }
- }
- $template->assign_vars(array(
- 'U_GAME_SEARCH' => append_sid("{$phpbb_root_path}arcadeoa." . $phpEx, "mode=search")
- ));
- $template->assign_block_vars('navlinks', array(
- 'FORUM_NAME' => $user->lang['ARCADEOA'],
- 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}arcadeoa.$phpEx")
- )
- );
- $template->assign_block_vars('navlinks', array(
- 'FORUM_NAME' => $user->lang['CHAMPIONSHIP'],
- 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}arcadeoa.$phpEx")
- )
- );
- page_header();
- $template->set_filenames(array(
- 'body' => 'championship_results.html'
- )
- );
- page_footer();
- }
- //Done
- function view_round_results($round_id = 0) {
- global $db, $template, $user, $phpbb_root_path, $phpEx, $arcadeoa;
- $champ_id = $arcadeoa->check_round($round_id, false);
- $sql_array = array(
- 'SELECT' => 'COUNT(ut.id) AS gamers_nbr',
- 'FROM' => array(
- USERS_TEAMS_TABLE => 'ut'
- ),
- 'WHERE' => 'ut.champ_id = ' . (int)$champ_id,
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- $row = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
- $gamers_nbr = (int)$row['gamers_nbr'];
- $games = array();
- $users = array();
- $users_points = array();
- $users_ranks = array();
- $scores = array();
- $scores_table = array();
- $users_team = array();
- $teams = array();
- $sql_array = array(
- 'SELECT' => 's.points, s.game_id, s.gamer_id, u.username, u.user_colour, g.best_score_first',
- 'FROM' => array(
- CHAMPIONSHIPS_SCORES_TABLE => 's'
- ),
- 'WHERE' => 's.round_id = ' . (int)$round_id,
- 'LEFT_JOIN' => array(
- array(
- 'FROM' => array(GAMES_TABLE => 'g'),
- 'ON' => 'g.id = s.game_id'
- ),
- array(
- 'FROM' => array(USERS_TABLE => 'u'),
- 'ON' => 'u.user_id = s.gamer_id'
- )
- )
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result)) {
- if (!isset($games[$row['game_id']])) {
- $games[$row['game_id']] = $row['best_score_first'];
- }
- $scores_table[$row['game_id']][] = array($row['gamer_id'] => $row['points']);
- if (!isset($users[$row['gamer_id']])) {
- $users[$row['gamer_id']] = $row;
- }
- }
- $db->sql_freeresult($result);
- $sql_array = array(
- 'SELECT' => 't.id, t.name, ut.user_id',
- 'FROM' => array(
- USERS_TEAMS_TABLE => 'ut'
- ),
- 'WHERE' => 'ut.champ_id = ' . (int)$champ_id,
- 'LEFT_JOIN' => array(
- array(
- 'FROM' => array(TEAMS_TABLE => 't'),
- 'ON' => 't.id = ut.team_id'
- )
- )
- );
- $sql = $db->sql_build_query('SELECT', $sql_array);
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result)) {
- if (!isset($teams[$row['id']])) {
- $teams[$row['id']] = $row['name'];
- }
- $users_team[$row['user_id']] = $row['id'];
- }
- $db->sql_freeresult($result);
- foreach ($games as $id => $bscore) {
- $scores_game = array();
- for ($t = 0; $t < sizeof($scores_table[$id]); $t++) {
- foreach ($scores_table[$id][$t] as $uid => $points) {
- $scores_game[$uid] = $points;
- }
- }
- if (!$bscore) {
- arsort($scores_game);
- } else {
- asort($scores_game);
- }
- $m = 0;
- foreach ($scores_game as $uid => $p) {
- $users_ranks[$uid] = isset($users_ranks[$uid]) ? ($users_ranks[$uid] + $gamers_nbr - $m) : ($gamers_nbr - $m);
- $m++;
- }
- }
- arsort($users_ranks);
- $r = 1;
- //Top
- $top_teams = array();
- foreach ($teams as $id => $name) {
- $top_teams[$id] = 0;
- }
- foreach ($users_ranks as $user_id => $points) {
- $template->assign_block_vars('user_rank', array(
- 'RANK' => $r,
- 'U_GAMER' => append_sid("{$phpbb_root_path}memberlist." . $phpEx, "mode=viewprofile&u=" . $user_id),
- 'GAMER_NAME' => get_username_string('full', $user_id, $users[$user_id]['username'], $users[$user_id]['user_colour'], $users[$user_id]['username']),
- 'POINTS' => $points
- ));
- $top_teams[$users_team[$user_id]] += $points;
- $r++;
- if ($r == 11) {
- break;
- }
- }
- $r = 1;
- arsort($top_teams);
- foreach ($top_teams as $id => $points) {
- $template->assign_block_vars('team', array(
- 'RANK' => $r,
- 'NAME' => stripslashes($teams[$id]),
- 'POINTS' => $points
- ));
- $r++;
- if ($r == 11) {
- break;
- }
- }
- $template->assign_vars(array(
- 'U_GAME_SEARCH' => append_sid("{$phpbb_root_path}arcadeoa." . $phpEx, "mode=search")
- ));
- $template->assign_block_vars('navlinks', array(
- 'FORUM_NAME' => $user->lang['ARCADEOA'],
- 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}arcadeoa.$phpEx")
- )
- );
- $template->assign_block_vars('navlinks', array(
- 'FORUM_NAME' => $user->lang['ROUND'],
- 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}arcadeoa.$phpEx?mode=champ&id=" . $round_id)
- )
- );
- page_header();
- $template->set_filenames(array(
- 'body' => 'round_results.html'
- )
- );
- page_footer();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment