SHOW:
|
|
- or go back to the newest paste.
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],"fcopy",true) == 0) | |
49 | { | |
50 | command[1] = strtok(cmd, idx); | |
51 | command[2] = strtok(cmd, idx); | |
52 | ||
53 | if(!strlen(command[1]) || !strlen(command[2])) | |
54 | { | |
55 | print("[USAGE]: fmove <file> <newfile>"); | |
56 | return 1; | |
57 | } | |
58 | ||
59 | if(file_copy(command[1],command[2])) print("[SUCCESS]: The file has been copied!"); | |
60 | else print("[FAIL]: The file did not copy."); | |
61 | return 1; | |
62 | } | |
63 | else if(strcmp(command[0],"fdelete",true) == 0) | |
64 | { | |
65 | command[1] = strtok(cmd, idx); | |
66 | ||
67 | if(!strlen(command[1])) | |
68 | { | |
69 | print("[USAGE]: fdelete <file>"); | |
70 | return 1; | |
71 | } | |
72 | ||
73 | if(file_delete(command[1])) print("[SUCCESS]: The file has been deleted"); | |
74 | else print("[FAIL]: The file did not delete"); | |
75 | return 1; | |
76 | } | |
77 | else if(strcmp(command[0],"fexists",true) == 0) | |
78 | { | |
79 | command[1] = strtok(cmd, idx); | |
80 | ||
81 | if(!strlen(command[1])) | |
82 | { | |
83 | print("[USAGE]: fexists <file>"); | |
84 | return 1; | |
85 | } | |
86 | ||
87 | if(file_exists(command[1])) printf("[SUCCESS]: The file '%s' does exist",command[1]); | |
88 | else printf("[FAIL]: The file '%s' does not exist",command[1]); | |
89 | return 1; | |
90 | } | |
91 | else if(strcmp(command[0],"fread",true) == 0) | |
92 | { | |
93 | command[1] = strtok(cmd, idx); | |
94 | ||
95 | if(!strlen(command[1])) | |
96 | { | |
97 | print("[USAGE]: fread <file>"); | |
98 | return 1; | |
99 | } | |
100 | ||
101 | if(file_read(command[1],command[2])) printf("[SUCCESS]: File '%s' contains '%s'",command[1],command[2]); | |
102 | else print("[FAIL]: The file could not be read"); | |
103 | return 1; | |
104 | } | |
105 | else if(strcmp(command[0],"dcreate",true) == 0) | |
106 | { | |
107 | command[1] = strtok(cmd, idx); | |
108 | ||
109 | if(!strlen(command[1])) | |
110 | { | |
111 | print("[USAGE]: dcreate <directory>"); | |
112 | return 1; | |
113 | } | |
114 | ||
115 | if(dir_create(command[1])) printf("[SUCCESS]: Directory '%s' created!",command[1]); | |
116 | else print("[FAIL]: The directory could not be created"); | |
117 | return 1; | |
118 | } | |
119 | else if(strcmp(command[0],"ddelete",true) == 0) | |
120 | { | |
121 | command[1] = strtok(cmd, idx); | |
122 | ||
123 | if(!strlen(command[1])) | |
124 | { | |
125 | print("[USAGE]: ddelete <directory>"); | |
126 | return 1; | |
127 | } | |
128 | ||
129 | if(dir_delete(command[1])) printf("[SUCCESS]: Directory '%s' deleted",command[1]); | |
130 | else print("[FAIL]: The directory could not be deleted, note, it needs to be empty!"); | |
131 | return 1; | |
132 | } | |
133 | else if(strcmp(command[0],"dexists",true) == 0) | |
134 | { | |
135 | command[1] = strtok(cmd, idx); | |
136 | ||
137 | if(!strlen(command[1])) | |
138 | { | |
139 | print("[USAGE]: dexists <directory>"); | |
140 | return 1; | |
141 | } | |
142 | ||
143 | if(dir_exists(command[1])) printf("[SUCCESS]: Directory '%s' exists!",command[1]); | |
144 | else print("[FAIL]: The directory does not exist!"); | |
145 | return 1; | |
146 | } | |
147 | return 1; | |
148 | } | |
149 | ||
150 | strtok(const string[], &index) | |
151 | { | |
152 | new length = strlen(string); | |
153 | while ((index < length) && (string[index] <= ' ')) | |
154 | { | |
155 | index++; | |
156 | } | |
157 | ||
158 | new offset = index; | |
159 | new result[20]; | |
160 | while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1))) | |
161 | { | |
162 | result[index - offset] = string[index]; | |
163 | index++; | |
164 | } | |
165 | result[index - offset] = EOS; | |
166 | return result; | |
167 | } |