annotate keygen.php @ 2151:4071db9216b7

Python 2.x server can perform intermediate saves.
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Wed, 09 Mar 2016 13:12:02 +0000
parents 90212e9e9295
children ba6b9e1aaef5
rev   line source
nickjillings@2147 1 <?php
nickjillings@2147 2 // This checks the key sent by the JavaScript against the current bunch of saves
nickjillings@2147 3 // XML Saves location - assumes it will be saves/
nickjillings@2149 4 $saves = glob("saves/*.xml");
nickjillings@2147 5
nickjillings@2147 6 $key_requested = $_GET['key'];
nickjillings@2147 7
nickjillings@2147 8 $xml_good = "<response><state>OK</state><key>".$key_requested."</key></response>";
nickjillings@2147 9 $xml_bad = "<response><state>NO</state><key>".$key_requested."</key></response>";
nickjillings@2151 10 $xml_error = "<response><state>ERROR</state><key>".$key_requested."</key></response>";
nickjillings@2147 11 if (is_array($saves))
nickjillings@2147 12 {
nickjillings@2147 13 foreach($saves as $filename) {
nickjillings@2147 14 $xml_string = file_get_contents($filename, FILE_TEXT);
nickjillings@2147 15 $xml_object = simplexml_load_string($xml_string);
nickjillings@2147 16 if ($xml_object != false) {
nickjillings@2147 17 if (isset($value['key']))
nickjillings@2147 18 {
nickjillings@2147 19 if ($value['key'] == $key_requested) {
nickjillings@2147 20 echo $xml_bad;
nickjillings@2147 21 return;
nickjillings@2147 22 }
nickjillings@2147 23 }
nickjillings@2147 24 }
nickjillings@2147 25 }
nickjillings@2147 26 echo $xml_good;
nickjillings@2147 27 // TODO:
nickjillings@2147 28 // Generate the XML Base file and save it
nickjillings@2149 29 $doc_struct = new SimpleXMLElement('<waetresult/>');
nickjillings@2149 30 $doc_struct->addAttribute("key",$key_requested);
nickjillings@2147 31 // Add start time
nickjillings@2147 32 // Add IP Address information
nickjillings@2149 33 // Save the file
nickjillings@2149 34 $doc_struct->asXML("saves/save-".$key_requested.".xml");
nickjillings@2147 35 return;
nickjillings@2147 36 } else {
nickjillings@2147 37 echo $xml_error;
nickjillings@2147 38 return;
nickjillings@2147 39 }
nickjillings@2147 40 ?>