Fix harvestables
This commit is contained in:
parent
c50e332d92
commit
c0fe76acce
|
@ -102,17 +102,30 @@ except:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
c.execute("""
|
c.execute("""
|
||||||
CREATE TABLE harvestList(
|
CREATE TABLE containerList(
|
||||||
Name TEXT(12),
|
Name TEXT(12),
|
||||||
HarvestableTemplateId int,
|
HarvestableTemplateId int,
|
||||||
LastHarvest int,
|
LastHarvest int,
|
||||||
ContainerName TEXT(128),
|
ContainerName TEXT(128),
|
||||||
Harvestables TEXT(8024),
|
|
||||||
AreaId int
|
AreaId int
|
||||||
);
|
);
|
||||||
""")
|
""")
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
try:
|
||||||
|
c.execute("""
|
||||||
|
CREATE TABLE harvestablesList(
|
||||||
|
Name TEXT(12),
|
||||||
|
ItemTemplateId int,
|
||||||
|
UpdateTime int,
|
||||||
|
SlotIndex int,
|
||||||
|
HarvestableName TEXT(128),
|
||||||
|
AreaId int,
|
||||||
|
ParentContainerName TEXT(128)
|
||||||
|
);
|
||||||
|
""")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
try:
|
try:
|
||||||
c.execute("""
|
c.execute("""
|
||||||
CREATE TABLE rubishList(
|
CREATE TABLE rubishList(
|
||||||
|
|
|
@ -39,9 +39,13 @@ def TryAdd():
|
||||||
rows = cur.fetchone()
|
rows = cur.fetchone()
|
||||||
username = rows[0]
|
username = rows[0]
|
||||||
|
|
||||||
|
cur = c.execute('SELECT COUNT(1) from containerList where Name=? and AreaId=? and containerName=?',(username,AreaId,ContainerName))
|
||||||
c.execute('DELETE from harvestList where Name=? and AreaId=? and containerName=?',(username,AreaId,ContainerName))
|
rows = cur.fetchone()
|
||||||
c.execute('INSERT INTO harvestList VAlUES (?,?,NULL,?,NULL,?)',(username,HarvestableTemplateId,ContainerName,AreaId))
|
count = rows[0]
|
||||||
|
if count == 0:
|
||||||
|
c.execute('INSERT INTO containerList VAlUES (?,?,NULL,?,?)',(username,HarvestableTemplateId,ContainerName,AreaId))
|
||||||
|
else:
|
||||||
|
c.execute('UPDATE containerList SET HarvestableTemplateId=? where Name=? and AreaId=? and ContainerName=?',(HarvestableTemplateId,username,AreaId,ContainerName))
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
58
DreamTown/cgi-bin/harvestable/addHarvestable
Normal file
58
DreamTown/cgi-bin/harvestable/addHarvestable
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
#!/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()
|
||||||
|
|
||||||
|
|
||||||
|
content_len = int(os.environ["CONTENT_LENGTH"])
|
||||||
|
post = sys.stdin.read(content_len)
|
||||||
|
jsonData = json.loads(post)
|
||||||
|
result = {"status":SUCCESS}
|
||||||
|
|
||||||
|
def TryAdd():
|
||||||
|
ContainerName = jsonData['containerName']
|
||||||
|
ItemTemplateId = jsonData['itemTemplateId']
|
||||||
|
UpdateTime = jsonData['updateTime']
|
||||||
|
Index = jsonData['index']
|
||||||
|
HarvestableName = jsonData['harvestableName']
|
||||||
|
AreaId = jsonData['areaId']
|
||||||
|
authToken = jsonData['authToken']
|
||||||
|
|
||||||
|
c = db.cursor()
|
||||||
|
cur = c.execute('SELECT COUNT(1) from users WHERE LastSession=?',(authToken,))
|
||||||
|
rows = cur.fetchone()
|
||||||
|
count = rows[0]
|
||||||
|
if count == 0:
|
||||||
|
result['status'] = USER_DOES_NOT_EXIST
|
||||||
|
return 0
|
||||||
|
|
||||||
|
#Find Username
|
||||||
|
cur = c.execute('SELECT Name from users WHERE LastSession=?',(authToken,))
|
||||||
|
rows = cur.fetchone()
|
||||||
|
username = rows[0]
|
||||||
|
|
||||||
|
c.execute('DELETE from harvestablesList where Name=? and HarvestableName=? and AreaId=? and ParentContainerName=?',(username,HarvestableName,AreaId,ContainerName))
|
||||||
|
c.execute('INSERT INTO harvestablesList VAlUES (?,?,?,?,?,?,?)',(username,ItemTemplateId,UpdateTime,Index,HarvestableName,AreaId,ContainerName))
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
db = sqlite3.connect(SQLLITE_DB_PATH)
|
||||||
|
TryAdd()
|
||||||
|
db.commit()
|
||||||
|
db.close()
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
os._exit()
|
||||||
|
|
||||||
|
print(json.dumps(result))
|
|
@ -37,14 +37,30 @@ def TryGet():
|
||||||
rows = cur.fetchone()
|
rows = cur.fetchone()
|
||||||
username = rows[0]
|
username = rows[0]
|
||||||
|
|
||||||
cur = c.execute('SELECT HarvestableTemplateId,LastHarvest,ContainerName, Harvestables,AreaId from harvestList WHERE Name=?',(username,))
|
|
||||||
|
cur = c.execute('SELECT HarvestableTemplateId,LastHarvest,ContainerName,AreaId from containerList WHERE Name=?',(username,))
|
||||||
rows = cur.fetchall()
|
rows = cur.fetchall()
|
||||||
harvestList = []
|
containerList = []
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
containers = {'harvestableTemplateId':row[0], 'lastHarvest':row[1], 'containerName':row[2], 'harvestables':json.loads(row[3]), 'areaId':row[4]}
|
harvestableTemplateId=row[0]
|
||||||
harvestList.append(containers)
|
lastHarvest=row[1]
|
||||||
result['containers'] = harvestList
|
containerName=row[2]
|
||||||
|
areaId=row[3]
|
||||||
|
|
||||||
|
cur = c.execute('SELECT ItemTemplateId,UpdateTime,SlotIndex,HarvestableName from harvestablesList WHERE Name=? AND ParentContainerName=? AND AreaId=?',(username,containerName,areaId))
|
||||||
|
rows2 = cur.fetchall()
|
||||||
|
harvestablesList = []
|
||||||
|
for row2 in rows2:
|
||||||
|
harvestable = {'itemTemplateId':row2[0],'updateTime':row2[1],'index':row2[2],'harvestableName':row2[3]}
|
||||||
|
harvestablesList.append(harvestable)
|
||||||
|
|
||||||
|
|
||||||
|
containers = {'harvestableTemplateId':harvestableTemplateId, 'lastHarvest':lastHarvest, 'containerName':containerName, 'harvestables':harvestablesList, 'areaId':areaId}
|
||||||
|
containerList.append(containers)
|
||||||
|
|
||||||
|
|
||||||
|
result['containers'] = containerList
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
57
DreamTown/cgi-bin/harvestable/remove
Normal file
57
DreamTown/cgi-bin/harvestable/remove
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
from dreamtown_config import *
|
||||||
|
import sys
|
||||||
|
import binascii
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import sqlite3
|
||||||
|
import math
|
||||||
|
import time
|
||||||
|
import hashlib
|
||||||
|
|
||||||
|
print("Content-Type: application/json")
|
||||||
|
print("")
|
||||||
|
method = os.environ["REQUEST_METHOD"]
|
||||||
|
if method != "POST":
|
||||||
|
print("Expected POST")
|
||||||
|
os._exit()
|
||||||
|
|
||||||
|
|
||||||
|
content_len = int(os.environ["CONTENT_LENGTH"])
|
||||||
|
post = sys.stdin.read(content_len)
|
||||||
|
jsonData = json.loads(post)
|
||||||
|
result = {"status":SUCCESS}
|
||||||
|
|
||||||
|
def TryAdd():
|
||||||
|
ContainerName = jsonData['containerName']
|
||||||
|
UpdateTime = jsonData['updateTime']
|
||||||
|
HarvestableName = jsonData['harvestableName']
|
||||||
|
AreaId = jsonData['areaId']
|
||||||
|
authToken = jsonData['authToken']
|
||||||
|
|
||||||
|
c = db.cursor()
|
||||||
|
cur = c.execute('SELECT COUNT(1) from users WHERE LastSession=?',(authToken,))
|
||||||
|
rows = cur.fetchone()
|
||||||
|
count = rows[0]
|
||||||
|
if count == 0:
|
||||||
|
result['status'] = USER_DOES_NOT_EXIST
|
||||||
|
return 0
|
||||||
|
|
||||||
|
#Find Username
|
||||||
|
cur = c.execute('SELECT Name from users WHERE LastSession=?',(authToken,))
|
||||||
|
rows = cur.fetchone()
|
||||||
|
username = rows[0]
|
||||||
|
|
||||||
|
c.execute('DELETE from harvestablesList where Name=? and HarvestableName=? and AreaId=? and ParentContainerName=?',(username,HarvestableName,AreaId,ContainerName))
|
||||||
|
c.execute('UPDATE containerList SET LastHarvest=? WHERE Name=? AND ContainerName=? AND AreaId=?',(math.floor(time.time()),username,ContainerName,AreaId))
|
||||||
|
|
||||||
|
try:
|
||||||
|
db = sqlite3.connect(SQLLITE_DB_PATH)
|
||||||
|
TryAdd()
|
||||||
|
db.commit()
|
||||||
|
db.close()
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
os._exit()
|
||||||
|
|
||||||
|
print(json.dumps(result))
|
|
@ -46,8 +46,8 @@ def TrySave():
|
||||||
|
|
||||||
harvestablesEncoded = json.dumps(harvestables)
|
harvestablesEncoded = json.dumps(harvestables)
|
||||||
|
|
||||||
c.execute('DELETE from harvestList where Name=? and AreaId=? and containerName=?',(username,areaId,containerName))
|
c.execute('DELETE from containerList where Name=? and AreaId=? and containerName=?',(username,areaId,containerName))
|
||||||
c.execute('INSERT INTO harvestList VAlUES (?,?,?,?,?,?)',(username,harvestableTemplateId,lastHarvest,containerName,harvestablesEncoded,areaId))
|
c.execute('INSERT INTO containerList VAlUES (?,?,?,?,?,?)',(username,harvestableTemplateId,lastHarvest,containerName,harvestablesEncoded,areaId))
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user