summaryrefslogtreecommitdiff
path: root/src/map/atcommand.c
diff options
context:
space:
mode:
authorKenpachi Developer <Kenpachi.Developer@gmx.de>2020-02-08 00:42:44 +0100
committerHaru <haru@dotalux.com>2020-02-09 20:23:14 +0100
commitd84aee4cd917fd1a151d7ec0b3a2d7e32df02441 (patch)
tree90114c301dfcdd0c0243874e0a87458ed610b0ff /src/map/atcommand.c
parentab0eb2c722872ecf33c1449e74468e362a879ba4 (diff)
downloadhercules-d84aee4cd917fd1a151d7ec0b3a2d7e32df02441.tar.gz
hercules-d84aee4cd917fd1a151d7ec0b3a2d7e32df02441.tar.bz2
hercules-d84aee4cd917fd1a151d7ec0b3a2d7e32df02441.tar.xz
hercules-d84aee4cd917fd1a151d7ec0b3a2d7e32df02441.zip
Update ACMD(unloadnpcfile) path verification
Diffstat (limited to 'src/map/atcommand.c')
-rw-r--r--src/map/atcommand.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index c92995977..c9191d27d 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -9056,30 +9056,32 @@ ACMD(addperm)
**/
ACMD(unloadnpcfile)
{
- char file_path[100] = {'\0'};
+ char format[20];
+
+ snprintf(format, sizeof(format), "%%%ds %%1d", MAX_DIR_PATH);
+
+ char file_path[MAX_DIR_PATH + 1] = {'\0'};
int flag = 1;
- if (*message == '\0' || (sscanf(message, "%99s %1d", file_path, &flag) < 1)) {
+ if (*message == '\0' || (sscanf(message, format, file_path, &flag) < 1)) {
clif->message(fd, msg_fd(fd, 1385)); /// Usage: @unloadnpcfile <path> {<flag>}
return false;
}
- const char *dot = strrchr(file_path, '.');
-
- if (dot == NULL) {
- clif->message(fd, msg_fd(fd, 1518)); /// No file extension specified.
+ if (!exists(file_path)) {
+ clif->message(fd, msg_fd(fd, 1387)); /// File not found.
return false;
}
- if (strlen(dot) < 4 || strncmp(dot, ".txt", 4) != 0) {
- clif->message(fd, msg_fd(fd, 1519)); /// Not a TXT file.
+ if (!is_file(file_path)) {
+ clif->message(fd, msg_fd(fd, 1518)); /// Not a file.
return false;
}
FILE *fp = fopen(file_path, "r");
if (fp == NULL) {
- clif->message(fd, msg_fd(fd, 1387)); /// File not found.
+ clif->message(fd, msg_fd(fd, 1519)); /// Can't open file.
return false;
}