dev #34

Merged
lopar merged 2 commits from dev into master 2021-01-27 15:59:15 +00:00
2 changed files with 33 additions and 23 deletions
Showing only changes of commit 4701e4b542 - Show all commits

View File

@ -1,6 +1,9 @@
<?php
namespace Battles;
use Exceptions\GameException;
use db;
class User
{
@ -53,7 +56,7 @@ class User
public function __construct($user)
{
$user_query = \db::c()->query('SELECT * FROM users WHERE id = "?s" OR login = "?s"', $user, $user)->fetch_assoc();
$user_query = db::c()->query('SELECT * FROM users WHERE id = "?s" OR login = "?s"', $user, $user)->fetch_assoc();
foreach ($this as $key => $value) {
if (isset($user_query[$key])) {
$this->$key = $user_query[$key];
@ -80,7 +83,7 @@ class User
return $this->$stat_name;
}
} else {
throw new \Exceptions\GameException(self::ERROR_STAT_UNKNOWN);
throw new GameException(self::ERROR_STAT_UNKNOWN);
}
}
@ -95,12 +98,12 @@ class User
if (in_array($stat_name, $allowed)) {
if ($this->free_stat_points > 0 && $this->$stat_name <= self::STAT_MAXIMUM_AMOUNT) {
$query = 'UPDATE users SET ?f = ?f + 1, free_stat_points = free_stat_points - 1 WHERE id = ?i';
\db::c()->query($query, $stat_name, $stat_name, $this->id);
db::c()->query($query, $stat_name, $stat_name, $this->id);
} else {
throw new \Exceptions\GameException(self::ERROR_STAT_IS_MAXIMUM);
throw new GameException(self::ERROR_STAT_IS_MAXIMUM);
}
} else {
throw new \Exceptions\GameException(self::ERROR_STAT_UNKNOWN);
throw new GameException(self::ERROR_STAT_UNKNOWN);
}
}

View File

@ -1,4 +1,7 @@
<?php
use Battles\Template;
session_start();
require_once "config.php";
if ($_COOKIE[GAMEDOMAIN] ?? null) {
@ -15,25 +18,29 @@ if ($_COOKIE[GAMEDOMAIN] ?? null) {
$ip = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP);
if ($login && $password && $email && $birthday && $law && $law2) {
$check = db::c()->query('SELECT 1 FROM `users` WHERE `login` = "?s" OR `email` = "?s"', $login, $email)->getNumRows();
if ($check > 0) {
$error = "В системе уже есть такие данные!";
} else {
db::c()->query('INSERT INTO users (login,pass,email,borndate,ip,session_id)
VALUES ("?s", "?s", "?s", "?s", "?s", "?s")', $login, $password, $email, $birthday, $ip, session_id());
$nid = db::c()->getLastInsertId();
db::c()->query('INSERT INTO `online` (user_id, date, room, real_time) VALUES (?i, ?i, ?i, ?i)', $nid, time(), 1, time());
db::c()->query('INSERT INTO `bank` (`user_id`) VALUES (?i)', $nid, 5);
setcookie(GAMEDOMAIN, $nid, time() + 3600);
$newUser = new class {
public static function addUser(string $login, string $password, string $email, string $birthday): bool
{
if (db::c()->query('SELECT 1 FROM `users` WHERE `login` = "?s" OR `email` = "?s"', $login, $email)->getNumRows()) {
return false;
}
db::c()->query('INSERT INTO users (login,pass,email,borndate,ip,session_id,shadow)
VALUES ("?s", "?s", "?s", "?s", "?s", "?s", "?s")', $login, $password, $email, $birthday, $_SERVER['REMOTE_ADDR'], session_id(), '0.gif');
db::c()->query('INSERT INTO `online` (user_id, date, room, real_time) VALUES (?i, ?i, ?i, ?i)', db::c()->getLastInsertId(), time(), 1, time());
db::c()->query('INSERT INTO `bank` (user_id) VALUES (?i)', db::c()->getLastInsertId());
setcookie(GAMEDOMAIN, db::c()->getLastInsertId(), time() + 3600);
setcookie("battle", time());
$_SESSION['uid'] = $nid;
$_SESSION['uid'] = db::c()->getLastInsertId();
$_SESSION['sid'] = session_id();
return true;
}
};
$newUser::addUser($login, $password, $email, $birthday);
header('Location: fight.php');
exit;
}
}
}
\Battles\Template::header('Регистрация персонажа');
Template::header('Регистрация персонажа');
?>
<a href="/"> на главную</a>
<?php if ($error ?? null): ?>