source: subversion/sites/other/tilesAtHome/Requests/index.php @ 3655

Last change on this file since 3655 was 2941, checked in by ojw, 13 years ago

display errors

File size: 1.6 KB
Line 
1<?php
2  header("Content-type:text/plain");
3
4  if(0){ // Option to kill database access, but keep sending request queries
5    printf("OK|3|%d|%d|%d|dev_random",
6      rand(0,4095),
7      rand(0,4095),
8      12);
9  exit;
10  }
11
12  if(0){ // Option to kill request queries
13    print "XX|3||||disabled";
14    exit;
15  }
16
17  if(0){
18    if(rand(0,3) != 0){
19      print "XX|3||||rate_limiting";
20      exit;
21    }
22  }
23
24  include("../connect/connect.php");
25  include("../lib/log.inc");
26  include("../lib/requests.inc");
27  include("../lib/versions.inc");
28
29  # Check whether the client version is allowed to upload
30  # (if they can't, there's no point in them taking requests)
31  $VersionID = checkVersion($_GET["version"]);
32  if($VersionID == -1){
33    print "XX|3||||client_version_unacceptable";
34    exit;
35  }
36
37  CheckForRequest();
38  print "XX|3||||nothing_to_do";
39  // Queue empty, return a random tile
40  //$x = rand(0,4095);
41  //$y = rand(0,4095);
42  //printf("OK|3|%d|%d|%d|dev_random",$x,$y,12);
43
44function CheckForRequest(){
45  $SQL =  "select `x`,`y`,`status`,`priority`,`date` from `tiles_queue` where `status`=0 union ";
46  $SQL .= "select `x`,`y`,`status`,`priority`,`date` from `tiles_queue` where `status`=1 ";
47  $SQL .= "order by `priority`,`date` limit 1;";
48
49//  print "$SQL\n";return;
50  $Result = mysql_query($SQL);
51
52  if(mysql_errno()){
53    print "XX|3||||error: " . mysql_error();
54    exit;
55  }
56  if(mysql_num_rows($Result) == 0){
57    return;
58  }
59
60  $Data = mysql_fetch_assoc($Result);
61  printf("OK|3|%d|%d|%d|db",
62    $Data["x"],
63    $Data["y"],
64    12);
65
66  moveRequest(
67    $Data["x"],
68    $Data["y"],
69    $Data["status"],
70    REQUEST_ACTIVE);
71
72  logSqlError();
73  exit;
74}
75
76?>
Note: See TracBrowser for help on using the repository browser.