diff --git a/zayavka.php b/zayavka.php index 9149200..0141cbf 100644 --- a/zayavka.php +++ b/zayavka.php @@ -1,13 +1,14 @@ battle != 0) { header('Location: fbattle.php'); - die(); + exit; } db::c()->query('LOCK TABLES `bots` WRITE, `battle` WRITE, `logs` WRITE, `users` WRITE, `inventory` WRITE, `zayavka` WRITE, `effects` WRITE, `online` WRITE, `clans` WRITE'); @@ -16,7 +17,7 @@ if ($do == "clear" && $user->admin == 1) { db::c()->query('UPDATE `zayavka` SET `coment` = "?s" WHERE `id` = ?i', 'Вырезано цензурой!', $_GET['zid']); } -if (!empty($_GET['del']) && $user['admin'] == 1) { //удаление заявки на бой. +if (!empty($_GET['del']) && $user->admin == 1) { //удаление заявки на бой. $zayavka = db::c()->query('SELECT `id` FROM `zayavka` WHERE `id` = ?i', $_GET['zid'])->fetch_assoc(); if (isset($zayavka['id'])) { db::c()->query('UPDATE `users` SET `zayavka` = 0 WHERE `zayavka` = ?i', $zayavka['id']); @@ -26,16 +27,20 @@ if (!empty($_GET['del']) && $user['admin'] == 1) { //удаление заявк } } $_SESSION['view'] = false; -if (isset($_REQUEST['view'])) $_SESSION['view'] = $_REQUEST['view']; +if (isset($_REQUEST['view'])) { + $_SESSION['view'] = $_REQUEST['view']; +} -class zayavka +class Zayavka { - var $mysql; + /** + * @var string + */ + private $errorMessage; - function __construct() + function __construct($user_id) { - global $mysql; - $this->mysql = $mysql; + } function fteam($team) @@ -53,7 +58,7 @@ class zayavka * @return mixed * @throws \Krugozor\Database\Mysql\Exception */ - function getlist($razdel = 4, $level = null, $id = null) + public function getlist($razdel = 4, $level = null, $id = null) { $sql = db::c()->prepare('SELECT * FROM `zayavka` WHERE `level` = ?i', $razdel); if (!is_null($level)) { @@ -86,65 +91,71 @@ class zayavka return $zay; } - function addteam($team, $r) + public function addteam($team, $r) { global $user; $id = $_SESSION['uid']; $zay = $_REQUEST['gocombat']; + $error = null; $owntravma = db::c()->query('SELECT `id`, `type` FROM `effects` WHERE (`type` = 12 OR `type` = 13) AND `owner` = ?i', $id)->fetch_assoc(); $z = $this->getlist($r, null, $zay); - if ($owntravma) { - switch ($owntravma['type']) { - case ($owntravma['type'] == 12 && ($z[$zay]['type'] != 4 && $z[$zay]['type'] != 5)): - return "У Вас средняя травма, поединки с оружием слишком тяжелы для Вас..."; - break; - case 13: - return "У Вас тяжелая травма, Вы не сможете драться..."; - break; - } + if ($owntravma['type'] == 12 && ($z[$zay]['type'] != 4 && $z[$zay]['type'] != 5)) { + $this->errorMessage = "У Вас средняя травма, поединки с оружием слишком тяжелы для Вас..."; + } elseif ($owntravma['type'] == 13) { + $this->errorMessage = "У Вас тяжелая травма, Вы не сможете драться..."; } - - if (!empty($user['zayavka'])) return "Вы находитесь в заявке"; - - if ($user['hp'] < $user['maxhp'] * 0.33) return "Вы слишком ослаблены для боя, восстановитесь."; - - if (!$z) return "Эта заявка не может быть принята Вами."; - - if ($this->user_status($id) != 0) return "Эта заявка не может быть принята Вами."; - - if ($z[$zay]['type'] != 3 OR $z[$zay]['type'] != 5) { - if ($team == 1) $teamz = 2; - else $teamz = 1; + if (!empty($user['zayavka'])) { + $this->errorMessage = "Вы находитесь в заявке"; + } + if ($user['hp'] < $user['maxhp'] * 0.33) { + $this->errorMessage = "Вы слишком ослаблены для боя, восстановитесь."; + } + if (!$z || !empty($this->user_status($id))) { + $this->errorMessage = "Эта заявка не может быть принята Вами."; + } + if ($z[$zay]['type'] != 3 || $z[$zay]['type'] != 5) { + if ($team == 1) { + $teamz = 2; + } else { + $teamz = 1; + } foreach ($z[$zay]['team' . $teamz] as $v) { $enemy = db::c()->query('SELECT `klan` FROM `users` WHERE `id` = ?i', $v)->fetch_assoc(); - if ($user['klan'] == $enemy['klan']) return "Нельзя драться против сокланов!"; + if ($user['klan'] == $enemy['klan']) { + $this->errorMessage = "Нельзя драться против сокланов!"; + } } } if ($z[$zay]['t' . $team . 'min'] == 99) { $toper = db::c()->query('SELECT `klan` FROM `users` WHERE `id` = ?i', $z[$zay]['team' . $team][0])->fetch_assoc(); - if ($user['klan'] != $toper['klan']) return "Эта заявка не может быть принята Вами."; + if ($user['klan'] != $toper['klan']) { + $this->errorMessage = "Эта заявка не может быть принята Вами."; + } } else { if ($user['level'] > 0 && !($z[$zay]['t' . $team . 'min'] <= $user['level'] && $z[$zay]['t' . $team . 'max'] >= $user['level'])) { - return "Эта заявка не может быть принята Вами. - " . $z[$zay]['t' . $team . 'min']; + $this->errorMessage = "Эта заявка не может быть принята Вами. - " . $z[$zay]['t' . $team . 'min']; } } if (count($z[$zay]['team' . $team]) >= $z[$zay]['t' . $team . 'c']) { - return "Группа уже набрана."; + $this->errorMessage = "Группа уже набрана."; } $z[$zay]['team' . $team][] = ''; - if (mysql_query("UPDATE `users`, `zayavka` SET `users`.`zayavka` = {$zay}, `zayavka`.`team{$team}` = '" . implode(";", $z[$zay]['team' . $team]) . "" . $id . ";' WHERE `users`.`id` = {$id} AND `users`.`zayavka` = 0 AND `zayavka`.`id` = {$zay}")) { + if ($this->errorMessage) { + return $this->errorMessage; + } else { + mysql_query("UPDATE `users`, `zayavka` SET `users`.`zayavka` = {$zay}, `zayavka`.`team{$team}` = '" . implode(";", $z[$zay]['team' . $team]) . "" . $id . ";' WHERE `users`.`id` = {$id} AND `users`.`zayavka` = 0 AND `zayavka`.`id` = {$zay}"); return "Вы приняли заявку на бой."; - } else return 'addteam(): database error!'; + } } - function delteam($id, $zay, $r) + public function delteam($id, $zay, $r) { $z = $this->getlist($r, null, $zay); if ($z[$zay]['level'] > 3 || $z[$zay]['level'] == null) { - return "Ай-ай-ай!"; + $this->errorMessage = 'Неизвестная ошибка.'; } foreach ($z[$zay]['team2'] as $v) { @@ -152,73 +163,85 @@ class zayavka $teams[] = $v; } } - - if (mysql_query("UPDATE `users`, `zayavka` SET `users`.`zayavka` = '0', `zayavka`.`team{$team}` = '{$teams}' WHERE `users`.`id` = {$id} AND `zayavka`.`id` = {$zay};")) { + if ($this->errorMessage) { + return $this->errorMessage; + } else { + mysql_query("UPDATE `users`, `zayavka` SET `users`.`zayavka` = '0', `zayavka`.`team{$team}` = '{$teams}' WHERE `users`.`id` = {$id} AND `zayavka`.`id` = {$zay};"); return "Вы отозвали запрос"; - } else return 'delteam(): database error!'; + } } - function addzayavka($start, $timeout, $t1c, $t2c, $type, $t1min, $t2min, $t1max, $t2max, $coment, $level, $blood = 0) + public function addzayavka($start, $timeout, $t1c, $t2c, $type, $t1min, $t2min, $t1max, $t2max, $coment, $level, $blood = 0) { global $user; - if (!in_array($level, [2, 4, 5])) $level = 4; /*2-физ, 4-группа, 5-хаос*/ - - if ($level == 2 AND $type != 1 AND $type != 4 AND $type != 6) $type = 1; - if ($level == 4 AND $type != 2 AND $type != 4) $type = 2; - if ($level == 5 AND $type != 3 AND $type != 5) $type = 3; - - if (!in_array($start, [1, 3, 5, 10, 15, 30, 60])) $start = 1; - if (!in_array($timeout, [1, 3, 5, 10])) $timeout = 1; - - if ($this->user_status($user['id']) != 0) exit(); + if (!in_array($level, [2, 4, 5])) { + $level = 4; + } /*2-физ, 4-группа, 5-хаос*/ + if ($level == 2 && $type != 1 && $type != 4 && $type != 6) { + $type = 1; + } + if ($level == 4 && $type != 2 && $type != 4) { + $type = 2; + } + if ($level == 5 && $type != 3 && $type != 5) { + $type = 3; + } + if (!in_array($start, [1, 3, 5, 10, 15, 30, 60])) { + $start = 1; + } + if (!in_array($timeout, [1, 3, 5, 10])) { + $timeout = 1; + } + if ($this->user_status($user['id']) != 0) { + exit(); + } if (!$user['klan'] && $t1min == 99) { - return "Вы не состоите в клане."; + $this->errorMessage = "Вы не состоите в клане."; } if ($user['hp'] < $user['maxhp'] * 0.33) { - return "Вы слишком ослаблены для боя, восстановитесь."; + $this->errorMessage = "Вы слишком ослаблены для боя, восстановитесь."; } + if ($this->errorMessage) { + return $this->errorMessage; + } else { + if ($type == 3) { + AddChatSystem('Внимание! Подана заявка на хаотический поединок ({$t1min} - {$t1max}), который начнется через {$start} минут.'); + } + $start = time() + $start * 60; - if ($type == 3) { - AddChatSystem('Внимание! Подана заявка на хаотический поединок ({$t1min} - {$t1max}), который начнется через {$start} минут.'); - } - - $start = time() + $start * 60; - - db::c()->query('INSERT INTO `zayavka` + db::c()->query('INSERT INTO `zayavka` (`start`, `timeout`, `t1c`, `t2c`, `type`, `level`, `coment`, `team1`, `t1min`, `t2min`, `t1max`, `t2max`,`podan`,`blood`) VALUES (?i,?i,?i,?i,?i,?i,"?s","?s",?d,?i,?i,?i,?i,"?s",?i)', - $start, $timeout, $t1c, $t2c, $type, $level, $coment, $user['id'], $t1min, $t2min, $t1max, $t2max, date('H:i'), $blood); - db::c()->query('UPDATE `users` SET `zayavka` = ?i WHERE `id` = ?i', db::c()->getLastInsertId(), $user['id']); - - return null; + $start, $timeout, $t1c, $t2c, $type, $level, $coment, $user['id'], $t1min, $t2min, $t1max, $t2max, date('H:i'), $blood); + db::c()->query('UPDATE `users` SET `zayavka` = ?i WHERE `id` = ?i', db::c()->getLastInsertId(), $user['id']); + return 'Заявка подана!'; + } } - function delzayavka($id, $zay, $r, $f = 1) + public function delzayavka($id, $zay, $r, $f = 1) { $z = $this->getlist($r, null, $zay); - if ($f != 1) { - if ($z[$zay]['level'] > 3) { - return 'Ай-ай-ай!'; - } - } - - if (mysql_query("DELETE FROM `zayavka` WHERE `id` = {$zay} AND (`team1` LIKE '{$id};%' OR `team2` LIKE '{$id};%') LIMIT 1")) { + if ($f != 1 && $z[$zay]['level'] > 3) { + return 'Неизвестная ошибка.'; + } else { + mysql_query("DELETE FROM `zayavka` WHERE `id` = {$zay} AND (`team1` LIKE '{$id};%' OR `team2` LIKE '{$id};%') LIMIT 1"); if (count($z[$zay]['team1']) > 0) { - foreach ($z[$zay]['team1'] as $k => $v) + foreach ($z[$zay]['team1'] as $k => $v) { db::c()->query('UPDATE `users` SET `zayavka` = 0 WHERE `id` = ?i', $v); + } } - if (count($z[$zay]['team2']) > 0) { - foreach ($z[$zay]['team2'] as $k => $v) + foreach ($z[$zay]['team2'] as $k => $v) { db::c()->query('UPDATE `users` SET `zayavka` = 0 WHERE `id` = ?i', $v); + } } return 'Вы отозвали заявку.'; - } else return 'delzayavka(): database error!'; + } } - function showfiz($row) + public function showfiz($row) { global $user; $rr = "{$row['podan']} "; @@ -246,7 +269,7 @@ class zayavka return $rr; } - function showgroup($row) + public function showgroup($row) { if ($row['t1min'] == 99) { $range1 = "клан"; @@ -308,7 +331,7 @@ class zayavka return $rr; } - function showhaos($row) + public function showhaos($row) { global $user; $rr = "{$row['podan']} ("; @@ -367,7 +390,7 @@ class zayavka return $rr; } - function user_status($id) + public function user_status($id) { $r = db::c()->query('SELECT `team1`,`team2` FROM `zayavka`, `users` WHERE `users`.`id` = ?i AND `zayavka`.`id` = `users`.`zayavka`', $id)->fetch_assoc(); $t1 = $this->fteam($r['team1']); @@ -381,7 +404,7 @@ class zayavka } } - function battlestart($id, $zay, $r) + public function battlestart($id, $zay, $r) { global $user; $z = $this->getlist($r, null, $zay); @@ -470,7 +493,7 @@ class zayavka } } - while (count($cost) > 0) { + while (!empty($cost)) { if ($power1 <= $power2) { $tmp = array_shift($cost); $power1 += $tmp[1]; @@ -509,7 +532,9 @@ class zayavka die(); } - if (!in_array($z['timeout'], [3, 4, 5, 7, 10])) $z['timeout'] = 3; + if (!in_array($z['timeout'], [3, 4, 5, 7, 10])) { + $z['timeout'] = 3; + } if (count($teams) > 1) { if ($z['type'] == 1 || $z['type'] == 4) { @@ -576,7 +601,7 @@ VALUES ("?s","?s",?i,?i,?i,"?s","?s",?i,?i,?i,?i)', } } -$zay = new zayavka; +$zay = new Zayavka; header("Cache-Control: no-cache"); if (!empty($_POST['open'])) { $f = fopen("/tmp/zayavka/" . $user['id'] . ".txt", "w+"); @@ -609,7 +634,9 @@ if (!empty($_POST['open'])) {
- battle();} ?> + battle(); + } ?> | @@ -629,8 +656,12 @@ if (!empty($_POST['open'])) { |
Выберите раздел';
+ if ($user->room != 1 && $get != 'current') {
+ exit('В этой комнате невозможно подавать заявки!');
+ }
+ if (!$get) {
+ echo ' Выберите раздел '; + } if ($get == 'fiz') { echo ""; @@ -657,7 +688,7 @@ if (!empty($_POST['open'])) { echo $zay->delteam($z[$user['zayavka']]['team2'][0], $user['zayavka'], 2); AddChatSystem('Внимание!' . Nick::id($user['id'])->short() . ' отказался от поединка.'); } - if (!empty($_POST['confirm2']) AND empty($user['zayavka'])) { + if (!empty($_POST['confirm2']) && empty($user['zayavka'])) { $z = $zay->getlist(2, null, $_REQUEST['gocombat']); $toper = db::c()->query('SELECT `klan` FROM `users` WHERE `id` = ?i', $z[$_REQUEST['gocombat']]['team1'][0])->fetch_assoc(); if ($user['klan'] != $toper['klan'] || $user['klan'] == '') { @@ -740,16 +771,16 @@ if (!empty($_POST['open'])) { } } } - if ($zay->user_status($user['id']) == 2) { - if ($z[$user['zayavka']]['level'] == 2) - echo "Ожидаем подтверждения боя. "; + if ($zay->user_status($user['id']) == 2 && $z[$user['zayavka']]['level'] == 2) { + echo "Ожидаем подтверждения боя. "; } echo ' |