-
Notifications
You must be signed in to change notification settings - Fork 0
/
botserver.lua
87 lines (84 loc) · 2.74 KB
/
botserver.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
local component = require("component")
local computer = require("computer")
local robot = require("robot")
local shell = require("shell")
local sides = require("sides")
local event = require("event")
local keyboard = require("keyboard")
local tunnel = component.tunnel
local function handleResponse(failed, message)
failedStr = tostring(failed)
if failed then
robot.setLightColor(0x00FF00)
else
robot.setLightColor(0x808000)
end
if message then
return failedStr .. " " .. message
else
return failedStr
end
end
local function handleControl()
robot.setLightColor(0xFFC0CB)
if keyboard.isKeyDown(keyboard.keys.w) and keyboard.isControlDown() then
robot.setLightColor(0xFF0000)
os.exit()
end
local _, localNetworkCard, remoteAddress, port, distance, payload = event.pull("modem_message")
if payload == "c" then
robot.setLightColor(0xFF0000)
os.exit()
elseif payload == "w" then
failed, message = robot.forward()
tunnel.send(handleResponse(failed, message))
elseif payload == "s" then
failed, message = robot.back()
tunnel.send(handleResponse(failed, message))
elseif payload == "a" then
failed, message = robot.turnLeft()
tunnel.send(handleResponse(failed, message))
elseif payload == "d" then
failed, message = robot.turnRight()
tunnel.send(handleResponse(failed, message))
elseif payload == "z" then
failed, message = robot.swing()
tunnel.send(handleResponse(failed, message))
robot.suck()
robot.suckUp()
robot.suckDown()
elseif payload == "t" then
failed, message = robot.suck()
message1 = handleResponse(failed, message)
failed, message = robot.suckUp()
message2 = handleResponse(failed, message)
failed, message = robot.suckDown()
message3 = handleResponse(failed, message)
tunnel.send("Suck: " .. message1 .. " SuckUp: " .. message2 .. " SuckDown: ".. message3)
elseif payload == "x" then
failed, message = robot.use()
tunnel.send(handleResponse(failed, message))
elseif payload == "v" then
failed, message = robot.place()
tunnel.send(handleResponse(failed, message))
elseif payload == "q" then
failed, message = robot.up()
tunnel.send(handleResponse(failed, message))
elseif payload == "f" then
tunnel.send("Inventory slot number? ")
local _, localNetworkCard, remoteAddress, port, distance, payload = event.pull("modem_message")
number = tostring(robot.select(tonumber(payload)))
tunnel.send(number)
elseif payload == "r" then
computer.beep(500, 0.25)
tunnel.send("beep!")
elseif payload == "e" then
failed, message = robot.down()
tunnel.send(handleResponse(failed, message))
end
end
print("Press ctrl+w to quit")
robot.setLightColor(0xFFC0CB)
while true do
handleControl()
end