Add: sql - login, history_record

This commit is contained in:
2018-05-17 18:51:09 +09:00
parent 976e5563b7
commit 235327cd3e
19 changed files with 529 additions and 91 deletions
+7 -7
View File
@@ -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);
+106 -9
View File
@@ -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));
+14 -49
View File
@@ -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) {
+2 -2
View File
@@ -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;