Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Variablen--
- local fs = require("filesystem")
- local event = require("event")
- local component = require("component")
- local modem = component.modem
- local Tablet = "e0d2bad8-26dc-44b8-a307-592316ea050b" --Adresse des Tablets für das Konto--
- local Channel = 1 --Port des kontos(immer unterschiedliche Ports verwenden!)--
- --Netzwerkkanal öffnen--
- modem.open(Channel)
- --Schleife für Aktionen--
- while true do -- --
- -- --
- --Warten auf Nachricht mit Absenderadresse und Wert-- -- --
- local _, _, Adresse, _, _, Betr = event.pull("modem_message") -- --
- local Betrag = tostring(Betr) -- --
- -- --
- --Prüfen ob der Kontostand nur gelesen werden soll-- -- --
- if Betrag == "read" then -- __________ --
- fs.open("Konto.txt", "rb") -- \ --
- local Konto = "Konto.txt" -- ! --
- modem.send(Tablet, Channel, Konto.read()) -- ! --
- Konto.close() -- ! --
- -- ! --
- --Sonst mit der Überweisung beginnen-- -- ! --
- else -- ___________! --
- -- ! --
- --Prüfen ob Der Betrag Positiv ist-- -- ! --
- if Betrag > 0 then -- ________ ! --
- -- \ ! --
- --Wenn ja prüfen ob die Nachricht vom User stammt-- -- ! ! --
- if Adresse == Tablet then -- ______ ! ! --
- -- \ ! ! --
- --Wenn ja, Überweisung-- -- ! ! ! --
- fs.open("konto.txt", "r") -- ! ! ! --
- local Konto = "konto.txt" -- ! ! ! --
- local Kontostand = "tostring(Konto.read())" -- ! ! ! --
- -- ! ! ! --
- --Prüfen ob auf dem Konto genug Geld vorhanden ist-- -- ! ! ! --
- if Kontostand >= Betrag then -- ____ ! ! ! --
- -- \ ! ! ! --
- --Überweisung des Geldes-- -- ! ! ! ! --
- modem.send(Tablet, Channel, "Success") -- ! ! ! ! --
- local _, _, _, _, _, Empf, Port = event.pull("modem_message") -- ! ! ! ! --
- local Emp = tostring(Empf) -- ! ! ! ! --
- modem.send(Emp, Port, Betrag) -- ! ! ! ! --
- local _, _, _, _, _, _ = event.pull("modem_message") -- ! ! ! ! --
- Kontostand = Kontostand - Betrag -- ! ! ! ! --
- Konto.close() -- ! ! ! ! --
- fs.open("konto.txt", "w") -- ! ! ! ! --
- Konto.write(Kontostand) -- ! ! ! ! --
- modem.send(Tablet, Channel, "Success") -- ! ! ! ! --
- Konto.close() -- ! ! ! ! --
- --Sonst Fehler senden-- -- ! ! ! ! --
- else -- _____! ! ! ! --
- modem.send(Tablet, Channel, "Error2: Not enough money on account") -- ! ! ! ! --
- end -- ____/ ! ! ! --
- -- ! ! ! --
- --Sonst Addition des Geldes-- -- ! ! ! --
- else -- _______! ! ! --
- fs.open("konto.txt", "r") -- ! ! ! --
- local Konto = "konto.txt" -- ! ! ! --
- local kontostand = "tostring(Konto.read())" -- ! ! ! --
- Kontostand = Kontostand + Betrag -- ! ! ! --
- Konto.close() -- ! ! ! --
- fs.open("konto.txt", "w") -- ! ! ! --
- Konto.write(Kontostand) -- ! ! ! --
- modem.send(Adresse, Channel, "Success") -- ! ! ! --
- Konto.close() -- ! ! ! --
- end -- ______/ ! ! --
- --Wenn nicht Positiv Fehler Senden -- ! ! --
- else -- _________! ! --
- modem.send(Tablet, Channel, "Error1: Cannot transfer negative values or nil") -- ! ! --
- end -- ________/ ! --
- end -- __________/ --
- end -- --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement