Guest User

Dopey

a guest
Jul 23rd, 2009
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.51 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #define FILTERSCRIPT
  4.  
  5. #if defined FILTERSCRIPT
  6. #define COLOR_GREY 0xBEBEBEAA
  7. #define COLOR_WHITE 0xFFFFFFAA
  8. #define COLOR_GREEN 0x33AA33AA
  9. #define COLOR_GRAD5 0xE3E3E3FF
  10. #define COLOR_GRAD1 0xB4B5B7FF
  11.  
  12. forward ShowStats(playerid,targetid);
  13. forward OnPlayerUpdate(playerid);
  14. forward Encrypt(string[]);
  15. forward OnPlayerLogin(playerid,const string[]);
  16.  
  17. enum pInfo
  18. {
  19. pPassword[128],
  20. pKills,
  21. pDeaths,
  22. pCash,
  23. };
  24.  
  25. new PlayerInfo[MAX_PLAYERS][pInfo];
  26. new gPlayerLogged[MAX_PLAYERS];
  27. new gPlayerAccount[MAX_PLAYERS];
  28.  
  29.  
  30. public OnFilterScriptInit()
  31. {
  32. print("\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
  33. print(" Kevin433's Login/Register Filterscript");
  34. print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
  35. return 1;
  36. }
  37.  
  38. public OnFilterScriptExit()
  39. {
  40. return 1;
  41. }
  42.  
  43. public OnPlayerRequestClass(playerid, classid)
  44. {
  45. return 1;
  46. }
  47.  
  48. public OnPlayerRequestSpawn(playerid)
  49. {
  50. return 1;
  51. }
  52.  
  53. public OnPlayerConnect(playerid)
  54. {
  55. return 1;
  56. }
  57.  
  58. public OnPlayerDisconnect(playerid, reason)
  59. {
  60. OnPlayerUpdate(playerid);
  61. gPlayerLogged[playerid] = 0;
  62. return 1;
  63. }
  64.  
  65. public OnPlayerSpawn(playerid)
  66. {
  67. return 1;
  68. }
  69.  
  70. public OnPlayerDeath(playerid, killerid, reason)
  71. {
  72. new kills = PlayerInfo[playerid][pKills];
  73. SetPlayerScore(playerid, kills);
  74. new Float:Health;
  75. GetPlayerHealth(playerid, Health);
  76. if(Health == 0.0)
  77. {
  78. PlayerInfo[playerid][pDeaths] += 1;
  79. }
  80. GivePlayerMoney(killerid,2000);
  81. PlayerInfo[killerid][pKills] = PlayerInfo[killerid][pKills] + 1;
  82. return 1;
  83. }
  84.  
  85. public OnPlayerCommandText(playerid, cmdtext[])
  86. {
  87. new cmd[256];
  88. new idx;
  89. cmd = strtok(cmdtext, idx);
  90. new tmp[256];
  91. new playername[MAX_PLAYER_NAME];
  92. if (strcmp(cmd, "/login", true) ==0 )
  93. {
  94. if(IsPlayerConnected(playerid))
  95. {
  96. new tmppass[64];
  97. if(gPlayerLogged[playerid] == 1)
  98. {
  99. SendClientMessage(playerid, COLOR_GREY, " You are already logged in.");
  100. return 1;
  101. }
  102. tmp = strtok(cmdtext, idx);
  103. if(!strlen(tmp))
  104. {
  105. SendClientMessage(playerid, COLOR_GREY, " USAGE: /login [password]");
  106. return 1;
  107. }
  108. strmid(tmppass, tmp, 0, strlen(cmdtext), 255);
  109. Encrypt(tmppass);
  110. OnPlayerLogin(playerid,tmppass);
  111. }
  112. return 1;
  113. }
  114. else if (strcmp(cmd, "/register", true)==0)
  115. {
  116. new string[265];
  117. tmp = strtok(cmdtext, idx);
  118. if(!strlen(tmp))
  119. {
  120. SendClientMessage(playerid, COLOR_GREY, "USAGE: /register [password]");
  121. return 1;
  122. }
  123. if (gPlayerAccount[playerid] == 1)
  124. {
  125. SendClientMessage(playerid, COLOR_GREY, " That name is already registered");
  126. return 1;
  127. }
  128.  
  129. strmid(PlayerInfo[playerid][pPassword], tmp, 0, strlen(cmdtext), 255);
  130. Encrypt(PlayerInfo[playerid][pPassword]);
  131. GetPlayerName(playerid, playername, sizeof(playername));
  132. format(string, sizeof(string), "%s.cer", playername);
  133. new File: file = fopen(string, io_read);
  134. if (file)
  135. {
  136. SendClientMessage(playerid, COLOR_GREY, " That name is already registered");
  137. fclose(file);
  138. return 1;
  139. }
  140. new File:hFile;
  141. hFile = fopen(string, io_append);
  142. new var[32];//
  143. format(var, 32, "%s\n", PlayerInfo[playerid][pPassword]);fwrite(hFile, var);
  144. format(var, 32, "Kills=%d\n",PlayerInfo[playerid][pKills]);fwrite(hFile, var);
  145. format(var, 32, "Deaths=%d\n",PlayerInfo[playerid][pDeaths]);fwrite(hFile, var);
  146. PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
  147. format(var, 32, "Money=%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var);
  148. fclose(hFile);
  149. SendClientMessage(playerid, COLOR_WHITE, "Succesfully Registered!");
  150. SendClientMessage(playerid, COLOR_WHITE, "Next time you connect, type /login <password> to log in.");
  151. OnPlayerLogin(playerid,PlayerInfo[playerid][pPassword]);
  152. return 1;
  153. }
  154. if (strcmp(cmd, "/stats", true) == 0)
  155. {
  156. if(IsPlayerConnected(playerid))
  157. {
  158. if (gPlayerLogged[playerid] != 0)
  159. {
  160. ShowStats(playerid,playerid);
  161. }
  162. else
  163. {
  164. SendClientMessage(playerid, COLOR_GRAD1, " You are not Logged in !");
  165. }
  166. }
  167. return 1;
  168. }
  169. return 0;
  170. }
  171.  
  172. public Encrypt(string[])
  173. {
  174. for(new x=0; x < strlen(string); x++)
  175. {
  176. string[x] += (3^x) * (x % 15);
  177. if(string[x] > (0xff))
  178. {
  179. string[x] -= 64;
  180. }
  181. }
  182. return 1;
  183. }
  184.  
  185.  
  186. public OnPlayerLogin(playerid,const string[])
  187. {
  188. new pname2[MAX_PLAYER_NAME];
  189. new pname3[MAX_PLAYER_NAME];
  190. new string2[64];
  191. new string3[128];
  192. GetPlayerName(playerid, pname2, sizeof(pname2));
  193. format(string2, sizeof(string2), "%s.cer", pname2);
  194. new File: UserFile = fopen(string2, io_read);
  195.  
  196. if (UserFile)
  197. {
  198. new valtmp[128];
  199. fread(UserFile, valtmp);strmid(PlayerInfo[playerid][pPassword], valtmp, 0, strlen(valtmp)-1, 255);
  200.  
  201. if ((strcmp(PlayerInfo[playerid][pPassword], string, true, strlen(valtmp)-1) == 0))
  202. {
  203. new key[128],val[128];
  204. new Data[128];
  205. while(fread(UserFile,Data,sizeof(Data)))
  206. {
  207. key = ini_GetKey(Data);
  208. if( strcmp( key , "Kills" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pKills] = strval( val ); }
  209. if( strcmp( key , "Deaths" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pDeaths] = strval( val ); }
  210. if( strcmp( key , "Money" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pCash] = strval( val ); }
  211. GivePlayerMoney(playerid,PlayerInfo[playerid][pCash]);
  212. }
  213. fclose(UserFile);
  214. gPlayerLogged[playerid] = 1;
  215. gPlayerAccount[playerid] = 1;
  216. new kills = PlayerInfo[playerid][pKills];
  217. SetPlayerScore(playerid, kills);
  218. GetPlayerName(playerid, pname3, sizeof(pname3));
  219. format(string3, sizeof(string3), "Welcome %s, you have been succesfully logged in!", pname3);
  220. SendClientMessage(playerid, COLOR_WHITE,string3);
  221. }
  222. else
  223. {
  224. SendClientMessage(playerid, COLOR_GREY, " Password does not match your name");
  225. fclose(UserFile);
  226. }
  227. }
  228. return 1;
  229. }
  230.  
  231. public OnPlayerUpdate(playerid)
  232. {
  233. if(IsPlayerConnected(playerid))
  234. {
  235. if(gPlayerLogged[playerid])
  236. {
  237. new string3[32];
  238. new pname3[MAX_PLAYER_NAME];
  239. GetPlayerName(playerid, pname3, sizeof(pname3));
  240. format(string3, sizeof(string3), "%s.cer", pname3);
  241. new File: pFile = fopen(string3, io_write);
  242. if (pFile)
  243. {
  244. new var[32];
  245. format(var, 32, "%s\n", PlayerInfo[playerid][pPassword]);fwrite(pFile, var);
  246. fclose(pFile);
  247. new File: hFile = fopen(string3, io_append);
  248. PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
  249. format(var, 32, "Kills=%d\n",PlayerInfo[playerid][pKills]);fwrite(hFile, var);
  250. format(var, 32, "Deaths=%d\n",PlayerInfo[playerid][pDeaths]);fwrite(hFile, var);
  251. format(var, 32, "Money=%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var);
  252. fclose(hFile);
  253. }
  254. }
  255. }
  256. return 1;
  257. }
  258.  
  259. stock ini_GetKey( line[] )
  260. {
  261. new keyRes[128];
  262. keyRes[0] = 0;
  263. if ( strfind( line , "=" , true ) == -1 ) return keyRes;
  264. strmid( keyRes , line , 0 , strfind( line , "=" , true ) , sizeof( keyRes) );
  265. return keyRes;
  266. }
  267.  
  268. stock ini_GetValue( line[] )
  269. {
  270. new valRes[128];
  271. valRes[0]=0;
  272. if ( strfind( line , "=" , true ) == -1 ) return valRes;
  273. strmid( valRes , line , strfind( line , "=" , true )+1 , strlen( line ) , sizeof( valRes ) );
  274. return valRes;
  275. }
  276.  
  277.  
  278. strtok(const string[], &index)
  279. {
  280. new length = strlen(string);
  281. while ((index < length) && (string[index] <= ' '))
  282. {
  283. index++;
  284. }
  285.  
  286. new offset = index;
  287. new result[20];
  288. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  289. {
  290. result[index - offset] = string[index];
  291. index++;
  292. }
  293. result[index - offset] = EOS;
  294. return result;
  295. }
  296.  
  297. public ShowStats(playerid,targetid)
  298. {
  299. if(IsPlayerConnected(playerid)&&IsPlayerConnected(targetid))
  300. {
  301. new cash = GetPlayerMoney(targetid);
  302. new deaths = PlayerInfo[targetid][pDeaths];
  303. new kills = PlayerInfo[targetid][pKills];
  304. new name[MAX_PLAYER_NAME];
  305. GetPlayerName(targetid, name, sizeof(name));
  306. new Float:px,Float:py,Float:pz;
  307. GetPlayerPos(targetid, px, py, pz);
  308. new coordsstring[256];
  309. SendClientMessage(playerid, COLOR_GREEN,"_______________________________________");
  310. format(coordsstring, sizeof(coordsstring),"*** %s ***",name);
  311. SendClientMessage(playerid, COLOR_WHITE,coordsstring);
  312. format(coordsstring, sizeof(coordsstring), "Kills:[%d] Deaths:[%d] Cash:[$%d]",kills,deaths,cash);
  313. SendClientMessage(playerid, COLOR_GRAD5,coordsstring);
  314. SendClientMessage(playerid, COLOR_GREEN,"_______________________________________");
  315. }
  316. }
  317.  
  318. #endif
Advertisement
Add Comment
Please, Sign In to add comment