SHOW:
|
|
- or go back to the newest paste.
| 1 | --VARIABILI DA POPOLARE | |
| 2 | ||
| 3 | - | apiVersion = "NaN" |
| 3 | + | apiVersion = "1.0" |
| 4 | progVersion = "v1.0" | |
| 5 | - | defconLvl = "DEFCON 5" |
| 5 | + | defconLvl = "Defcon 5" |
| 6 | - | isEndorOn = true |
| 6 | + | isEndorOn = false |
| 7 | - | message = "Questo è un messaggio generico" |
| 7 | + | lockTrain = false |
| 8 | sleep = 60 | |
| 9 | ||
| 10 | - | apiVersion = "NaN" |
| 10 | + | shell.run("pastebin get ADaQ4War json")
|
| 11 | - | progVersion = "v1.0" |
| 11 | + | os.loadAPI("json")
|
| 12 | - | defconLvl = "DEFCON 5" |
| 12 | + | |
| 13 | - | isEndorOn = false |
| 13 | + | |
| 14 | - | message = "Questo è un messaggio generico" |
| 14 | + | rest = http.get("http://rgbvm.fabrimat.me/~fabrimat/tds.php")
|
| 15 | s = rest.readAll() | |
| 16 | t = json.decode(s) | |
| 17 | ||
| 18 | defconLvl = t.defcon | |
| 19 | isEndorOn = t.endor | |
| 20 | lockTrain = t.lock_train | |
| 21 | sleep = t.next_sleep | |
| 22 | end | |
| 23 | ||
| 24 | maxw, maxh = term.getSize() | |
| 25 | halfw = math.floor(maxw/2) | |
| 26 | halfh = math.floor(maxh/2) | |
| 27 | ||
| 28 | -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX | |
| 29 | local function drawPixelInternal(xPos, yPos) | |
| 30 | term.setCursorPos(xPos, yPos) | |
| 31 | term.write(" ")
| |
| 32 | end | |
| 33 | ||
| 34 | local tColourLookup = {}
| |
| 35 | for n = 1, 16 do | |
| 36 | tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
| |
| 37 | end | |
| 38 | ||
| 39 | function drawFilledBox(startX, startY, endX, endY, nColour) | |
| 40 | if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~= | |
| 41 | "number" or type(endY) ~= "number" or | |
| 42 | (nColour ~= nil and type(nColour) ~= "number") then | |
| 43 | error("Expected startX, startY, endX, endY, colour", 2)
| |
| 44 | end | |
| 45 | ||
| 46 | startX = math.floor(startX) | |
| 47 | startY = math.floor(startY) | |
| 48 | endX = math.floor(endX) | |
| 49 | endY = math.floor(endY) | |
| 50 | ||
| 51 | if nColour then term.setBackgroundColor(nColour) end | |
| 52 | if startX == endX and startY == endY then | |
| 53 | drawPixelInternal(startX, startY) | |
| 54 | return | |
| 55 | end | |
| 56 | ||
| 57 | local minX = math.min(startX, endX) | |
| 58 | if minX == startX then | |
| 59 | minY = startY | |
| 60 | maxw = endX | |
| 61 | maxh = endY | |
| 62 | else | |
| 63 | minY = endY | |
| 64 | maxw = startX | |
| 65 | maxh = startY | |
| 66 | end | |
| 67 | ||
| 68 | for x = minX, maxw do for y = minY, maxh do drawPixelInternal(x, y) end end | |
| 69 | end | |
| 70 | ||
| 71 | function colore(sfumatura) term.setTextColour(sfumatura) end | |
| 72 | ||
| 73 | function sfondo(sfumaturaSfondo) term.setBackgroundColour(sfumaturaSfondo) end | |
| 74 | ||
| 75 | function fineColore() term.setTextColour(colours.white) end | |
| 76 | ||
| 77 | function fineSfondo() term.setBackgroundColour(colours.black) end | |
| 78 | ||
| 79 | function titolo(testo) | |
| 80 | maxw, maxh = term.getSize() | |
| 81 | drawFilledBox(1, 1, maxw, 1, colors.yellow) | |
| 82 | term.setCursorPos((maxw - #testo) / 2, 1) | |
| 83 | colore(colors.black) | |
| 84 | term.write(testo) | |
| 85 | end | |
| 86 | ||
| 87 | function clear() | |
| 88 | term.clear() | |
| 89 | term.setCursorPos(1,1) | |
| 90 | end | |
| 91 | ||
| 92 | function printCentered(text) | |
| 93 | local curx, cury = term.getCursorPos() | |
| 94 | local maxw, maxh = term.getSize() | |
| 95 | term.setCursorPos((maxw - #text) / 2, cury) | |
| 96 | - | drawFilledBox(halfw - 9, halfh, halfw + 9, halfh + 2, colors.lime) |
| 96 | + | |
| 97 | - | term.setCursorPos(1, halfh+1) |
| 97 | + | |
| 98 | - | printCentered("Richiesta accesso")
|
| 98 | + | |
| 99 | ||
| 100 | ||
| 101 | function drawMain() | |
| 102 | titolo("Tyrian Defense System")
| |
| 103 | if(lockTrain) then | |
| 104 | drawFilledBox(halfw - 9, halfh, halfw + 9, halfh + 2, colors.lime) | |
| 105 | - | defconLvls["DEFCON 1"] = colors.red |
| 105 | + | term.setCursorPos(1, halfh+1) |
| 106 | - | defconLvls["DEFCON 2"] = colors.yellow |
| 106 | + | printCentered("Richiesta accesso")
|
| 107 | - | defconLvls["DEFCON 3"] = colors.lime |
| 107 | + | |
| 108 | - | defconLvls["DEFCON 4"] = colors.cyan |
| 108 | + | |
| 109 | - | defconLvls["DEFCON 5"] = colors.purple |
| 109 | + | |
| 110 | ||
| 111 | term.setCursorPos(1, halfh/2) | |
| 112 | ||
| 113 | local defconLvls = {}
| |
| 114 | defconLvls["Defcon 1"] = colors.red | |
| 115 | defconLvls["Defcon 2"] = colors.yellow | |
| 116 | defconLvls["Defcon 3"] = colors.lime | |
| 117 | defconLvls["Defcon 4"] = colors.cyan | |
| 118 | defconLvls["Defcon 5"] = colors.purple | |
| 119 | colore(defconLvls[defconLvl]) | |
| 120 | printCentered(defconLvl) | |
| 121 | ||
| 122 | term.setCursorPos(1, halfh/2 + 2) | |
| 123 | colore(colors.white) | |
| 124 | if isEndorOn == false then | |
| 125 | printCentered("ENDOR non attivo")
| |
| 126 | else | |
| 127 | - | function drawMessage() |
| 127 | + | |
| 128 | end | |
| 129 | ||
| 130 | maxw, maxh = term.getSize() | |
| 131 | local versionString = "(C) Proclus & Albannach 2021 - " .. progVersion .. " - API " .. apiVersion .. " " | |
| 132 | term.setCursorPos(1, maxh) | |
| 133 | printCentered(versionString) | |
| 134 | end | |
| 135 | ||
| 136 | function drawMessage(message, background, text) | |
| 137 | clear() | |
| 138 | titolo("Tyrian Defense System")
| |
| 139 | term.setBackgroundColor(background) | |
| 140 | term.setTextColor(text) | |
| 141 | ||
| 142 | term.setCursorPos(1, halfh) | |
| 143 | ||
| 144 | - | function func_484192a() |
| 144 | + | |
| 145 | - | drawMessage() |
| 145 | + | |
| 146 | - | os.pullEvent() |
| 146 | + | |
| 147 | term.setBackgroundColor(colors.black) | |
| 148 | term.setTextColor(colors.white) | |
| 149 | local versionString = "(C) Proclus & Albannach 2021 - " .. progVersion .. " - API " .. apiVersion .. " " | |
| 150 | term.setCursorPos(1, maxh) | |
| 151 | printCentered(versionString) | |
| 152 | - | updateVars() |
| 152 | + | |
| 153 | ||
| 154 | - | event, button, x, y = os.pullEvent("mouse_click")
|
| 154 | + | |
| 155 | function requestAuthorization() | |
| 156 | - | if x >= (halfw - 9) and x <= (halfw + 9) and y <= (halfh + 2) and y >= (halfh) then |
| 156 | + | drawMessage("Richiesta accesso in corso", colors.black, colors.white)
|
| 157 | - | func_484192a() |
| 157 | + | os.sleep(0.5) |
| 158 | - | break |
| 158 | + | drawMessage("Richiesta accesso in corso.", colors.black, colors.white)
|
| 159 | os.sleep(0.5) | |
| 160 | drawMessage("Richiesta accesso in corso..", colors.black, colors.white)
| |
| 161 | os.sleep(0.5) | |
| 162 | drawMessage("Richiesta accesso in corso...", colors.black, colors.white)
| |
| 163 | os.sleep(0.5) | |
| 164 | if(isEndorOn) then | |
| 165 | denyAuth() | |
| 166 | else | |
| 167 | allowAuth() | |
| 168 | end | |
| 169 | end | |
| 170 | ||
| 171 | function denyAuth() | |
| 172 | drawMessage("Accesso negato", colors.black, colors.red)
| |
| 173 | os.sleep(10) | |
| 174 | end | |
| 175 | ||
| 176 | function allowAuth() | |
| 177 | drawMessage("Accesso consentito", colors.black, colors.lime)
| |
| 178 | rs.setOutput("back", false)
| |
| 179 | os.sleep(30) | |
| 180 | end | |
| 181 | ||
| 182 | clear() | |
| 183 | updateVars() | |
| 184 | ||
| 185 | while true do | |
| 186 | if(lockTrain) then | |
| 187 | rs.setOutput("top", true)
| |
| 188 | rs.setOutput("back", true)
| |
| 189 | else | |
| 190 | rs.setOutput("top", false)
| |
| 191 | rs.setOutput("back", false)
| |
| 192 | end | |
| 193 | ||
| 194 | os.startTimer(sleep) | |
| 195 | ||
| 196 | clear() | |
| 197 | drawMain() | |
| 198 | event, button, x, y = os.pullEvent() | |
| 199 | term.setCursorPos(1, 17) | |
| 200 | if(event == 'mouse_click' and lockTrain) then | |
| 201 | if x >= (halfw - 9) and x <= (halfw + 9) and y <= (halfh + 2) and y >= (halfh) then | |
| 202 | requestAuthorization() | |
| 203 | end | |
| 204 | elseif(event == 'timer') then | |
| 205 | updateVars() | |
| 206 | end | |
| 207 | end | |
| 208 | ||
| 209 |