add license and copyright stuff
[quakecontrol.git] / loadmap.c
1 // Copyright (2013) Jann Horn <jann@thejh.net>
2 // This code is licensed under the AGPLv3.
3
4 #include "common.h"
5
6 char *map;
7
8 void check_map_name(void) {
9   if (map == NULL) senderr("missing query string", false);
10   for (char *p = map; *p; p++) {
11     if (*p >= 'a' && *p <= 'z') continue;
12     if (*p >= 'A' && *p <= 'Z') continue;
13     if (*p >= '0' && *p <= '9') continue;
14     if (*p == '_') continue;
15     senderr("bad map name", false);
16   }
17 }
18
19 int main(void) {
20   map = getenv("QUERY_STRING");
21   check_map_name();
22   
23   char cmd[4+strlen(map)+1];
24   memcpy(cmd, "map ", 4);
25   strcpy(cmd+4, map);
26   rcon_send(cmd);
27   
28   puts("Status: 204 changed map"
29      "\nX-Frame-Options: DENY"
30      "\n");
31   exit(0);
32 }