battles/enter.php

68 lines
2.8 KiB
PHP
Raw Normal View History

2018-01-28 16:40:49 +00:00
<?php
session_start();
include("config.php");
2019-03-28 15:02:04 +00:00
foreach ($_POST as $key => $val) { //Проверка всех значений массива POST одним махом.
2018-01-28 16:40:49 +00:00
$_POST[$key] = iconv(mb_detect_encoding($_POST[$key], 'auto'), 'utf-8', $val);
}
$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_SPECIAL_CHARS);
2020-06-23 08:49:49 +00:00
$password = $_POST['password'] ?? '';
$battle = $_COOKIE['battle'] ?? '';
2018-01-28 16:40:49 +00:00
$error = "";
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
if (!$data['id']) {
$error = 'Ой! Такого пользователя нет!';
} elseif ($data['block'] == 1) {
$error = 'Ой! Вы заблокированы!';
} elseif (password_verify($password, $data['pass'])) {
2018-01-28 16:40:49 +00:00
if (!$error) {
2018-12-11 17:40:12 +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"', $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
db::c()->query('UPDATE `users` SET `sid` = "?s", `enter_game` = ?i WHERE `id` = ?i', session_id(), 1, $data['id']);
2018-01-28 16:40:49 +00:00
2019-02-12 14:40:53 +00:00
$sms = db::c()->query('SELECT * FROM `telegraph` WHERE `receiver` = ?i', $data['id']);
while ($res = $sms->fetch_assoc()) {
2019-02-15 22:35:49 +00:00
db::c()->query('INSERT INTO `chat` (`touid`, `msg`, `type`) VALUES (?i, "?s", "?s")', $res['receiver'], $res['text'], 'sms');
}
db::c()->query('DELETE FROM `telegraph` WHERE `receiver` = ?i', $data['id']);
header("Location: fight.php");
}
2018-01-28 16:40:49 +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>
<?php endif; ?>
2018-01-28 16:40:49 +00:00
</body>
</html>