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

@@ -48,7 +48,9 @@ function Core:read()
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)
@@ -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");
@@ -102,3 +104,15 @@ function Core:download(file)
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