Advertisement
Guest User

JaTochNietDan

a guest
Aug 25th, 2010
1,378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.55 KB | None | 0 0
  1. #include <a_samp>
  2. #include <filemanager>
  3.  
  4. new command[3][120];
  5.  
  6. public OnFilterScriptInit()
  7. {
  8.     print("FileManager test filterscript has been loaded");
  9.     return 1;
  10. }
  11.  
  12. public OnRconCommand(cmd[])
  13. {
  14.     new idx;
  15.  
  16.     command[0] = strtok(cmd, idx);
  17.  
  18.     if(strcmp(command[0],"fwrite",true) == 0)
  19.     {
  20.         command[1] = strtok(cmd, idx);
  21.         command[2] = strtok(cmd, idx);
  22.        
  23.         if(!strlen(command[1]) || !strlen(command[2]))
  24.         {
  25.             print("[USAGE]: fwrite <file> <text>");
  26.             return 1;
  27.         }
  28.            
  29.         if(file_write(command[1],command[2])) printf("[SUCCESS]: '%s' has been written to '%s'",command[2],command[1]);
  30.         else print("[FAIL]: The file could not be written!");
  31.             return 1;
  32.     }
  33.     else if(strcmp(command[0],"fmove",true) == 0)
  34.     {
  35.         command[1] = strtok(cmd, idx);
  36.         command[2] = strtok(cmd, idx);
  37.        
  38.         if(!strlen(command[1]) || !strlen(command[2]))
  39.         {
  40.             print("[USAGE]: fmove <file> <newfile>");
  41.             return 1;
  42.         }
  43.        
  44.         if(file_move(command[1],command[2])) print("[SUCCESS]: The file has been moved");
  45.         else print("[FAIL]: The file did not move");
  46.             return 1;
  47.     }
  48.     else if(strcmp(command[0],"fdelete",true) == 0)
  49.     {
  50.         command[1] = strtok(cmd, idx);
  51.  
  52.         if(!strlen(command[1]))
  53.         {
  54.             print("[USAGE]: fdelete <file>");
  55.             return 1;
  56.         }
  57.  
  58.         if(file_delete(command[1])) print("[SUCCESS]: The file has been deleted");
  59.         else print("[FAIL]: The file did not delete");
  60.             return 1;
  61.     }
  62.     else if(strcmp(command[0],"fexists",true) == 0)
  63.     {
  64.         command[1] = strtok(cmd, idx);
  65.  
  66.         if(!strlen(command[1]))
  67.         {
  68.             print("[USAGE]: fexists <file>");
  69.             return 1;
  70.         }
  71.  
  72.         if(file_exists(command[1])) printf("[SUCCESS]: The file '%s' does exist",command[1]);
  73.         else printf("[FAIL]: The file '%s' does not exist",command[1]);
  74.             return 1;
  75.     }
  76.     else if(strcmp(command[0],"fread",true) == 0)
  77.     {
  78.         command[1] = strtok(cmd, idx);
  79.  
  80.         if(!strlen(command[1]))
  81.         {
  82.             print("[USAGE]: fread <file>");
  83.             return 1;
  84.         }
  85.  
  86.         if(file_read(command[1],command[2])) printf("[SUCCESS]: File '%s' contains '%s'",command[1],command[2]);
  87.         else print("[FAIL]: The file could not be read");
  88.             return 1;
  89.     }
  90.     else if(strcmp(command[0],"dcreate",true) == 0)
  91.     {
  92.         command[1] = strtok(cmd, idx);
  93.  
  94.         if(!strlen(command[1]))
  95.         {
  96.             print("[USAGE]: dcreate <directory>");
  97.             return 1;
  98.         }
  99.  
  100.         if(dir_create(command[1])) printf("[SUCCESS]: Directory '%s' created!",command[1]);
  101.         else print("[FAIL]: The directory could not be created");
  102.             return 1;
  103.     }
  104.     else if(strcmp(command[0],"ddelete",true) == 0)
  105.     {
  106.         command[1] = strtok(cmd, idx);
  107.  
  108.         if(!strlen(command[1]))
  109.         {
  110.             print("[USAGE]: ddelete <directory>");
  111.             return 1;
  112.         }
  113.  
  114.         if(dir_delete(command[1])) printf("[SUCCESS]: Directory '%s' deleted",command[1]);
  115.         else print("[FAIL]: The directory could not be deleted, note, it needs to be empty!");
  116.             return 1;
  117.     }
  118.     else if(strcmp(command[0],"dexists",true) == 0)
  119.     {
  120.         command[1] = strtok(cmd, idx);
  121.  
  122.         if(!strlen(command[1]))
  123.         {
  124.             print("[USAGE]: dexists <directory>");
  125.             return 1;
  126.         }
  127.  
  128.         if(dir_exists(command[1])) printf("[SUCCESS]: Directory '%s' exists!",command[1]);
  129.         else print("[FAIL]: The directory does not exist!");
  130.             return 1;
  131.     }
  132.         return 1;
  133. }
  134.  
  135. strtok(const string[], &index)
  136. {
  137.     new length = strlen(string);
  138.     while ((index < length) && (string[index] <= ' '))
  139.     {
  140.         index++;
  141.     }
  142.  
  143.     new offset = index;
  144.     new result[20];
  145.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  146.     {
  147.         result[index - offset] = string[index];
  148.         index++;
  149.     }
  150.     result[index - offset] = EOS;
  151.     return result;
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement