PageRenderTime 56ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/query.php

https://bitbucket.org/mikel3377/webgame
PHP | 81 lines | 47 code | 16 blank | 18 comment | 9 complexity | 2293fe2a9cd8ffa5d9a4761ab3500556 MD5 | raw file
  1. <?php
  2. // echo json_encode( array( 'status' => $_SERVER['QUERY_STRING']) );
  3. // return;
  4. include('lib/applicationlib.php');
  5. use updatelib as ulib;
  6. if(isset($_POST['gameid']) && isset($_POST['updateid']) && isset($_POST['updates']))
  7. {
  8. $gameid = mysql_real_escape_string( $_POST['gameid']);
  9. $updateid = mysql_real_escape_string( $_POST['updateid']);
  10. $query = "SELECT * FROM gameupdates WHERE gameid = $gameid AND id > $updateid ORDER BY id ASC";
  11. $result = mysql_query($query);
  12. $updateList=array();
  13. while ($row = mysql_fetch_array($result))
  14. {
  15. /*
  16. if ($row["type"]==1) //move
  17. {
  18. $updateList[] = new ulib\MoveUpdate($row["gameid"],(int)$row["id"],$row["param1"],$row["param2"],$row["param3"]);
  19. }
  20. if ($row["type"]==2) //attack
  21. {
  22. $updateList[] = new ulib\AttackUpdate($row["gameid"],(int)$row["id"],$row["param1"],$row["param2"],$row["param3"]);
  23. }
  24. if ($row["type"]==3) //turn update
  25. {
  26. $updateList[] = new ulib\TurnUpdate($row["gameid"],(int)$row["id"],$row["param1"]);
  27. }
  28. */
  29. $updateList[] = ulib\GetUpdateObject($row);
  30. }
  31. $response = array( "status" => "OK",
  32. "updates" => $updateList );
  33. echo json_encode( $response );
  34. return;
  35. }
  36. else if(isset($_POST['gameid']))
  37. {
  38. $gameid = mysql_real_escape_string( $_POST['gameid']);
  39. $gameData = Application::$GameDataService->GetGameByID( $gameid );
  40. if( !isset( $_POST['updateid'] ) )
  41. {
  42. $response = array( "status" => "UPDATE", "data" => $gameData );
  43. echo json_encode( $response );
  44. return;
  45. }
  46. $updateid = mysql_real_escape_string( $_POST['updateid']);
  47. if( (int)$updateid != $gameData->UpdateID )
  48. {
  49. $response = array( "status" => "UPDATE", "data" => $gameData );
  50. echo json_encode( $response );
  51. return;
  52. }
  53. $response = array( "status" => "NO UPDATE" );
  54. echo json_encode( $response );
  55. return;
  56. }
  57. else
  58. {
  59. echo json_encode( array( 'status' => 'gameid not set') );
  60. return;
  61. }
  62. echo json_encode( array( 'status' => 'invalid parameters') );
  63. ?>