blob: 69576e175e0a15cd30052810bf1b37f13e0092da (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
local json = require("json")
Messages = {
-- Handshake
RequestServerInfo = {
RequestServerInfo = {
Id = 1,
ClientName = "Funsaac v0.0.2",
MessageVersion = 3
}
},
-- Enumeration
StartScanning = {
StartScanning = {
Id = 1
}
}
}
local cnt = 1;
function GetMessage(msg)
local message = msg
message[next(msg)]["Id"] = cnt
cnt = cnt + 1
return "[" .. json.encode(message) .. "]"
end
function ResponseContent(message)
local msg = json.decode(message)[1]
local type = next(msg)
return type, msg[type]
end
function HandleResponse(type, content)
if type == "ServerInfo" then
print("Connected to Server: " .. content["ServerName"])
CONNECTED = true
elseif type == "Ok" then
print("Id: " .. content["Id"])
elseif type == "DeviceAdded" then
print("DeviceAdded: " .. content["DeviceName"])
end
end
|