Сегодня я расскажу вам как можно связать форму в html с pawn с помощью CEF.
Для начала вам нужно будет скачать собранный CEF для сервера и клиента.
Затем вам нужно будет арендовать хостинг с доменом. ( Советую beget.com )
Далее вам нужно создать html страницу с кодом
<style>
/* Bordered form */
form {
border: 3px solid #f1f1f1;
}
/* Full-width inputs */
input[type=text], input[type=password] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
/* Set a style for all buttons */
button {
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
}
/* Add a hover effect for buttons */
button:hover {
opacity: 0.8;
}
/* Extra style for the cancel button (red) */
.cancelbtn {
width: auto;
padding: 10px 18px;
background-color: #f44336;
}
/* Center the avatar image inside this container */
.imgcontainer {
text-align: center;
margin: 24px 0 12px 0;
}
/* Avatar image */
img.avatar {
width: 40%;
border-radius: 50%;
}
/* Add padding to containers */
.container {
padding: 16px;
}
/* The "Forgot password" text */
span.psw {
float: right;
padding-top: 16px;
}
/* Change styles for span and cancel button on extra small screens */
@media screen and (max-width: 300px) {
span.psw {
display: block;
float: none;
}
.cancelbtn {
width: 100%;
}
}
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
padding-top: 60px;
}
/* Modal Content/Box */
.modal-content {
background-color: #fefefe;
margin: 5px auto; /* 15% from the top and centered */
border: 1px solid #888;
width: 80%; /* Could be more or less, depending on screen size */
}
/* The Close Button */
.close {
/* Position it in the top right corner outside of the modal */
position: absolute;
right: 25px;
top: 0;
color: #000;
font-size: 35px;
font-weight: bold;
}
/* Close button on hover */
.close:hover,
.close:focus {
color: red;
cursor: pointer;
}
/* Add Zoom Animation */
.animate {
-webkit-animation: animatezoom 0.6s;
animation: animatezoom 0.6s
}
@-webkit-keyframes animatezoom {
from {-webkit-transform: scale(0)}
to {-webkit-transform: scale(1)}
}
@keyframes animatezoom {
from {transform: scale(0)}
to {transform: scale(1)}
}
</style>
<!-- Button to open the modal login form -->
<button onclick="document.getElementById('id01').style.display='block'">Login</button>
<!-- The Modal -->
<div id="id01" class="modal">
<span onclick="document.getElementById('id01').style.display='none'"
class="close" title="Close Modal">×</span>
<!-- Modal Content -->
<form class="modal-content animate" class="rf" novalidate>
<div class="imgcontainer">
<img src="img_avatar2.png" alt="Avatar" class="avatar">
</div>
<p id="response">None</p>
<div class="container">
<label for="uname"><b>Username</b></label>
<input class="login" type="text" name="uname">
<label for="psw"><b>Password</b></label>
<input class="pass" type="password" name="psw">
<button onclick="LoginClick(this)" type="button">Login</button>
<label>
<input type="checkbox" checked="checked" name="remember"> Remember me
</label>
</div>
<div class="container" style="background-color:#f1f1f1">
<button type="button" onclick="onExitClick(this)" class="cancelbtn">Cancel</button>
<span class="psw">Forgot <a href="#">password?</a></span>
</div>
</form>
</div>
<script>
// Get the modal
var modal = document.getElementById('id1');
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
<script src="cef.js"></script>
После создания данной страницы вам нужно создать js файл , затем назвать его cef.js.
Далее нужно будет закинуть все файлы на ваш купленный хостинг.
Код cef.js:
const PWD_OK = 0;
const PWD_WRONG = 1;
const serverResponse = document.getElementById('response');
function LoginClick(event)
{
//получения значения input, затем сравнивание
let a = document.querySelector('.pass').value;
let b = document.querySelector('.login').value;
if(a == "" && b == "")
{
//если пароль и логин не введены.
serverResponse.innerText = "Вы не ввели пароль или логин!";
cef.emit('pwd:exit_forms'); //отправляем событие в игру
}
else
{
cef.emit("pwd:try"); // отправляем событие в игру если поля введены.
}
}
//человек нажал кнопку закрыть
function onExitClick(event) {
serverResponse.innerText = "Close";
cef.emit('pwd:exit_forms');
}
//принимаем событие с игры и обрабатываем его
cef.on('pwd:login_succes', (response) => {
if (response == PWD_OK) {
cef.set_focus(false);
cef.hide(true);
cef.emit('pwd:exit_forms');
} else {
serverResponse.innerText = "Вы успешно авторизовались!";
cef.hide(true); //скрываем браузер
cef.set_focus(false); //убираем фокусирование с браузера
}
});
Теперь перейдем к Pawn коду:
#include <cef>
#define LOGIN_BROWSER_ID 0x12346
forward ExitCef(player_id, const arguments[]);
forward Login(player_id, const arguments);
public OnGameModeInit()
{
cef_subscribe("pwd:try", "Login"); //подписываемся на событие которое вызывали в cef.js , затем передаем ее в паблик Login
cef_subscribe("pwd:exit_forms", "ExitCef"); //подписываемся на событие которое вызывали в cef.js , затем передаем ее в паблик ExitCef
}
forward OnCefInitialize(player_id, success);
forward OnCefBrowserCreated(player_id, browser_id, status_code);
//при подключении игроку будет автоматически создавать браузер
public OnCefInitialize(player_id, success) {
if (success == 1) {
cef_create_browser(player_id, LOGIN_BROWSER_ID, "url на ваш сайт", false, true);
return;
}
}
public OnCefBrowserCreated(player_id, browser_id, status_code) {
if (browser_id == LOGIN_BROWSER_ID) {
if (status_code != 200) {
return;
}
}
}
//паблик который будет отвечать за то что игрок закрыл форму .
public ExitCef(player_id, const arguments[]) {
SendClientMessage(player_id, -1, "Вы не ввели логин или пароль!");
cef_focus_browser(player_id, LOGIN_BROWSER_ID, false);
cef_hide_browser(player_id, LOGIN_BROWSER_ID, true);
return 1;
}
//если все нормально , то передаем в js скрипт значение 1 .
public Login(player_id, const arguments) {
new result = 1;
cef_emit_event(player_id, "pwd:login_succes", CEFINT(result));
SendClientMessage(player_id, -1, "Вы успешно авторизовались!");
}
Автор темы: Я
Помогал: Андрей Дрыгин
Если вам нужна помощь , то могу помочь в личных сообщениях в VK.
Ссылка на загрузку:
Видео:
Скрытый текст [Показать]
Можно сделать полноценную авторизацию/регистрацию.
Т.к тут описаны все пункты для работы с CEF.
Сообщение отредактировал Romzes: 05 марта 2023 - 07:44
Вход
Регистрация
Помощь










