Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
badcast committed Nov 15, 2023
1 parent df1b9d6 commit dc34638
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 39 deletions.
1 change: 1 addition & 0 deletions server-php/api/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
send_auth_fail(STATUS_INVALID_REQUEST_DATA);
exit;
} else {

if (!check_valid_nickname($data->user_nickname)) {
send_auth_fail(STATUS_INVALID_NICKNAME);
exit;
Expand Down
2 changes: 1 addition & 1 deletion server-php/api/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function push_user($user_nickname)
{
global $USERS,$CHANGED_USERS;

$time = time(); // get creation date
$time = time(); // get creation time
$newID = -1;
do {
//0 .. 127 - reserved
Expand Down
6 changes: 4 additions & 2 deletions server-php/server_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
const STATUS_INVALID_AUTH_METHOD = 3;
// Invalid nickname, exists characters
const STATUS_INVALID_NICKNAME = 4;
// Invalid register on server
const STATUS_INVALID_REGISTER = 5;
// Admin account is no reachable
const STATUS_ADMIN_ACCOUNT_REACHABLE = 6;

// Private message is not support by this server
const STATUS_PRIVATE_MESSAGE_NOT_SUPPORTED = 128;

// Internal Server Error (bad code)
const STATUS_INTERNAL_SERVER_ERROR = 500;
42 changes: 30 additions & 12 deletions webclient/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,40 @@
<title>Dragon Tea - Web Client</title>
<script src="./tea_api.js"></script>
<script src="./tea_ui.js"></script>
<link rel="stylesheet" type="text/css" href="./style.css">
<link rel="stylesheet" type="text/css" href="./styles/design.css">
<link rel="stylesheet" type="text/css" href="./styles/form.css">
</head>

<body>
<div class="form_sigin">
<p>Добро пожалаловать на сервер Драконего чая!</p>
<input id="inputSignin" type="text" placeholder="User ID" value="">
<button onclick="tea_ui_signin()">Вход</button>
<p>
<button>RU</button>
<button disabled>EN</button>
</p>
<div id="_wforms">
<div class="form_sigin">
<p>Добро пожалаловать на сервер Драконего чая!</p>
<input id="inputSignin" type="text" placeholder="User ID" value=""/>
<button style="left: 0;" onclick="document.getElementById('inputSignin').value=''">x</button>
<p></p>
<button onclick="tea_ui_signin()">Вход</button>
<div style="font-size: 12px;">
<p class="sticky_label">(!) для входа требуется только UserID которое выдано лично вам.</p>
<p>Данная Веб странница под лицензией <a target="_blank"
href="https://wikipedia.org/wiki/GNU_General_Public_License#GPL_v3">GPLv3</a></p>
<p><a target="_blank" href="https://github.com/badcast/dragon-tea">Исходный код</a> <a target="_blank"
href="https://github.com/badcast/dragon-tea/tree/main/server-php">сервера</a> и <a
target="_blank" href="https://github.com/badcast/dragon-tea/tree/main/webclient">web-клиента</a>
</p>
<p>Так-же имееться программное обеспечение под <br /><a target="_blank"
href="https://github.com/badcast/dragon-tea/releases">Linux и Windows</a></p>
<p>
<button>RU</button>
<button disabled>EN</button>
</p>
</div>
</div>

<p>Данная Веб странница под лицензией <a target="_blank" href="https://wikipedia.org/wiki/GNU_General_Public_License#GPL_v3">GPLv3</a></p>
<p><a target="_blank" href="https://github.com/badcast/dragon-tea">Исходный код</a> <a target="_blank" href="https://github.com/badcast/dragon-tea/tree/main/server-php">сервера</a> и <a target="_blank" href="https://github.com/badcast/dragon-tea/tree/main/webclient">web-клиента</a> </p>
<div style="display: none;" class="form_sigin">
<p>Ваше сообщение</p>
<button>OK</button>
</div>
</div>
</body>

</html>
</html>
26 changes: 9 additions & 17 deletions webclient/style.css → webclient/styles/design.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/*Этот файл описывает стиль для всей странницы, очень красивый!*/

body {
background: lightgray;
font-family: Arial, Helvetica, sans-serif;
Expand All @@ -10,14 +12,12 @@ input {
border: 1px solid #939393;
color: #000;
background-color: #d8d8d8;
transition: background-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}

input:hover,
input:focus {
background-color: #c0c0c0;
color: #000;
box-shadow: 1px 1px 1px #a0a0a0;
}

/* Стиль кнопки в стиле Windows XP */
Expand All @@ -32,7 +32,6 @@ button {
border: 1px solid #939393;
color: #000;
background-color: #d8d8d8;
transition: background-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}

button:hover {
Expand All @@ -50,20 +49,6 @@ button[disabled] {
cursor: not-allowed;
}

.form_sigin {
margin: auto;
width: 400px;
height: 250px;
background: #dbdbdb;
padding: 10px;
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
text-align: center;
}

/* Стиль ссылок в стиле Windows XP */
a {
color: #000;
Expand All @@ -76,3 +61,10 @@ a:hover {
color: #0066cc;
border-bottom: 1px solid #0066cc;
}

.sticky_label
{
background: rgba(226, 255, 25, 0.74);
border-radius: 10px;
padding: 3px;
}
14 changes: 14 additions & 0 deletions webclient/styles/form.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.form_sigin {
border: 1px solid black;
margin: auto;
background: #dbdbdb;
padding: 10px;
position: absolute;
width: 400px;
height: 300px;
left: 0;
top: 0;
bottom: 0;
right: 0;
text-align: center;
}
84 changes: 78 additions & 6 deletions webclient/tea_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,29 @@ function tea_str_error(errcode) {
return "";
}

var net_stats =
{
requestVerified: 0,
requestError: 0,
uploadBytes: 0,
downloadBytes: 0
};

var serverInfo =
{
hasDamager: false
};

var userProfile =
{
user: {
user_id: 0,
creation_date: 0,
last_login: 0,
user_nickname: ""
}
};

async function tea_request(requestData) {
const _netapi = {
signin: "/api/auth.php",
Expand All @@ -45,22 +68,71 @@ async function tea_request(requestData) {
var host = "http://localhost:8000";//"https://dragontea.lightmister.repl.co";//
let url = host + _netapi.signin;

let bodyStr = JSON.stringify(requestData);
console.log(bodyStr);

// Опции для запроса
const requestOptions = {
method: 'POST',
mode: 'cors',
body: JSON.stringify(requestData)
body: bodyStr
};

// Выполняем запрос
await fetch(url, requestOptions)
.then(response => response.text()) // Распарсить ответ как JSON
let status = await fetch(url, requestOptions).then(response => response.text()) // Распарсить ответ как JSON
.then(data => {
// Обработка данных, полученных в ответе
alert(data)
let status = false;
let errStr = null;
net_stats.requestVerified++;
while (1) {
if (data == "") {
errStr = "Internal server error. Responce is empty.";
break;
}

// Get index of the JSON data
let fIndex = data.indexOf("{");
if ((serverInfo.hasDamager = fIndex != 0)) {
if (fIndex === -1) {
errStr = "Server is force damager";
break;
}
// remove damaged
data = data.slice(fIndex, data.length);
}

// Convert string data to json object
data = JSON.parse(data);

if (data.status != 0) {
errStr = tea_str_error(data.status);
break;
}

if (data.authorized) {
status = true;
}
break;
}

if (status) {

}

return { error: errStr, ok: status }
})
.catch(error => {
// Обработка ошибок
alert(error)
console.error(error);
net_stats.requestError++;
return { error: error, ok: false };
});

if (status.ok) {
userProfile.user = status.result;
}
else {
console.error(status.error);
}
return status;
}
25 changes: 24 additions & 1 deletion webclient/tea_ui.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@

const FORM =
{
FDialog: 0,
FSigin: 1
};

var UI =
{
forms: [],
activeForm: 0
};

async function tea_ui_signin() {
let userId = document.getElementById("inputSignin").value;
let userId = parseInt(document.getElementById("inputSignin").value);

let req = { user_id: userId };
await tea_request(req);
}

function tea_ui_start(){
alert("asdsadasd");
}

document.body.onload = function ( env ) { tea_ui_start(); };

void tea_ui_show(formId)
{

}

0 comments on commit dc34638

Please sign in to comment.