1. deadspacex27.07.2024 в 21:15от
  2. Patronchik27.07.2024 в 20:31от
Загрузка...

Нужна помощь

Тема в разделе "Web-программирование", создана пользователем Dadashov, 31.01.2017.

  1. Dadashov

    Dadashov

    Статус:
    Оффлайн
    Регистрация:
    24.01.17
    Сообщения:
    14
    Репутация:
    0 +/-
    Вообщем поставил скрипт на vds, проблема заключается в том, когда зашёл на сайт, инвентарь бота отображается, собственный ивентарь отображается, обновляем страницу, инвентарь бота перестаёт отображаться. Обновляем ещё раз, собственный инвентарь тоже перестаёт отображаться. Обновляем через 5 минут, всё ок. И так по кругу.
    Сайт: http://steambalans.ru/ ( не реклама )
    Код:
    PHP:
    <script>
    var buyitems = new Array();
    var sellitems = new Array();
    var buyvalue = 0;
    var sellvalue = 0;
    function rewritevalue(){
        
        if(sellvalue==0 & logged==1){
        document.getElementById("checkout_r").style.display = "none";
        }
        else if(logged==1){
        document.getElementById("checkout_r").style.display = "";
        }
        document.getElementById("sell").innerHTML = "<?php echo $currencyname;?> " + (sellvalue) / 100.00;
        
        if(buyvalue==0 & logged==1){
        document.getElementById("checkout").style.display = "none";
        }
        else if(logged==1){
        document.getElementById("checkout").style.display = "";
        }
        document.getElementById("buy").innerHTML = "<?php echo $currencyname;?> " + (buyvalue) / 100.00;
        }
        
    function submit(){
        
    var sellitemids = JSON.stringify(sellitems);
    var buyitemids = JSON.stringify(buyitems);


    window.location = "queue.php?action=sell&botid=<?php echo $botsteamid?>&steamid=<?php echo $steamid?>&sellitems=" + sellitemids;
    window.location = "queue.php?action=buy&botid=<?php echo $botsteamid?>&steamid=<?php echo $steamid?>&buyitems=" + buyitemids;

    }       
        
        
    Array.prototype.remove = function(value) {
    var idx = this.indexOf(value);
    if (idx != -1) {
        return this.splice(idx, 1); // The second parameter is the number of elements to remove.
    }
    return false;
    }
    </script>
    PHP:
    </style>
    <?php
    ob_start
    ();
    include 
    "config.php";
    if (empty(
    $steamid)){
        
    header("Location: ".$notloggedurl);
    }
    ?>
    <div class="container" style="padding: 50px; color: white;">
    <div>

    </div>
    <?php
    if($_GET["action"]){
        
        
        
    //Checking if User is already in Queue
        
        
    $conn = new mysqli($servername$username$password$dbname);
        if (
    $conn->connect_error) {
            die(
    "Connection failed: " $conn->connect_error);
        }
        
    $sql7 "SELECT steamid FROM `csgotrades` WHERE (`completed` = 0 or `completed` = 1) and steamid = ".$steamid;
        
    $result7 mysqli_query($conn$sql7);

        if(
    $result7->num_rows 0){
            
    $allow "false";
            goto 
    process;
        }
        else {
            
    $allow "true";
        }
        
    $conn->close();
        
        
    //Defining important vars
        
        
    $action $_GET['action'];    //The Action that is performed (buy or sell)
        
    $SelectedItems json_decode($_GET['buyitems']);    //The itemids the user selected
        
    $UserSID $_SESSION["steamid"];    //The Users SteamID
        
    $BotSID $_GET['botid'];        //The Bots SteamID
        
    $SelectedItemsValue 0;                        //Defining SelectedItems Value
        
    $trade;
        
    $credits;
        
    $json//For Price Calc
        
        //Enabling Caching of Backpacks
        
    include "cache.php";
        
        
    //Getting Bots CSGO Backpack
        
    $data getJson('http://steamcommunity.com/profiles/'.$BotSID.'/inventory/json/730/2'$BotSID"730");
        
    $BotCSGOBackpack json_decode($data);
        
        
    //Getting Users CSGO Backpack
        
    $data getJson('http://steamcommunity.com/profiles/'.$UserSID.'/inventory/json/730/2'$UserSID"730");
        
    $UserCSGOBackpack json_decode($data);

        
        
    //Getting Pricing Data from Cache
        
    $pricedata file_get_contents('https://api.csgofast.com/price/all');
        
    $pricing json_decode($pricedata);
        
        
    //Pricing SelectedItems with SelectedItems Value
        
    if ($action=="buy")
        {
            
    $json $BotCSGOBackpack;
        }
        if (
    $action=="sell")
        {
            
    $json $UserCSGOBackpack;
        }
        
        
    //Checking for double items
        
    $items = [];
        foreach (
    $SelectedItems as $item){
            if (!
    in_array($item$items)){
                
    array_push($items,$item);
            } else {
                
    $allow "false";
            }
        }
        
        foreach (
    $SelectedItems as $item) {
            
    //Getting ItemIds
            
    $classid $json->rgInventory->$item->classid;
            
    $instanceid $json->rgInventory->$item->instanceid;
            
    $combined $classid "_" $instanceid;
            
            
    //Getting Market Hash Name
            
    $itemname $json->rgDescriptions->$combined->market_hash_name;
            
            
                
    $key false;
                
    $pos strpos($itemname"Case Key");
                if (
    $pos !== false) {
                
    $key true;
                }
                
    $pos strpos($itemname"eSports Key");
                if (
    $pos !== false) {
                
    $key true;
                }
            
            
    //Getting Type
            
    $ic 0;
            foreach (
    $json->rgDescriptions->$combined->tags as $colors){
                    
    $ic $ic 1;
                    if (
    $ic ==2){
                        
    $itemtype $colors->category;
                        
            }
            }
            
            if (
    $itemtype!== "Weapon" and $key == false){
                    
    $allow "false";
                    goto 
    process;
            }
            
            
    //Getting Price
            
    $itemprice $pricing->{$itemname};
            
    $itemprice $itemprice 1;
            
    $SelectedItemsValue $SelectedItemsValue $itemprice;
            if(
    $SelectedItemsValue == 0) {
                
    $accept "false";
                goto 
    process;
            }           
            if(
    $action=="buy"){
                
    //User buys Items
                
                
    $conn = new mysqli($servername$username$password$dbname);
                
    // Check connection
                
    if ($conn->connect_error) {
                    die(
    "Connection failed: " $conn->connect_error);
                }
                
                
    $sql29 "SELECT * FROM `prices`";
                
    $result4 mysqli_query($conn$sql29);
                
                while(
    $row mysqli_fetch_assoc($result4)) {
                    
                    
    $v=$row['value'] ;
                    
    $bpa=$row['buyadd'];
                    
    $bpm $row['buymulti'];
                    
    $spa=$row['selladd'];
                    
    $spm $row['sellmulti'];
                    
                    if(
    $v>=$itemprice){
                        
    $itemprice ceil(($itemprice $spa) * $spm);
                        
    $accept "true";
                        goto 
    b;
                    } else {
                        
                        
    $accept "false";
                    }
                    
                }
                
    b:
                
    $conn->close();
            }
            if(
    $action=="sell"){
                
    //User sells Items
                
                
    $conn = new mysqli($servername$username$password$dbname);
                
    // Check connection
                
    if ($conn->connect_error) {
                    die(
    "Connection failed: " $conn->connect_error);
                }
                
                
    $sql29 "SELECT * FROM `prices`";
                
    $result4 mysqli_query($conn$sql29);
                
                
                while(
    $row mysqli_fetch_assoc($result4)) {
                    
                    
    $v=$row['value'] ;
                    
    $bpa=$row['buyadd'];
                    
    $bpm $row['buymulti'];
                    
    $spa=$row['selladd'];
                    
    $spm $row['sellmulti'];
                    
                    if(
    $v $itemprice){
                        
    $itemprice ceil(($itemprice $bpa) * $bpm);
                        
    $accept "true";
                        goto 
    a;
                    } else {
                        
                        
    $accept "false";
                    }
                    
                }
                
    a:
                
    $conn->close();
                
            }

            
        }
        
    //Defining Vars first
        
        //Item Arrays
        
    $UserCSGOItems = [];
        
    $BotCSGOItems = [];

        
            
    //Getting Users current Credit Amount
            
    $conn = new mysqli($servername$username$password$dbname);
            if (
    $conn->connect_error) {
                die(
    "Connection failed: " $conn->connect_error);
            }
        
            
    $sql7 "SELECT balance FROM `users` WHERE steamid = ".$UserSID;
            
    $result7 mysqli_query($conn$sql7);
        
            while(
    $row mysqli_fetch_assoc($result7)) {
                
    $credits $row['balance'];
            }
        
            
    //Updating Users current Credit amount
            
    if($action=="buy"){
                if (
    $credits >= $SelectedItemsValue){
                    
    $trade "true";
                    
    $newvalue $credits $SelectedItemsValue;
                    
    $sql6 "UPDATE `users` SET balance = '".$newvalue."' WHERE `steamid` = ".$UserSID;
                    
    $result6 mysqli_query($conn$sql6);
                } else {
                    
    $trade "false";
                }
                if(
    $SelectedItemsValue == 0)
                    
    $trade "false";
            } else {
                
    $trade "true";
            }
            
            
    $conn->close();
            

            
        
        
    process:
        if(
    $trade=="true" and $allow=="true" and $accept == "true"){
                
    $empty = [];
            if(
    $action=="buy"){
                
    $takecsgoitems=json_encode($empty);
                
    $givecsgoitems=json_encode($SelectedItems);
                
            }
            if(
    $action=="sell"){
                
                
    $takecsgoitems=json_encode($SelectedItems);
                
    $givecsgoitems=json_encode($empty);
                
            }
            
            
                
    $paymenttype=1;
                if (
    $action == "buy"){
                
    $message "".$itemname." ".$SelectedItemsValue." ".$currencyname."";
                }
                if (
    $action == "sell"){
                
    $message "If you accept this Trade ".$SelectedItemsValue." ".$currencyname." will be given to your Balance!";
                }
            
            
    $tradeoffertoken=substr($tradeofferurl, -8);
            
    $conn = new mysqli($servername$username$password$dbname);
            
    // Check connection
            
    if ($conn->connect_error) {
                die(
    "Connection failed: " $conn->connect_error);
            }
            
    $sid=$steamid;
            
    $nick=$_SESSION['steam_personaname'];
            
    $sql "INSERT INTO csgotrades (completed, token, takecsgoitems, givecsgoitems, steamid, action, amount, message, nick)
            VALUES (0, '
    $tradeoffertoken', '$takecsgoitems', '$givecsgoitems', '$sid', '$action', '$SelectedItemsValue', '$message', '$nick')";
            
            if (
    $conn->query($sql) === TRUE) {
                
    header("Location: queue.php");
            } else {
                
    ob_end_flush();
                echo 
    "Error: " $sql "<br>" $conn->error;
            }
            
            
    $conn->close();
            
            
        } elseif (
    $trade =="false"){
            
    ob_end_flush();
            echo 
    '<div class="alert alert-danger" role="alert">You have not enough '.$currencyname.' to pay! Deposit!</div>';
        }
        elseif (
    $accept =="false") {
            echo 
    '<div class="alert alert-danger" role="alert">Error price skins</div>';
        }
        else {
            
    ob_end_flush();
            echo 
    '<div class="alert alert-danger" role="alert">You are already in the Queue! Please wait until your TradeOffer is processed!</div>';
        }
        
    }else{
        
    ob_end_flush();

        echo 
    "<br><h3>Users in the Queue:</h3><p><br>";
        
    //Get Queue
        
        
    $tradeofferurl;
        
    // Create connection
        
    $conn = new mysqli($servername$username$password$dbname);
        
    // Check connection
        
    if ($conn->connect_error) {
            die(
    "Connection failed: " $conn->connect_error);
        }
        
        
    $activeoffers "false";
        
    $sql7 "SELECT steamid FROM `csgotrades` WHERE `completed` = 0";
        
    $result7 mysqli_query($conn$sql7);
        
        while(
    $row mysqli_fetch_assoc($result7)) {
            
    $sid $row['steamid'];
                
    //Displaying Queue Users! Change this on your Own!
    $sql5 "SELECT avatar, nickname FROM `users` WHERE `steamid` = ".$sid;
    $result5 mysqli_query($conn$sql5);

        while(
    $row mysqli_fetch_assoc($result5)) {
        
    $uavatar $row['avatar'];
        
    $uname $row["nickname"];
         }

            if (
    $sid==$steamid){
                
    $border "4px solid #CF6A32";
                
    $activeoffers "true";
                
            } else {
                
    $border "4px solid gray";
            }
            echo 
    " <span tooltip='".$uname."'><img style='border: ".$border.";' src='".$uavatar."'></img></span>";
        }
        
        
        
        
    $conn->close();
        
        
    }


    ?>
    queue.php: