Compare commits

..

2 Commits

Author SHA1 Message Date
3bd305dc10 Added disconnect 2025-05-06 14:03:58 +02:00
9f3771cea9 Fixed syntax error 2025-05-06 14:01:57 +02:00

View File

@@ -43,19 +43,21 @@ function Core:read()
if not self then if not self then
error("No instance!") error("No instance!")
end end
if not self.ws then if not self.ws then
return false, "Websocket not initiated"; return false, "Websocket not initiated";
end end
return true, textutils.unserialiseJSON(self.ws.receive()) local data, success = self.ws.receive()
return true, textutils.unserialiseJSON(data)
end end
function Core:download(file) function Core:download(file)
if not self then if not self then
error("No instance!") error("No instance!")
end end
if not self.ws then if not self.ws then
return false, "Websocket not initiated"; return false, "Websocket not initiated";
end end
@@ -65,15 +67,15 @@ function Core:download(file)
local success, data = self:read(); local success, data = self:read();
if not success then if not success then
return false, "Failed to read: "+data; return false, "Failed to read: "..data;
end end
if not data.type then if not data.type then
return false, "Invalid package: "+textutils.serialiseJSON(data); return false, "Invalid package: "..textutils.serialiseJSON(data);
end end
if not (data.type == "FILE_INFO") then if not (data.type == "FILE_INFO") then
return false, "Invalid package type: "+textutils.serialiseJSON(data); return false, "Invalid package type: "..textutils.serialiseJSON(data);
end end
if not data.exists then if not data.exists then
@@ -85,15 +87,15 @@ function Core:download(file)
local success, data = self:read(); local success, data = self:read();
if not success then if not success then
return false, "Failed to read: "+data; return false, "Failed to read: "..data;
end end
if not data.type then if not data.type then
return false, "Invalid package: "+textutils.serialiseJSON(data); return false, "Invalid package: "..textutils.serialiseJSON(data);
end end
if not data.type == "FILE_DATA" then if not data.type == "FILE_DATA" then
return false, "Invalid type: "+textutils.serialiseJSON(data) return false, "Invalid type: "..textutils.serialiseJSON(data)
end end
local fileStream = io.open(file, "w"); local fileStream = io.open(file, "w");
@@ -101,4 +103,16 @@ function Core:download(file)
fileStream:close(); fileStream:close();
return true, "Success" 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 end