PHP Code:
<?php
/*
LastThief's Ultimate Sro Class
Email:lastthiefrocketmail.com
skype:thelastthief
Please do not remove this.
*/
class Silkroad
{
protected $connection;
protected $connectionInfo;
public function SQL($credentials, $connect)
{
$this->connectionInfo = $credentials;
if ($connect)
$this->Connect();
}
public function Connect()
{
$this->connection = mssql_connect($this->connectionInfo['Host'], $this->connectionInfo['User'], $this->connectionInfo['Pass']);
if (!$this->connection)
die('Couldn\'t establish a connection to the datatabase');
}
public function getConnection()
{
return $this->connection;
}
public function Query($query)
{
$result = mssql_query($query, $this->connection);
if (!$result)
die('Couldn\'t execute query.');
return $result;
}
public function selectDB($db)
{
if (!mssql_select_db($db, $this->connection))
die('Couldn\'t select database.');
}
public function Close()
{
mssql_close($this->connection);
}
public function rowcount($result)
{
$return = mssql_num_rows($result);
if (!$result)
die('Could\'t get rowcount.');
return $return;
}
public function fetchrow($resource)
{
$result = mssql_fetch_row($resource);
return $result;
}
public function fetcharray($resource)
{
$result = mssql_fetch_array($resource);
return $result;
}
public function fetchassoc($resource)
{
$result = mssql_fetch_assoc($resource);
return $result;
}
public function rowsaffected()
{
$rows = mssql_rows_affected($this->connection);
return $rows;
}
function is_secure($string)
{
$pattern = "#[^a-zA-Z0-9_\-]#";
if (preg_match($pattern, $string) == true)
return false;
else
return true;
}
function MessageBox($message, $delay, $url)
{
echo "<script>
alert(\"$message\")
</script>";
header("Refresh: $delay; url=$url");
}
function redirect($url, $permanent = false)
{
if ($permanent) {
header('HTTP/1.1 301 Moved Permanently');
}
header('Location: ' . $url);
exit();
}
public function Result($query, $number, $rowname)
{
$result = mssql_result($query, $number, $rowname);
return $result;
}
function check_access($file)
{
if (eregi("$file", $_SERVER['PHP_SELF'])) {
die("<h4>You don't have right permission to access this file directly.</h4>");
}
}
function getFutureDate($sqldate, $day, $month, $year)
{
$d = substr($sqldate, 8, 2);
$m = substr($sqldate, 5, 2);
$y = substr($sqldate, 0, 4);
$h = substr($sqldate, 11, 2);
$min = substr($sqldate, 14, 2);
$d = intval($d) + $day;
$m = intval($m) + $month;
$y = intval($y) + $year;
if ($d > 31) {
while ($d > 31) {
$d -= 31;
$m += 1;
}
}
if ($m > 12) {
while ($m > 12) {
$m -= 12;
$y += 1;
}
}
if ($d < 10)
$d = '0' . $d;
if ($m < 10)
$m = '0' . $m;
$r = $y . '-' . $m . '-' . $d . ' ' . $h . ':' . $min . ':00.000';
return $r;
}
function ms_escape_string($data)
{
if (!isset($data) or empty($data))
return '';
if (is_numeric($data))
return $data;
$non_displayables = array(
'/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15
'/%1[0-9a-f]/', // url encoded 16-31
'/[\x00-\x08]/', // 00-08
'/\x0b/', // 11
'/\x0c/', // 12
'/[\x0e-\x1f]/' // 14-31
);
foreach ($non_displayables as $regex)
$data = preg_replace($regex, '', $data);
$data = str_replace("'", "''", $data);
return $data;
}
function isValidEmail($email)
{
return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
}
function getChars($JID, $database)
{
$charNames = array();
$i = 0;
$query = $this->Query("SELECT CharID from $database.dbo._User WHERE UserJID='$JID'");
while ($row = $this->fetchrow($query)) {
$charName = $this->fetchrow($this->Query("select CharName16,Deleted from $database.dbo._Char where CharID='$row[0]'"));
if ($charName[1] == "1")
continue;
$charName = $charName[0];
$charNames[$i] = $charName;
$i++;
}
$Chars = "Select your char :<br> <select name='char'>";
for ($i = 0; $i < count($charNames); $i++) {
$Chars .= "<option style='width:220px;' name='$charNames[$i]'>$charNames[$i]</option>";
}
$Chars .= "</select>";
return $Chars;
}
function getJID($username)
{
$query = $this->Query("SELECT * FROM TB_User WHERE StrUserID='$username'");
$row = $this->fetcharray($query);
$JID = $row['JID'];
return $JID;
}
function getSilkAmount($JID)
{
$query = $this->Query("SELECT * FROM SK_Silk WHERE JID = '$JID'");
$row = $this->fetcharray($query);
$silk = $row['silk_own'] + $row['silk_point'] + $row['silk_gift'];
return $silk;
}
function Reg($username, $password,$email)
{
//todo
}
function Login($username, $password,$redirect)
{
$username = $this->ms_escape_string($username);
$password = md5($this->ms_escape_string($password));
$pw = $this->ms_escape_string($password);
if(empty($username) || empty($password)) $msg[]='Please fill in all required fileds';
if(strlen($username) < 6) $msg[]='Username is shorter than 6 letters';
//to-continue
}
function ChangePassword($oldpassword, $newpassword, $newpassword2)
{
//todo
}
}
?>
Ciao :)