1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#include "AppHdr.h"
#include "ng-input.h"
#include <cwctype>
#include "end.h"
#include "format.h"
#include "item-name.h" // make_name
#include "libutil.h"
#include "options.h"
#include "stringutil.h"
#include "unicode.h"
#include "version.h"
// Eventually, this should be something more grand. {dlb}
formatted_string opening_screen()
{
string msg =
"<yellow>Hello, welcome to " CRAWL " " + string(Version::Long) + "!</yellow>\n"
"<brown>" CRAWL_COPYRIGHT;
return formatted_string::parse_string(msg);
}
formatted_string options_read_status()
{
string msg;
FileLineInput f(Options.filename.c_str());
if (!f.error())
{
msg += "<lightgrey>Options read from \"";
#ifdef DGAMELAUNCH
// For dgl installs, show only the last segment of the .crawlrc
// file name so that we don't leak details of the directory
// structure to (untrusted) users.
msg += Options.basefilename;
#else
msg += Options.filename;
#endif
msg += "\".</lightgrey>";
}
else
{
msg += "<lightred>Options file ";
if (!Options.filename.empty())
{
msg += make_stringf("\"%s\" is not readable",
Options.filename.c_str());
}
else
msg += "not found";
msg += "; using defaults.</lightred>";
}
msg += "\n";
return formatted_string::parse_string(msg);
}
bool is_good_name(const string& name, bool blankOK)
{
// verification begins here {dlb}:
// Disallow names that would result in a save named just ".cs".
if (strip_filename_unsafe_chars(name).empty())
return blankOK && name.empty();
return validate_player_name(name);
}
bool validate_player_name(const string &name)
{
#if defined(TARGET_OS_WINDOWS)
// Quick check for CON -- blows up real good under DOS/Windows.
if (strcasecmp(name.c_str(), "con") == 0
|| strcasecmp(name.c_str(), "nul") == 0
|| strcasecmp(name.c_str(), "prn") == 0
|| strnicmp(name.c_str(), "LPT", 3) == 0)
{
return false;
}
#endif
if (strwidth(name) > MAX_NAME_LENGTH)
return false;
char32_t c;
for (const char *str = name.c_str(); int l = utf8towc(&c, str); str += l)
{
// The technical reasons are gone, but enforcing some sanity doesn't
// hurt.
if (!iswalnum(c) && c != '-' && c != '.' && c != '_' && c != ' ')
return false;
}
return true;
}
|