Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.0.3 #3

Merged
merged 7 commits into from
Mar 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ $ npm install steem
```

Import the .sql file into your database

Copy the htdocs folder in your Apache/Xampp/etc

Modify the first lines of Transaction Bot/main.js with your information
Expand Down
3 changes: 3 additions & 0 deletions htdocs/balance.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php
include_once('src/config.php');

include_once('src/head.php');

if(isset($_GET['balanceTop']))
if($_GET['balanceTop'] != 0)
{
Expand Down
143 changes: 111 additions & 32 deletions htdocs/coinflip.php
Original file line number Diff line number Diff line change
@@ -1,55 +1,134 @@
<?php
include_once('src/db.php');

$body = "";

$win = 0;

$query = $db->prepare('SELECT * FROM coinflip WHERE win = ?');
$query->bind_param('i', $win);
$query = $db->prepare('SELECT * FROM coinflip');

$query->execute();
$result = $query->get_result();
if($result->num_rows) {
$body = "";
while ($row = $result->fetch_assoc()) {
$gameid = $row['ID'];
$player1 = $row['player1'];
$player2 = $row['player2'];
$bet = $row['bet'];
$reward = $row['reward'];
$hash = $row['hash'];

if($player1 == "")
$players = "Steem - <a href=\"#\" onClick=\"MyWindow=window.open('confirmcoinflip.php?game=".$gameid."','MyWindow',width=600,height=300); return false;\">Enter game</a><br>Bitcoin - ".$player2;
else if($player2 == "")
$players = "Steem - ".$player1."<br>Bitcoin - <a href=\"#\" onClick=\"MyWindow=window.open('confirmcoinflip.php?game=".$gameid."','MyWindow',width=600,height=300); return false;\">Enter game</a>";
else
$players = $player1."<br>".$player2."<br><a href=\"#\">View game</a>";

$body .= "
<div>
<h1>Game #".$gameid."</h1>
<h3>Players<br>".$players."<br><br>
Bet: ".$bet." SBD (Reward:".$reward." SBD)<br><a href=\"#\" onClick=\"MyWindow=window.open('hash.php?hash=".$hash."','MyWindow',width=600,height=300); return false;\">
See hash
</a>
</div>
";
if(!isset($_GET['past'])) {
$past = 0;
if($result->num_rows) {
while ($row = $result->fetch_assoc()) {
$timestamp = $row['timestamp'];
$timestamper = time() - $timestamp;
if($timestamp == 0) {
$gameid = $row['ID'];
$player1 = $row['player1'];
$player2 = $row['player2'];
$bet = $row['bet'];
$reward = $row['reward'];
$hash = $row['hash'];

if($player1 == "")
$players = "Steem - <a href=\"#\" onClick=\"MyWindow=window.open('confirmcoinflip.php?game=".$gameid."','MyWindow',width=600,height=300); return false;\">Enter game</a><br>Bitcoin - ".$player2;
else
$players = "Steem - ".$player1."<br>Bitcoin - <a href=\"#\" onClick=\"MyWindow=window.open('confirmcoinflip.php?game=".$gameid."','MyWindow',width=600,height=300); return false;\">Enter game</a>";

$body .= "
<div style=\"display:inline;float:left;padding-left:10px\"><center>
<h3>Game #".$gameid."</h3>
<h4>Players<br>".$players."<br><br>
Bet: ".$bet." SBD <br><br><a href=\"#\" onClick=\"MyWindow=window.open('hash.php?hash=".$hash."','MyWindow',width=600,height=300); return false;\">
See hash
</a></center>
</div>
";
} else if($timestamper <= 60) {
$gameid = $row['ID'];
$player1 = $row['player1'];
$player2 = $row['player2'];
$bet = $row['bet'];
$reward = $row['reward'];
$hash = $row['hash'];
$secret = $row['secret'];

$win = $row['win'];

if($win == 1)
$winner = $player1;
else
$winner = $player2;

$players = $player1."<br>".$player2."<br><a href=\"#\" onClick=\"MyWindow=window.open('viewcoinflipgame.php?gameid=".$gameid."&player1=".$player1."&player2=".$player2."&bet=".$bet."&reward=".$reward."&hash=".$hash."&secret=".$secret."','MyWindow',width=600,height=300); return false;\">View game</a>";

$body .= "
<div style=\"display:inline;float:left;padding-left:10px;\"><center>
<h3>Game #".$gameid."</h3>
<h4>Players<br>".$players."<br>
Jackpot: ".$reward." SBD
<br><br><a href=\"#\" onClick=\"MyWindow=window.open('hash.php?hash=".$hash."&secret=".$secret."','MyWindow',width=600,height=300); return false;\">
See hash and secret
</a></center>
</div>
";
}
}
} else {
$body = "<br><center><h1 style=\"color:red\">No games avalabile.</h1></center>";
}
} else {
$body = "<h1 style=\"color:red\">No games avalabile.</h1>";
}
else {
$past=1;
if($result->num_rows) {
if($result->num_rows) {
while ($row = $result->fetch_assoc()) {
$gameid = $row['ID'];
$player1 = $row['player1'];
$player2 = $row['player2'];
$bet = $row['bet'];
$reward = $row['reward'];
$hash = $row['hash'];
$secret = $row['secret'];

$win = $row['win'];

if($win == 0)
continue;

if($win == 1)
$winner = $player1;
else
$winner = $player2;

$players = $player1."<br>".$player2."<br><a href=\"#\" onClick=\"MyWindow=window.open('viewcoinflipgame.php?gameid=".$gameid."&player1=".$player1."&player2=".$player2."&bet=".$bet."&reward=".$reward."&hash=".$hash."&secret=".$secret."','MyWindow',width=600,height=300); return false;\">View game</a>";

$body = "
<div style=\"display:inline;float:left;padding-left:10px;\"><center>
<h3>Game #".$gameid."</h3>
<h4>Players<br>".$players."<br>
Jackpot: ".$reward." SBD
<br>Winner: ".$winner."<br><a href=\"#\" onClick=\"MyWindow=window.open('hash.php?hash=".$hash."&secret=".$secret."','MyWindow',width=600,height=300); return false;\">
See hash and secret
</a></center>
</div>".$body;
}
}
}
else {
$body = "<br><center><h1 style=\"color:red\">No game history avalabile.</h1></center>";
}
}

$page = $_SERVER['PHP_SELF'];
$secrefresh = "30";
?>

<html>
<head>
<?php include('src/head.php'); ?>
<meta http-equiv="refresh" content="<?php echo $secrefresh?>;URL='<?php echo $page?><?php if($past == 1) echo "?past=1";?>'">
</head>
<body>
<?php include('navbar.php'); ?>
<div>
<center><h1 style="display:inline">Coinflip </h1><b><a href="games.php" style="display:inline;text-decoration:none;color:black;">(Go back)</a></b></center>
<center><a href="#" style="text-decoration:none;color:black;font-size:24px" onClick="MyWindow=window.open('coinflipaction.php?action=newgame','MyWindow',width=600,height=300); return false;">Start new game</a></center>
<center><?php echo $body; ?></center>
<center><a href="#" style="text-decoration:none;color:black;font-size:24px" onClick="MyWindow=window.open('coinflipaction.php?action=newgame','MyWindow',width=600,height=300); return false;">Start new game </a> | <a href="<?php if($past == 1) echo "coinflip.php"; else echo "?past=1";?>" style="text-decoration:none;color:black;font-size:20px"> <?php if($past == 1) echo "See avalabile games"; else echo "See games that ended"; ?></a></center>
<?php echo $body; ?>
</div>
<?php include('src/footer.php'); ?>
</body>
</html>
18 changes: 10 additions & 8 deletions htdocs/coinflipaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@

include_once('src/db.php');

include_once('src/head.php');

include_once('src/coinfliputils.php');

include_once('src/utils.php');

if(isset($_GET['balanceTop']))
if($_GET['balanceTop'] != 0 && ($_GET['player'] == 1 || $_GET['player'] == 2)) {
if($_GET['action'] == "newgame") {
Expand All @@ -15,21 +19,19 @@

$result = $query->get_result();
if($result->num_rows) {
$token = $_COOKIE['access_token'];
while ($row = $result->fetch_assoc()) {
$hash = $row['token'];
$balanced = $row['balance'];
}

if(password_verify($token, $hash)) {
if(IsLoggedOnUser()) {
$secret = generateSecret();
$hashed = hash("whirlpool", $secret);
if($balanced >= $_GET['balanceTop']) {
if($_GET['player'] == 1)
if($_GET['player'] == 1)
$playered = 1;
else
else
$playered = 2;

$reward = $_GET['balanceTop'] * 2;

$newbalance = $balanced - $_GET['balanceTop'];
Expand All @@ -49,10 +51,10 @@
echo '<p style="color:red">You don\'t have enough balance. Balance: '.$balanced.' SBD</p>';
}
} else {
echo '<p style="color:red">Your session is invalid! Please relog.</p>';
echo '<p style="color:red">Error 1: Your session is invalid! Please relog.</p>';
}
} else {
echo '<p style="color:red">Your session is invalid! Please relog.</p>';
echo '<p style="color:red">Error 2: Your session is invalid! Please relog.</p>';
}
}
}
Expand Down
73 changes: 45 additions & 28 deletions htdocs/confirmcoinflip.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@

include_once('src/db.php');

include_once('src/head.php');

include_once('src/coinfliputils.php');

include_once('src/utils.php');

if(isset($_GET['game'])) {
if(!$_GET['game'] == NULL) {
if($_GET['game'] == 0)
Expand All @@ -16,12 +20,12 @@

$result = $query->get_result();
if($result->num_rows) {
$token = $_COOKIE['access_token'];
while ($row = $result->fetch_assoc()) {
$balanced = $row['balance'];
$hash = $row['token'];
$thiswon = $row['won'];
$thislost = $row['losted'];
}
if(password_verify($token, $hash)) {
if(IsLoggedOnUser()) {
$query = $db->prepare('SELECT * FROM coinflip WHERE ID = ?');
$query->bind_param('i', $_GET['game']);

Expand All @@ -42,57 +46,70 @@
die("You don't have enough money!");
if($player2 == "") {
$playered = 2;
if($player1 == $_COOKIE['username'])
die("You can't play in your own games!");
$otherplayer = $player1;
}
else {
$playered = 1;
if($player2 == $_COOKIE['username'])
die("You can't play in your own games!");
$otherplayer = $player2;
}

if($secret[0] == "A")
$win = 1;
else
else if($secret[0] == "B")
$win = 2;

$query = $db->prepare('UPDATE coinflip SET player'.$playered.' = ?, win = ? WHERE ID = ?');
$query->bind_param('sii', $_COOKIE['username'], $win, $_GET['game']);
$timestamp = time();

$query = $db->prepare('UPDATE coinflip SET player'.$playered.' = ?, win = ?, timestamp = ? WHERE ID = ?');
$query->bind_param('siii', $_COOKIE['username'], $win, $timestamp, $_GET['game']);

$query->execute();
if($playered = $win)

$query = $db->prepare('SELECT * FROM users WHERE username = ?');
$query->bind_param('s', $otherplayer);

$query->execute();
$result = $query->get_result();
while ($row = $result->fetch_assoc()) {
$otherbalance = $row['balance'];
$otherwon = $row['won'];
$otherlost = $row['losted'];
}

if($playered == $win)
{
$newbalance = $balanced + $bet;
$won = 4;
} else {
$newbalance = $balance - $bet;

$query = $db->prepare('SELECT * FROM users WHERE username = ?');
$query->bind_param('s', $otherplayer);

$query->execute();
$result = $query->get_result();
while ($row = $result->fetch_assoc()) {
$otherbalance = $row['balance'];
}

$otherbalance = $otherbalance + $bet;
$thiswon = $thiswon + $bet;
$otherlost = $otherlost + $bet;

$query = $db->prepare('UPDATE users SET balance = ? WHERE username = ?');
$query->bind_param('ds', $otherbalance, $otherplayer);

$query->execute();
} else{
$newbalance = $balanced - $bet;
$thislost = $thislost + $bet;
$otherwon = $otherwon + $bet;
$otherbalance = $otherbalance + $reward;
}

$query = $db->prepare('UPDATE users SET balance = ? WHERE username = ?');
$query->bind_param('ds', $newbalance, $_COOKIE['username']);
$query = $db->prepare('UPDATE users SET balance = ?, won = ?, losted = ? WHERE username = ?');
$query->bind_param('ddds', $otherbalance, $otherwon, $otherlost, $otherplayer);

$query->execute();

$query = $db->prepare('UPDATE users SET balance = ?, won = ?, losted = ? WHERE username = ?');
$query->bind_param('ddds', $newbalance, $thiswon, $thislost, $_COOKIE['username']);

$query->execute();

echo "<script>
window.onunload = refreshParent;
function refreshParent() {
window.opener.location.reload();
}
window.close();
</script>";
</script>";
} else
die("Your session is invalid. Please relog.");
} else
Expand Down
14 changes: 14 additions & 0 deletions htdocs/credits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html>
<head>
<?php include('src/head.php'); ?>
</head>
<body>
<?php include('navbar.php'); ?>
<div>
<center><h1>Credits</h1>
<h3><a href="steemit.com/@andreistalker">andreistalker</a> - Developer</h3>
</center>
</div>
<?php include('src/footer.php'); ?>
</body>
</html>
1 change: 1 addition & 0 deletions htdocs/games.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
<center><h1>SteemCasino's Games</h1></center>
<center><a href="coinflip.php" style="display:inline;text-decoration:none;color:black;">Coinflip</a></center>
</div>
<?php include('src/footer.php'); ?>
</body>
</html>
5 changes: 4 additions & 1 deletion htdocs/hash.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<?php
echo "<p style=\"word-wrap: break-word\">".$_GET['hash']."</p>";
echo "Hash :<p style=\"word-wrap: break-word\">".$_GET['hash']."</p>";

if(isset($_GET['secret']))
echo "Secret: <p style=\"word-wrap:break-word\">".$_GET['secret']."</p>";
?>
Binary file added htdocs/img/animation1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added htdocs/img/animation2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added htdocs/img/animation3.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added htdocs/img/animation4.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading