Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --KSC Computing.
- local Account = {ID=0,name="",balance=0}
- local Accounts = {}
- local function wait(x)
- local start = os.time()
- while os.time()>start+x do end
- end
- if fs.exists("karma/") == false then
- fs.makeDir("karma/")
- end
- local function CStrip(str,chrs)
- local data = str
- for i,chr in ipairs(chrs) do
- data = string.gsub(data,'%'..chr,'')
- end
- return(data)
- end
- local function Save()
- alen = table.getn(Accounts)
- savefile = fs.open("karma/accounts","w")
- savefile.writeLine(alen)
- for i=1,alen do
- local savedata = textutils.serialise(Accounts[i])
- savedata = CStrip(savedata,{'{','}',' ','\n'})
- savedata = string.sub(1,-2)
- savefile.writeLine(savedata)
- end
- savefile.close()
- --rfile = fs.open("karma/accounts","r")
- --for i,line in ipairs(rfile) do print(rfile.readLine()) end
- --rfile.close()
- end
- Interest = {SID=0,RID=0,Date = 0,Amount = 0,Rate = 0}
- Interests = {}
- local function FindID(id)
- for i,account in ipairs(Accounts) do
- if account.ID == id then
- return(i)
- end
- end
- end
- local function AccountOpen(name,id,balance)
- local newaccount = {}
- setmetatable(newaccount,{__index=Account})
- newaccount.ID=id
- newaccount.name = name
- if balance == nil then
- newaccount.balance = 0
- else
- newaccount.balance = balance
- end
- return(newaccount)
- end
- if fs.exists("karma/accounts") == true then
- accountfile = fs.open("karma/accounts","r")
- local alen = accountfile.readLine()
- for i=1,tonumber(alen) do
- data = {}
- for value in string.gmatch(line,"([^,]+)") do
- table.insert(data,value)
- end
- table.insert(Accounts,AccountOpen(data[2],data[1],data[3]))
- print(data,line)
- sleep(1)
- end
- accountfile.close()
- end
- local function AccountDeposit(ID,amount)
- Accounts[FindID(ID)].balance= Accounts[FindID(ID)].balance+amount
- end
- local function AccountWithdraw(ID,amount)
- Accounts[FindID(ID)].balance=Accounts[FindID(ID)].balance-amount
- end
- local function InterestOpen(SID,RID,Amount,Rate)
- local opened = {}
- setmetatable(opened,{__index=Interest})
- opened.SID = SID
- opened.RID = RID
- opened.Date = os.day()
- opened.Amount = Amount
- opened.Rate = Rate
- return(opened)
- end
- running = true
- local modem = peripheral.wrap("top")
- modem.open(248)
- local function spam(channel,message,x)
- for i=1,tonumber(x) do modem.transmit(channel,248,tostring(message)) end
- print(channel,message)
- end
- local console = ""
- while running == true do --INTERACTOR
- local event,p1,p2,p3,p4,p5 = os.pullEvent()
- term.clear()
- term.setCursorPos(1,1)
- term.write("KSC MAINSERVER")
- term.setCursorPos(1,3)
- term.write("STATUS:ACTIVE")
- term.setCursorPos(1,4)
- --print(event,p1,p2,p3,p4,p5)
- term.setCursorPos(2,6)
- if console == "" then
- term.write("<>")
- else
- term.write(">"..console.."<")
- end
- term.setCursorPos(1,7)
- term.write(CStrip(textutils.serialise(Accounts),{'{','}',' '}))
- if event == "modem_message" then
- message = {}
- for word in string.gmatch(p4,"([^%s]+)") do
- table.insert(message,word)
- end
- if message[1] == "K912" then --K912 is temp
- if message[2] == "lsa" then
- term.write("LISA")
- elseif message[2] == "new" then
- table.insert(Accounts,AccountOpen(message[3],p3))
- spam(p3,"Account Opened",10)
- Save()
- elseif message[2] == "TRQ" then
- spam(p3,"TRS",10)
- spam(tonumber(message[4]),"TRQ "..message[3].." "..message[5].." "..message[6],1)
- elseif message[2] == "VwA" then
- for i,account in ipairs(Accounts) do
- if p3 == account[1] then
- spam(p3,"VwA "..tostring(Accounts[tonumber(message[3])].balance),5)
- break
- end
- end
- elseif message[2] == "NTQ" then
- spam(message[3],"NTQ",1)
- elseif message[2] == "FTQ" then
- AccountWithdraw(message[3],message[4])
- AccountDeposit(p3,message[4])
- AccountWithdraw(p3,message[5])
- AccountDeposit(message[3],message[5])
- end
- end
- elseif event == "key" then
- if p1 == 14 then
- if string.len(console) >0 then
- console = string.sub(console,1,-2)
- end
- elseif p1 == 207 then
- running = false
- elseif p1 == 28 then
- cmessage = {}
- for word in string.gmatch(console,"([^%s]+)") do table.insert(cmessage,word) end
- if string.lower(cmessage[1]) == "sv" then
- Save()
- elseif string.lower(cmessage[1]) == "up" then
- spam(1119,cmessage[2],3)
- elseif string.lower(cmessage[1]) == "konami" then
- spam(cmessage[2],"Konami 00100100",4)
- elseif string.lower(cmessage[1]) == "nw" then
- table.insert(Accounts,AccountOpen(cmessage[2],tonumber(cmessage[3])))
- Save()
- end
- console = ""
- end
- elseif event == "char" then
- console = console..p1
- end
- end
- term.setCursorPos(8,3)
- term.write("INACTIVE")
- term.setCursorPos(1,8)
- --COMMANDS:
- -- wdl ID Amount
- -- dip ID Amount
- -- new Name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement