diff --git a/Makefile b/Makefile index 573c0ae..1e37cb2 100644 --- a/Makefile +++ b/Makefile @@ -27,3 +27,6 @@ watch: debug: craftos --mount-ro /=build + +webconsole: + node console.js diff --git a/console.js b/console.js new file mode 100644 index 0000000..c66c5a1 --- /dev/null +++ b/console.js @@ -0,0 +1,30 @@ +const http = require('http'); + +function time() { + let now = new Date(); + + return `${now.getHours().toString().padStart(2,"0")}:${now.getMinutes().toString().padStart(2,0)}:${now.getSeconds().toString().padStart(2,0)}`; +} + +const server = http.createServer((req,res)=>{ + + if (req.method != "POST" ){ + res.writeHead(400); + return; + } + + let data = ""; + + req.on('data', chunk => { + data += chunk; + }) + + req.on('end', () => { + console.log(`[${time()}]${data}`); + res.writeHead(200); + res.end(); + }) +}); + +console.log("Listening on port 8080") +server.listen(8080); diff --git a/src/kernel/Log.hx b/src/kernel/Log.hx index 13cbf80..d683d90 100644 --- a/src/kernel/Log.hx +++ b/src/kernel/Log.hx @@ -1,5 +1,6 @@ package kernel; +import util.Debug; import kernel.ui.WindowContext; import kernel.ui.WindowManager; import lib.TermWriteable; @@ -18,18 +19,30 @@ class Log { public static function info(msg: Dynamic, ?pos:haxe.PosInfos){ writer.writeLn("[INFO]["+pos.className+"]: "+Std.string(msg)); + #if webconsole + Debug.printWeb("[INFO]["+pos.className+"]: "+Std.string(msg)); + #end } public static function warn(msg: Dynamic, ?pos:haxe.PosInfos){ writer.writeLn("[WARN]["+pos.className+"]: "+Std.string(msg),Yellow); + #if webconsole + Debug.printWeb("[WARN]["+pos.className+"]: "+Std.string(msg)); + #end } public static function error(msg: Dynamic,?pos:haxe.PosInfos) { writer.writeLn("[ERRO]["+pos.className+"]: "+Std.string(msg),Red); + #if webconsole + Debug.printWeb("[ERRO]["+pos.className+"]: "+Std.string(msg)); + #end } public static function debug(msg: Dynamic,?pos:haxe.PosInfos) { writer.writeLn("[DEBG]["+pos.className+"]: "+Std.string(msg),Gray); + #if webconsole + Debug.printWeb("[DEBG]["+pos.className+"]: "+Std.string(msg)); + #end } public static function moveToOutput(addr: String) { diff --git a/src/util/Debug.hx b/src/util/Debug.hx index 929b83e..01e4b39 100644 --- a/src/util/Debug.hx +++ b/src/util/Debug.hx @@ -1,5 +1,6 @@ package util; +import cc.HTTP; import cc.ComputerCraft; import kernel.Log; @@ -13,4 +14,10 @@ class Debug { Log.debug("CC/MC version:" + ComputerCraft._HOST); } + + #if webconsole + public static function printWeb(msg: String) { + HTTP.post("http://127.0.0.1:8080/",msg); + } + #end }