Advertisement
Guest User

Extra.inc

a guest
Sep 19th, 2013
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.87 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. return 1;
  55. }
  56.  
  57. public OnPlayerText(playerid, text[])
  58. {
  59. if(Muted[playerid] == 1)
  60. {
  61. SendClientMessage(playerid,-1,"You have been muted");
  62. return 0;
  63. }
  64. return 1;
  65. }
  66.  
  67. stock Extra_Kick(playerid, reason[])
  68. {
  69. SetTimer("KickPlayer",3000,false);
  70. SendClientMessage(playerid,-1,reason);
  71. return 1;
  72. }
  73.  
  74. stock Extra_Ban(playerid, reason[])
  75. {
  76. SendClientMessage(playerid,-1,reason);
  77. Banned[playerid] = 1;
  78. new file[200];
  79. format(file,sizeof(file),"Extra/%s.ini",GetName(playerid));
  80. Extra_IntSet(file,"Ban",1);
  81. SetTimer("KickPlayer",3000,false);
  82. return 1;
  83. }
  84.  
  85. stock Extra_UnBan(playername[])
  86. {
  87. new file[200]
  88. format(file,sizeof(file),"Extra/%s.ini",playername);
  89. Extra_IntSet(file,"Ban",0);
  90. return 1;
  91. }
  92.  
  93. stock Extra_Mute(playerid, reason[])
  94. {
  95. new file[200]
  96. format(file,sizeof(file),"Extra/%s.ini",GetName(playerid));
  97. Extra_IntSet(file,"Mute",1);
  98. Muted[playerid] = 1;
  99. return 1;
  100. }
  101.  
  102. stock Extra_UnMute(playerid, reason[])
  103. {
  104. new file[200]
  105. format(file,sizeof(file),"Extra/%s.ini",GetName(playerid));
  106. Extra_IntSet(file,"Mute",0);
  107. Muted[playerid] = 0;
  108. return 1;
  109. }
  110.  
  111. stock Extra_Freeze(playerid, reason[])
  112. {
  113. new file[200]
  114. format(file,sizeof(file),"Extra/%s.ini",GetName(playerid));
  115. Extra_IntSet(file,"Freeze",1);
  116. Freezed[playerid] = 1;
  117. TogglePlayerControlLabel(playerid,0);
  118. return 1;
  119. }
  120.  
  121. stock Extra_UnFreeze(playerid, reason[])
  122. {
  123. new file[200]
  124. format(file,sizeof(file),"Extra/%s.ini",GetName(playerid));
  125. Extra_IntSet(file,"Freeze",0);
  126. Freezed[playerid] = 0;
  127. TogglePlayerControlLabel(playerid,1);
  128. return 1;
  129. }
  130.  
  131. stock GetName(playerid)
  132. {
  133. new pname[24];
  134. GetPlayerName(playerid,pname,sizeof(pname));
  135. return pname;
  136. }
  137.  
  138. stock Extra_Set(filename[],key[],value[])
  139. {
  140. new key_length = strlen(key);
  141. new value_length = strlen(value);
  142. if (key_length==0 || key_length+value_length+2>MAX_STRING) return false;
  143.  
  144. new File:fohnd, File:fwhnd;
  145. new tmpres[MAX_STRING];
  146. new bool:wasset=false;
  147.  
  148. // Let's remove the old *.part file if there was one.
  149. format(tmpres,sizeof(tmpres),"%s.part",filename);
  150. fremove(tmpres);
  151.  
  152. // We'll open the source file.
  153. fohnd=fopen(filename,io_read);
  154. if (!fohnd) return false;
  155.  
  156. fwhnd=fopen(tmpres,io_write);
  157. if (!fwhnd) {
  158. // we can't open the second file for writing, so .. let's close the open one and exit.
  159. fclose(fohnd);
  160. return false;
  161. }
  162.  
  163. while (fread(fohnd,tmpres)) {
  164. if (
  165. !wasset
  166. && tmpres[key_length]=='='
  167. && !strcmp(tmpres, key, true, key_length)
  168. ) {
  169. // We've got what needs to be replaced!
  170. format(tmpres,sizeof(tmpres),"%s=%s",key,value);
  171. wasset=true;
  172. } else {
  173. Extra_StripNewLine(tmpres);
  174. }
  175. fwrite(fwhnd,tmpres);
  176. fwrite(fwhnd,"\r\n");
  177. }
  178.  
  179. if (!wasset) {
  180. format(tmpres,sizeof(tmpres),"%s=%s",key,value);
  181. fwrite(fwhnd,tmpres);
  182. fwrite(fwhnd,"\r\n");
  183. }
  184.  
  185. fclose(fohnd);
  186. fclose(fwhnd);
  187.  
  188. format(tmpres,sizeof(tmpres),"%s.part",filename);
  189. if (Extra_fcopytextfile(tmpres,filename)) {
  190. return fremove(tmpres);
  191. }
  192. return false;
  193. }
  194.  
  195. stock Extra_IntSet(filename[],key[],value)
  196. {
  197. new valuestring[MAX_STRING];
  198. format(valuestring,MAX_STRING,"%d",value);
  199. return Extra_Set(filename,key,valuestring);
  200. }
  201.  
  202. stock Extra_StripNewLine(string[])
  203. {
  204. new len = strlen(string);
  205. if (string[0]==0) return ;
  206. if ((string[len - 1] == '\n') || (string[len - 1] == '\r')) {
  207. string[len - 1] = 0;
  208. if (string[0]==0) return ;
  209. if ((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0;
  210. }
  211. }
  212.  
  213. stock Extra_fcopytextfile(oldname[],newname[])
  214. {
  215. new File:ohnd,File:nhnd;
  216. if (!fexist(oldname)) return false;
  217. ohnd=fopen(oldname,io_read);
  218. if (!ohnd) return false;
  219. nhnd=fopen(newname,io_write);
  220. if (!nhnd) {
  221. fclose(ohnd);
  222. return false;
  223. }
  224. new tmpres[MAX_STRING];
  225. while (fread(ohnd,tmpres)) {
  226. Extra_StripNewLine(tmpres);
  227. format(tmpres,sizeof(tmpres),"%s\r\n",tmpres);
  228. fwrite(nhnd,tmpres);
  229. }
  230. fclose(ohnd);
  231. fclose(nhnd);
  232. return true;
  233. }
  234.  
  235. stock Extra_Get(filename[],key[])
  236. {
  237. new tmpres[MAX_STRING];
  238.  
  239. new key_length = strlen(key);
  240. if (key_length==0 || key_length+2>MAX_STRING) return tmpres;
  241.  
  242. new File:fohnd;
  243. fohnd=fopen(filename,io_read);
  244. if (!fohnd) return tmpres;
  245.  
  246. while (fread(fohnd,tmpres)) {
  247. if (
  248. tmpres[key_length]=='='
  249. && !strcmp(tmpres, key, true, key_length)
  250. ) {
  251. /* We've got what we need */
  252. Extra_StripNewLine(tmpres);
  253. strmid(tmpres, tmpres, key_length + 1, strlen(tmpres), MAX_STRING);
  254. fclose(fohnd);
  255. return tmpres;
  256. }
  257. }
  258. fclose(fohnd);
  259. return tmpres;
  260. }
  261.  
  262. stock Extra_Int(filename[],key[])
  263. {
  264. return strval(Extra_Get(filename,key));
  265. }
  266.  
  267.  
  268. public KickPlayer(playerid)
  269. {
  270. Kick(playerid);
  271. return 1;
  272. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement