Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NETWORK_SIDE = "right"
- MINER_SIDE = "back"
- NETWORK_BROADCAST_CHANNEL = 1
- NETWORK_LISTEN_CHANNEL = os.getComputerID() % 0xFFFF
- MESSAGE_PING = "miner ping"
- MESSAGE_INITIALIZE = "miner initialize"
- MESSAGE_STATUS = "miner status"
- MESSAGE_STATUS_IDLE = "miner status idle"
- MESSAGE_DISCONNECT = "miner disconnect"
- function WaitForConnection()
- while true do
- local event, side, in_channel, out_channel, message, distance = os.pullEvent("modem_message");
- if (message == MESSAGE_PING) then
- return out_channel
- end
- end
- end
- miner = peripheral.wrap(MINER_SIDE)
- wireless = peripheral.wrap(NETWORK_SIDE)
- wireless.open(NETWORK_BROADCAST_CHANNEL);
- wireless.open(NETWORK_LISTEN_CHANNEL);
- --while true do
- local server_channel = WaitForConnection();
- print("Connected to Server @ " .. server_channel);
- wireless.transmit(server_channel, NETWORK_LISTEN_CHANNEL, MESSAGE_INITIALIZE);
- while true do
- local event, side, in_channel, out_channel, message, distance = os.pullEvent("modem_message");
- if message == MESSAGE_DISCONNECT then
- break
- end
- if message == MESSAGE_STATUS then
- print("Sending status");
- wireless.transmit(server_channel, NETWORK_LISTEN_CHANNEL, MESSAGE_STATUS_IDLE);
- end
- end
- print("Disconnected from Server " .. server_channel);
- --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement