className char(64),
objectAttribute char(255),
ownerUserID int,
+ modifiedTimestamp bigint,
+ addedTimestamp bigint,
index(id)
);
create table userInventoryTable (
if($stmt->num_rows == 0){
//ユーザー名はリストになかった=はじめてのひと
$stmt = $db->prepare(QUERY_ADD_USER);
- $stmt->bind_param(QUERY_ADD_USER_TYPES, $name);
+ $stgName = DEFAULT_START_STAGE;
+ $stmt->bind_param(QUERY_ADD_USER_TYPES, $name, $stgName);
$stmt->execute();
if($stmt->errno == 0){
//クエリ成功
//
// response
//
-// [[userID], [timestamp], [stageName], [info]];
+// [[userID], [timestamp], [stageName], [info], [[objectID,origin.x,origin.y,speed.x,speed.y,className,attribute], ...]];
// info == 10: エラーなし。ログインできる。
// info == 0:データベース通信エラー。ログインできない。
// info == 11: すでにユーザーがログインしている。ログインできない。
{
updateUserTimestamp($db, $userID);
updateUserStage($db, $userID, DEFAULT_START_STAGE);
- exit("[" . $userID . "," . getTimeStampMs() . ",\"" . DEFAULT_START_STAGE . "\", 10];");
+ exit("[" . $userID . "," . getTimeStampMs() . ",\"" . DEFAULT_START_STAGE . "\", 10]");
}
function responseExistUser($db, $userID, $stageName)
// info == 11: すでにユーザーがログインしている。ログインできない。
exit("[" . $userID . "," . getTimeStampMs() . ",\"" . $stageName . "\", 11];");
}
+ deleteUserStageObjectAll($db, $userID);
updateUserTimestamp($db, $userID);
- exit("[" . $userID . "," . getTimeStampMs() . ",\"" . $stageName . "\", 10];");
+ exit("[" . $userID . "," . getTimeStampMs() . ",\"" . $stageName . "\", 10]");
}
//
//エラーチェック省略
}
+function deleteUserStageObjectAll($db, $userID)
+{
+ $stmt = $db->prepare(QUERY_DELETE_USER_OBJECT_ALL);
+ $stmt->bind_param(QUERY_DELETE_USER_OBJECT_ALL_TYPES, $userID);
+ $stmt->execute();
+ //エラーチェック省略
+}
+
//
// add
//
CharacterClass.base.apply(this, [stage]);
//\83L\83\83\83\89\93Æ\8e©\82Ì\8b@\94\\81i\82½\82Æ\82¦\82Î\8dU\8c\82\82â\91\8a\8eè\82ª\93\96\82½\82Á\82Ä\82«\82½\82Æ\82«\82Ì\82 \82½\82è\94»\92è\82È\82Ç)
-
+ this.ownerUID = 0;
+ this.objectID = 0;
}.extend(MovableStageObjectClass, {
+ className: "CharacterClass",
draw: function(){
//\8cÊ\82Ì\95`\89æ
this.stage.mainContext.save();
tick: function(){
MovableStageObjectClass.prototype.tick.apply(this, []);
- }
+ },
});
this.debugContext = null;
//StageObject\82Ì\83\8a\83X\83g
this.stageObjectList = new Array();
+ this.globalStageObjectList = new Array();
//\83I\81[\83o\81[\83\89\83C\83h\82³\82ê\82é\89Â\94\\90«\82Ì\82 \82é\8aÖ\90\94\82Ì\95Û\91¶
//this.super = new Object();
//\8fã\8bL\82Ì\95û\96@\82Å\82Í\81Athis\82ªsuper\82É\82È\82Á\82Ä\82µ\82Ü\82¢\93®\8dì\82µ\82È\82¢\82Ì\82Å\81A\93¯\88ê\8aK\91w\82É\8aÖ\90\94\82Ì\8eQ\8fÆ\82ð\8dì\90¬\82·\82é\82±\82Æ\82É\82È\82Á\82½\81B
this.collisionMapContext = null;
this.stageObjectList = null;
},
- addStageObject: function(aStageObject){
-
+ addStageObject: function(aStageObject, isGlobalObject){
+ //isGlobalObject:\83l\83b\83g\83\8f\81[\83N\8dX\90V\82ª\95K\97v\82È\8fê\8d\87true\82ð\93n\82·\81B\95s\97v\82È\8fê\8d\87\82Í\8fÈ\97ª\82Å\82«\82é\81B
var sp = aStageObject.constructor;
- if(!this.stageObjectList[sp])
+ if(this.stageObjectList[sp] == undefined)
{
this.stageObjectList[sp] = [];
}
this.stageObjectList[sp].push(aStageObject);
+ if(isGlobalObject){
+ this.globalStageObjectList.push(aStageObject);
+ }
},
removeStageObject: function(aStageObject){
var sp = aStageObject.constructor;
removeObjectFromArray(this.stageObjectList, sp);
}
}
+ removeObjectFromArray(this.globalStageObjectList, aStageObject);
},
eachStageObject: function(f){
for(var sp in this.stageObjectList)
f(stgobj);
}
}
- }
+ },
+ eachOwnStageObject: function(f){
+ //\8e©\95ª\8e©\90g\82ª\8f\8a\97L\82·\82é\83I\83u\83W\83F\83N\83g\82·\82×\82Ä\82É\91Î\82µ\82Ä\8aÖ\90\94f\82ð\93K\97p\82·\82é
+ for(var sp in this.stageObjectList)
+ {
+ for(i = 0; i < this.stageObjectList[sp].length; i++){
+ var stgobj = this.stageObjectList[sp][i];
+ if(stgobj.ownerUID == this.manager.userID){
+ f(stgobj);
+ }
+ }
+ }
+ },
+ getGlobalStageObject: function(objid){
+ for(i = 0; i < this.globalStageObjectList.length; i++){
+ if(objid == this.globalStageObjectList[i].objectID){
+ return this.globalStageObjectList[i];
+ }
+ }
+ return null;
+ },
};
//\83C\83\81\81[\83W\82Ì\8dÅ\91å\90\94
//
//定数
//
-var URL_PCD_Root = "http://192.168.6.242/pcd2013dev/www/";
+
+//var URL_PCD_Root = "http://localhost/pcd2013dev/www/";
+//var URL_PCD_Root = "http://192.168.6.242/pcd2013dev/www/";
//var URL_PCD_Root = "http://192.168.0.8/PCD2013GSCL/www/";
+var URL_PCD_Root = "http://192.168.6.242/pcd2013hikarupsp/pcd2013dev/www/";
var URL_PCD_Auth = URL_PCD_Root + "auth.php";
var URL_PCD_Stage = URL_PCD_Root + "stage/";
var URL_PCD_Stage_Local = "stage/";
this.timeStamp = 0;
//タイマーカウントの秒あたりの回数を設定
this.tickPerSecond = 60;
- this.updateIntervalMs = 250;
+ this.updateIntervalMs = 128;
//キーボード状態を格納するプロパティの設定
this.keyState = new Object();
this.keyState.upArrow = false;
event.preventDefault();
break;
}
-
- this.debugOut("keyDw:" + keyCode + "\n");
//実行中のステージに通知
if(this.runningStage){
this.runningStage.keyDown(event);
this.keyState.rightArrow = false;
break;
}
-
- this.debugOut("keyUp:" + keyCode + "\n");
//実行中のステージに通知
if(this.runningStage){
this.runningStage.keyUp(event);
this.timeStamp += this.updateIntervalMs;
drawText(this.debugContext, " timeStamp:" + this.timeStamp, 0, 40);
+ //サーバーに追加情報をアップデート
//update
if(this.userID != 0){
request = this.networkManager.CreateRequestObject();
- request.onreadystatechange = function(){
- //requestコールバックなのでthisはrequest!
- //onloadedはステージプリロード用
- switch(request.readyState){
- case 0:
- //console.log("XMLHttpRequest created.");
- break;
- case 1:
- //console.log("open() called.");
- break;
- case 2:
- //console.log("Response header received.");
- break;
- case 3:
- //console.log("Response body receiving.");
- break;
- case 4:
- //mainManager.debugOut("send() compleated.\n");
- //mainManager.debugOut("status:" + this.status + ":" + this.statusText + "\n");
- if(request.status == 0){
- //alert("ネットワークにアクセスできません。" + this.status + ":" + this.statusText);
- }else if((200 <= request.status && request.status < 300) || (request.status == 304)){
- //console.log("ACK");
- var res = request.responseText
- this.timeStamp = eval(res);
- drawText(mainManager.debugContext, "ServertimeStamp:" + res.toString(), 0, 80);
- }else{
- //alert("サーバーがエラーを返しました。" + this.status + ":" + this.statusText);
- }
- break;
+ //同期モード
+ request.open('POST', URL_PCD_Root + "update.php?uid=" + this.userID + "&action=refresh", false);
+
+ aData = new FormData();
+
+ for(i = 0; i < this.runningStage.globalStageObjectList.length; i++){
+ anObj = this.runningStage.globalStageObjectList[i];
+ if(anObj.ownerUID == this.userID){
+ aData.append(i, anObj.objectID + "," + anObj.origin.x + "," + anObj.origin.y + "," + anObj.movingSpeed.x + "," + anObj.movingSpeed.y+ "," + "F");
}
- };
- request.open('GET', URL_PCD_Root + "update.php?uid=" + this.userID);
+ }
+
this.networkManager.RequestObjectDisableCache(request);
- request.send(null);
+
+ request.send(aData);
+
+ if(request.status == 0){
+ alert("ネットワークにアクセスできません。" + this.status + ":" + this.statusText);
+ }else if((200 <= request.status && request.status < 300) || (request.status == 304)){
+ var res = request.responseText;
+ retArray = eval(res);
+ this.timeStamp = retArray[0];
+ //削除処理
+ for(var i = 0; i < retArray[3].length; i++){
+ anObject = this.runningStage.getGlobalStageObject(retArray[3][i]);
+ //removeObjectFromArray(retArray[3], anObject);
+ }
+ //更新処理
+ //this.debugOut("refdata:" + retArray[1].length + "\n");
+ for(var i = 0; i < retArray[1].length; i++){
+ anArray = retArray[1][i];
+ //this.debugOut("i:" + i + "\n");
+ anObject = this.runningStage.getGlobalStageObject(anArray[0]);
+ if(anObject){
+ //this.debugOut("refresh:ID=" + anArray[0] + "\n");
+ anObject.origin.x = anArray[1];
+ anObject.origin.y = anArray[2];
+ anObject.movingSpeed.x = anArray[3];
+ anObject.movingSpeed.y = anArray[4];
+ } else{
+ //this.debugOut("notFound:ID=" + anArray[0] + "\n");
+ }
+ }
+ //this.debugOut("outi:" + i + "\n");
+ //追加処理
+ for(var i = 0; i < retArray[2].length; i++){
+ anArray = retArray[2][i];
+ anObject = eval("new " + anArray[5] + "(this.runningStage);");
+ if(anObject){
+ this.debugOut("Network:addObject:ObjectID=" + anArray[0] + "\n");
+ anObject.objectID = anArray[0];
+ anObject.origin.x = anArray[1];
+ anObject.origin.y = anArray[2];
+ anObject.movingSpeed.x = anArray[3];
+ anObject.movingSpeed.y = anArray[4];
+ anObject.frame.size.x = 2 * (8 + 1);
+ anObject.frame.size.y = 2 * (8 + 1);
+ this.runningStage.addStageObject(anObject, true);
+ }
+ }
+ }else{
+ alert("サーバーがエラーを返しました。" + this.status + ":" + this.statusText);
+ }
+
}
},
runStage: function(stage){
stage.debugContext = this.debugContext
//GameStage側の初期化処理を行わせる。
stage.runStage();
+ //サーバーに追加情報をアップデート
+ //update
+ if(this.userID != 0){
+ request = this.networkManager.CreateRequestObject();
+ //同期モード
+ request.open('POST', URL_PCD_Root + "update.php?uid=" + this.userID + "&action=add", false);
+
+ aData = new FormData();
+
+ for(i = 0; i < stage.globalStageObjectList.length; i++){
+ anObj = stage.globalStageObjectList[i];
+ aData.append(i, anObj.origin.x.toString() + "," + anObj.origin.y.toString() + "," + anObj.movingSpeed.x.toString() + "," + anObj.movingSpeed.y.toString() + "," + anObj.className + "," + "F");
+ }
+
+ this.networkManager.RequestObjectDisableCache(request);
+
+ request.send(aData);
+
+ if(request.status == 0){
+ alert("ネットワークにアクセスできません。" + this.status + ":" + this.statusText);
+ }else if((200 <= request.status && request.status < 300) || (request.status == 304)){
+ var res = request.responseText
+ var retArray = eval(res);
+ this.timeStamp = retArray[0];
+ for(var i = 0; i < stage.globalStageObjectList.length; i++){
+ stage.globalStageObjectList[i].objectID = retArray[1][i];
+ }
+ for(var i = 0; i < retArray[2].length; i++){
+ var anArray = retArray[2][i];
+ var anObject = eval("new " + anArray[5] + "(stage);");
+ if(anObject){
+ this.debugOut("Network:addObject:ObjectID=" + anArray[0] + "\n");
+ anObject.objectID = anArray[0];
+ anObject.origin.x = anArray[1];
+ anObject.origin.y = anArray[2];
+ anObject.movingSpeed.x = anArray[3];
+ anObject.movingSpeed.y = anArray[4];
+ anObject.frame.size.x = 2 * (8 + 1);
+ anObject.frame.size.y = 2 * (8 + 1);
+ stage.addStageObject(anObject, true);
+ }
+ }
+ }else{
+ alert("サーバーがエラーを返しました。" + this.status + ":" + this.statusText);
+ }
+
+ }
//runningStageに登録することで、イベントの通知が開始され、GameStageは実行状態に入る。
this.runningStage = stage;
},
var stage = eval(code);
mainManager.runStage(stage);
},
- loadStageFromNetwork: function(name, onLoaded){
+ loadStageFromNetwork: function(name){
//urlに存在するjavascriptファイルを利用してステージを作成する。
request = this.networkManager.CreateRequestObject();
- request.onreadystatechange = function(){
- //requestコールバックなのでthisはrequest!とは限らない(IE)
- console.log("state:" + request.readyState);
- switch(request.readyState){
- case 0:
- //console.log("XMLHttpRequest created.");
- break;
- case 1:
- //console.log("open() called.");
- break;
- case 2:
- //console.log("Response header received.");
- break;
- case 3:
- //console.log("Response body receiving.");
- break;
- case 4:
- //mainManager.debugOut("send() compleated.\n");
- //mainManager.debugOut("status:" + this.status + ":" + this.statusText + "\n");
- if(request.status == 0){
- alert("ネットワークにアクセスできません。" + request.status + ":" + request.statusText);
- }else if((200 <= request.status && request.status < 300) || (request.status == 304)){
- //console.log("ACK");
- var stage = eval(request.responseText);
- mainManager.runStage(stage);
- }else{
- alert("サーバーがエラーを返しました。" + request.status + ":" + request.statusText);
- }
- break;
- }
- };
- request.open('GET', URL_PCD_Stage + name + ".js");
+ //同期モード
+ request.open('GET', URL_PCD_Stage + name + ".js", false);
this.networkManager.RequestObjectDisableCache(request);
- //IEで使えない…
- //console.log("reqObject:" + request.toString());
request.send(null);
+ if(request.status == 0){
+ alert("ネットワークにアクセスできません。" + request.status + ":" + request.statusText);
+ }else if((200 <= request.status && request.status < 300) || (request.status == 304)){
+ //console.log("ACK");
+ var stage = eval(request.responseText);
+ mainManager.runStage(stage);
+ }else{
+ alert("サーバーがエラーを返しました。" + request.status + ":" + request.statusText);
+ }
},
debugOut: function(str){
if(!/*@cc_on!@*/false)
return ((0.5 + coordinateElement) | 0);
}
-
//データベース名
define("DATABASE_NAME", "pcd2013dev");
-//SQL文 for AuthUserTable
-define("QUERY_SELECT_USER_ID", "SELECT id from authUserTable where name = ?;");
+//SQL文 for authUserTable
+define("QUERY_SELECT_USER_ID", "SELECT id from authUserTable where name = ?");
define("QUERY_SELECT_USER_ID_TYPES", "s");
-define("QUERY_SELECT_USER_STAGE", "SELECT userStageName from authUserTable where id = ?;");
+define("QUERY_SELECT_USER_STAGE", "SELECT userStageName from authUserTable where id=?");
define("QUERY_SELECT_USER_STAGE_TYPES", "i");
-define("QUERY_ADD_USER", "insert into authUserTable (name) values (?)");
-define("QUERY_ADD_USER_TYPES", "s");
-define("QUERY_UPDATE_USER_STAGE", "UPDATE authUserTable SET userStageName=? WHERE id=?;");
+define("QUERY_SELECT_USER_STAGE_AND_TIMESTAMP", "SELECT userStageName, lastResponseTimestamp from authUserTable where id=?");
+define("QUERY_SELECT_USER_STAGE_AND_TIMESTAMP_TYPES", "i");
+define("QUERY_ADD_USER", "insert into authUserTable (name, userStageName) values (?, ?)");
+define("QUERY_ADD_USER_TYPES", "ss");
+define("QUERY_UPDATE_USER_STAGE", "UPDATE authUserTable SET userStageName=? WHERE id=?");
define("QUERY_UPDATE_USER_STAGE_TYPES", "si");
-define("QUERY_UPDATE_USER_TIMESTAMP", "UPDATE authUserTable SET lastResponseTimestamp=? WHERE id=?;");
+define("QUERY_UPDATE_USER_TIMESTAMP", "UPDATE authUserTable SET lastResponseTimestamp=? WHERE id=?");
define("QUERY_UPDATE_USER_TIMESTAMP_TYPES", "ii");
-define("QUERY_SELECT_USER_TIMESTAMP", "SELECT lastResponseTimestamp from authUserTable where id = ?;");
+define("QUERY_SELECT_USER_TIMESTAMP", "SELECT lastResponseTimestamp from authUserTable where id = ?");
define("QUERY_SELECT_USER_TIMESTAMP_TYPES", "i");
-
+//SQL文 for stageObjectTable
+define("QUERY_ADD_OBJECT", "insert into stageObjectTable (locationX, locationY, velocityX, velocityY, stageName, className, objectAttribute, ownerUserID, modifiedTimestamp, addedTimestamp) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+define("QUERY_ADD_OBJECT_TYPES", "ddddsssiii");
+define("QUERY_DELETE_USER_OBJECT_ALL", "delete from stageObjectTable where ownerUserID=?");
+define("QUERY_DELETE_USER_OBJECT_ALL_TYPES", "i");
+define("QUERY_SELECT_ADDED_OBJECT", "SELECT id, locationX, locationY, velocityX, velocityY, className, objectAttribute FROM stageObjectTable WHERE stageName=? AND ownerUserID<>? AND addedTimestamp>? AND objectAttribute<>'Deleted'");
+define("QUERY_SELECT_ADDED_OBJECT_TYPES", "sii");
+define("QUERY_SELECT_UPDATED_OBJECT", "SELECT id, locationX, locationY, velocityX, velocityY, className, objectAttribute FROM stageObjectTable WHERE stageName=? AND ownerUserID<>? AND modifiedTimestamp>=? AND addedTimestamp<? AND objectAttribute<>'Deleted'");
+define("QUERY_SELECT_UPDATED_OBJECT_TYPES", "siii");
+define("QUERY_SELECT_DELETED_OBJECT", "SELECT id, locationX, locationY, velocityX, velocityY, className, objectAttribute FROM stageObjectTable WHERE stageName=? AND ownerUserID<>? AND modifiedTimestamp>=? AND objectAttribute='Deleted'");
+define("QUERY_SELECT_DELETED_OBJECT_TYPES", "sii");
+define("QUERY_UPDATE_STAGE_OBJECT", "UPDATE stageObjectTable SET locationX=?, locationY=?, velocityX=?, velocityY=?, objectAttribute=?, modifiedTimestamp=? WHERE stageName=? AND id=? AND objectAttribute<>'Deleted'");
+define("QUERY_UPDATE_STAGE_OBJECT_TYPES", "ddddsisi");
+define("QUERY_SELECT_ALL_OTHER_USER_OBJECT", "SELECT id, locationX, locationY, velocityX, velocityY, className, objectAttribute FROM stageObjectTable WHERE stageName=? AND ownerUserID<>? AND modifiedTimestamp>? AND objectAttribute<>'Deleted'");
+define("QUERY_SELECT_ALL_OTHER_USER_OBJECT_TYPES", "sii");
//デフォルト開始ステージ名
define("DEFAULT_START_STAGE", "main");
$stmt->bind_param(QUERY_UPDATE_USER_TIMESTAMP_TYPES, getTimeStampMs(), $userID);
$stmt->execute();
//エラーチェック省略
+ $stmt->close();
}
function getUserLastResponseTimestamp($db, $userID)
$stmt->fetch();
}
}
+ $stmt->close();
return $ts;
}
stage.runStage = function(){
//元々定義されていた、疑似スーパークラス(prototype)の関数を呼び出す。
GameStage.prototype.runStage.apply(this, []);
- for(i = 0; i < 2; i++){
- aCircle = new CharacterClass(this);
- aCircle.origin.x = 16 + 16 * i;
- aCircle.origin.y = 16 + 16 * i;
- aCircle.frame.origin.x = - (8 + i);
- aCircle.frame.origin.y = - (8 + i);
- aCircle.frame.size.x = 2 * (8 + i);
- aCircle.frame.size.y = 2 * (8 + i);
-
- this.addStageObject(aCircle);
- }
+
+ //メインキャラクタの設定
+ aCircle = new CharacterClass(this);
+ aCircle.ownerUID = this.manager.userID;
+ aCircle.origin.x = 16 + 16 * 1;
+ aCircle.origin.y = 16 + 16 * 1;
+ aCircle.frame.origin.x = - (8 + 1);
+ aCircle.frame.origin.y = - (8 + 1);
+ aCircle.frame.size.x = 2 * (8 + 1);
+ aCircle.frame.size.y = 2 * (8 + 1);
+ this.addStageObject(aCircle, true);
};
stage.drawBackground = function(){
-console.log(this.manager.timeStamp);
- this.mainContext.fillStyle = (["rgb(200,0,0)","rgb(0,200,0)","rgb(0,0,200)"])[Math.floor((this.manager.timeStamp) / 60) % 3];
+ //this.mainContext.fillStyle = (["rgb(200,0,0)","rgb(0,200,0)","rgb(0,0,200)"])[Math.floor((this.manager.timeStamp) / 60) % 3];
this.mainContext.fillRect(0, 0, this.mainCanvas.width, this.mainCanvas.height);
this.collisionMapContext.clearRect(0, 0, this.collisionMapCanvas.width * 8, this.collisionMapCanvas.height * 8);
GameStage.prototype.timerTick.apply(stage, []);
if(this.manager.keyState.upArrow){
//上カーソル
- stage.eachStageObject(function(item){item.movingSpeed.y -= stage.moveForce; });
+ stage.eachOwnStageObject(function(item){item.movingSpeed.y -= stage.moveForce; });
}
if(this.manager.keyState.downArrow){
//下カーソル
- stage.eachStageObject(function(item){item.movingSpeed.y += stage.moveForce;});
+ stage.eachOwnStageObject(function(item){item.movingSpeed.y += stage.moveForce;});
}
if(this.manager.keyState.leftArrow){
- stage.eachStageObject(function(item){item.movingSpeed.x -= stage.moveForce;});
+ stage.eachOwnStageObject(function(item){item.movingSpeed.x -= stage.moveForce;});
}
if(this.manager.keyState.rightArrow){
//右カーソル
- stage.eachStageObject(function(item){item.movingSpeed.x += stage.moveForce;});
+ stage.eachOwnStageObject(function(item){item.movingSpeed.x += stage.moveForce;});
}
};
<?php
+//FOR DEBUG
+mysqli_report(MYSQLI_REPORT_ERROR);
+
require("header.php");
//MySQL 更新データの仕様
// URL引数でUserID(uid)を渡す。
// 文字化け防止
$db->set_charset("utf8");
-if(isset($_GET['uid'])){
+if(isset($_GET['uid']) && isset($_GET['action'])){
$uid = $_GET['uid'];
- $stmt = $db->prepare(QUERY_SELECT_USER_STAGE);
- $stmt->bind_param(QUERY_SELECT_USER_STAGE_TYPES, $uid);
+ $action = $_GET['action'];
+ //ステージ名の取得
+ $stmt = $db->prepare(QUERY_SELECT_USER_STAGE_AND_TIMESTAMP);
+ $stmt->bind_param(QUERY_SELECT_USER_STAGE_AND_TIMESTAMP_TYPES, $uid);
$stmt->execute();
-
- if($stmt->errno == 0){
- //クエリ成功
- $stmt->store_result();
- if($stmt->num_rows == 0){
- //echo "nothing";
- } else{
- $stmt->bind_result($stageName);
+ if($stmt->errno != 0){
+ exit("error0");
+ }
+ //クエリ成功
+ $stmt->store_result();
+ if($stmt->num_rows == 0){
+ exit("error1");
+ }
+ $stmt->bind_result($stgName, $lastTimeStamp);
+ $stmt->fetch();
+ $stmt->close();
+
+ if ($_SERVER['REQUEST_METHOD'] != "POST"){
+ exit("error2");
+ }
+ $request_param = array();
+ foreach ( $_POST as $k => $v){
+ // URL デコードを行い値を連想配列に格納する
+ $request_param{"$k"} = urldecode($v);
+ }
+
+ if(strcmp($action, 'add') == 0){
+ //オブジェクトをデータベースに追加
+ //postデータは、"origin.x,origin.y,speed.x,speed.y,className,attribute"
+ //retvデータは、"[timestamp,[objectID, ...], [otherobjectlist]]"
+ $retarray = array();
+ foreach($request_param as $aParam){
+ $subparam = explode(',', $aParam);
+ $stmt = $db->prepare(QUERY_ADD_OBJECT);
+ $stmt->bind_param(QUERY_ADD_OBJECT_TYPES, $subparam[0], $subparam[1], $subparam[2], $subparam[3], $stgName, $subparam[4], $subparam[5], $uid, getTimeStampMs(), getTimeStampMs());
+ $stmt->execute();
+ if($stmt->errno != 0){
+ exit("error3");
+ }
+ array_push($retarray, $db->insert_id);
+ $stmt->close();
+ }
+ //出力
+ echo("[" . getTimeStampMs() . ",[");
+ foreach($retarray as $v){
+ echo($v . ",");
+ }
+ echo("],");
+ echo(getAllOtherUserObjectArrayString($db, $uid, $stgName));
+ echo("]");
+ } else if(strcmp($action, 'refresh') == 0){
+ //渡されたオブジェクトのデータ更新
+ //postデータは、"objectID,origin.x,origin.y,speed.x,speed.y,attribute"
+ //retvデータは、"[timestamp, [[objectID,origin.x,origin.y,speed.x,speed.y,className,attribute], ...], ...]"
+ foreach($request_param as $aParam){
+ $subparam = explode(',', $aParam);
+ $stmt = $db->prepare(QUERY_UPDATE_STAGE_OBJECT);
+ $stmt->bind_param(QUERY_UPDATE_STAGE_OBJECT_TYPES, $subparam[1], $subparam[2], $subparam[3], $subparam[4], $subparam[5], getTimeStampMs(), $stgName, $subparam[0]);
+ $stmt->execute();
+ if($stmt->errno != 0){
+ exit("error14");
+ }
+ $stmt->close();
+ }
+
+
+ //retv[2]:追加リスト
+ $retv2 = array();
+ $stmt = $db->prepare(QUERY_SELECT_ADDED_OBJECT);
+ $stmt->bind_param(QUERY_SELECT_ADDED_OBJECT_TYPES, $stgName, $uid, $lastTimeStamp);
+ $stmt->execute();
+ if($stmt->errno != 0){
+ exit("error7");
+ }
+ $result = $stmt->get_result();
+ for($i = 0; $i < $result->num_rows; $i++){
+ $tmpAry = $result->fetch_array(MYSQLI_NUM);
+ array_push($retv2, "[" . $tmpAry[0] . "," . $tmpAry[1] . "," . $tmpAry[2] . "," . $tmpAry[3] . "," . $tmpAry[4] . ",'" . $tmpAry[5] . "','" . $tmpAry[6] . "']");
+ }
+ $stmt->close();
+ //retv[1]:更新リスト
+ $retv1 = array();
+ $stmt = $db->prepare(QUERY_SELECT_UPDATED_OBJECT);
+ if(!$stmt){
+ exit("error:" . $db->error);
+ }
+ $stmt->bind_param(QUERY_SELECT_UPDATED_OBJECT_TYPES, $stgName, $uid, $lastTimeStamp, $lastTimeStamp);
+ $stmt->execute();
+ if($stmt->errno != 0){
+ exit("error8");
+ }
+ $result = $stmt->get_result();
+ for($i = 0; $i < $result->num_rows; $i++){
+ echo(" ");
+ $tmpAry = $result->fetch_array(MYSQLI_NUM);
+ array_push($retv1, "[" . $tmpAry[0] . "," . $tmpAry[1] . "," . $tmpAry[2] . "," . $tmpAry[3] . "," . $tmpAry[4] . ",'" . $tmpAry[5] . "','" . $tmpAry[6] . "']");
+ }
+ $stmt->close();
+ //retv[3]:削除リスト
+ $retv3 = array();
+ $stmt = $db->prepare(QUERY_SELECT_DELETED_OBJECT);
+ $stmt->bind_param(QUERY_SELECT_DELETED_OBJECT_TYPES, $stgName, $uid, $lastTimeStamp);
+ $stmt->execute();
+ if($stmt->errno != 0){
+ exit("error9");
+ }
+ $stmt->bind_result($objID, $objOrgX, $objOrgY, $objVelX, $objVelY, $objClassName, $objAttr);
+ for($i = 0; $i < $stmt->num_rows; $i++){
$stmt->fetch();
-
- //echo $stageName;
+ array_push($retv3, $objID);
+ }
+ $stmt->close();
+ //出力
+ echo("[");
+ echo(getTimeStampMs());
+ echo(",[");
+ foreach($retv1 as $v){
+ echo($v . ",");
}
+ echo("],[");
+ foreach($retv2 as $v){
+ echo($v . ",");
+ }
+ echo("],[");
+ foreach($retv3 as $v){
+ echo($v . ",");
+ }
+ echo("]]");
}
updateUserTimestamp($db, $uid);
- exit(getTimeStampMs());
+ exit();
+}
+
+function getAllOtherUserObjectArrayString($db, $userID, $stageName)
+{
+ $retary = array();
+ $stmt = $db->prepare(QUERY_SELECT_ALL_OTHER_USER_OBJECT);
+ $limittime = getTimeStampMs() - USER_ALIVE_TIME_MS;
+ $stmt->bind_param(QUERY_SELECT_ALL_OTHER_USER_OBJECT_TYPES, $stageName, $userID, $limittime);
+ $stmt->execute();
+ if($stmt->errno != 0){
+ exit("error745");
+ }
+ $result = $stmt->get_result();
+ for($i = 0; $i < $result->num_rows; $i++){
+ $tmpAry = $result->fetch_array(MYSQLI_NUM);
+ array_push($retary, "[" . $tmpAry[0] . "," . $tmpAry[1] . "," . $tmpAry[2] . "," . $tmpAry[3] . "," . $tmpAry[4] . ",'" . $tmpAry[5] . "','" . $tmpAry[6] . "']");
+ }
+ $stmt->close();
+ $retstr = "[";
+ foreach($retary as $v){
+ $retstr = $retstr . $v . ",";
+ }
+ $retstr = $retstr . "]";
+ return $retstr;
}
//