2018-01-28 16:40:49 +00:00
|
|
|
<?php
|
|
|
|
session_start();
|
|
|
|
include("config.php");
|
|
|
|
|
|
|
|
foreach ($_POST as $key => $val) { //???????????????
|
|
|
|
$_POST[$key] = iconv(mb_detect_encoding($_POST[$key], 'auto'), 'utf-8', $val);
|
|
|
|
}
|
|
|
|
|
|
|
|
$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_SPECIAL_CHARS);
|
2018-03-06 13:08:21 +00:00
|
|
|
$password = filter_input(INPUT_POST, 'password');
|
2018-01-28 16:40:49 +00:00
|
|
|
$battle = filter_input(INPUT_COOKIE, 'battle');
|
|
|
|
$error = "";
|
|
|
|
|
2018-03-05 18:02:24 +00:00
|
|
|
if ($username && $password) {
|
2018-03-06 13:10:04 +00:00
|
|
|
$data = db::c()->query('SELECT `id`, `login` ,`pass`, `room`, `block` FROM `users` WHERE `login` = "?s"', $username)->fetch_assoc();
|
2018-01-28 16:40:49 +00:00
|
|
|
|
2018-03-05 18:02:24 +00:00
|
|
|
if (!$data['id']) {
|
2018-03-06 13:08:21 +00:00
|
|
|
$error = 'Ой! Такого пользователя нет!';
|
2018-03-05 18:02:24 +00:00
|
|
|
} elseif ($data['block'] == 1) {
|
2018-03-06 13:08:21 +00:00
|
|
|
$error = 'Ой! Вы заблокированы!';
|
2018-03-05 18:02:24 +00:00
|
|
|
} elseif (password_verify($password, $data['pass'])) {
|
2018-01-28 16:40:49 +00:00
|
|
|
|
2018-03-05 18:02:24 +00:00
|
|
|
if (!$error) {
|
2018-12-11 17:40:12 +00:00
|
|
|
# Проверка на мультоводство по используемому кукису.
|
2018-03-05 18:02:24 +00:00
|
|
|
if ($battle != null && $data['id'] != $battle) {
|
|
|
|
db::c()->query('INSERT INTO `delo_multi` (`idperslater`, `idpersnow`) VALUES (?i, ?i)', $battle, $data['id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
setcookie("battle", $data['id']);
|
|
|
|
$_SESSION['uid'] = $data['id'];
|
|
|
|
setcookie("uid", $data['id'], time() + 43200, "/", GAMEDOMAIN);
|
|
|
|
setcookie("hashcode", md5($data['id'] . $data["pass"] . $data["login"]), time() + 43200, "/", GAMEDOMAIN);
|
|
|
|
$_SESSION['sid'] = session_id();
|
|
|
|
|
|
|
|
$onl = db::c()->query('SELECT `id` FROM `online` WHERE `id` = "?s" LIMIT 1', $data['id'])->fetch_assoc();
|
|
|
|
if (isset($onl['id'])) {
|
|
|
|
db::c()->query('UPDATE `online` SET `date` = ?i WHERE `id` = "?s"', time(), $data['id']);
|
|
|
|
} else {
|
|
|
|
db::c()->query('INSERT INTO `online` (`id`, `date`, `room`) VALUES (?i, ?i, ?i)', $data['id'], time(), $data['room']);
|
|
|
|
}
|
2018-01-28 16:40:49 +00:00
|
|
|
|
2018-03-05 18:02:24 +00:00
|
|
|
db::c()->query('UPDATE `users` SET `sid` = "?s", `enter_game` = ?i WHERE `id` = ?i LIMIT 1', session_id(), 1, $data['id']);
|
|
|
|
$_SESSION['sid'] = session_id();
|
2018-01-28 16:40:49 +00:00
|
|
|
|
2018-03-05 18:02:24 +00:00
|
|
|
//TODO Лог IP адресов планировался удаляться из проекта.
|
|
|
|
$ip = $_SERVER['REMOTE_ADDR'];
|
|
|
|
db::c()->query('INSERT INTO `iplog` (`owner`, `ip`, `date`) VALUES (?i, "?s", ?i)', $data['id'], $ip, time());
|
|
|
|
|
2018-06-23 20:14:33 +00:00
|
|
|
$rs = db::c()->query('SELECT * FROM `telegraph` WHERE `receiver` = ?i', $data['id']);
|
2018-03-05 18:02:24 +00:00
|
|
|
while ($res = $rs->fetch_assoc()) {
|
|
|
|
addchp($res['text'], '{[]}' . $data['login'] . '{[]}');
|
|
|
|
}
|
2018-06-23 20:14:33 +00:00
|
|
|
db::c()->query('DELETE FROM `telegraph` WHERE `receiver` = ?i', $data['id']);
|
2018-03-05 18:02:24 +00:00
|
|
|
header("Location: fight.php");
|
|
|
|
}
|
2018-01-28 16:40:49 +00:00
|
|
|
}
|
2018-03-05 18:02:24 +00:00
|
|
|
}
|
2018-01-28 16:40:49 +00:00
|
|
|
|
2018-03-05 18:02:24 +00:00
|
|
|
/**
|
|
|
|
* Обновляем пароли пользователей...
|
|
|
|
*/
|
2018-01-28 16:40:49 +00:00
|
|
|
|
2018-03-05 18:02:24 +00:00
|
|
|
$username_upd = filter_input(INPUT_POST, 'username_upd', FILTER_SANITIZE_SPECIAL_CHARS);
|
|
|
|
$password_upd = filter_input(INPUT_POST, 'password_upd');
|
2018-01-28 16:40:49 +00:00
|
|
|
|
2018-03-05 18:02:24 +00:00
|
|
|
if ($username_upd && $password_upd) {
|
2018-03-06 12:34:57 +00:00
|
|
|
$data = db::c()->query('SELECT `id`, `login` ,`pass`, `room`, `block` FROM `users` WHERE `login` = "?s" AND `pass` = "?s"', $username_upd, md5($password_upd))->fetch_assoc();
|
|
|
|
if ($data['id']) {
|
2018-03-06 13:00:07 +00:00
|
|
|
db::c()->query('UPDATE `users` SET `pass` = "?s" WHERE `login` = "?s"', password_hash($password_upd, PASSWORD_DEFAULT), $username_upd);
|
|
|
|
header("Location: index.php");
|
2018-03-06 12:34:57 +00:00
|
|
|
} else {
|
2018-03-06 13:11:39 +00:00
|
|
|
$error = 'Ошибка!';
|
2018-01-28 16:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-05 18:02:24 +00:00
|
|
|
|
2018-01-28 16:40:49 +00:00
|
|
|
?>
|
|
|
|
|
|
|
|
<!doctype html>
|
|
|
|
<html lang="ru-RU">
|
|
|
|
<head>
|
|
|
|
<meta charset=UTF-8">
|
|
|
|
<link href="css/main.css" rel="stylesheet">
|
|
|
|
<title>Входим...</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<?php if (!empty($error)): ?>
|
|
|
|
<a href="/"> ← на главную</a>
|
|
|
|
<h1><?php echo $error; ?></h1>
|
|
|
|
<? endif; ?>
|
|
|
|
</body>
|
|
|
|
</html>
|