$shotid ORDER BY id ASC LIMIT 1"); if (db_rows($res)) $nextid = db_get($res, 0, "id"); if ($a == 'shot') */ include 'blocks/shot'; } // function racing_shots($id) { global $dbh; $dirname = "pic/shots/"; $q = "SELECT * FROM racing_shots ORDER BY filename ASC"; $res = db_query($dbh, $q); if (!$res || !db_rows($res)) return; $cnt = 0; for ($i = 0; $i < db_rows($res); $i++) { $file = db_get($res, $i, "filename"); list ($name, $ext) = split('\.', $file); $filebig = $file; $file = $name.'_s.gif'; if (!file_exists($dirname.$filebig) || !file_exists($dirname.$file)) continue; if (!$cnt) echo ''."\n"; $shotid = db_get($res, $i, "id"); $name = iconv('koi8-r', 'cp1251', db_get($res, $i, "name")); $desc = ''; $desc = iconv('koi8-r', 'cp1251', db_get($res, $i, "description")); $desc = preg_replace("/\n/", " ", $desc); include 'blocks/shotlist_item'; if ($cnt) echo "\n"; $cnt = !$cnt; } } // function mylog($msg) { global $logfile; $ipaddr = $_SERVER['REMOTE_ADDR']; if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ipaddr.= '-'.@$_SERVER['HTTP_X_FORWARDED_FOR']; $time = strftime("%H:%M"); error_log("$time : $ipaddr : $msg\n", 3, $logfile); } // ==================================================================== // RC4 /** * The symmetric encryption function * * @param string $pwd Key to encrypt with (can be binary of hex) * @param string $data Content to be encrypted * @param bool $ispwdHex Key passed is in hexadecimal or not * @access public * @return string */ function encrypt ($pwd, $data) { $key[] = ''; $box[] = ''; $cipher = ''; $pwd_length = strlen($pwd); $data_length = strlen($data); for ($i = 0; $i < 256; $i++) { $key[$i] = ord($pwd[$i % $pwd_length]); $box[$i] = $i; } for ($j = $i = 0; $i < 256; $i++) { $j = ($j + $box[$i] + $key[$i]) & 255; $tmp = $box[$i]; $box[$i] = $box[$j]; $box[$j] = $tmp; } /*$s = ""; for ($i = 0; $i < 256; $i++) { $v = $box[$i]; $s .= "[$i] = $v\n"; } mylog($s);*/ $s = ""; for ($a = $j = $i = 0; $i < $data_length; $i++) { $a = ($a + 1) & 255; $j = ($j + $box[$a]) & 255; $tmp = $box[$a]; $box[$a] = $box[$j]; $box[$j] = $tmp; $k = $box[(($box[$a] + $box[$j]) & 255)]; $s .= "[$i] = $k\n"; $cipher .= chr((ord($data[$i]) ^ $k) & 255); } // mylog($s); return $cipher; } // function racing_decode_data(&$data) { $data = @pack('H*', $data); $data = encrypt("FlkVythfmYJFJGHhgdfjkbjGDfhbv", $data); //mylog($data); $pos = strpos($data, ' '); if ($pos === false) { return 0; } $in_CRC = substr($data, 0, $pos); $data = substr($data, $pos + 1); $CRC = sprintf('%d', crc32($data)); if ($CRC != $in_CRC) { mylog("InCRC = $in_CRC, CRC = $CRC"); return 0; } return 1; } // function racing_add_track_record($data, $isdemo = 0) { global $dbh; $array = preg_split('/[=\n]/', $data); array_shift($array); array_pop($array); for($i = 0; $i < sizeof($array); $i += 2) { $key = rtrim(trim($array[$i])); $val = rtrim(trim($array[$i + 1])); // mylog("[$key] => [$val]"); ${$key} = $val; } // ID ID $res = db_query($dbh, "SELECT * FROM racing_tracks WHERE stringid = '$TrackID'"); mylog("dbh:".$dbh); if (!$res || !db_rows($res)) { mylog("No such track [$TrackID]"); return 0; } $TrackID = db_get($res, 0, "id"); // ID ID $res = db_query($dbh, "SELECT * FROM racing_gliders WHERE stringid = '$GliderID'"); if (!$res || !db_rows($res)) { mylog("No such glider [$GliderID]"); return 0; } $GliderID = db_get($res, 0, "id"); $ip = $_SERVER['REMOTE_ADDR']; $ip2 = @$_SERVER['HTTP_X_FORWARDED_FOR']; if ($isdemo) $GUID = 'demo'; // $res = db_query($dbh, "SELECT * FROM racing_track_records ". "WHERE TrackID = $TrackID AND CategoryID = $CategoryID AND ". ($isdemo ? "Name = '$Name'" : "GUID = '$GUID' "). "AND Value = $Value"); if ($res && db_rows($res) > 0) { mylog("Trying to add same record."); return 1; } $res = db_query($dbh, "INSERT INTO racing_track_records (ipaddr, ipaddr2, date, Difficulty, TrackID, CategoryID, ". "Name, GUID, Value, GliderID, BestLapTime, AverageSpeed, MaxSpeed, ". "Killed, Outed, Accuracy, Rating) ". "VALUES ('$ip', '$ip2', now(), $Difficulty, $TrackID, $CategoryID, '$Name', ". "'$GUID', $Value, $GliderID, ". "$BestLapTime, $AverageSpeed, $MaxSpeed, $Killed, $Outed, $Accuracy, ". "$Rating)"); if (!$res) { mylog("Error adding record : ".mysql_error($dbh)); return 0; } // $order = ($CategoryID == 0 ? "ASC" : "DESC"); $res = db_query($dbh, "SELECT ID FROM racing_track_records ". "WHERE CategoryID = $CategoryID AND TrackID = $TrackID AND ". ($isdemo ? "Name = '$Name'" : "GUID = '$GUID' "). "ORDER BY Value $order LIMIT 1"); if (!$res || !db_rows($res)) return 1; $ID = db_get($res, 0, "id"); if ($ID > 0) $res = db_query($dbh, "DELETE FROM racing_track_records ". "WHERE CategoryID = $CategoryID AND TrackID = $TrackID AND ". ($isdemo ? "Name = '$Name'" : "GUID = '$GUID' "). "AND ID <> $ID "); return 1; } // function racing_add_championship_record($data, $isdemo = 0) { global $dbh; $array = preg_split('/[=\n]/', $data); array_shift($array); array_pop($array); for($i = 0; $i < sizeof($array); $i += 2) { $key = rtrim(trim($array[$i])); $val = rtrim(trim($array[$i + 1])); // mylog("[$key] => [$val]"); ${$key} = $val; } $ip = $_SERVER['REMOTE_ADDR']; $ip2 = @$_SERVER['HTTP_X_FORWARDED_FOR']; $res = db_query($dbh, "INSERT INTO racing_championship_records (ipaddr, ipaddr2, date, ". "Difficulty, Name, GUID, ". "Rating, TotalTime, AverageSpeed, MaxSpeed, Killed, Outed, Accuracy, ". "WinCount, LossCount, Upgrade0, Upgrade1, Upgrade2, Upgrade3, Upgrade4) ". "VALUES ('$ip', '$ip2', now(), $Difficulty, '$Name', '$GUID', $Rating, ". "$TotalTime, $AverageSpeed, ". "$MaxSpeed, $Killed, $Outed, $Accuracy, $WinCount, $LossCount, ". "$Upgrade0, $Upgrade1, $Upgrade2, $Upgrade3, $Upgrade4) "); if (!$res) { mylog("Error adding record : ".mysql_error($dbh)); return 0; } return 1; } // function racing_get_track_records($data) { global $dbh; $array = preg_split('/[=\n]/', $data); array_shift($array); array_pop($array); for($i = 0; $i < sizeof($array); $i += 2) { $key = rtrim(trim($array[$i])); $val = rtrim(trim($array[$i + 1])); // mylog("[$key] => [$val]"); ${$key} = $val; } // ID ID $res = db_query($dbh, "SELECT * FROM racing_tracks WHERE stringid = '$TrackID'"); if (!$res || !db_rows($res)) { mylog("No such track [$TrackID]"); return 0; } $TrackID = db_get($res, 0, "id"); $str_order = ($CategoryID == 0 ? "ASC" : "DESC"); $res = db_query($dbh, "SELECT Difficulty, CategoryID, racing_track_records.Name, ". "racing_track_records.GUID, Value, ". "racing_gliders.stringid AS GliderID, racing_gliders.name AS GliderName, ". "BestLapTime, AverageSpeed, MaxSpeed, Killed, Outed, Accuracy, Rating ". "FROM racing_track_records, racing_gliders ". "WHERE racing_track_records.TrackID = $TrackID AND ". "racing_track_records.GliderID = racing_gliders.ID AND ". "racing_track_records.CategoryID = $CategoryID AND ". "racing_track_records.Difficulty = $Difficulty ". "ORDER BY Value $str_order ". "LIMIT 100"); if (!$res) { mylog("Error getting records : ".mysql_error($dbh)); return 0; } echo db_rows($res)."\n"; while ($row = db_get_hash($res)) { echo "Record\n"; // mylog("Record\n"); foreach (array_keys($row) as $key) { echo "$key=".$row[$key]."\n"; // mylog("$key=".$row[$key]); } } return 1; } // function racing_get_championship_records($data) { global $dbh; $array = preg_split('/[=\n]/', $data); array_shift($array); array_pop($array); for($i = 0; $i < sizeof($array); $i += 2) { $key = rtrim(trim($array[$i])); $val = rtrim(trim($array[$i + 1])); // mylog("[$key] => [$val]"); ${$key} = $val; } $res = db_query($dbh, "SELECT Difficulty, racing_championship_records.Name, ". "racing_championship_records.GUID, Rating, ". "TotalTime, AverageSpeed, MaxSpeed, Killed, Outed, Accuracy, ". "WinCount, LossCount, Upgrade0, Upgrade1, Upgrade2, Upgrade3, Upgrade4 ". "FROM racing_championship_records ". "WHERE Difficulty = $Difficulty ". "ORDER BY Rating DESC ". "LIMIT 100"); if (!$res) { mylog("Error getting records : ".mysql_error($dbh)); return 0; } echo db_rows($res)."\n"; // mylog(db_rows($res)); while ($row = db_get_hash($res)) { echo "Record\n"; foreach (array_keys($row) as $key) { echo "$key=".$row[$key]."\n"; // mylog("$key=".$row[$key]); } } return 1; } // function racing_championship_records($Difficulty) { global $dbh; $res = db_query($dbh, "SELECT Difficulty, racing_championship_records.Name, Rating, ". "TotalTime, AverageSpeed, MaxSpeed, Killed, Outed, Accuracy, ". "WinCount, LossCount, Upgrade0, Upgrade1, Upgrade2, Upgrade3, Upgrade4 ". "FROM racing_championship_records ". "WHERE Difficulty = $Difficulty ". "ORDER BY Rating DESC ". "LIMIT 100"); if (!$res) return 0; for ($i = 0; $i < db_rows($res); $i++) { $name = db_get($res, $i, "name"); $rating = db_get($res, $i, "rating"); include 'blocks/cship_record'; } return 1; } // function racing_track_options() { global $dbh; $res = db_query($dbh, "SELECT * FROM racing_tracks ORDER BY Name"); if (!$res) return 0; for ($i = 0; $i < db_rows($res); $i++) { $id = db_get($res, $i, "id"); $name = db_get($res, $i, "name"); echo "