11 extern std::string init_file_error
; // defined in main.cc
13 // Eventually, this should be something more grand. {dlb}
14 void opening_screen(void)
17 "<yellow>Hello, welcome to " CRAWL
" " + Version::Long() + "!</yellow>\n"
18 "<brown>(c) Copyright 1997-2002 Linley Henzell, "
19 "2002-2010 Crawl DevTeam\n"
20 "Read the instructions for legal details."
23 const bool init_found
= init_file_error
.empty();
26 msg
+= "<lightred>(No init file ";
28 msg
+= "<lightgrey>(Read options from ";
33 // For dgl installs, show only the last segment of the .crawlrc
34 // file name so that we don't leak details of the directory
35 // structure to (untrusted) users.
36 msg
+= get_base_filename(Options
.filename
);
38 msg
+= Options
.filename
;
44 msg
+= init_file_error
;
45 msg
+= ", using defaults.)";
50 formatted_string::parse_string(msg
).display();
54 static void _show_name_prompt(int where
)
59 cprintf("\nWhat is your name today? ");
64 bool is_good_name(const std::string
& name
, bool blankOK
, bool verbose
)
66 // verification begins here {dlb}:
73 cprintf("\nThat's a silly name!\n");
77 return (validate_player_name(name
, verbose
));
80 static bool _read_player_name(std::string
&name
)
82 const int name_x
= wherex(), name_y
= wherey();
83 char buf
[kNameLen
+ 1];
84 // XXX: Prompt displays garbage otherwise, but don't really know why.
85 // Other places don't do this. --rob
87 line_reader
reader(buf
, sizeof(buf
));
91 cgotoxy(name_x
, name_y
);
93 cprintf("%-*s", 80 - name_x
+ 1, "");
95 cgotoxy(name_x
, name_y
);
96 int ret
= reader
.read_line(false);
103 if (key_is_escape(ret
))
106 // Go back and prompt the user.
110 // Reads a valid name from the player, writing it to ng.name.
111 void enter_player_name(newgame_def
*ng
)
113 int prompt_start
= wherey();
117 // Prompt for a new name if current one unsatisfactory {dlb}:
118 _show_name_prompt(prompt_start
);
120 // If the player wants out, we bail out.
121 if (!_read_player_name(ng
->name
))
123 trim_string(ng
->name
);
125 while (!is_good_name(ng
->name
, false, true));
128 bool validate_player_name(const std::string
&name
, bool verbose
)
130 #if defined(TARGET_OS_DOS) || defined(TARGET_OS_WINDOWS)
131 // Quick check for CON -- blows up real good under DOS/Windows.
132 if (stricmp(name
.c_str(), "con") == 0
133 || stricmp(name
.c_str(), "nul") == 0
134 || stricmp(name
.c_str(), "prn") == 0
135 || strnicmp(name
.c_str(), "LPT", 3) == 0)
138 cprintf("\nSorry, that name gives your OS a headache.\n");
143 if (strwidth(name
) > kNameLen
)
146 cprintf("\nThat name is too long.\n");
150 for (unsigned int i
= 0; i
< name
.length(); i
++)
153 // Note that this includes systems which may be using the
154 // packaging system. The packaging system is very simple
155 // and doesn't take the time to escape every character that
156 // might be a problem for some random shell or OS... so we
157 // play it very conservative here. -- bwr
158 // Accented 8-bit letters are probably harmless here. -- 1KB
159 if (!isalnum(c
) && c
!= '-' && c
!= '.' && c
!= '_' && c
!= ' ')
164 "Alpha-numerics, spaces, dashes, periods "
165 "and underscores only, please."