Advertisement
Guest User

Untitled

a guest
Nov 10th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.30 KB | None | 0 0
  1. --Variablen--
  2. local fs = require("filesystem")
  3. local event = require("event")
  4. local component = require("component")
  5. local modem = component.modem
  6. local Tablet = "e0d2bad8-26dc-44b8-a307-592316ea050b" --Adresse des Tablets für das Konto--
  7. local Channel = 1 --Port des kontos(immer unterschiedliche Ports verwenden!)--
  8.  
  9. --Netzwerkkanal öffnen--
  10. modem.open(Channel)
  11.  
  12. --Schleife für Aktionen--
  13. while true do -- --
  14. -- --
  15. --Warten auf Nachricht mit Absenderadresse und Wert-- -- --
  16. local _, _, Adresse, _, _, Betr = event.pull("modem_message") -- --
  17. local Betrag = tostring(Betr) -- --
  18. -- --
  19. --Prüfen ob der Kontostand nur gelesen werden soll-- -- --
  20. if Betrag == "read" then -- __________ --
  21. fs.open("Konto.txt", "rb") -- \ --
  22. local Konto = "Konto.txt" -- ! --
  23. modem.send(Tablet, Channel, Konto.read()) -- ! --
  24. Konto.close() -- ! --
  25. -- ! --
  26. --Sonst mit der Überweisung beginnen-- -- ! --
  27. else -- ___________! --
  28. -- ! --
  29. --Prüfen ob Der Betrag Positiv ist-- -- ! --
  30. if Betrag > 0 then -- ________ ! --
  31. -- \ ! --
  32. --Wenn ja prüfen ob die Nachricht vom User stammt-- -- ! ! --
  33. if Adresse == Tablet then -- ______ ! ! --
  34. -- \ ! ! --
  35. --Wenn ja, Überweisung-- -- ! ! ! --
  36. fs.open("konto.txt", "r") -- ! ! ! --
  37. local Konto = "konto.txt" -- ! ! ! --
  38. local Kontostand = "tostring(Konto.read())" -- ! ! ! --
  39. -- ! ! ! --
  40. --Prüfen ob auf dem Konto genug Geld vorhanden ist-- -- ! ! ! --
  41. if Kontostand >= Betrag then -- ____ ! ! ! --
  42. -- \ ! ! ! --
  43. --Überweisung des Geldes-- -- ! ! ! ! --
  44. modem.send(Tablet, Channel, "Success") -- ! ! ! ! --
  45. local _, _, _, _, _, Empf, Port = event.pull("modem_message") -- ! ! ! ! --
  46. local Emp = tostring(Empf) -- ! ! ! ! --
  47. modem.send(Emp, Port, Betrag) -- ! ! ! ! --
  48. local _, _, _, _, _, _ = event.pull("modem_message") -- ! ! ! ! --
  49. Kontostand = Kontostand - Betrag -- ! ! ! ! --
  50. Konto.close() -- ! ! ! ! --
  51. fs.open("konto.txt", "w") -- ! ! ! ! --
  52. Konto.write(Kontostand) -- ! ! ! ! --
  53. modem.send(Tablet, Channel, "Success") -- ! ! ! ! --
  54. Konto.close() -- ! ! ! ! --
  55. --Sonst Fehler senden-- -- ! ! ! ! --
  56. else -- _____! ! ! ! --
  57. modem.send(Tablet, Channel, "Error2: Not enough money on account") -- ! ! ! ! --
  58. end -- ____/ ! ! ! --
  59. -- ! ! ! --
  60. --Sonst Addition des Geldes-- -- ! ! ! --
  61. else -- _______! ! ! --
  62. fs.open("konto.txt", "r") -- ! ! ! --
  63. local Konto = "konto.txt" -- ! ! ! --
  64. local kontostand = "tostring(Konto.read())" -- ! ! ! --
  65. Kontostand = Kontostand + Betrag -- ! ! ! --
  66. Konto.close() -- ! ! ! --
  67. fs.open("konto.txt", "w") -- ! ! ! --
  68. Konto.write(Kontostand) -- ! ! ! --
  69. modem.send(Adresse, Channel, "Success") -- ! ! ! --
  70. Konto.close() -- ! ! ! --
  71. end -- ______/ ! ! --
  72. --Wenn nicht Positiv Fehler Senden -- ! ! --
  73. else -- _________! ! --
  74. modem.send(Tablet, Channel, "Error1: Cannot transfer negative values or nil") -- ! ! --
  75. end -- ________/ ! --
  76. end -- __________/ --
  77. end -- --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement