Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ARGS = {...}
- local SERVER_NAME = ARGS[3] or 'tydium_siren'
- local CHANNEL = ARGS[1] or 'siren'
- local OUTPUT_SIDE = ARGS[4] or 'left'
- local PORT = ARGS[2] or 17234
- local AUTHENTICATION = nil -- if specified, clients must include a password under message.auth
- local repr = require('cc.pretty').pretty
- local modem = peripheral.find('modem')
- modem.open(PORT)
- function handleEvent(message, senderPort, replyPort)
- if type(message) ~= 'table' or type(message.level) ~= 'number' then
- modem.transmit(replyPort,senderPort, {
- success = false,
- response = 'Invalid message "'..repr(message)..'"',
- channel = CHANNEL..'_response',
- author_name = SERVER_NAME,
- description = {
- received_message = message
- }
- })
- return
- end
- if not (message.channel == CHANNEL or message.channel == 'all') then
- return
- end
- if AUTHENTICATION and message.auth ~= AUTHENTICATION then
- print('Client "'..tostring(message.author_name)..'" sent unauthorized request (key: '..tostring(message.auth)..')')
- modem.transmit(replyPort, senderPort, {
- success = false,
- response = 'Unauthorized',
- channel = CHANNEL..'_response',
- author_name = SERVER_NAME,
- description = {
- received_auth = message.auth,
- device_name = message.author_name
- }
- })
- end
- redstone.setAnalogOutput(OUTPUT_SIDE, message.level)
- print('Request recieved from client "'..tostring(message.author_name)..'" (port '..senderPort..') to change redstone level to '..message.level)
- modem.transmit(replyPort, senderPort, {
- success = true,
- response = 'Setting redstone output level to '..message.level,
- channel = CHANNEL..'_response',
- author_name = SERVER_NAME,
- description = {
- output_level = message.level,
- output_side = OUTPUT_SIDE,
- }
- })
- end
- while true do
- local event, side, senderPort, replyPort, message, distance = os.pullEvent('modem_message')
- handleEvent(message, senderPort, replyPort)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement