Add: check player name, enterCode before add player
This commit is contained in:
@@ -18,30 +18,44 @@ if(!is_numeric($enterCode)) {
|
||||
*/
|
||||
|
||||
|
||||
$result = hasPlayerName($maestroID, $playerName, $enterCode);
|
||||
$result = has_player_name($maestroID, $playerName, $enterCode);
|
||||
if($result !== null) {
|
||||
set_error_message("이미 등록된 학생과 입장 코드 정보입니다.");
|
||||
send_result_fail();
|
||||
exit;
|
||||
}
|
||||
|
||||
addPlayer($maestroID, $playerName, $enterCode);
|
||||
$maestroAccountType = get_maestro_account_type($maestroID);
|
||||
$playerCount = get_player_count($maestroID);
|
||||
if($playerCount >= $maestroAccountType * 10) {
|
||||
set_error_message("학생을 더 이상 추가할 수 없습니다. (더 많은 학생수로 업그레이드 하세요)");
|
||||
send_result_fail();
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = hasPlayerName($maestroID, $playerName, $enterCode);
|
||||
add_player($maestroID, $playerName, $enterCode);
|
||||
|
||||
$result = has_player_name($maestroID, $playerName, $enterCode);
|
||||
if($result === null) {
|
||||
set_error_message("학생 등록에 실패했습니다.");
|
||||
send_result_fail();
|
||||
exit;
|
||||
}
|
||||
|
||||
increase_player_count($maestroID, 1);
|
||||
|
||||
send_result_success();
|
||||
exit;
|
||||
|
||||
|
||||
function hasPlayerName($maestroID, $playerName, $enterCode) {
|
||||
function has_player_name($maestroID, $playerName, $enterCode) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "SELECT PlayerID FROM moty_player WHERE MaestroID=? AND Name=? AND EnterCode=?";
|
||||
$query = "
|
||||
SELECT PlayerID
|
||||
FROM moty_player
|
||||
WHERE MaestroID = ? AND Name = ? AND EnterCode = ?
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("iss", $maestroID, $playerName, $enterCode);
|
||||
$stmt->execute();
|
||||
@@ -53,13 +67,67 @@ function hasPlayerName($maestroID, $playerName, $enterCode) {
|
||||
return $playerID;
|
||||
}
|
||||
|
||||
function addPlayer($maestroID, $playerName, $enterCode) {
|
||||
function get_maestro_account_type($maestroID) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "INSERT INTO moty_player (MaestroID, Name, EnterCode) VALUES (?, ?, ?)";
|
||||
$query = "
|
||||
SELECT AccountType
|
||||
FROM moty_maestro
|
||||
WHERE MaestroID = ?
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("i", $maestroID);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($accountType);
|
||||
// while($stmt->fetch())
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
return $accountType;
|
||||
}
|
||||
|
||||
function get_player_count($maestroID) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
SELECT PlayerCount
|
||||
FROM moty_maestro
|
||||
WHERE MaestroID = ?
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("i", $maestroID);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($playerCount);
|
||||
// while($stmt->fetch())
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
return $playerCount;
|
||||
}
|
||||
|
||||
function add_player($maestroID, $playerName, $enterCode) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
INSERT INTO moty_player (MaestroID, Name, EnterCode)
|
||||
VALUES (?, ?, ?)
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("iss", $maestroID, $playerName, $enterCode);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
function increase_player_count($maestroID, $count) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
UPDATE moty_maestro
|
||||
SET PlayerCount = PlayerCount + ?
|
||||
WHERE MaestroID = ?
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("ii", $count, $maestroID);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -24,6 +24,8 @@ if($result === true) {
|
||||
exit;
|
||||
}
|
||||
|
||||
decrease_player_count($maestroID, 1);
|
||||
|
||||
send_result_success();
|
||||
exit;
|
||||
|
||||
@@ -31,7 +33,10 @@ exit;
|
||||
function deletePlayer($maestroID, $playerID) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "DELETE FROM moty_best_record WHERE MaestroID = ? AND PlayerID = ?";
|
||||
$query = "
|
||||
DELETE FROM moty_best_record
|
||||
WHERE MaestroID = ? AND PlayerID = ?
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("ii", $maestroID, $playerID);
|
||||
$result = $stmt->execute();
|
||||
@@ -41,7 +46,10 @@ function deletePlayer($maestroID, $playerID) {
|
||||
// echo "deleted row count : ".$stmt->affected_rows;
|
||||
// }
|
||||
|
||||
$query = "DELETE FROM moty_player WHERE MaestroID = ? AND PlayerID = ?";
|
||||
$query = "
|
||||
DELETE FROM moty_player
|
||||
WHERE MaestroID = ? AND PlayerID = ?
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("ii", $maestroID, $playerID);
|
||||
$result = $stmt->execute();
|
||||
@@ -55,7 +63,11 @@ function deletePlayer($maestroID, $playerID) {
|
||||
function hasPlayerID($maestroID, $playerID) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "SELECT PlayerID FROM moty_player WHERE MaestroID=? AND PlayerID=?";
|
||||
$query = "
|
||||
SELECT PlayerID
|
||||
FROM moty_player
|
||||
WHERE MaestroID=? AND PlayerID=?
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("ii", $maestroID, $playerID);
|
||||
$stmt->execute();
|
||||
@@ -73,7 +85,11 @@ function hasPlayerID($maestroID, $playerID) {
|
||||
function hasPlayerRecord($maestroID, $playerID) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "SELECT PlayerID FROM moty_best_record WHERE MaestroID=? AND PlayerID=?";
|
||||
$query = "
|
||||
SELECT PlayerID
|
||||
FROM moty_best_record
|
||||
WHERE MaestroID=? AND PlayerID=?
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("ii", $maestroID, $playerID);
|
||||
$stmt->execute();
|
||||
@@ -88,4 +104,17 @@ function hasPlayerRecord($maestroID, $playerID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function decrease_player_count($maestroID, $count) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
UPDATE moty_maestro
|
||||
SET PlayerCount = PlayerCount - ?
|
||||
WHERE MaestroID = ?
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("ii", $count, $maestroID);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user