X-Git-Url: https://git.jsancho.org/?p=lugaru.git;a=blobdiff_plain;f=Source%2FDevtools%2FConsoleCmds.cpp;h=f3ac22c0fbeaf594f225d5191e5c43d38fdfc1a1;hp=f69984b79890c5e2d8de038ba5d32e0c8009abdb;hb=7ed95b0f483ca64a550e391f8151d7ceb30acc18;hpb=cd451341c5ee01374268559885871ca9d454cbd0 diff --git a/Source/Devtools/ConsoleCmds.cpp b/Source/Devtools/ConsoleCmds.cpp index f69984b..f3ac22c 100644 --- a/Source/Devtools/ConsoleCmds.cpp +++ b/Source/Devtools/ConsoleCmds.cpp @@ -142,7 +142,7 @@ static void set_clothes(int pnum, const char *args) snprintf(buf, 63, "Textures/%s.png", args); int id = Person::players[pnum]->numclothes; - strcpy(Person::players[pnum]->clothes[id], buf); + strncpy(Person::players[pnum]->clothes[id], buf, 64); Person::players[pnum]->clothestintr[id] = tintr; Person::players[pnum]->clothestintg[id] = tintg; Person::players[pnum]->clothestintb[id] = tintb; @@ -163,19 +163,32 @@ void ch_quit(const char *) void ch_map(const char *args) { - Loadlevel(args); + if (!LoadLevel(args)) { + // FIXME: Reduce code duplication with GameTick (should come from a Console class) + for (int k = 14; k >= 1; k--) { + consoletext[k] = consoletext[k - 1]; + } + consoletext[0] = std::string("Could not load the requested level '") + args + "', aborting."; + consoleselected = 0; + } whichlevel = -2; campaign = 0; } void ch_save(const char *args) { - std::string map_path = Folders::getUserDataPath() + "/Maps/" + args; + std::string map_path = Folders::getUserDataPath() + "/Maps"; + Folders::makeDirectory(map_path); + map_path = map_path + "/" + args; int mapvers = 12; FILE *tfile; tfile = fopen( map_path.c_str(), "wb" ); + if (tfile == NULL) { + perror((std::string("Couldn't open file ") + map_path + " for saving").c_str()); + return; + } fpackf(tfile, "Bi", mapvers); fpackf(tfile, "Bi", maptype); fpackf(tfile, "Bi", hostile);