[Dev] Sell Resources Module

dota-sdso

Well-Known Member
Joined
Apr 30, 2014
Messages
590
Reaction score
822
Модула го написах за Webshop-a на Savoy, но пък реших да го споделя и в този вид, защото може да се прикачи към абсолютно всеки уебсайт.

Така като както е направен може да си работи самостоятелно, стига да му осигурите връзка с базата и да разпознава акаунта, който е логнат.

PHP:
<?php
$items_for_sell = array(
	//         ItemName           HexMark   Credits
	   array("Box of Kundun + 1"  ,'CB40'     ,200),
	   array("Box of Kundun + 2"  ,'CB48'     ,300),
	   array("Box of Kundun + 3"  ,'CB50'     ,400),
	   array("Box of Kundun + 4"  ,'CB58'     ,500),
	   array("Box of Kundun + 5"  ,'CB60'     ,600),
       array("Jewel of Chaos"     ,'8F00'     ,600),
       array("Jewel of Life"      ,'D000'     ,600),
       array("Jewel of Bless"     ,'CD00'     ,600),
       array("Jewel of Soul"      ,'CE00'     ,600),	   
	 );
	 
	$inv           = array();
	$current_items = '0x' . strtoupper(bin2hex(mssql_fetch_row(mssql_query("SELECT [Items] FROM [warehouse] WHERE [AccountID]='" . htmlspecialchars($_COOKIE['WebShopUsername']. "'")))[0]));
	$user_items    = substr($current_items,2);
    $empty         = str_repeat('F',20);
	
	for($i=0;$i<120;$i++){	    
        $item 	= substr($user_items,(20 * $i), 20);
        if(substr($item,0,4) <> "FFFF"){
			$inv[]    = substr($item,0,4);
		}					
	}		
    
	if(isset($_POST['hex']) && isset($_POST['submit']))
	{
		$key = (int)$_POST['hex'];
		if(mssql_num_rows(mssql_query("Select * from Memb_Stat where ConnectStat=0 and memb___id='" . htmlspecialchars($_COOKIE['WebShopUsername']. "'"))) == 1){
			if(($key <= count($items_for_sell)) && ($key >= 0) && (in_array($items_for_sell[$key][1],$inv))){			
			  for($i=0;$i<120;$i++){
				    if(substr($user_items,$i*20,4)== $items_for_sell[$key][1]){
				    	$mynewitems = substr_replace($user_items,$empty,$i*20,20);
				    }   
			  }  
			  $update_ware = mssql_query("Update warehouse set items = 0x".$mynewitems." where AccountID='".htmlspecialchars($_COOKIE['WebShopUsername'])."'");
                 if($update_ware){
			   	      mssql_query("Update Memb_Credits set credits = credits+".$items_for_sell[$key][2]." where memb___id='".htmlspecialchars($_COOKIE['WebShopUsername'])."'");        
			          echo "You have successfully sold one " . $items_for_sell[$key][0] ." for " . $items_for_sell[$key][2] . " credits " ;
				 }
                 else{
                	  echo "We found a problem, please contact the administrator";
                 }			 
		    }
			else{
			   echo "You do not have these resource at the moment";
		    }
		}
		else{
			echo "Please leave the game first";
		}
	}
		print '<fieldset style="width: 350px;background-color: #DDDDDD;border: 1px solid #000000; font-family: arial; font-size: 12px;"><legend class="mu_style2" style="padding: 3px;font-weight:bold;background-color: #DDDDDD;border: 1px solid #000000;border-bottom:0px;">Sell Resources</legend>';	
	echo "

	<form method='post'>
	<table width=100% cellpadding='2' cellspacing='1'	border='1'>
        <tr style='background:#bbbbbb;font-weight:600'>
		   <td>Item Name</td>
		   <td>Availability</td>
		   <td>Selling Price</td>
		   <td>Sell Now</td>
		</tr>			
	    ";

		foreach($items_for_sell as $key => $values){
	     echo "<tr><form method='post'>
		               <td>".$values[0]."</td>
					   <td>".count(array_keys($inv, $values[1]))."</td>
					   <td>x".bcmul(count(array_keys($inv, $values[1])),$values[2])." Credits</td>
					   <td align='center'>
					       <input type='hidden' name='hex' value='".$key."'/>
					       <input class='button' type='submit' value='Sell 1x' name='submit'/>
						</td>
			   </tr></form>";
		}

?>
 
  • Like
Reactions: Dude and Ivaylo99