18.08.2010, 15:58
Sistema de registro por: LeLeTe
Crйditos:Cobertozinho: idйia;
LARP - Cуdigo original.
Nгo tenho muito o que explicar (Atй porquк, tх atrasado pra ir pra escola).
Й um sistema de Registro simples, com dialog e tudo.
Instruзхes (Bem bбsicas) de como adicionar arrays para salvar e carregar se encontram no meu tutorial de Arrays e informaзхes de players (As funзхes J_CARREGAR e J_SALVAR sгo OnPlayerLogin e OnPlayerRegister, respectivamente.)
Have fun.
pawn Code:
#define FILTERSCRIPT
#include <a_samp>
enum sInfo
{
sValor,//Valor de exemplo. Delete se quiser.
Float:sFloat,//Float de Exemplo. Delete se quiser.
sString[32],//String de exemplo. Delete se quiser.
sSenha[128],
}
new SuaDataBase[MAX_PLAYERS][sInfo];
forward OnPlayerRegister(playerid, password[]);
new gPlayerAccount[MAX_PLAYERS];
new gPlayerLogTries[MAX_PLAYERS];
new gPlayerLogged[MAX_PLAYERS];
public OnFilterScriptInit()
{
return 1;
}
public OnPlayerConnect(playerid)
{
new plname[MAX_PLAYER_NAME];
GetPlayerName(playerid, plname, sizeof(plname));
if(IsPlayerNPC(playerid))
{
SpawnPlayer(playerid);
return 1;
}
new string[MAX_PLAYER_NAME];
GetPlayerName(playerid, plname, sizeof(plname));
format(string, sizeof(string), "LeLeTe/%s.ini", plname);
SendClientMessage(playerid, 0xFFFFFFFF, "Por favor aguarde...");
SetPlayerColor(playerid, 0x00000000);
if(fexist(string))
{
gPlayerAccount[playerid] = 0;
}
else
{
gPlayerAccount[playerid] = 1;
}
return 1;
}
forward split(const strsrc[], strdest[][], delimiter);
public split(const strsrc[], strdest[][], delimiter)
{
new i, li;
new aNum;
new len;
while(i <= strlen(strsrc)){
if(strsrc[i]==delimiter || i==strlen(strsrc)){
len = strmid(strdest[aNum], strsrc, li, i, 128);
strdest[aNum][len] = 0;
li = i+1;
aNum++;
}
i++;
}
return 1;
}
forward ini_GetKey( line[] );
stock ini_GetKey( line[] )
{
new keyRes[256];
keyRes[0] = 0;
if ( strfind( line , "=" , true ) == -1 ) return keyRes;
strmid( keyRes , line , 0 , strfind( line , "=" , true ) , sizeof( keyRes) );
return keyRes;
}
forward ini_GetValue( line[] );
stock ini_GetValue( line[] )
{
new valRes[256];
valRes[0]=0;
if ( strfind( line , "=" , true ) == -1 ) return valRes;
strmid( valRes , line , strfind( line , "=" , true )+1 , strlen( line ) , sizeof( valRes ) );
return valRes;
}
public OnPlayerRequestClass(playerid, classid)
{
if(IsPlayerNPC(playerid))
{
SpawnPlayer(playerid);
return 1;
}
if (gPlayerLogged[playerid] != 1)
{
if (gPlayerAccount[playerid] != 1)
{
new loginstring[128];
new loginname[64];
GetPlayerName(playerid,loginname,sizeof(loginname));
format(loginstring,sizeof(loginstring),"Olб, e Bem-Vindo, %s!\nEste nome encontra-se registrado em nosso sistema.\nPor favor, digite sua senha:",loginname);
ShowPlayerDialog(playerid,12346,DIALOG_STYLE_INPUT,"Login",loginstring,"Login","Sair");
SendClientMessage(playerid, 0xFF6347AA, "ATENЗГO: Vocк serб kickado do servidor em 30 segundos se nгo fizer o login!");
}
if (gPlayerAccount[playerid] != 0)
{
SendClientMessage(playerid, 0x2641FEAA, "Imigraзгo: Por favor, cheque seus documentos para a inscriзгo.");
new regstring[128];
new regname[64];
GetPlayerName(playerid,regname,sizeof(regname));
format(regstring,sizeof(regstring),"Bem Vindo, %s!\nInfelizmente, vocк nгo estб registrado.\nPor favor, registre-se para poder jogar!",regname);
ShowPlayerDialog(playerid,12345,DIALOG_STYLE_INPUT,"Registrar",regstring,"Registrar","Sair");
}
SetPlayerCameraPos(playerid, 1890.1014,-1194.7969,25.8091);
SetPlayerCameraLookAt(playerid, 1933.4393,-1196.2479,18.8163);
}
else SpawnPlayer(playerid);
return false;
}
forward OnPlayerLogin(playerid,password[]);
public OnPlayerLogin(playerid,password[])
{
new string2[64];
new playername2[MAX_PLAYER_NAME];
new playernamesplit[3][MAX_PLAYER_NAME];
GetPlayerName(playerid, playername2, sizeof(playername2));
split(playername2, playernamesplit, '_');
format(string2, sizeof(string2), "LeLeTe/%s.ini", playername2);
new File: UserFile = fopen(string2, io_read);
if ( UserFile )
{
new PassData[128];
new keytmp[256], valtmp[256];
fread( UserFile , PassData , sizeof( PassData ) );
keytmp = ini_GetKey( PassData );
if( strcmp( keytmp , "sSenha" , true ) == 0 )
{
valtmp = ini_GetValue( PassData );
strmid(SuaDataBase[playerid][sSenha], valtmp, 0, strlen(valtmp)-1, 255);
}
if(strcmp(SuaDataBase[playerid][sSenha],password, true ) == 0 )
{
new key[ 256 ] , val[ 256 ];
new Data[ 256 ];
while ( fread( UserFile , Data , sizeof( Data ) ) )
{
key = ini_GetKey( Data );
if( strcmp( key , "sValor" , true ) == 0 ) { val = ini_GetValue( Data ); SuaDataBase[playerid][sValor] = strval( val ); }
if( strcmp( key , "sFloat" , true ) == 0 ) { val = ini_GetValue( Data ); SuaDataBase[playerid][sFloat] = floatstr( val ); }
if( strcmp( key , "sString" , true ) == 0 ) { val = ini_GetValue( Data ); strmid(SuaDataBase[playerid][sString], val, 0, strlen(val)-1, 255); }
}
fclose(UserFile);
}
}
}
public OnPlayerRegister(playerid, password[])
{
if(IsPlayerConnected(playerid))
{
new string3[64];
new playername3[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername3, sizeof(playername3));
format(string3, sizeof(string3), "LeLeTe/%s.ini", playername3);
new File: hFile = fopen(string3, io_write);
if (hFile)
{
strmid(SuaDataBase[playerid][sSenha], password, 0, strlen(password), 255);
new var[64];
format(var, 64, "sValor=%d\n", SuaDataBase[playerid][sValor]);fwrite(hFile, var);
format(var, 64, "sFloat=%1.f\n", SuaDataBase[playerid][sFloat]);fwrite(hFile, var);
format(var, 64, "sString=%s\n", SuaDataBase[playerid][sString]);fwrite(hFile, var);
fclose(hFile);
new loginstring[128];
new loginname[64];
GetPlayerName(playerid,loginname,sizeof(loginname));
format(loginstring,sizeof(loginstring),"Bem vindo, %s\nFзa seu login agora!",loginname);
ShowPlayerDialog(playerid,12346,DIALOG_STYLE_INPUT,"Logar",loginstring,"Logar","Exit");
}
}
return 1;
}
forward Encrypt(string[]);
public Encrypt(string[])
{
for(new x=0; x < strlen(string); x++)
{
string[x] += (3^x) * (x % 15);
if(string[x] > (0xff))
{
string[x] -= 256;
}
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
new string[128];
if(dialogid == 12345)
{
if(strlen(inputtext))
{
new sendername[MAX_PLAYER_NAME];
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "LeLeTe/%s.ini", sendername);
new File: hFile = fopen(string, io_read);
if (hFile)
{
SendClientMessage(playerid, 0xDABB3EAA, "Este nome jб existe! Escolha outro.");
fclose(hFile);
return 1;
}
new tmppass[64];
strmid(tmppass, inputtext, 0, strlen(inputtext), 255);
Encrypt(tmppass);
OnPlayerRegister(playerid,tmppass);
}
else
{
new regstring[128];
new regname[64];
GetPlayerName(playerid,regname,sizeof(regname));
format(regstring,sizeof(regstring),"Bem Vindo, %s!\nInfelizmente, vocк nгo estб registrado.\nPor favor, registre-se para poder jogar!",regname);
ShowPlayerDialog(playerid,12345,DIALOG_STYLE_INPUT,"Registrar",regstring,"Registrar","Sair");
}
}
if(dialogid == 12346 || dialogid == 12347)
{
if(strlen(inputtext))
{
new tmppass[64];
strmid(tmppass, inputtext, 0, strlen(inputtext), 255);
Encrypt(tmppass);
OnPlayerLogin(playerid,tmppass);
}
else
{
new loginstring[128];
new loginname[64];
GetPlayerName(playerid,loginname,sizeof(loginname));
format(loginstring,sizeof(loginstring),"Senha errada\nPor favor coloque a senha corretamente.",loginname);
ShowPlayerDialog(playerid,12347,DIALOG_STYLE_INPUT,"Login",loginstring,"Login","Exit");
gPlayerLogTries[playerid] += 1;
if(gPlayerLogTries[playerid] == 4) { Ban(playerid); }
}
}
return 1;
}
public OnFilterScriptExit()
{
return 1;
}