";
break;
}
return $ladderhtml;
}
//------------------------------------------
// Show_Games
//
// This shows the list of games available
//
//------------------------------------------
public function show_games()
{
global $ibforums, $DB, $std, $vbulletin, $vboptions, $NATIVEMODE;
$games = array();
$game_gids = array();
$game_string = '(0)';
$rowcol = 'alt1';
$total_num = 0;
// cleanup some incoming stuff
$ibforums->input['gsearch'] = ibp_cleansql($ibforums->input['gsearch']);
$stylecolumns = $this->arcade->settings['games_pr']; // this affects the ibPro-Style only!
// Newest Games
$DB->query("SELECT g.gid, g.gtitle, g.gname, g.gcat, cat.password, cat.active FROM ibf_games_list AS g, ibf_games_cats AS cat WHERE g.active=1 AND cat.active=1 AND g.gcat=cat.c_id AND trim(password)='' ORDER BY g.added DESC LIMIT ".$this->arcade->settings['games_new']);
$firstnew = true;
while ($newgline = $DB->fetch_row()) {
if ($firstnew) {
$firstnew = false;
} else {
$new_games .= " \n";
}
$new_games .= "{$newgline['gtitle']} ";
}
// End Newest Games
// Begin Most Popular Games
$DB->query("SELECT g.gid, g.gtitle, g.gname, g.gcat, cat.password, g.gcount, cat.active FROM ibf_games_list AS g, ibf_games_cats AS cat WHERE g.active=1 AND cat.active=1 AND g.gcat=cat.c_id AND trim(password)='' ORDER BY g.gcount DESC LIMIT ".$this->arcade->settings['games_popular']);
$firstpop = true;
while ($popgline = $DB->fetch_row()) {
if ($firstpop) {
$firstpop = false;
} else {
$pop_games .= " \n";
}
$pop_games .= " {$popgline['gtitle']}";
}
//Most End Popular Games
// Random Game
$DB->query("SELECT g.gid, g.gtitle, g.gname, g.gcat, cat.password, cat.active FROM ibf_games_list AS g, ibf_games_cats AS cat WHERE g.active=1 AND cat.active=1 AND g.gcat=cat.c_id AND trim(password)='' ORDER BY RAND() LIMIT 1");
$firstran = true;
while ($rangline = $DB->fetch_row()) {
if ($firstran) {
$firstran = false;
} else {
$ran_games .= " \n";
}
// Create Code based on setting for static/AJAX
$this->arcade->settings['random_AJAX'] = 0;
if ($this->arcade->settings['random_AJAX'] < 1) {
// static display
$ran_games .= "
{$rangline['gtitle']}";
} else {
$ran_games .= '
';
}
}
// End Random Game
// Begin Total Stuff
$tot_games = 0;
//Arrays
$games2 = array();
$gid_array2 = array();
$DB->query("SELECT g.gid, c.password from ibf_games_list AS g, ibf_games_cats AS c WHERE g.active=1 AND g.gcat=c.c_id AND trim(password)='' ORDER BY ".$this->arcade->settings['g_display_sort'].' '.$this->arcade->settings['g_display_order']);
while ($this_game = $DB->fetch_row()) {
$games2[] = array(
'gid' => $this_game2['gid'],
);
$gid_array2[] = $this_game2['gid'];
++$tot_games;
}
if (count($gid_array2) > 0) {
$game_string2 = '('.implode(',', $gid_array2).')';
}
$tot_cats = 0;
$DB->query('SELECT * FROM ibf_games_cats AS c WHERE c.active=1 AND c.show_all=0');
while ($this_cat = $DB->fetch_row()) {
++$tot_cats;
}
// End Total Stuff
// die Top3 der Highscores
$query = 'SELECT champ_gid AS GID, champ_mid AS MID, champ_name AS name, COUNT(champ_mid) AS total FROM ibf_games_champs GROUP BY MID ORDER BY total DESC LIMIT 3';
$result = $DB->query($query);
$Cpt = 1;
while ($data = $DB->fetch_row($result)) {
$Highscorechamp['ArcadeChampion'.$Cpt] = ''.$data['name'].' '.$ibforums->lang[top3box_txt1].''.$data['total'].''.$ibforums->lang[top3box_txt2];
$Highscorechamp['ArcadeChampionMid'.$Cpt] = $data['MID'];
$Highscorechamp['ArcadeChampionScore'.$Cpt] = $data['total'];
$DB->query('SELECT avatar,avatar_size AS size FROM ibf_members WHERE id='.$Highscorechamp['ArcadeChampionMid'.$Cpt]);
if ($avatar = $DB->fetch_row()) {
$Highscorechamp['ArcadeChampionAvatarCode'.$Cpt] = $std->get_avatar($avatar, 1, $avatar['size']);
if ($Highscorechamp['ArcadeChampionAvatarCode'.$Cpt] == '') {
$Highscorechamp['ArcadeChampionAvatarCode'.$Cpt] = "";
}
} else {
$Highscorechamp['ArcadeChampionAvatarCode'.$Cpt] = "";
if ($Highscorechamp['ArcadeChampionScore2'] == $Highscorechamp['ArcadeChampionScore1']) {
if ($Highscorechamp['ArcadeChampionScore2'] > 0) {
$Highscorechamp['ArcadeChampionSmily2'] = $Highscorechamp['ArcadeChampionSmily1'];
}
}
if ($Highscorechamp['ArcadeChampionScore3'] == $Highscorechamp['ArcadeChampionScore2']) {
if ($Highscorechamp['ArcadeChampionScore3'] > 0) {
$Highscorechamp['ArcadeChampionSmily3'] = $Highscorechamp['ArcadeChampionSmily2'];
}
}
// Champion mit den meisten besten Ergebnissen aller Zeiten
$Champion['ArcadeChampion1'] = "{$ibforums->lang['top3box_norank']}";
$Champion['ArcadeChampion2'] = "{$ibforums->lang['top3box_norank']}";
$Champion['ArcadeChampion3'] = "{$ibforums->lang['top3box_norank']}";
$Cpt = 0;
$DB->query('SELECT g.gid, g.active, count(*) nb, g.bestscore, g.bestmid AS champ_mid, u.username AS champ_name FROM ibf_games_list AS g INNER JOIN ibf_user AS u ON u.userid=g.bestmid WHERE active=1 GROUP BY bestmid ORDER BY 3 DESC LIMIT 1');
while ($res = $DB->fetch_row()) {
++$Cpt;
$Champion['ArcadeChampion'.$Cpt] = ''.$res['champ_name'].' '.$ibforums->lang[arcadeking_txt1].''.$res['nb'].''.$ibforums->lang[arcadeking_txt2];
$Champion['ArcadeChampionMid'.$Cpt] = $res['champ_mid'];
}
for ($i = 1; $i <= $Cpt; ++$i) {
$DB->query('SELECT avatar,avatar_size AS size FROM ibf_members WHERE id='.$Champion['ArcadeChampionMid'.$i]);
if ($avatar = $DB->fetch_row()) {
$Champion['ArcadeChampionAvatarCode'.$i] = $std->get_avatar($avatar, 1, $avatar['size']);
if ($Champion['ArcadeChampionAvatarCode'.$i] == '') {
$Champion['ArcadeChampionAvatarCode'.$i] = "";
}
} else {
$Champion['ArcadeChampionAvatarCode'.$i] = "";
}
}
$std->time_options['ARCADE'] = "{$ibforums->lang['timeformat4']}";
$cattable = '';
$show_all = '';
if (isset($ibforums->input['cat'])) {
$cat = $ibforums->input['cat'];
} else {
$cat = $this->arcade->settings['def_cat'];
}
if (!is_numeric($cat)) {
$cat = 1;
}
$termine = 0;
$actifs = 0;
$attente = 0;
$DB->query('SELECT demare, champion FROM ibf_tournaments');
while ($row = $DB->fetch_row()) {
if ($row['demare'] == 0) {
++$attente;
} else {
if ($row['champion'] == '') {
++$actifs;
} else {
++$termine;
}
}
}
$termine = "$termine ".$ibforums->lang['finished_tourneys'].'';
$actifs = "$actifs ".$ibforums->lang['running_tourneys'].'';
if ($attente == 0) {
$attente = $ibforums->lang['no_tourney_waiting'];
} else {
$attente = "$attente ".$ibforums->lang['tourneys_waiting'].'';
}
$DB->query("SELECT tps.*, ta.tid FROM ibf_tournament_players_statut tps LEFT JOIN ibf_tournaments ta ON (tps.tid=ta.tid) WHERE tps.mid='".$ibforums->member['id']."' AND tps.statut<'3' AND ta.demare = '1'");
$mtinfo['encourse'] = 0;
$mtinfo['elimine'] = 0;
$mtinfo['disqualifie'] = 0;
if ($ibforums->member['id'] != 0) {
while ($res = $DB->fetch_row()) {
if ($res['statut'] == 0) {
++$mtinfo['encourse'];
}
if ($res['statut'] == 1) {
++$mtinfo['elimine'];
}
if ($res['statut'] == 2) {
++$mtinfo['disqualifie'];
}
}
}
$mtinfo['participe'] = $mtinfo['encourse'] + $mtinfo['elimine'] + $mtinfo['disqualifie'];
$mtinfo['participe'] = $ibforums->lang['active_in'].$mtinfo['participe'];
$mtinfo['encourse'] = $ibforums->lang['still_qualified'].' '.$mtinfo['encourse'];
$mtinfo['elimine'] = $ibforums->lang['eliminated_in'].' '.$mtinfo['elimine'];
$mtinfo['disqualifie'] = $ibforums->lang['disqualified_in'].' '.$mtinfo['disqualifie'];
$cat_counter = 0;
//Category System
if ($this->arcade->settings['use_cats']) {
$show_all = ' AND gcat='.$cat;
$categories = '';
if ($this->arcade->user['userid'] == 0) {
// this is a guest!
$DB->query('SELECT ibpa_cats FROM ibf_groups WHERE g_id = 1');
$guestperm = $DB->fetch_row();
$this->arcade->user['allowed_categories'] = $guestperm['ibpa_cats'];
}
$restrictedcats = false;
$allowedcats = explode(',', $this->arcade->user['allowed_categories']);
if (!in_array(0, $allowedcats)) {
$restrictedcats = true;
}
$DB->query('SELECT cat_name, c_id, show_all, password, num_of_games, description FROM ibf_games_cats WHERE active=1 ORDER BY pos ASC');
while ($the_cat = $DB->fetch_row()) {
$displaycat = true;
if ($restrictedcats) {
if (!in_array($the_cat['c_id'], $allowedcats)) {
$displaycat = false;
}
}
if ($displaycat) {
if ($cat == $the_cat['c_id']) {
$total_num = $the_cat['num_of_games'];
if ($the_cat['show_all'] == 1) {
$show_all = " AND trim(password)=''";
$the_cat['num_of_games'] = $ibforums->lang['acp_all'];
}
if ($the_cat['password'] != '') {
$the_cookie = 'cat_pass_'.$the_cat['c_id'];
$pass = ibp_cleansql($_COOKIE[$the_cookie]);
if ($pass != $the_cat['password']) {
$this->output .= $this->html->cat_pass($the_cat['c_id']);
return;
}
}
$the_cat['cat_name'] = ''.$the_cat['cat_name'].'';
if (strlen($the_cat['description']) > 2) {
$tourneyinfo['desc'] = $this->html->cat_desc($the_cat['description']);
} else {
$tourneyinfo['desc'] = '';
}
} else {
if ($the_cat['show_all'] == 1) {
$the_cat['num_of_games'] = $ibforums->lang['acp_all'];
}
}
if (intval($this->arcade->settings['cats_per_tr']) > 0) {
if ((($cat_counter % $this->arcade->settings['cats_per_tr']) == 0) && ($this->arcade->settings['cats_per_tr'] != 0) && ($cat_counter != 0)) {
$categories .= '
';
$cat_counter = 0;
}
}
$file = CAT_IMGS.$the_cat['c_id'].'.gif';
if (file_exists($file)) {
$the_cat['cat_name'] = " ".$the_cat['cat_name'];
}
$the_cat = ''.$the_cat['cat_name'].' ('.$the_cat['num_of_games'].')';
$categories .= $this->html->cat_cell($the_cat);
++$cat_counter;
}
}
if (($this->arcade->settings['cats_per_tr'] != 0) && ($this->arcade->settings['cats_per_tr'] - $cat_counter > 0)) {
$left_over = $this->arcade->settings['cats_per_tr'] - $cat_counter;
for ($a = 1; $a <= $left_over; ++$a) {
$categories .= $this->html->cat_cell(' ');
}
}
$cattable = $this->html->the_cat_table($categories, $stylecolumns);
$extquery = '';
$DB->query('SELECT mid, gid, sum(position) AS position, sum(points) AS points FROM ibf_games_league '.$extquery.' GROUP BY mid ORDER BY points DESC LIMIT 1');
$row = $DB->fetch_row();
if ($row['mid'] > 0) {
$DB->query('SELECT name FROM ibf_members WHERE id='.$row['mid']);
$row = $DB->fetch_row();
$tourneyinfo['catchamp'] = $row['name'];
} else {
$tourneyinfo['catchamp'] = $ibforums->lang['nobody'];
}
if ($this->arcade->settings['skin'] != 0) {
$tourneyinfo['catchamp'] = ''.$tourneyinfo['catchamp'].' '.$ibforums->lang['category_champion'].'';
} else {
$tourneyinfo['catchamp'] = ''.$tourneyinfo['catchamp'].'';
}
}
//End category table building.
$query_limit = '';
if ($this->arcade->settings['games_pp'] && ($ibforums->input['gsearch'] == '')) {
$this->arcade->get_pages(0, $this->arcade->settings['use_cats'], $total_num);
$start = 0;
if (isset($ibforums->input['st'])) {
$start = intval($ibforums->input['st']);
}
if ($start < 0) {
$start = 0;
}
$query_limit = 'LIMIT '.$start.', '.$this->arcade->settings['games_pp'];
}
//tourney stuff
$tourneyinfo['active'] = 0;
$tourneyinfo['unactive'] = 0;
$tourneyinfo['numenrolled'] = 0;
$tourneyinfo['championships'] = 0;
$tourneyinfo['playable'] = $ibforums->lang['no_active'];
$DB->query('SELECT champion FROM ibf_tournaments');
while ($this_tourney = $DB->fetch_row()) {
if ($this_tourney['champion'] == $this->arcade->user['name']) {
++$tourneyinfo['championships'];
}
if ($this_tourney['champion'] == '') {
++$tourneyinfo['active'];
} else {
++$tourneyinfo['unactive'];
}
}
$DB->query("SELECT DISTINCT(p.tid) FROM ibf_tournaments as t, ibf_tournament_players as p WHERE t.tid=p.tid AND t.champion='' AND p.mid = '".$this->arcade->user['id']."' ORDER BY t.datestarted ASC");
while ($this_tourney = $DB->fetch_row()) {
++$tourneyinfo['numenrolled'];
$tourneyinfo['playable'] = "".$ibforums->lang['view_latest_active'].'';
}
//plays left today
$plays_left = '';
if ($this->arcade->user['max_play'] != 0 && $this->arcade->user['arcade_access'] == 2) {
$plays_left = $ibforums->lang['plays'].($this->arcade->user['max_play'] - $this->arcade->user['times_played']);
}
//latest score and champions
//Added g.decpoints after g.title
$DB->query("SELECT s.*, g.gtitle, g.decpoints, c.password FROM ibf_games_scores AS s, ibf_games_list AS g, ibf_games_cats AS c WHERE s.gid=g.gid AND g.gcat=c.c_id AND g.active=1 AND trim(password)='' ORDER BY datescored DESC LIMIT 0,5");
$newest_score = $DB->fetch_row();
//$newest_score['score'] = $this->arcade->t3h_format($newest_score['score']);
// Replaced
$newest_score['score'] = $this->arcade->do_arcade_format($newest_score['score'], $newest_score['decpoints']);
if ($this->arcade->settings['use_announce']) {
$announce = $this->arcade->settings['announcement_parsed'];
$tourneyinfo['announcement'] = $this->html->generalbox($ibforums->lang['arcade_announcements'], $announce);
} else {
$tourneyinfo['announcement'] = '';
}
$latestinfo = $ibforums->lang['newest_score'];
$latestinfo = preg_replace('/<% NAME %>/i', $newest_score['name'], $latestinfo);
$latestinfo = preg_replace('/<% SCORE %>/i', $newest_score['score'], $latestinfo);
$latestinfo = preg_replace('/<% GAME %>/i', $newest_score['gtitle'], $latestinfo);
$newtext = '';
$DB->query("SELECT c.*, g.gcat, cat.password FROM ibf_games_champs AS c, ibf_games_list AS g, ibf_games_cats AS cat WHERE c.champ_gid=g.gid AND g.gcat=cat.c_id AND g.active=1 AND trim(password)='' ORDER BY champ_date DESC LIMIT 0,5");
while ($row = $DB->fetch_row()) {
$row['champ_date'] = $std->get_date($row['champ_date'], 'ARCADE');
if ($row['champ_date'] == date("{$ibforums->lang['timeformat4']}")) {
$row['champ_date'] = $ibforums->lang['today'];
} else {
if ($ibforums->lang[timeformat1] == 'de') {
$yesterday = date("{$ibforums->lang['timeformat4']}", mktime(0, 0, 0, date('d') - 1, date('m'), date('Y')));
} else {
$yesterday = date("{$ibforums->lang['timeformat4']}", mktime(0, 0, 0, date('m') - 1, date('d'), date('Y')));
}
if ($row['champ_date'] == $yesterday) {
$row['champ_date'] = $ibforums->lang['yesterday'];
}
}
$row['text'] = $ibforums->lang['new_champ'];
$row['text'] = preg_replace('/<% USERNAME %>/i', $row['champ_name'], $row['text']);
$row['text'] = preg_replace('/<% GAMENAME %>/i', $row['champ_gtitle'], $row['text']);
$newtext .= $this->html->newest_champs_row($row);
}
$DB->query('SELECT mid, gid, sum(position) AS position, sum(points) AS points FROM ibf_games_league GROUP BY mid ORDER BY points DESC LIMIT 1');
$row = $DB->fetch_row();
$points = $row['points'];
$name = '';
if ($row['mid'] > 0) {
$Touruserid = $row['mid'];
$DB->query('SELECT name FROM ibf_members WHERE id='.$Touruserid);
$row = $DB->fetch_row();
$name = $name.$row['name'].'';
$tourneyinfo['champ'] = ''.$name." {$ibforums->lang['tourneyinfo_txt1']}".$points."{$ibforums->lang['tourneyinfo_txt2']}";
$tourneyinfo['champavatar'] = '';
$DB->query('SELECT avatar,avatar_size AS size FROM ibf_members WHERE id='.$Touruserid);
if ($avatar = $DB->fetch_row()) {
$tourneyinfo['champavatar'] = $std->get_avatar($avatar, 1, $avatar['size']);
if ($tourneyinfo['champavatar'] == '') {
$tourneyinfo['champavatar'] = "";
}
} else {
$tourneyinfo['champavatar'] = "";
}
} else {
$tourneyinfo['champ'] = "{$ibforums->lang['top3box_norank']}";
$tourneyinfo['champavatar'] = '';
}
$usecats = $this->arcade->settings['use_cats'];
$defcat = $this->arcade->settings['def_cat'];
// alpha-navbar by MrZeropage
$alphabet = array('ALL', '0-9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', );
$alphabar = '';
$currentfilter = 'ALL';
if ($ibforums->input['gsearch'] != '') {
$currentfilter = $ibforums->input['gsearch'];
}
foreach ($alphabet as $letter) {
$style = 'alt1';
$boldon = '';
$boldoff = '';
$width = '18';
$urlstring = 'act=Arcade&gsearch='.$letter.'&search_type=';
if ($letter == '0-9') {
$urlstring .= '3';
$width = '24';
} else {
$urlstring .= '1';
}
if ($letter == $currentfilter) {
$style = 'alt2';
$boldon = '';
$boldoff = '';
}
if ($letter == 'ALL') {
$urlstring = '';
$letter = $ibforums->lang['acp_all'];
$width = '26';
}
if (isset($ibforums->input['cat'])) {
$urlstring .= '&cat='.intval($ibforums->input['cat']);
}
$alphabar .= '
';
// detect vBplaza
if (($vbulletin->options['vbbux_enabled'] == 1) && ($vbulletin->options['vbbux_arcadeintegration'] == 1)) {
$the_game['ibprostyle_info1'] = " ';
$the_game['v3style_info'] = ' ';
$the_game['cost_info'] = $ibforums->lang['costs_pgame'].''.$the_game['cost'].' ';
if ($the_game['jackpot_type'] == '-1') {
// raising Jackpot, so display it in GameBit!
$the_game['jackpot_info'] = $ibforums->lang['gb_win_jackpot_raising'].''.$the_game['jackpot'].'';
} else {
// static Jackpot
$the_game['jackpot_info'] = $ibforums->lang['gb_win_jackpot_static'].''.$the_game['jackpot'].'';
}
}
$this->output .= $this->html->row($the_game, $gamesplit, $top, $pbesttext, $this->arcade->links, $rowcol, $rating, $actualtop, $newgame, $stylecolumns);
++$game_counter;
}
$this->output .= $this->html->stop($this->arcade->links['pages']);
$this->page_title = $ibforums->vars['board_name'].' -> '.$ibforums->lang['page_title'];
$this->nav = array($ibforums->lang['page_title']);
}
//------------------------------------------
// Play_Game
//
// This brings up the game to play
//
//------------------------------------------
public function play_game()
{
global $ibforums, $DB, $std, $vboptions, $vbulletin, $DEBUGMODE, $NATIVEMODE;
if (($GROUP['max_play'] - $ibforums->member['times_played']) <= 0 && $GROUP['max_play'] != 0) {
$std->Error(array(LEVEL => 1, MSG => 'max'));
}
$id = intval($ibforums->input['gameid']);
if ($id < 1) {
$id = 1;
}
setcookie('gidstarted', '', time() - 3600);
setcookie('gidstarted', $id);
setcookie('tidstarted', '', time() - 3600);
setcookie('gpstarted', time());
if (!preg_match("/^(\d+)$/", $id)) {
$std->Error(array(LEVEL => 1, MSG => 'no_help_file'));
}
$DB->query('SELECT * FROM ibf_games_list WHERE gid='.$id);
$game = $DB->fetch_row();
$game['hash'] = $hash;
$randomchar = '1';
$randomchar2 = '1';
// only run this if the game is using the new code
if ((file_exists(ROOT_PATH.'arcade/gamedata/'.$game['gname'].'/v32game.txt')) || (file_exists(ROOT_PATH.'arcade/gamedata/'.$game['gname'].'/v3game.txt'))) {
$randomchar = rand(1, 10);
$randomchar2 = rand(1, 5);
$game['gidencoded'] = $game['gid'] * $randomchar ^ $randomchar2;
}
if ($this->arcade->user['arcade_access'] > 2) {
// this is a guest
// create a hash for that guest playing
srand((double) microtime() * 1000000);
$guesthash = rand(100000, 999999);
setcookie('guesthash', $guesthash);
if ($_COOKIE['ibPAcookiecheck'] != 'yesss') {
$server = strtolower($_SERVER['HTTP_REFERER']);
if (strpos($server, 'arcade.php') > 0) {
$VERBOSE = ($DEBUGMODE == 2) ? ' cookie #001 -> ghash='.$guesthash.' | ibPAcheck='.$_COOKIE['ibPAcookiecheck'] : '';
$std->Error(array(LEVEL => 1, MSG => 'cat_pass_notice', EXTRA => $VERBOSE));
} else {
// game called directly (without arcade.php), so set cookie NOW for later verification
setcookie('ibPAcookiecheck', 'yesss');
}
}
// now create session-entry...
$DB->query("INSERT INTO ibf_games_session (gname, gameid, gtitle, mname, mid, randgid, randgid2) VALUES ('".addslashes($game['gname'])."', '".$game['gid']."', '".addslashes($game['gtitle'])."', '".$guesthash."', '0', '".$randomchar."', '".$randomchar2."')");
$sessionid = $DB->get_insert_id();
setcookie('guestsession', $sessionid);
} else {
// prune any old session from that user
$DB->query('DELETE FROM ibf_games_session WHERE mid='.$this->arcade->user['id']);
// now create session-entry...
$DB->query("INSERT INTO ibf_games_session (gname, gameid, gtitle, mname, mid, randgid, randgid2) VALUES ('".addslashes($game['gname'])."', '".$game['gid']."', '".addslashes($game['gtitle'])."', '".addslashes($this->arcade->user['name'])."', '".$this->arcade->user['id']."', '".$randomchar."', '".$randomchar2."')");
$sessionid = $DB->get_insert_id();
// ...and store session-info in userprofile
$DB->query("UPDATE ibf_members SET times_played=times_played+1, arcade_sess_gid='".$game['gid']."', arcade_sess_start='".time()."', arcade_gtype=0, arcade_session='".$sessionid."' WHERE id=".$this->arcade->user['id']);
}
$DB->query('SELECT champ_name AS name,champ_score AS score FROM ibf_games_champs WHERE champ_gid='.$id);
$top = $DB->fetch_row();
$DB->query('UPDATE ibf_games_list SET gcount=gcount+1 WHERE gid='.$id);
$top['score'] = $this->arcade->do_arcade_format($top['score'], $game['decpoints']);
if ($top['name'] == '') {
$top['name'] = $ibforums->lang['top3box_norank'];
}
/***********************************************************************
pnFlashGames Modification:
Add in extra information to the $game array so that it can be displayed properly
and so that the pnFlashGames component can get the information it needs
*/
$game['username'] = $player_name = $this->arcade->user['name'];
$game['checksum'] = $this->pnFlashGames_getChecksum($game['gname']);
$game['domain'] = $this->pnFlashGames_getDomain(); //couldnt get this to work for some reason
/**********************************************************************/
$extra_html = '';
if (trim($game['object']) != '') {
$extra_html .= $this->html->objective($game);
}
if (trim($game['gkeys']) != '') {
$extra_html .= $this->html->keys($game);
}
//fav games
$temp = unserialize($this->arcade->user['favs']);
if (!is_array($temp)) {
$temp = array();
}
$favs = $temp;
$favtitle = $ibforums->lang['add_to_faves'];
$favtitle = preg_replace('/<% GAMENAME %>/i', $game['gtitle'], $favtitle);
$star = '';
if (in_array($game['gid'], $favs)) {
$star = " ";
$favtitle = $ibforums->lang['remove_from_faves'];
$favtitle = preg_replace('/<% GAMENAME %>/i', $game['gtitle'], $favtitle);
}
if ($this->arcade->user['arcade_access'] == 2 && $this->arcade->user['id']) {
$game['fave'] = $star."$favtitle";
}
$vbversion = substr($vboptions[templateversion], 0, 3);
if (($vbversion != '3.0') && ($NATIVEMODE == 0)) {
($hook = vBulletinHook::fetch_hook('ibproarcade_play_game')) ? eval($hook) : false;
}
$this->output .= $this->html->game($game, $top, $extra_html);
$this->page_title = $ibforums->vars['board_name'].' -> '.$ibforums->lang['page_title'].' -> '.$game['gtitle'];
$this->nav = array('{$ibforums->lang['page_title']}", $game['gtitle']);
}
//------------------------------------------
// Play_Game In Popup Window v1.0
//
// This will allow users to play game in new window
//
//------------------------------------------
public function playfull()
{
global $ibforums, $DB, $std, $vboptions, $vbulletin, $DEBUGMODE, $NATIVEMODE;
if (($GROUP['max_play'] - $ibforums->member['times_played']) <= 0 && $GROUP['max_play'] != 0) {
$std->Error(array(LEVEL => 1, MSG => 'max'));
}
$id = intval($ibforums->input['gameid']);
if ($id < 1) {
$id = 1;
}
setcookie('gidstarted', '', time() - 3600);
setcookie('gidstarted', $id);
setcookie('tidstarted', '', time() - 3600);
setcookie('gpstarted', time());
$DB->query('SELECT * FROM ibf_games_list WHERE gid='.$id);
$game = $DB->fetch_row();
$game['hash'] = $hash;
$randomchar = '1';
$randomchar2 = '1';
// only run this if the game is using the new code
if ((file_exists(ROOT_PATH.'arcade/gamedata/'.$game['gname'].'/v32game.txt')) || (file_exists(ROOT_PATH.'arcade/gamedata/'.$game['gname'].'/v3game.txt'))) {
$randomchar = rand(1, 10);
$randomchar2 = rand(1, 5);
$game['gidencoded'] = $game['gid'] * $randomchar ^ $randomchar2;
}
if ($this->arcade->user['arcade_access'] > 2) {
// this is a guest
// create a hash for that guest playing
srand((double) microtime() * 1000000);
$guesthash = rand(10, 99);
setcookie('guesthash', $guesthash);
// check if cookies are working
if ($_COOKIE['ibPAcookiecheck'] != 'yesss') {
$VERBOSE = ($DEBUGMODE == 2) ? ' cookie #002 -> ghash='.$guesthash.' | ibPAcheck='.$_COOKIE['ibPAcookiecheck'] : '';
$std->Error(array(LEVEL => 1, MSG => 'cat_pass_notice', EXTRA => $VERBOSE));
}
// now create session-entry...
$DB->query("INSERT INTO ibf_games_session (gname, gameid, gtitle, mname, mid, randgid, randgid2) VALUES ('".addslashes($game['gname'])."', '".$game['gid']."', '".addslashes($game['gtitle'])."', '".$guesthash."', '0', '".$randomchar."', '".$randomchar2."')");
$sessionid = $DB->get_insert_id();
setcookie('guestsession', $sessionid);
} else {
// prune any old session from that user
$DB->query('DELETE FROM ibf_games_session WHERE mid='.$this->arcade->user['id']);
// now create session-entry...
$DB->query("INSERT INTO ibf_games_session (gname, gameid, gtitle, mname, mid, randgid, randgid2) VALUES ('".addslashes($game['gname'])."', '".$game['gid']."', '".addslashes($game['gtitle'])."', '".addslashes($this->arcade->user['name'])."', '".$this->arcade->user['id']."', '".$randomchar."', '".$randomchar2."')");
$sessionid = $DB->get_insert_id();
// ...and store session-info in userprofile
$DB->query("UPDATE ibf_members SET times_played=times_played+1, arcade_sess_gid='".$game['gid']."', arcade_sess_start='".time()."', arcade_gtype=0, arcade_session='".$sessionid."' WHERE id=".$this->arcade->user['id']);
}
if (!preg_match("/^(\d+)$/", $id)) {
$std->Error(array(LEVEL => 1, MSG => 'no_help_file'));
}
$DB->query('SELECT champ_name AS name,champ_score AS score FROM ibf_games_champs WHERE champ_gid='.$id);
$top = $DB->fetch_row();
$DB->query('UPDATE ibf_games_list SET gcount=gcount+1 WHERE gid='.$id);
/***********************************************************************
pnFlashGames Modification:
Add in extra information to the $game array so that it can be displayed properly
and so that the pnFlashGames component can get the information it needs
*/
$game['username'] = $player_name = $this->arcade->user['name'];
$game['checksum'] = $this->pnFlashGames_getChecksum($game['gname']);
$game['domain'] = $this->pnFlashGames_getDomain(); //couldnt get this to work for some reason
/**********************************************************************/
$vbversion = substr($vboptions[templateversion], 0, 3);
if (($vbversion != '3.0') && ($NATIVEMODE == 0)) {
($hook = vBulletinHook::fetch_hook('ibproarcade_play_game_popup')) ? eval($hook) : false;
}
echo <<{$ibforums->lang['popuptitle']}{$game['gname']}
EOF;
exit();
}
//------------------------------------------
// Play_Tourney
//
// This brings up the game to play
//
//------------------------------------------
public function play_tourney()
{
global $ibforums, $DB, $std, $vboptions, $vbulletin, $guestplayerid, $NATIVEMODE;
$id = intval($ibforums->input['gameid']);
$tid = intval($ibforums->input['tid']);
$rung = intval($ibforums->input['rung']);
$faceoff = intval($ibforums->input['faceoff']);
setcookie('gidstarted', '', time() - 3600);
setcookie('gidstarted', $id);
setcookie('tidstarted', '', time() - 3600);
setcookie('tidstarted', $tid);
if ($guestplayerid == $this->arcade->user['id']) {
$std->Error(array('LEVEL' => 1, 'MSG' => 'no_tourney_user'));
}
$DB->query('SELECT nbtries FROM ibf_tournaments WHERE tid='.$tid);
$readrow = $DB->fetch_row();
$nbtries = $readrow['nbtries'];
$DB->query('SELECT * FROM ibf_tournament_players WHERE mid='.$this->arcade->user['id'].' AND tid='.$tid.' AND timesplayed<'.$nbtries.' AND rung='.$rung);
$ctr = 0;
while ($row = $DB->fetch_row()) {
++$ctr;
}
if ($ctr == 0) {
$std->Error(array(LEVEL => 1, MSG => 'passed_times_played'));
}
if (!preg_match("/^(\d+)$/", $id)) {
$std->Error(array(LEVEL => 1, MSG => 'no_help_file'));
}
$DB->query('SELECT * FROM ibf_games_list WHERE gid='.$id);
$game = $DB->fetch_row();
$randomchar = '1';
$randomchar2 = '1';
// prune any old session from that user
$DB->query('DELETE FROM ibf_games_session WHERE mid='.$this->arcade->user['id']);
// now create session-entry...
$DB->query("INSERT INTO ibf_games_session (gname, gameid, gtitle, mname, mid) VALUES ('".addslashes($game['gname'])."', '".$game['gid']."', '".addslashes($game['gtitle'])."', '".addslashes($this->arcade->user['name'])."', '".$this->arcade->user['id']."')");
$sessionid = $DB->get_insert_id();
// ...and store session-info in userprofile
$DB->query("UPDATE ibf_members SET times_played=times_played+1, arcade_sess_gid='".$game['gid']."', arcade_sess_start='".time()."', arcade_gtype=1, arcade_session='".$sessionid."' WHERE id=".$this->arcade->user['id']);
$DB->query('SELECT m.name, t.rungscore, t.timesplayed FROM ibf_members as m, ibf_tournament_players as t WHERE m.id = t.mid AND t.tid='.$tid.' AND t.rung='.$rung.' AND t.faceoff='.$faceoff.' AND t.mid<>'.$this->arcade->user['id'].' LIMIT 0, 1');
$top = $DB->fetch_row();
$DB->query('UPDATE ibf_games_list SET gcount=gcount+1 WHERE gid='.$id);
$DB->query('UPDATE ibf_tournament_players SET timesplayed=timesplayed+1, notified=0 WHERE tid='.$tid.' AND mid='.$this->arcade->user['id'].' AND rung='.$rung);
/***********************************************************************
pnFlashGames Modification:
Add in extra information to the $game array so that it can be displayed properly
and so that the pnFlashGames component can get the information it needs
*/
$game['username'] = $player_name = $this->arcade->user['name'];
$game['checksum'] = $this->pnFlashGames_getChecksum($game['gname']);
$game['domain'] = $this->pnFlashGames_getDomain();
/**********************************************************************/
$top['nbtries'] = $nbtries;
$top['rungscore'] = $this->arcade->do_arcade_format($top['rungscore'], $game['decpoints']);
$top['playertext'] = $ibforums->lang['tourney_opponent'];
$top['name'] .= " (".$ibforums->lang['tourney_playinfo1'].' '.$top['timesplayed'].'/'.$top['nbtries'].' '.$ibforums->lang['tourney_playinfo2'].')';
$top['scoretext'] = $ibforums->lang['tourney_scoretext1'];
if ($top['timesplayed'] == 0) {
$top['scoretext'] = $ibforums->lang['tourney_scoretext2'];
$top['rungscore'] = '';
}
if ($top['timesplayed'] == $top['nbtries']) {
$top['scoretext'] = $ibforums->lang['tourney_scoretext3'];
}
$game['ginfotxt'] = "
*** ".$ibforums->lang['gtourneyinfotxt1']." ***
".$ibforums->lang['gtourneyinfotxt2'].'
';
$game['extra'] = '';
if (trim($game['object']) != '') {
$game['extra'] .= $this->html->objective($game);
}
if (trim($game['gkeys']) != '') {
$game['extra'] .= $this->html->keys($game);
}
$vbversion = substr($vboptions[templateversion], 0, 3);
if (($vbversion != '3.0') && ($NATIVEMODE == 0)) {
($hook = vBulletinHook::fetch_hook('ibproarcade_play_game_tourney')) ? eval($hook) : false;
}
$this->output .= $this->html->tourneygame($game, $top, $tid);
$this->page_title = $ibforums->vars['board_name'].' -> '.$ibforums->lang['page_title'].' -> '.$game['gtitle'];
$this->nav = array("{$ibforums->lang['page_title']}", $game['gtitle']);
}
//----------------------------------------
// Show_Stats
//
// This shows the leaderboard
//
//----------------------------------------
public function show_stats()
{
global $ibforums, $DB, $std, $vbulletin, $vboptions;
// clean incoming stuff...
$ibforums->input['comment'] = ibp_cleanhtml(ibp_cleansql($ibforums->input['comment']));
$ibforums->input['s_id'] = intval($ibforums->input['s_id']);
$ibforums->input['gameid'] = intval($ibforums->input['gameid']);
if ($ibforums->input['comment'] != '') {
if (isset($ibforums->input['s_id']) && $ibforums->input['s_id'] != '') {
$DB->query("UPDATE ibf_games_scores SET comment='".$ibforums->input['comment']."' WHERE s_id=".$ibforums->input['s_id']);
} else {
$DB->query("UPDATE ibf_games_scores SET comment='".$ibforums->input['comment']."' WHERE mid=".$this->arcade->user['id'].' AND gid='.$ibforums->input['gameid']);
}
}
$query_limit = '';
if ($this->arcade->settings['scores_amount']) {
$this->arcade->get_pages(1);
$start = 0;
if (isset($ibforums->input['st'])) {
$start = intval($ibforums->input['st']);
}
$query_limit = 'LIMIT '.$start.', '.$this->arcade->settings['scores_amount'];
}
$id = intval($ibforums->input['gameid']);
$DB->query('SELECT g.gid,g.gname,g.gtitle,g.gwords,g.gcat,g.highscore_type,g.decpoints, c.* FROM ibf_games_list AS g, ibf_games_champs AS c WHERE (g.gid = c.champ_gid) AND gid='.$id);
if ($DB->get_num_rows()) {
$ginfo = $DB->fetch_row();
//$ginfo['champ_score'] = $this->arcade->t3h_format($ginfo['champ_score']);
//replaced
$ginfo['champ_score'] = $this->arcade->do_arcade_format($ginfo['champ_score'], $ginfo['decpoints']);
if (!empty($ginfo['champ_mid'])) {
$DB->query('SELECT avatar,avatar_size AS size FROM ibf_members WHERE id='.$ginfo['champ_mid']);
$avatar = $DB->fetch_row();
$ginfo['avatarcode'] = $std->get_avatar($avatar, 1, $avatar['size']);
}
} else {
$DB->query('SELECT * FROM ibf_games_list WHERE gid='.$id);
$ginfo = $DB->fetch_row();
}
$ginfo['avatarcode'] = (empty($ginfo['avatarcode'])) ? "" : $ginfo['avatarcode'];
// favorites-link
$temp = unserialize($this->arcade->user['favs']);
if (!is_array($temp)) {
$temp = array();
}
$favs = $temp;
$favtitle = $ibforums->lang['add_to_faves'];
$favtitle = preg_replace('/<% GAMENAME %>/i', $game['gtitle'], $favtitle);
$star = '';
if (in_array($ginfo['gid'], $favs)) {
//$star = " ";
$favtitle = $ibforums->lang['remove_from_faves'];
$favtitle = preg_replace('/<% GAMENAME %>/i', $ginfo['gtitle'], $favtitle);
}
if ($this->arcade->user['arcade_access'] == 2 && $this->arcade->user['id']) {
$ginfo['fave'] = "$favtitle";
}
// make the link fit everything ;)
$ginfo['backlink'] = $ibforums->lang['arcade_home'];
if ($this->arcade->settings['use_cats']) {
$ginfo['backlink'] = $ibforums->lang['showothersincat'];
}
$this->arcade->make_links($ginfo['gid'], $ginfo['gtitle']);
$this->output .= $this->html->leaderstart($ginfo, $this->arcade->links);
$DB->query('SELECT mid FROM ibf_games_scores WHERE gid='.$id);
$num_scores = 0;
while ($nsarray = $DB->fetch_row()) {
++$num_scores;
}
$ordering = ($ginfo['highscore_type'] == 'high') ? 'DESC' : 'ASC';
//$this_query = $DB->query("SELECT * FROM ibf_games_scores WHERE gid=".$id." ORDER BY score ".$ordering.", datescored ASC ".$query_limit);
$this_query = $DB->query('SELECT * FROM ibf_games_scores WHERE gid='.$id.' ORDER BY score '.$ordering.',timespent ASC '.$query_limit);
$ctr = $start + 1;
$intctr = 1;
$rowcol = 'alt2';
while ($lboard = $DB->fetch_row($this_query)) {
//$lboard['comment'] = array( 'TEXT' => $lboard['comment'], 'SMILIES' => 1, 'CODE' => 1, 'SIGNATURE' => 0, 'HTML' => 0);
//$lboard['comment'] = $this->parser->convert($lboard['comment']);
// parse the comment
$vbversion = substr($vboptions[templateversion], 0, 3); // Version 3.0 oder 3.5
if ($vbversion == '3.0') {
require_once './includes/functions_bbcodeparse.php';
$parsed_comment = parse_bbcode($lboard['comment']);
} else {
require_once './includes/class_bbcode.php';
$bbcode_parser = &new vB_BbCodeParser($vbulletin, fetch_tag_list());
$parsed_comment = $bbcode_parser->parse($lboard['comment'], 0, 1);
}
$lboard['comment'] = $parsed_comment;
if ($ibforums->lang[timeformat1] == 'de') {
$std->time_options['LROW'] = "{$ibforums->lang['timeformat2']} \u\m {$ibforums->lang['timeformat3']}";
} else {
$std->time_options['LROW'] = "{$ibforums->lang['timeformat2']} {$ibforums->lang['timeformat3']}";
}
$formatteddate = $std->get_date($lboard['datescored'], 'LROW');
$usercell = "";
$usercell .= "{$lboard[name]}";
$datecell = $formatteddate;
$scorecell = $this->arcade->do_arcade_format($lboard['score'], $ginfo['decpoints']);
if ($lboard['timespent'] == 0) {
$lboard['timespent'] = $ibforums->lang['n_a'];
} else {
$lboard['timespent'] = $this->arcade->thatdate($lboard['timespent']);
}
if ($this->arcade->settings['skin'] != 0) {
if ($rowcol == 'alt1') {
$rowcol = 'alt2';
} else {
$rowcol = 'alt1';
}
}
$this->output .= $this->html->leaderrow($lboard, $ctr, $usercell, $datecell, $scorecell, $rowcol);
++$ctr;
++$intctr;
++$start_row;
}
$this->output .= $this->html->stop($this->arcade->links['pages']);
$this->page_title = $ibforums->vars['board_name'].' -> '.$ibforums->lang['page_title'].' -> '.$ibforums->lang['arcade_scores'];
$this->nav = array("{$ibforums->lang['page_title']}", "{$ibforums->lang['hscores_title']}");
}
// #######################################
// new function for secure games (v32/v33)
// #######################################
public function verify_score()
{
global $DB, $DEBUGMODE;
list($usec, $sec) = explode(' ', microtime());
$gametime = ((float) $usec + (float) $sec);
$randomchar = rand(1, 10);
$randomchar2 = rand(1, 5);
if ($this->arcade->user['arcade_access'] > 2) {
// this is a guest
$userinfo['arcade_session'] = intval($_COOKIE['guestsession']);
} else {
$userquery = $DB->query('SELECT * FROM ibf_user WHERE userid='.$this->arcade->user['id']);
$userinfo = $DB->fetch_row($userquery);
}
if ($userinfo['arcade_session'] == '') {
$ERRORLEVEL = ($DEBUGMODE == 0) ? '' : 'Error #021 - no session';
$std->Error(array(LEVEL => 1, MSG => 'cheater', EXTRA => $ERRORLEVEL));
}
$DB->query("SELECT sessd FROM ibf_games_session WHERE sessid='".$userinfo['arcade_session']."'");
$s = $DB->fetch_row();
if (!$DB->get_num_rows()) {
die();
}
if ($s['sessd'] != 1) {
$DB->query("UPDATE ibf_games_session SET randchar1 = '".$randomchar."' , randchar2 = '".$randomchar2."' , start = '".$gametime."' , sessd = 1 WHERE sessid = '".$userinfo['arcade_session']."'");
//sleep(1); // Do not unedit this unless your instructed to !
// Do not edit this line!
echo "&randchar=$randomchar&randchar2=$randomchar2&savescore=1&blah=OK";
exit();
}
}
public function save_score()
{
// ### for new, secured ibPro-Games
global $DB, $ibforums, $std, $DEBUGMODE, $FIXIE, $vboptions, $vbulletin, $NATIVEMODE;
$tgame = 0;
$player_ip = $ibforums->input['IP_ADDRESS'];
$player_score = isset($ibforums->input['gscore']) ? $ibforums->input['gscore'] : 0;
$gidencoded = isset($ibforums->input['arcadegid']) ? $ibforums->input['arcadegid'] : 0;
$genscore = $ibforums->input['enscore'];
$swfgname = $ibforums->input['gname'];
$player_score_encode = $player_score;
// ### protection for external scripts faking incoming gamedata
// ### by MrZeropage
// look who sends the POST-data...
$referer = '';
if ($_SERVER['REFERER'] != '') {
$referer = strtolower($_SERVER['REFERER']);
}
if ($_SERVER['HTTP_REFERER'] != '') {
$referer = strtolower($_SERVER['HTTP_REFERER']);
}
if ($HTTP_SERVER_VARS['REFERER'] != '') {
$referer = strtolower($HTTP_SERVER_VARS['REFERER']);
}
// avoid external scripts calling this function
if ((strpos($referer, 'arcade.php') > 0) && (strpos($referer, $vboptions[bburl]) > 0)) {
// maybe there is some cheater trying to inject a score ?! *boooooh*
$VERBOSE = ($DEBUGMODE == 2) ? ' -> referrercheck | referer='.$referer : '';
$ERRORLEVEL = ($DEBUGMODE == 0) ? '' : 'Error #002';
$ERRORLEVEL = $ERRORLEVEL.$VERBOSE;
$std->Error(array(LEVEL => 1, MSG => 'cheater', EXTRA => $ERRORLEVEL));
}
// ###
if ($this->arcade->user['arcade_access'] == 3) {
// This is a Guest that won't record any score
$player_score = 0;
$good_score = 1;
}
if ($this->arcade->user['arcade_access'] > 2) {
// this is a guest
$userinfo['arcade_session'] = intval($_COOKIE['guestsession']);
$userinfo['arcade_sess_start'] = $_COOKIE['gpstarted'];
$userinfo['arcade_gtype'] = 0; // guests never play tourneys!
$userinfo['arcade_sess_gid'] = intval($_COOKIE['gidstarted']);
$player_name = $this->arcade->user['name'];
} else {
$userquery = $DB->query('SELECT * FROM ibf_user WHERE userid='.$this->arcade->user['id']);
$userinfo = $DB->fetch_row($userquery);
$player_name = $userinfo['username'];
}
$DB->query('SELECT * FROM ibf_games_list WHERE gid='.$userinfo['arcade_sess_gid']);
$g = $DB->fetch_row();
// Kiss Cookies good bye!
if (!isset($userinfo['arcade_gtype']) || $userinfo['arcade_gtype'] == '0') {
$tgame = 0;
$tid = 0;
} else {
$tgame = 1;
$tid = $userinfo['arcade_gtype'];
}
if ($userinfo['arcade_session'] == '') {
$ERRORLEVEL = ($DEBUGMODE == 0) ? '' : 'Error #022 - no session';
$std->Error(array(LEVEL => 1, MSG => 'cheater', EXTRA => $ERRORLEVEL));
}
$DB->query("SELECT * FROM ibf_games_session WHERE sessid='".$userinfo['arcade_session']."' LIMIT 1");
$vs = $DB->fetch_row();
$gid = $vs['gameid'];
$vbversion = substr($vboptions[templateversion], 0, 3);
if (($vbversion != '3.0') && ($NATIVEMODE == 0)) {
($hook = vBulletinHook::fetch_hook('ibproarcade_savescore_readsessiondata')) ? eval($hook) : false;
}
if ((($vs['sessd'] != 1) && ($vs['sessid'] > 0)) && ($FIXIE == 1)) {
// this score has NOT run through the verify() function!
// actual issue using IE7 and doing more than one play per game
// make it valid anyway ;)
list($usec, $sec) = explode(' ', microtime());
$gametime = ((float) $usec + (float) $sec);
$randomchar = rand(1, 10);
$randomchar2 = rand(1, 5);
$vs['sessd'] = 1;
$vs['start'] = $gametime;
$vs['randchar1'] = $randomchar;
$vs['randchar2'] = $randomchar2;
$genscore = $player_score * $vs['randchar1'] ^ $vs['randchar2'];
}
// for the new games...
if ((file_exists(ROOT_PATH.'arcade/gamedata/'.$g['gname'].'/v32game.txt')) || (file_exists(ROOT_PATH.'arcade/gamedata/'.$g['gname'].'/v3game.txt'))) {
$encoded_gid = $vs['gameid'] * $vs['randgid'] ^ $vs['randgid2'];
if ($gidencoded == 0) {
$gidencoded = $g['gid'] * $vs['randgid'] ^ $vs['randgid2'];
}
}
$decodescore = $player_score * $vs['randchar1'] ^ $vs['randchar2'];
list($usec, $sec) = explode(' ', microtime());
$time_end = ((float) $usec + (float) $sec);
$timecheck = round($time_end - $vs['start'], 4);
$DB->query('DELETE FROM ibf_games_session WHERE sessid='.$userinfo['arcade_session']);
if (($vs['sessd'] != 1) || (!$vs['start']) || (!$vs['sessid'])) {
$ERRORLEVEL = ($DEBUGMODE == 0) ? '' : 'Error #003';
$BROWSERDATA = ($_SERVER['HTTP_USER_AGENT'] != '') ? $_SERVER['HTTP_USER_AGENT'] : $HTTP_SERVER_VARS['HTTP_USER_AGENT'];
$VERBOSE = ($DEBUGMODE == 2) ? ' -> sessd='.$vs['sessd'].' | start='.$vs['start'].' | sessid='.$vs['sessid'].' userid='.$this->arcade->user['id'].' | ui[arcade_session]='.$userinfo['arcade_session'].' | ui[arcade_sess_gid]='.$userinfo['arcade_sess_gid'].' FIXIE = '.$FIXIE.'
'.$BROWSERDATA : '';
$ERRORLEVEL = $ERRORLEVEL.$VERBOSE;
$std->Error(array(LEVEL => 1, MSG => 'cheater', EXTRA => $ERRORLEVEL));
}
if ($gid != $userinfo['arcade_sess_gid']) {
// avoid cross-scoring... finally! *gg*
$ERRORLEVEL = ($DEBUGMODE == 0) ? '' : 'Error #004';
$VERBOSE = ($DEBUGMODE == 2) ? ' -> gid='.$gid.' | ui[arcade_sess_gid]='.$userinfo['arcade_sess_gid'] : '';
$ERRORLEVEL = $ERRORLEVEL.$VERBOSE;
$std->Error(array(LEVEL => 1, MSG => 'cheater', EXTRA => $ERRORLEVEL));
}
$readtimeoutquery = $DB->query('SELECT scoretimeout FROM ibf_games_settings');
$readtimeout = $DB->fetch_row($readtimeoutquery);
$SCORETIMEOUT = $readtimeout['scoretimeout'];
if (!$timecheck || $timecheck > $SCORETIMEOUT) {
$ERRORLEVEL = ($DEBUGMODE == 0) ? 'Transmission Timeout ('.$timecheck.' sec)' : 'Error #005';
$VERBOSE = ($DEBUGMODE == 2) ? ' -> timecheck='.$timecheck : '';
$ERRORLEVEL = $ERRORLEVEL.$VERBOSE;
$std->Error(array(LEVEL => 1, MSG => 'cheater', EXTRA => $ERRORLEVEL));
}
if ($genscore != $decodescore) {
$ERRORLEVEL = ($DEBUGMODE == 0) ? '' : 'Error #006';
$VERBOSE = ($DEBUGMODE == 2) ? ' -> genscore='.$genscore.' | decodescore='.$decodescore.' | score='.$player_score : '';
$ERRORLEVEL = $ERRORLEVEL.$VERBOSE;
$std->Error(array(LEVEL => 1, MSG => 'cheater', EXTRA => $ERRORLEVEL));
}
if (file_exists(ROOT_PATH.'arcade/gamedata/'.$g['gname'].'/v32game.txt')) {
if (($gidencoded != $encoded_gid) || ($swfgname != $g['gname'])) {
$ERRORLEVEL = ($DEBUGMODE == 0) ? '' : 'Error #007';
$VERBOSE = ($DEBUGMODE == 2) ? ' -> gidenc='.$gidencoded.' | enc_gid='.$encoded_gid.' | swfgn='.$swfgname.' | g[gname]='.$g['gname'] : '';
$ERRORLEVEL = $ERRORLEVEL.$VERBOSE;
$std->Error(array(LEVEL => 1, MSG => 'cheater', EXTRA => $ERRORLEVEL));
}
}
//Get's the timespent
$timespent = 0;
if ($userinfo['arcade_sess_start']) {
$timespent = time() - $userinfo['arcade_sess_start'];
}
if ($timespent) {
$DB->query("UPDATE ibf_games_list SET gtime=gtime+'".$timespent."', gtotalscore=gtotalscore+'".$player_score."' WHERE gid='".$gid."' LIMIT 1");
$DB->query("UPDATE ibf_members SET games_played=games_played+1, time_played=time_played+'".$timespent."' WHERE id=".$ibforums->member['id']);
}
// users sessiondata is no longer needed, so kick it to avoid any re-usage
$DB->query("UPDATE ibf_members SET arcade_sess_gid='0', arcade_sess_start='0', arcade_gtype=0, arcade_session='0' WHERE id=".$this->arcade->user['id']);
$this->storescore($this->arcade->user['id'], $player_score, $timespent, $gid, $tgame, $tid, 0);
}
public function post_score()
{
// ### for old, unsecured ibPro-Games
// ### for v3arcade-Games
// ### for pnFlashGames-Games
global $ibforums, $DB, $std, $vboptions, $vbulletin, $DEBUGMODE, $NATIVEMODE;
$tgame = 0;
$player_ip = $ibforums->input['IP_ADDRESS'];
$member_id = $this->arcade->user['id'];
$player_name = $this->arcade->user['name'];
$player_score = floatval($_POST['gscore']);
$game_name = ibp_cleansql($_POST['gname']);
$score = $ibforums->input['gscore'];
$keepsess = $ibforums->input['keepsess'];
// ### protection for external scripts faking incoming gamedata
// ### by MrZeropage
// look who sends the POST-data...
$referer = '';
if ($_SERVER['REFERER'] != '') {
$referer = strtolower($_SERVER['REFERER']);
}
if ($_SERVER['HTTP_REFERER'] != '') {
$referer = strtolower($_SERVER['HTTP_REFERER']);
}
if ($HTTP_SERVER_VARS['REFERER'] != '') {
$referer = strtolower($HTTP_SERVER_VARS['REFERER']);
}
// avoid external scripts calling this function
if ((strpos($referer, 'arcade.php') > 0) && (strpos($referer, $vboptions[bburl]) > 0)) {
// maybe there is some cheater trying to inject a score ?! *boooooh*
$ERRORLEVEL = ($DEBUGMODE == 0) ? '' : 'Error #008';
$VERBOSE = ($DEBUGMODE == 2) ? ' -> REF = '.$referer : '';
$ERRORLEVEL = $ERRORLEVEL.$VERBOSE;
$std->Error(array(LEVEL => 1, MSG => 'cheater', EXTRA => $ERRORLEVEL));
}
// ###
if ($this->arcade->user['arcade_access'] == 3) {
// This is a Guest that won't record any score
$player_score = 0;
$good_score = 1;
}
if ($this->arcade->user['arcade_access'] > 2) {
// GUEST
$userinfo['arcade_session'] = $_COOKIE['guestsession'];
$userinfo['arcade_sess_start'] = $_COOKIE['gpstarted'];
$userinfo['arcade_gtype'] = 0; // guests never play tourneys!
} else {
$userquery = $DB->query('SELECT * FROM ibf_user WHERE userid='.$this->arcade->user['id']);
$userinfo = $DB->fetch_row($userquery);
}
$getgameidquery = $DB->query("SELECT gid FROM ibf_games_list WHERE gname='".$game_name."'");
$getgameid = $DB->fetch_row($getgameidquery);
$timespent = 0;
if ($userinfo['arcade_sess_start']) {
$timespent = time() - $userinfo['arcade_sess_start'];
}
if (strstr($score, ':') !== false) {
$timestamp = strtotime($score);
$formatedTime = strftime('%H:%M:%S', $timestamp);
$hours = substr($formatedTime, 0, 2);
$minutes = substr($formatedTime, 3, 2);
$seconds = substr($formatedTime, 6, 2);
$numSeconds = (($hours * 60) * 60) + ($minutes * 60) + $seconds;
$score = $numSeconds;
$ibforums->input['gscore'] = $score;
}
// Kiss Cookies good bye!
if (!isset($userinfo['arcade_gtype']) || $userinfo['arcade_gtype'] == '0') {
$tgame = 0;
$tid = 0;
} else {
$tgame = 1;
$tid = $userinfo['arcade_gtype'];
}
$DB->query("SELECT gid, highscore_type, game_type FROM ibf_games_list WHERE gname='".$game_name."' LIMIT 1");
$g = $DB->fetch_row();
if ($g['game_type'] == 1) {
// this is a secure game which should not use POST_SCORE !!
$ERRORLEVEL = ($DEBUGMODE == 0) ? '' : 'Error #009';
$std->Error(array(LEVEL => 1, MSG => 'cheater', EXTRA => $ERRORLEVEL));
}
if ($userinfo['arcade_session'] == '') {
$ERRORLEVEL = ($DEBUGMODE == 0) ? '' : 'Error #023 - no session';
$std->Error(array(LEVEL => 1, MSG => 'cheater', EXTRA => $ERRORLEVEL));
}
$DB->query("SELECT * FROM ibf_games_session WHERE sessid='".$userinfo['arcade_session']."' LIMIT 1");
$vs = $DB->fetch_row();
$gid = $vs['gameid'];
$vbversion = substr($vboptions[templateversion], 0, 3);
if (($vbversion != '3.0') && ($NATIVEMODE == 0)) {
($hook = vBulletinHook::fetch_hook('ibproarcade_postscore_readsessiondata')) ? eval($hook) : false;
}
if ($keepsess != 1) {
// remove session as all data is read from it... and this is NO PNfg
$DB->query('DELETE FROM ibf_games_session WHERE sessid='.$userinfo['arcade_session']);
}
if ((!$vs['sessid'])) {
$ERRORLEVEL = ($DEBUGMODE == 0) ? '' : 'Error #010';
$std->Error(array(LEVEL => 1, MSG => 'cheater', EXTRA => $ERRORLEVEL));
}
// #########################################
// final fix for cross-scoring by MrZeropage
// #########################################
// first we check if GameID stored in userinfo is the same of submitting Game
if ($this->arcade->user['arcade_access'] < 3) {
// make sure this is NOT a guest
// compare userinfo and sessiondata
if (($gid != $userinfo['arcade_sess_gid']) || ($gid != $g['gid']) || ($userinfo['userid'] != $vs['mid']) || ($vs['gname'] != $game_name)) {
$ERRORLEVEL = ($DEBUGMODE == 0) ? '' : 'Error #011';
$VERBOSE = ($DEBUGMODE == 2) ? ' -> gid='.$gid.'|ui[a_sess_gid]='.$userinfo['arcade_sess_gid'].'|g[gid]='.$g['gid'].'|vs[mid]='.$vs['mid'].'|vs[gname]='.$vs['gname'].'|gamename='.$game_name : '';
$ERRORLEVEL = $ERRORLEVEL.$VERBOSE;
$std->Error(array(LEVEL => 1, MSG => 'cheater', EXTRA => $ERRORLEVEL));
}
// compare incoming gameid with the one stored in sessiondata
if ($getgameid['gid'] != $gid) {
$ERRORLEVEL = ($DEBUGMODE == 0) ? '' : 'Error #012';
$VERBOSE = ($DEBUGMODE == 2) ? ' -> gid='.$gid.'|getgameid='.$getgameid['gid'] : '';
$ERRORLEVEL = $ERRORLEVEL.$VERBOSE;
$std->Error(array(LEVEL => 1, MSG => 'cheater', EXTRA => $ERRORLEVEL));
}
} else {
// this is a guest...
if ($vs['mname'] != $_COOKIE['guesthash']) {
$ERRORLEVEL = ($DEBUGMODE == 0) ? '' : 'Error #013';
$VERBOSE = ($DEBUGMODE == 2) ? ' -> vs[mname]='.$vs['mname'].'|guesthash='.$_COOKIE['guesthash'] : '';
$ERRORLEVEL = $ERRORLEVEL.$VERBOSE;
$std->Error(array(LEVEL => 1, MSG => 'cheater', EXTRA => $ERRORLEVEL));
}
// cleanup cookiestuff from guest
$_COOKIE['guesthash'] = '';
$_COOKIE['guestsession'] = '';
}
if ($keepsess != 1) {
// users sessiondata is no longer needed, so kick it to avoid any re-usage
$DB->query("UPDATE ibf_members SET arcade_sess_gid='0', arcade_sess_start='0', arcade_gtype=0, arcade_session='0' WHERE id=".$this->arcade->user['id']);
}
// #########################################
if ($timespent < 86400) {
$DB->query("UPDATE ibf_games_list SET gtime=gtime+'".$timespent."', gtotalscore=gtotalscore+'".$player_score."' WHERE gid='".$gid."' LIMIT 1");
if (($ibforums->member['id'] > 0) && ($this->arcade->user['arcade_access'] == 2 || $this->arcade->user['arcade_access'] == 4)) {
$DB->query("UPDATE ibf_members SET games_played=games_played+1, time_played=time_played+'".$timespent."' WHERE id=".$ibforums->member['id']);
}
}
$this->storescore($this->arcade->user['id'], $player_score, $timespent, $gid, $tgame, $tid, $keepsess);
}
public function storescore($userid, $player_score, $timespent, $gid, $tgame, $tid, $keepsess)
{
// ##############################################################
// common handling of scores coming from any game (by MrZeropage)
// ##############################################################
global $DB, $std, $vbulletin, $vboptions, $ibforums, $LOGIPS, $NATIVEMODE;
$gid = intval($gid);
$tid = intval($tid);
$userid = intval($userid);
$keepsess = intval($keepsess);
$player_score = floatval($player_score);
$timespent = ibp_cleansql($timespent);
$server = strtolower($_SERVER['HTTP_REFERER']);
$referer = strpos($server, 'arcade.php');
// for guests playing and calling games directly (without arcade.php) we have to re-check cookies
if (($_COOKIE['ibPAcookiecheck'] != 'yesss') && ($_COOKIE['guesthash']) > 0) {
$VERBOSE = ($DEBUGMODE == 2) ? ' cookie #003 -> ghash='.$_COOKIE['guesthash'].' | ibPAcheck='.$_COOKIE['ibPAcookiecheck'].' | referer='.$_SERVER['HTTP_REFERER'] : '';
$std->Error(array(LEVEL => 1, MSG => 'cat_pass_notice', EXTRA => $VERBOSE));
}
$gamequery = $DB->query("SELECT highscore_type FROM ibf_games_list WHERE gid='".$gid."' LIMIT 1");
$g = $DB->fetch_row($gamequery);
$ordering = ($g['highscore_type'] == 'high') ? 'DESC' : 'ASC';
$player_name = $this->arcade->user['name'];
$member_id = $userid;
$player_ip = ($LOGIPS == 0) ? '' : $ibforums->input['IP_ADDRESS'];
// get this user's best result in that game
$scorequery = $DB->query('SELECT score, timespent FROM ibf_games_scores WHERE gid='.$gid.' AND mid='.$this->arcade->user['id'].' ORDER BY score '.$ordering.' LIMIT 0, 1');
if ($DB->get_num_rows($scorequery)) {
$userscore = $DB->fetch_row($scorequery);
$score = $userscore['score'];
$usertime = $userscore['timespent'];
$name_found = 1;
} else {
$score = 0;
$usertime = 0;
$name_found = 0;
}
if ($tgame == 0) {
$std->time_options['LROW'] = 'G:i';
$max_scores_shown = $this->arcade->settings['scores_amount'];
$DB->query('SELECT g.gid,g.gname,g.gtitle,g.gwords,g.gcat,g.highscore_type,g.decpoints,g.cost,g.jackpot,g.jackpot_type,g.g_rating,g.g_raters,c.* FROM ibf_games_list AS g, ibf_games_champs AS c WHERE (g.gid = c.champ_gid) AND gid='.$gid);
if ($DB->get_num_rows()) {
$ginfo = $DB->fetch_row();
$ginfo['champ_score'] = $this->arcade->do_arcade_format($ginfo['champ_score'], $ginfo['decpoints']);
if (!empty($ginfo['champ_mid'])) {
$DB->query('SELECT avatar,avatar_size AS size FROM ibf_members WHERE id='.$ginfo['champ_mid']);
$avatar = $DB->fetch_row();
$ginfo['avatarcode'] = $std->get_avatar($avatar, 1, $avatar['size']);
}
} else {
$DB->query('SELECT * FROM ibf_games_list WHERE gid='.$gid);
$ginfo = $DB->fetch_row();
}
$ginfo['avatarcode'] = (empty($ginfo['avatarcode'])) ? "" : $ginfo['avatarcode'];
$DB->query('SELECT champ_score AS score, champ_time AS time, champ_name AS name, champ_mid AS mid, champ_gtitle FROM ibf_games_champs WHERE champ_gid='.$gid);
if ($DB->get_num_rows()) {
$champ = $DB->fetch_row();
//xxxxx
if (($player_score != 0) && ((($player_score > $champ['score'] && $ginfo['highscore_type'] == 'high') || ($player_score < $champ['score'] && $ginfo['highscore_type'] == 'low')) || (($player_score == $champ['score']) && (($timespent < $champ['time']) || ($champ['time'] == 0))))) {
$vbversion = substr($vboptions[templateversion], 0, 3);
if (($vbversion != '3.0') && ($NATIVEMODE == 0)) {
($hook = vBulletinHook::fetch_hook('ibproarcade_new_champ')) ? eval($hook) : false;
}
$db_string = $DB->compile_db_update_string(array('champ_gid' => $gid,
'champ_gtitle' => $ginfo['gtitle'],
'champ_mid' => $this->arcade->user['id'],
'champ_name' => $this->arcade->user['name'],
'champ_date' => time(),
'champ_score' => $player_score,
'champ_time' => $timespent, ));
// update Avatarinfo for HTML-Output
$DB->query('SELECT avatar,avatar_size AS size FROM ibf_members WHERE id='.$this->arcade->user['id']);
$avatar = $DB->fetch_row();
$ginfo['avatarcode'] = $std->get_avatar($avatar, 1, $avatar['size']);
$ginfo['avatarcode'] = (empty($ginfo['avatarcode'])) ? "" : $ginfo['avatarcode'];
if ($player_score != 0) {
// PM-Notification on new highscore by MrZeropage :-)
$senderid = $this->arcade->user['id'];
$sendername = $this->arcade->user['name'];
$recipient = $champ['mid'];
$vbversion = substr($vboptions[templateversion], 0, 3); // Version 3.0 oder 3.5
if ($vbversion == '3.0') {
$forumlink = $vboptions['bburl'].'/';
} else {
$forumlink = $vbulletin->options['bburl'].'/';
}
$title = $ibforums->lang['pmnote_title'];
$mailtitle = $ibforums->lang['mailnote_title'];
$message = $this->arcade->settings['msgsys_hscore_text'];
$mailmessage = $this->arcade->settings['msgsys_hscore_text'];
$message = preg_replace('/%NAME%/', $champ['name'], $message);
$message = preg_replace('/%GAME%/', $ginfo['gtitle'], $message);
$message = preg_replace('/%CHAMP%/', $this->arcade->user['name'], $message);
$message = preg_replace("#%LINKGAME\|(.*?)%#", "[url='".$forumlink.'arcade.php?do=play&gameid='.$gid."']$1[/url]", $message);
$message = preg_replace("#%LINKHIGH\|(.*?)%#", "[url='".$forumlink.'arcade.php?do=stats&gameid='.$gid."']$1[/url]", $message);
$mailmessage = preg_replace('/%NAME%/', $champ['name'], $mailmessage);
$mailmessage = preg_replace('/%GAME%/', $ginfo['gtitle'], $mailmessage);
$mailmessage = preg_replace('/%CHAMP%/', $this->arcade->user['name'], $mailmessage);
$mailmessage = preg_replace("#%LINKGAME\|(.*?)%#", "$1", $mailmessage);
$mailmessage = preg_replace("#%LINKHIGH\|(.*?)%#", "$1", $mailmessage);
$mailmessage = strip_bbcode($mailmessage, true);
$mailmessage = preg_replace('/<\/?[a-z][a-z0-9]*[^<>]*>/i', '', $mailmessage);
if (($senderid != $recipient) && ($this->arcade->settings['msgsys_hscore'] == 1)) {
// does the recipient want to receive any Notifications from the Arcade ?
$DB->query("SELECT arcade_pmactive, email FROM ibf_user WHERE userid=$recipient");
$recip = $DB->fetch_row();
// check for possible Guest-Player
if ($guestplayerid == $recipient) {
$recip['arcade_pmactive'] = 0;
}
if (($recip['arcade_pmactive'] == 1) && ($this->arcade->settings['msgsys_hscore'] == 1)) {
// Notification via PM
if (($this->arcade->settings['notification'] == 'pm') || ($this->arcade->settings['notification'] == 'pm+mail')) {
$DB->query("INSERT INTO ibf_pmtext (fromuserid, fromusername, title, message, touserarray, iconid, dateline, showsignature, allowsmilie) VALUES ('".$senderid."', '".addslashes($sendername)."', '".addslashes($title)."', '".addslashes($message)."', '".addslashes(serialize(array($recipient)))."', 0, ".TIMENOW.', 0, 0)');
$pmid = $DB->get_insert_id();
$DB->query("UPDATE ibf_user SET pmtotal=pmtotal+1, pmunread=pmunread+1 WHERE userid=$recipient");
$DB->query("INSERT INTO ibf_pm (pmtextid, userid, folderid, messageread) VALUES ('$pmid', '$recipient', '0', '0')");
}
// Notification via eMail
if (($this->arcade->settings['notification'] == 'mail') || ($this->arcade->settings['notification'] == 'pm+mail')) {
vbmail($recip['email'], $mailtitle, $mailmessage);
}
}
}
// finally update Highscore-Table
if (($this->arcade->user['id'] != 0) && ($player_score != 0)) {
$DB->query('UPDATE ibf_games_champs SET '.$db_string.' WHERE champ_gid='.$gid);
$ginfo['champ_mid'] = $this->arcade->user['id'];
$ginfo['champ_name'] = $this->arcade->user['name'];
$ginfo['champ_score'] = $player_score;
// 100 vcash for high score of all time
$DB->query("UPDATE juventuz_user SET ucash=ucash+100 WHERE userid=$userid");
// 100 vcash for high score of all time
}
}
}
} else {
$db_string = $DB->compile_db_insert_string(array('champ_gid' => $gid,
'champ_gtitle' => $ginfo['gtitle'],
'champ_mid' => $this->arcade->user['id'],
'champ_name' => $this->arcade->user['name'],
'champ_date' => time(),
'champ_score' => $player_score,
'champ_time' => $timespent, ));
if ($player_score != 0) {
// no champ with no result ...
$DB->query('INSERT INTO ibf_games_champs ('.$db_string['FIELD_NAMES'].') VALUES ('.$db_string['FIELD_VALUES'].')');
$ginfo['champ_mid'] = $this->arcade->user['id'];
$ginfo['champ_name'] = $this->arcade->user['name'];
$ginfo['champ_score'] = $player_score;
}
}
// best result of all time? by MrZeropage
if ($player_score != 0) {
$DB->query('SELECT gid, bestmid, bestscore, besttime, highscore_type FROM ibf_games_list WHERE gid='.$gid);
if ($DB->get_num_rows()) {
// check if existing best result ever is lower
$best = $DB->fetch_row();
if (($best['bestscore'] < $player_score && $best['highscore_type'] == 'high') || ($best['bestscore'] > $player_score && $best['highscore_type'] == 'low') || (intval($best['bestscore']) == 0) || ($best['bestscore'] == '') || (($best['bestscore'] == $player_score) && (($best['besttime'] == 0) || ($best['besttime'] > $timespent)))) {
$userid = $this->arcade->user['id'];
// 1000 vcash for best high score of all time
$DB->query("UPDATE juventuz_user SET ucash=ucash+1000 WHERE userid=$userid");
// 1000 vcash for best high score of all time
$DB->query('UPDATE ibf_games_list SET bestmid='.$userid.', bestscore='.$player_score.", besttime='".$timespent."' WHERE gid=$gid");
}
}
}
// end of b.r.o.a.t.
if (isset($player_score) && is_numeric($player_score) && isset($player_name)) {
//Has this name played already?
$gtime = time();
$highsid = array();
$highsid['s_id'] = 0;
if ($this->arcade->settings['score_type'] == 'top' || empty($this->arcade->settings['score_type'])) {
if ($name_found == 1) {
// if name already exists, and score is good enough, update it
if ((($player_score > $score) && $ginfo['highscore_type'] == 'high') || (($player_score < $score && $ginfo['highscore_type'] == 'low') && $score != 0) || (($player_score == $score) && ($timespent < $usertime))) {
$db_string = $DB->compile_db_update_string(array('score' => $player_score,
'datescored' => $gtime,
'ip' => $player_ip,
'timespent' => $timespent, ));
$DB->query('UPDATE ibf_games_scores SET '.$db_string.' WHERE mid='.$member_id.' AND gid='.$gid);
$good_score = 1;
$DB->query('SELECT s_id FROM ibf_games_scores WHERE score='.$player_score.' AND datescored='.$gtime.' AND gid='.$gid.' AND mid='.$member_id.' ORDER BY s_id DESC LIMIT 0, 1');
$highsid = $DB->fetch_row();
}
} else {
$good_score = 1;
//Insert new name, score and ip
if ($good_score == 1) {
$db_string = $DB->compile_db_insert_string(array('mid' => $member_id,
'gid' => $gid,
'name' => $player_name,
'score' => $player_score,
'ip' => $player_ip,
'timespent' => $timespent,
'datescored' => $gtime,
'comment' => '', ));
$DB->query('INSERT INTO ibf_games_scores
('.$db_string['FIELD_NAMES'].') VALUES
('.$db_string['FIELD_VALUES'].')');
//$getsid = $DB->get_insert_id();
//$highsid['s_id']=$getsid;
$DB->query('SELECT s_id FROM ibf_games_scores WHERE score='.$player_score.' AND datescored='.$gtime.' AND gid='.$gid.' AND mid='.$member_id.' ORDER BY s_id DESC LIMIT 0, 1');
$highsid = $DB->fetch_row();
}
}
} else {
$good_score = 1;
$db_string = $DB->compile_db_insert_string(array('mid' => $member_id,
'gid' => $gid,
'name' => $player_name,
'score' => $player_score,
'ip' => $player_ip,
'timespent' => $timespent,
'datescored' => $gtime,
'comment' => '', ));
$DB->query('INSERT INTO ibf_games_scores
('.$db_string['FIELD_NAMES'].') VALUES
('.$db_string['FIELD_VALUES'].')');
//$highsid = $DB->get_insert_id();
//$highsid['s_id']=$getsid;
$DB->query('SELECT s_id FROM ibf_games_scores ORDER BY s_id DESC LIMIT 0, 1');
$highsid = $DB->fetch_row();
}
}
if ($keepsess != 1) {
// favorites-link
$temp = unserialize($this->arcade->user['favs']);
if (!is_array($temp)) {
$temp = array();
}
$favs = $temp;
$favtitle = $ibforums->lang['add_to_faves'];
$favtitle = preg_replace('/<% GAMENAME %>/i', $game['gtitle'], $favtitle);
$star = '';
if (in_array($ginfo['gid'], $favs)) {
//$star = " ";
$favtitle = $ibforums->lang['remove_from_faves'];
$favtitle = preg_replace('/<% GAMENAME %>/i', $ginfo['gtitle'], $favtitle);
}
if ($this->arcade->user['arcade_access'] == 2 && $this->arcade->user['id']) {
$ginfo['fave'] = "$favtitle";
}
// make the link fit everything ;)
$ginfo['backlink'] = $ibforums->lang['arcade_home'];
if ($this->arcade->settings['use_cats']) {
$ginfo['backlink'] = $ibforums->lang['showothersincat'];
}
$this->arcade->make_links($ginfo['gid'], $ginfo['gtitle']);
$this->output .= $this->html->leaderstart($ginfo, $this->arcade->links);
$yscore[1] = $player_name;
$yscore[2] = $this->arcade->do_arcade_format($player_score, $ginfo['decpoints']);
$yscore[3] = $std->get_date($gtime, 'LROW');
$yscore[4] = $gid;
$yscore[5] = $good_score;
$yscore[6] = $this->arcade->thatdate($timespent);
$ordering = ($ginfo['highscore_type'] == 'high') ? 'DESC' : 'ASC';
// set all League-Scores for this Game to default, as they get recalculated next
$leaguearray = explode(',', $this->arcade->settings['league_scores']);
$DB->query("UPDATE ibf_games_league SET points='".$leaguearray[10]."', position='0' WHERE gid=".$gid);
// calculate which scores should show up on page
$s_query = $DB->query('SELECT COUNT(*) AS counter FROM ibf_games_scores WHERE gid='.$gid);
$s_all = $DB->fetch_row($s_query);
$s_all = $s_all['counter'];
$s_limit = $this->arcade->settings['scores_amount'];
$lookctr = 1;
$s_pos = 0;
$lookupquery = $DB->query('SELECT s_id, mid, name, score FROM ibf_games_scores WHERE gid='.$gid.' ORDER BY score '.$ordering.',timespent ASC');
while ($lookup = $DB->fetch_row($lookupquery)) {
if ((($highsid['s_id'] != 0) && ($lookup['s_id'] == $highsid['s_id'])) || (($highsid['s_id'] == '0') && ($lookup['name'] == $player_name))) {
$s_pos = $lookctr;
}
++$lookctr;
}
if (($s_pos / $s_limit) == (floor($s_pos / $s_limit))) {
$startpage = (floor($s_pos / $s_limit) * $s_limit) - $s_limit;
} else {
$startpage = floor($s_pos / $s_limit) * $s_limit;
}
$endpage = $startpage + $s_limit + 1;
$startpage = $startpage;
if ($endpage > $s_all) {
$endpage = $s_all;
}
if ($startpage < 0) {
$startpage = 0;
}
if ($endpage <= $startpage) {
$endpage = $startpage + 1;
}
// setup LIMIT which should be at least 11 to make sure all Top10 get leaguepoints
if ($endpage < 11) {
$limitquery = 'LIMIT 11';
} else {
$limitquery = 'LIMIT '.$endpage;
}
$this_query = $DB->query('SELECT * FROM ibf_games_scores WHERE gid='.$gid.' ORDER BY score '.$ordering.',timespent ASC '.$limitquery);
$ctr = 1;
$rowcol = 'alt2';
while ($lboard = $DB->fetch_row($this_query)) {
// parse the comment
$vbversion = substr($vboptions[templateversion], 0, 3); // Version 3.0 oder 3.5
if ($vbversion == '3.0') {
require_once './includes/functions_bbcodeparse.php';
$parsed_comment = parse_bbcode($lboard['comment']);
} else {
require_once './includes/class_bbcode.php';
$bbcode_parser = &new vB_BbCodeParser($vbulletin, fetch_tag_list());
$parsed_comment = $bbcode_parser->parse($lboard['comment'], 0, 1);
}
$lboard['comment'] = $parsed_comment;
if ($ibforums->lang[timeformat1] == 'de') {
$std->time_options['LROW'] = "{$ibforums->lang['timeformat2']} \u\m {$ibforums->lang['timeformat3']}";
} else {
$std->time_options['LROW'] = "{$ibforums->lang['timeformat2']} {$ibforums->lang['timeformat3']}";
}
$formatteddate = $std->get_date($lboard['datescored'], 'LROW');
$usercell = "";
$usercell .= "{$lboard[name]}";
$datecell = $formatteddate;
$scorecell = $this->arcade->do_arcade_format($lboard['score'], $ginfo['decpoints']);
if ($lboard['timespent'] == 0) {
$lboard['timespent'] = $ibforums->lang['n_a'];
} else {
$lboard['timespent'] = $this->arcade->thatdate($lboard['timespent']);
}
if ($this->arcade->settings['skin'] != 0) {
if ($rowcol == 'alt1') {
$rowcol = 'alt2';
} else {
$rowcol = 'alt1';
}
}
// only display scorelines that match the page needed
if (($ctr > $startpage) && ($ctr < ($endpage + 1))) {
if ($ctr != $s_pos) {
$this->output .= $this->html->leaderrow($lboard, $ctr, $usercell, $datecell, $scorecell, $rowcol);
} else {
if ($this->arcade->user['arcade_access'] == 3) {
$yscore[5] = 0;
}
if (($ctr == 1 && $s_pos == 1) && ($yscore[5] == 1)) {
$usercell = " ".$usercell." ";
}
$commentcell = $lboard['comment'];
if ($yscore[5] == 1) {
$commentcell = '';
}
$data['comment'] = $commentcell;
$data['timespent'] = $yscore[6];
$vbversion = substr($vboptions[templateversion], 0, 3);
if (($vbversion != '3.0') && ($NATIVEMODE == 0)) {
($hook = vBulletinHook::fetch_hook('ibproarcade_play_game_finished')) ? eval($hook) : false;
}
$this->output .= $this->html->leaderrow($data, ''.$ctr.'', ''.$usercell.'', $datecell, $scorecell, 'alt1');
}
}
switch ($ctr) {
case 1: $points = $leaguearray[0];
break;
case 2: $points = $leaguearray[1];
break;
case 3: $points = $leaguearray[2];
break;
case 4: $points = $leaguearray[3];
break;
case 5: $points = $leaguearray[4];
break;
case 6: $points = $leaguearray[5];
break;
case 7: $points = $leaguearray[6];
break;
case 8: $points = $leaguearray[7];
break;
case 9: $points = $leaguearray[8];
break;
case 10: $points = $leaguearray[9];
break;
default: $points = $leaguearray[10];
}
// ***** LEAGUE finally fixed by MrZeropage :) *****
if (($ctr < 11) && ($points != $leaguearray[10])) {
// check if that player already has an entry for that game
$DB->query('SELECT gid, mid, lid FROM ibf_games_league WHERE gid='.$gid.' AND mid='.$lboard['mid'].' AND position=0');
if ($DB->get_num_rows()) {
// already in league, so just update the entry
$onerow = $DB->fetch_row();
$db_string = $DB->compile_db_update_string(array(
'mid' => $lboard['mid'],
'gid' => $gid,
'position' => $ctr,
'points' => $points,
'cat' => $ginfo['gcat'],
));
$DB->query('UPDATE ibf_games_league SET '.$db_string.' WHERE gid='.$gid.' AND mid='.$lboard['mid'].' AND lid='.$onerow['lid']);
} else {
// new entry in league
$db_string = $DB->compile_db_insert_string(array(
'mid' => $lboard['mid'],
'gid' => $gid,
'position' => $ctr,
'points' => $points,
'cat' => $ginfo['gcat'],
));
$DB->query('INSERT INTO ibf_games_league ('.$db_string['FIELD_NAMES'].') VALUES ('.$db_string['FIELD_VALUES'].')');
}
}
// ***** end of League *****
++$ctr;
}
$this->output .= $this->html->stop($this->arcade->links['pages']);
if ($yscore[5] != 1) {
// show information if score is not stored because of main settings
if ($this->arcade->user['arcade_access'] == 3) {
$this->output .= "