Code Fix Lỗi VPoint SWeb

Admin

Lính đánh thuê
Staff member
Tôi đã xem sơ qua và có đoạn này
Mã:
[COLOR="#FF0000"]$general1 = "UPDATE MEMB_INFO SET vpoint = $check WHERE memb___id='$login'";
    $msgeneral1 = $db->Execute($general1);[/COLOR]


và vấn đề ở đây là người code viết ... quá. đọi tí có code fix


for($j=0;$j<$slg;$j++) ==> bug here


do đoạn code - vpoin nằm dưới vòng lặp for, vậy khi mình mua với số lượng là 1 thì ko sao, nhưng nếu mua số lượng > 1 mà trong hành trang ko đủ chổ trống thì nó bị bắt lỗi ngay đoạn
Mã:
[COLOR="#FF0000"]if ( empty($reponse) ) {
			$notice = "Server bảo trì vui lòng liên hệ Admin để FIX";
			exit();
		} else {
			$info = read_TagName($reponse, 'info');
			if ($info == "OK") {
				$inventory_rec= read_TagName($reponse, 'inventory');
				if(strlen($inventory_rec) ==0) {
					echo "Dữ liệu trả về lỗi. Vui lòng liên hệ Admin để FIX";
					$arr_view = "\nDataSend:\n";
					foreach($getcontent_data as $k => $v) {
						$arr_view .= "\t". $k ."\t=>\t". $v .",\n"; 
					}
					writelog("log_api.txt", $arr_view . $reponse);
					exit();
				}	
			}else if($info=="Error"){
				echo read_TagName($reponse, 'msg');
				exit();
			}
			else {
				echo "Kết nối API gặp sự cố. Vui lòng liên hệ nhà cung cấp SWebMU để kiểm tra.";
				writelog("log_api.txt", $reponse);
				exit();
			}
		}[/COLOR]
ngay trong vòng lặp for
vậy chúng ta có cách giải quyết như sau:


Cách 1: trừ tiền theo vòng lặp. Ví dụ mình add 1 thì trừ tiền 1 lần với giá = chính giá của vật phẩm mua. (chú ý là ko nhân với số lượng)
Cách 2: Tạo thêm 1 biến để kiểm tra khi thùng đồ đầy item. và đã add được bao nhiêu vào thùng đồ
Ở đây tôi làm theo cách 2. Vì cách 1 nó request lên SQL Server quá nhiều.


File: shop_item.php
Mã:
<?php
include_once("security.php");
include_once("config.php");
include_once("function.php");
include('config/config_chucnang.php');
include('config/config_webshop_promotions.php');
$login=$_POST["login"];
$name=$_POST["name"];
$act = $_POST['act'];
$item=$_POST["item"]; //ID Load
$slg=$_POST["slg"];
$pass2 = $_POST['pass2'];
$passtransfer = $_POST["passtransfer"];
if ($passtransfer == $transfercode) {
$string_login = $_POST['string_login'];
checklogin($login,$string_login);
kiemtra_pass2($login,$pass2);
kiemtra_doinv($login,$name);
if(check_nv($login, $name) == 0) {
    echo "Nhân vật <b>{$name}</b> không nằm trong tài khoản <b>{$login}</b>. Vui lòng kiểm tra lại."; exit();
}
	switch ($act)
	{
		case 'shop_taphoa': 
			$file_shop = 'config/shop_taphoa.txt';
			$file_log = 'shop_taphoa.php';
			break;
		case 'shop_event': 
			$file_shop = 'config/shop_event.txt';
			$file_log = 'shop_event.php';
			break;
		case 'shop_acient': 
			$file_shop = 'config/shop_acient.txt';
			$file_log = 'shop_acient.php';
			break;
		case 'shop_kiem': 
			$file_shop = 'config/shop_kiem.txt';
			$file_log = 'shop_kiem.php';
			break;
		case 'shop_gay': 
			$file_shop = 'config/shop_gay.txt';
			$file_log = 'shop_gay.php';
			break;
		case 'shop_cung': 
			$file_shop = 'config/shop_cung.txt';
			$file_log = 'shop_cung.php';
			break;
		case 'shop_vukhikhac': 
			$file_shop = 'config/shop_vukhikhac.txt';
			$file_log = 'shop_vukhikhac.php';
			break;
		case 'shop_khien': 
			$file_shop = 'config/shop_khien.txt';
			$file_log = 'shop_khien.php';
			break;
		case 'shop_mu': 
			$file_shop = 'config/shop_mu.txt';
			$file_log = 'shop_mu.php';
			break;
		case 'shop_ao': 
			$file_shop = 'config/shop_ao.txt';
			$file_log = 'shop_ao.php';
			break;
		case 'shop_quan': 
			$file_shop = 'config/shop_quan.txt';
			$file_log = 'shop_quan.php';
			break;
		case 'shop_tay': 
			$file_shop = 'config/shop_tay.txt';
			$file_log = 'shop_tay.php';
			break;
		case 'shop_chan': 
			$file_shop = 'config/shop_chan.txt';
			$file_log = 'shop_chan.php';
			break;
		case 'shop_trangsuc': 
			$file_shop = 'config/shop_trangsuc.txt';
			$file_log = 'shop_trangsuc.php';
			break;
		case 'shop_canh': 
			$file_shop = 'config/shop_canh.txt';
			$file_log = 'shop_canh.php';
			break;
		default: $file_shop = ''; break;
	}
	$item_read = shop_load($file_shop);
	$item_true = $item-1;
	$itemcode = $item_read[$item_true]['code'];
	if(($Use_Promotion_Webshop==1) && strtotime($Promotion_Webshop_Start)<time() && strtotime($Promotion_Webshop_End.' 23:59:00')>time()){
		$price = $item_read[$item_true][price]-($item_read[$item_true][price]*($Promotion_Webshop/100));
	}else{
		$price = $item_read[$item_true]['price'];
	}
	$item_name = $item_read[$item_true]['des'];
	$item_hsd = $item_read[$item_true]['hsd'];
	if($item_hsd>1 && $slg>1){
	 echo "Đối với Item có thời hạn bạn chỉ được phép mua 1 lần 1 Item"; 
	 exit();
	}
	if(strlen($itemcode)<=0){
		echo "Trên server không tồn tại Item bạn mua. Vui lòng liên hệ admin để fix"; exit();
	}
	$query = "select vpoint from MEMB_INFO WHERE memb___id='$login'";
	$result = $db->Execute( $query );
	$row = $result->fetchrow();
	$gias = $slg*$price;
	$check=$row[0]-$gias;
	
	if( $check < 0 ){
		echo "Bạn đang có $row[0] Vpoint. $slg đồ $item_name giá $gias Vpoint.<br>Bạn còn thiếu $check Vpoint";
		exit(); 
	}
	
	[COLOR="#FF0000"]$count = 0;
	$bRet = 0;
	for($j=0;$j<$slg;$j++)
	{
		$bRet = 0;
		$item_seri_send = serial_gen();
		$inventory=inventory($name);
		include_once('config_license.php');
		include_once('func_getContent.php');
		$getcontent_url = $url_license . "/api_webshop_buy.php";
		$getcontent_data = array(
			'acclic'    =>  $acclic,
			'key'    =>  $key,
			'name' =>$name,
			'inventory' =>$inventory,
			'itemcode' =>$itemcode,
			'item_seri_send' =>$item_seri_send,
			//'slg' => $slg, ==> Stupid code
			'item_hsd' => $item_hsd
		); 	
		$reponse = _getContent($getcontent_url, $getcontent_data, $getcontent_method, $getcontent_curl);
		if ( empty($reponse) ) {
			$bRet = 1;
			//exit();
			break;
		} else {
			$info = read_TagName($reponse, 'info');
			if ($info == "OK") {
				$inventory_rec= read_TagName($reponse, 'inventory');
				if(strlen($inventory_rec) ==0) {
					$bRet = 2;
					//exit();
					break;
				}	
			}else if($info=="Error"){
				$bRet = 3;
				//exit();
				break;
			}
			else {
				$bRet = 4;
				//exit();
				break;
			}
		}
		
		$general = "UPDATE Character SET [inventory]=0x$inventory_rec WHERE name='$name'";
		$msgeneral = $db->Execute($general) or die("Loi query: $general");
		$count++;
	}
	
	if ($bRet > 0 && $count <= 0)
	{
		if ($bRet == 1){
			$notice = "Server bảo trì vui lòng liên hệ Admin để FIX";
		}else if ($bRet == 2) {
			echo "Dữ liệu trả về lỗi. Vui lòng liên hệ Admin để FIX";
			$arr_view = "\nDataSend:\n";
			foreach($getcontent_data as $k => $v) {
				$arr_view .= "\t". $k ."\t=>\t". $v .",\n"; 
			}
			writelog("log_api.txt", $arr_view . $reponse);
		}else if ($bRet == 3) {
			echo read_TagName($reponse, 'msg');
		}else if ($bRet == 4) {
			echo "Kết nối API gặp sự cố. Vui lòng liên hệ nhà cung cấp SWebMU để kiểm tra.";
			writelog("log_api.txt", $reponse);
		}else{
			$notice = "Loi chua biet liên hệ Admin để FIX";
		}
		exit();
	}
	
	$PricePay = $count * $price;
	if ($count > 0){
		$strQuery = "UPDATE MEMB_INFO SET vpoint = vpoint - $PricePay WHERE memb___id = '$login'";
		$pResult = $db->Execute($strQuery) or die("Query Error: $strQuery");
	}
    
    //Ghi vào Log nhung nhan vat mua Item
	$info_log_query = "SELECT gcoin, gcoin_km, vpoint FROM MEMB_INFO WHERE memb___id='$login'";
	$info_log_result = $db->Execute($info_log_query);
	check_queryerror($info_log_query, $info_log_result);
	$info_log = $info_log_result->fetchrow();


	$log_acc = "$login";
	$log_gcoin = $info_log[0];
	$log_gcoin_km = $info_log[1];
	$log_vpoint = $info_log[2];
	$log_price = "- $PricePay Vpoint";
	$log_Des = "Mua $count vật phẩm $item_name .Seri: $log_seri";
	$log_time = $timestamp;


	$insert_log_query = "INSERT INTO Log_TienTe (acc, gcoin, gcoin_km, vpoint, price, Des, time) VALUES ('$log_acc', $log_gcoin, $log_gcoin_km, $log_vpoint, '$log_price', '$log_Des', $log_time)";
	$insert_log_result = $db->execute($insert_log_query);
	check_queryerror($insert_log_query, $insert_log_result);
    //End Ghi vào Log nhung nhan vat mua Item
    echo "OK<nbb>$PricePay<nbb>Bạn đã mua thành công $count Item $item_name. Bạn đã bị trừ $PricePay V.Point";[/COLOR]
}
$db->Close();
?>


file: api_webshop_buy.php
Mã:
<?php
	include('checklic.php');
	include('func_item.php');
	$Name = $_POST['name'];
	$inventory = $_POST['inventory'];
	$itemcode = $_POST['itemcode'];
	$item_seri_send = $_POST['item_seri_send'];
	[COLOR="#FF0000"]//$slg = $_POST['slg']; ==> Stupid code[/COLOR]
	$item_hsd = $_POST['item_hsd']; $item_hsd = abs(intval($item_hsd));
	
	if($item_hsd!=0){
		$invetory_after = item_charactersweb_thue($itemcode,$inventory,$item_seri_send,$item_hsd);
	}else{
		$invetory_after = item_charactersweb($itemcode,$inventory,$item_seri_send);
	}
	if(isset($invetory_after)){
		echo "
			<info>OK</info>
			<inventory>$invetory_after</inventory>
		";
	}else{
		$Content = "Thùng đồ của $Name không còn chỗ trống";
		echo "
			<info>Error</info>
			<msg>$Content</msg>
		";
	}
				
?>


Đã test và chạy thành công.
Đây là code mẫu mình chỉ làm ở file đó. Còn chỗ nào thì các bạn tự xem code và thêm vào nhé.


Tôi có xem qua 1 số file. Và cũng thấy nhiều đoạn code lũng cũng, ko cần thiêt, hoặc có thể viết 1 cách ngắn gọn hơn. Và có nhiều cái rất hài hước như
Đoạn serial của bless nén level 0 (10 cục) như sau
1E0000001234560000C0000000000000


trong code php đã có GenSerial, mà trong code item lại để 123456.
Code bless no Serial: 1E0000000000000000C000FFFFFFFFFF
Code bless have serial: 1E0000000046510000C000FFFFFFFFFF


Nếu như dùng tool check dupe quét thì chắc chắn sẽ bị xóa. vì trùng serial. Nếu ai xài GS của tôi thì ko cần dùng tool. GS tự quét. Mà GS tự quét thì MU chắc đóng cửa sớm.
Thường thì những ngọc này ko check serial. nên nó là lý do vì sao bị dupe :))


P/S: Ai xài thì xài, không xài thì đừng có ném đã.
À, Bạn thiensu_muvn xài là dog nhé. Nói thẳng luôn.
 
Bên trên