diff --git a/src/nightserver.py b/src/nightserver.py index af2a7ac..4819fc8 100644 --- a/src/nightserver.py +++ b/src/nightserver.py @@ -130,7 +130,7 @@ def setFitness(): # Cyberware management cyberware = [] -newCyberwareTemplate = { "uuid": None, "name": None, "hotpluggable": False, "lastMalfunction": None, "canSet": [], "battery": None, "messages": [] } +newCyberwareTemplate = { "uuid": None, "name": None, "hotpluggable": False, "lastMalfunction": None, "canSet": None, "battery": None, "messages": None } newMessageTemplate = { "title": None, "message": None, "progress": None } # Messages: { Title, Message, Progress } # Title, Message, and Progress are all technically optional. It's up to the frontend to make heads or tails of what's happening. @@ -169,6 +169,7 @@ def addCyberware(): tempNewCyberware['name'] = tempName tempNewCyberware['hotpluggable'] = tempHotpluggable + cyberware.append(tempNewCyberware) except: return 'Incorrect usage.\nUsage: { name: STRING, hotpluggable: BOOL, canSet: ARRAY }\n', 400 @@ -226,8 +227,35 @@ def getCyberwareMessages(): if c['messages'] != None: returnArr.append({ 'name': c['name'], 'messages': c['messages'] }) resetMessages() + print(returnArr) return jsonify(returnArr), 200 +# Arguments { uuid: STRING, message:{ title: STRING, message: STRING, progress: INT } } +@app.route('/api/cyberware/messages', methods=['POST']) +def setCyberwareMessages(): + global cyberware + json = request.get_json() + + try: + desiredId = json['uuid'] + message = json['message'] + + # Test message validity + testTitle = message["title"] + testMessage = message["message"] + testProgress = message["progress"] + + requestedCyberware = getCyberwareHelper(desiredId) + + if (requestedCyberware != None): + if (requestedCyberware["messages"] == None): + requestedCyberware["messages"] = [] + requestedCyberware["messages"].append(message) + return '', 204 + except: + return "Incorrect usage.\nUsage: { uuid: STRING, message:{ title: STRING, message: STRING, progress: INT } }\n", 400 + return "UUID Invalid\n", 400 + @app.route('/api/cyberware/get', methods=['POST']) def getCyberwareSpecific(): json = request.get_json() @@ -243,7 +271,7 @@ def getCyberwareSpecific(): return 'Incorrect usage.\nUsage: { uuid: STRING }\n', 400 return 'UUID Invalid\n', 400 -# Arguments { uuid: INT } +# Arguments { uuid: STRING } @app.route('/api/cyberware/battery') def getCyberwareBattery(): json = request.get_json() @@ -262,6 +290,7 @@ def getCyberwareBattery(): # Arguments { uuid: STRING, battery: INT } @app.route('/api/cyberware/battery', methods=['POST']) def setCyberwareBattery(): + global cyberware json = request.get_json() try: @@ -284,6 +313,7 @@ def resetAllCyberwareMalfunction(): # Arguments { uuid: STRING } @app.route('/api/cyberware/reset_malfunction', methods=['POST']) def resetCyberwareMalfunction(): + global cyberware json = request.get_json() try: @@ -299,22 +329,29 @@ def resetCyberwareMalfunction(): return 'UUID Invalid\n', 400 def resetMalfunctions(): + global cyberware for c in cyberware: c['lastMalfunction'] = None def resetMessages(): + global cyberware for c in cyberware: - newMessageList = [] - for m in c['messages']: - if(m['progress'] == None): # Unless we're FULLY resetting messages, we want to keep messages with a progress bar attached. - newMessageList.append(m) - c['messages'] = newMessageList + if c['messages'] != None: + newMessageList = [] + for m in c['messages']: + if(m['progress'] != None): # Unless we're FULLY resetting messages, we want to keep messages with a progress bar attached. + newMessageList.append(m) + if newMessageList == []: + c['messages'] = None + else: + c['messages'] = newMessageList def resetMessagesFull(): + global cyberware for c in cyberware: c['messages'] = None -def getCyberwareHelper(uuid): +def getCyberwareHelper(desiredId): i = 0 for c in cyberware: if c['uuid'] == desiredId: diff --git a/src/templates/index.html b/src/templates/index.html index 18cec3c..e098c12 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -218,16 +218,32 @@