[Release] Partial Code from (S-y) WS2

strsup

New Member
Joined
Jan 18, 2009
Messages
69
Reaction score
11
I came to possession of some interesting files...
A friend of mine sent me these files cuz i wanted some socket and harmony enchanting scripts from web... As far as i am aware of they are from the s-y private webshop (v2) and i cant seem to get it how they function w/o the rest of the files which my mate doesn't want to give away ...
(no template, no config, no core)

I give you the files with the hope that someone can give me the other functions and the core of this shop :S
sock.php
PHP:
<?php
/*

	S-y Mu WebShop v2 Socket Enchanter Plugin
	[email protected]
	
													*/
													
$xml	= xml2var(file_get_contents('./cfg/sockets.xml'));
$cfg	= $xml['main'];

if ( $cfg['enabled'] != 1 ) 
{// Check if enabled

	header('location: Index.php');
	exit;
}

$sockets	= Array( );
$sockets[0]	= 'No Socket';

foreach( $cfg['sockets'] as $sockid => $sockname ) 
{// Make sure all socket IDs are valid

	$sockets[str_replace('_', '', $sockid)]	= addslashes($sockname);
}

// Smaartyyyy
$stpl 				= new Smarty;
$stpl->compile_check= true;
$stpl->debugging 	= false;
$stpl->template_dir	= $cfgmain['tplpath'].'/'.$cfgmain['template'];

if ( @$_SESSION['sy_user'] ) 
{// Case we are logged in

	require_once './inc/db.connect.php';
	include_once './inc/ws_parseitem.php';
	$stpl->assign('user', $_SESSION["sy_user"]);
	
	// Parse warehouse contents
	$query = $db->query("
	if exists(select * from tempdb.dbo.sysobjects where id = OBJECT_ID(N'tempdb..#Items')) drop table #Items;
	create table #Items(Item varchar(32));
	declare @item varbinary(16), @i int;
	set @i = 0;
	while (@i<120) begin
		set @item=(select substring(Items, (@i*16)+1, 16) from [Warehouse] where [AccountId]='".substr($_SESSION['sy_user'], 0, 10)."');
		if (@item!=0xffffffffffffffffffffffffffffffff) insert into #Items(Item) VALUES(@item);
		set @i = @i+1;
	end
	select Item from #Items;");
	
	$sockEnabledItems	= Array( ); 
	$_ie				= Array( );
	
	while ($query->fetchInto($res)) 
	{// Check if each item has sockets enabled
	
		$res	= bin2hex($res[0]);
		$item 	= parseitem($res);
		if (@$item['socket']) 
		{// Case we have an item that has sockets enabled
		
			$lvl				= $item['level']==0 ? '' : ' +'. $item['level'];
			$sockEnabledItems[] = Array(
										"$res", 
										$item["name"].$lvl,  
										str_split(substr($res, -10, 10), 2)
									);
			$_ie["$res"]		= 1;
			
		}
	}
	
	foreach ($_POST as $item) 
		if ( (strlen($item)==32) && ($_POST[1]>0 || $_POST[2]>0 || $_POST[3]>0 || $_POST[4]>0 || $_POST[5]>0) )
		{// Do The Works

			$err	= 0;
			$shells	= 0;
			$item	= substr($item,0,32);
			if (@$cfg["no_socket_diplicity"])
			{// Ensure that no socket options are multiplied
			
				$checker= $_POST;
				$tmpArr = Array( );
				$i		= 0;
				while ($i<$cfg['max_sockets'])
				{// Loop throught all sockets

						$i++;
						while($checker[$i]>50) 
							$checker[$i]-=50;		
						
						if (@$tmpArr[$checker[$i]]==1 && $checker[$i]>0) 
						{

							$err=1;// ECode #1 > Duplicity Error
							break;
						}
						$tmpArr[$checker[$i]]	= 1;
				}			
			}
			if (@$_ie[$item]!=1)
				$err	= 3; // ECode #3 > Invalid item selected
				
			$olditem	= $item;
			$newitem	= $olditem;
			$i			= 0;
			while ($i<$cfg['max_sockets'])
			{
				
				$i++;
				$sock[$i]	= (int)$_POST[$i];
				if (!$sockets[$sock[$i]]) 
				{
				
					$err	= 2;// Ecode #2 > Invalid Socket ID
					break;
				}
				$rm=0;
				if ($sock[$i]>0)
				{
				
					$rm=1;
					$shells	+= $cfg['shell_per_socket'];
				}
				
				$prenew		= $newitem;
				$newitem	= substr_replace($newitem, sprintf("%02X", $sock[$i]), 20+($i*2), 2);
				//print $newitem."(".strlen($newitem).")<BR>".$prenew."(".strlen($prenew).")<BR><BR>";#debug
				if (strtolower($prenew)==strtolower($newitem)&&$rm==1) 
					$shells	-= $cfg['shell_per_socket'];
				elseif (hexdec(substr($prenew,20+($i*2), 2))>0 && $rm==1) 
					$shells -= round($cfg['shell_per_socket']/2);
			}
			if (sh3lls($_SESSION["sy_user"])<$shells) 
				$err=4;// ECode #4 > Insufficient Shell Amount.
				
			if ($err==0) 
			{// Case Everything is okay
			
				$z		= 0;
				$removed= 0;
				$itemz	= array();
				$itemz[]= '0x';
				while ($z<120)
				{
				
					$query	=& $db->query("select substring(Items,".($z*16+1).",16) from warehouse where AccountId='".$_SESSION['sy_user']."'");
					$query->fetchInto($row);
					if ($removed==0 && bin2hex($row[0])==$olditem) 
					{ 
						
						$removed=1;
						$itemz[]= $newitem;
					}
					else
						$itemz[]= bin2hex($row[0]);
					$z++;
				}
				if ($removed==1)
				{			
				
					sh3lls($_SESSION["sy_user"],$shells);
					$err=-1;
					wlog("ENCHANT_ITEM",array($olditem, $newitem ,$shells));
					$db->query("update warehouse set items=".implode('',$itemz)." where accountid='".$_SESSION['sy_user']."'");
				} else $err=3;
			}
	}
}
$stpl->assign('socket_array', $sockets);
$stpl->assign('socket_array2', array_keys($sockets));
$stpl->assign('myconfig', $cfg);
$stpl->assign('items', $sockEnabledItems);
@$stpl->assign('err', $err);

$stpl->display('sock_edit.tpl');
?>

harmony.php
PHP:
<?php
/*

	S-y Mu WebShop v2 Harmony Enchanter Plugin
	[email protected]
	
													*/

$err					= 0;
$method					= @(int)$_GET['do'];

$harm 					= new Smarty;
$harm->compile_check 	= true;
$harm->debugging 		= false;
$harm->template_dir		= $cfgmain['tplpath'].'/'.$cfgmain['template'];
$xml					= xml2var(file_get_contents('./cfg/harmony.xml'));
$cfg					= $xml['main'];

if ($cfg['enabled']!=1)				$harm->assign('err',1);
	elseif (@!$_SESSION['sy_user'])	$harm->assign('err',2);
else {// Start the proccess

	require_once './inc/db.connect.php';
	include_once './inc/ws_parseitem.php';
	
	// Parse warehouse contents
	$query = $db->query("if exists(select * from tempdb.dbo.sysobjects where id = OBJECT_ID(N'tempdb..#Items')) drop table #Items;
	create table #Items(Item varchar(32));
	declare @item varbinary(16), @i int;
	set @i = 0;
	while (@i<120) begin
		set @item=(select substring(Items, (@i*16)+1, 16) from [Warehouse] where [AccountId]='".substr($_SESSION['sy_user'], 0, 10)."');
		if (@item!=0xffffffffffffffffffffffffffffffff) insert into #Items(Item) VALUES(@item);
		set @i = @i+1;
	end
	select Item from #Items;");
	
	$ItemArray	= Array ( );
	$_ie			= Array ( );
	while ($query->fetchInto($res)) 
	{
	
		$res	= bin2hex($res[0]);

		$item 	= parseitem($res);
		if (@$item['canRefine']) 
		{
		
			$lvl			= $item['level']==0?'':' +'.$item['level'];
			$ItemArray[] 	= Array("$res", $item["name"].$lvl);
			$_ie["$res"]	= 1;
		}
	}
	if ($method==1)
	{
	
		$item=@substr($_GET["enchant_item"],0,32);
		if (@$_ie["$item"]!=1) 	$err=3;
		else 
		{
			$info			= parseitem($item);
			$info['hex']	= $item;
			$harm->assign('item', $info);
		}
	}
	if ($method==2)
	{
		$item		= @substr($_GET["enchant_item"],0,32);
		$olditem	= $item;
		if (@$_ie["$item"]!=1) 	$err=3;
		else 
		{
			$enchantby	= (int)$_GET["harmony"];
			if ($enchantby>10||$enchantby<1) $err=4; else
			{
			
				$item		= str_split($item,1);
				
				if ($item[20]>0) 	$shells=$cfg['shell_for_change'];
				else				$shells=$cfg['shell_for_add'];
				if (sh3lls($_SESSION["sy_user"])<$shells) die("Insufficient shells");
				$item[20]	= dechex($enchantby);
				if ($enchantby<5) $enchantwith=15;
				else $enchantwith=13;
				$item[21]	= dechex($enchantwith);
				
				$newitem 	= implode('', $item);
				
				
				$z		= 0;
				$removed= 0;
				$itemz	= array();
				$itemz[]= '0x';
				while ($z<120)
				{
				
					$query	=& $db->query("select substring(Items,".($z*16+1).",16) from warehouse where AccountId='".$_SESSION['sy_user']."'");
					$query->fetchInto($row);
					if ($removed==0 && bin2hex($row[0])==$olditem) 
					{ 
						
						$removed=1;
						$itemz[]= $newitem;
					}
					else
						$itemz[]= bin2hex($row[0]);
					$z++;
				}

				if ($removed==1) 
				{
				
					sh3lls($_SESSION["sy_user"],$shells);
					$err=-1;
					wlog("ENCHANT_ITEM_H",array($olditem, $newitem ,$shells));
					$db->query("update warehouse set items=".implode('',$itemz)." where accountid='".$_SESSION['sy_user']."'");
				}
			}
		}
	}
}
$harm->assign('method', $method);
$harm->assign('myconfig', $cfg);
$harm->assign('items', $ItemArray);
$harm->assign('cfg', $cfg);
$harm->assign('err', $err);

$harm->display('harmony.tpl');
?>