Merge branch 'master' of thejh.net:quakecontrol
[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   if (strlen(map) > 100) senderr("map string is too long - no stack/heap overlap issue for you!", false);
11   for (char *p = map; *p; p++) {
12     if (*p >= 'a' && *p <= 'z') continue;
13     if (*p >= 'A' && *p <= 'Z') continue;
14     if (*p >= '0' && *p <= '9') continue;
15     if (*p == '_') continue;
16     senderr("bad map name", false);
17   }
18 }
19
20 int main(void) {
21   map = getenv("QUERY_STRING");
22   check_map_name();
23   
24   char cmd[4+strlen(map)+1];
25   memcpy(cmd, "map ", 4);
26   strcpy(cmd+4, map);
27   rcon_send(cmd);
28   
29   puts("Status: 204 changed map"
30      "\nX-Frame-Options: DENY"
31      "\n");
32   exit(0);
33 }