function parse_file($file, $game_id, $device_id, $options) { global $start_date; global $end_date; $user_count = 0; echo "NOTE: Memory Usage: parse_file: " . memory_get_usage() . "\n"; # Do we have a zipped file or not? if (substr($file, -3, 3) == '.gz') { debugger("Got file, attempting to open it."); $gz = @gzopen($file, 'rb'); if ($gz) { # Check to see if we got a report $buffer = gzread($gz, 4096); //debugger("Buffer=$buffer\n"); # Check to make sure we have a valid file if (strpos($buffer, "<head><title>302 Found</title></head>")) { echo "NOTE: " . date("Y-m-d H:i:s") . ": 302 Redirect found for {$start_date} to {$end_date}. Waiting...\n"; return FALSE; } # So, we must have a valid JSON $offset = strpos($buffer, 'sessionEvents'); if ($offset == FALSE) { return FALSE; } # Read the file while (!gzeof($gz)) { $user_start = strpos($buffer, '{"u":'); $user_end = strpos($buffer, '{"u":', $user_start + 5); # Do we have one? If not, keep reading until we do if ($user_end == FALSE && !gzeof($gz)) { $data = substr($buffer, $user_start); # Save current bufferr while ($user_end == FALSE && !gzeof($gz)) { $buffer = gzread($gz, 4096); //debugger("Buffer While Loop=$buffer\n"); $user_end = strpos($buffer, '{"u":'); if ($user_end == FALSE) { $data .= $buffer; } } $str = $data . substr($buffer, 0, $user_end - 1); //debugger("Str1=$str\n"); } else { $str = substr($buffer, $user_start, $user_end - $user_start - 1); //debugger("Str2=$str\n"); } $user_count++; parse_user($str, $game_id, $device_id, $options); # Get new buffer string $buffer = substr($buffer, $user_end); # Get User start tag $user_start = strpos($buffer, '{"u":'); } gzclose($gz); } else { echo "ERROR: Could not open gzip file. Exiting...\n"; exit(4); } } exit; if ($offset != FALSE) { $user_count = 0; while ($user_start != FALSE) { $user_end = strpos($data, '{"u":', $user_start + 5); //debugger("user_start=$user_start and user_end=$user_end."); if ($user_end != FALSE) { $str = substr($data, $user_start, $user_end - $user_start - 1); } else { $str = substr($data, $user_start); } $user_count++; parse_user($str, $game_id, $device_id, $options); $user_start = $user_end; } echo "NOTE: " . date("Y-m-d H:i:s") . ": Processed {$user_count} users from {$start_date} to {$end_date}.\n"; } return TRUE; }
function parse_file($file, $game_id, $device_id, $options) { global $start_date; global $end_date; $offset = 0; $gz = @gzopen($file, 'rb', $use_include_path); if ($gz) { $data = ''; while (!gzeof($gz)) { $data .= gzread($gz, 4096); } gzclose($gz); } # Check to make sure we have a valid file if (strpos($data, "<head><title>302 Found</title></head>")) { echo "NOTE: " . date("Y-m-d H:i:s") . ": 302 Redirect found for {$start_date} to {$end_date}. Waiting...\n"; return FALSE; } $offset = strpos($data, 'sessionEvents', $offset); if ($offset != FALSE) { $user_start = strpos($data, '{"u":', $offset); $user_count = 0; while ($user_start != FALSE) { $user_end = strpos($data, '{"u":', $user_start + 5); debugger("user_start={$user_start} and user_end={$user_end}."); if ($user_end != FALSE) { $str = substr($data, $user_start, $user_end - $user_start - 1); } else { $str = substr($data, $user_start); } $user_count++; parse_user($str, $game_id, $device_id, $options); $user_start = $user_end; } echo "NOTE: " . date("Y-m-d H:i:s") . ": Processed {$user_count} users from {$start_date} to {$end_date}.\n"; } return TRUE; }
$dbname = 'arcanium'; $dbuser = '******'; $dbpass = ''; // Connect to the database try { $dbdata = 'mysql:host=' . $dbhost . ';dbname=' . $dbname . ';charset=utf8'; $db = new PDO($dbdata, $dbuser, $dbpass); } catch (Exception $e) { die('Could not connect to the database: ' . $e); } // Identify the player making the request $client = Null; if (isset($_SESSION['client_id'])) { $req = $db->prepare('SELECT * FROM users WHERE id = ?'); $req->execute([$_SESSION['client_id']]); if ($data = $req->fetch()) { $client = parse_user($data); } } /** * UTILITY FUNCTIONS */ function hash_password($passwd) { return hash('sha512', $passwd); } /// Get the data representation of some user based on a MySQL result. function parse_user($data) { return ['id' => (int) $data['id'], 'name' => $data['name'], 'groups' => json_decode($data['groups'], True)]; }
function Do_Work() { global $settings; global $need_reload; global $px_Setops; global $res_str; pluginload(); $vDir = './farmville-logs'; if (!file_exists($vDir)) { mkdir($vDir); } $time_limit = 7 * 24 * 60 * 60; // number of seconds to 'keep' the log DAYSxHOURSxMINSxSECS if ($df = opendir($vDir)) { while (false !== ($file = readdir($df))) { if ($file != "." && $file != "..") { $file1 = $vDir . '/' . $file; $last_modified = filemtime($file1); if (time() - $last_modified > $time_limit) { unlink($file1); } } } closedir($df); } while (file_exists('notrun_parser.txt') || file_exists('notrun_parser_' . $_SESSION['userId'] . '.txt')) { AddLog2("Bot Paused. Next check in 30 seconds."); sleep(30); } parse_neighbors(); parse_user(); AddLog2("Beginning Bot Cycle"); Hook('before_work'); // Init $res = DoInit('full'); if ($res != 'OK') { RaiseError(2); } else { $res_str = ''; //for main logs } Hook('before_load_settings'); // load settings if (!function_exists('LoadSavedSettings')) { die("\n\nSettings plugin installed incorrectly no LoadSavedSettings found!\n\n"); } $px_Setopts = LoadSavedSettings(); $enable_lonlyanimals = $px_Setopts['lonlyanimals']; Hook('after_load_settings'); if ($enable_lonlyanimals) { AddLog2("check lonlyanimal"); Do_Check_Lonlyanimals(); } Hook('flybiplane'); Hook('before_harvest'); Hook('harvest'); Hook('after_harvest'); Hook('before_harvest_buildings'); Hook('harvest_buildings'); Hook('after_harvest_buildings'); //after building harvest Hook('before_harvest_animals'); //get product from livestock Hook('harvest_animals'); Hook('after_harvest_animals'); Hook('before_transform_animals'); Hook('transform_animals'); Hook('after_transform_animals'); Hook('before_harvest_trees'); Hook('harvest_trees'); Hook('after_harvest_trees'); Hook('before_hoe'); Hook('hoe'); Hook('after_hoe'); Hook('before_before_planting'); Hook('before_planting'); Hook('planting'); Hook('after_planting'); Hook('after_work'); Parser_Check_Images(); AddLog2("Peak Memory Usaged: " . round(memory_get_peak_usage(true) / 1024 / 1024, 2) . "MB"); AddLog2("Finished Bot Cycle"); }
function parse_file($file, $game_id, $device_id, $options) { global $start_date; global $end_date; $user_count = 0; //debugger("Memory Usage: parse_file: " . memory_get_usage() . "."); # Do we have a zipped file or not? if (substr($file, -3, 3) == '.gz') { debugger("Got file, attempting to open it."); $gz = @gzopen($file, 'rb'); if ($gz) { # Check to see if we got a report $buffer = gzread($gz, 4096); //debugger("Buffer=$buffer\n"); # Check to make sure we have a valid file if (strpos($buffer, "<head><title>302 Found</title></head>")) { note("302 Redirect found for Game: {$game_id}, Client: {$device_id} between {$start_date} and {$end_date}."); return FALSE; } if (strpos($buffer, "APICodeCompanyNotFound")) { error("Incorrect API Code found for Game: {$game_id}, Client: {$device_id} between {$start_date} and {$end_date}."); } # So, we must have a valid JSON $offset = strpos($buffer, 'sessionEvents'); if ($offset === FALSE) { return FALSE; } $user_count = 0; # Read the file while (!gzeof($gz)) { $user_start = strpos($buffer, '{"u":'); $user_end = strpos($buffer, '{"u":', $user_start + 5); # Do we have one? If not, keep reading until we do if ($user_end == FALSE && !gzeof($gz)) { $data = substr($buffer, $user_start); # Save current bufferr while ($user_end == FALSE && !gzeof($gz)) { $buffer = gzread($gz, 4096); //debugger("Buffer While Loop=$buffer\n"); $user_end = strpos($buffer, '{"u":'); if ($user_end == FALSE) { $data .= $buffer; } } $str = $data . substr($buffer, 0, $user_end - 1); //debugger("Str1=$str\n"); } else { $str = substr($buffer, $user_start, $user_end - $user_start - 1); //debugger("Str2=$str\n"); } $user_count++; parse_user($str, $game_id, $device_id, $options); # Get new buffer string $buffer = substr($buffer, $user_end); # Get User start tag $user_start = strpos($buffer, '{"u":'); } gzclose($gz); } else { error("Could not open gzip file. Exiting..."); } } note("Processed {$user_count} users for Game: {$game_id}, Client: {$device_id} between {$start_date} and {$end_date}."); return TRUE; }