-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.lua
97 lines (83 loc) · 2.19 KB
/
main.lua
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---------------
-- ## vocontrol - a remote control plugin for Vendetta Online.
--
-- [Github Page](https://github.com/fhirschmann/vocontrol)
--
-- @author Fabian Hirschmann <[email protected]>
-- @copyright 2013
-- @license MIT/X11
vocontrol = {
VERSION="0.5",
http=dofile("lib/vohttp_packed.lua"),
util=dofile("util.lua"),
config=dofile("config.lua"),
}
-- Server setup
local server = vocontrol.http.Server:new()
local port = vocontrol.config.get("port")
for k, v in pairs(dofile("urls.lua")) do
server:add_route(k, v)
end
-- Stop listening on reload
RegisterEvent(function(event, data)
if server.listening then
server:stop()
end
end, "UNLOAD_INTERFACE")
-- CLI
local cmd = {
config={
set=vocontrol.config.set,
get=function(s) print(vocontrol.config.get(s)) end,
},
reload=ReloadInterface,
help=dofile("help.lua")}
function cmd.start()
server:start(port)
print("vocontrol: now listening on port "..port)
end
function cmd.stop()
server:stop()
print("vocontrol: no longer listening on port "..port)
end
function cmd.restart()
cmd.stop()
cmd.start()
end
function cmd.ctrl(...)
if ... ~= nil then
ProcessEvent("VOMOTE_CTRL", {...})
end
end
--- Dispatches function calls in a DFS-manner
-- @param root the top element in the function tree
-- @param args arguments given by the user
local function dispatch(root, args)
if type(root) == "table" and root[args[1]] ~= nil then
local a = table.remove(args, 1)
dispatch(root[a], args)
else
if type(root) == "table" then
print("vocontrol: incomplete command.")
else
root(unpack(args))
end
end
end
--- Main entry point for the Command Line Interface (CLI).
function cli(data, args)
if not args then
print("vocontrol: no arguments given - try /vocontrol help.")
else
local f = table.remove(args, 1)
if args and cmd[f] then
dispatch(cmd[f], args)
else
print("vocontrol: invalid argument(s).")
end
end
end
RegisterUserCommand("vocontrol", cli)
if vocontrol.config.get("autostart") == 1 then
cmd.start(port)
end