<?php
if (!defined("STRESSWEB"))
die("Доступ к данной странице запрещен!");
function is_loged()
{
if (isset($_SESSION['sw_user_name']) && isset($_SESSION['sw_user_id']))
return true;
else
return false;
}
function pass_encode($pass)
{
$res = base64_encode(pack('H*', sha1(utf8_encode($pass))));
return $res;
}
function redirect($url)
{
header("Location: $url");
exit;
}
function sqlInjection($data)
{
$filter = array("select", "delete", "union", "update", "insert");
$filter_data = str_replace($filter, "", strtolower($data));
return $filter_data;
}
function phpInjection($data)
{
$filter = array("\\", "'", ",", ";", "--", "-", "%20", "%27", " ", "`", "=", "%");
$filter_data = str_replace($filter, "", $data);
return $filter_data;
}
function cookie_check()
{
global $ldb, $qList, $l2db_ls;
if (isset($_COOKIE['sw_usr_name']) && isset($_COOKIE['sw_usr_id']))
{
$sel = $ldb->query($ldb->_parse_query($qList[$l2db_ls]["getAccount"], array("login" => $ldb->safe($_COOKIE['sw_usr_name']), "where" => "AND `password`='" . $ldb->safe($_COOKIE['sw_usr_id']) . "'")));
if ($ldb->numrows($sel) == 0)
{
set_cookies(array("sw_usr_name" => "", "sw_usr_id" => ""), 0);
}
else
{
$acc_data = $ldb->fetch_array($sel);
if ($acc_data["accessLevel"] < 0)
{
set_cookies(array("sw_usr_name" => "", "sw_usr_id" => ""), 0);
}
else
{
$_SESSION['sw_user_name'] = $acc_data["login"];
$_SESSION['sw_user_id'] = $acc_data["password"];
}
}
$host = $_SERVER['HTTP_HOST'] ? $_SERVER['HTTP_HOST'] : @getenv('HTTP_HOST');
$self = $_SERVER['REQUEST_URI'] ? $_SERVER['REQUEST_URI'] : @getenv('REQUEST_URI');
redirect("http://"'>http://" . $host . $self . "");
}
}
function user_check($user_name, $user_pass)
{
global $error_msg, $ldb, $qList, $l2db_ls;
$_l2sec_code = $_POST["l2sec_code"];
$_l2ses_code = $_SESSION["seccode"];
$sel = $ldb->query($ldb->_parse_query($qList[$l2db_ls]["getAccount"], array("login" => $user_name, "where" => "")));
if ($ldb->numrows($sel) > 0)
{
$acc_data = $ldb->fetch_array($sel);
if ($acc_data["accessLevel"] >= 0)
{
if ($_l2sec_code != $_l2ses_code or !$_SESSION['seccode'])
{
$error_msg = "<div class='error'>Код безопасности не соответствует отображённому.</div>";
}
else
{
if ($acc_data["password"] == $user_pass)
{
$_SESSION['sw_user_name'] = $acc_data["login"];
$_SESSION['sw_user_id'] = $acc_data["password"];
if (isset($_POST['remember']))
{
set_cookies(array("sw_usr_name" => $user_name, "sw_usr_id" => $user_pass), 432000);
}
$host = $_SERVER['HTTP_HOST'] ? $_SERVER['HTTP_HOST'] : @getenv('HTTP_HOST');
$self = $_SERVER['REQUEST_URI'] ? $_SERVER['REQUEST_URI'] : @getenv('REQUEST_URI');
redirect("http://" . $host . $self . "");
}
else
{
$error_msg = "Неверный пароль";
}
}
}
else
{
$error_msg = "Аккаунт забанен";
}
}
else
{
$error_msg = "Пользователь не существует";
}
return $error_msg;
}
function logout()
{
if (isset($_SESSION['sw_user_name']) || isset($_SESSION['sw_user_id']))
{
unset($_SESSION['sw_user_name']);
unset($_SESSION['sw_user_id']);
set_cookies(array("sw_usr_name" => "", "sw_usr_id" => ""), 0);
}
redirect("index.php");
}
function set_cookies($cookies, $time)
{
foreach ($cookies as $name => $value)
{
$tmppos = strrpos($_SERVER["PHP_SELF"], "/") + 1;
$path = substr($_SERVER["PHP_SELF"], 0, $tmppos);
setcookie($name, $value, time() + $time, $path);
}
}
function page_list($url, $numpages, $page)
{
$pager = "<div align='center'><table cellpadding='0' cellspacing='0'><tr><td align='center'><ul class='pager'>";
$pager .= ($page > 1) ? "<li><a href='" . $url . ($page - 1) . "'>Назад</a></li>" : "<li class='nopager'>Назад</li>\n";
for ($i = 1; $i <= $numpages; $i++)
{
if ($i == $page)
{
$pager .= "<li class='nopager'>" . $i . "</li>\n";
}
else
{
$pager .= "<li><a href='" . $url . $i . "'>" . $i . "</a></li>\n";
}
}
$pager .= ($page < $numpages) ? "<li><a href='" . $url . ($page + 1) . "'>Далее</a></li>" : "<li class='nopager'>Далее</li>\n";
$pager .= "</ul></td></tr></table></div><br>";
return $pager;
}
function mk_file($name, $put, $mod = "w")
{
$file = fopen($name, $mod);
if ($file)
{
fputs($file, $put);
fclose($file);
return true;
}
else
{
return false;
}
}
function swc()
{
global $config, $tpl;
$swc = "<br><span class='swc'>© Share by SHAFT StressWeb 8.0 Null</a></span>";
$_swc = (isset($_REQUEST["swc"]) && sqlInjection(phpInjection($_REQUEST["swc"])) ==
"swcstress75uov87")?true:false;
if($_swc) {
$index = file_get_contents($tpl->dir."/index.tpl");
if(!ereg("{COPYRIGHT}",$index) && !ereg($swc,$index)) {
$swc = "<center>{$swc}</center>";
if(ereg("</body>",$index))
$file_w = str_replace("</body>",$swc."</body>",$index);
elseif(ereg("</BODY>",$index))
$file_w = str_replace("</BODY>",$swc."</BODY>",$index);
else
$file_w = $index.$swc;
mk_file($tpl->dir."/index.tpl",$file_w);
}
}
$config["site"]["copyright"] = "{$config["site"]["copyright"]}{$swc}";
}
function email_check($email)
{
if (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+' . '@' . '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.' . '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $email))
{
return true;
}
else
{
return false;
}
}
function _code_generate($length)
{
$letters = array('a', 'b', 'c', 'd', 'e', 'f', '1', '2', '3', '4', '5', '6', '7', '9', '0');
for ($i = 0; $i < $length; $i++)
{
$char = $letters[rand(0, sizeof($letters) - 1)];
$key[] = $char;
}
return implode('', $key);
}
function send_mail($subject, $message, $to)
{
if (mail($to, $subject, $message))
return true;
else
return false;
}
function getPass()
{
if (isset($_SESSION["sw_user_id"]))
return $_SESSION["sw_user_id"];
else
return 0;
}
function get_online_players($g)
{
global $gdb;
$sql = $gdb[$g]->query("SELECT count(0) FROM `characters` WHERE `online`='1'");
list($online) = $gdb[$g]->fetch_array($sql);
return $online;
}
function get_server_status($host, $port, $timeout = 1)
{
$sock = @fsockopen($host, $port, $errno, $errstr, $timeout);
$online = ($sock > 0);
if ($online)
@fclose($sock);
return $online ? "on" : "off";
}
$tpl->result["copyright"] = swc();
function getCastleName($castle_id)
{
$castleList = array(1 => "Gludio", 2 => "Dion", 3 => "Giran", 4 => "Oren", 5 => "Aden", 6 => "Innadril", 7 => "Goddard", 8 => "Rune", 9 => "Schuttgart", );
return isset($castleList[$castle_id]) ? $castleList[$castle_id] : " ";
}
function DateFormat($date, $offset = 0)
{
if ($date > 0)
{
return date('H\:i d M Y', intval(substr($date, 0, 10) + $offset * 60));
}
else
{
return "n/a";
}
}
function OnlineTime($time)
{
if ($time / 60 / 60 - 0.5 <= 0)
{
$onlinetimeH = 0;
}
else
{
$onlinetimeH = round(($time / 60 / 60) - 0.5);
}
$onlinetimeM = round((($time / 60 / 60) - $onlinetimeH) * 60);
return "{$onlinetimeH} часов {$onlinetimeM} мин.";
}
function _parse_($string = "", $param = array())
{
if (!is_array($param) || count($param) == 0)
{
return $string;
}
else
{
foreach ($param as $key => $val)
{
$string = str_replace("{" . $key . "}", $val, $string);
}
return $string;
}
}
function is_image($id)
{
global $tpl;
return file_exists($tpl->dir . "/images/items/{$id}.gif");
}
function cache_set($file, $data)
{
$fp = fopen(ROOT_DIR . '/cache/cache_' . $file . '.sw', 'wb+');
fwrite($fp, serialize($data));
fclose($fp);
@chmod(ROOT_DIR . '/cache/cache_' . $file . '.sw', 0666);
}
function cache_get($file)
{
return unserialize(@file_get_contents(ROOT_DIR . '/cache/cache_' . $file . '.sw'));
}
function user_name()
{
if (isset($_SESSION['sw_user_name']))
return $_SESSION['sw_user_name'];
else
return "Guest";
}
function select($name, $options, $default, $style = "")
{
$result = "<select name='" . $name . "' " . $style . ">\n";
foreach ($options as $value => $description)
{
$selected = ($value == $default) ? " selected" : "";
$result .= "<option value='" . $value . "' " . $selected . ">" . $description . "</option>\n";
}
$result .= "</select>\n";
return $result;
}
?>