64 lines
1.5 KiB
Python
64 lines
1.5 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 TryUpdate():
|
|
RequestLevel = jsonData['requestLevel']
|
|
CharacterId = jsonData['characterId']
|
|
Pool = jsonData['pool']
|
|
NextTimestamp = jsonData['nextTimestamp']
|
|
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]
|
|
|
|
|
|
|
|
c.execute('SELECT COUNT(1) from npcList WHERE Name=? AND CharacterId=?',(username,CharacterId))
|
|
rows = c.fetchone()
|
|
count = rows[0]
|
|
if count == 0:
|
|
c.execute('INSERT INTO npcList VALUES(?,?,?,?,?)',(username,CharacterId,NextTimestamp,Pool,RequestLevel))
|
|
else:
|
|
c.execute('UPDATE npcList SET RequestLevel=?,Pool=?, NextTimestamp=? WHERE Name=? AND CharacterId=?',(RequestLevel,Pool,NextTimestamp,username,CharacterId))
|
|
|
|
|
|
try:
|
|
db = DbConnect()
|
|
TryUpdate()
|
|
db.commit()
|
|
db.close()
|
|
except Exception as e:
|
|
raise e
|
|
os._exit(1)
|
|
|
|
print(json.dumps(result)) |