MCPcopy Create free account
hub / github.com/assaultcube/AC / validmapname

Function validmapname

source/src/protocol.cpp:253–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

251//#define FILENAMESALLLOWERCASE
252
253bool validmapname(const char *s) // checks for length, allowed chars and special DOS filenames
254{
255 int len = strlen(s);
256 if(len > MAXMAPNAMELEN) return false;
257 if(len == 3 || len == 4)
258 {
259 char uc[4];
260 loopi(3) uc[i] = toupper(s[i]);
261 uc[3] = '\0';
262 const char *resd = "COMLPTCONPRNAUXNUL", *fnd = strstr(resd, uc);
263 if(fnd)
264 {
265 int pos = (int) (fnd - resd);
266 if(pos == 0 || pos == 3)
267 {
268 if(isdigit(s[3])) return false; // COMx, LPTx
269 }
270 else if(pos % 3 == 0) return false; // CON, PRN, AUX, NUL
271 }
272 }
273 while(*s != '\0')
274 {
275#ifdef FILENAMESALLLOWERCASE
276 if(!islower(*s) && !isdigit(*s) && *s != '_' && *s != '-' && *s != '.') return false;
277#else
278 if(!isalnum(*s) && *s != '_' && *s != '-' && *s != '.') return false;
279#endif
280 ++s;
281 }
282 return true;
283}
284
285
286// filter text according to rules

Callers 6

loadMethod · 0.85
mapactionMethod · 0.85
save_worldFunction · 0.85
save_world9Function · 0.85
load_worldFunction · 0.85
validxmapnameFunction · 0.85

Calls 1

loopiFunction · 0.70

Tested by

no test coverage detected