From c3d0f628e599b73e310f1a62cad5ba6542a359d4 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 1 Jul 2016 07:50:35 +0200 Subject: [PATCH] log init message --- src/arenas/tron/act.php | 16 ++++++---------- src/arenas/tron/js.js | 21 +++++++++++++++++++-- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index b3783cb..f3b7722 100644 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -69,16 +69,12 @@ switch ($_POST['act']){ } } - /* - if($_POST['fullLogs'] == "true"){ - $fullLogs='Arena send to '.$playerName.''.htmlentities($tempPlayer['messageSend']).'
- HTTP status: '.htmlentities($tempPlayer['httpStatus']).'
- Bot anwser: '.htmlentities($tempPlayer['response']).'
'; - - }else{ - $fullLogs=''; - } - */ + + return json_encode(array( + 'status' => 'OK', + 'logs' => $logs + )); + die; break; default: diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index e7ed5c1..12757b6 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -4,6 +4,14 @@ function createElem(type,attributes){ {elem.setAttribute(i,attributes[i]);} return elem; } +function addLog(message){ + var divLogs = document.getElementById("logs"); + var p=createElem('p',{}); + p.innerHTML=message; + divLogs.appendChild(p); + divLogs.scrollTop = divLogs.scrollHeight; + +} function createElemNS(type,attributes){ //same as createElem but with ns for svg file var elem=document.createElementNS("http://www.w3.org/2000/svg",type); @@ -52,7 +60,14 @@ function applyInitMessage(req){ //callback function when init game request if(req.readyState == 4){ if(req.status == 200) { - alert (req.responseText); + //alert (req.responseText); + try{ + var ret = JSON.parse(req.responseText); + }catch(e){ + addLog('erreur' +xhr.responseText); + return; + } + addLog(ret['logs']); }else{ alert ('error ' + req.status); @@ -71,7 +86,9 @@ function tron(xd_check){ var rect=createElemNS('rect',{'x':'0','y':'0','width':'1000','height':'1000','style':'stroke:#000000; fill:none;'}); svg.appendChild(rect); document.getElementById("fightResult").appendChild(svg); - + + var plogs = createElem("p",{'id':'logs'}); + document.getElementById("fightResult").appendChild(plogs); //get bot list var botsList=[]; var i=0;