Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <a_mysql>
- #include <zcmd>
- #include <sscanf2>
- #include <CTime>
- //#include <streamer>
- native gpci(playerid, serial[], len = sizeof serial);
- // Constantes
- new const
- SCRIPT_VERSION[] = "0.1",
- SERVER_NAME[] = "(MySQL) Get started!",
- DB_HOST[] = "localhost",
- DB_USER[] = "root",
- DB_NAME[] = "rpg",
- DB_PASS[] = "";
- new gstring[1024];
- new g_dbConnection = 0;
- #if defined MAX_PLAYERS
- #undef MAX_PLAYERS
- #endif
- enum {
- MAX_PLAYERS = 100,
- MIN_PASS_LENGTH = 05,
- MAX_PASS_LENGTH = 32,
- MAX_LOGIN_ATT = 05,
- }
- enum {
- // Register/login
- DIALOG_REGISTER,
- DIALOG_LOGIN
- }
- // Correções
- #define Kick(%0) SetTimerEx("kick_Fix", 100, 0, "i", %0)
- // Players
- enum E_PLAYER_INFO {
- // Identificação
- playerID,
- playerName[25],
- playerSerial[129],
- // Registro e login
- playerPass[129],
- playerLoginAtt,
- playerLogged,
- // Importante
- playerAdmin,
- // Personagem
- playerMoney,
- playerSkin
- }
- new gPlayerInfo[MAX_PLAYERS][E_PLAYER_INFO];
- main();
- public OnGameModeInit() {
- g_dbConnection = mysql_connect(DB_HOST, DB_USER, DB_NAME, DB_PASS);
- if(mysql_ping(g_dbConnection) == -1) {
- print("\n\n!! Ocorreu um erro durante a tentativa de conexão com o banco de dados.");
- print("!! O servidor não foi inicializado com êxito.\n\n");
- return SendRconCommand("exit");
- }
- UsePlayerPedAnims();
- ShowPlayerMarkers(0);
- EnableStuntBonusForAll(0);
- DisableInteriorEnterExits();
- SendRconCommand("mapname Los Santos");
- SendRconCommand((format(gstring, sizeof gstring, "gamemodetext SA:MP v%s", SCRIPT_VERSION), gstring));
- SendRconCommand((format(gstring, sizeof gstring, "hostname [BR] %s v%s", SERVER_NAME, SCRIPT_VERSION), gstring));
- return true;
- }
- public OnGameModeExit() {
- mysql_close(g_dbConnection);
- return true;
- }
- public OnPlayerConnect(playerid) {
- GetPlayerName(playerid, gPlayerInfo[playerid][playerName], 25);
- gpci(playerid, gPlayerInfo[playerid][playerSerial]);
- SetPlayerColor(playerid, 0x696969ff);
- TogglePlayerSpectating(playerid, true);
- Player_Init(playerid);
- return true;
- }
- public OnPlayerDisconnect(playerid, reason) {
- if(gPlayerInfo[playerid][playerLogged]) {
- gPlayerInfo[playerid][playerLogged] = 0;
- gPlayerInfo[playerid][playerMoney] = GetPlayerMoney(playerid);
- gPlayerInfo[playerid][playerSkin] = GetPlayerSkin(playerid);
- mysql_format(g_dbConnection, gstring, sizeof gstring, "UPDATE `player_info` SET `money` = %d, `skin` = %d WHERE `id` = %d",
- gPlayerInfo[playerid][playerMoney],
- gPlayerInfo[playerid][playerSkin],
- gPlayerInfo[playerid][playerID]);
- mysql_function_query(g_dbConnection, gstring, false, #, #);
- }
- return true;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
- switch(dialogid) {
- // Registro/login
- case DIALOG_REGISTER: {
- if(!response) {
- SendClientMessage(playerid, -1, " Você optou por não se registrar no servidor.");
- SendClientMessage(playerid, -1, " Logo, foi retirado do mesmo.");
- Kick(playerid);
- }
- else {
- if(!((MIN_PASS_LENGTH - 1) < strlen(inputtext) < (MAX_PASS_LENGTH - 1))) {
- format(gstring, sizeof gstring, "{ffffff}Caro(a) {f6f600}%s{ffffff}, ocorreu um erro durante seu registro.\n\nSua senha deve conter entre {f6f600}%02d {ffffff}e {f6f600}%02d {ffffff}caracteres.\nPor favor, tente novamente.",
- gPlayerInfo[playerid][playerName], MIN_PASS_LENGTH, MAX_PASS_LENGTH);
- ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{ffffff}Registro", gstring, "Registrar", "Sair");
- }
- else {
- format(gPlayerInfo[playerid][playerPass], (MAX_PASS_LENGTH + 1), inputtext);
- SendClientMessage(playerid, -1, " Você se registrou com sucesso no servidor!");
- SendClientMessage(playerid, -1, " Aguarde enquanto o redirecionamos para a cidade...");
- mysql_format(g_dbConnection, gstring, sizeof gstring, "INSERT INTO `player_info` (`name`, `password`) VALUES ('%s', PASSWORD('%e'))",
- gPlayerInfo[playerid][playerName], gPlayerInfo[playerid][playerPass]);
- mysql_function_query(g_dbConnection, gstring, false, #, #);
- Player_Login(playerid, gPlayerInfo[playerid][playerPass]);
- }
- }
- }
- case DIALOG_LOGIN: {
- if(!response) {
- SendClientMessage(playerid, -1, " Você optou por não fazer login no servidor.");
- SendClientMessage(playerid, -1, " Logo, foi retirado do mesmo.");
- Kick(playerid);
- }
- else {
- Player_Login(playerid, inputtext);
- }
- }
- //
- }
- return true;
- }
- // Players
- forward Player_Init(playerid);
- forward Player_Login(playerid, password[]);
- forward r@Player_Init(playerid);
- forward r@Player_Login(playerid);
- public Player_Init(playerid) {
- mysql_format(g_dbConnection, gstring, sizeof gstring, "SELECT * FROM `player_info` WHERE `name` = '%s'",
- gPlayerInfo[playerid][playerName]);
- mysql_function_query(g_dbConnection, gstring, true, "r@Player_Init", "i", playerid);
- return true;
- }
- public Player_Login(playerid, password[]) {
- mysql_format(g_dbConnection, gstring, sizeof gstring, "SELECT * FROM `player_info` WHERE `name` = '%s' AND `password` = PASSWORD('%e')",
- gPlayerInfo[playerid][playerName], password);
- mysql_function_query(g_dbConnection, gstring, true, "r@Player_Login", "i", playerid);
- return true;
- }
- public r@Player_Init(playerid) {
- new rows, fields;
- cache_get_data(rows, fields, g_dbConnection);
- if(rows) {
- // Registrado
- format(gstring, sizeof gstring, "{ffffff}Olá, {f6f600}%s{ffffff}.\nSeja bem-vindo ao {f6f600}%s{ffffff}!\n\nDigite sua senha abaixo para fazer login.",
- gPlayerInfo[playerid][playerName], SERVER_NAME);
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{ffffff}Login", gstring, "Entrar", "Sair");
- }
- else {
- // Não registrado
- format(gstring, sizeof gstring, "{ffffff}Olá, {f6f600}%s{ffffff}.\nSeja bem-vindo ao {f6f600}%s{ffffff}!\nParece que você é novo por aqui, não?\n\nPara se registrar, basta digitar uma senha no campo abaixo.",
- gPlayerInfo[playerid][playerName], SERVER_NAME);
- ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{ffffff}Registro", gstring, "Registrar", "Sair");
- }
- return true;
- }
- public r@Player_Login(playerid) {
- new rows, fields;
- cache_get_data(rows, fields, g_dbConnection);
- if(rows) {
- gPlayerInfo[playerid][playerLogged] = 1;
- gPlayerInfo[playerid][playerID] = cache_get_field_content_int(0, "id", g_dbConnection);
- cache_get_field_content(0, "password", gPlayerInfo[playerid][playerPass], g_dbConnection);
- gPlayerInfo[playerid][playerAdmin] = cache_get_field_content_int(0, "admin", g_dbConnection);
- GivePlayerMoney(playerid, (gPlayerInfo[playerid][playerMoney] = cache_get_field_content_int(0, "money", g_dbConnection)));
- SetPlayerSkin(playerid, (gPlayerInfo[playerid][playerSkin] = cache_get_field_content_int(0, "skin", g_dbConnection)));
- SetSpawnInfo(playerid, 0, gPlayerInfo[playerid][playerSkin], 2247.6187, -1262.2136, 23.9550, 266.1028, 0, 0, 0, 0, 0, 0);
- SendClientMessage(playerid, -1, "Aguarde enquanto verificamos se há algum registro ativo de ban em sua conta.");
- Ban_Check(playerid);
- }
- else {
- gPlayerInfo[playerid][playerLoginAtt]++;
- if(gPlayerInfo[playerid][playerLoginAtt] == MAX_LOGIN_ATT) {
- SendClientMessage(playerid, -1, " Você excedeu o limite de tentativas de login.");
- SendClientMessage(playerid, -1, " Por isso foi despejado do servidor.");
- Kick(playerid);
- }
- else {
- format(gstring, sizeof gstring, "{ffffff}Senha incorreta! (%02d/%02d)\n\nCaro(a) {f6f600}%s{ffffff}, ocorreu um erro durante o processo de login.\nVocê digitou uma senha não corresponde à registrada no banco de dados.\nPor favor, tente novamente.",
- gPlayerInfo[playerid][playerLoginAtt], MAX_LOGIN_ATT, gPlayerInfo[playerid][playerName]);
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{ffffff}Login", gstring, "Entrar", "Sair");
- }
- }
- return true;
- }
- // Ban
- forward Ban_Apply(playerid, admin[], reason[], time);
- forward Ban_Check(playerid);
- forward r@Ban_Check(playerid);
- public Ban_Apply(playerid, admin[], reason[], time) {
- if(time != -1)
- time *= 86400;
- mysql_format(g_dbConnection, gstring, sizeof gstring, "INSERT INTO `ban_info` (`pid`, `admin`, `reason`, `date`, `expire`) VALUES (%d, '%s', '%s', UNIX_TIMESTAMP(), %d)",
- gPlayerInfo[playerid][playerID], admin, reason,
- time != -1 ? gettime() + time : time);
- mysql_function_query(g_dbConnection, gstring, false, #, #);
- if(time == -1)
- format(gstring, sizeof gstring, "AdmCmd: %s foi banido por tempo indeterminado pelo admin %s. (%s)", gPlayerInfo[playerid][playerName], admin, reason);
- else
- format(gstring, sizeof gstring, "AdmCmd: %s foi banido por %02d dias pelo admin %s. (%s)", gPlayerInfo[playerid][playerName], (time / 86400), admin, reason);
- SendClientMessageToAll(0xff0000ff, gstring);
- Kick(playerid);
- return true;
- }
- public Ban_Check(playerid) {
- mysql_format(g_dbConnection, gstring, sizeof gstring, "SELECT * FROM `ban_info` WHERE `pid` = %d AND (`expire` = -1 OR `expire` > UNIX_TIMESTAMP())",
- gPlayerInfo[playerid][playerID]);
- mysql_function_query(g_dbConnection, gstring, true, "r@Ban_Check", "i", playerid);
- return true;
- }
- public r@Ban_Check(playerid) {
- new rows, fields;
- cache_get_data(rows, fields, g_dbConnection);
- if(rows) {
- // Registros encontrados
- SendClientMessage(playerid, -1, "Foram encontrados registros ativos de ban em sua conta.");
- SendClientMessage(playerid, -1, "Verifique as ocorrências e busque uma revisão caso necessário.");
- new admin[25], reason[64],
- Time:date, Time:expire,
- tm<tmTime>;
- cache_get_field_content(0, "admin", admin, g_dbConnection);
- cache_get_field_content(0, "reason", reason, g_dbConnection);
- date = Time:cache_get_field_content_int(0, "date", g_dbConnection);
- localtime(Time:date, tmTime);
- strftime(gstring, sizeof gstring, "%d/%m/%Y às %X", tmTime);
- format(gstring, sizeof gstring, " %s, aplicado pelo administrador %s.", gstring, admin);
- SendClientMessage(playerid, -1, gstring);
- format(gstring, sizeof gstring, " Motivo: %s", reason);
- SendClientMessage(playerid, -1, gstring);
- expire = Time:cache_get_field_content_int(0, "expire", g_dbConnection);
- if(_:expire != -1) {
- localtime(Time:expire, tmTime);
- strftime(gstring, sizeof gstring, "%d/%m/%Y às %X", tmTime);
- format(gstring, sizeof gstring, " Expira em %s", gstring);
- SendClientMessage(playerid, -1, gstring);
- }
- else {
- SendClientMessage(playerid, -1, " Não há um prazo determinado para expirar.");
- }
- Kick(playerid);
- }
- else {
- // Nenhum registro encontrado. Liberado!
- SendClientMessage(playerid, -1, " Nenhum registro encontrado, tenha um bom jogo!");
- TogglePlayerSpectating(playerid, false);
- SpawnPlayer(playerid);
- }
- return true;
- }
- // AdmCmd: Comandos de exemplo
- CMD:admin(playerid, params[]) {
- if(!gPlayerInfo[playerid][playerAdmin])
- return SendClientMessage(playerid, 0xff0000ff, "(!) Ação exclusiva de administradores.");
- new targetid;
- if(sscanf(params, "u", targetid))
- return SendClientMessage(playerid, 0x32cd32ff, "CMD: /admin <id/nome>");
- if(!gPlayerInfo[targetid][playerLogged])
- return SendClientMessage(playerid, 0xff0000ff, "(!) O jogador não efetuou login.");
- format(gstring, sizeof gstring, " Você promoveu %s a administrador.", gPlayerInfo[targetid][playerName]);
- SendClientMessage(playerid, 0x32cd32ff, gstring);
- format(gstring, sizeof gstring, " %s promoveu você a administrador.", gPlayerInfo[playerid][playerName]);
- SendClientMessage(playerid, 0x32cd32ff, gstring);
- gPlayerInfo[targetid][playerAdmin] = 1;
- mysql_format(g_dbConnection, gstring, sizeof gstring, "UPDATE `player_info` SET `admin` = 1 WHERE `id` = %d", gPlayerInfo[targetid][playerID]);
- mysql_function_query(g_dbConnection, gstring, false, #, #);
- return true;
- }
- CMD:ban(playerid, params[]) {
- if(!gPlayerInfo[playerid][playerAdmin])
- return SendClientMessage(playerid, 0xff0000ff, "(!) Ação exclusiva de administradores.");
- new targetid, reason[64], days = -1;
- if(sscanf(params, "us[64]I(-1)", targetid, reason, days)) {
- SendClientMessage(playerid, 0x32cd32ff, "CMD: /ban <id/nome> <motivo> <dias>");
- SendClientMessage(playerid, 0x32cd32ff, " Para banir por tempo indeterminado, não digite os dias ou coloque \"-1\".");
- return true;
- }
- if(!gPlayerInfo[targetid][playerLogged])
- return SendClientMessage(playerid, 0xff0000ff, "(!) O jogador não efetuou login.");
- Ban_Apply(targetid, gPlayerInfo[playerid][playerName], reason, days);
- return true;
- }
- CMD:grana(playerid, params[]) {
- if(!gPlayerInfo[playerid][playerAdmin])
- return SendClientMessage(playerid, 0xff0000ff, "(!) Ação exclusiva de administradores.");
- new targetid, amount;
- if(sscanf(params, "ui", targetid, amount))
- return SendClientMessage(playerid, 0x32cd32ff, "CMD: /grana <id/nome> <valor>");
- if(!gPlayerInfo[targetid][playerLogged])
- return SendClientMessage(playerid, 0xff0000ff, "(!) O jogador não efetuou login.");
- GivePlayerMoney(targetid, amount);
- return true;
- }
- CMD:skin(playerid, params[]) {
- if(!gPlayerInfo[playerid][playerAdmin])
- return SendClientMessage(playerid, 0xff0000ff, "(!) Ação exclusiva de administradores.");
- new targetid, skinid;
- if(sscanf(params, "ui", targetid, skinid))
- return SendClientMessage(playerid, 0x32cd32ff, "CMD: /skin <id/nome> <skinid>");
- if(!gPlayerInfo[targetid][playerLogged])
- return SendClientMessage(playerid, 0xff0000ff, "(!) O jogador não efetuou login.");
- SetPlayerSkin(targetid, skinid);
- return true;
- }
- CMD:v(playerid, params[]) {
- if(!gPlayerInfo[playerid][playerAdmin])
- return SendClientMessage(playerid, 0xff0000ff, "(!) Ação exclusiva de administradores.");
- new modelid, color1, color2;
- if(sscanf(params, "iii", modelid, color1, color2))
- return SendClientMessage(playerid, 0x32cd32ff, "CMD: /v <modelo> <cor 1> <cor 2>");
- if(modelid < 400 || modelid > 611)
- return true;
- if(color1 < 0 || color2 < 0 || color1 > 255 || color2 > 255)
- return true;
- new Float:p[4];
- GetPlayerPos(playerid, p[0], p[1], p[2]);
- GetPlayerFacingAngle(playerid, p[3]);
- PutPlayerInVehicle(playerid, CreateVehicle(modelid, p[0], p[1], p[2], p[3], color1, color2, -1), 0);
- return true;
- }
- // Correção bug kick (0.3x)
- forward kick_Fix(playerid);
- public kick_Fix(playerid) {
- #undef Kick
- Kick(playerid);
- #define Kick(%0) SetTimerEx("kick_Fix", 100, 0, "i", %0)
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement