Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local CLIENT_NAME = 'Tydium'
- local DEFAULT_AUTH = nil -- optional
- local SERVER_PORT,CLIENT_PORT,AUTH = ...
- SERVER_PORT = SERVER_PORT or 17234
- CLIENT_PORT = CLIENT_PORT or 17235
- AUTH = AUTH or DEFAULT_AUTH
- local modem = peripheral.find('modem')
- print('Starting redstone client on port '..CLIENT_PORT)
- if not modem then
- print('No modem connected')
- return
- end
- modem.open(CLIENT_PORT)
- print('Successfully connected')
- print('Type your commands below using the format "channel=level".')
- print('Example: siren=15\n')
- print('Other commands:')
- print(' enable <channel>')
- print(' disable <channel>')
- print(' impulse <channel> [number duration]')
- print(' exit')
- function showResponses()
- while true do
- local event, side, senderPort, replyPort, message, distance = os.pullEvent('modem_message')
- if type(message) == 'string' then
- print('Recieved string response: "'..message..'"')
- elseif type(message) == 'table' and message.response then
- print(tostring(message.author_name)..': '..tostring(message.response))
- end
- end
- end
- function sendSignal(channel, level)
- modem.transmit(SERVER_PORT, CLIENT_PORT, {
- level = level,
- channel = channel,
- author_name = CLIENT_NAME,
- })
- end
- function processCommands()
- while true do
- command = read()
- if command == 'exit' then
- return
- elseif command:sub(1,8) == 'disable ' then
- sendSignal(command:sub(9, #command), 0)
- elseif command:sub(1,7) == 'enable ' then
- sendSignal(command:sub(8, #command), 15)
- elseif command:find('=') then
- local equalIndex = command:find('=')
- local level = tonumber(command:sub(equalIndex + 1))
- if level then
- sendSignal(command:sub(1, equalIndex - 1), level)
- else
- print('level is not a valid number')
- end
- elseif command:sub(1,8) == 'impulse ' then
- sendSignal(command:sub(9, #command), 15)
- local spaceIndex = command:sub(9,#command):find(' ') or #command
- local length = tonumber(command:sub(spaceIndex + 1, #command)) or 1
- os.sleep(length)
- sendSignal(command:sub(9, #command), 0)
- else
- print('Unknown command.')
- end
- end
- end
- parallel.waitForAny(processCommands, showResponses)
- modem.close(CLIENT_PORT)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement