Advertisement
Guest User

Extra.inc (Hooked version)

a guest
Oct 14th, 2013
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.43 KB | None | 0 0
  1. /**********************************
  2. * *
  3. * @Author: WazzUp *
  4. * @Version: 0.3.1 *
  5. * @Released: 20/09/2013 *
  6. * *
  7. **********************************/
  8.  
  9. #include <a_samp>
  10.  
  11.  
  12. /*
  13. native Extra_Kick(playerid, reason[]);
  14. native Extra_Ban(playerid, reason[]);
  15. native Extra_UnBan(playername);
  16. native Extra_Mute(playerid, reason[]);
  17. native Extra_UnMute(playerid, reason[]);
  18. native Extra_Freeze(playerid, reason[]);
  19. native Extra_UnFreeze(playerid, reason[]);
  20. */
  21.  
  22. #define MAX_STRING 600
  23.  
  24.  
  25. forward KickPlayer(playerid);
  26.  
  27.  
  28. new Banned[MAX_PLAYERS],
  29. Muted[MAX_PLAYERS],
  30. Freezed[MAX_PLAYERS];
  31.  
  32. public OnPlayerConnect(playerid)
  33. {
  34. new file[200];
  35. format(file,sizeof(file),"Extra/%s.ini",GetName(playerid));
  36.  
  37. if(!fexist(file))
  38. {
  39. new File:bfile;
  40. bfile = fopen(file,io_write);
  41. if(bfile)
  42. {
  43. fclose(bfile);
  44. return 1;
  45. }
  46. }
  47. else
  48. {
  49. Banned[playerid] = Extra_Int(file,"Ban");
  50. if(Banned[playerid] == 1) return Extra_Kick(playerid,"You has been banned from this server");
  51. Muted[playerid] = Extra_Int(file,"Mute");
  52. Freezed[playerid] = Extra_Int(file,"Freeze");
  53.  
  54. if(Freezed[playerid] == 1)
  55. {
  56. TogglePlayerControllable(playerid,0);
  57. }
  58. }
  59. return CallLocalFunction("Extra_OnPlayerConnect","u",playerid);
  60. }
  61.  
  62.  
  63. #if defined _ALS_OnPlayerConnect
  64. #undef OnPlayerConnect
  65. #endif
  66.  
  67. #define _ALS_OnPlayerConnect
  68.  
  69. #define OnPlayerConnect Extra_OnPlayerConnect
  70.  
  71.  
  72. public OnPlayerText(playerid, text[])
  73. {
  74. if(Muted[playerid] == 1)
  75. {
  76. SendClientMessage(playerid,-1,"You have been muted");
  77. return 0;
  78. }
  79. return CallLocalFunction("Extra_OnPlayerText","us",playerid,text);
  80. }
  81.  
  82.  
  83. #if defined _ALS_OnPlayerText
  84. #undef OnPlayerText
  85. #endif
  86.  
  87. #define _ALS_OnPlayerText
  88.  
  89. #define OnPlayerText Extra_OnPlayerText
  90.  
  91. stock Extra_Kick(playerid, reason[])
  92. {
  93. SetTimer("KickPlayer",3000,false);
  94. SendClientMessage(playerid,-1,reason);
  95. return 1;
  96. }
  97.  
  98. stock Extra_Ban(playerid, reason[])
  99. {
  100. SendClientMessage(playerid,-1,reason);
  101. Banned[playerid] = 1;
  102. new file[200];
  103. format(file,sizeof(file),"Extra/%s.ini",GetName(playerid));
  104. Extra_IntSet(file,"Ban",1);
  105. SetTimer("KickPlayer",3000,false);
  106. return 1;
  107. }
  108.  
  109. stock Extra_UnBan(playername[])
  110. {
  111. new file[200]
  112. format(file,sizeof(file),"Extra/%s.ini",playername);
  113. Extra_IntSet(file,"Ban",0);
  114. return 1;
  115. }
  116.  
  117. stock Extra_Mute(playerid, reason[])
  118. {
  119. new file[200]
  120. format(file,sizeof(file),"Extra/%s.ini",GetName(playerid));
  121. Extra_IntSet(file,"Mute",1);
  122. Muted[playerid] = 1;
  123. return 1;
  124. }
  125.  
  126. stock Extra_UnMute(playerid, reason[])
  127. {
  128. new file[200]
  129. format(file,sizeof(file),"Extra/%s.ini",GetName(playerid));
  130. Extra_IntSet(file,"Mute",0);
  131. Muted[playerid] = 0;
  132. return 1;
  133. }
  134.  
  135. stock Extra_Freeze(playerid, reason[])
  136. {
  137. new file[200]
  138. format(file,sizeof(file),"Extra/%s.ini",GetName(playerid));
  139. Extra_IntSet(file,"Freeze",1);
  140. Freezed[playerid] = 1;
  141. TogglePlayerControlLabel(playerid,0);
  142. return 1;
  143. }
  144.  
  145. stock Extra_UnFreeze(playerid, reason[])
  146. {
  147. new file[200]
  148. format(file,sizeof(file),"Extra/%s.ini",GetName(playerid));
  149. Extra_IntSet(file,"Freeze",0);
  150. Freezed[playerid] = 0;
  151. TogglePlayerControlLabel(playerid,1);
  152. return 1;
  153. }
  154.  
  155. stock GetName(playerid)
  156. {
  157. new pname[24];
  158. GetPlayerName(playerid,pname,sizeof(pname));
  159. return pname;
  160. }
  161.  
  162. stock Extra_Set(filename[],key[],value[])
  163. {
  164. new key_length = strlen(key);
  165. new value_length = strlen(value);
  166. if (key_length==0 || key_length+value_length+2>MAX_STRING) return false;
  167.  
  168. new File:fohnd, File:fwhnd;
  169. new tmpres[MAX_STRING];
  170. new bool:wasset=false;
  171.  
  172. // Let's remove the old *.part file if there was one.
  173. format(tmpres,sizeof(tmpres),"%s.part",filename);
  174. fremove(tmpres);
  175.  
  176. // We'll open the source file.
  177. fohnd=fopen(filename,io_read);
  178. if (!fohnd) return false;
  179.  
  180. fwhnd=fopen(tmpres,io_write);
  181. if (!fwhnd) {
  182. // we can't open the second file for writing, so .. let's close the open one and exit.
  183. fclose(fohnd);
  184. return false;
  185. }
  186.  
  187. while (fread(fohnd,tmpres)) {
  188. if (
  189. !wasset
  190. && tmpres[key_length]=='='
  191. && !strcmp(tmpres, key, true, key_length)
  192. ) {
  193. // We've got what needs to be replaced!
  194. format(tmpres,sizeof(tmpres),"%s=%s",key,value);
  195. wasset=true;
  196. } else {
  197. Extra_StripNewLine(tmpres);
  198. }
  199. fwrite(fwhnd,tmpres);
  200. fwrite(fwhnd,"\r\n");
  201. }
  202.  
  203. if (!wasset) {
  204. format(tmpres,sizeof(tmpres),"%s=%s",key,value);
  205. fwrite(fwhnd,tmpres);
  206. fwrite(fwhnd,"\r\n");
  207. }
  208.  
  209. fclose(fohnd);
  210. fclose(fwhnd);
  211.  
  212. format(tmpres,sizeof(tmpres),"%s.part",filename);
  213. if (Extra_fcopytextfile(tmpres,filename)) {
  214. return fremove(tmpres);
  215. }
  216. return false;
  217. }
  218.  
  219. stock Extra_IntSet(filename[],key[],value)
  220. {
  221. new valuestring[MAX_STRING];
  222. format(valuestring,MAX_STRING,"%d",value);
  223. return Extra_Set(filename,key,valuestring);
  224. }
  225.  
  226. stock Extra_StripNewLine(string[])
  227. {
  228. new len = strlen(string);
  229. if (string[0]==0) return ;
  230. if ((string[len - 1] == '\n') || (string[len - 1] == '\r')) {
  231. string[len - 1] = 0;
  232. if (string[0]==0) return ;
  233. if ((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0;
  234. }
  235. }
  236.  
  237. stock Extra_fcopytextfile(oldname[],newname[])
  238. {
  239. new File:ohnd,File:nhnd;
  240. if (!fexist(oldname)) return false;
  241. ohnd=fopen(oldname,io_read);
  242. if (!ohnd) return false;
  243. nhnd=fopen(newname,io_write);
  244. if (!nhnd) {
  245. fclose(ohnd);
  246. return false;
  247. }
  248. new tmpres[MAX_STRING];
  249. while (fread(ohnd,tmpres)) {
  250. Extra_StripNewLine(tmpres);
  251. format(tmpres,sizeof(tmpres),"%s\r\n",tmpres);
  252. fwrite(nhnd,tmpres);
  253. }
  254. fclose(ohnd);
  255. fclose(nhnd);
  256. return true;
  257. }
  258.  
  259. stock Extra_Get(filename[],key[])
  260. {
  261. new tmpres[MAX_STRING];
  262.  
  263. new key_length = strlen(key);
  264. if (key_length==0 || key_length+2>MAX_STRING) return tmpres;
  265.  
  266. new File:fohnd;
  267. fohnd=fopen(filename,io_read);
  268. if (!fohnd) return tmpres;
  269.  
  270. while (fread(fohnd,tmpres)) {
  271. if (
  272. tmpres[key_length]=='='
  273. && !strcmp(tmpres, key, true, key_length)
  274. ) {
  275. /* We've got what we need */
  276. Extra_StripNewLine(tmpres);
  277. strmid(tmpres, tmpres, key_length + 1, strlen(tmpres), MAX_STRING);
  278. fclose(fohnd);
  279. return tmpres;
  280. }
  281. }
  282. fclose(fohnd);
  283. return tmpres;
  284. }
  285.  
  286. stock Extra_Int(filename[],key[])
  287. {
  288. return strval(Extra_Get(filename,key));
  289. }
  290.  
  291.  
  292. public KickPlayer(playerid)
  293. {
  294. Kick(playerid);
  295. return 1;
  296. }
  297.  
  298. forward Extra_OnPlayerConnect(playerid);
  299. forward Extra_OnPlayerText(playerid, text[]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement