From c2e349569fcf796412b376db89304a19648f18b8 Mon Sep 17 00:00:00 2001 From: johannes Date: Sun, 11 Feb 2024 02:00:20 +0100 Subject: added argument parser and run function --- src/commands.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'src/commands.c') diff --git a/src/commands.c b/src/commands.c index 599c6d0..e2353d8 100644 --- a/src/commands.c +++ b/src/commands.c @@ -1,5 +1,6 @@ #include "../inc/demo.h" #include "../inc/pack.h" +#include "../inc/commands.h" #include #include @@ -122,7 +123,6 @@ int setskinbyname(char *name, char *skin, demo *demo) char iname[16]; intstostr(item->data, 4, iname); - printf("comparing: %s : %s\n", name, iname); if (strcmp(name, iname) == 0) { memcpy(&item->data[8], intskin, 5 * sizeof(int)); @@ -142,6 +142,9 @@ int changemap(FILE *map, char *mapname, demo *demo) fseek(map, 0, SEEK_END); long mapsize = ftell(map); fseek(map, 0, SEEK_SET); + + if (mapsize < 4) + return -1; char *mapbuff = (char *)malloc(mapsize); if (mapbuff == NULL) @@ -167,3 +170,43 @@ int changemap(FILE *map, char *mapname, demo *demo) return 1; } + +void runcommand(cmdinput *cmd, demo *demo) +{ + switch(cmd->cmdtype) + { + case 'n': + switch(cmd->settype) + { + case 'i': + if (setnamebyid(cmd->id, cmd->to, demo) < 0) + printf("WARNING: Could not set name '%s' because it exeeds max limit of 15 characters\n", cmd->to); + break; + case 'n': + if (setnamebyname(cmd->from, cmd->to, demo) < 0) + printf("WARNING: Could not set name '%s' because it exeeds max limit of 15 characters\n", cmd->to); + break; + default: + printf("WARNING: Unknown modifier for name\n"); + } + break; + case 's': + switch(cmd->settype) + { + case 'i': + if (setskinbyid(cmd->id, cmd->to, demo) < 0) + printf("WARNING: Could not set skin '%s' because it exeeds max limit of 23 characters\n", cmd->to); + break; + case 'n': + if (setskinbyname(cmd->from, cmd->to, demo) < 0) + printf("WARNING: Could not set skin '%s' because it exeeds max limit of 23 characters\n", cmd->to); + break; + default: + printf("WARNING: Unknown modifier for skin\n"); + } + break; + default: + printf("WARNING: Unknown command type\n"); + break; + } +} -- cgit v1.2.3