diff --git a/gamefix.php b/gamefix.php deleted file mode 100644 index afc6288..0000000 --- a/gamefix.php +++ /dev/null @@ -1,251 +0,0 @@ -'error','message'=>'Jumlah top up tidak valid.']); - exit; - } - - // UPDATE SALDO (BANK) - $sql = "UPDATE users SET bank = bank + ? WHERE id = ?"; - $stmt = mysqli_prepare($conn, $sql); - mysqli_stmt_bind_param($stmt, "ii", $amount, $user_id); - mysqli_stmt_execute($stmt); - mysqli_stmt_close($stmt); - - // Ambil saldo baru - $sql2 = "SELECT bank FROM users WHERE id = ?"; - $stmt2 = mysqli_prepare($conn, $sql2); - mysqli_stmt_bind_param($stmt2, "i", $user_id); - mysqli_stmt_execute($stmt2); - $result = mysqli_stmt_get_result($stmt2); - $row = mysqli_fetch_assoc($result); - mysqli_stmt_close($stmt2); - - $_SESSION['bank'] = intval($row['bank']); - - echo json_encode([ - 'status' => 'ok', - 'bank' => $_SESSION['bank'], - 'message' => 'Top up berhasil.' - ]); - exit; - } - - // ========= SET BANK (saldo game win/lose) =========== - if ($action === 'set_balance') { - $newBank = intval($_POST['balance']); - if ($newBank < 0) { - echo json_encode(['status'=>'error','message'=>'Bank tidak valid']); - exit; - } - - $sql = "UPDATE users SET bank = ? WHERE id = ?"; - $stmt = mysqli_prepare($conn, $sql); - mysqli_stmt_bind_param($stmt, "ii", $newBank, $user_id); - mysqli_stmt_execute($stmt); - mysqli_stmt_close($stmt); - - $_SESSION['bank'] = $newBank; - - echo json_encode(['status'=>'ok','bank'=>$newBank]); - exit; - } - - echo json_encode(['status'=>'error','message'=>'Action tidak dikenal']); - exit; -} - -// ============================= -// LOAD USER DATA NORMAL -// ============================= -$user_id = intval($_SESSION['user_id']); - -$sql = "SELECT username, bank FROM users WHERE id = ?"; -$stmt = mysqli_prepare($conn, $sql); -mysqli_stmt_bind_param($stmt, "i", $user_id); -mysqli_stmt_execute($stmt); -$res = mysqli_stmt_get_result($stmt); -$user = mysqli_fetch_assoc($res); -mysqli_stmt_close($stmt); - -if (!$user) { - session_destroy(); - header("Location: loginn.php"); - exit; -} - -$_SESSION['username'] = $user['username']; -$_SESSION['bank'] = intval($user['bank']); - -$username = htmlspecialchars($_SESSION['username']); -$bank = intval($_SESSION['bank']); -?> - - - - -Blackjack [21] - - - - -
-
-

Blackjack [21]

- -
-
- Signed in as: - - Logout -
- -
-
Bank: Rp
-
Taruhan: 0
-
-
-
- -
-
-
- - -
- - - - - - - - - - \ No newline at end of file diff --git a/html.php b/html.php index 30dc1cb..1c27870 100644 --- a/html.php +++ b/html.php @@ -1,81 +1,10 @@ = 0) { - // Update saldo di database - $update_query = "UPDATE users SET bank = ? WHERE id = ?"; - $update_stmt = mysqli_prepare($conn, $update_query); - mysqli_stmt_bind_param($update_stmt, "ii", $new_balance, $_SESSION['user_id']); - - if (mysqli_stmt_execute($update_stmt)) { - $_SESSION['balance'] = $new_balance; - $_SESSION['bank'] = $new_balance; - header('Content-Type: application/json'); - echo json_encode(['status' => 'success', 'balance' => $_SESSION['balance']]); - exit; - } else { - header('Content-Type: application/json'); - echo json_encode(['status' => 'error', 'message' => 'Failed to update balance']); - exit; - } - } -} ?> @@ -85,226 +14,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_balance'])) { Blackjack [21] - OCA GameHub -
@@ -313,11 +22,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_balance'])) {
Signed in as:
- + Top Up Logout
-
-
Bank: 0
+
+
Bank:
Taruhan: 0
@@ -349,196 +58,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_balance'])) {
- - -
OCA GameHub - Blackjack_[21] - Semoga menang bosq
- - \ No newline at end of file + diff --git a/loginn.php b/loginn.php index 63c613a..f0ff8c6 100644 --- a/loginn.php +++ b/loginn.php @@ -1,116 +1,67 @@ 0) { $user = mysqli_fetch_assoc($result); - - if($password === $user['password']) { - - // SESSION PAKAI BANK - $_SESSION['user_id'] = $user['id']; - $_SESSION['username'] = $user['username']; - $_SESSION['bank'] = intval($user['bank']); - - $update_sql = "UPDATE users SET last_login = NOW() WHERE id = ?"; - $update_stmt = mysqli_prepare($conn, $update_sql); - mysqli_stmt_bind_param($update_stmt, "i", $user['id']); - mysqli_stmt_execute($update_stmt); - - header("Location: html.php"); - exit; - } else { - $error = 'Invalid username or password.'; - } + session_start(); + $_SESSION['username'] = $user['username']; + // ensure balance key exists + $_SESSION['balance'] = isset($user['balance']) ? (int)$user['balance'] : 0; + header("Location: html.php"); + exit; } else { $error = 'Invalid username or password.'; } - mysqli_stmt_close($stmt); } ?> - - + + + + + Login + + + +
+ -$error = ''; -$success = ''; +
+
-if(isset($_POST['register'])){ - $username = mysqli_real_escape_string($conn, $_POST['username']); - $password = $_POST['password']; - $confirm_password = $_POST['confirm_password']; - - if(empty($username) || empty($password)) { - $error = 'All fields are required.'; - } elseif($password !== $confirm_password) { - $error = 'Passwords do not match.'; - } elseif(strlen($password) < 6) { - $error = 'Password must be at least 6 characters.'; - } else { - $check_sql = "SELECT id FROM users WHERE username = ?"; - $check_stmt = mysqli_prepare($conn, $check_sql); - mysqli_stmt_bind_param($check_stmt, "s", $username); - mysqli_stmt_execute($check_stmt); - mysqli_stmt_store_result($check_stmt); - - if(mysqli_stmt_num_rows($check_stmt) > 0) { - $error = 'Username already exists.'; - } else { - $hashed_password = $password; + +
+ - // INSERT KE KOLOM BANK, BUKAN BALANCE - $insert_sql = "INSERT INTO users (username, password, bank, created_at) - VALUES (?, ?, 1000, NOW())"; - $insert_stmt = mysqli_prepare($conn, $insert_sql); - mysqli_stmt_bind_param($insert_stmt, "ss", $username, $hashed_password); - - if(mysqli_stmt_execute($insert_stmt)) { - $success = 'Registration successful! You can now login.'; +
+
+ + +
+ +
+ + +
+ +
+ + +
- $user_id = mysqli_insert_id($conn); - $_SESSION['user_id'] = $user_id; - $_SESSION['username'] = $username; - $_SESSION['bank'] = 1000; - - header("Location: html.php"); - exit; - } else { - $error = 'Registration failed. Please try again.'; - } - } - } -} -?> - +
+
+ + diff --git a/ody git.js b/ody git.js index a525c7b..3200acc 100644 --- a/ody git.js +++ b/ody git.js @@ -1,23 +1,14 @@ - -// ========================= -// SET MESSAGE -// ========================= -function setMessage(text, status) { - if (messageEl) { - messageEl.textContent = text; - messageEl.className = status; - } +// SET MESSAGE (WIN/LOSE) +function setMessage(text, status){ + messageEl.textContent = text; + messageEl.className = status; // 'win', 'lose', atau '' (tie) } -// ========================= -// KONSTANTA KARTU -// ========================= -const SUITS = ['♠', '♥', '♦', '♣']; -const RANKS = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']; +// Simple Blackjack implementation +const SUITS = ['♠','♥','♦','♣']; +const RANKS = ['A','2','3','4','5','6','7','8','9','10','J','Q','K']; -// ========================= -// DOM ELEMENTS -// ========================= +// DOM const dealerHandEl = document.getElementById('dealer-hand'); const playerHandEl = document.getElementById('player-hand'); const dealerValueEl = document.getElementById('dealer-value'); @@ -32,149 +23,68 @@ const doubleBtn = document.getElementById('double'); const newRoundBtn = document.getElementById('new-round'); const messageEl = document.getElementById('message'); -// TOPUP DOM -const topupBtn = document.getElementById('topup-btn'); -const topupModal = document.getElementById('topup-modal'); -const topupForm = document.getElementById('topup-form'); -const topupMessage = document.getElementById('topup-message'); -const modalAmount = document.getElementById('modal-amount'); - -// ========================= -// VARIABEL GAME -// ========================= let deck = []; let dealer = []; let player = []; let dealerHidden = true; -let balance = 0; +let balance = 1000; let currentBet = 0; let inRound = false; -// ========================================= -// AMBIL VALUE DARI PHP (HIDDEN INPUT) -// ========================================= -let gameBalance = parseInt(document.getElementById('php-balance').value); -let userId = parseInt(document.getElementById('php-userid').value); - -// ========================= -// UPDATE BALANCE DISPLAY -// ========================= -function updateBalanceDisplay() { - if (balanceEl) balanceEl.textContent = gameBalance.toLocaleString('id-ID'); - const modalBalance = document.getElementById('modal-balance'); - if (modalBalance) modalBalance.textContent = gameBalance.toLocaleString('id-ID'); -} - -// ========================= -// SYNC KE SERVER -// ========================= -async function syncBalanceToServer() { - try { - const response = await fetch('update_balance.php', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ userId, balance: gameBalance }) - }); - - const data = await response.json(); - return data.success; - } catch (err) { - console.error("Error:", err); - return false; - } -} - -// ========================= -// UPDATE SESSION PHP -// ========================= -async function updateSessionBalance() { - try { - await fetch('update_session.php', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ balance: gameBalance }) - }); - } catch (err) { - console.error("Error:", err); - } -} - -// ========================= -// UPDATE BALANCE LOGIC -// ========================= -function updateGameBalance(amount, type) { - if (type === 'win') gameBalance += amount; - else if (type === 'loss') gameBalance -= amount; - else if (type === 'bet') gameBalance -= amount; - else if (type === 'refund') gameBalance += amount; - - updateBalanceDisplay(); - syncBalanceToServer(); - updateSessionBalance(); -} - -window.updateGameBalance = updateGameBalance; -window.gameBalance = gameBalance; -window.userId = userId; - -// ========================= -// FUNGSI KARTU -// ========================= -function makeDeck() { +function makeDeck(){ deck = []; - for (const s of SUITS) { - for (const r of RANKS) deck.push({ suit: s, rank: r }); + for(const s of SUITS){ + for(const r of RANKS){ + deck.push({suit:s,rank:r}); + } } } -function shuffle() { - for (let i = deck.length - 1; i > 0; i--) { - const j = Math.floor(Math.random() * (i + 1)); - [deck[i], deck[j]] = [deck[j], deck[i]]; +function shuffle(){ + for(let i=deck.length-1;i>0;i--){ + const j = Math.floor(Math.random()*(i+1)); + [deck[i],deck[j]] = [deck[j],deck[i]]; } } -function cardValue(card) { - if (card.rank === 'A') return [1, 11]; - if (['J', 'Q', 'K'].includes(card.rank)) return [10]; - return [parseInt(card.rank)]; +function cardValue(card){ + const r = card.rank; + if(r==='A') return [1,11]; + if(['J','Q','K'].includes(r)) return [10]; + return [parseInt(r,10)]; } -function handValues(hand) { +function handValues(hand){ let totals = [0]; - - for (const card of hand) { - const cv = cardValue(card); + for(const c of hand){ + const vals = cardValue(c); const newTotals = []; - - totals.forEach(t => cv.forEach(v => newTotals.push(t + v))); - - totals = [...new Set(newTotals)]; + for(const t of totals){ + for(const v of vals){ newTotals.push(t+v); } + } + totals = Array.from(new Set(newTotals)); } - - const valid = totals.filter(t => t <= 21); - return valid.length ? Math.max(...valid) : Math.min(...totals); + const valid = totals.filter(t=>t<=21); + if(valid.length) return Math.max(...valid); + return Math.min(...totals); } -function renderHand(el, hand, hideFirst = false) { - el.innerHTML = ''; - - hand.forEach((c, i) => { +function renderHand(el,hand,hideFirst=false){ + el.innerHTML=''; + hand.forEach((c,i)=>{ const div = document.createElement('div'); + div.className='card'+(c.suit==='♥'||c.suit==='♦'?' red':''); - if (hideFirst && i === 0) { - div.className = 'card back'; - div.textContent = 'HIDE'; + if(hideFirst && i===0){ + div.className='card back'; + div.textContent='TERSEMBUNYI'; } else { - div.className = 'card' + ((c.suit === '♥' || c.suit === '♦') ? ' red' : ''); - const top = document.createElement('div'); - const bot = document.createElement('div'); - + const top = document.createElement('div'); top.textContent = c.rank + ' ' + c.suit; + const bot = document.createElement('div'); + bot.style.alignSelf='flex-end'; bot.textContent = c.rank + ' ' + c.suit; - bot.style.alignSelf = 'flex-end'; - - div.appendChild(top); + div.appendChild(top); div.appendChild(bot); } @@ -182,219 +92,298 @@ function renderHand(el, hand, hideFirst = false) { }); } -// ========================= -// UPDATE UI -// ========================= -function updateUI() { - renderHand(dealerHandEl, dealer, dealerHidden); - renderHand(playerHandEl, player); - - dealerValueEl.textContent = dealerHidden ? '??' : 'Nilai: ' + handValues(dealer); - playerValueEl.textContent = 'Nilai: ' + handValues(player); - updateBalanceDisplay(); - - if (currentBetEl) currentBetEl.textContent = currentBet.toLocaleString('id-ID'); +function updateUI(){ + renderHand(dealerHandEl,dealer,dealerHidden); + renderHand(playerHandEl,player,false); + dealerValueEl.textContent = dealerHidden ? '??' : 'Nilai: '+handValues(dealer); + playerValueEl.textContent = 'Nilai: '+handValues(player); + balanceEl.textContent = balance; + currentBetEl.textContent = currentBet; } -// ========================= -// START ROUND -// ========================= -function startRound() { - if (inRound) return; +function startRound(){ + if(inRound) return; - const bet = Number(betInput.value); - if (bet <= 0) return alert("Masukkan jumlah taruhan!"); - if (bet > gameBalance) return alert("BANK TIDAK CUKUP!"); + const bet = Number(betInput.value) || 0; + if(bet <=0 || bet > balance){ alert(' BANK TIDAK CUKUP! '); return; } - currentBet = bet; - updateGameBalance(bet, 'bet'); - inRound = true; - dealerHidden = true; - setMessage("", ""); + currentBet = bet; + balance -= bet; + inRound=true; + dealerHidden=true; - makeDeck(); - shuffle(); + setMessage('', ''); // RESET MESSAGE + makeDeck(); shuffle(); dealer = [deck.pop(), deck.pop()]; player = [deck.pop(), deck.pop()]; + updateUI(); // NATURAL BLACKJACK - if (handValues(player) === 21) { - dealerHidden = false; + if(handValues(player)===21){ + dealerHidden=false; updateUI(); + const dealerVal = handValues(dealer); - if (handValues(dealer) === 21) { - updateGameBalance(currentBet, 'refund'); - setMessage("Tie!", ""); + if(dealerVal===21){ + balance += currentBet; + setMessage('Tie (seri).', ''); } else { - updateGameBalance(Math.floor(currentBet * 2.5), 'win'); - setMessage("Blackjack! You win!", "win"); + const payout = Math.floor(currentBet * 2.5); + balance += payout; + setMessage('Blackjack! You Win!', 'win'); } - inRound = false; - currentBet = 0; + inRound=false; + currentBet=0; + updateUI(); } } -// ========================= -// HIT -// ========================= -function playerHit() { - if (!inRound) return; +function playerHit(){ + if(!inRound) return; player.push(deck.pop()); updateUI(); - if (handValues(player) > 21) { - dealerHidden = false; - setMessage("Bust! You Lose!", "lose"); - inRound = false; - currentBet = 0; + if(handValues(player) > 21){ + dealerHidden=false; + setMessage('Bust! You Lose!', 'lose'); + inRound=false; + currentBet=0; + updateUI(); } } -// ========================= -// STAND -// ========================= -function playerStand() { - if (!inRound) return; +function playerStand(){ + if(!inRound) return; - dealerHidden = false; + dealerHidden=false; - while (handValues(dealer) < 17) dealer.push(deck.pop()); - - updateUI(); + while(handValues(dealer)<17){ + dealer.push(deck.pop()); + } const pv = handValues(player); const dv = handValues(dealer); - if (dv > 21 || pv > dv) { - updateGameBalance(currentBet * 2, 'win'); - setMessage("You Win!", "win"); - } else if (pv === dv) { - updateGameBalance(currentBet, 'refund'); - setMessage("Tie!", ""); + if(dv>21 || pv>dv){ + balance += currentBet*2; + setMessage('You Win!', 'win'); + + } else if(pv===dv){ + balance += currentBet; + setMessage('Tie (seri).', ''); + } else { - setMessage("You Lose!", "lose"); + setMessage('You Lose!', 'lose'); } - inRound = false; - currentBet = 0; + inRound=false; + currentBet=0; + updateUI(); } -// ========================= -// DOUBLE -// ========================= -function playerDouble() { - if (!inRound) return; - if (gameBalance < currentBet) return alert("Bank tidak cukup untuk double."); +function playerDouble(){ + if(!inRound) return; + if(balance < currentBet){ alert('Bank tidak cukup untuk double.'); return; } - updateGameBalance(currentBet, 'bet'); + balance -= currentBet; currentBet *= 2; player.push(deck.pop()); updateUI(); - if (handValues(player) > 21) { - dealerHidden = false; - setMessage("Bust! You Lose!", "lose"); - inRound = false; - currentBet = 0; + if(handValues(player)>21){ + dealerHidden=false; + setMessage('Bust! You Lose!', 'lose'); + inRound=false; + currentBet=0; + updateUI(); return; } playerStand(); } -// ========================= -// TOP UP MODAL -// ========================= -topupBtn.addEventListener('click', () => { - topupModal.style.display = 'flex'; - topupForm.reset(); - topupMessage.style.display = 'none'; - updateBalanceDisplay(); -}); - -function closeTopUpModal() { - topupModal.style.display = 'none'; - topupMessage.style.display = 'none'; -} - -window.addEventListener('click', e => { - if (e.target === topupModal) closeTopUpModal(); -}); - -function setModalAmount(amount) { - modalAmount.value = amount; -} - -function showTopUpMessage(msg, type) { - topupMessage.textContent = msg; - topupMessage.className = 'topup-message ' + type; - topupMessage.style.display = 'block'; -} - -topupForm.addEventListener('submit', e => { - e.preventDefault(); - - const bankMethod = document.querySelector('input[name="bank_method"]:checked'); - const amount = parseInt(modalAmount.value); - - if (!bankMethod) return showTopUpMessage("Pilih metode pembayaran!", "error"); - if (amount <= 0 || amount > 1000000) return showTopUpMessage("Jumlah harus 1–1.000.000", "error"); - - const formData = new FormData(topupForm); - formData.append('userId', userId); - - fetch('process_topup.php', { method: 'POST', body: formData }) - .then(res => res.json()) - .then(data => { - if (data.success) { - gameBalance = data.new_balance; - updateBalanceDisplay(); - showTopUpMessage("✓ Top up berhasil!", "success"); - setTimeout(closeTopUpModal, 2000); - } else { - showTopUpMessage(data.message, "error"); - } - }) - .catch(() => showTopUpMessage("Terjadi kesalahan.", "error")); -}); - -// ========================= -// EVENT LISTENERS -// ========================= +// EVENTS betBtn.addEventListener('click', startRound); hitBtn.addEventListener('click', playerHit); standBtn.addEventListener('click', playerStand); doubleBtn.addEventListener('click', playerDouble); -newRoundBtn.addEventListener('click', () => { - if (inRound && !confirm("Masih dalam ronde. Reset?")) return; - - dealer = []; - player = []; - deck = []; - inRound = false; - dealerHidden = true; - currentBet = 0; - - setMessage("Game di-reset.", ""); +newRoundBtn.addEventListener('click', ()=>{ + if(inRound && !confirm('Masih dalam ronde. Reset?')) return; + balance = 1000; + currentBet=0; + inRound=false; + dealer=[]; + player=[]; + deck=[]; + dealerHidden=true; + setMessage('Bank di-reset.', ''); updateUI(); }); -window.addEventListener('keydown', e => { - if (e.key === 'h') playerHit(); - if (e.key === 's') playerStand(); - if (e.key === 'd') playerDouble(); - if (e.key === 'Enter') startRound(); +// KEYBOARD +window.addEventListener('keydown', e=>{ + if(e.key==='h') playerHit(); + if(e.key==='s') playerStand(); + if(e.key==='d') playerDouble(); + if(e.key==='Enter') startRound(); }); -// ========================= -// INIT -// ========================= -document.addEventListener('DOMContentLoaded', () => { - updateBalanceDisplay(); +updateUI(); + +// TOP UP FEATURE +// Tambahkan variabel global untuk top up +let topUpAmount = 0; +let topUpHistory = []; + +// DOM elements untuk top up +const topUpBtn = document.getElementById('top-up-btn'); +const topUpModal = document.getElementById('top-up-modal'); +const topUpClose = document.getElementById('top-up-close'); +const topUpInput = document.getElementById('top-up-input'); +const topUpConfirm = document.getElementById('top-up-confirm'); +const topUpHistoryEl = document.getElementById('top-up-history'); +const topUpBalanceEl = document.getElementById('top-up-balance'); + +// Fungsi untuk menampilkan modal top up +function showTopUpModal() { + topUpModal.style.display = 'block'; + topUpInput.value = ''; + updateTopUpHistory(); +} + +// Fungsi untuk menyembunyikan modal top up +function hideTopUpModal() { + topUpModal.style.display = 'none'; +} + +// Fungsi untuk memproses top up +function processTopUp() { + const amount = Number(topUpInput.value) || 0; + + if (amount <= 0) { + alert('Masukkan jumlah top up yang valid!'); + return; + } + + if (amount > 1000000) { + alert('Maksimal top up adalah 1.000.000!'); + return; + } + + // Simulasi proses top up (dalam implementasi nyata, ini akan terhubung ke payment gateway) + balance += amount; + topUpAmount += amount; + + // Tambahkan ke riwayat top up + topUpHistory.push({ + amount: amount, + date: new Date().toLocaleString('id-ID'), + balanceAfter: balance + }); + + // Update UI + updateUI(); + updateTopUpHistory(); + + // Tampilkan pesan sukses + setMessage(`Top up berhasil! +${amount.toLocaleString('id-ID')}`, 'win'); + + // Sembunyikan modal + hideTopUpModal(); +} + +// Fungsi untuk memperbarui riwayat top up +function updateTopUpHistory() { + if (!topUpHistoryEl) return; + + topUpHistoryEl.innerHTML = ''; + + if (topUpHistory.length === 0) { + topUpHistoryEl.innerHTML = '

Belum ada riwayat top up

'; + return; + } + + // Tampilkan maksimal 5 riwayat terbaru + const recentHistory = topUpHistory.slice(-5).reverse(); + + recentHistory.forEach(record => { + const historyItem = document.createElement('div'); + historyItem.className = 'history-item'; + historyItem.innerHTML = ` +
+${record.amount.toLocaleString('id-ID')}
+
${record.date}
+
Saldo: ${record.balanceAfter.toLocaleString('id-ID')}
+ `; + topUpHistoryEl.appendChild(historyItem); + }); +} + +// Fungsi untuk memperbarui tampilan saldo top up +function updateTopUpBalance() { + if (topUpBalanceEl) { + topUpBalanceEl.textContent = `Total Top Up: ${topUpAmount.toLocaleString('id-ID')}`; + } +} + +// Event listeners untuk top up +if (topUpBtn) { + topUpBtn.addEventListener('click', showTopUpModal); +} + +if (topUpClose) { + topUpClose.addEventListener('click', hideTopUpModal); +} + +if (topUpConfirm) { + topUpConfirm.addEventListener('click', processTopUp); +} + +// Tutup modal jika klik di luar modal +window.addEventListener('click', (e) => { + if (e.target === topUpModal) { + hideTopUpModal(); + } }); + +// Keyboard shortcut untuk top up (Ctrl+T) +window.addEventListener('keydown', e => { + if (e.ctrlKey && e.key === 't') { + e.preventDefault(); + showTopUpModal(); + } +}); + +// Modifikasi fungsi updateUI untuk menampilkan informasi top up +const originalUpdateUI = updateUI; +updateUI = function() { + originalUpdateUI();` []` + updateTopUpBalance(); +}; + +// Modifikasi fungsi newRound untuk reset saldo yang tidak mempengaruhi riwayat top up +const originalNewRound = newRoundBtn.onclick; +newRoundBtn.onclick = function() { + if (inRound && !confirm('Masih dalam ronde. Reset?')) return; + + // Reset saldo tapi pertahankan riwayat top up + const currentTopUpAmount = topUpAmount; + balance = 1000 + currentTopUpAmount; + currentBet = 0; + inRound = false; + dealer = []; + player = []; + deck = []; + dealerHidden = true; + setMessage('Bank di-reset.', ''); + updateUI(); +}; + +// Inisialisasi +updateTopUpHistory(); +updateTopUpBalance(); \ No newline at end of file diff --git a/register.php b/register.php index bd32d02..6831756 100644 --- a/register.php +++ b/register.php @@ -1,175 +1,141 @@ 0) { - $user = mysqli_fetch_assoc($result); - - if ($password === $user['password']) { - - // Set SESSION - $_SESSION['user_id'] = $user['id']; - $_SESSION['username'] = $user['username']; - $_SESSION['bank'] = intval($user['bank']); // PASTIKAN integer - - // Update last login - $update_sql = "UPDATE users SET last_login = NOW() WHERE id = ?"; - $update_stmt = mysqli_prepare($conn, $update_sql); - mysqli_stmt_bind_param($update_stmt, "i", $user['id']); - mysqli_stmt_execute($update_stmt); - - // Masuk ke game page - header("Location: html.php"); - exit; - } else { - $error = "Invalid username or password"; - } - } else { - $error = "Invalid username or password"; - } - mysqli_stmt_close($stmt); -} - -/* ========================================================== - ======================= REGISTER ========================== - ========================================================== */ - -$success = ""; if (isset($_POST['register'])) { - - $username = mysqli_real_escape_string($conn, $_POST['username']); + $username = $_POST['username']; $password = $_POST['password']; - $confirm = $_POST['confirm_password']; - if (empty($username) || empty($password)) { - $error = "All fields are required."; - } elseif ($password !== $confirm) { - $error = "Passwords do not match."; - } elseif (strlen($password) < 6) { - $error = "Password must be at least 6 characters."; - } else { + // basic escaping to avoid simple injection (keep consistent with existing style) + $username = mysqli_real_escape_string($conn, $username); + $password = mysqli_real_escape_string($conn, $password); - // cek username sudah ada - $check_sql = "SELECT id FROM users WHERE username = ?"; - $check_stmt = mysqli_prepare($conn, $check_sql); - mysqli_stmt_bind_param($check_stmt, "s", $username); - mysqli_stmt_execute($check_stmt); - mysqli_stmt_store_result($check_stmt); + // insert with initial balance = 0 + $SQL = "INSERT INTO users (username, password, balance) VALUES ('$username', '$password', 0)"; + $result = mysqli_query($conn, $SQL); - if (mysqli_stmt_num_rows($check_stmt) > 0) { - $error = "Username already exists."; - - } else { - - // simpan password plain text (testing) - $hashed = $password; - - // Insert user baru — gunakan kolom bank! - $insert_sql = "INSERT INTO users (username, password, bank, created_at) - VALUES (?, ?, 1000, NOW())"; - $insert_stmt = mysqli_prepare($conn, $insert_sql); - mysqli_stmt_bind_param($insert_stmt, "ss", $username, $hashed); - - if (mysqli_stmt_execute($insert_stmt)) { - - $success = "Registration successful. You may login."; - - // Auto-login - $new_id = mysqli_insert_id($conn); - $_SESSION['user_id'] = $new_id; - $_SESSION['username'] = $username; - $_SESSION['bank'] = 1000; - - header("Location: html.php"); - exit; - } else { - $error = "Registration failed. Try again."; - } - } + if ($result) { + $success = true; } } ?> - + + - Login / Register + + + OCA Gaming Hub - Login -
+
+ - -
+ + \ No newline at end of file diff --git a/topup.php b/topup.php index e321cf8..e924af2 100644 --- a/topup.php +++ b/topup.php @@ -1,4 +1,5 @@ 0) { + $row = mysqli_fetch_assoc($res); + $_SESSION['balance'] = (int)$row['balance']; +} if ($_SERVER['REQUEST_METHOD'] === 'POST') { $bank_method = isset($_POST['bank_method']) ? $_POST['bank_method'] : ''; @@ -25,15 +29,31 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $message = 'Pilih metode pembayaran terlebih dahulu.'; $message_type = 'error'; } else { - // Add balance to session - $_SESSION['balance'] += $amount; - $message = 'Top up berhasil! Saldo Anda: Rp ' . number_format($_SESSION['balance'], 0, ',', '.'); - $message_type = 'success'; + // Simulasi proses bank + $virtual_account = 'VA-' . strtoupper(substr($bank_method, 0, 3)) . '-' . substr($username, 0, 3) . '-' . rand(10000, 99999); + + // Update balance di database + $update = mysqli_query($conn, "UPDATE users SET balance = balance + $amount WHERE username = '$username'"); + if ($update) { + // Fetch saldo terbaru + $res = mysqli_query($conn, "SELECT balance FROM users WHERE username = '$username'"); + if ($res && mysqli_num_rows($res) > 0) { + $row = mysqli_fetch_assoc($res); + $_SESSION['balance'] = (int)$row['balance']; + $message = 'Top up berhasil! Saldo Anda: Rp ' . number_format($_SESSION['balance'], 0, ',', '.'); + $message_type = 'success'; + } else { + $message = 'Top up berhasil, tetapi gagal mengambil saldo terbaru.'; + $message_type = 'error'; + } + } else { + $message = 'Gagal memproses top up. Coba lagi.'; + $message_type = 'error'; + } } } ?> - @@ -246,10 +266,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { transition: all 0.3s ease; letter-spacing: 1px; flex: 1; - text-decoration: none; - display: flex; - align-items: center; - justify-content: center; } .btn-topup { @@ -288,7 +304,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
Saldo Saat Ini: - Rp + Rp
@@ -363,7 +379,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- Kembali + Kembali
@@ -373,15 +389,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { function setAmount(amount) { document.getElementById('amount').value = amount; } - - // Update balance display on page load - const serverBalance = ; - document.getElementById('topup-balance').textContent = 'Rp ' + serverBalance.toLocaleString('id-ID', { - minimumFractionDigits: 0, - maximumFractionDigits: 0 - }); - localStorage.setItem('playerBalance', serverBalance); - diff --git a/users.sql b/users.sql index 0cad9d6..f264ffd 100644 --- a/users.sql +++ b/users.sql @@ -1,22 +1,70 @@ --- ========================================== --- FIX: TABLE USERS DENGAN KOLOM BANK --- BANK TETAP TERSIMPAN SAAT LOGOUT & LOGIN --- ========================================== +-- phpMyAdmin SQL Dump +-- version 5.2.1 +-- https://www.phpmyadmin.net/ +-- +-- Host: 127.0.0.1 +-- Generation Time: Dec 01, 2025 at 04:50 AM +-- Server version: 10.4.32-MariaDB +-- PHP Version: 8.0.30 -DROP TABLE IF EXISTS users; +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +START TRANSACTION; +SET time_zone = "+00:00"; -CREATE TABLE users ( - id INT PRIMARY KEY AUTO_INCREMENT, - username VARCHAR(50) UNIQUE NOT NULL, - password VARCHAR(255) NOT NULL, - bank INT DEFAULT 1000, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - last_login TIMESTAMP NULL DEFAULT NULL -); --- Tambahin contoh user -INSERT INTO users (username, password, bank) VALUES -('Ody', '123', 1500), -('Claudia', '123', 2000), -('Alex', '123', 1000); +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; +-- +-- Database: `login` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `users` +-- + +CREATE TABLE `users` ( + `id` int(11) NOT NULL, + `username` varchar(50) DEFAULT NULL, + `password` varchar(255) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- +-- Dumping data for table `users` +-- + +INSERT INTO `users` (`id`, `username`, `password`) VALUES +(1, '', ''), +(15, 'Alex', '123'), +(16, 'Ody', '123'), +(17, 'cliff', '123'); + +-- +-- Indexes for dumped tables +-- + +-- +-- Indexes for table `users` +-- +ALTER TABLE `users` + ADD PRIMARY KEY (`id`), + ADD UNIQUE KEY `username` (`username`); + +-- +-- AUTO_INCREMENT for dumped tables +-- + +-- +-- AUTO_INCREMENT for table `users` +-- +ALTER TABLE `users` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=23; +COMMIT; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;