Bläddra i källkod

Fix in the run log API.

Iñigo Valentin 6 år sedan
förälder
incheckning
38264efa31
2 ändrade filer med 12 tillägg och 10 borttagningar
  1. 9 6
      application/bin/log-run.py
  2. 3 4
      install_data/setup.sql

+ 9 - 6
application/bin/log-run.py

@@ -3,6 +3,7 @@
 import sqlite3
 import json
 import sys
+import os
 
 """
 Reads the API KEY, that must be passed as first command line argument.
@@ -27,7 +28,7 @@ Reads the JSON data, that must be passed as second command line argument.
 """
 def readData():
     try:
-        #print(sys.argv[1])
+        print(sys.argv[2])
         data = json.loads(sys.argv[2])
         return data
     except Exception as e:
@@ -48,7 +49,7 @@ def verifyKey(db, data, key):
     print('Verifying KEY...')
     status = False
     try:
-        uid = data["wizard_info"]["wizard_id"]
+        uid = data["uid"]
         cursor = db.cursor()
         cursor.execute('SELECT count(uid) AS c FROM player WHERE uid = ? AND api_key = ?;', (uid, key))
         if cursor.fetchone()[0] == 1:
@@ -128,6 +129,8 @@ def parseRun(db, data):
     helper = data["helper"]
     cursor.execute("SELECT max(id) + 1 AS id FROM run;")
     id = cursor.fetchone()[0]
+    if id == None:
+        id = 1
     insert(db, "run", (uid, id, dtime, area, stage, difficulty, win, time, mana, energy, crystal, helper))
     if data["shapeshifting"] > 0:
         insert(db, "run_drop_shapeshifting", (id, data["shapeshifting"]))
@@ -175,13 +178,13 @@ def parseRun(db, data):
 Begin script
 """
 data = readData()
-data = readKey()
-db = openDatabase('../../../../application/sw.sqlite')
+key = readKey()
+db = openDatabase(os.path.dirname(os.path.realpath(sys.argv[0])) + '/../sw.sqlite')
 if verifyKey(db, data, key) == False:
     print("Invalid API KEY...")
-    return -1
+    sys.exit(-1)
 else:
     parseRun(db, data)
-return 0
+sys.exit(0)
 
 

+ 3 - 4
install_data/setup.sql

@@ -399,9 +399,9 @@ CREATE TABLE IF NOT EXISTS run(
     difficulty INT REFERENCES k_difficulty(id),
     win INT NOT NULL CHECK(win IN (0, 1)),
     time INT NOT NULL CHECK(time > 0),
-    mana INT NOT NULL CHECK(mana > 0),
-    energy INT NOT NULL CHECK(energy > 0),
-    crystal INT NOT NULL CHECK(crystal > 0),
+    mana INT NOT NULL CHECK(mana >= 0),
+    energy INT NOT NULL CHECK(energy >= 0),
+    crystal INT NOT NULL CHECK(crystal >= 0),
     helper INT NOT NULL CHECK(helper IN (0, 1))
 );
 CREATE TABLE IF NOT EXISTS run_party(
@@ -417,7 +417,6 @@ CREATE TABLE IF NOT EXISTS run_drop_rune(
     slot INT NOT NULL CHECK(slot BETWEEN 1 AND 6),
     stars INT NOT NULL CHECK(stars BETWEEN 1 AND 6),
     ancient INT NOT NULL CHECK(ancient IN (0, 1)),
-    level INT NOT NULL CHECK(level BETWEEN 0 AND 15),
     quality INT NOT NULL REFERENCES k_quality(id),
     value INT NOT NULL CHECK(value > 0),
     efficiency FLOAT NOT NULL CHECK(efficiency BETWEEN 0 AND 100),