2019-06-21 10:22:26 +00:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Copyright (c) 2018.
|
|
|
|
|
* Author: Igor Barkov <lopar.4ever@gmail.com>
|
|
|
|
|
* Project name: Battles-Game
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
session_start();
|
2020-09-30 12:58:44 +00:00
|
|
|
|
if (empty($_SESSION['uid'])) header("Location: index.php");
|
2019-06-21 10:22:26 +00:00
|
|
|
|
//include("config.php");
|
|
|
|
|
|
|
|
|
|
//$msg = filter_input(INPUT_POST,'msg');
|
|
|
|
|
//$uid = $_SESSION['uid'];
|
|
|
|
|
//if ($msg) db::c()->query('INSERT INTO `chat` (`cid`, `uid`, `msg`) VALUES (?i, ?i, "?s")', 1, $uid, $msg);
|
2020-09-30 14:54:44 +00:00
|
|
|
|
Template::header('Окно игры');
|
2019-06-21 10:22:26 +00:00
|
|
|
|
?>
|
2020-09-30 14:54:44 +00:00
|
|
|
|
<style>
|
|
|
|
|
form {
|
|
|
|
|
width: 100%;
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
2019-06-21 10:22:26 +00:00
|
|
|
|
|
2020-09-30 14:54:44 +00:00
|
|
|
|
form input {
|
|
|
|
|
border: 1px solid silver;
|
|
|
|
|
width: 80%;
|
|
|
|
|
margin-right: .5%;
|
|
|
|
|
}
|
2019-06-21 10:22:26 +00:00
|
|
|
|
|
2020-09-30 14:54:44 +00:00
|
|
|
|
form input[type="submit"] {
|
|
|
|
|
width: 15%;
|
|
|
|
|
}
|
2019-06-21 10:22:26 +00:00
|
|
|
|
|
2020-09-30 14:54:44 +00:00
|
|
|
|
body {
|
|
|
|
|
margin: 0;
|
|
|
|
|
}
|
2019-06-21 10:22:26 +00:00
|
|
|
|
|
2020-09-30 14:54:44 +00:00
|
|
|
|
.wrap {
|
|
|
|
|
display: grid;
|
|
|
|
|
height: 100vh;
|
|
|
|
|
grid-template-rows: 45px /* Шапка */ 2fr /* Окно игры */ 1fr /* Окно чата*/ 30px; /* Подвал */
|
|
|
|
|
}
|
2019-06-21 10:22:26 +00:00
|
|
|
|
|
2020-09-30 14:54:44 +00:00
|
|
|
|
header {
|
|
|
|
|
text-align: right;
|
|
|
|
|
box-shadow: 0 3px 2px -2px slategray;
|
|
|
|
|
}
|
2019-06-21 10:22:26 +00:00
|
|
|
|
|
2020-09-30 14:54:44 +00:00
|
|
|
|
footer {
|
|
|
|
|
margin: 5px;
|
|
|
|
|
}
|
2019-06-21 10:22:26 +00:00
|
|
|
|
|
2020-09-30 14:54:44 +00:00
|
|
|
|
#game, #chat {
|
|
|
|
|
overflow: auto;
|
|
|
|
|
box-shadow: 0 3px 2px -2px slategray;
|
|
|
|
|
padding: 5px;
|
|
|
|
|
}
|
2019-06-21 10:22:26 +00:00
|
|
|
|
|
2020-09-30 14:54:44 +00:00
|
|
|
|
a img {
|
|
|
|
|
border: 1px solid #fff;
|
|
|
|
|
transition: box-shadow 0.5s ease;
|
|
|
|
|
margin: 5px;
|
|
|
|
|
}
|
2019-06-21 10:22:26 +00:00
|
|
|
|
|
2020-09-30 14:54:44 +00:00
|
|
|
|
a img:hover {
|
|
|
|
|
box-shadow: 0 0 7px slategray;
|
|
|
|
|
}
|
2019-06-21 14:27:17 +00:00
|
|
|
|
|
|
|
|
|
|
2020-09-30 14:54:44 +00:00
|
|
|
|
.chat {
|
|
|
|
|
border: 1px solid #333;
|
|
|
|
|
margin: 15px;
|
|
|
|
|
width: 40%;
|
|
|
|
|
height: 70%;
|
|
|
|
|
background: #555;
|
|
|
|
|
color: #fff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.chat-messages {
|
|
|
|
|
min-height: 93%;
|
|
|
|
|
max-height: 93%;
|
|
|
|
|
overflow: auto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.chat-messages__content {
|
|
|
|
|
padding: 1px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.chat__message {
|
|
|
|
|
border-left: 3px solid #333;
|
|
|
|
|
margin-top: 2px;
|
|
|
|
|
padding: 2px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.chat__message_black {
|
|
|
|
|
border-color: #000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.chat__message_blue {
|
|
|
|
|
border-color: blue;
|
|
|
|
|
}
|
2019-06-21 14:27:17 +00:00
|
|
|
|
|
2020-09-30 14:54:44 +00:00
|
|
|
|
.chat__message_green {
|
|
|
|
|
border-color: green;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.chat__message_red {
|
|
|
|
|
border-color: red;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.chat-input {
|
|
|
|
|
min-height: 6%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
input {
|
|
|
|
|
font-family: arial;
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
vertical-align: middle;
|
|
|
|
|
background: #333;
|
|
|
|
|
color: #fff;
|
|
|
|
|
border: 0;
|
|
|
|
|
display: inline-block;
|
|
|
|
|
margin: 1px;
|
|
|
|
|
height: 30px;
|
|
|
|
|
}
|
2019-06-21 10:22:26 +00:00
|
|
|
|
|
2020-09-30 14:54:44 +00:00
|
|
|
|
.chat-form__input {
|
|
|
|
|
width: 79%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.chat-form__submit {
|
|
|
|
|
width: 18%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</style>
|
2019-06-21 10:22:26 +00:00
|
|
|
|
<div class="wrap">
|
|
|
|
|
<header>
|
|
|
|
|
Всякие заголовки, кнопки, ссылки, etc...
|
|
|
|
|
</header>
|
|
|
|
|
<div id="game"></div>
|
|
|
|
|
|
2019-06-21 14:27:17 +00:00
|
|
|
|
<div class='chat'>
|
|
|
|
|
<div class='chat-messages'>
|
|
|
|
|
<div class='chat-messages__content' id='messages'>
|
|
|
|
|
Загрузка...
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class='chat-input'>
|
|
|
|
|
<form method='post' id='chat-form'>
|
2020-09-30 14:54:44 +00:00
|
|
|
|
<input id='message-text' class='chat-form__input' placeholder='Введите сообщение'> <input type='submit'
|
|
|
|
|
class='chat-form__submit'
|
|
|
|
|
value='=>'>
|
2019-06-21 14:27:17 +00:00
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
2019-06-21 10:22:26 +00:00
|
|
|
|
</div>
|
|
|
|
|
<script>
|
|
|
|
|
$("#game").load("main.php");
|
2019-06-21 14:27:17 +00:00
|
|
|
|
</script>
|
2019-06-21 10:22:26 +00:00
|
|
|
|
|
2019-06-21 14:27:17 +00:00
|
|
|
|
<script>
|
|
|
|
|
var messages__container = document.getElementById('messages');
|
|
|
|
|
//Контейнер сообщений — скрипт будет добавлять в него сообщения
|
|
|
|
|
var interval = null; //Переменная с интервалом подгрузки сообщений
|
|
|
|
|
var sendForm = document.getElementById('chat-form'); //Форма отправки
|
|
|
|
|
var messageInput = document.getElementById('message-text'); //Инпут для текста сообщения
|
|
|
|
|
|
|
|
|
|
function send_request(act, login = null, password = null) {//Основная функция
|
|
|
|
|
//Переменные, которые будут отправляться
|
|
|
|
|
var var1 = null;
|
|
|
|
|
var var2 = null;
|
2020-09-30 14:54:44 +00:00
|
|
|
|
if (act == 'auth') {
|
2019-06-21 14:27:17 +00:00
|
|
|
|
//Если нужно авторизоваться, получаем логин и пароль, которые были переданы в функцию
|
|
|
|
|
var1 = login;
|
|
|
|
|
var2 = password;
|
2020-09-30 14:54:44 +00:00
|
|
|
|
} else if (act == 'send') {
|
2019-06-21 14:27:17 +00:00
|
|
|
|
//Если нужно отправить сообщение, то получаем текст из поля ввода
|
|
|
|
|
var1 = messageInput.value;
|
|
|
|
|
}
|
2020-09-30 14:54:44 +00:00
|
|
|
|
$.post('includes/chat.php', { //Отправляем переменные
|
2019-06-21 14:27:17 +00:00
|
|
|
|
act: act,
|
|
|
|
|
var1: var1,
|
|
|
|
|
var2: var2
|
|
|
|
|
}).done(function (data) {
|
|
|
|
|
//Заносим в контейнер ответ от сервера
|
|
|
|
|
messages__container.innerHTML = data;
|
2020-09-30 14:54:44 +00:00
|
|
|
|
if (act == 'send') {
|
2019-06-21 14:27:17 +00:00
|
|
|
|
//Если нужно было отправить сообщение, очищаем поле ввода
|
|
|
|
|
messageInput.value = '';
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function update() {
|
|
|
|
|
send_request('load');
|
|
|
|
|
}
|
2020-09-30 14:54:44 +00:00
|
|
|
|
|
|
|
|
|
interval = setInterval(update, 500);
|
2019-06-21 14:27:17 +00:00
|
|
|
|
|
|
|
|
|
//отлавливается событие отправки формы — это поможет отказаться от обновления страницы:
|
|
|
|
|
sendForm.onsubmit = function () {
|
|
|
|
|
send_request('send');
|
|
|
|
|
return false; //Возвращаем ложь, чтобы остановить классическую отправку формы
|
|
|
|
|
};
|
2020-09-30 14:54:44 +00:00
|
|
|
|
</script>
|