TamaTown/DreamTown/cgi-bin/rubish/save
2022-11-10 04:11:58 +13:00

60 lines
1.3 KiB
Python

#!/usr/bin/python3
from dreamtown_config import *
import sys
import binascii
import os
import json
import sqlite3
import hashlib
print("Content-Type: application/json")
print("")
method = os.environ["REQUEST_METHOD"]
if method != "POST":
print("Expected POST")
os._exit(1)
content_len = int(os.environ["CONTENT_LENGTH"])
post = sys.stdin.read(content_len)
jsonData = json.loads(post)
result = {"status":SUCCESS}
def TrySave():
Rubishs = jsonData['rubishs'] # bandai' bad grammar, not mine
authToken = jsonData['authToken']
c = db.cursor()
c.execute('SELECT COUNT(1) from users WHERE LastSession=?',(authToken,))
rows = c.fetchone()
count = rows[0]
if count == 0:
result['status'] = USER_DOES_NOT_EXIST
return 0
#Find Username
c.execute('SELECT Name from users WHERE LastSession=?',(authToken,))
rows = c.fetchone()
username = rows[0]
for Rubish in Rubishs:
Id = Rubish['id']
X = Rubish['x']
Y = Rubish['y']
AreaId = Rubish['areaId']
ItemTemplateId = Rubish['itemTemplateId']
c.execute('DELETE from rubishList where Name=? and Id=?',(username,Id))
c.execute('INSERT INTO rubishList VAlUES (?,?,?,?,?,?)',(username,Id,X,Y,AreaId,ItemTemplateId))
try:
db = DbConnect()
TrySave()
db.commit()
db.close()
except Exception as e:
print(e)
os._exit(1)
print(json.dumps(result))