mirror of
https://github.com/Kiritow/OpenComputerScripts.git
synced 2024-03-22 13:10:46 +08:00
kiritow
757d965bf2
Fix GetNextEvent. Now GetNextEvent will wait infinitely by default. Update transport system due to libnetbox api update.
66 lines
1.4 KiB
Lua
66 lines
1.4 KiB
Lua
local component=require("component")
|
|
require("libevent")
|
|
require("libnetbox")
|
|
require("util")
|
|
|
|
--- Auto Configure
|
|
local network_card = proxy("modem")
|
|
|
|
local function checkDevice()
|
|
print("Checking Devices...")
|
|
|
|
local function doCheckDevice(device)
|
|
if(device==nil) then
|
|
error("Some device is nil. Please double check your configure.")
|
|
end
|
|
end
|
|
|
|
doCheckDevice(network_card)
|
|
|
|
print("Device check pass.")
|
|
end
|
|
|
|
local idt={}
|
|
|
|
local function getNextID()
|
|
local nextid=1
|
|
for k,v in pairs(idt) do
|
|
if(k>nextid) then nextid=k+1 end
|
|
end
|
|
idt[nextid]=true
|
|
return nextid
|
|
end
|
|
|
|
local function main()
|
|
checkDevice()
|
|
NetBoxInit()
|
|
|
|
OpenPort(10010)
|
|
|
|
print("Center Started. Press Ctrl+C to stop.")
|
|
|
|
while true do
|
|
local e=WaitEvent()
|
|
if(e~=nil) then
|
|
if(e.event=="net_message" and e.data[1]=="TSCM") then
|
|
if(e.data[2]=="req") then
|
|
if(e.data[3]=="store") then
|
|
local id=getNextID()
|
|
SendData(e.senderAddress,10011,"TSCM","ack","pass",id)
|
|
print("NextID: ",id)
|
|
end
|
|
end
|
|
elseif(e.event=="interrupted") then
|
|
break
|
|
end
|
|
end
|
|
end
|
|
|
|
ClosePort(10010)
|
|
NetBoxCleanUp()
|
|
end
|
|
|
|
print("Transport System Center Started.")
|
|
print("Author: Kiritow")
|
|
main()
|
|
print("Transport System Center Stopped.") |