Guest User

sistema de registro

a guest
Aug 18th, 2010
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.31 KB | None | 0 0
  1. #include <a_samp>
  2. #include <Dini>
  3. #include <DUDB>
  4.  
  5. #define GREEN 0x21DD00FF
  6. #define RED 0xE60000FF
  7. #define ADMIN_RED 0xFB0000FF
  8. #define YELLOW 0xFFFF00FF
  9. #define ORANGE 0xF97804FF
  10. #define LIGHTRED 0xFF8080FF
  11. #define LIGHTBLUE 0x00C2ECFF
  12. #define PURPLE 0xB360FDFF
  13. #define PLAYER_COLOR 0xFFFFFFFF
  14. #define BLUE 0x1229FAFF
  15. #define LIGHTGREEN 0x38FF06FF
  16. #define DARKPINK 0xE100E1FF
  17. #define DARKGREEN 0x008040FF
  18. #define ANNOUNCEMENT 0x6AF7E1FF
  19. #define COLOR_SYSTEM 0xEFEFF7AA
  20. #define GREY 0xCECECEFF
  21. #define PINK 0xD52DFFFF
  22. #define DARKGREY 0x626262FF
  23. #define AQUAGREEN 0x03D687FF
  24. #define NICESKY 0x99FFFFAA
  25. #define WHITE 0xFFFFFFFF
  26. //**MISC**//
  27. #define ACCOUNTS_FOLDER "%s.ini"
  28. #define LOGAR_DELAY 3 // Seconds. Default = 3 seconds
  29. //**VARIABLES**//
  30. forward OnPlayerDisconnect(playerid, reason)
  31. enum aInfo
  32. {
  33. aPassword[2],
  34. aLogged,
  35.  
  36. };
  37. enum jInfo //Adicione aqui novas Vars, como exemplo: jChaveDaCasa;
  38. {
  39. jArma1,
  40. jArma2,
  41. jArma3,
  42. jArma4,
  43. jArma5,
  44. jArma6,
  45. jArma7,
  46. jArma8,
  47. jArma9,
  48. jArma10,
  49. jArma11,
  50. jMunicao1,
  51. jMunicao2,
  52. jMunicao3,
  53. jMunicao4,
  54. jMunicao5,
  55. jMunicao6,
  56. jMunicao7,
  57. jMunicao8,
  58. jMunicao9,
  59. jMunicao10,
  60. jMunicao11,
  61. jChaveDoCarro,
  62. //jString[Tamanho_Da_String], //Exemplo de como definir uma nova string
  63. //Float:jFloat, //Exemplo de como definir um novo float. Notem que o nome da variavel, no caso "jFloat", deve ser escrita DEPOIS de Float:
  64. //jVar, //Exemplo de como definir uma nova variável(var)
  65. }
  66.  
  67. };
  68. new PlayerInfo[MAX_PLAYERS][pInfo];
  69. new AccountInfo[MAX_PLAYERS][aInfo];
  70. new Registrar[MAX_PLAYERS];
  71. new LOGAR[MAX_PLAYERS];
  72. forward login(playerid);
  73. forward OnPlayerUpdate(playerid);
  74. /*x---------------------------------CallBacks-------------------------------------x*/
  75. public OnGameModeInit()
  76. {
  77. SendRconCommand("reloadfs Seifistration");
  78. return 1;
  79. }
  80. public OnPlayerDisconnect(playerid, reason)
  81. {
  82. OnPlayerUpdate(playerid);
  83. AccountInfo[playerid][aLogged] = 0;
  84. Registrar[playerid] = 0;
  85. LOGAR[playerid] = 0;
  86. return 1;
  87. }
  88.  
  89. public OnPlayerConnect(playerid)
  90. {
  91. SetPlayerTime(playerid,04,0);
  92. new name[MAX_PLAYER_NAME];
  93. GetPlayerName(playerid, name, sizeof(name));
  94. new string[128];
  95. format(string, sizeof(string), ACCOUNTS_FOLDER, name);
  96. if (AccountInfo[playerid][aLogged] == 0)
  97. {
  98. if (!fexist(string))
  99. {
  100. new kayitmsg[256];
  101. format(kayitmsg,256,"Bem Vindo ao Server\n\n%s please open a new account\n\nEnter the new password:",name);
  102. ShowPlayerDialog(playerid,12345,DIALOG_STYLE_INPUT,"Registrar",kayitmsg,"Registrar","Sair");
  103. Registrar[playerid] = 1;
  104. LOGAR[playerid] = 0;
  105. }
  106. else if (fexist(string))
  107. {
  108. new girismsg[256];
  109. format(girismsg,256,"Bem Vindo ao Server\n\nNick: %s\n\nDigite a sua senha:",name);
  110. ShowPlayerDialog(playerid,12346,DIALOG_STYLE_INPUT,"Logar",girismsg,"Logar","Sair");
  111. Registrar[playerid] = 0;
  112. LOGAR[playerid] = 1;
  113. }
  114. }
  115. return 1;
  116. }
  117.  
  118. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  119. {
  120. if (response == 1)
  121. {
  122. if(dialogid == 12345)
  123. {
  124. if(strlen(inputtext))
  125. {
  126. Encrypt(inputtext);
  127. new player[MAX_PLAYER_NAME];
  128. GetPlayerName(playerid, player, 50);
  129. new string3[32];
  130. new playername3[MAX_PLAYER_NAME];
  131. GetPlayerName(playerid, playername3, sizeof(playername3));
  132. format(string3, sizeof(string3), ACCOUNTS_FOLDER, playername3);
  133. new ip[20];
  134. GetPlayerIp(playerid,ip,sizeof(ip));
  135. new File: hFile = fopen(string3, io_write);
  136. if (hFile)
  137. {
  138. strmid(AccountInfo[playerid][aPassword], inputtext, 0, strlen(inputtext), 255);
  139. new var[128];
  140. format(var, 128, "Senha=%s\n", PlayerInfo[playerid][pSenha]);fwrite(hFile, var);
  141. format(var, 128, "IP=%s\n",ip);fwrite(hFile, var);
  142. fclose(hFile);
  143. printf("%s is signed up.",playername3);
  144. SendClientMessage(playerid, GREEN, "|- Have you Registrared. You can LOGAR now. -|");
  145. new girismsg[256];
  146. format(girismsg,256,"Welcome to the server\n\nUser Name: %s\n\nEnter your password:",playername3);
  147. ShowPlayerDialog(playerid,12346,DIALOG_STYLE_INPUT,"LOGAR",girismsg,"LOGAR","Sair");
  148. Registrar[playerid] = 0;
  149. LOGAR[playerid] = 1;
  150. }
  151. }
  152. else if(!strlen(inputtext))
  153. {
  154. new name[MAX_PLAYER_NAME];
  155. GetPlayerName(playerid, name, sizeof(name));
  156. new kayitmsg[256];
  157. format(kayitmsg,256,"Welcome to the server\n\n%s please open a new account\n\nEnter the new password:",name);
  158. ShowPlayerDialog(playerid,12345,DIALOG_STYLE_INPUT,"Registrar",kayitmsg,"Registrar","Sair");
  159. Registrar[playerid] = 1;
  160. LOGAR[playerid] = 0;
  161. }
  162. }
  163. if(dialogid == 12346)
  164. {
  165. Encrypt(inputtext);
  166. new string2[128];
  167. new playername2[MAX_PLAYER_NAME];
  168. GetPlayerName(playerid, playername2, sizeof(playername2));
  169. format(string2, sizeof(string2), ACCOUNTS_FOLDER, playername2);
  170. new File: UserFile = fopen(string2, io_read);
  171. if ( UserFile )
  172. {
  173. new PassData[256];
  174. new keytmp[256], valtmp[256];
  175. fread( UserFile , PassData , sizeof( PassData ) );
  176. keytmp = ini_GetKey( PassData );
  177. if( strcmp( keytmp , "Password" , true ) == 0 )
  178. {
  179. valtmp = ini_GetValue( PassData );
  180. strmid(AccountInfo[playerid][aPassword], valtmp, 0, strlen(valtmp)-1, 255);
  181. }
  182. if(strcmp(AccountInfo[playerid][aPassword],inputtext, true ) == 0)
  183. {
  184. if(strlen(inputtext))
  185. {
  186. for(new p = 0; p < strlen(AccountInfo[playerid][aPassword]); p++)
  187. {
  188. inputtext[p] = '?';
  189. }
  190. SetTimerEx("LOGAR", LOGAR_DELAY*1000, 0, "d", playerid);
  191. printf("%s is logged in.",playername2);
  192. new key[256];
  193. new Data[256];
  194. while ( fread( UserFile , Data , sizeof( Data ) ) )
  195.  
  196. {
  197. key = ini_GetKey( Data );
  198. /*if(strcmp(key, "AdminLevel", true) == 0) // This is only an example if you want to add more stuff to store in a file.
  199.  
  200. {
  201. val = ini_GetValue( Data );
  202. AccountInfo[playerid][AdminLevel] = strval(val); // Uncommenting this will give you errors if the variable isn't defined.
  203.  
  204. }
  205. */
  206.  
  207. }
  208. fclose(UserFile);
  209. }
  210. }
  211. else
  212. {
  213. if(strlen(inputtext))
  214. {
  215. new girismsg[256];
  216. printf("%s is used the wrong password.",playername2);
  217. format(girismsg,256,"WRONG PASSWORD\n\nPlease enter your password:");
  218. ShowPlayerDialog(playerid,12347,DIALOG_STYLE_INPUT,"LOGAR",girismsg,"LOGAR","Sair");
  219. LOGAR[playerid] = 1;
  220. Registrar[playerid] = 0;
  221. fclose(UserFile);
  222. return 1;
  223. }
  224. }
  225. if(!strlen(inputtext))
  226. {
  227. new girismsg[256];
  228. printf("%s did not enter the password.",playername2);
  229. format(girismsg,256,"WRONG PASSWORD\n\nPlease enter your password:");
  230. ShowPlayerDialog(playerid,12347,DIALOG_STYLE_INPUT,"LOGAR",girismsg,"LOGAR","Sair");
  231. LOGAR[playerid] = 1;
  232. Registrar[playerid] = 0;
  233. fclose(UserFile);
  234. return 1;
  235. }
  236. }
  237. }
  238. if(dialogid == 12347)
  239. {
  240. Encrypt(inputtext);
  241. new string2[128];
  242. new playername2[MAX_PLAYER_NAME];
  243. GetPlayerName(playerid, playername2, sizeof(playername2));
  244. format(string2, sizeof(string2), ACCOUNTS_FOLDER, playername2);
  245. new File: UserFile = fopen(string2, io_read);
  246. if ( UserFile )
  247. {
  248. new PassData[256];
  249. new keytmp[256], valtmp[256];
  250. fread( UserFile , PassData , sizeof( PassData ) );
  251. keytmp = ini_GetKey( PassData );
  252. if( strcmp( keytmp , "Password" , true ) == 0 )
  253. {
  254. valtmp = ini_GetValue( PassData );
  255. strmid(AccountInfo[playerid][aPassword], valtmp, 0, strlen(valtmp)-1, 255);
  256. }
  257. if(strcmp(AccountInfo[playerid][aPassword],inputtext, true ) == 0)
  258. {
  259. if(strlen(inputtext))
  260. {
  261. for(new p = 0; p < strlen(AccountInfo[playerid][aPassword]); p++)
  262. {
  263. inputtext[p] = '?';
  264. }
  265. SetTimerEx("LOGAR", LOGAR_DELAY*1000, 0, "d", playerid);
  266. printf("%s is logged in.",playername2);
  267. new key[256];
  268. new Data[256];
  269. while ( fread( UserFile , Data , sizeof( Data ) ) )
  270.  
  271. {
  272. key = ini_GetKey( Data );
  273. /*if(strcmp(key, "AdminLevel", true) == 0) // This is only an example if you want to add more stuff to store in a file.
  274.  
  275. {
  276. val = ini_GetValue( Data );
  277. AccountInfo[playerid][AdminLevel] = strval(val); // Uncommenting this will give you errors if the variable isn't defined.
  278.  
  279. }
  280. */
  281.  
  282. }
  283. fclose(UserFile);
  284. }
  285. }
  286. else
  287. {
  288. if(strlen(inputtext))
  289. {
  290. new girismsg[256];
  291. printf("%s is used the wrong password.",playername2);
  292. format(girismsg,256,"WRONG PASSWORD\n\nPlease enter your password:");
  293. ShowPlayerDialog(playerid,12347,DIALOG_STYLE_INPUT,"LOGAR",girismsg,"LOGAR","Sair");
  294. LOGAR[playerid] = 1;
  295. Registrar[playerid] = 0;
  296. fclose(UserFile);
  297. return 1;
  298. }
  299. }
  300. if(!strlen(inputtext))
  301. {
  302. new girismsg[256];
  303. printf("%s did not enter the password.",playername2);
  304. format(girismsg,256,"WRONG PASSWORD\n\nPlease enter your password:");
  305. ShowPlayerDialog(playerid,12347,DIALOG_STYLE_INPUT,"LOGAR",girismsg,"LOGAR","Sair");
  306. LOGAR[playerid] = 1;
  307. Registrar[playerid] = 0;
  308. fclose(UserFile);
  309. return 1;
  310. }
  311. }
  312.  
  313. }
  314. }
  315. else return Kick(playerid);
  316. return 0;
  317. }
  318.  
  319. public OnPlayerDeath(playerid, killerid, reason)
  320. {
  321. return 1;
  322. }
  323.  
  324. public OnVehicleSpawn(vehicleid)
  325. {
  326. return 1;
  327. }
  328.  
  329. public OnVehicleDeath(vehicleid, killerid)
  330. {
  331. return 1;
  332. }
  333.  
  334. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  335. {
  336. return 1;
  337. }
  338.  
  339. public OnPlayerExitVehicle(playerid, vehicleid)
  340. {
  341. return 1;
  342. }
  343.  
  344. public OnPlayerStateChange(playerid, newstate, oldstate)
  345. {
  346. return 1;
  347. }
  348.  
  349. public OnPlayerEnterCheckpoint(playerid)
  350. {
  351. return 1;
  352. }
  353.  
  354. public OnPlayerLeaveCheckpoint(playerid)
  355. {
  356. return 1;
  357. }
  358.  
  359. public OnPlayerEnterRaceCheckpoint(playerid)
  360. {
  361. return 1;
  362. }
  363.  
  364. public OnPlayerLeaveRaceCheckpoint(playerid)
  365. {
  366. return 1;
  367. }
  368.  
  369. public OnRconCommand(cmd[])
  370. {
  371. return 1;
  372. }
  373.  
  374. public OnObjectMoved(objectid)
  375. {
  376. return 1;
  377. }
  378.  
  379. public OnPlayerObjectMoved(playerid, objectid)
  380. {
  381. return 1;
  382. }
  383.  
  384. public OnPlayerPickUpPickup(playerid, pickupid)
  385. {
  386. return 1;
  387. }
  388.  
  389. public OnPlayerSelectedMenuRow(playerid, row)
  390. {
  391. return 1;
  392. }
  393.  
  394. public OnPlayerExitedMenu(playerid)
  395. {
  396. return 1;
  397. }
  398.  
  399. stock ini_GetKey( line[] )
  400. {
  401. new keyRes[256];
  402. keyRes[0] = 0;
  403. if ( strfind( line , "=" , true ) == -1 ) return keyRes;
  404. strmid( keyRes , line , 0 , strfind( line , "=" , true ) , sizeof( keyRes) );
  405. return keyRes;
  406. }
  407.  
  408. stock ini_GetValue( line[] )
  409. {
  410. new valRes[256];
  411. valRes[0]=0;
  412. if ( strfind( line , "=" , true ) == -1 ) return valRes;
  413. strmid( valRes , line , strfind( line , "=" , true )+1 , strlen( line ) , sizeof( valRes ) );
  414. return valRes;
  415. }
  416.  
  417. public login(playerid)
  418. {
  419. AccountInfo[playerid][aLogged] = 1;
  420. Registrar[playerid] = 0;
  421. LOGAR[playerid] = 0;
  422. return 1;
  423. }
  424.  
  425. public OnPlayerUpdate(playerid)
  426. {
  427. if(IsPlayerConnected(playerid))
  428. {
  429. if(AccountInfo[playerid][aLogged] == 1)
  430. {
  431. new string3[128];
  432. new playername3[MAX_PLAYER_NAME];
  433. GetPlayerName(playerid, playername3, sizeof(playername3));
  434. format(string3, sizeof(string3), ACCOUNTS_FOLDER, playername3);
  435. new ip[20];
  436. GetPlayerIp(playerid,ip,sizeof(ip));
  437. new File: hFile = fopen(string3, io_write);
  438. if (hFile)
  439. {
  440. new var[128];
  441. format(var, 128, "Password=%s\n", AccountInfo[playerid][aPassword]);fwrite(hFile, var);
  442. format(var, 128, "IP=%s\n",ip);fwrite(hFile, var);
  443. format(var, 32, "TempoOn=%d\n",PlayerInfo[playerid][pConnectTime]);fwrite(hFile, var);
  444. format(var, 32, "Dinheiro=%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var);
  445. fclose(hFile);
  446. }
  447. }
  448. }
  449. return 1;
  450. }
  451.  
  452. Encrypt(string[])
  453. {
  454. for(new x=0; x < strlen(string); x++)
  455. {
  456. string[x] += (3^x) * (x % 15);
  457. if(string[x] > (0xff))
  458. {
  459. string[x] -= 256;
  460. }
  461. }
  462. }
  463.  
  464. stock PlayerName(playerid)
  465. {
  466. new Name[MAX_PLAYERS];
  467. GetPlayerName(playerid, Name, sizeof(Name));
  468. return Name;
  469. }
Advertisement
Add Comment
Please, Sign In to add comment