SHOW:
|
|
- or go back to the newest paste.
| 1 | args = {...}
| |
| 2 | alert = nil | |
| 3 | sender = nil | |
| 4 | notes = nil | |
| 5 | isDebugging = false | |
| 6 | ||
| 7 | function mouse_wrapper(minX, maxX, Y) | |
| 8 | event, button, xPos, yPos = os.pullEvent(mouse_click) | |
| 9 | if (xPos >= minX or xPos <= maxX and yPos == Y) then | |
| 10 | return true | |
| 11 | else | |
| 12 | return false | |
| 13 | end | |
| 14 | end | |
| 15 | ||
| 16 | function key_wrapper(keyYes) | |
| 17 | event, key = os.pullEvent(mouse_click) | |
| 18 | if key==keyYes then | |
| 19 | return true | |
| 20 | else | |
| 21 | return false | |
| 22 | end | |
| 23 | end | |
| 24 | ||
| 25 | function doError() | |
| 26 | error("Wrong event code")
| |
| 27 | end | |
| 28 | ||
| 29 | function openModems() | |
| 30 | for _, v in pairs(rs.getSides()) do | |
| 31 | if peripheral.getType(v) == "modem" then | |
| 32 | rednet.open(v) | |
| 33 | if isDebugging then print("[Debug mode] Attempted to open modem on side: "..v) end
| |
| 34 | end | |
| 35 | end | |
| 36 | end | |
| 37 | ||
| 38 | function broadcastAlert(same_raw, same_dec, sndr, message) | |
| 39 | term.clear() | |
| 40 | term.setCursorPos(1, 1) | |
| 41 | print("You are going to broadcast:")
| |
| 42 | print("Alert type: "..same_dec)
| |
| 43 | print("Sender: "..sndr)
| |
| 44 | print("Description: "..message)
| |
| 45 | print("[Broadcast (Y)] [Cancel]")
| |
| 46 | if term.isColour() then | |
| 47 | if mouse_wrapper(1,14,4) then | |
| 48 | rednet.broadcast(textutils.formatTime(os.time(), false)..";"..same_raw..";"..sndr..";"..message, "easraw") | |
| 49 | rednet.broadcast(same_dec.." has been issued by "..sndr.." with text \""..message.."\"", "easp") | |
| 50 | if isDebugging then print("[Debug mode] Attempted to broadcast EAS transmission") end
| |
| 51 | print("Broadcasted successfully")
| |
| 52 | else | |
| 53 | print("Cancelled")
| |
| 54 | end | |
| 55 | else | |
| 56 | if key_wrapper("Y") then
| |
| 57 | if isDebugging then print("[Debug mode] Attempted to broadcast EAS transmission") end
| |
| 58 | rednet.broadcast(textutils.formatTime(os.time(), false)..";"..same_raw..";"..sndr..";"..message, "easraw") | |
| 59 | rednet.broadcast(same_dec.." has been issued by "..sndr.." with text \""..message.."\"", "easp") | |
| 60 | print("Broadcasted successfully")
| |
| 61 | else | |
| 62 | print("Cancelled")
| |
| 63 | end | |
| 64 | end | |
| 65 | end | |
| 66 | ||
| 67 | function same_decode(code) | |
| 68 | local same_d = nil | |
| 69 | if code == "EAN" then | |
| 70 | same_d = "Emergency Action Notification" | |
| 71 | sender = "EAN Network" | |
| 72 | elseif code == "EAT" then | |
| 73 | same_d = "Emergency Action Termination" | |
| 74 | sender = "EAN Network" | |
| 75 | elseif code == "EVI" then | |
| 76 | same_d = "Evacuation Immediate" | |
| 77 | sender = "Civil Authorities" | |
| 78 | elseif code == "CDW" then | |
| 79 | same_d = "Civil Danger Warning" | |
| 80 | sender = "Civil Authorities" | |
| 81 | elseif code == "CEM" then | |
| 82 | same_d = "Civil Emergency Message" | |
| 83 | sender = "Civil Authorities" | |
| 84 | elseif code == "ADM" then | |
| 85 | same_d = "Administrative Message" | |
| 86 | sender = "Civil Authorities" | |
| 87 | elseif code == "LAE" then | |
| 88 | same_d = "Local Area Emergency" | |
| 89 | sender = "Civil Authorities" | |
| 90 | elseif code == "LEW" then | |
| 91 | same_d = "Law Enforcement Warning" | |
| 92 | sender = "Civil Authorities" | |
| 93 | elseif code == "NIC" then | |
| 94 | same_d = "National Information Center Statement" | |
| 95 | sender = "National Information Center" | |
| 96 | elseif code == "HMW" then | |
| 97 | same_d = "Hazardous Materials Warning" | |
| 98 | sender = "Environmental Protection Agency" | |
| 99 | elseif code == "SPW" then | |
| 100 | same_d = "Shelter-In-Place Warning" | |
| 101 | sender = "Civil Authorities" | |
| 102 | elseif code == "SVS" then | |
| 103 | same_d = "Severe Weather Statement" | |
| 104 | sender = "National Weather Service" | |
| 105 | elseif code == "TOR" then | |
| 106 | same_d = "Tornado Warning" | |
| 107 | sender = "National Weather Service" | |
| 108 | elseif code == "BHW" then | |
| 109 | same_d = "Biological Hazard Warning" | |
| 110 | sender = "Centers for Disease Control and Prevention" | |
| 111 | elseif code == "CHW" then | |
| 112 | same_d = "Chemical Hazard Warning" | |
| 113 | sender = "Centers for Disease Control and Prevention" | |
| 114 | elseif code == "FCW" then | |
| 115 | same_d = "Food Contamination Warning" | |
| 116 | sender = "Centers for Disease Control and Prevention" | |
| 117 | elseif code == "WCW" then | |
| 118 | same_d = "Water Contamination Warning" | |
| 119 | sender = "Centers for Disease Control and Prevention" | |
| 120 | elseif code == "FLW" then | |
| 121 | same_d = "Flood Warning" | |
| 122 | sender = "National Weather Service" | |
| 123 | elseif code == "EQW" then | |
| 124 | same_d = "Earthquake Warning" | |
| 125 | sender = "National Weather Service" | |
| 126 | elseif code == "TSW" then | |
| 127 | same_d = "Tsunami Warning" | |
| 128 | sender = "National Weather Service" | |
| 129 | else | |
| 130 | doError() | |
| 131 | end | |
| 132 | return same_d | |
| 133 | end | |
| 134 | ||
| 135 | openModems() | |
| 136 | term.clear() | |
| 137 | term.setCursorPos(1, 1) | |
| 138 | if args[1] == "-debug" then | |
| 139 | if term.isColour then | |
| 140 | print("[Debug mode] Running on Advanced PC.")
| |
| 141 | else | |
| 142 | print("[Debug mode] Running on Standard PC.")
| |
| 143 | end | |
| 144 | isDebugging = true | |
| 145 | end | |
| 146 | sleep(0.5) | |
| 147 | term.clear() | |
| 148 | term.setCursorPos(15, 1) | |
| 149 | print("EMERGENCY ALERT SYSTEM")
| |
| 150 | print("")
| |
| 151 | print("National Emergency Codes: EAN, EAT, NIC.")
| |
| 152 | print("Civil Emergency Codes: EVI, CDW, CEM, ADM, LAE.")
| |
| 153 | print("NWS Weather Codes: SVS, TOR, FLW, EQW, TSW.")
| |
| 154 | print("Specialized Alert Codes:")
| |
| 155 | print("LEW, HMW, SPW, BHW, CHW, FCW, WCW.")
| |
| 156 | print("See \"Specific Area Message Encoding\"")
| |
| 157 | print("on Wikipedia for further information.")
| |
| 158 | write("Enter event code: ")
| |
| 159 | local inputc = read() | |
| 160 | if isDebugging then print("[Debug mode] Received Event Code: "..inputc) end
| |
| 161 | print("Received type: ".. same_decode(inputc))
| |
| 162 | alert = same_decode(inputc) | |
| 163 | write("Enter message: ")
| |
| 164 | local inputm = read() | |
| 165 | print("Received text: "..inputm)
| |
| 166 | notes = inputm | |
| 167 | broadcastAlert(inputc, alert, sender, notes) |