- 24
- 1
Код:
#include <a_samp>
#include <a_mysql>
#include <fix>
#include <streamer>
#include <crashdetect>
#include <Pawn.CMD>
#include <Pawn.Regex>
#include <sscanf2>
#include <foreach>
#define MYSQL_HOST "localhost"
#define MYSQL_USER "root"
#define MYSQL_PASS "root"
#define MYSQL_BASE "bdm"
#define SCM SendClientMessage
#define SCMTA SendClientMessageToALL
#define SPD ShowPlayerDialog
#define DEFAULT_SPAWN_X 1759.0189
#define DEFAULT_SPAWN_Y -1898.1260
#define DEFAULT_SPAWN_Z 13.5622
#define DEFAULT_SPAWN_ANGLE 266.4503
#define COLOR_WHITE 0xFFFFFFFF
#define COLOR_RED 0xFF0000FF
main()
{
print("\n----------------------------------");
print("Bloody DeatMatch - NEW PROJECT");
print("----------------------------------\n");
}
//---------------------- ПЕРЕМЕНАЯ ---------------------
new MySQL:dbHandle;
new bool:isPlayerLogged[MAX_PLAYERS];
//---------------------------------------------------------
enum player
{
ID,
NAME[MAX_PLAYER_NAME],
PASSWORD[32],
}
new player_info[MAX_PLAYERS][player];
enum dialogs
{
DLG_NONE,
DLG_REG,
DLG_REGEMAIL,
DLG_LOG,
}
public OnGameModeInit()
{
AddPlayerClass(14,DEFAULT_SPAWN_X, DEFAULT_SPAWN_Y, DEFAULT_SPAWN_Z, DEFAULT_SPAWN_ANGLE,-1,-1,-1,-1,-1,-1);
AddPlayerClass(15,DEFAULT_SPAWN_X, DEFAULT_SPAWN_Y, DEFAULT_SPAWN_Z, DEFAULT_SPAWN_ANGLE,-1,-1,-1,-1,-1,-1);
AddPlayerClass(101,DEFAULT_SPAWN_X, DEFAULT_SPAWN_Y, DEFAULT_SPAWN_Z, DEFAULT_SPAWN_ANGLE,-1,-1,-1,-1,-1,-1);
AddPlayerClass(183,DEFAULT_SPAWN_X, DEFAULT_SPAWN_Y, DEFAULT_SPAWN_Z, DEFAULT_SPAWN_ANGLE,-1,-1,-1,-1,-1,-1);
AddPlayerClass(184,DEFAULT_SPAWN_X, DEFAULT_SPAWN_Y, DEFAULT_SPAWN_Z, DEFAULT_SPAWN_ANGLE,-1,-1,-1,-1,-1,-1);
AddPlayerClass(14,DEFAULT_SPAWN_X, DEFAULT_SPAWN_Y, DEFAULT_SPAWN_Z, DEFAULT_SPAWN_ANGLE,-1,-1,-1,-1,-1,-1);
SetGameModeText("Blank Script");
ConnectMySQL();
return 1;
}
stock ConnectMySQL()
{
dbHandle = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_BASE);
switch(mysql_errno())
{
case 0: print("Подключение к MySQL успешно");
default: print("MySQL error!");
}
mysql_log(ERROR | WARNING);
mysql_set_charset("cp1251");
}
public OnGameModeExit()
{
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
if(isPlayerLogged[playerid]) return SpawnPlayer(playerid); // ???? ????? ????? F4, ?? ??? ???????????, ?? ????? ??? ??????? ????????? ??? ???
SetPlayerInterior(playerid,11); // ???????? ????
SetPlayerPos(playerid, 508.7362,-87.4335,998.9609); // ??????? ??????
SetPlayerFacingAngle(playerid, 0); // ???? ???????? ??????
SetPlayerCameraPos(playerid, 508.7362,-83.4335,998.9609); // ??????? ??????
SetPlayerCameraLookAt(playerid, 508.7362,-87.4335,998.9609); // ??????????, ?? ??????? ????? ???????? ??????
SetPlayerVirtualWorld(playerid, playerid+1); // ????????? ??????????? ??? ? ID ?????? ID ?????? + 1, ???? ??????? ????? ???
return 1;
}
public OnPlayerConnect(playerid)
{
GetPlayerName(playerid, player_info[playerid][NAME], MAX_PLAYER_NAME);
static const fmt_query[] = "SELECT id FROM users WHERE name = '%s'";
new query[sizeof(fmt_query)+(-2+MAX_PLAYER_NAME)];
format(query, sizeof(query), fmt_query, player_info[playerid] [NAME]);
mysql_tquery(dbHandle, query, "CheckRegistration", "i", playerid);
return 1;
}
forward CheckRegistration(playerid);
public CheckRegistration(playerid)
{
new rows;
cache_get_row_count(rows);
if(rows) ShowLogin(playerid);
else ShowRegistration(playerid);
}
stock ShowLogin(playerid)
{
SCM(playerid, COLOR_WHITE, "Игрок зарегистрирован");
}
stock ShowRegistration(playerid)
{
new dialog[410+(-2+MAX_PLAYER_NAME)];
format(dialog, sizeof(dialog),
"{FFFFFF}Уважаемый {594de1}%s{FFFFFF}, мы рады видеть вас на {594de1}Bloody DeatMatch{FFFFFF}\n\
Аккаунт с таким ником не зарегистрирован\n\
Для игры на сервере вы должны пройти регистрацию\n\n\
Придумайте сложный пароль для вашего аккаунта и нажмите\"Далее\"\n\
{Ffff00}\t*Пароль должен быть от 8-ми до 36-ти символов\n\
\t*Пароль должен состоять из цифр и латинских символов любого регистра",
player_info[playerid] [NAME]
);
SPD(playerid, DLG_REG, DIALOG_STYLE_INPUT, "{e743e4}Регистрация{FFFFFF}", dialog, "Далее", "Выход");
}
public OnPlayerDisconnect(playerid, reason)
{
return 1;
}
public OnPlayerSpawn(playerid)
{
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
return 1;
}
public OnVehicleSpawn(vehicleid)
{
return 1;
}
public OnVehicleDeath(vehicleid, killerid)
{
return 1;
}
public OnPlayerText(playerid, text[])
{
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
// Do something here
return 1;
}
return 0;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
return 1;
}
public OnPlayerEnterCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveCheckpoint(playerid)
{
return 1;
}
public OnPlayerEnterRaceCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveRaceCheckpoint(playerid)
{
return 1;
}
public OnRconCommand(cmd[])
{
return 1;
}
public OnPlayerRequestSpawn(playerid)
{
isPlayerLogged[playerid] = true;
SendClientMessage(playerid, -1, "Все хорошо. Приятной игры.");
SetPlayerVirtualWorld(playerid, 0);
return 1;
}
public OnObjectMoved(objectid)
{
return 1;
}
public OnPlayerObjectMoved(playerid, objectid)
{
return 1;
}
public OnPlayerPickUpPickup(playerid, pickupid)
{
return 1;
}
public OnVehicleMod(playerid, vehicleid, componentid)
{
return 1;
}
public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
return 1;
}
public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
return 1;
}
public OnPlayerSelectedMenuRow(playerid, row)
{
return 1;
}
public OnPlayerExitedMenu(playerid)
{
return 1;
}
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
return 1;
}
public OnRconLoginAttempt(ip[], password[], success)
{
return 1;
}
public OnPlayerUpdate(playerid)
{
return 1;
}
public OnPlayerStreamIn(playerid, forplayerid)
{
return 1;
}
public OnPlayerStreamOut(playerid, forplayerid)
{
return 1;
}
public OnVehicleStreamIn(vehicleid, forplayerid)
{
return 1;
}
public OnVehicleStreamOut(vehicleid, forplayerid)
{
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case DLG_REG:
{
if(response)
{
if(!strlen(inputtext))
{
ShowRegistration(playerid);
return SCM(playerid, COLOR_RED, "[Ошибка] {FFFFFF}Введите в поле ниже и нажмите \"Далее\"");
}
if(strlen(inputtext) < 8 || strlen(inputtext) > 24)
{
ShowRegistration(playerid);
return SCM(playerid, COLOR_RED, "[Ошибка] {FFFFFF}Длина пароля должна быть от 8-ми до 24-ух символов");
}
new regex:rg_passwordcheck = regex_new("^[a-zA-Z0-9]{1,}$");
if(regex_check(inputtext, rg_passwordcheck))
{
ShowRegistration(playerid);
return SCM(playerid, COLOR_RED, "[Ошибка] {FFFFFF}Пароль должен состоять из цифр и латинских символов любого регистра");
}
}
else
{
SCM(playerid, COLOR_RED, "Используйте \"/q\" чтобы покинуть сервер");
SPD(playerid, -1, 0, "", "", "", "");
return Kick(playerid);
}
}
}
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case DLG_REG:
{
if(response)
{
if(!strlen(inputtext))
{
ShowRegistration(playerid);
return SCM(playerid, COLOR_RED, "[Ошибка] {FFFFFF}Введите в поле ниже и нажмите \"Далее\"");
}
if(strlen(inputtext) < 8 || strlen(inputtext) > 24)
{
ShowRegistration(playerid);
return SCM(playerid, COLOR_RED, "[Ошибка] {FFFFFF}Длина пароля должна быть от 8-ми до 24-ух символов");
}
new regex:rg_passwordcheck = regex_new("^[a-zA-Z0-9]{1,}$");
if(regex_check(inputtext, rg_passwordcheck))
{
ShowRegistration(playerid);
return SCM(playerid, COLOR_RED, "[Ошибка] {FFFFFF}Пароль должен состоять из цифр и латинских символов любого регистра");
}
}
else
{
SCM(playerid, COLOR_RED, "Используйте \"/q\" чтобы покинуть сервер");
SPD(playerid, -1, 0, "", "", "", "");
return Kick(playerid);
}
}
}
return 1;
}
Код:
public OnPlayerConnect(playerid)
{
GetPlayerName(playerid, player_info[playerid][NAME], MAX_PLAYER_NAME);
static const fmt_query[] = "SELECT id FROM users WHERE name = '%s'";
new query[sizeof(fmt_query)+(-2+MAX_PLAYER_NAME)];
format(query, sizeof(query), fmt_query, player_info[playerid] [NAME]);
mysql_tquery(dbHandle, query, "CheckRegistration", "i", playerid);
return 1;
}
forward CheckRegistration(playerid);
public CheckRegistration(playerid)
{
new rows;
cache_get_row_count(rows);
if(rows) ShowLogin(playerid);
else ShowRegistration(playerid);
}
stock ShowLogin(playerid)
{
SCM(playerid, COLOR_WHITE, "Игрок зарегистрирован");
}
stock ShowRegistration(playerid)
{
new dialog[410+(-2+MAX_PLAYER_NAME)];
format(dialog, sizeof(dialog),
"{FFFFFF}Уважаемый {594de1}%s{FFFFFF}, мы рады видеть вас на {594de1}Bloody DeatMatch{FFFFFF}\n\
Аккаунт с таким ником не зарегистрирован\n\
Для игры на сервере вы должны пройти регистрацию\n\n\
Придумайте сложный пароль для вашего аккаунта и нажмите\"Далее\"\n\
{Ffff00}\t*Пароль должен быть от 8-ми до 36-ти символов\n\
\t*Пароль должен состоять из цифр и латинских символов любого регистра",
player_info[playerid] [NAME]
);
SPD(playerid, DLG_REG, DIALOG_STYLE_INPUT, "{e743e4}Регистрация{FFFFFF}", dialog, "Далее", "Выход");
}
сам код на регу