21.12.2013, 22:01
Hy guys,
I've a little problem while learning the pawn. I made a register/login system with one tutorial from this forum but forgot wich one exactly.
So that is my problem, YSI is creating a file, put the hashed password inside but in this file money = 0 and skin = 0, i don't know why cause i writted Money = 500 and Skin = 26 during register step.
Here is my code :
EDIT : The indentation is really horrible on a copy/paste code :O Maybe some people will prefer pastebin
Really sorry for my bad english and thank you for your help.
I've a little problem while learning the pawn. I made a register/login system with one tutorial from this forum but forgot wich one exactly.
So that is my problem, YSI is creating a file, put the hashed password inside but in this file money = 0 and skin = 0, i don't know why cause i writted Money = 500 and Skin = 26 during register step.
Here is my code :
EDIT : The indentation is really horrible on a copy/paste code :O Maybe some people will prefer pastebin
Код:
// ---------------------------------- // | | // | Includes gйnйraux | // | | // ---------------------------------- #include <a_samp> #include <YSI\y_ini> #include <sscanf2> #include <zcmd> // ---------------------------------- // | | // | Defines gйnйraux | // | | // ---------------------------------- #define COLOR_ARED 0xFF0000AA // ---------------------------------- // | | // | Partie login | // | | // ---------------------------------- #define dregister 2011 #define dlogin 2012 #define UserPath "Users/%s.ini" native WP_Hash(buffer[], len, const str[]); enum PlayerInfo { Pass[129], AdminLevel, VIPLevel, Money, Skin } new pInfo[MAX_PLAYERS][PlayerInfo]; new aDuty[MAX_PLAYERS]; stock Path(playerid) { new str[128],name[MAX_PLAYER_NAME]; GetPlayerName(playerid,name,sizeof(name)); format(str,sizeof(str),UserPath,name); return str; } forward LoadAccount_User(playerid, name[], value[]); public LoadAccount_User(playerid, name[], value[]) { INI_String("Password", pInfo[playerid][Pass], 129); INI_Int("AdminLevel", pInfo[playerid][AdminLevel]); INI_Int("VIPLevel", pInfo[playerid][VIPLevel]); INI_Int("Money", pInfo[playerid][Money]); INI_Int("Skin", pInfo[playerid][Skin]); return 1; } main() { print("\n----------------------------------"); print(" Blank Gamemode by your name here"); print("----------------------------------\n"); } public OnGameModeInit() { // A modifier pour retenir la derniиre position au lieu de ramener au spawn gйnйral SetGameModeText("Blank Script"); return 1; } OnGameModeExit() { return 1; } public OnPlayerConnect(playerid) { new name[MAX_PLAYER_NAME]; aDuty[playerid] = 0; GetPlayerName(playerid, name, sizeof(name)); if(fexist(Path(playerid))) // On est si l'utilisateur est dйjа enregistrй { INI_ParseFile(Path(playerid),"LoadAccount_%s", .bExtra = true, .extra = playerid); // Si oui on charge les infos et on demande le mdp ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","De retour ! Ce compte est enregistrй, entrez votre mot de passe pour commencer.","Login","Quitter"); } else { ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Bienvenue, ce compte n'est pas enregistrй. Entrez votre mot de passe.","Enregistrer","Quitter"); // Sinon on crйe un new compte return 1; } AddPlayerClass(pInfo[playerid][Skin], 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0); return 1; } public OnPlayerRequestClass(playerid, classid) { SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746); SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746); SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746); SetSpawnInfo(playerid, 0, pInfo[playerid][Skin], 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0); SpawnPlayer(playerid); return 1; } public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { if(dialogid == dregister) { if(!response) return Kick(playerid); // Si la personne clique sur "Quitter" => kick if(response) // Sinon on l'enregistre { if(!strlen(inputtext)) { ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Bienvenue! Votre compte n'existe pas encore.\nVotre mot de passe est strictement personnel.\nEntrez le mdp svp","Enregistrer","Quitter"); return 1; } // Si le mot de passe est correct, on le chiffre et on lui crйe son compte new hashpass[129]; hashpass = udb_hash(inputtext); new INI:file = INI_Open(Path(playerid)); INI_SetTag(file,"Infos joueur"); INI_WriteString(file,"Password",hashpass); INI_WriteInt(file,"AdminLevel",0); INI_WriteInt(file,"VIPLevel",0); INI_WriteInt(file,"Money",500); INI_WriteInt(file,"Skin",26); INI_Close(file); SendClientMessage(playerid,-1,"Enregistrement rйussi !"); return 1; } } if(dialogid == dlogin) // Si c'est une tentative de login { if(!response) return Kick(playerid); if(response) { new hashpass[129]; WP_Hash(hashpass,sizeof(hashpass),inputtext); if(!strcmp(hashpass, pInfo[playerid][Pass], false)) { INI_ParseFile(Path(playerid),"LoadAccount_%s",.bExtra = true, .extra = playerid);// Chargement de toutes les infos GivePlayerMoney(playerid,pInfo[playerid][Money]); SetPlayerSkin(playerid,pInfo[playerid][Skin]); SendClientMessage(playerid,-1,"Connexion rйussie, bon jeu !"); } else // si mdp incorrect { ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Mot de passe incorrect pour ce compte !\nVeuillez rйessayer.","Login","Quitter");//We will tell to them that they've entered an incorrect password return 1; } } } return 1; } public OnPlayerDisconnect(playerid, reason) { new INI:file = INI_Open(Path(playerid)); aDuty[playerid] = 0; SetPlayerSkin(playerid, pInfo[playerid][Skin]); INI_SetTag(file,"Infos joueur"); INI_WriteInt(file,"AdminLevel",pInfo[playerid][AdminLevel]); INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPLevel]); INI_WriteInt(file,"Money",GetPlayerMoney(playerid)); INI_WriteInt(file,"Skin",GetPlayerSkin(playerid)); INI_Close(file); return 1; } public OnRconLoginAttempt(ip[], password[], success) { new pip[16]; for(new i = 0 ; i < MAX_PLAYERS ; i++) { GetPlayerIp(i, pip, sizeof(pip)); if(!strcmp(ip, pip, true)) { SendClientMessageToAll(0xFFFFFFFF,"Un joueur a йtй kickй pour avoir tentй de se connectй au Rcon"); PlayerPlaySound(i, 1141, 0.0, 0.0, 0.0); Kick(i); } } return 1; } // ---------------------------------- // | | // | Commandes | // | | // ---------------------------------- CMD:aduty(playerid) { new name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name,sizeof(name)); if(pInfo[playerid][AdminLevel] >=1) { if (aDuty[playerid] == 0) { new string[128]; new Float:x,Float:y,Float:z; new Text3D:label = Create3DTextLabel("Admin On Duty!", COLOR_ARED,x,y,z, 40.0, 0, 0); GetPlayerPos(playerid,x,y,z); SetPlayerHealth(playerid,999999); SetPlayerColor(playerid,COLOR_ARED); SetPlayerSkin(playerid,217); format(string,sizeof(string), "%s est en mode admin!",name); SendClientMessageToAll(COLOR_ARED,string); SendClientMessage(playerid,COLOR_ARED,"Vous кtes en mode admin"); Attach3DTextLabelToPlayer(label,playerid,0.0, 0.0, 0.7); aDuty[playerid] = 1; } else if (aDuty[playerid] == 1) { new Float:x,Float:y,Float:z; new Text3D:label = Create3DTextLabel("Admin On Duty!", COLOR_ARED,x,y,z, 40.0, 0, 0); Delete3DTextLabel(label); SetPlayerHealth(playerid,100); SetPlayerSkin(playerid, pInfo[playerid][Skin]); SendClientMessage(playerid, COLOR_ARED,"Vous кtes en mode normal"); aDuty[playerid] = 0; } } else SendClientMessage(playerid,COLOR_ARED,"Vous n'avez pas le pouvoir de faire зa!"); return 1; }