Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Lupus590 committed Jan 15, 2018
1 parent 3bb21d7 commit 000b711
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hopperServer .lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local transportRequestAPI = dofile("transportRequestAPI.lua")

while true do
-- listen for transport requests and watch for arrivals
local event = {os.pullEvent()}
local event = table.pack(os.pullEvent())
if event[1] == "turtle_inventory" then

elseif event[1] == "modem_message" then
Expand Down
36 changes: 36 additions & 0 deletions turtleTransportAPI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,49 @@

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



Expand Down

0 comments on commit 000b711

Please sign in to comment.