3 mysqli_report(MYSQLI_REPORT_ERROR);
7 // URL引数でUserID(uid)を渡す。
12 $db = new mysqli('localhost', DATABASE_USER, DATABASE_PWD, DATABASE_NAME);
13 if (mysqli_connect_error()) {
17 $db->set_charset("utf8");
19 if(isset($_GET['uid']) && isset($_GET['action'])){
21 $action = $_GET['action'];
23 $stmt = $db->prepare(QUERY_SELECT_USER_STAGE_AND_TIMESTAMP);
24 $stmt->bind_param(QUERY_SELECT_USER_STAGE_AND_TIMESTAMP_TYPES, $uid);
26 if($stmt->errno != 0){
30 $stmt->store_result();
31 if($stmt->num_rows == 0){
34 $stmt->bind_result($stgName, $lastTimeStamp);
38 //if ($_SERVER['REQUEST_METHOD'] != "POST"){
41 $request_param = array();
42 foreach ( $_POST as $k => $v){
43 // URL デコードを行い値を連想配列に格納する
44 $request_param{"$k"} = urldecode($v);
47 if(strcmp($action, 'add') == 0){
49 //postデータは、"origin.x,origin.y,speed.x,speed.y,className,attribute,constructorArgs"
50 //retvデータは、"[timestamp,[objectID, ...], [[objectID,origin.x,origin.y,speed.x,speed.y,className,attribute,constructorArgs]...]]"
52 foreach($request_param as $aParam){
53 $subparam = explode('|', $aParam);
54 $stmt = $db->prepare(QUERY_ADD_OBJECT);
55 $stmt->bind_param(QUERY_ADD_OBJECT_TYPES, $subparam[0], $subparam[1], $subparam[2], $subparam[3], $stgName, $subparam[4], $subparam[5], $subparam[6],$uid, getTimeStampMs(), getTimeStampMs());
57 if($stmt->errno != 0){
60 array_push($retarray, $db->insert_id);
64 echo("[" . getTimeStampMs() . ",[");
65 foreach($retarray as $v){
69 echo(getAllOtherUserObjectArrayString($db, $uid, $stgName));
71 } else if(strcmp($action, 'refresh') == 0){
73 //postデータは、"objectID,origin.x,origin.y,speed.x,speed.y,attribute"
74 foreach($request_param as $aParam){
75 $subparam = explode('|', $aParam);
76 $stmt = $db->prepare(QUERY_UPDATE_STAGE_OBJECT);
77 $stmt->bind_param(QUERY_UPDATE_STAGE_OBJECT_TYPES, $subparam[1], $subparam[2], $subparam[3], $subparam[4], $subparam[5], getTimeStampMs(), $stgName, $subparam[0]);
79 if($stmt->errno != 0){
87 //[objectID,origin.x,origin.y,speed.x,speed.y,className,attribute,constructorArgs]"
89 $stmt = $db->prepare(QUERY_SELECT_ADDED_OBJECT);
90 $stmt->bind_param(QUERY_SELECT_ADDED_OBJECT_TYPES, $stgName, $uid, $lastTimeStamp);
92 if($stmt->errno != 0){
95 $result = $stmt->get_result();
96 for($i = 0; $i < $result->num_rows; $i++){
97 $tmpAry = $result->fetch_array(MYSQLI_NUM);
98 array_push($retv2, "[" . $tmpAry[0] . "," . $tmpAry[1] . "," . $tmpAry[2] . "," . $tmpAry[3] . "," . $tmpAry[4] . ",\"" . $tmpAry[5] . "\",\"" . $tmpAry[6] . "\",\"" . $tmpAry[7] . "\"," . $tmpAry[8] . "]");
102 //[objectID,origin.x,origin.y,speed.x,speed.y,className,attribute]"
104 $stmt = $db->prepare(QUERY_SELECT_UPDATED_OBJECT);
106 exit("error:" . $db->error);
108 $stmt->bind_param(QUERY_SELECT_UPDATED_OBJECT_TYPES, $stgName, $uid, $lastTimeStamp, $lastTimeStamp);
110 if($stmt->errno != 0){
113 $result = $stmt->get_result();
114 for($i = 0; $i < $result->num_rows; $i++){
116 $tmpAry = $result->fetch_array(MYSQLI_NUM);
117 array_push($retv1, "[" . $tmpAry[0] . "," . $tmpAry[1] . "," . $tmpAry[2] . "," . $tmpAry[3] . "," . $tmpAry[4] . ",\"" . $tmpAry[5] . "\",\"" . $tmpAry[6] . "\"]");
123 $stmt = $db->prepare(QUERY_SELECT_DELETED_OBJECT);
124 $stmt->bind_param(QUERY_SELECT_DELETED_OBJECT_TYPES, $stgName, $uid, $lastTimeStamp);
126 if($stmt->errno != 0){
129 $result = $stmt->get_result();
130 for($i = 0; $i < $result->num_rows; $i++){
131 $tmpAry = $result->fetch_array(MYSQLI_NUM);
132 array_push($retv3, $tmpAry[0]);
138 $stmt = $db->prepare("select id, name from authUserTable");
140 if($stmt->errno != 0){
143 $result = $stmt->get_result();
144 for($i = 0; $i < $result->num_rows; $i++){
145 $tmpAry = $result->fetch_array(MYSQLI_NUM);
146 array_push($retv4, $tmpAry[0] . ":\"" . $tmpAry[1] . "\"");
151 echo(getTimeStampMs());
153 foreach($retv1 as $v){
157 foreach($retv2 as $v){
161 foreach($retv3 as $v){
165 foreach($retv4 as $v){
170 updateUserTimestamp($db, $uid);
174 function getAllOtherUserObjectArrayString($db, $userID, $stageName)
177 $stmt = $db->prepare(QUERY_SELECT_ALL_OTHER_USER_OBJECT);
178 $limittime = getTimeStampMs() - USER_ALIVE_TIME_MS;
179 $stmt->bind_param(QUERY_SELECT_ALL_OTHER_USER_OBJECT_TYPES, $stageName, $userID, $limittime);
181 if($stmt->errno != 0){
184 $result = $stmt->get_result();
185 for($i = 0; $i < $result->num_rows; $i++){
186 $tmpAry = $result->fetch_array(MYSQLI_NUM);
187 array_push($retary, "[" . $tmpAry[0] . "," . $tmpAry[1] . "," . $tmpAry[2] . "," . $tmpAry[3] . "," . $tmpAry[4] . ",\"" . $tmpAry[5] . "\",\"" . $tmpAry[6] . "\",\"" . $tmpAry[7] . "\"," . $tmpAry[8] . "]");
191 foreach($retary as $v){
192 $retstr = $retstr . $v . ",";
194 $retstr = $retstr . "]";
205 function responseError()
207 exit("[0, 0, null];");