Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Game by SickWebsites
- class game {
- public static function isLoggedIn() {
- if (empty($_SESSION['login'])) {
- header('Location: login.php');
- }
- }
- public static function resurrect($name, $conn) {
- mysqli_query($conn, "UPDATE users SET health = '1', isdead = '0' WHERE username = '$name'");
- globalfunc::redirect("game.php?page=main");
- }
- public static function isDead($name, $conn) {
- if (self::get("r", $name, "isdead", $conn)) {
- return true;
- } else {
- return false;
- }
- }
- public static function validateUser($username) {
- $pattern = "/^[A-Za-z0-9]+$/";
- $result = preg_match($pattern, $username);
- if (!$result) {
- return false;
- }
- return true;
- }
- public static function validateEmail($email) {
- $result = filter_var($email, FILTER_VALIDATE_EMAIL);
- if (!$result) {
- return false;
- }
- return true;
- }
- public static function updateAvatar($name, $link, $conn) {
- $stmt = $conn->prepare("UPDATE users SET image = ? WHERE username = ?");
- $stmt->bind_param("ss", $link, $name);
- $stmt->execute();
- }
- public static function validateExternalLink($link) {
- if (!filter_var($link, FILTER_VALIDATE_URL) === false) {
- return true;
- } else {
- return false;
- }
- }
- public static function checkCurrentPass($name, $curpass, $conn) {
- $encPW = sha1($curpass);
- $stmt = $conn->prepare("SELECT * FROM users WHERE username = ? AND password = ?");
- $stmt->bind_param("ss", $name, $encPW);
- $stmt->execute();
- $stmt->store_result();
- $stmt->fetch();
- if ($stmt->num_rows() > 0) {
- return true;
- } else {
- return false;
- }
- }
- public static function updatePassword($name, $newpass, $conn) {
- $encPW = sha1($newpass);
- $stmt = $conn->prepare("UPDATE users SET password = ? WHERE username = ?");
- $stmt->bind_param("ss", $encPW, $name);
- $stmt->execute();
- $stmt->store_result();
- }
- public static function showPersonalMoney($kind, $name, $conn) {
- $stmt = $conn->prepare("SELECT " . $kind . " FROM users WHERE username = ?");
- $stmt->bind_param("s", $name);
- $stmt->execute();
- $stmt->store_result();
- $stmt->bind_result($result);
- $stmt->fetch();
- $setCorrectMoney = self::moneyformat($result);
- return $setCorrectMoney;
- }
- public static function showPersonalBullets($kind, $name, $conn) {
- $stmt = $conn->prepare("SELECT " . $kind . " FROM users WHERE username = ?");
- $stmt->bind_param("s", $name);
- $stmt->execute();
- $stmt->store_result();
- $stmt->bind_result($result);
- $stmt->fetch();
- $setBullets = self::bulletformat($result);
- return $setBullets;
- }
- public static function changeEmail($user, $email, $conn) {
- $stmt = $conn->prepare("SELECT email FROM users WHERE email = ?");
- $stmt->bind_param("s", $email);
- $stmt->execute();
- $stmt->store_result();
- $stmt->bind_result($emailResult);;
- $stmt->fetch();
- if ($stmt->num_rows() > 0) {
- echo '<div class="alert alert-danger">That E-Mail already exists within our database.<br />Please choose a different one.</div>';
- } else {
- echo '<div class="alert alert-success">You have updated your E-Mail adress to ' . $email . ' succesfully.</div>';
- mysqli_query($conn, "UPDATE users SET email = '$email' WHERE username = '$user'");
- }
- }
- public static function online($name, $page, $session, $time, $conn) {
- $stmt = $conn->prepare('SELECT session, time FROM online WHERE session = ?');
- $stmt->bind_param("s", $session);
- $stmt->execute();
- $stmt->store_result();
- $stmt->bind_result($getsession, $gettime);
- $stmt->fetch();
- if ($stmt->num_rows() == 0) {
- if ($name != "") {
- mysqli_query($conn, "INSERT INTO online (user, page, session, time) VALUES ('$name', '$page', '$session', '$time')") or die ("Error: " . mysqli_error($conn));
- }
- } else {
- mysqli_query($conn, "UPDATE online SET time = '$gettime' WHERE session = '$getsession'");
- }
- }
- public static function profileExists($user, $conn) {
- $fetchUser = "SELECT * FROM users WHERE username = '$user'";
- if ($stmt = $conn->prepare($fetchUser)) {
- $stmt->execute();
- $stmt->store_result();
- if ($stmt->num_rows > 0) {
- return true;
- } else {
- return false;
- }
- $stmt->close();
- }
- }
- public static function fetchProfileItem($user, $item, $conn) {
- $fetchUser = "SELECT " . $item . " FROM users WHERE username = '$user'";
- $stmt = $conn->prepare($fetchUser);
- $stmt->execute();
- $stmt->store_result();
- $stmt->bind_result($itemToFind);
- $stmt->fetch();
- return $itemToFind;
- }
- public static function attemptTravel($user, $dir, $conn) {
- $stmt = $conn->prepare("SELECT location, lastflight FROM users WHERE username = ?");
- $stmt->bind_param("s", $user);
- $stmt->execute();
- $stmt->store_result();
- $stmt->bind_result($location, $lastflight);
- $stmt->fetch();
- $newFlightTime = $lastflight + game::fetchVehicleDelay($user, $conn);
- $curTime = time() - 400000;
- $nextFlight = time() + game::fetchVehicleDelay($user, $conn);
- if ($location != $dir) {
- if ($newFlightTime > time()) { //Cant fly
- echo '<div class="alert alert-danger">Sorry, but you have to wait untill ' . date("H:i:s", $newFlightTime) . ' to fly again.</div>';
- } else {
- echo '<div class="alert alert-success">You have succesfully arrived in ' . $dir . '!
- <br />You can fly again at ' . date("H:i:s", $nextFlight) . '</div>';
- mysqli_query($conn, "UPDATE users SET location = '$dir', lastflight = '$curTime' WHERE username = '$user'");
- }
- } else {
- echo '<div class="alert alert-danger">You are already in ' . $dir . ', silly!</div>';
- }
- }
- public static function fetchVehicleDelay($user, $conn) {
- if (self::get("r", $user, "vehicle", $conn) == "None") {
- return 7200;
- } else if (self::get("r", $user, "vehicle", $conn) == "Small plane") {
- return 6000;
- } else if (self::get("r", $user, "vehicle", $conn) == "Fast plane") {
- return 4800;
- } else if (self::get("r", $user, "vehicle", $conn) == "Jet") {
- return 3600;
- } else {
- return 0;
- }
- }
- public static function handleExtortion($name, $conn) {
- $stmt = $conn->prepare("SELECT xp, lastextortion, money FROM users WHERE username = ?");
- $stmt->bind_param("s", $name);
- $stmt->execute();
- $stmt->store_result();
- $stmt->bind_result($xp, $lastextortion, $money);
- $stmt->fetch();
- $nextExtortion = time() + 1800;
- $jailTime = time() + 900;
- if ($lastextortion > time()) {
- echo '<div class="alert alert-danger">You have to wait untill '.date("H:i:s", $lastextortion).' to extort someone again.</div>';
- } else {
- $stmt = $conn->prepare("SELECT SQL_NO_CACHE username, xp, money FROM users ORDER BY RAND() LIMIT 1");
- $stmt->execute();
- $stmt->store_result();
- $stmt->bind_result($usernametarget, $xptarget, $cashtarget);
- $stmt->fetch();
- $randChance = rand(1,2);
- if ($randChance == 1) {
- if ($xp > $xptarget) {
- $randomChance = rand(1,3);
- if ($randomChance == 1) {
- $amountWon = $cashtarget / 100 * 10;
- $newCashExtorter = $money + $amountWon;
- $newCashTarget = $cashtarget - $amountWon;
- echo '<div class="alert alert-success">You have succesfully extorted '.$usernametarget.' for '.self::moneyformat($amountWon).'!</div>';
- mysqli_query($conn, "UPDATE users SET money = '$newCashExtorter' WHERE username = '$name'");
- mysqli_query($conn, "UPDATE users SET money = '$newCashTarget' WHERE username = '$usernametarget'");
- } else {
- echo '<div class="alert alert-danger">Sorry, but your target escaped, and called the police.
- <br />You are now in jail untill '.date("H:i:s", $jailTime).'.</div>';
- mysqli_query($conn, "UPDATE users SET injail = '$jailTime' WHERE username = '$name'");
- }
- } else {
- if ($name != $usernametarget) {
- echo '<div class="alert alert-danger"><a href="game.php?page=profile&user='.$usernametarget.'">'.$usernametarget.'</a> was just a bit stronger than you, sorry!
- <br />You still managed to get away without a scratch.</div>';
- } else {
- echo '<div class="alert alert-danger">Your target was just a bit stronger than you, sorry!
- <br />You still managed to get away without a scratch.</div>';
- }
- }
- } else {
- echo '<div class="alert alert-danger">You could not find a target to extort.</div>';
- }
- mysqli_query($conn, "UPDATE users SET lastextortion = '$nextExtortion' WHERE username = '$name'");
- }
- }
- public static function renameMoney($amount) {
- if (($amount >= 0) && ($amount <= 1000)) { //0 - 1k
- return 'Bankrupt';
- } else if (($amount > 1000) && ($amount <= 50000)) { // 1k - 50k
- return 'A sad story';
- } else if (($amount > 50000) && ($amount <= 100000)) { //50k - 100k
- return 'Really poor';
- } else if (($amount > 100000) && ($amount <= 250000)) { //100k - 250k
- return 'Not that poor';
- } else if (($amount > 250000) && ($amount <= 750000)) { //250k - 750k
- return 'Wealthy';
- } else if (($amount > 750000) && ($amount <= 1250000)) { //750k - 1250k
- return 'Rich';
- } else if (($amount > 1250000) && ($amount <= 5000000)) { //1.250k - 5m
- return 'Richer than the queen';
- } else if (($amount > 5000000) && ($amount <= 20000000)) { //5m - 20m
- return 'Set for life';
- } else if (($amount > 20000000) && ($amount <= 50000000)) { //20m - 50m
- return 'Drugsdealer much?';
- } else if (($amount > 50000000) && ($amount <= 150000000)) { //50m - 150m
- return 'Set for 5 lifetimes';
- } else if (($amount > 150000000) && ($amount <= 500000000)) { //150m - 500m
- return 'Insane much';
- } else if (($amount > 500000000) && ($amount <= 1000000000)) { //500m - 1b
- return 'Incredibly rich';
- } else if (($amount > 1000000000) && ($amount <= 1500000000)) { //1b - 1.5b
- return 'Too much';
- } else if (($amount > 1500000000) && ($amount <= maxValues)) { //1.5b - max
- return 'Bruh...';
- } else {
- return 'Unknown';
- }
- }
- public static function fetchWeapon($name, $conn) {
- $stmt = $conn->prepare("SELECT weapon FROM users WHERE username = ?");
- $stmt->bind_param("s", $name);
- $stmt->execute();
- $stmt->bind_result($weapon);
- $stmt->fetch();
- if ($weapon == "") {
- echo 'None';
- } else if ($weapon == "Knife") {
- echo 'Knife';
- } else if ($weapon == "Pistol") {
- echo 'Pistol';
- } else if ($weapon == "Auto Pistol") {
- echo 'Auto pistol';
- } else if ($weapon == "Rifle") {
- echo 'Rifle';
- } else if ($weapon == "Auto Rifle") {
- echo 'Auto rifle';
- }
- }
- public static function cansenddrink($name, $conn) {
- $stmt = $conn->prepare("SELECT lastdrinksend FROM users WHERE username = ?");
- $stmt->bind_param("s", $name);
- $stmt->execute();
- $stmt->bind_result($drinksend);
- $stmt->store_result();
- $stmt->fetch();
- return $drinksend;
- }
- public static function useBar($name, $target, $drink, $conn) {
- $stmt = $conn->prepare("SELECT money, xp, lastdrink FROM users WHERE username = ?");
- $stmt->bind_param("s", $target);
- $stmt->execute();
- $stmt->bind_result($moneyUser, $xpUser, $lastdrinkUser);
- $stmt->store_result();
- $stmt->fetch();
- $userXP = self::getLevelForXP($xpUser);
- $senderXP = self::get("r", $name, "xp", $conn);
- $senderMoney = self::get("r", $name, "money", $conn);
- $curTime = time();
- if (self::profileExists($target, $conn)) {
- if (time() > self::cansenddrink($name, $conn)) {
- if (time() > $lastdrinkUser) {
- if ($drink == "beer") {
- if ($senderXP >= 5) {
- if ($senderMoney >= 500000) {
- $calculatenewxp = $xpUser + 1000;
- $calculatenewbal = $senderMoney - 500000;
- $setdelay = $curTime + 3600;
- mysqli_query($conn, "UPDATE users SET xp = '$calculatenewxp', lastdrink = '$setdelay' WHERE username = '$target'");
- mysqli_query($conn, "UPDATE users SET money = '$calculatenewbal', lastdrinksend = '$setdelay' WHERE username = '$name'");
- echo '<div class="alert alert-success">You have succesfully send a '.$drink.' to '.$target.'.</div>'; mysqli_query($conn, "UPDATE users SET lastdrink = '$setdelay', xp = '$calculatenewxp' WHERE username = '$target'"); mysqli_query($conn, "UPDATE users SET money = '$calculatenewbal', lastdrinksend = '$setdelay' WHERE username = '$name'");
- } else {
- echo '<div class="alert alert-danger">Sorry, but you do not have enough money for this drink.</div>';
- }
- } else {
- echo '<div class="alert alert-danger">You have to be level 5 to send this drink!</div>';
- }
- } else if ($drink == "cocktail") {
- if ($senderXP >= 10) {
- if ($senderMoney >= 1000000) {
- if (strtolower($target) != "thrallix") {
- $calculateNewMoney = $moneyUser / 100 * 2;
- $extract = $moneyUser - $calculateNewMoney;
- $setdelay = $curTime + 7200;
- $add = self::get("r", $name, "money", $conn) + $calculateNewMoney - 1000000;
- echo '<div class="alert alert-success">Congratulations, '.$target.' drank your drink, and gave you '.self::moneyformat($calculateNewMoney).'.</div>';
- mysqli_query($conn, "UPDATE users SET money = '$add', lastdrinksend = '$setdelay' WHERE username = '$name'");
- mysqli_query($conn, "UPDATE users SET money = '$extract', lastdrink = '$setdelay' WHERE username = '$target'");
- } else {
- echo '<div class="alert alert-danger">This target seems to be immune!</div>';
- }
- } else {
- echo '<div class="alert alert-danger">Sorry, but you do not have enough money for this drink.</div>';
- }
- } else {
- echo '<div class="alert alert-danger">You have to be level 10 to send this drink!</div>';
- }
- } else if ($drink == "vodka") {
- } else if ($drink == "whiskey") {
- } else {
- echo '<div class="alert alert-danger">Sorry, but that is not a valid drink.</div>';
- }
- } else {
- echo '<div class="alert alert-danger">Sorry, but that user cannot receive a drink untill '.date("H:i:s", $lastdrinkUser).'</div>'; }
- } else {
- echo '<div class="alert alert-danger">Sorry, but you have to wait untill '.date("H:i:s", self::cansenddrink($name, $conn)).' to send another drink</div>';
- }
- } else {
- echo '<div class="alert alert-danger">Sorry, that is not a user.</div>';
- }
- }
- public static function moneyformat($number) {
- return '$' . number_format($number, 0);
- }
- public static function bulletformat($number) {
- return number_format($number, 0);
- }
- public static function validateCrimes($crime, $validCrimes) {
- if (in_array($crime, $validCrimes)) {
- return true;
- } else {
- return false;
- }
- }
- public static function calculateChance($crime, $name, $conn) {
- $stmt = $conn->prepare("SELECT stealchance FROM users WHERE username = ?");
- $stmt->bind_param("s", $name);
- $stmt->execute();
- $stmt->store_result();
- $stmt->bind_result($stealchance);
- $stmt->fetch();
- if ($crime == "candy") {
- $crimeChance = candyMinChance;
- } else if ($crime == "elderly") {
- $crimeChance = elderlyMinChance;
- } else if ($crime == "gas") {
- $crimeChance = gasMinChance;
- } else if ($crime == "burglary") {
- $crimeChance = burglaryMinChance;
- }
- $cChance = $stealchance - $crimeChance;
- if ($cChance < 0) {
- return 0;
- } else if ($cChance > 100) {
- return 100;
- } else {
- return $cChance;
- }
- }
- public static function transferMoney($user, $amount, $target, $conn) {
- $targetBalance = self::get("r", $target, "bank", $conn);
- $userBalance = self::get("r", $user, "bank", $conn);
- $newUserBalance = $userBalance - $amount;
- $newTargetBalance = $targetBalance + $amount;
- $date = date("d/m/Y - H:i:s");
- if ($amount <= maxValues) {
- if ($newTargetBalance <= maxValues) {
- if ($userBalance >= $amount) {
- echo '<div class="alert alert-success">You have succesfully transfered '.self::moneyformat($amount).' to '.$target.'.</div>';
- mysqli_query($conn, "INSERT INTO transfers (transferrer, receiver, amount, date) VALUES ('$user', '$target', '$amount', '$date')");
- mysqli_query($conn, "UPDATE users SET bank = '$newUserBalance' WHERE username = '$user'");
- mysqli_query($conn, "UPDATE users SET bank = '$newTargetBalance' WHERE username = '$target'");
- } else {
- echo '<div class="alert alert-danger">You do not have this much money.</div>'; //Amount too high
- }
- } else {
- echo '<div class="alert alert-danger">Sending this amount would cause the targets bank value to be too high.</div>'; //Target new amount too high
- }
- } else {
- echo '<div class="alert alert-danger">You can not send that much money.</div>'; //Too much money
- }
- }
- public static function jailuser($time, $user, $conn) {
- $jailTime = time() + $time;
- mysqli_query($conn, "UPDATE users SET injail = '$jailTime' WHERE user = '$user'");
- }
- public static function isJailed($name, $conn) {
- $stmt = $conn->prepare("SELECT injail FROM users WHERE username = ?");
- $stmt->bind_param("s", $name);
- $stmt->execute();
- $stmt->store_result();
- $stmt->bind_result($injail);
- $stmt->fetch();
- if ($injail > time()) { //If your jailtime is higher than current time
- return true;
- } else {
- return false;
- }
- }
- public static function handleSteal($crime, $user, $conn) {
- $stmt = $conn->prepare("SELECT stealchance, nextsteal FROM users WHERE username = ?");
- $stmt->bind_param("s", $user);
- $stmt->execute();
- $stmt->store_result();
- $stmt->bind_result($stealchance, $nextsteal);
- $stmt->fetch();
- if ($nextsteal > time()) {
- echo '<div class="alert alert-danger">You can not steal yet, you have to wait untill ' . date("H:i:s", $nextsteal) . '!</div>';
- } else {
- if ($crime == "candy") {
- $crimesuccess = rand(candyMinChance, 100);//You need atleast 10 stealchance to be able to do this.
- $mychance = $stealchance - candyMinChance;
- $reward = rand(5,10);
- $xpreward = rand(10, 50);
- $chanceReward = rand(1, 1);
- $failChanceReward = rand(1, 1);
- $waittime = 60;
- $jailtime = 60;
- } else if ($crime == "elderly") {
- $crimesuccess = rand(elderlyMinChance, 100); //You need atleast 10 stealchance to be able to do this.
- $mychance = $stealchance - elderlyMinChance;
- $reward = rand(30,85);
- $xpreward = rand(100, 300);
- $chanceReward = rand(1, 2);
- $failChanceReward = rand(1, 1);
- $waittime = 120;
- $jailtime = 120;
- } else if ($crime == "gas") {
- $crimesuccess = rand(gasMinChance, 100); //You need atleast 10 stealchance to be able to do this.
- $mychance = $stealchance - gasMinChance;
- $reward = rand(300,500);
- $xpreward = rand(60, 70);
- $chanceReward = rand(1, 3);
- $failChanceReward = rand(1, 1);
- $waittime = 240;
- $jailtime = 240;
- } else if ($crime == "burglary") {
- $crimesuccess = rand(burglaryMinChance, 100); //You need atleast 10 stealchance to be able to do this.
- $mychance = $stealchance - burglaryMinChance;
- $reward = rand(500, 2500);
- $xpreward = rand(100, 200);
- $chanceReward = rand(1, 3);
- $failChanceReward = rand(1, 1);
- $waittime = 480; //600
- $jailtime = 480; //600
- }
- $newAmount = self::get("r", $user, "money", $conn) + $reward;
- $newXPAmount = self::get("r", $user, "xp", $conn) + $xpreward;
- $newChanceAmount = self::get("r", $user, "stealchance", $conn) + $chanceReward;
- $newChanceAmountONFail = self::get("r", $user, "stealchance", $conn) + 1;
- $nextstealtime = time() + $waittime;
- $untillJailtime = time() + $jailtime;
- if ($mychance > 0) {
- if ($newAmount <= maxValues) {
- if ($mychance > $crimesuccess) { //If mychance is higher than crimesuccess
- echo '<div class="alert alert-success">The crime went succesfull!<br />Money earned: ' . self::moneyformat($reward) . '<br />XP earned: ' . $xpreward . '<br />Extra success chance: ' . $chanceReward . '%</div>';
- mysqli_query($conn, "UPDATE users SET nextsteal = '$nextstealtime', stealchance = '$newChanceAmount', money = '$newAmount', xp = '$newXPAmount' WHERE username = '$user'");
- } else {
- $hasToGoToJail = rand(1,2);
- if ($hasToGoToJail == 1) {
- echo '<div class="alert alert-danger">The crime went unsuccesfull!<br />Money earned: $0<br />XP earned: 0<br />Extra success chance: ' . $failChanceReward . '% </div>';
- echo '<div class="alert alert-success">You managed to escape, even though you have no loot.</div>';
- mysqli_query($conn, "UPDATE users SET nextsteal = '$nextstealtime', stealchance = '$newChanceAmountONFail' WHERE username = '$user'");
- } else {
- echo '<div class="alert alert-danger">The crime went unsuccesfull!<br />Money earned: $0<br />XP earned: 0<br />Extra success chance: ' . $failChanceReward . '% </div>';
- echo '<div class="alert alert-warning">You are now in jail untill ' . date("H:i:s", $untillJailtime) . '</div>';
- mysqli_query($conn, "UPDATE users SET injail = '$untillJailtime', nextsteal = '$nextstealtime', stealchance = '$newChanceAmountONFail' WHERE username = '$user'");
- }
- }
- } else {
- echo '<div class="alert alert-danger">You already have max money, you can now have over $2.147.483.647.</div>';
- }
- } else {
- echo '<div class="alert alert-danger">Sorry, but you have no chance on succeeding this crime.<br />You need more success chance.</div>';
- }
- }
- }
- public static function fetchTitle($page) {
- if (($page == "") || ($page == "main")) {
- echo 'Main and FaQ';
- } else if ($page == "bank") {
- echo 'Personal bank account';
- } else if ($page == "shop") {
- echo 'The store of ' . websiteName;
- } else if ($page == "stealing") {
- echo 'Attempt to steal';
- } else if ($page == "jail") {
- echo 'The jail of ' . websiteName;
- } else if ($page == "profile") {
- echo 'Welcome to the profile of ' . $_GET['user'];
- } else if ($page == "settings") {
- echo 'Edit your settings';
- } else if ($page == "whosonline") {
- echo 'Who is online?';
- } else if ($page == "travel") {
- echo 'Traveling';
- } else if ($page == "transfer") {
- echo 'Transfer money to another user.';
- } else if ($page == "extortion") {
- echo 'Attempting to extort a player';
- } else if ($page == "casino") {
- echo 'Gambling';
- } else if ($page == "casinooverview") {
- echo 'Casino overview';
- } else if ($page == "attack") {
- echo 'Attack another player';
- } else if ($page == "bullets") {
- echo 'The bulletfactory';
- } else if ($page == "hospital") {
- echo 'The hospital of ' . websiteName;
- } else {
- echo 'Error fetching title.';
- }
- }
- public static function checkPage($pagelist, $get, $location) {
- if (!in_array($get, $pagelist)) {
- header('Location: ' . $location);
- }
- }
- public static function showName($noy) {
- if ($noy == "n") {
- echo ucfirst($_SESSION['login']);
- } else {
- echo '<i class="fa fa-user"></i> ' . ucfirst($_SESSION['login']);
- }
- }
- public static function showClass($name, $conn) {
- $stmt = $conn->prepare('SELECT class FROM users WHERE username = ?');
- $stmt->bind_param('s', $name);
- $stmt->execute();
- $stmt->store_result();
- $stmt->bind_result($class);
- $stmt->fetch();
- if ($class == "pimp") {
- echo 'Pimp';
- } else if ($class == "drugsdealer") {
- echo 'Drugs dealer';
- } else if ($class == "undercovercop") {
- echo 'Undercover cop';
- } else {
- echo 'Invalid class';
- }
- }
- public static function get($eor, $nametofind, $item, $conn) {
- $stmt = $conn->prepare('SELECT ' . $item . ' FROM users WHERE username = ?');
- $stmt->bind_param('s', $nametofind);
- $stmt->execute();
- $stmt->store_result();
- if ($stmt->num_rows > 0) {
- $stmt->bind_result($requestanswer);
- $stmt->fetch();
- if ($eor == "e") {
- echo $requestanswer;
- } else if ($eor == "r") {
- return $requestanswer;
- } else if ($eor == "o") {
- printf($requestanswer);
- }
- }
- }
- public static $EXPERIENCE_TABLE = array(
- 83, 174, 276, 388, 512, 650, 801, 969, 1154, 1358, 1584, 1833, 2107,
- 2411, 2746, 3115, 3523, 3973, 4470, 5018, 5624, 6291, 7028, 7842, 8740,
- 9730, 10824, 12031, 13363, 14833, 16456, 18247, 20224, 22406, 24815,
- 27473, 30408, 33648, 37224, 41171, 45529, 50339, 55649, 61512, 67983,
- 75127, 83014, 91721, 101333, 111945, 123660, 136594, 150872, 166636,
- 184040, 203254, 224466, 247886, 273742, 302288, 333804, 368599, 407015,
- 449428, 496254, 547953, 605032, 668051, 737627, 814445, 899257, 992895,
- 1096278, 1210421, 1336443, 1475581, 1629200, 1798808, 1986068, 2192818,
- 2421087, 2673114, 2951373, 3258594, 3597792, 3972294, 4385776, 4842295,
- 5346332, 5902831, 6517253, 7195629, 7944614, 8771558, 9684577, 10692629,
- 11805606, 13034431, 15678941
- );
- public static function getLevelForXP($xp) {
- for ($i = 0; $i < count(self::$EXPERIENCE_TABLE); $i++) {
- if ($xp < self::$EXPERIENCE_TABLE[$i]) {
- return $i + 1;
- }
- }
- return 100;
- }
- public static function purchaseOut($buyer, $name, $conn) {
- $stmt = $conn->prepare("SELECT injail FROM users WHERE username = ?");
- $stmt->bind_param("s", $name);
- $stmt->execute();
- $stmt->bind_result($injail);
- $stmt->store_result();
- $stmt->fetch();
- $calculateTimeLeft = $injail - time();
- if ($calculateTimeLeft == 0) {
- echo '<div class="alert alert-warning">' . $name . ' is already out of jail!</div>';
- } else {
- $calculatePrice = $calculateTimeLeft * 100;
- if (self::get("r", $buyer, "money", $conn) >= $calculatePrice) {
- if ($calculatePrice > 0) {
- echo '<div class="alert alert-success">You have succesfully bought out ' . $name . ' for ' . self::moneyformat($calculatePrice) . '.</div>';
- mysqli_query($conn, "UPDATE users SET injail = '0' WHERE username = '$name'");
- $newamount = self::get("r", $buyer, "money", $conn) - $calculatePrice;
- $getDat = mysqli_query($conn, "UPDATE users SET money = '$newamount' WHERE username = '$buyer'");
- if ($getDat) {
- } else {
- echo 'Error: ' . mysqli_error($conn);
- }
- } else {
- echo '<div class="alert alert-danger">This person is already out of jail.</div>';
- }
- } else {
- echo '<div class="alert alert-danger">Sorry, but you do not have enough money to buy ' . $name . ' out of jail.</div>';
- }
- }
- $stmt->close();
- }
- public static function getPrice($name, $conn) {
- $stmt = $conn->prepare("SELECT injail FROM users WHERE username = ?");
- $stmt->bind_param("s", $name);
- $stmt->execute();
- $stmt->bind_result($injail);
- $stmt->store_result();
- $stmt->fetch();
- $calculateTimeLeft = $injail - time();
- $price = $calculateTimeLeft * 100;
- echo 'Name to buy out: ' . $name;
- echo '<br />Price to pay: ' . $price;
- }
- public static function showLevel($name, $conn) {
- $stmt = $conn->prepare("SELECT xp FROM users WHERE username = ?");
- $stmt->bind_param("s", $name);
- $stmt->execute();
- $stmt->bind_result($xp);
- $stmt->store_result();
- while($stmt->fetch()) {
- echo '<b>' . self::getLevelForXP($xp) . '</b>';
- }
- }
- public static function showXP($name, $conn) {
- $stmt = $conn->prepare("SELECT xp FROM users WHERE username = ?");
- $stmt->bind_param("s", $name);
- $stmt->execute();
- $stmt->bind_result($xp);
- $stmt->store_result();
- while($stmt->fetch()) {
- echo $xp;
- }
- }
- public static function validateNumber($string, $conn) {
- $pattern = "/^[0-9]+$/";
- $result = preg_match($pattern, $string);
- if (!$result) {
- return false;
- }
- return true;
- }
- public static function bankDeposit($name, $amount, $conn) {
- $cash = game::get("r", $name, "money", $conn);
- $bank = game::get("r", $name, "bank", $conn);
- $newTotalBank = $bank + $amount;
- $newTotalCash = $cash - $amount;
- $datetime = date("d/m/Y - H:i:s");
- if ($cash >= $amount) {
- if ($newTotalBank <= maxValues) {
- echo '<div class="alert alert-success">Succesfully deposited '.self::moneyformat($amount).' to your bank account.</div>';
- mysqli_query($conn, "UPDATE users SET bank = '$newTotalBank', money = '$newTotalCash' WHERE username = '$name'");
- mysqli_query($conn, "INSERT INTO banklogs (username, value, action, date) VALUES ('$name', '$amount', 'Deposit', '$datetime')");
- } else {
- echo '<div class="alert alert-danger">The maximum amount of money you can have on your bank is '.self::moneyformat(maxValues).'.</div>';
- }
- } else {
- echo '<div class="alert alert-danger">Sorry, but you do not have that much money.</div>';
- }
- }
- public static function bankWithdraw($name, $amount, $conn) {
- $cash = game::get("r", $name, "money", $conn);
- $bank = game::get("r", $name, "bank", $conn);
- $newTotalBank = $bank - $amount;
- $newTotalCash = $cash + $amount;
- $datetime = date("d/m/Y - H:i:s");
- if ($bank >= $amount) {
- if ($newTotalCash <= maxValues) {
- echo '<div class="alert alert-success">Succesfully withdrawn '.self::moneyformat($amount).' from your bank account.</div>';
- mysqli_query($conn, "UPDATE users SET bank = '$newTotalBank', money = '$newTotalCash' WHERE username = '$name'");
- mysqli_query($conn, "INSERT INTO banklogs (username, value, action, date) VALUES ('$name', '$amount', 'Withdraw', '$datetime')");
- } else {
- echo '<div class="alert alert-danger">The maximum amount of money you can have on you is '.self::moneyformat(maxValues).'.</div>';
- }
- } else {
- echo '<div class="alert alert-danger">Sorry, but you do not have that much money on your bank.</div>';
- }
- }
- //Casino's
- public static function attemptToBuyCasino($name, $country, $type, $conn) {
- $stmt = $conn->prepare("SELECT money FROM users WHERE username = ?");
- $stmt->bind_param("s", $name);
- $stmt->execute();
- $stmt->store_result();
- $stmt->bind_result($money);
- $stmt->fetch();
- $newBalanceUser = $money - 1500000;
- if ($money >= 1500000) {
- $stmt = $conn->prepare("SELECT owner FROM casinos WHERE owner = ?");
- $stmt->bind_param("s", $name);
- $stmt->execute();
- $stmt->store_result();
- $stmt->fetch();
- if ($stmt->num_rows() < 2) {
- echo '<div class="alert alert-success">You have succesfully bought the casino.<br />You can manage it by clicking <a href="game.php?page=casino&casino='.$type.'">here</a>.</div>';
- mysqli_query($conn, "UPDATE casinos SET value = '500000', minbet = '1000', maxbet = '50000', owner = '$name' WHERE type = '$type' AND country = '$country'");
- mysqli_query($conn, "UPDATE users SET money = '$newBalanceUser' WHERE username = '$name'");
- } else {
- echo '<div class="alert alert-danger">You already have 2 casinos!</div>';
- }
- } else {
- echo '<div class="alert alert-danger">You do not have enough cash money to buy this casino.</div>';
- }
- }
- public static function updateCasinoMinMax($casinoType, $casinoCountry, $setCasinoMin, $setCasinoMax, $conn) {
- mysqli_query($conn, "UPDATE casinos SET minbet = '$setCasinoMin', maxbet = '$setCasinoMax' WHERE type = '$casinoType' AND country = '$casinoCountry'");
- }
- public static function handleCasinoMoney($action, $amount, $casinoCountry, $casinoType, $name, $conn) {
- $stmt = $conn->prepare("SELECT value, owner FROM casinos WHERE country = ? AND type = ?");
- $stmt->bind_param("ss", $casinoCountry, $casinoType);
- $stmt->execute();
- $stmt->store_result();
- $stmt->bind_result($casinoValue, $casinoOwner);
- $stmt->fetch();
- $amountGet = $amount;
- $ownerMoney = self::get("r", $name, "money", $conn);
- $newDCasinoValue = $casinoValue + $amountGet;
- $newDUserValue = $ownerMoney - $amountGet;
- $newWCasinoValue = $casinoValue - $amountGet;
- $newWUserValue = $ownerMoney + $amountGet;
- if ($amount > 0) {
- if ($casinoOwner == $name) {
- if ($action == "withdraw") {
- if ($newWCasinoValue >= 100000) {
- if ($amountGet <= $casinoValue) {
- if ($ownerMoney + $amountGet <= maxValues) {
- echo '<div class="alert alert-success">You have succesfully withdrawn '.self::moneyformat($amountGet).' from your casino bank.</div>';
- mysqli_query($conn, "UPDATE casinos SET value = '$newWCasinoValue' WHERE country = '$casinoCountry' AND type = '$casinoType'");
- mysqli_query($conn, "UPDATE users SET money = '$newWUserValue' WHERE username = '$name'");
- } else {
- echo '<div class="alert alert-danger">You have too much cash money to withdraw that much.</div>';
- }
- } else {
- echo '<div class="alert alert-danger">You do not have that much money on your casino bank.</div>';
- }
- } else {
- echo '<div class="alert alert-danger">You need to keep atleast $100,000 on your casino bank.</div>';
- }
- } else if ($action == "deposit") {
- if ($amountGet <= $ownerMoney) {
- if ($amountGet + $casinoValue <= maxValues) {
- echo '<div class="alert alert-success">You have succesfully deposited '.self::moneyformat($amountGet).' into your casino bank.</div>';
- mysqli_query($conn, "UPDATE casinos SET value = '$newDCasinoValue' WHERE country = '$casinoCountry' AND type = '$casinoType'");
- mysqli_query($conn, "UPDATE users SET money = '$newDUserValue' WHERE username = '$name'");
- } else {
- echo '<div class="alert alert-danger">Your casino has too much money to deposit that much.
- <br />The maximum value is $2,147,483,646</div>';
- }
- } else {
- echo '<div class="alert alert-danger">You do not have that much money.</div>';
- }
- } else {
- echo '<div class="alert alert-danger">Invalid action</div>';
- }
- } else {
- echo '<div class="alert alert-danger">You do not own this casino!</div>';
- }
- } else {
- echo '<div class="alert alert-danger">Please enter an amount above 0.</div>';
- }
- }
- public static function casinodelay($name, $conn) {
- $stmt = $conn->prepare("SELECT casinodelay FROM users WHERE username = ?");
- $stmt->bind_param("s", $name);
- $stmt->execute();
- $stmt->bind_result($casinodelay);
- $stmt->store_result();
- $stmt->fetch();
- if ($casinodelay > time()) {
- return false;
- } else {
- return true;
- }
- }
- public static function handleBulletsPurchase($name, $userBullets, $bulAmount, $userCountry, $conn) {
- $stmt = $conn->prepare("SELECT country, bullets FROM bulletfactories WHERE country = ?");
- $stmt->bind_param("s", $userCountry);
- $stmt->execute();
- $stmt->store_result();
- $stmt->bind_result($country, $bulletsleft);
- $stmt->fetch();
- $userMoney = self::get("r", $name, "money", $conn);
- $userBullets = self::get("r", $name, "bullets", $conn);
- $subTotal = $bulAmount * bulletPrice;
- $updateleft = $bulletsleft - $bulAmount;
- $updatmoney = $userMoney - $subTotal;
- $newbul = $userBullets + $bulAmount;
- if ($subTotal <= $userMoney) {
- echo '<div class="alert alert-success">You have succesfully bought '.self::bulletformat($bulAmount).' bullets for '.self::moneyformat($subTotal).'.</div>';
- mysqli_query($conn, "UPDATE bulletfactories SET bullets = '$updateleft' WHERE country = '$userCountry'");
- mysqli_query($conn, "UPDATE users SET bullets = '$newbul', money = '$updatmoney' WHERE username = '$name'");
- } else {
- echo '<div class="alert alert-danger">Sorry, but you do not have enough money for this purchase.</div>';
- }
- echo '<hr>';
- }
- public static function buyHealth($name, $health, $conn) {
- $currentHealth = self::get("r", $name, "health", $conn);
- $userMoney = self::get("r", $name, "money", $conn);
- $newHealth = $currentHealth + $health;
- $calcprice = $health * 10000;
- $newBalance = $userMoney - $calcprice;
- if ($calcprice <= $userMoney) {
- if (($newHealth > 1) && ($newHealth <= 100)) {
- echo '<div class="alert alert-success">You have succesfully bought '.$health.' health for '.game::moneyformat($calcprice).'.</div>';
- mysqli_query($conn, "UPDATE users SET health = '$newHealth', money = '$newBalance' WHERE username = '$name'");
- } else {
- echo '<div class="alert alert-danger">You cannot have below 1 health and above 100 health.</div>';
- }
- } else {
- echo '<div class="alert alert-danger">You do not have enough money to buy '.$health.' health.</div>';
- }
- }
- public static function getWeaponStrength($weapon) {
- if ($weapon == "Knife") {
- return 0.1;
- } else if ($weapon == "Pistol") {
- return 0.25;
- } else if ($weapon == "Auto Pistol") {
- return 0.40;
- } else if ($weapon == "Rifle") {
- return 0.6;
- } else if ($weapon == "Auto Rifle") {
- return 0.8;
- } else if ($weapon == "Sniper") {
- return 1;
- }
- }
- public static function fetchTarget($name, $item, $conn) {
- $stmt = $conn->prepare("SELECT ".$item." FROM users WHERE username = ?");
- $stmt->bind_param("s", $name);
- $stmt->execute();
- $stmt->store_result();
- $stmt->bind_result($itemFetch);
- $stmt->fetch();
- return $itemFetch;
- }
- public static function killUser($target, $conn) {
- $amountLost = self::fetchTarget($target, "bank", $conn) / 100 * 25;
- $newCash = self::fetchTarget($target, "bank", $conn) - $amountLost;
- mysqli_query($conn, "UPDATE users SET health = '0', money = '0', bank = '$newCash', isdead = '1' WHERE username = '$target'");
- }
- public static function handleKill($name, $target, $bulamount, $conn) {
- $stmt = $conn->prepare("SELECT lastkill, money, location, weapon, bullets FROM users WHERE username = ?");
- $stmt->bind_param("s", $name);
- $stmt->execute();
- $stmt->store_result();
- $stmt->bind_result($lastkill, $cash, $location, $weapon, $bullets);
- $stmt->fetch();
- $targetArmour = self::fetchTarget($target, "armour", $conn);
- $targetLife = self::fetchTarget($target, "health", $conn);
- $targetCash = self::fetchTarget($target, "money", $conn);
- $targetBank = self::fetchTarget($target, "bank", $conn);
- $targetLevel = self::getLevelForXP(self::fetchTarget($target, "xp", $conn));
- $targetLoc = self::fetchTarget($target, "location", $conn);
- $bulletdamage = self::getWeaponStrength(self::get("r", $name, "weapon", $conn)) * $bulamount / $targetArmour / $targetLevel;
- $rounddmg = round($bulletdamage);
- $newtarglife = $targetLife - $rounddmg;
- $newbullets = $bullets - $bulamount;
- $rewardbank = $targetBank / 100 * 25; //Target
- $reward = $targetCash + $rewardbank; //Target
- $newcash = $cash + $reward;
- $curtime = time() + 3600;
- if ($lastkill > time()) {
- echo '<div class="alert alert-danger">You have to wait untill '.date("H:i:s", $lastkill).' to attack again.</div>';
- } else {
- if ($targetLife > 0) {
- if ($location == $targetLoc) {
- if ($bulamount <= $bullets) {
- echo '<div class="alert alert-success">You have shot '.$target.' with '.self::bulletformat($bulamount).' bullets.</div>';
- if ($newtarglife <= 0) {
- echo '<div class="alert alert-success">You have killed '.$target.' and received '.self::moneyformat($reward).'!</div>';
- mysqli_query($conn, "UPDATE casinos SET value = '0', owner = '' WHERE owner = '$target'");
- mysqli_query($conn, "UPDATE users SET lastkill = '$curtime', bullets = '$newbullets' WHERE username = '$name'");
- game::killUser($target, $conn);
- if ($cash + $reward <= maxValues) {
- mysqli_query($conn, "UPDATE users SET money = '$newcash' WHERE username = '$name'");
- } else {
- $wasted = $newcash - 5000000000;
- mysqli_query($conn, "UPDATE users SET money = '5000000000' WHERE username = '$name'");
- echo '<div class="alert alert-danger">The reward + your own money was over max cash. <br />'.game::moneyformat($wasted).' has been lost!</div>';//towaste
- }
- } else {
- echo '<div class="alert alert-warning">'.$target.' has survived with '.$newtarglife.' health!</div>';
- mysqli_query($conn, "UPDATE users SET lastkill = '$curtime', bullets = '$newbullets' WHERE username = '$name'");
- mysqli_query($conn, "UPDATE users SET health = '$newtarglife' WHERE username = '$target'");
- }
- } else {
- echo '<div class="alert alert-danger">You do not have that many bullets.</div>';
- }
- } else {
- echo '<div class="alert alert-danger">Sorry, but your target could not be found in '.$location.'.</div>';
- }
- } else {
- echo '<div class="alert alert-danger">This user has aleady been slaughtered.</div>';
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment