-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturtleTransportAPI.lua
61 lines (41 loc) · 1.79 KB
/
turtleTransportAPI.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
-- os.loadAPI or require, both should work
local api = shell and {} or (_ENV or getfenv())
if not rednet.host then
error("turtleTransportAPI can't find a required function. It's possible that your CC version is too old.")
end
api.PROTOCOL_NAME = "turtleTransportationFramework"
api.bindModem = rednet.open
-- Transport Station API
-- This is the API for computers which run the stations where turtles 'board' the transports.
api.transportStationAPI = {}
local transportStationAPI = api.transportStationAPI -- cache for internal use
local STATION_NAME
local routes = {}
function transportStationAPI.registerStation(stationName)
if type(stationName) ~= "string" then
return false, "Station name must be a string."
end
STATION_NAME = stationName
local success, errorString = pcall(rednet.host, api.PROTOCOL_NAME, STATION_NAME)
if not success then
if type(errorString) == "string" and errorString == "pcall: Hostname in use" then
return false, "Station name already registered, on multiplayer servers it's recommended to prepend destinations with your username."
elseif type(errorString) == "string" and errorString == "Reserved hostname" then
return false, "Invalid station name"
else
error("unknown error from pcall rednet.host: "..tostring(errorString))
end
end
return true
end
function transportStationAPI.unregisterStation()
rednet.unhost(PROTOCOL_NAME)
end
function transportStationAPI.registerRoute(remoteStationNameOrID) -- TODO: decide how this works
if type(remoteStationNameOrID) == "string" then
end
-- Turtle API
-- This is the API for the turtles which will be transported using the system.
api.turtleAPI = {}
local turtleAPI = api.turtleAPI -- cache for internal use
return api