-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjoin2.cgi
executable file
·41 lines (36 loc) · 1.08 KB
/
join2.cgi
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
#!/usr/bin/python3
from os import getenv
from urllib.parse import unquote_plus as unquote
from urllib.parse import quote
import utils
import sys
import codecs
import os
import json
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
utils.printcgiheader("text/html")
game=""
name=""
dic={}
try:
dic=utils.parseurl(getenv("QUERY_STRING"))
game=dic["game"]
try:
name = unquote(utils.parseurl(getenv("QUERY_STRING"))["name"])
for ch in name:
if not ch.isalnum() and not (ch in "ěščřžýáíéďťňůúĚŠČŘŽÝÁÍÉĎŤŇÚŮ_ "):
raise Exception(name)
f=open("games/"+game,"r")
data=json.load(f)
f.close
if name in data["players"]:
raise Exception("Name taken")
data["players"].append(name)
f=open("games/"+game,"w")
f.write(json.dumps(data))
f.close()
utils.redirect("lobby.cgi?game={}&name={}".format(game,quote(name)))
except Exception as e:
utils.redirect("errorjoin.cgi?game="+game)
except:
utils.redirect("error.html")