SHOW:
|
|
- or go back to the newest paste.
| 1 | --[[ICBM Launch Server]]-- | |
| 2 | ||
| 3 | size = {term.getSize()}
| |
| 4 | ||
| 5 | users = {"Andrew2070"}
| |
| 6 | passwords = {"3765"}
| |
| 7 | ||
| 8 | local silos = {}
| |
| 9 | local curSilo = 1 | |
| 10 | local hostName = "Andrew2060_Silo_System" | |
| 11 | local protocolName = "Andrew2060_Silo" | |
| 12 | rednet.host(protocolName, hostName) | |
| 13 | --[[Functions]]-- | |
| 14 | ||
| 15 | rednet.open("top")
| |
| 16 | local waitDelay = 2 | |
| 17 | ||
| 18 | local function red() | |
| 19 | term.setBackgroundColor(colors.red) | |
| 20 | print(" ")
| |
| 21 | term.setBackgroundColor(colors.blue) | |
| 22 | end | |
| 23 | ||
| 24 | local function findSilos() | |
| 25 | rednet.broadcast("ping silo")
| |
| 26 | ||
| 27 | local timerID = os.startTimer(waitDelay) | |
| 28 | ||
| 29 | while true do | |
| 30 | event, id, msg, distance = os.pullEvent() | |
| 31 | ||
| 32 | if event == "rednet_message" and msg == "pong" then | |
| 33 | table.insert(silos, id) | |
| 34 | timerID = os.startTimer(waitDelay) | |
| 35 | elseif event == "timer" and id == timerID then | |
| 36 | return | |
| 37 | end | |
| 38 | end | |
| 39 | end | |
| 40 | ||
| 41 | local function listenForSilos() | |
| 42 | while true do | |
| 43 | local message = {rednet.recive()}
| |
| 44 | if message[3] == protocolName then | |
| 45 | --# message is expected protocol, continue | |
| 46 | silo[#silo+1] = message[2] | |
| 47 | end | |
| 48 | end | |
| 49 | end | |
| 50 | ||
| 51 | local function printSiloInfo() | |
| 52 | if silo[1] then | |
| 53 | textutils.pagedTabulate({"ID", "Type", "Armed"}, unpack(silo))
| |
| 54 | else print("No connected slaves") end
| |
| 55 | end | |
| 56 | ||
| 57 | local function fire(ID) | |
| 58 | if silo[ID][3] then | |
| 59 | rednet.send(silo[ID][1],"fire", protocolName ) | |
| 60 | else print("Silo not armed, can't fire while not armed") end
| |
| 61 | end | |
| 62 | ||
| 63 | local function arm(ID) | |
| 64 | silo[ID][3] = "true" | |
| 65 | rednet.send(silo[ID][1],"arm", protocolName ) | |
| 66 | end | |
| 67 | ||
| 68 | local function disarm(ID) | |
| 69 | silo[ID][3] = "false" | |
| 70 | rednet.send(silo[ID][1],"disarm", protocolName ) | |
| 71 | end | |
| 72 | ||
| 73 | parallel.waitForAny(listenForSilos, main) | |
| 74 | ||
| 75 | local function launch(count, x, y, z) | |
| 76 | local msg = {x = x, y = y, z = z}
| |
| 77 | print("launching Missiles At " .. x .. ", " .. y .. ", " .. z)
| |
| 78 | for i = 1, count do | |
| 79 | rednet.send(silos[curSilo], msg) | |
| 80 | curSilo = (curSilo == #silos) and 1 or (curSilo + 1) | |
| 81 | sleep(5) | |
| 82 | end | |
| 83 | end | |
| 84 | ||
| 85 | local function printSilos() | |
| 86 | term.clear() | |
| 87 | term.setCursorPos(1,1) | |
| 88 | print(" [Detected silos] ")
| |
| 89 | for k, v in ipairs(silos) do | |
| 90 | print(" silo #" .. k .. " id = "..v)
| |
| 91 | end | |
| 92 | end | |
| 93 | ||
| 94 | function drawBoxPos(x,y,x1,y1) | |
| 95 | cy = y | |
| 96 | term.setCursorPos(x,y) | |
| 97 | for i = 1,(y1-y)+1 do | |
| 98 | for i = 1,(x1-x) do | |
| 99 | term.write(" ")
| |
| 100 | end | |
| 101 | cy = cy+1 | |
| 102 | term.setCursorPos(x,cy) | |
| 103 | end | |
| 104 | end | |
| 105 | ||
| 106 | function reset() | |
| 107 | term.setBackgroundColor(colors.lightGray) | |
| 108 | term.setCursorPos(2,12) | |
| 109 | for i = 1,size[1]-4 do | |
| 110 | term.write(" ")
| |
| 111 | end | |
| 112 | term.setTextColor(colors.gray) | |
| 113 | term.setBackgroundColor(colors.gray) | |
| 114 | drawBoxPos(9,8,size[1]-1,8) | |
| 115 | term.setBackgroundColor(colors.lightGray) | |
| 116 | term.setCursorPos(3,8) | |
| 117 | print("USER:")
| |
| 118 | term.setBackgroundColor(colors.gray) | |
| 119 | drawBoxPos(9,10,size[1]-1,10) | |
| 120 | term.setBackgroundColor(colors.lightGray) | |
| 121 | term.setCursorPos(3,10) | |
| 122 | print("PASS:")
| |
| 123 | end | |
| 124 | ||
| 125 | function loginScreen() | |
| 126 | term.setBackgroundColor(colors.white) | |
| 127 | term.clear() | |
| 128 | term.setBackgroundColor(colors.lightGray) | |
| 129 | drawBoxPos(2,2,size[1],size[2]-1) | |
| 130 | term.setCursorPos(1,size[2]-7) | |
| 131 | term.setBackgroundColor(colors.gray) | |
| 132 | drawBoxPos(((size[1]/2)-10)-1,2,((size[1]/2)+13)-1,4) | |
| 133 | term.setBackgroundColor(colors.red) | |
| 134 | drawBoxPos((size[1]/2)-10,1,(size[1]/2)+13,3) | |
| 135 | term.setTextColor(colors.gray) | |
| 136 | str = "Skynet Mainframe" | |
| 137 | term.setCursorPos((size[1]/2)-(#str/2) +1,2) | |
| 138 | term.write(str) | |
| 139 | term.setBackgroundColor(colors.lightGray) | |
| 140 | str = "Enter Authentication Credentials" | |
| 141 | term.setCursorPos((size[1]/2)-(#str/2) +1,6) | |
| 142 | term.write(str) | |
| 143 | term.setBackgroundColor(colors.gray) | |
| 144 | drawBoxPos(9,8,size[1]-1,8) | |
| 145 | term.setBackgroundColor(colors.lightGray) | |
| 146 | term.setCursorPos(3,8) | |
| 147 | print("USER:")
| |
| 148 | term.setBackgroundColor(colors.gray) | |
| 149 | drawBoxPos(9,10,size[1]-1,10) | |
| 150 | term.setBackgroundColor(colors.lightGray) | |
| 151 | term.setCursorPos(3,10) | |
| 152 | print("PASS:")
| |
| 153 | term.setBackgroundColor(colors.red) | |
| 154 | drawBoxPos(((size[1]/2)-9)-1,13,((size[1]/2)+13)-1,15) | |
| 155 | term.setTextColor(colors.gray) | |
| 156 | str = "Login to Skynet!" | |
| 157 | term.setCursorPos((size[1]/2)-(#str/2) +1,14) | |
| 158 | term.write(str) | |
| 159 | term.setBackgroundColor(colors.lightGray) | |
| 160 | str = "(c) 2016 Skynet - Build. Innovate. Conquer" | |
| 161 | term.setCursorPos((size[1]/2)-(#str/2) +1,size[2]-2) | |
| 162 | term.write(str) | |
| 163 | while true do | |
| 164 | evnt = {os.pullEvent()}
| |
| 165 | if evnt[1] == "mouse_click" then | |
| 166 | if evnt[3] > 8 and evnt[3] < size[1]-1 and evnt[4] == 8 then | |
| 167 | term.setBackgroundColor(colors.gray) | |
| 168 | term.setTextColor(colors.lightGray) | |
| 169 | term.setCursorPos(9,8) | |
| 170 | username = read() | |
| 171 | elseif evnt[3] > 8 and evnt[3] < size[1]-1 and evnt[4] == 10 then | |
| 172 | term.setBackgroundColor(colors.gray) | |
| 173 | term.setTextColor(colors.lightGray) | |
| 174 | term.setCursorPos(9,10) | |
| 175 | password = read("*")
| |
| 176 | elseif evnt[3] > ((size[1]/2)-9)-2 and evnt[3] < ((size[1]/2)+13)-2 and evnt[4] > 12 and evnt[4] < 16 then | |
| 177 | if username ~= nil and password ~= nil then | |
| 178 | loggedin = false | |
| 179 | for i = 1,#users do | |
| 180 | if username == users[i] then | |
| 181 | if password == passwords[i] then | |
| 182 | term.setTextColor(colors.lime) | |
| 183 | term.setBackgroundColor(colors.lightGray) | |
| 184 | str = "Access Granted. Welcome back, "..username | |
| 185 | term.setCursorPos((size[1]/2)-(#str/2) +1,12) | |
| 186 | term.write(str) | |
| 187 | loggedin = true | |
| 188 | sleep(3) | |
| 189 | end | |
| 190 | end | |
| 191 | end | |
| 192 | if loggedin then | |
| 193 | term.setBackgroundColor(colors.blue) | |
| 194 | term.clear() | |
| 195 | findSilos() | |
| 196 | - | print("Target Selection Complete:")
|
| 196 | + | |
| 197 | term.setBackgroundColor(colors.blue) | |
| 198 | term.clear() | |
| 199 | printSilos() | |
| 200 | red() | |
| 201 | write("Enter Launch Verification Code: ")
| |
| 202 | input = read() | |
| 203 | red() | |
| 204 | term.setBackgroundColor(colors.blue) | |
| 205 | if input == "exit" then | |
| 206 | break | |
| 207 | elseif input == "949-854-3444" then | |
| 208 | while true do | |
| 209 | sleep(1) | |
| 210 | red() | |
| 211 | write("Launch Confirmation [Yes/No]: ")
| |
| 212 | input2 = read() | |
| 213 | if input2 == "No" then | |
| 214 | os.reboot() | |
| 215 | elseif input2 == "Yes" then | |
| 216 | local count, x, y, z | |
| 217 | while not (type(count) == "number" and type(x) == "number" and type(y) == "number" and type(z) == "number") do | |
| 218 | red() | |
| 219 | print(" [Target Selection] ")
| |
| 220 | red() | |
| 221 | term.setBackgroundColor(colors.blue) | |
| 222 | write(" Missile Count: ")
| |
| 223 | count = tonumber(read()) | |
| 224 | print("Arming Warheads..")
| |
| 225 | arm(silos[curSilo]) | |
| 226 | print("Coordinates:")
| |
| 227 | write("X: ")
| |
| 228 | x = tonumber(read()) | |
| 229 | write("Y: ")
| |
| 230 | y = tonumber(read()) | |
| 231 | write("Z: ")
| |
| 232 | z = tonumber(read()) | |
| 233 | sleep(1) | |
| 234 | Print("Target Selection Complete:")
| |
| 235 | red() | |
| 236 | term.setBackgroundColor(colors.blue) | |
| 237 | print("Launching at: "..x..","..y..","..z)
| |
| 238 | print("Launching Missiles -T Minus 10 Seconds.")
| |
| 239 | sleep(1) | |
| 240 | red() | |
| 241 | ||
| 242 | sleep(1) | |
| 243 | write(" Abort [Yes/No]: ")
| |
| 244 | local abort = read() | |
| 245 | if abort == "Yes" then | |
| 246 | ||
| 247 | disarm(silos[curSilo]) | |
| 248 | ||
| 249 | ||
| 250 | write("Warheads Disarmed Successfully")
| |
| 251 | sleep(1) | |
| 252 | write("Session Expired, renewing login:")
| |
| 253 | sleep(2) | |
| 254 | os.reboot() | |
| 255 | elseif abort == "No" then | |
| 256 | end | |
| 257 | launch(count, x, y, z) | |
| 258 | sleep(10) | |
| 259 | os.reboot() | |
| 260 | end | |
| 261 | elseif loggedin == false then | |
| 262 | term.setTextColor(colors.red) | |
| 263 | term.setBackgroundColor(colors.lightGray) | |
| 264 | str = "Username or Password incorrect." | |
| 265 | term.setCursorPos((size[1]/2)-(#str/2) +1,12) | |
| 266 | term.write(str) | |
| 267 | sleep(2) | |
| 268 | reset() | |
| 269 | end | |
| 270 | end | |
| 271 | elseif username == nil or password == nil then | |
| 272 | reset() | |
| 273 | term.setTextColor(colors.red) | |
| 274 | term.setBackgroundColor(colors.lightGray) | |
| 275 | str = "Username or Password not recognized." | |
| 276 | term.setCursorPos((size[1]/2)-(#str/2) +1,12) | |
| 277 | term.write(str) | |
| 278 | sleep(2) | |
| 279 | reset() | |
| 280 | end | |
| 281 | end | |
| 282 | end | |
| 283 | end | |
| 284 | end | |
| 285 | end | |
| 286 | end | |
| 287 | ||
| 288 | loginScreen() | |
| 289 | term.setBackgroundColor(colors.black) | |
| 290 | term.clear() | |
| 291 | term.setCursorPos(1,1) |