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();
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user