Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Global Banking Main Server
- --this program manages the Transactions and Information of all Accounts on the server
- --this is for CC Tweaked 1.16.5 for minecraft
- local Misc = nil
- local BankingProtocol = 8452
- local AccountBalance = nil
- local ContactedID = nil
- local SelectedAccount = nil
- local AccountKey = nil
- 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","_"]
- 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"]
- local EncryptedData = nil
- start()
- function start()
- Standby()
- end
- function Standby()
- ContactedID = nil
- AccountBalance = nil
- AccountKey = nil
- SelectedAccount = nil
- EncryptedData = nil
- rednet.open()
- rednet.host(8452,"BankingServer")
- local DATA = nil
- repeat
- local id, message, protocol = rednet.receive()
- until protocol == BankingProtocol
- ContactedID = id
- if message == "NewAccount" then
- repeat
- local id, message, protocol = rednet.receive()
- until id == ContactedID and protocol == BankingProtocol
- SelectedAccount = message
- if fs.exists("Account_"..SelectedAccount) == true then
- rednet.send(ContactedID,"Denied",8452)
- Standby()
- else
- local BankName = "n"
- AccountKey = rng(2,9)
- local file = fs.open("Account_"..SelectedAccount,"w")
- file.writeLine(SelectedAccount)
- file.writeLine(AccountKey)
- file.writeLine(BankName)
- file.writeLine(os.date(IRL))
- file.writeLine(ContactedID)
- file.writeLine(0)
- file.close()
- rednet.send(AccountKey)
- rednet.send(BankName)
- Standby()
- end
- else
- DATA = message
- repeat
- local id, message, protocol = rednet.receive()
- until id == ContactedID and protocol == BankingProtocol
- SelectedAccount = message
- FindAccount(account)
- Encryption_TypeB(DATA,"Decrypt")
- FindAccount(SelectedAccount)
- local Method == EncryptedData
- if Method.substring("r_",1,2) == true then
- Encryption_TypeB(AccountBalance,"Encrypt")
- rednet.send(ContactedID,EncryptedData,8452)
- elseif Method.substring("t_",1,2) == true then
- repeat
- local id, message, protocol = rednet.receive()
- until id == ContactedID and protocol == BankingProtocol
- local TargetAccount = message
- FindAccount(TargetAccount,"n")
- if Misc == false then
- rednet.send(ContactedID,"Account Not Found",8452)
- Standby()
- else
- rednet.send(ContactedID,"Account Found",8452)
- repeat
- local id, message, protocol = rednet.receive()
- until id == ContactedID and protocol == BankingProtocol
- if AccountBalance - message > -1 then
- rednet.send(ContactedID,"Accepted",BankingProtocol)
- EditBalance(SelectedAccount,message*-1)
- EditBalance(TargetAccount,message)
- else
- rednet.send(ContactedID,"Denied",BankingProtocol)
- Standby()
- end
- end
- end
- end
- end
- function EditBalance(Account,Action)
- local file = fs.open("Account_"..Account,"a")
- file.setCursorPos(1,6)
- local balance = file.readLine(6)
- file.clearLine(6)
- file.writeLine(balance+Action)
- file.close()
- end
- function FindAccount(account,save)
- if save == "n" then
- if fs.exists("Account_"..account) == true then
- Misc = true
- else
- Misc = false
- end
- else
- local File = fs.open("Account_"..account,"r")
- AccountKey = File.readLine(2)
- AccountBalance = File.readLine(6)
- File.close()
- end
- end
- function Encryption_TypeB(data,mode)
- data = string.lowerCase(data)
- local Result = ""
- if mode == "Encrypt" then
- Result = "B_"
- for i = 1, #data.bytes do
- local n = 1
- for n = 1, #CryptionCharacter_Base do
- if substring(data,i,i) == CryptionCharacter_Base[n] then
- Result = Result..CryptionCharacter_Locked[n+AccountKey]
- end
- end
- end
- EncryptedData = Result
- elseif mode == "Decrypt" then
- Result = ""
- for i = 1, #data.bytes do
- local n = 1
- for n = 1, #CryptionCharacter_Base do
- if substring(data,i,i) == CryptionCharacter_Locked[n] then
- if CryptionCharacter_Base[n-AccountKey] == "space" then
- Result = Result.." "
- else
- Result = Result..CryptionCharacter_Base[n-AccountKey]
- end
- end
- end
- end
- EncryptedData = Result
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement