Skip to content

xxx #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
VaheHA opened this issue Feb 4, 2025 · 0 comments
Open

xxx #44

VaheHA opened this issue Feb 4, 2025 · 0 comments

Comments

@VaheHA
Copy link

VaheHA commented Feb 4, 2025

#include <a_samp>

// Максимальное количество игроков
#define MAX_PLAYERS 1000

// Диалоги имеют ID: 101 - Логин, 102 - Регистрация, 103 - Заявка

// Для простоты данные хранятся в массивах (для реального проекта рекомендуется использовать базу данных)
new bool:Registered[MAX_PLAYERS];
new playerLogin[MAX_PLAYERS][32];
new playerPass[MAX_PLAYERS][32];

// Обработчик текстовых команд игрока
public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp(cmdtext, "/login", true) == 0)
{
ShowLoginDialog(playerid);
return 1;
}
if(strcmp(cmdtext, "/register", true) == 0)
{
ShowRegisterDialog(playerid);
return 1;
}
if(strcmp(cmdtext, "/apply", true) == 0)
{
ShowApplicationDialog(playerid);
return 1;
}
return 0;
}

// Функция показа диалога для входа
public ShowLoginDialog(playerid)
{
ShowPlayerDialog(playerid, 101, DIALOG_STYLE_INPUT, "Вход",
"Введите логин;Введите пароль", "Войти", "Отмена");
}

// Функция показа диалога для регистрации
public ShowRegisterDialog(playerid)
{
ShowPlayerDialog(playerid, 102, DIALOG_STYLE_INPUT, "Регистрация",
"Введите логин;Введите пароль", "Зарегистрироваться", "Отмена");
}

// Функция показа диалога для подачи заявки
public ShowApplicationDialog(playerid)
{
ShowPlayerDialog(playerid, 103, DIALOG_STYLE_INPUT, "Заявка",
"Введите текст заявки", "Отправить", "Отмена");
}

// Обработчик выбора в диалоговом окне
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
// Если игрок нажал "ОК" (response == 1)
if(response == 1)
{
switch(dialogid)
{
case 101: // Логин
{
HandleLogin(playerid, inputtext);
}
case 102: // Регистрация
{
HandleRegistration(playerid, inputtext);
}
case 103: // Заявка
{
HandleApplication(playerid, inputtext);
}
}
}
return 1;
}

// Функция обработки входа
// Ожидается, что в inputtext будет строка вида "логин;пароль"
public HandleLogin(playerid, inputtext[])
{
new username[32], password[32];
// Разбиваем строку по символу ';'
SplitInput(inputtext, ';', username, sizeof(username), password, sizeof(password));

if(!strcmp(username, playerLogin[playerid], true) && !strcmp(password, playerPass[playerid], true))
{
    SendClientMessage(playerid, 0x00FF00FF, "Вход выполнен успешно!");
}
else
{
    SendClientMessage(playerid, 0xFF0000FF, "Неверный логин или пароль!");
}

}

// Функция обработки регистрации
// Ожидается, что в inputtext будет строка вида "логин;пароль"
public HandleRegistration(playerid, inputtext[])
{
new username[32], password[32];
SplitInput(inputtext, ';', username, sizeof(username), password, sizeof(password));

// Простейшая проверка: если игрок уже зарегистрирован
if(Registered[playerid])
{
    SendClientMessage(playerid, 0xFF0000FF, "Вы уже зарегистрированы!");
    return;
}

strcopy(playerLogin[playerid], sizeof(playerLogin[]), username);
strcopy(playerPass[playerid], sizeof(playerPass[]), password);
Registered[playerid] = true;

SendClientMessage(playerid, 0x00FF00FF, "Регистрация прошла успешно! Теперь вы можете войти.");

}

// Функция обработки заявки
public HandleApplication(playerid, inputtext[])
{
// Здесь можно добавить проверку, запись в базу, логирование и т.д.
printf("Игрок %d подал заявку: %s", playerid, inputtext);
SendClientMessage(playerid, 0x00FF00FF, "Заявка отправлена!");
}

// Функция для разбивки входной строки по разделителю
// input - исходная строка, separator - символ-разделитель,
// output1 и output2 - буферы для записанных подстрок.
stock SplitInput(const input[], separator, output1[], len1, output2[], len2)
{
new i = 0, j = 0, k = 0, inputlen = strlen(input);

// Копируем символы в output1 до разделителя
while(i < inputlen && input[i] != separator)
{
    output1[j++] = input[i++];
    if(j >= len1 - 1) break;
}
output1[j] = '\0';

// Если разделитель найден, пропускаем его
if(i < inputlen && input[i] == separator) i++;

// Копируем оставшуюся часть в output2
while(i < inputlen)
{
    output2[k++] = input[i++];
    if(k >= len2 - 1) break;
}
output2[k] = '\0';

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant