$game){ $secs = time() - $game["__SEC_AFTER_EPOCH_SINCE_LAST_UPDATE"]; if($secs > TIMEOUT){ unset($records[$index]); } } //Save the file $fp = fopen(RECORD_FILE, "w"); fwrite($fp, ''); fclose($fp); } } function uploadRecords($post_body){ //IMPORTANT //Include the var_export of the variable $records include("RecordFile.data.php"); $output = ""; $post_array = array(); //Modified code to handle multiple rows separated by \002 $post_body_rows = explode("\002", $post_body); foreach($post_body_rows as $row_num => $post_body_row){ //row columns and values are separated by \001 //Even indexes are columns, the following odd value is the column_value $post_body_array = explode("\001", $post_body_row); foreach($post_body_array as $index => $post_body_item){ if($index % 2 == 0){ $post_array[$row_num][$post_body_item] = $post_body_array[$index+1]; } } } //This places each value pair into a PHP array to be outputted to the Recordfile foreach($post_array as $post_item){ if(isset($post_item["__GAME_PORT"]) && isset($post_item["__GAME_NAME"]) ){ $record = array(); foreach($post_item as $key => $value){ //Decode because post values are send with url encoded symbols like %20 $record[$key] = rawurldecode($value); } //Store the IP address if not included in the POST if(!isset($record["__System_Address"])){ $record["__System_Address"] = $_SERVER["REMOTE_ADDR"]; } $record["__SEC_AFTER_EPOCH_SINCE_LAST_UPDATE"] = time(); //Search the $records for a matching record. If the GAME_PORT, GAME_NAME, and System Address match replace it //Otherwise just add the record to the $records array. $record_found = false; if(!empty($records)){ foreach($records as $index => $save_record){ if($save_record["__GAME_PORT"] == $record["__GAME_PORT"] && $save_record["__GAME_NAME"] == $record["__GAME_NAME"] && $save_record["__System_Address"] == $record["__System_Address"]){ //We found the record so replace it here. $records[$index] = $record; $record_found = true; break; } } } //Record couldn't be found simply add a new record if(!$record_found){ $records[] = $record; } //Save the file $fp = fopen(RECORD_FILE, "w"); fwrite($fp, ''); fclose($fp); } else{ $output .= "\003".microtime(true)."\003"; $output .= "__GAME_PORT and __GAME_NAME must be provided"; } } return $output; } function downloadRecords(){ //IMPORTANT //Include the var_export of the variable $records include("RecordFile.data.php"); //Comment prefix $output = "\003".microtime(true)."\003"; //Output the records. Traverse and output rows separated by \002 and values seperated by \001 if(!empty($records)){ $row_count = 0; foreach($records as $game){ if(!empty($game)){ if($row_count > 0){ $output .= "\002"; } $count = 0; foreach($game as $key => $value){ if($count > 0){ $output .= "\001"; } $output .= "$key"."\001"."$value"; $count++; } } $row_count++; } } return $output; } function generateCss(){ $output = "
"; return $output; } function viewRecords(){ $output = ""; //IMPORTANT //Include the var_export of the variable $records include("RecordFile.data.php"); if(!empty($records)){ foreach($records as $game){ $vars = ""; $secs = $game["__SEC_AFTER_EPOCH_SINCE_LAST_UPDATE"] + TIMEOUT - time(); $output .= "Game Port: {$game["__GAME_PORT"]}
Game Name: {$game["__GAME_NAME"]}
System Address: {$game["__System_Address"]}
Time Until Expiration: $secs secs
"; foreach($game as $key => $value){ if($key != "__GAME_PORT" && $key != "__GAME_NAME" && $key != "__System_Address" && $key != "__SEC_AFTER_EPOCH_SINCE_LAST_UPDATE" ){ $vars .= "Record Table is Empty.