Advertisement
Parix

Mammt è a mij

Oct 17th, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1.  
  2. #define PATH "Utenza/%s.ini" // definisco la directory dove verra salvato il file ini riguardante il singolo giocatore
  3.  
  4. forward Spawn(playerid);
  5. forward CaricaDatiUtente(playerid,name[],value[]); //forward della funzione CaricaDatiUtente a finchè possa essere ricordata
  6.  
  7. new Loggato[MAX_PLAYERS];
  8.  
  9. stock ClearChat(playerid, times) //Pulisce la chat al giocatore
  10. {
  11. for(new j=0; j<times; j++)
  12. {
  13. SendClientMessage(playerid, -1, "");
  14. }
  15. return 1;
  16. }
  17.  
  18. stock PathUtente(playerid)// Creo una funzione di immagazinamento per i file dati del singolo utente
  19. {
  20. new stringa[128],nomeplayer[MAX_PLAYER_NAME]; //Dichiaro una stringa grande 128, e nomeplayer grande il massimo possibile per il nome di un giocatore
  21. GetPlayerName(playerid,nomeplayer,sizeof(nomeplayer)); //Getto il nome del player nella mia variabile nomeplayer
  22. format(stringa,sizeof(stringa),PATH,nomeplayer); //formatto una stringa che sarà l'equivalente di nomeplayer nel PATH di destinazione
  23. return stringa; //Quindi ritorno la stringa
  24. }
  25.  
  26. enum Utente // definisco un contenitore enum che conterrà le informazione del singolo giocatore
  27. {
  28. Password, // contenitore della password
  29. Soldi, // contenitore dei soldi
  30. Skin, //contenitore della skin
  31. Admin // contenitore del livello admin
  32. }
  33. new Info[MAX_PLAYERS][Utente];
  34.  
  35. // Credits to Dracoblue - la funzione d'immagazzinamento serve per creare una stringra criptata.
  36.  
  37. stock udb_hash(buf[])
  38. {
  39. new length=strlen(buf);
  40. new s1 = 1;
  41. new s2 = 0;
  42. new n;
  43. for (n=0; n<length; n++)
  44. {
  45. s1 = (s1 + buf[n]) % 65521;
  46. s2 = (s2 + s1) % 65521;
  47. }
  48. return (s2 << 16) + s1;
  49. }
  50.  
  51. public CaricaDatiUtente(playerid,name[],value[])
  52. {
  53. INI_Int("Password",Info[playerid][Password]); //INI_Int legge l'intero salvato nel contenitore gPassword,
  54. INI_Int("Soldi",Info[playerid][Soldi]);
  55. INI_Int("Skin",Info[playerid][Skin]);
  56. INI_Int("LivelloAdmin",Info[playerid][Admin]);
  57. return 1;
  58. }
  59.  
  60. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  61. {
  62. switch(dialogid)
  63. {
  64. case 1: //Login
  65. {
  66. if(!response)
  67. {
  68. Kick(playerid);
  69. }
  70. if(response)
  71. {
  72. if(strlen(inputtext) < 3 || strlen(inputtext) > 12) return ShowPlayerDialog(playerid,Registrazione,DIALOG_STYLE_INPUT,"Registrazione!","La tua password deve avere minimo 3 caratteri e massimo 12!","Registrati!","Esci");
  73. new INI:File = INI_Open(PathUtente(playerid)); // inizio la scrittura del file ini all'interno della directori utenza
  74. INI_SetTag(File,"Informazioni Account"); // Do un intestazione al file ini
  75. INI_WriteInt(File,"Password",udb_hash(inputtext)); //Scrivo la Password data dall'utente e con la funzione udb_hash la cripto
  76. INI_WriteInt(File,"Soldi",0); // Scrivo i soldi del player
  77. INI_WriteInt(File,"Skin", 0); // Scrivo la skin del player
  78. INI_WriteInt(File,"Admin",0); //Scrivo il livello di admin
  79. INI_Close(File);
  80. }
  81. }
  82.  
  83. case 2: //Registrazione
  84. {
  85. if(!response)
  86. {
  87. Kick(playerid);
  88. }
  89. if(response)
  90. {
  91. if(udb_hash(inputtext) == Info[playerid][Password])
  92. {
  93. INI_ParseFile(PathUtente(playerid),"CaricamentoDatiUtente_%s", .bExtra = true, .extra = playerid);
  94. GivePlayerMoney(playerid,Info[playerid][Soldi]);
  95. SetPlayerSkin(playerid,Info[playerid][Skin]);
  96. Loggato[playerid] = 1;
  97. SendClientMessage(playerid, Azzurro, "Hai loggato con successo!");
  98. }
  99. }
  100. }
  101. }
  102. return 1;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement