<?php $myFile = 'racedata.txt'; $fh = fopen($myFile, 'r+') or die("Can't open file"); $theData = fread($fh, filesize($myFile)); $ranks = explode(",", $theData); fclose($fh); $racers = array($_GET['position-1'], $_GET['position-2'], $_GET['position-3'], $_GET['position-4']); setRanks($racers); updatePositions(); function setRanks($list) { global $racers, $ranks; for ($i = 0; $i < count($list); $i++) { if ($list[$i]) { $rank = array_search($list[$i], $ranks); $racers[$i] = array('name' => $list[$i], 'team' => getTeam($rank)); } else { array_pop($racers); } } } function getTeam($position) { $rank; if ($position < 3) { $rank = 0; } else { if ($position < 6) { $rank = 1; } else {
function deleteScores(&$game, $id_score) { global $scripturl, $txt, $db_prefix, $modSettings, $context, $smcFunc, $user_info; if (!is_array($id_score) && is_numeric($id_score)) { $id_score = array((int) $id_score); } if (empty($id_score)) { return true; } $request = $smcFunc['db_query']('', ' SELECT id_score, id_member, position, score, personal_best FROM {db_prefix}arcade_scores WHERE id_score IN({array_int:score}) AND id_game = {int:game} ORDER BY position', array('game' => $game['id'], 'score' => $id_score)); $removeIds = array(); $personalBest = array(); $positions = array(); $championUpdate = false; while ($row = $smcFunc['db_fetch_assoc']($request)) { if ($row['personal_best']) { $personalBest[] = $row['id_member']; } $removeIds[] = $row['id_score']; $positions[] = $row['position']; if ($row['position'] == 1) { $championUpdate = true; } } $smcFunc['db_free_result']($request); $personalBest = array_unique($personalBest); $count = -1; if (empty($positions)) { return true; } $startPos = $positions[0]; $smcFunc['db_query']('', ' DELETE FROM {db_prefix}arcade_scores WHERE id_score IN({array_int:scores})', array('scores' => $removeIds)); // Log removed scores logAction('arcade_remove_scores', array('game' => $game['id'], 'scores' => count($removeIds))); for ($i = 0; $i < count($positions); $i++) { if (isset($positions[$i + 1]) && $positions[$i] + 1 == $positions[$i + 1]) { $count--; } else { updatePositions($game, $startPos, $count); $startPos = $positions[$i]; $count = -1; } } if ($championUpdate) { $request = $smcFunc['db_query']('', ' SELECT id_score, id_member FROM {db_prefix}arcade_scores WHERE position = 1 AND id_game = {int:game} LIMIT 1', array('game' => $game['id'])); $row = $smcFunc['db_fetch_assoc']($request); if ($row !== false) { updateGame($game['id'], array('champion' => $row['id_member'], 'champion_score' => $row['id_score'])); } else { updateGame($game['id'], array('champion' => 0, 'champion_score' => 0)); } $smcFunc['db_free_result']($request); if (!empty($row['id_score'])) { $smcFunc['db_query']('', ' UPDATE {db_prefix}arcade_scores SET champion_from = {int:time} WHERE id_score = {int:score}', array('time' => time(), 'score' => $row['id_score'])); } } if (empty($personalBest)) { return true; } $request = $smcFunc['db_query']('', ' SELECT id_score, id_member FROM {db_prefix}arcade_scores WHERE id_game = {int:game} AND id_member IN({array_int:members}) ORDER BY position', array('game' => $game['id'], 'members' => $personalBest)); $newPersonalBest = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { if (!isset($newPersonalBest[$row['id_member']])) { $newPersonalBest[$row['id_member']] = $row['id_score']; } } $smcFunc['db_free_result']($request); if (empty($newPersonalBest)) { return true; } $smcFunc['db_query']('', ' UPDATE {db_prefix}arcade_scores SET personal_best = 1 WHERE id_score IN({array_int:scores})', array('scores' => $newPersonalBest)); return true; }