Advertisement
Marlingaming

Global Banking System - Server Script

Sep 14th, 2021 (edited)
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. --Global Banking Main Server
  2. --this program manages the Transactions and Information of all Accounts on the server
  3. --this is for CC Tweaked 1.16.5 for minecraft
  4.  
  5.  
  6. local Misc = nil
  7. local BankingProtocol = 8452
  8. local AccountBalance = nil
  9. local ContactedID = nil
  10. local SelectedAccount = nil
  11. local AccountKey = nil
  12. local CryptionCharacter_Base = ["space","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","\n","_"]
  13. local CryptionCharacter_Locked = ["00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35"]
  14. local EncryptedData = nil
  15.  
  16. start()
  17.  
  18. function start()
  19. Standby()
  20. end
  21.  
  22. function Standby()
  23. ContactedID = nil
  24. AccountBalance = nil
  25. AccountKey = nil
  26. SelectedAccount = nil
  27. EncryptedData = nil
  28. rednet.open()
  29. rednet.host(8452,"BankingServer")
  30. local DATA = nil
  31. repeat
  32. local id, message, protocol = rednet.receive()
  33. until protocol == BankingProtocol
  34. ContactedID = id
  35. if message == "NewAccount" then
  36. repeat
  37. local id, message, protocol = rednet.receive()
  38. until id == ContactedID and protocol == BankingProtocol
  39. SelectedAccount = message
  40. if fs.exists("Account_"..SelectedAccount) == true then
  41. rednet.send(ContactedID,"Denied",8452)
  42. Standby()
  43. else
  44. local BankName = "n"
  45. AccountKey = rng(2,9)
  46. local file = fs.open("Account_"..SelectedAccount,"w")
  47. file.writeLine(SelectedAccount)
  48. file.writeLine(AccountKey)
  49. file.writeLine(BankName)
  50. file.writeLine(os.date(IRL))
  51. file.writeLine(ContactedID)
  52. file.writeLine(0)
  53. file.close()
  54. rednet.send(AccountKey)
  55. rednet.send(BankName)
  56. Standby()
  57. end
  58. else
  59. DATA = message
  60. repeat
  61. local id, message, protocol = rednet.receive()
  62. until id == ContactedID and protocol == BankingProtocol
  63. SelectedAccount = message
  64. FindAccount(account)
  65. Encryption_TypeB(DATA,"Decrypt")
  66. FindAccount(SelectedAccount)
  67. local Method == EncryptedData
  68. if Method.substring("r_",1,2) == true then
  69. Encryption_TypeB(AccountBalance,"Encrypt")
  70. rednet.send(ContactedID,EncryptedData,8452)
  71. elseif Method.substring("t_",1,2) == true then
  72. repeat
  73. local id, message, protocol = rednet.receive()
  74. until id == ContactedID and protocol == BankingProtocol
  75. local TargetAccount = message
  76. FindAccount(TargetAccount,"n")
  77. if Misc == false then
  78. rednet.send(ContactedID,"Account Not Found",8452)
  79. Standby()
  80. else
  81. rednet.send(ContactedID,"Account Found",8452)
  82. repeat
  83. local id, message, protocol = rednet.receive()
  84. until id == ContactedID and protocol == BankingProtocol
  85. if AccountBalance - message > -1 then
  86. rednet.send(ContactedID,"Accepted",BankingProtocol)
  87. EditBalance(SelectedAccount,message*-1)
  88. EditBalance(TargetAccount,message)
  89. else
  90. rednet.send(ContactedID,"Denied",BankingProtocol)
  91. Standby()
  92. end
  93. end
  94. end
  95. end
  96. end
  97.  
  98. function EditBalance(Account,Action)
  99. local file = fs.open("Account_"..Account,"a")
  100. file.setCursorPos(1,6)
  101. local balance = file.readLine(6)
  102. file.clearLine(6)
  103. file.writeLine(balance+Action)
  104. file.close()
  105. end
  106.  
  107. function FindAccount(account,save)
  108. if save == "n" then
  109. if fs.exists("Account_"..account) == true then
  110. Misc = true
  111. else
  112. Misc = false
  113. end
  114. else
  115. local File = fs.open("Account_"..account,"r")
  116. AccountKey = File.readLine(2)
  117. AccountBalance = File.readLine(6)
  118. File.close()
  119. end
  120. end
  121.  
  122. function Encryption_TypeB(data,mode)
  123. data = string.lowerCase(data)
  124. local Result = ""
  125. if mode == "Encrypt" then
  126. Result = "B_"
  127. for i = 1, #data.bytes do
  128. local n = 1
  129. for n = 1, #CryptionCharacter_Base do
  130. if substring(data,i,i) == CryptionCharacter_Base[n] then
  131. Result = Result..CryptionCharacter_Locked[n+AccountKey]
  132. end
  133. end
  134. end
  135. EncryptedData = Result
  136. elseif mode == "Decrypt" then
  137. Result = ""
  138. for i = 1, #data.bytes do
  139. local n = 1
  140. for n = 1, #CryptionCharacter_Base do
  141. if substring(data,i,i) == CryptionCharacter_Locked[n] then
  142. if CryptionCharacter_Base[n-AccountKey] == "space" then
  143. Result = Result.." "
  144. else
  145. Result = Result..CryptionCharacter_Base[n-AccountKey]
  146. end
  147. end
  148. end
  149. end
  150. EncryptedData = Result
  151. end
  152. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement