From 235327cd3e42a2456ac0d8ce910d46fe4875d0ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Thu, 17 May 2018 18:51:09 +0900 Subject: [PATCH] Add: sql - login, history_record --- src/game/global/global_variables.js | 14 +-- src/game/lib/db_connect_manager.js | 115 +++++++++++++++-- src/game/login/login.js | 63 +++------- src/game/start/start.js | 4 +- src/web/admin/activate_stage.html | 56 +++++++++ src/web/admin/activate_stage.php | 29 +++++ src/web/admin/add_user.html | 23 ++++ src/web/admin/add_user.php | 31 +++++ src/web/admin/delete_test_user_data.php | 11 ++ src/web/client/login.html | 1 + src/web/client/php/connect_test_db.php | 15 --- src/web/server/NA_service_db_setting.php | 8 ++ src/web/server/app/activated_stage_list.php | 38 ++++++ src/web/{client/php => server}/connect_db.php | 0 .../php => server/lib}/send_error_code.php | 0 src/web/server/record/history_record.php | 42 +++++++ src/web/server/record/stage_insert_record.php | 32 +++++ src/web/server/record/stage_ranking.php | 118 ++++++++++++++++++ .../check_user.php => server/user/login.php} | 20 +-- 19 files changed, 529 insertions(+), 91 deletions(-) create mode 100644 src/web/admin/activate_stage.html create mode 100644 src/web/admin/activate_stage.php create mode 100644 src/web/admin/add_user.html create mode 100644 src/web/admin/add_user.php create mode 100644 src/web/admin/delete_test_user_data.php delete mode 100644 src/web/client/php/connect_test_db.php create mode 100644 src/web/server/NA_service_db_setting.php create mode 100644 src/web/server/app/activated_stage_list.php rename src/web/{client/php => server}/connect_db.php (100%) rename src/web/{client/php => server/lib}/send_error_code.php (100%) create mode 100644 src/web/server/record/history_record.php create mode 100644 src/web/server/record/stage_insert_record.php create mode 100644 src/web/server/record/stage_ranking.php rename src/web/{client/php/check_user.php => server/user/login.php} (57%) diff --git a/src/game/global/global_variables.js b/src/game/global/global_variables.js index 0fbb623..4400653 100644 --- a/src/game/global/global_variables.js +++ b/src/game/global/global_variables.js @@ -22,13 +22,13 @@ const GAME_SCREEN_SIZE = { x: 1024, y: 768 } let sessionStorageManager = new SessionStorageManager(); { - // if(isDebugMode()) { - // sessionStorageManager.playerName = "박지상"; - // sessionStorageManager.playerUserID = 1; - // sessionStorageManager.playingAppName = "space_invaders"; - // sessionStorageManager.score = 1000; - // sessionStorageManager.highScore = 2000; - // } + if(isDebugMode()) { + sessionStorageManager.playerName = "박지상"; + sessionStorageManager.playerUserID = 24; + sessionStorageManager.playingAppName = "space_invaders"; + sessionStorageManager.score = 1000; + sessionStorageManager.highScore = 2000; + } console.log("maestroID : " + sessionStorageManager.maestroID); console.log("playerName : " + sessionStorageManager.playerName); diff --git a/src/game/lib/db_connect_manager.js b/src/game/lib/db_connect_manager.js index 6e498c2..3668120 100644 --- a/src/game/lib/db_connect_manager.js +++ b/src/game/lib/db_connect_manager.js @@ -18,30 +18,127 @@ class DBConnectManager { this.appName = appName; } + requestCheckUserLogin(userName, enterCode, onSucceededListener, onFailedListener) { + let xhr = new XMLHttpRequest(); + xhr.open("POST", "../../web/server/user/login.php", true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.onreadystatechange = function() { + if(xhr.readyState == 4 && xhr.status == 200) { + let jsonData = JSON.parse(xhr.responseText); + + if(jsonData != null && jsonData["UserID"] != null) + onSucceededListener(jsonData); + else + onFailedListener(jsonData); + } + }; + xhr.send("name=" + sessionStorageManager.playerName + "&enter_code=" + enterCode); + } + requestPlayerHistory(listener) { let historyRecordManager = new HistoryRecordManager(); - if(isDebugMode()) + /* + if(isDebugMode()) { this.loadTempPlayerHistory(historyRecordManager); - if(listener === null) - return; + if(listener !== null) + listener(historyRecordManager); - listener(historyRecordManager); + return; + } + */ + + let self = this; + + let xhr = new XMLHttpRequest(); + xhr.open("POST", "../../web/server/record/history_record.php", true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.onreadystatechange = function() { + if(xhr.readyState == 4 && xhr.status == 200) { + let jsonData = JSON.parse(xhr.responseText); + + if(jsonData != null) { + listener(self.parseJSONtoHistoryRecord(jsonData)); + } + else + onFailedListener(jsonData); + } + }; + xhr.send("UserID=" + sessionStorageManager.playerUserID + "&AppName=" + sessionStorageManager.playingAppName); + } + + parseJSONtoHistoryRecord(json) { + let historyRecordManager = new HistoryRecordManager(); + + let count = json.history.length; + for(let i = 0; i < count; i++) { + let record = new HistoryRecord( + json.history[i]["Date"], + json.history[i]["AppName"], + json.history[i]["HighScore"] + ); + historyRecordManager.push(record); + } + + return historyRecordManager; + +/* + var startIndex = 0; + var endIndex = jsonRankingList.length; + + var recordArray = []; + for(var i = startIndex; i < endIndex; i++) { + var bestRecordRow = []; + var strDate = jsonRankingList[i]['Date']; + var dateArray = strDate.split("-"); + var recordDate = new Date(dateArray[0], dateArray[1], dateArray[2]); + bestRecordRow[0] = recordDate.getMonth() + "월 " + recordDate.getDate() + "일"; + bestRecordRow[1] = Math.floor(jsonRankingList[i]['BestRecord']); + bestRecordRow[2] = getStageNameForKorean(jsonRankingList[i]['StageName']); + // console.log("$BestRecordRow : " + bestRecordRow[0] + ", " + bestRecordRow[1] + ", " + bestRecordRow[2]); + + recordArray.push(bestRecordRow); + } + + return recordArray; +*/ } requestRanking(type, listener) { let rankingRecordManager = new RankingRecordManager(); - if(isDebugMode()) - this.loadTempRanking(rankingRecordManager); + if(isDebugMode()) { + this.loadTempPlayerHistory(historyRecordManager); + + if(listener !== null) + listener(historyRecordManager); - if(listener === null) return; - - listener(rankingRecordManager); + } } + onFailed(errorMessage) { + console.log("failed : " + errorMessage); + } + + + makeXHRWithParam(url, param, onSucceededListener, onFailedListener) { + xhr.onreadystatechange = function() { + if(xhr.readyState == 4 && xhr.status == 200) { + let jsonData = JSON.parse(xhr.responseText); + + if(jsonData != null && jsonData["UserID"] != null) + onSucceededListener(jsonData); + else + onFailedListener(jsonData); + } + } + + return xhr; + } + + loadTempPlayerHistory(historyRecordManager) { historyRecordManager.push(new HistoryRecord("05/14", "space_invaders", 14460)); diff --git a/src/game/login/login.js b/src/game/login/login.js index a10e7c3..3f1ffe1 100644 --- a/src/game/login/login.js +++ b/src/game/login/login.js @@ -54,20 +54,20 @@ class Login { .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2) .boundsAlignH = 'right'; - this.inputTextBirthday = new InputTypeText(inputX, birthdayTextY); - this.inputTextBirthday.anchor.set(0.5); - this.inputTextBirthday.canvasInput.value(''); + this.inputTextEnterCode = new InputTypeText(inputX, birthdayTextY); + this.inputTextEnterCode.anchor.set(0.5); + this.inputTextEnterCode.canvasInput.value(''); if(isDebugMode()) { - this.inputTextBirthday.canvasInput.value('760621'); + this.inputTextEnterCode.canvasInput.value('760621'); } - this.inputTextBirthday.canvasInput._onkeyup = function() { + this.inputTextEnterCode.canvasInput._onkeyup = function() { if(event.keyCode == Phaser.Keyboard.ENTER) { self.startMenu(); } } this.inputTextName.canvasInput.focus(); - // this.inputTextBirthday.canvasInput.focus(); + // this.inputTextEnterCode.canvasInput.focus(); } makeButton() { @@ -80,50 +80,15 @@ class Login { startMenu() { sessionStorageManager.playerName = self.inputTextName.canvasInput._value; - let birthday = self.inputTextBirthday.canvasInput._value; + let enterCode = self.inputTextEnterCode.canvasInput._value; - let xhr = new XMLHttpRequest(); - xhr.onreadystatechange = function() { - // console.log("onreadystatechange : " + xhr); - // console.log("xhr.readyState : " + xhr.readyState); - // console.log("xhr.status : " + xhr.status); - if(xhr.readyState == 4 && xhr.status == 200) { - // console.log(xhr.responseText); - let jsonData = JSON.parse(xhr.responseText); - // console.log(JSON.stringify(jsonData)); - - // console.log(jsonData); - if(jsonData != null && jsonData["UserID"] != null) { - // login successed - - self.loginSucceeded(jsonData); - } else { - // login failed - self.loginFailed(jsonData); - } - } - } - xhr.open('POST', '../../web/client/php/check_user.php', true); - xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - let param = 'name=' + sessionStorageManager.playerName + '&birthday=' + birthday; - // console.log(param); - xhr.send(param); - - /* - let params = { - 'name': this.inputTextName.canvasInput._value, - 'birthday': this.inputTextBirthday.canvasInput._value - }; - console.log(params); - console.log(JSON.stringify(params)); - - xhr.setRequestHeader("Content-type", "application/json"); - // let data = JSON.stringify({"name":"박지상","birthday":"760621","test":101}); - xhr.send(data); - xhr.send(JSON.stringify(params)); - - // xhr.send(null); - */ + let dbConnectManager = new DBConnectManager(); + dbConnectManager.requestCheckUserLogin( + sessionStorageManager.playerName, + enterCode, + self.loginSucceeded, + self.loginFailed + ); } loginSucceeded(jsonData) { diff --git a/src/game/start/start.js b/src/game/start/start.js index 3fde5f1..bca9dad 100644 --- a/src/game/start/start.js +++ b/src/game/start/start.js @@ -25,11 +25,11 @@ class Start { // contents this.printHowToPlay(appInfoManager.getHowToPlayText(sessionStorageManager.playingAppName)); this.makeStartButton(); - this.printChartBaseLine(); this.dbConnectManager.requestPlayerHistory( historyRecordManager => { + this.printChartBaseLine(); + let underValue = historyRecordManager.underValueForGraph(); let upperValue = historyRecordManager.upperValueForGraph(); - for(let i = 0; i < historyRecordManager.count; i++) { if(i > 6) break; diff --git a/src/web/admin/activate_stage.html b/src/web/admin/activate_stage.html new file mode 100644 index 0000000..8232f01 --- /dev/null +++ b/src/web/admin/activate_stage.html @@ -0,0 +1,56 @@ + + + + + hello phaser! + + + + + + + + +
+ 전체 선택
+ +

+
+ 기본자리
+ 왼손 윗글쇠
+ 검지 글쇠
+ 오른손 윗글쇠
+ 왼손 밑글쇠
+ 오른손 밑글쇠
+ 쌍자음
+ 쌍모음
+ 짧은 글
+ 긴 글
+ +

+
+ 기본자리
+ 왼손 윗글쇠
+ 검지 글쇠
+ 오른손 윗글쇠
+ 왼손 밑글쇠
+ 오른손 밑글쇠
+ 짧은 글
+ 긴 글
+ +

+ +
+ + + \ No newline at end of file diff --git a/src/web/admin/activate_stage.php b/src/web/admin/activate_stage.php new file mode 100644 index 0000000..c08cd62 --- /dev/null +++ b/src/web/admin/activate_stage.php @@ -0,0 +1,29 @@ +query($query); + +for($i = 0; $i < $cnt; $i++) { + $array_item = $active_stage_list[$i]; + + $query = "UPDATE afterschool_activated_stage SET Activated = 1 WHERE StageName = ?"; + $stmt = $db_conn->prepare($query); + $stmt->bind_param('s', $array_item); + $stmt->execute(); + + if($stmt->affected_rows > 0) { + echo($array_item." : activated
"); + } else { + echo $array_item." : db error
"; + } +} + +?> \ No newline at end of file diff --git a/src/web/admin/add_user.html b/src/web/admin/add_user.html new file mode 100644 index 0000000..249b08a --- /dev/null +++ b/src/web/admin/add_user.html @@ -0,0 +1,23 @@ + + + + + hello phaser! + + + + +
+ 이름 :
+ 생년월일 :
+ +
+ +

+ +
+ +
+ + + \ No newline at end of file diff --git a/src/web/admin/add_user.php b/src/web/admin/add_user.php new file mode 100644 index 0000000..1411296 --- /dev/null +++ b/src/web/admin/add_user.php @@ -0,0 +1,31 @@ +prepare($query); +$stmt->bind_param('ss', $name, $birthday); +$stmt->execute(); + +if($stmt->affected_rows > 0) { + echo("succeed"); +} else { + echo "fail"; +} + +$db_conn->close(); + +?> \ No newline at end of file diff --git a/src/web/admin/delete_test_user_data.php b/src/web/admin/delete_test_user_data.php new file mode 100644 index 0000000..80b4c35 --- /dev/null +++ b/src/web/admin/delete_test_user_data.php @@ -0,0 +1,11 @@ +query($query); + +$db_conn->close(); + +?> \ No newline at end of file diff --git a/src/web/client/login.html b/src/web/client/login.html index 46eb2cd..9b2eafa 100644 --- a/src/web/client/login.html +++ b/src/web/client/login.html @@ -18,6 +18,7 @@ + diff --git a/src/web/client/php/connect_test_db.php b/src/web/client/php/connect_test_db.php deleted file mode 100644 index 2c9884d..0000000 --- a/src/web/client/php/connect_test_db.php +++ /dev/null @@ -1,15 +0,0 @@ -connect_error) { - send_error_code("Connection failed: ".$db_conn->connect_error); - exit; -} - -?> \ No newline at end of file diff --git a/src/web/server/NA_service_db_setting.php b/src/web/server/NA_service_db_setting.php new file mode 100644 index 0000000..ae05c35 --- /dev/null +++ b/src/web/server/NA_service_db_setting.php @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/src/web/server/app/activated_stage_list.php b/src/web/server/app/activated_stage_list.php new file mode 100644 index 0000000..df15940 --- /dev/null +++ b/src/web/server/app/activated_stage_list.php @@ -0,0 +1,38 @@ +"; + + if($result) { + $rows = array(); + while($row = mysqli_fetch_assoc($result)) { + // $row_array['Language'] = $row['Language']; + $row_array['StageName'] = $row['StageName']; + $row_array['Activated'] = $row['Activated']; + array_push($return_array, $row_array); + } + } +} else { + send_error_code("Error : ".mysqli_error($db_conn)); +} + +echo json_encode($return_array, JSON_UNESCAPED_UNICODE); + +// 결과 해제 +mysqli_free_result($result); + +$db_conn->close(); + +?> \ No newline at end of file diff --git a/src/web/client/php/connect_db.php b/src/web/server/connect_db.php similarity index 100% rename from src/web/client/php/connect_db.php rename to src/web/server/connect_db.php diff --git a/src/web/client/php/send_error_code.php b/src/web/server/lib/send_error_code.php similarity index 100% rename from src/web/client/php/send_error_code.php rename to src/web/server/lib/send_error_code.php diff --git a/src/web/server/record/history_record.php b/src/web/server/record/history_record.php new file mode 100644 index 0000000..54f5985 --- /dev/null +++ b/src/web/server/record/history_record.php @@ -0,0 +1,42 @@ +prepare($query); +$stmt->bind_param('s', $user_id); +$stmt->execute(); + +$stmt->bind_result($date, $score, $app_name); + +$bestRecordArray = array(); +while($stmt->fetch()) { + $best_record['Date'] = $date; + $best_record['HighScore'] = $score; + $best_record['AppName'] = $app_name; + array_push($bestRecordArray, $best_record); + array_push($return_array, $best_record); +} +$return_array['history'] = $bestRecordArray; + +echo json_encode($return_array, JSON_UNESCAPED_UNICODE); + +$db_conn->close(); + +?> \ No newline at end of file diff --git a/src/web/server/record/stage_insert_record.php b/src/web/server/record/stage_insert_record.php new file mode 100644 index 0000000..f726573 --- /dev/null +++ b/src/web/server/record/stage_insert_record.php @@ -0,0 +1,32 @@ +prepare($query); +$stmt->bind_param('ids', $user_id, $record, $stage_name); +$stmt->execute(); + +$db_conn->close(); + +?> \ No newline at end of file diff --git a/src/web/server/record/stage_ranking.php b/src/web/server/record/stage_ranking.php new file mode 100644 index 0000000..950a8ce --- /dev/null +++ b/src/web/server/record/stage_ranking.php @@ -0,0 +1,118 @@ +prepare($query); +$stmt->bind_param('s', $user_id); +$stmt->execute(); + +$stmt->bind_result($date, $record, $stage_name); + +$bestRecordArray = array(); +while($stmt->fetch()) { + $best_record['Date'] = $date; + $best_record['BestRecord'] = $record; + $best_record['StageName'] = $stage_name; + array_push($bestRecordArray, $best_record); + array_push($return_array, $best_record); +} +$return_array['myRanking'] = $bestRecordArray; + + +// ranking hour +$query = " + SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS BestRecord + FROM afterschool_record D, afterschool_user U + WHERE D.userID = U.userID AND DATE(D.RecordDateTime) = DATE(NOW()) AND HOUR(D.RecordDateTime) = HOUR(NOW()) AND StageName = ? + GROUP BY D.userID + ORDER BY max(D.Record) DESC; +"; +$stmt = $db_conn->prepare($query); +$stmt->bind_param('s', $stageName); +$stmt->execute(); + +$stmt->bind_result($userID, $name, $record); + +$bestRecordArray = array(); +while($stmt->fetch()) { + $best_record['UserID'] = $userID; + $best_record['Name'] = $name; + $best_record['BestRecord'] = $record; + array_push($bestRecordArray, $best_record); + // array_push($return_array, $best_record); +} +$return_array['rankingHour'] = $bestRecordArray; + + +// ranking day +$query = " + SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS BestRecord + FROM afterschool_record D, afterschool_user U + WHERE D.userID = U.userID AND DATE(D.RecordDateTime) = DATE(NOW()) AND StageName = ? + GROUP BY D.userID + ORDER BY max(D.Record) DESC; +"; +$stmt = $db_conn->prepare($query); +$stmt->bind_param('s', $stageName); +$stmt->execute(); + +$stmt->bind_result($userID, $name, $record); + +$bestRecordArray = array(); +while($stmt->fetch()) { + $best_record['UserID'] = $userID; + $best_record['Name'] = $name; + $best_record['BestRecord'] = $record; + array_push($bestRecordArray, $best_record); + // array_push($return_array, $best_record); +} +$return_array['rankingDay'] = $bestRecordArray; + + +// ranking month +$query = " + SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS BestRecord + FROM afterschool_record D, afterschool_user U + WHERE D.userID = U.userID AND MONTH(D.RecordDateTime) = MONTH(NOW()) AND StageName = ? + GROUP BY D.userID + ORDER BY max(D.Record) DESC; +"; +$stmt = $db_conn->prepare($query); +$stmt->bind_param('s', $stageName); +$stmt->execute(); + +$stmt->bind_result($userID, $name, $record); + +$bestRecordArray = array(); +while($stmt->fetch()) { + $best_record['UserID'] = $userID; + $best_record['Name'] = $name; + $best_record['BestRecord'] = $record; + array_push($bestRecordArray, $best_record); + // array_push($return_array, $best_record); +} +$return_array['rankingMonth'] = $bestRecordArray; + +echo json_encode($return_array, JSON_UNESCAPED_UNICODE); + + +$db_conn->close(); + +?> \ No newline at end of file diff --git a/src/web/client/php/check_user.php b/src/web/server/user/login.php similarity index 57% rename from src/web/client/php/check_user.php rename to src/web/server/user/login.php index 75915e5..326184f 100644 --- a/src/web/client/php/check_user.php +++ b/src/web/server/user/login.php @@ -1,25 +1,27 @@ prepare($query); -$stmt->bind_param('ss', $name, $birthday); +$stmt->bind_param('ss', $name, $enterCode); $stmt->execute(); $stmt->bind_result($user_id); // while($stmt->fetch())