View difference between Paste ID: e2EbikLx and XF6UmWjW
SHOW: | | - or go back to the newest paste.
1
-- CONFIGURAZIONE
2-
sideIsPaymentGood = "right"
2+
beneficiario = "eternalcaos"
3-
sideToStopPaymentGood = "back"
3+
4-
beneficiario = "eternal"
4+
5
-- Implementazione di dio volevo dire del sensore
6
os.loadAPI("ocs/apis/sensor")
7
 
8
se = sensor.wrap("top")
9
 
10
-- Configurazione di base del sensore
11
side = "left" -- Lato del segnale se viene rilevato un giocatopre
12
 
13
14
15
local maxw, maxh = term.getSize()
16
 
17
--IMPLEMENTAZIONE DEL DRAWFILLEDBOX
18
local function drawPixelInternal(xPos, yPos)
19
    term.setCursorPos(xPos, yPos)
20
    term.write(" ")
21
end
22
 
23
local tColourLookup = {}
24
for n = 1,16 do
25
    tColourLookup[string.byte("0123456789abcdef", n, n)] = 2^(n-1)
26
end
27
 
28
function drawFilledBox(startX, startY, endX, endY, nColour)
29
    if type(startX) ~= "number" or type(startX) ~= "number" or
30
       type(endX) ~= "number" or type(endY) ~= "number" or
31
       (nColour ~= nil and type(nColour) ~= "number") then
32
        error("Expected startX, startY, endX, endY, colour", 2)
33
    end
34
 
35
    startX = math.floor(startX)
36
    startY = math.floor(startY)
37
    endX = math.floor(endX)
38
    endY = math.floor(endY)
39
 
40
    if nColour then
41
        term.setBackgroundColor(nColour)
42
    end
43
    if startX == endX and startY == endY then
44
        drawPixelInternal(startX, startY)
45
        return
46
    end
47
 
48
    local minX = math.min(startX, endX)
49
    if minX == startX then
50
        minY = startY
51
        maxX = endX
52
        maxY = endY
53
    else
54
        minY = endY
55
        maxX = startX
56
        maxY = startY
57
    end
58
 
59
    for x = minX, maxX do
60
        for y = minY, maxY do
61
            drawPixelInternal(x, y)
62
        end
63
    end
64
end
65
66
function button(x, y, color, text)
67
    term.setBackgroundColor(colors[color])
68
    term.setTextColor(colors.white)
69
    term.setCursorPos(x, y)
70
    print(text)
71
    term.setBackgroundColor(colors.white)
72
    term.setTextColor(colors.black)
73
end
74
 
75
function clear()
76
    term.setBackgroundColor(colors.white)
77
    term.setTextColor(colors.black)
78
    term.clear()
79
    term.setCursorPos(1, 1)
80
end
81
 
82
function titolo(testo)
83
    drawFilledBox(1, 1, maxw, 1, colors.blue)
84-
isGood = false
84+
85
    term.setTextColor(colors.white)
86
    term.write(testo)
87
    term.setBackgroundColor(colors.white)
88
    term.setTextColor(colors.black)
89
end
90-
-- Facciamo prima il check
90+
91-
 if rs.getInput(sideToStopPaymentGood) == false and isGood == true then
91+
isGoodPayment = false
92-
   rs.setOutput(sideIsPaymentGood, true)
92+
93-
 elseif rs.getInput(sideToStopPaymentGood) == true then
93+
94-
   isGood = false
94+
rs.setOutput(side, true)
95-
   rs.setOutput(sideIsPaymentGood, false)
95+
96
page = 0
97
98
while true do
99
 if page == 0 and isLogged == false then
100
  clear()
101
  titolo("Pagamento con nPay - Accedi!")
102
  print("\n\n\nNome Utente:")
103
  utente = read()
104
  checkuser = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" .. utente).readAll()
105
  print("\nPassword:")
106
  password = read("#")
107
  checkpass = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" .. password .. "&richiesta=addebito&valore=0&utente=".. utente).readAll()
108
  risposta = textutils.unserialize(checkpass)
109
  tabcheckuser = textutils.unserialize(checkuser)
110
  if tabcheckuser.stato == "OK" and risposta.stato == "OK" then
111
   isLogged = true
112
   page = "logged"
113
  else
114
   isLogged = false
115
   term.setTextColor(colors.red)
116
   print("\n\nNome Utente o Password errati!\n\nPotrai riprovare tra 2 secondi....")
117
   sleep(1.5)
118
   os.reboot()
119
  end
120
 elseif page == "logged" and isLogged == true then
121
  clear()
122
  titolo("Pagamento con nPay - Benvenuto, " ..utente.."!")
123
  print("\n\nStai per pagare "..importo.."IC a favore di " ..beneficiario.."!")
124
  button(15, 10, "green", " PAGA ORA ")
125
  button(30, 10, "red", " ANNULLA ")
126
  
127
  local event, bt, x, y = os.pullEvent("mouse_click")
128
  if x > 15 and x < 25 then
129
     inviaDenaro = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" .. password .. "&utente=" .. utente .. "&richiesta=trasferimento&valore=" .. importo .. "&beneficiario=" .. beneficiario).readAll()
130-
       clear()
130+
131-
       titolo("Pagamento con nPay - Pagamento Effettuato")
131+
132-
       term.setTextColor(colors.lime)
132+
        -- la variabile che gestisce l'implementazione del sensore viene messa positiva
133-
       print("\n\nPAGAMENTO EFFETTUATO CON SUCCESSO!\n\nVerrai sloggato automaticamente tra qualche secondo...")
133+
        isGoodPayment = true
134-
       isGood = true
134+
        page = "sensor"
135-
       sleep(5)
135+
136-
       -- Slogghiamo
136+
        clear()
137-
       page = 0
137+
        term.setTextColor(colors.red)
138-
       utente = nil
138+
        print("\n\nUn errore selvatico e' appena apparso ed il pagamento non e' avvenuto con successo...\nn\Potrai riprovare tra qualche secondo...")
139-
       password = nil
139+
        sleep(3)
140
        -- Slogghiamo ma in modo bello
141-
      clear()
141+
        os.reboot()
142-
      term.setTextColor(colors.red)
142+
      end
143-
      print("\n\nUn errore selvatico e' appena apparso ed il pagamento non e' avvenuto con successo...\nn\Potrai riprovare tra qualche secondo...")
143+
144-
      sleep(3)
144+
145-
      -- Slogghiamo ma in modo bello
145+
146
      os.reboot()
147-
     end
147+
148
 elseif page == "sensor" and isGoodPayment == true then
149
   clear()
150
   titolo("Pagamento con nPay - Goditelo :D")
151
   print("\n\nIl pagamento è avvenuto con successo!\Fino a che rimarrai vicino a questo computer potrai usufruire del servizio\nPer sloggarti, allontatati dal computer!")
152
   -- Implementazione del sensore rileva-player
153
   -- Il check viene eseguito ogni secondo
154-
sleep(0.11)
154+
   os.loadAPI("ocs/apis/sensor")
155
   se = sensor.wrap("top")
156
   ta = se.getTargets()
157
   for k,v in pairs(ta) do
158
    if k ~= nil then
159
      rs.setOutput(side, false)
160
    else
161
      rs.setOutput(side, true)
162
    end
163
   end
164
 end
165
sleep(0.2)
166
end
167
  
168