Compare commits
No commits in common. "main" and "Backup" have entirely different histories.
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -1,4 +0,0 @@
|
||||
{
|
||||
"python-envs.defaultEnvManager": "ms-python.python:system",
|
||||
"python-envs.pythonProjects": []
|
||||
}
|
||||
251
gamefix.php
251
gamefix.php
@ -1,251 +0,0 @@
|
||||
<?php
|
||||
session_start();
|
||||
include "koneksi.php";
|
||||
|
||||
// =============================
|
||||
// REQUIRE LOGIN
|
||||
// =============================
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header("Location: loginn.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
// =============================
|
||||
// AJAX HANDLER
|
||||
// =============================
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
$user_id = intval($_SESSION['user_id']);
|
||||
$action = $_POST['action'];
|
||||
|
||||
// ========= TOP UP ==========
|
||||
if ($action === 'topup') {
|
||||
$amount = intval($_POST['amount']);
|
||||
$bank_method = trim($_POST['bank_method']);
|
||||
|
||||
if ($amount <= 0) {
|
||||
echo json_encode(['status'=>'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']);
|
||||
?>
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Blackjack [21]</title>
|
||||
<link rel="stylesheet" href="cliff.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="table">
|
||||
<header>
|
||||
<h1>Blackjack [21]</h1>
|
||||
|
||||
<div class="controls">
|
||||
<div>
|
||||
Signed in as: <strong><?php echo $username; ?></strong>
|
||||
<button id="topup-btn">Top Up</button>
|
||||
<a href="logout.php" class="btn-danger">Logout</a>
|
||||
</div>
|
||||
|
||||
<div style="margin-top:10px;">
|
||||
<div class="chip">Bank: Rp <span id="bank-display"><?php echo number_format($bank,0,',','.'); ?></span></div>
|
||||
<div class="chip">Taruhan: <span id="current-bet">0</span></div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<div id="game-area"></div>
|
||||
</main>
|
||||
|
||||
<footer>OCA GameHub - Blackjack [21]</footer>
|
||||
</div>
|
||||
|
||||
<!-- ========== MODAL TOP UP ========== -->
|
||||
<div id="topup-modal" class="modal" style="display:none;">
|
||||
<div class="modal-content">
|
||||
<span class="close" id="close-topup">×</span>
|
||||
|
||||
<h2>Top Up Saldo</h2>
|
||||
|
||||
<div id="topup-msg" style="display:none;"></div>
|
||||
|
||||
<p><strong>Pemain:</strong> <?php echo $username; ?></p>
|
||||
<p><strong>Saldo sekarang:</strong> Rp <span id="modal-bank"><?php echo number_format($bank,0,',','.'); ?></span></p>
|
||||
|
||||
<form id="topup-form">
|
||||
<label>Metode:</label>
|
||||
<select id="bank-method">
|
||||
<option value="">-- pilih --</option>
|
||||
<option value="bca">BCA</option>
|
||||
<option value="bni">BNI</option>
|
||||
<option value="mandiri">Mandiri</option>
|
||||
<option value="cimb">CIMB</option>
|
||||
<option value="ewallet">E-Wallet</option>
|
||||
</select>
|
||||
|
||||
<label>Jumlah (Rp):</label>
|
||||
<input type="number" id="topup-amount" min="1">
|
||||
|
||||
<button type="submit">Top Up</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let bank = <?php echo $bank; ?>;
|
||||
|
||||
// Format rupiah
|
||||
function formatIDR(n) {
|
||||
return Number(n).toLocaleString('id-ID');
|
||||
}
|
||||
|
||||
// Update UI
|
||||
function refreshBankUI() {
|
||||
document.getElementById("bank-display").innerText = formatIDR(bank);
|
||||
document.getElementById("modal-bank").innerText = formatIDR(bank);
|
||||
}
|
||||
|
||||
// Modal
|
||||
const modal = document.getElementById("topup-modal");
|
||||
document.getElementById("topup-btn").onclick = () => modal.style.display = "flex";
|
||||
document.getElementById("close-topup").onclick = () => modal.style.display = "none";
|
||||
|
||||
// ====== Top Up Submit ======
|
||||
document.getElementById("topup-form").onsubmit = function(e){
|
||||
e.preventDefault();
|
||||
|
||||
let amount = parseInt(document.getElementById("topup-amount").value);
|
||||
let method = document.getElementById("bank-method").value;
|
||||
|
||||
if (!method) { alert("Pilih metode dulu"); return; }
|
||||
if (amount <= 0) { alert("Jumlah tidak valid"); return; }
|
||||
|
||||
let data = new URLSearchParams();
|
||||
data.append("action","topup");
|
||||
data.append("amount",amount);
|
||||
data.append("bank_method",method);
|
||||
|
||||
fetch("game.php", {
|
||||
method: "POST",
|
||||
headers: {"Content-Type":"application/x-www-form-urlencoded"},
|
||||
body: data.toString()
|
||||
})
|
||||
.then(r=>r.json())
|
||||
.then(res=>{
|
||||
if(res.status === "ok"){
|
||||
bank = res.bank;
|
||||
refreshBankUI();
|
||||
alert("Top up berhasil!");
|
||||
modal.style.display = "none";
|
||||
} else {
|
||||
alert(res.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// ====== Called from JS game (win/lose) ======
|
||||
window.persistBalanceToServer = function(newBank){
|
||||
let data = new URLSearchParams();
|
||||
data.append("action","set_balance");
|
||||
data.append("balance",newBank);
|
||||
|
||||
return fetch("game.php", {
|
||||
method:"POST",
|
||||
headers:{"Content-Type":"application/x-www-form-urlencoded"},
|
||||
body:data.toString()
|
||||
})
|
||||
.then(r=>r.json())
|
||||
.then(res=>{
|
||||
if(res.status === "ok"){
|
||||
bank = res.bank;
|
||||
refreshBankUI();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// untuk script game
|
||||
window.getBank = () => bank;
|
||||
window.setBank = (v) => { bank = v; refreshBankUI(); };
|
||||
</script>
|
||||
|
||||
<script src="ody git.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
92
html.php
92
html.php
@ -1,58 +1,68 @@
|
||||
<?php
|
||||
session_start();
|
||||
include "koneksi.php";
|
||||
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header("Location: loginn.php");
|
||||
// If not logged in, redirect to login
|
||||
if (!isset($_SESSION['username'])) {
|
||||
header('Location: loginn.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Selalu ambil saldo dari DATABASE
|
||||
$query = "SELECT bank FROM users WHERE id = ?";
|
||||
$stmt = mysqli_prepare($conn, $query);
|
||||
mysqli_stmt_bind_param($stmt, "i", $_SESSION['user_id']);
|
||||
mysqli_stmt_execute($stmt);
|
||||
$result = mysqli_stmt_get_result($stmt);
|
||||
$data = mysqli_fetch_assoc($result);
|
||||
|
||||
$currentBank = intval($data["bank"]);
|
||||
$_SESSION["bank"] = $currentBank;
|
||||
?>
|
||||
|
||||
<!doctype html>
|
||||
<html lang="id">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="login.css">
|
||||
<title>Top Up</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Blackjack [21] - OCA GameHub</title>
|
||||
|
||||
<link rel="stylesheet" href="cliff.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="table" role="application" aria-label="Blackjack tanpa iklan">
|
||||
<header>
|
||||
<h1> Blackjack [21] </h1>
|
||||
<div class="controls">
|
||||
<div style="display:flex;gap:12px;align-items:center;margin-bottom:8px;">
|
||||
<div>Signed in as: <strong><?php echo htmlspecialchars($_SESSION['username']); ?></strong></div>
|
||||
<a href="topup.php" style="text-decoration:none;padding:6px 10px;background:#3b82f6;color:#fff;border-radius:6px;">Top Up</a>
|
||||
<a href="logout.php" style="text-decoration:none;padding:6px 10px;background:#ef4444;color:#fff;border-radius:6px;">Logout</a>
|
||||
</div>
|
||||
<div class="info">
|
||||
<div class="chip">Bank: <span id="balance"><?php echo isset($_SESSION['balance']) ? (int)$_SESSION['balance'] : 0; ?></span></div>
|
||||
<div class="chip">Taruhan: <span id="current-bet">0</span></div>
|
||||
</div>
|
||||
<div class="bet">
|
||||
<input id="bet-input" type="number" min="1" value="50" />
|
||||
<button id="bet-btn">Pasang Taruhan</button>
|
||||
<button id="new-round" class="secondary"> Reset </button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<h2>Top Up Saldo</h2>
|
||||
<main>
|
||||
<div class="board" id="dealer-area">
|
||||
<div class="section-title">Dealer</div>
|
||||
<div class="hand" id="dealer-hand"></div>
|
||||
<div class="values" id="dealer-value"></div>
|
||||
</div>
|
||||
|
||||
<p>User: <b><?= $_SESSION['username'] ?></b></p>
|
||||
<p>Saldo Bank Sekarang: <b>Rp <?= number_format($currentBank, 0, ',', '.') ?></b></p>
|
||||
<div class="board" id="player-area">
|
||||
<div class="section-title">Pemain</div>
|
||||
<div class="hand" id="player-hand"></div>
|
||||
<div class="values" id="player-value"></div>
|
||||
|
||||
<?php if ($message): ?>
|
||||
<div style="color:<?= $message_type == 'success' ? 'lime' : 'red' ?>;">
|
||||
<?= $message ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="actions" id="action-buttons">
|
||||
<button id="hit">Hit</button>
|
||||
<button id="stand">Stand</button>
|
||||
<button id="double">Double</button>
|
||||
</div>
|
||||
<div class="message" id="message"></div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<form method="POST">
|
||||
<label>Pilih Bank :</label><br>
|
||||
<input type="radio" name="bank_method" value="bca">BCA<br>
|
||||
<input type="radio" name="bank_method" value="bni">BNI<br>
|
||||
<input type="radio" name="bank_method" value="mandiri">Mandiri<br><br>
|
||||
|
||||
<label>Jumlah Top Up:</label>
|
||||
<input type="number" name="amount" required><br><br>
|
||||
|
||||
<button type="submit">Top Up</button>
|
||||
</form>
|
||||
|
||||
<br>
|
||||
<a href="html.php">Kembali</a>
|
||||
<footer>
|
||||
OCA GameHub - <code> Blackjack_[21] - </code> Semoga menang bosq
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<script src="ody git.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
145
loginn.php
145
loginn.php
@ -1,116 +1,67 @@
|
||||
<?php
|
||||
include "koneksi.php";
|
||||
session_start();
|
||||
|
||||
$error = '';
|
||||
if(isset($_POST['login'])){
|
||||
$username = mysqli_real_escape_string($conn, $_POST['username']);
|
||||
$username = $_POST['username'];
|
||||
$password = $_POST['password'];
|
||||
|
||||
// PAKAI KOLOM BANK, BUKAN BALANCE
|
||||
$sql = "SELECT id, username, password, bank FROM users WHERE username = ?";
|
||||
$stmt = mysqli_prepare($conn, $sql);
|
||||
mysqli_stmt_bind_param($stmt, "s", $username);
|
||||
mysqli_stmt_execute($stmt);
|
||||
$result = mysqli_stmt_get_result($stmt);
|
||||
$sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
|
||||
$result = mysqli_query($conn, $sql);
|
||||
|
||||
if (mysqli_num_rows($result) > 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);
|
||||
}
|
||||
?>
|
||||
<!-- ... form login tetap sama ... -->
|
||||
|
||||
<?php
|
||||
include "koneksi.php";
|
||||
session_start();
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login</title>
|
||||
<link rel="stylesheet" href="login.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="logo">
|
||||
<h1>OCAGamingHub</h1>
|
||||
<p>Welcome back — sign in to continue</p>
|
||||
</div>
|
||||
|
||||
$error = '';
|
||||
$success = '';
|
||||
<div class="form-container">
|
||||
<div class="card-icon">♠</div>
|
||||
|
||||
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;
|
||||
<?php if(!empty($error)): ?>
|
||||
<div class="error-message show"><?=htmlspecialchars($error)?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
// 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.';
|
||||
<form action="loginn.php" method="POST">
|
||||
<div class="form-group">
|
||||
<label for="username">Username</label>
|
||||
<input id="username" name="username" type="text" placeholder="Enter username" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password">Password</label>
|
||||
<input id="password" name="password" type="password" placeholder="Enter password" required>
|
||||
</div>
|
||||
|
||||
<div class="button-group">
|
||||
<button type="submit" name="login" class="btn btn-signin">Sign In</button>
|
||||
<a href="register.php" class="btn btn-signup">Sign Up</a>
|
||||
</div>
|
||||
|
||||
$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.';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?
|
||||
$sql = "SELECT id, username, password, bank FROM users WHERE username = ?";
|
||||
$stmt = mysqli_prepare($conn, $sql);
|
||||
mysqli_stmt_bind_param($stmt, "s", $username);
|
||||
mysqli_stmt_execute($stmt);
|
||||
$result = mysqli_stmt_get_result($stmt);
|
||||
|
||||
if ($row = mysqli_fetch_assoc($result)) {
|
||||
|
||||
if ($password === $row['password']) {
|
||||
|
||||
$_SESSION['user_id'] = $row['id'];
|
||||
$_SESSION['username'] = $row['username'];
|
||||
$_SESSION['bank'] = intval($row['bank']); // ← INI YANG PENTING
|
||||
|
||||
header("Location: html.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
419
ody git.js
419
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,146 @@ 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();
|
||||
|
||||
255
register.php
255
register.php
@ -1,178 +1,141 @@
|
||||
<?php
|
||||
include "koneksi.php";
|
||||
session_start();
|
||||
include 'koneksi.php';
|
||||
|
||||
/* ==========================================================
|
||||
======================= LOGIN ============================
|
||||
========================================================== */
|
||||
$success = false;
|
||||
|
||||
$error = "";
|
||||
if (isset($_POST['login'])) {
|
||||
$username = mysqli_real_escape_string($conn, $_POST['username']);
|
||||
$password = $_POST['password'];
|
||||
|
||||
// PENTING: ambil kolom bank, bukan balance
|
||||
$sql = "SELECT id, username, password, bank FROM users WHERE username = ?";
|
||||
$stmt = mysqli_prepare($conn, $sql);
|
||||
mysqli_stmt_bind_param($stmt, "s", $username);
|
||||
mysqli_stmt_execute($stmt);
|
||||
$result = mysqli_stmt_get_result($stmt);
|
||||
|
||||
if (mysqli_num_rows($result) > 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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>Login / Register</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>OCA Gaming Hub - Login</title>
|
||||
<link rel="stylesheet" href="login.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="container">
|
||||
<div class="logo">
|
||||
<h1>♠ OCA GAMING HUB ♠</h1>
|
||||
<p>BLACKJACK 21 CARD GAME</p>
|
||||
</div>
|
||||
|
||||
<div class="logo">
|
||||
<h1>OCAGamingHub</h1>
|
||||
<p>Sign in or create account</p>
|
||||
<div class="form-container">
|
||||
<div class="card-icon">🂡</div>
|
||||
|
||||
<?php if ($success): ?>
|
||||
<div class="success-message show">Register Success!</div>
|
||||
<script>
|
||||
setTimeout(function() {
|
||||
window.location.href = 'loginn.php';
|
||||
}, 2000);
|
||||
</script>
|
||||
<?php else: ?>
|
||||
<!-- Sign Up Page -->
|
||||
<form action ="register.php" method="POST">
|
||||
<div class="form-group">
|
||||
<label for="username">Username</label>
|
||||
<input id="username" type="text" name="username" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password">Password</label>
|
||||
<input id="password" type="password" name="password" required>
|
||||
</div>
|
||||
|
||||
<div class="button-group">
|
||||
<button type="submit" name="register" class="btn btn-register">Register</button>
|
||||
</div>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-container">
|
||||
<script>
|
||||
function goToMain() {
|
||||
document.getElementById('mainPage').style.display = 'block';
|
||||
document.getElementById('signupForm').style.display = 'none';
|
||||
// Clear messages
|
||||
document.getElementById('mainMessage').classList.remove('show');
|
||||
document.getElementById('mainError').classList.remove('show');
|
||||
}
|
||||
|
||||
<?php if (!empty($error)): ?>
|
||||
<div class="error-message show"><?= htmlspecialchars($error) ?></div>
|
||||
<?php endif; ?>
|
||||
function goToSignUp() {
|
||||
document.getElementById('mainPage').style.display = 'none';
|
||||
document.getElementById('signupForm').style.display = 'block';
|
||||
}
|
||||
|
||||
<?php if (!empty($success)): ?>
|
||||
<div class="success-message show"><?= htmlspecialchars($success) ?></div>
|
||||
<?php endif; ?>
|
||||
// Login handler: validate input and show messages
|
||||
function handleLogin() {
|
||||
const username = document.getElementById('mainUsername').value.trim();
|
||||
const password = document.getElementById('mainPassword').value.trim();
|
||||
const successEl = document.getElementById('mainMessage');
|
||||
const errorEl = document.getElementById('mainError');
|
||||
|
||||
<!-- ================== LOGIN FORM ================== -->
|
||||
<form method="POST">
|
||||
<h2>Login</h2>
|
||||
<div class="form-group">
|
||||
<label>Username</label>
|
||||
<input type="text" name="username">
|
||||
</div>
|
||||
// Reset messages
|
||||
successEl.classList.remove('show');
|
||||
errorEl.classList.remove('show');
|
||||
|
||||
<div class="form-group">
|
||||
<label>Password</label>
|
||||
<input type="password" name="password">
|
||||
</div>
|
||||
if (!username || !password) {
|
||||
errorEl.textContent = 'Please enter both username and password.';
|
||||
errorEl.classList.add('show');
|
||||
return;
|
||||
}
|
||||
|
||||
<button type="submit" name="login" class="btn btn-signin">Login</button>
|
||||
</form>
|
||||
// Simulate login (replace with real auth as needed)
|
||||
if (username.toLowerCase() === 'admin' && password === 'admin') {
|
||||
successEl.textContent = `Welcome back, ${username}! Redirecting...`;
|
||||
successEl.classList.add('show');
|
||||
setTimeout(() => {
|
||||
alert('Logged in as ' + username + '. (Simulated)');
|
||||
// Example: redirect to game/dashboard page
|
||||
// window.location.href = 'dashboard.html';
|
||||
}, 800);
|
||||
} else {
|
||||
errorEl.textContent = 'Invalid username or password.';
|
||||
errorEl.classList.add('show');
|
||||
}
|
||||
}
|
||||
|
||||
<hr>
|
||||
// Signup Form Handler
|
||||
document.getElementById('signupForm').addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
const username = document.getElementById('signupUsername').value;
|
||||
const email = document.getElementById('signupEmail').value;
|
||||
const password = document.getElementById('signupPassword').value;
|
||||
|
||||
<!-- ================== REGISTER FORM ================== -->
|
||||
<form method="POST">
|
||||
<h2>Register</h2>
|
||||
if (username && email && password) {
|
||||
const message = document.getElementById('signupMessage');
|
||||
message.textContent = `✓ Account created successfully for ${username}!`;
|
||||
message.classList.add('show');
|
||||
|
||||
<div class="form-group">
|
||||
<label>Username</label>
|
||||
<input type="text" name="username">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Password</label>
|
||||
<input type="password" name="password">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Confirm Password</label>
|
||||
<input type="password" name="confirm_password">
|
||||
</div>
|
||||
|
||||
<button type="submit" name="register" class="btn btn-signup">Create Account</button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
setTimeout(() => {
|
||||
alert(`Account created!\nUsername: ${username}\nEmail: ${email}`);
|
||||
// Add your redirect here
|
||||
goToMain();
|
||||
}, 1500);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
35
savebank.php
35
savebank.php
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
// save_bank.php
|
||||
session_start();
|
||||
include "koneksi.php";
|
||||
|
||||
// Pastikan user sudah login
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
die("Not logged in");
|
||||
}
|
||||
|
||||
$user_id = $_SESSION['user_id'];
|
||||
$amount = intval($_POST['amount']); // jumlah top up / perubahan saldo
|
||||
|
||||
// Ambil saldo awal dari database
|
||||
$sql = "SELECT bank FROM users WHERE id = ?";
|
||||
$stmt = mysqli_prepare($conn, $sql);
|
||||
mysqli_stmt_bind_param($stmt, "i", $user_id);
|
||||
mysqli_stmt_execute($stmt);
|
||||
$result = mysqli_stmt_get_result($stmt);
|
||||
$user = mysqli_fetch_assoc($result);
|
||||
|
||||
$current_bank = intval($user['bank']);
|
||||
$new_bank = $current_bank + $amount;
|
||||
|
||||
// Update saldo ke database
|
||||
$update_sql = "UPDATE users SET bank = ? WHERE id = ?";
|
||||
$update_stmt = mysqli_prepare($conn, $update_sql);
|
||||
mysqli_stmt_bind_param($update_stmt, "ii", $new_bank, $user_id);
|
||||
mysqli_stmt_execute($update_stmt);
|
||||
|
||||
// Update session biar realtime
|
||||
$_SESSION['bank'] = $new_bank;
|
||||
|
||||
// Kirim respon
|
||||
echo "SUCCESS:".$new_bank;
|
||||
389
topup.php
389
topup.php
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
include 'koneksi.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['username'])) {
|
||||
@ -6,382 +7,60 @@ if (!isset($_SESSION['username'])) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Initialize balance if not set
|
||||
if (!isset($_SESSION['balance'])) {
|
||||
$_SESSION['balance'] = 1000;
|
||||
}
|
||||
|
||||
$message = '';
|
||||
$message_type = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$bank_method = isset($_POST['bank_method']) ? $_POST['bank_method'] : '';
|
||||
$amount = isset($_POST['amount']) ? (int)$_POST['amount'] : 0;
|
||||
|
||||
if ($amount <= 0) {
|
||||
$message = 'Masukkan jumlah top up yang valid (lebih dari 0).';
|
||||
$message_type = 'error';
|
||||
} elseif (empty($bank_method)) {
|
||||
$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';
|
||||
$username = mysqli_real_escape_string($conn, $_SESSION['username']);
|
||||
// Update balance in DB
|
||||
$update = mysqli_query($conn, "UPDATE users SET balance = balance + $amount WHERE username = '$username'");
|
||||
if ($update) {
|
||||
// Fetch new balance
|
||||
$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 sekarang: ' . $_SESSION['balance'];
|
||||
} else {
|
||||
$message = 'Top up berhasil, tetapi gagal mengambil saldo terbaru.';
|
||||
}
|
||||
} else {
|
||||
$message = 'Gagal memproses top up. Coba lagi.';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<!doctype html>
|
||||
<html lang="id">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Top Up Saldo - OCA GameHub</title>
|
||||
<title>Top Up - OCA GameHub</title>
|
||||
<link rel="stylesheet" href="login.css" />
|
||||
<style>
|
||||
.topup-container {
|
||||
position: relative;
|
||||
z-index: 10;
|
||||
width: 100%;
|
||||
max-width: 600px;
|
||||
padding: 20px;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.topup-header {
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.topup-header h1 {
|
||||
color: #00FF00;
|
||||
font-size: 28px;
|
||||
text-shadow: 0 0 20px rgba(0, 255, 0, 0.6);
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
background: rgba(0, 100, 0, 0.3);
|
||||
border: 1px solid rgba(0, 255, 0, 0.3);
|
||||
border-radius: 8px;
|
||||
padding: 15px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.info-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
color: #88FF88;
|
||||
margin: 8px 0;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.balance-display {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
color: #00FF00;
|
||||
}
|
||||
|
||||
.bank-methods {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
|
||||
gap: 12px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.bank-option {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.bank-option input[type="radio"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.bank-label {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 15px;
|
||||
background: rgba(0, 100, 0, 0.2);
|
||||
border: 2px solid rgba(0, 255, 0, 0.3);
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
color: #88FF88;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.bank-option input[type="radio"]:checked + .bank-label {
|
||||
background: rgba(0, 255, 0, 0.3);
|
||||
border-color: #00FF00;
|
||||
box-shadow: 0 0 15px rgba(0, 255, 0, 0.5);
|
||||
color: #00FF00;
|
||||
}
|
||||
|
||||
.bank-label:hover {
|
||||
background: rgba(0, 150, 0, 0.2);
|
||||
border-color: rgba(0, 255, 0, 0.6);
|
||||
}
|
||||
|
||||
.bank-icon {
|
||||
font-size: 24px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.topup-form {
|
||||
background: rgba(0, 100, 0, 0.2);
|
||||
backdrop-filter: blur(10px);
|
||||
border: 2px solid rgba(0, 255, 0, 0.4);
|
||||
border-radius: 15px;
|
||||
padding: 30px;
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 255, 0, 0.2);
|
||||
}
|
||||
|
||||
.form-section {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-section label {
|
||||
display: block;
|
||||
color: #00FF00;
|
||||
font-size: 13px;
|
||||
margin-bottom: 8px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.form-section input {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border: 1px solid rgba(0, 255, 0, 0.5);
|
||||
background: rgba(0, 100, 0, 0.1);
|
||||
color: #88FF88;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.form-section input::placeholder {
|
||||
color: rgba(136, 255, 136, 0.5);
|
||||
}
|
||||
|
||||
.form-section input:focus {
|
||||
outline: none;
|
||||
border-color: #00FF00;
|
||||
background: rgba(0, 150, 0, 0.2);
|
||||
box-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
|
||||
}
|
||||
|
||||
.quick-amounts {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 8px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.amount-btn {
|
||||
padding: 8px;
|
||||
background: rgba(0, 255, 0, 0.2);
|
||||
border: 1px solid rgba(0, 255, 0, 0.4);
|
||||
color: #00FF00;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.amount-btn:hover {
|
||||
background: rgba(0, 255, 0, 0.3);
|
||||
border-color: #00FF00;
|
||||
}
|
||||
|
||||
.message-success {
|
||||
background: rgba(0, 255, 0, 0.2);
|
||||
border: 1px solid #00FF00;
|
||||
color: #00FF00;
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 15px;
|
||||
font-size: 13px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.message-success.show {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.message-error {
|
||||
background: rgba(255, 107, 107, 0.2);
|
||||
border: 1px solid #FF6B6B;
|
||||
color: #FF9999;
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 15px;
|
||||
font-size: 13px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.message-error.show {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.button-group {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 12px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
letter-spacing: 1px;
|
||||
flex: 1;
|
||||
text-decoration: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.btn-topup {
|
||||
background: linear-gradient(135deg, #00FF00, #00CC00);
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
.btn-topup:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 20px rgba(0, 255, 0, 0.6);
|
||||
}
|
||||
|
||||
.btn-back {
|
||||
background: rgba(0, 255, 0, 0.2);
|
||||
color: #00FF00;
|
||||
border: 1px solid #00FF00;
|
||||
}
|
||||
|
||||
.btn-back:hover {
|
||||
background: rgba(0, 255, 0, 0.3);
|
||||
box-shadow: 0 4px 15px rgba(0, 255, 0, 0.4);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="topup-container">
|
||||
<div class="topup-header">
|
||||
<h1>💳 Top Up Saldo</h1>
|
||||
<p style="color: #88FF88; font-size: 12px;">Pilih metode pembayaran bank Anda</p>
|
||||
</div>
|
||||
<div class="container">
|
||||
<h2>Top Up Saldo</h2>
|
||||
<p>Pengguna: <strong><?php echo htmlspecialchars($_SESSION['username']); ?></strong></p>
|
||||
<p>Saldo saat ini: <strong><?php echo isset($_SESSION['balance']) ? (int)$_SESSION['balance'] : 0; ?></strong></p>
|
||||
|
||||
<div class="user-info">
|
||||
<div class="info-row">
|
||||
<span>Pemain:</span>
|
||||
<strong style="color: #00FF00;"><?php echo htmlspecialchars($_SESSION['username']); ?></strong>
|
||||
<?php if ($message): ?>
|
||||
<div class="success-message show"><?php echo htmlspecialchars($message); ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="POST" action="topup.php">
|
||||
<div class="form-group">
|
||||
<label for="amount">Jumlah Top Up (angka):</label>
|
||||
<input id="amount" name="amount" type="number" min="1" required />
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<span>Saldo Saat Ini:</span>
|
||||
<span class="balance-display" id="topup-balance">Rp <?php echo number_format((int)$_SESSION['balance'], 0, ',', '.'); ?></span>
|
||||
<div class="button-group">
|
||||
<button type="submit" class="btn btn-register">Top Up</button>
|
||||
<a href="html.php" class="btn btn-signin">Kembali</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="topup-form">
|
||||
<?php if ($message): ?>
|
||||
<div class="message-<?php echo $message_type; ?> show">
|
||||
<?php echo htmlspecialchars($message); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="POST" action="topup.php">
|
||||
<div class="form-section">
|
||||
<label>🏦 Pilih Bank</label>
|
||||
<div class="bank-methods">
|
||||
<div class="bank-option">
|
||||
<input type="radio" id="bank-bca" name="bank_method" value="bca" required />
|
||||
<label for="bank-bca" class="bank-label">
|
||||
<div class="bank-icon">🏛️</div>
|
||||
<div>BCA</div>
|
||||
</label>
|
||||
</div>
|
||||
<div class="bank-option">
|
||||
<input type="radio" id="bank-mandiri" name="bank_method" value="mandiri" />
|
||||
<label for="bank-mandiri" class="bank-label">
|
||||
<div class="bank-icon">🏦</div>
|
||||
<div>Mandiri</div>
|
||||
</label>
|
||||
</div>
|
||||
<div class="bank-option">
|
||||
<input type="radio" id="bank-bni" name="bank_method" value="bni" />
|
||||
<label for="bank-bni" class="bank-label">
|
||||
<div class="bank-icon">🏤</div>
|
||||
<div>BNI</div>
|
||||
</label>
|
||||
</div>
|
||||
<div class="bank-option">
|
||||
<input type="radio" id="bank-cimb" name="bank_method" value="cimb" />
|
||||
<label for="bank-cimb" class="bank-label">
|
||||
<div class="bank-icon">💰</div>
|
||||
<div>CIMB Niaga</div>
|
||||
</label>
|
||||
</div>
|
||||
<div class="bank-option">
|
||||
<input type="radio" id="bank-ocbc" name="bank_method" value="ocbc" />
|
||||
<label for="bank-ocbc" class="bank-label">
|
||||
<div class="bank-icon">🏢</div>
|
||||
<div>OCBC NISP</div>
|
||||
</label>
|
||||
</div>
|
||||
<div class="bank-option">
|
||||
<input type="radio" id="bank-doku" name="bank_method" value="doku" />
|
||||
<label for="bank-doku" class="bank-label">
|
||||
<div class="bank-icon">📱</div>
|
||||
<div>e-Wallet</div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-section">
|
||||
<label for="amount">💵 Jumlah Top Up</label>
|
||||
<input id="amount" name="amount" type="number" min="1" placeholder="Contoh: 50000" required />
|
||||
<div class="quick-amounts">
|
||||
<button type="button" class="amount-btn" onclick="setAmount(10000)">Rp 10K</button>
|
||||
<button type="button" class="amount-btn" onclick="setAmount(50000)">Rp 50K</button>
|
||||
<button type="button" class="amount-btn" onclick="setAmount(100000)">Rp 100K</button>
|
||||
<button type="button" class="amount-btn" onclick="setAmount(250000)">Rp 250K</button>
|
||||
<button type="button" class="amount-btn" onclick="setAmount(500000)">Rp 500K</button>
|
||||
<button type="button" class="amount-btn" onclick="setAmount(1000000)">Rp 1JT</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="button-group">
|
||||
<button type="submit" class="btn btn-topup">Lanjutkan Top Up</button>
|
||||
<a href="html.php" class="btn btn-back">Kembali</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function setAmount(amount) {
|
||||
document.getElementById('amount').value = amount;
|
||||
}
|
||||
|
||||
// Update balance display on page load
|
||||
const serverBalance = <?php echo (int)$_SESSION['balance']; ?>;
|
||||
document.getElementById('topup-balance').textContent = 'Rp ' + serverBalance.toLocaleString('id-ID', {
|
||||
minimumFractionDigits: 0,
|
||||
maximumFractionDigits: 0
|
||||
});
|
||||
localStorage.setItem('playerBalance', serverBalance);
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
22
users.sql
22
users.sql
@ -1,22 +0,0 @@
|
||||
-- ==========================================
|
||||
-- FIX: TABLE USERS DENGAN KOLOM BANK
|
||||
-- BANK TETAP TERSIMPAN SAAT LOGOUT & LOGIN
|
||||
-- ==========================================
|
||||
|
||||
DROP TABLE IF EXISTS users;
|
||||
|
||||
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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user