diff options
Diffstat (limited to 'messages.lua')
-rw-r--r-- | messages.lua | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/messages.lua b/messages.lua new file mode 100644 index 0000000..69576e1 --- /dev/null +++ b/messages.lua | |||
@@ -0,0 +1,46 @@ | |||
1 | local json = require("json") | ||
2 | |||
3 | Messages = { | ||
4 | -- Handshake | ||
5 | RequestServerInfo = { | ||
6 | RequestServerInfo = { | ||
7 | Id = 1, | ||
8 | ClientName = "Funsaac v0.0.2", | ||
9 | MessageVersion = 3 | ||
10 | } | ||
11 | }, | ||
12 | |||
13 | -- Enumeration | ||
14 | |||
15 | StartScanning = { | ||
16 | StartScanning = { | ||
17 | Id = 1 | ||
18 | } | ||
19 | } | ||
20 | } | ||
21 | |||
22 | local cnt = 1; | ||
23 | |||
24 | function GetMessage(msg) | ||
25 | local message = msg | ||
26 | message[next(msg)]["Id"] = cnt | ||
27 | cnt = cnt + 1 | ||
28 | return "[" .. json.encode(message) .. "]" | ||
29 | end | ||
30 | |||
31 | function ResponseContent(message) | ||
32 | local msg = json.decode(message)[1] | ||
33 | local type = next(msg) | ||
34 | return type, msg[type] | ||
35 | end | ||
36 | |||
37 | function HandleResponse(type, content) | ||
38 | if type == "ServerInfo" then | ||
39 | print("Connected to Server: " .. content["ServerName"]) | ||
40 | CONNECTED = true | ||
41 | elseif type == "Ok" then | ||
42 | print("Id: " .. content["Id"]) | ||
43 | elseif type == "DeviceAdded" then | ||
44 | print("DeviceAdded: " .. content["DeviceName"]) | ||
45 | end | ||
46 | end \ No newline at end of file | ||