Compare commits
2 Commits
13a0d4dbaf
...
3bd305dc10
| Author | SHA1 | Date | |
|---|---|---|---|
|
3bd305dc10
|
|||
|
9f3771cea9
|
32
core.lua
32
core.lua
@@ -43,19 +43,21 @@ function Core:read()
|
||||
if not self then
|
||||
error("No instance!")
|
||||
end
|
||||
|
||||
|
||||
if not self.ws then
|
||||
return false, "Websocket not initiated";
|
||||
end
|
||||
|
||||
return true, textutils.unserialiseJSON(self.ws.receive())
|
||||
local data, success = self.ws.receive()
|
||||
|
||||
return true, textutils.unserialiseJSON(data)
|
||||
end
|
||||
|
||||
function Core:download(file)
|
||||
if not self then
|
||||
error("No instance!")
|
||||
end
|
||||
|
||||
|
||||
if not self.ws then
|
||||
return false, "Websocket not initiated";
|
||||
end
|
||||
@@ -65,15 +67,15 @@ function Core:download(file)
|
||||
local success, data = self:read();
|
||||
|
||||
if not success then
|
||||
return false, "Failed to read: "+data;
|
||||
return false, "Failed to read: "..data;
|
||||
end
|
||||
|
||||
if not data.type then
|
||||
return false, "Invalid package: "+textutils.serialiseJSON(data);
|
||||
return false, "Invalid package: "..textutils.serialiseJSON(data);
|
||||
end
|
||||
|
||||
if not (data.type == "FILE_INFO") then
|
||||
return false, "Invalid package type: "+textutils.serialiseJSON(data);
|
||||
return false, "Invalid package type: "..textutils.serialiseJSON(data);
|
||||
end
|
||||
|
||||
if not data.exists then
|
||||
@@ -85,15 +87,15 @@ function Core:download(file)
|
||||
local success, data = self:read();
|
||||
|
||||
if not success then
|
||||
return false, "Failed to read: "+data;
|
||||
return false, "Failed to read: "..data;
|
||||
end
|
||||
|
||||
if not data.type then
|
||||
return false, "Invalid package: "+textutils.serialiseJSON(data);
|
||||
return false, "Invalid package: "..textutils.serialiseJSON(data);
|
||||
end
|
||||
|
||||
if not data.type == "FILE_DATA" then
|
||||
return false, "Invalid type: "+textutils.serialiseJSON(data)
|
||||
return false, "Invalid type: "..textutils.serialiseJSON(data)
|
||||
end
|
||||
|
||||
local fileStream = io.open(file, "w");
|
||||
@@ -101,4 +103,16 @@ function Core:download(file)
|
||||
fileStream:close();
|
||||
|
||||
return true, "Success"
|
||||
end
|
||||
|
||||
function Core:disconnect()
|
||||
if not self then
|
||||
return "Not instance"
|
||||
end
|
||||
|
||||
if not self.ws then
|
||||
return "Not initilized"
|
||||
end
|
||||
|
||||
self.ws.close();
|
||||
end
|
||||
Reference in New Issue
Block a user