Compare commits
3 Commits
3bd305dc10
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
448e0354ea
|
|||
|
2edb549156
|
|||
|
37c404603d
|
45
core.lua
45
core.lua
@@ -98,16 +98,45 @@ function Core:download(file)
|
||||
return false, "Invalid type: "..textutils.serialiseJSON(data)
|
||||
end
|
||||
|
||||
if fs.exists(file) then
|
||||
fs.delete(file);
|
||||
end
|
||||
|
||||
local fileStream = io.open(file, "w");
|
||||
fileStream:write(data.fileContent);
|
||||
|
||||
if not fileStream then
|
||||
return false, "Failed to open fileStream"
|
||||
end
|
||||
|
||||
fileStream:write(data.data);
|
||||
fileStream:close();
|
||||
|
||||
return true, "Success"
|
||||
end
|
||||
|
||||
function Core:tick()
|
||||
if not self then
|
||||
error("No instance!")
|
||||
end
|
||||
|
||||
if not self.ws then
|
||||
return false, "Not initilized"
|
||||
end
|
||||
|
||||
self:send({type = "TICK"});
|
||||
|
||||
local success, data = self:read();
|
||||
|
||||
if not success then
|
||||
return false, "Failed to do anything: "..data;
|
||||
end
|
||||
|
||||
print("Server expects Action: "..textutils.serialiseJSON(data))
|
||||
end
|
||||
|
||||
function Core:disconnect()
|
||||
if not self then
|
||||
return "Not instance"
|
||||
error("No instance!")
|
||||
end
|
||||
|
||||
if not self.ws then
|
||||
@@ -115,4 +144,16 @@ function Core:disconnect()
|
||||
end
|
||||
|
||||
self.ws.close();
|
||||
end
|
||||
|
||||
function Core:setLoop(loop)
|
||||
self.loop = loop;
|
||||
end
|
||||
|
||||
function Core:start()
|
||||
while true do
|
||||
if self.loop then
|
||||
self.loop();
|
||||
end
|
||||
end
|
||||
end
|
||||
9
downloadCore.lua
Normal file
9
downloadCore.lua
Normal file
@@ -0,0 +1,9 @@
|
||||
require("core")
|
||||
|
||||
local core = Core.new();
|
||||
|
||||
core:connect();
|
||||
|
||||
core:download("core.lua");
|
||||
|
||||
core:disconnect();
|
||||
Reference in New Issue
Block a user