patcher.lua 916 B

123456789101112131415161718192021222324252627282930
  1. require 'love.filesystem'
  2. local sha1 = require 'lib/deps/sha1/sha1'
  3. local http = require 'socket.http'
  4. local json = require 'lib/deps/dkjson'
  5. local protocol = 'http'
  6. local address = '96.126.101.55'
  7. local port = 7000
  8. local hash, hashes = ...
  9. local response = love.thread.getChannel('patcher.response')
  10. local function format(data)
  11. if not data then return '' end
  12. local t = {}
  13. for k, v in pairs(data) do t[#t + 1] = k .. '=' .. v end
  14. return table.concat(t, '&')
  15. end
  16. local str, code = http.request(protocol .. '://' .. address .. ':' .. port .. '/api/patch', format({hash = hash}))
  17. local json = json.decode(str)
  18. if code == 200 and json.patch then
  19. local str, code = http.request(protocol .. '://' .. address .. ':' .. port .. '/api/patch', format({hashes = hashes}))
  20. love.filesystem.write('patch.zip', str)
  21. end
  22. response:push(type(json) == 'table' and type(json.patch) == 'bool' and json.patch == true)