Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent=os.pullEventRaw
- local debugMode=true
- local systems={[20]=true,[21]=true,}
- if fs.exists("db")==false then
- shell.run("pastebin get PdhBaBdZ db")
- end
- os.loadAPI("db")
- if fs.exists("databases/accounts")==false then
- db.createDataFile("accounts")
- end
- if fs.exists("databases/values")==false then
- db.createDataFile("values")
- end
- if fs.exists("databases/costs")==false then
- db.createDataFile("costs")
- end
- if fs.exists("databases/purchaseLogs")==false then
- db.createDataFile("purchaseLogs")
- end
- shell.run("delete databases/values")
- shell.run("pastebin get 5rzAAY2g databases/values")
- shell.run("delete databases/costs")
- shell.run("pastebin get SsrNAGBW databases/costs")
- rednet.open("bottom")
- function addCredit(account,count)
- local credit=getCredit(account)
- db.setData("accounts",account,credit+count)
- return true
- end
- function takeCredit(account,count)
- local credit=getCredit(account)
- if credit<count then
- return false
- else
- db.setData("accounts",account,credit-count)
- return true
- end
- end
- function getCredit(account)
- local credit=db.getData("accounts",account)
- if credit==false then
- credit=0
- end
- return credit
- end
- function getItemValue(itemID)
- local value=db.getData("values",itemID)
- if debugMode==true then print(value) end
- return value
- end
- function handleMessages()
- local id,message,protocol=rednet.receive()
- if debugMode==true then print(message) end
- if protocol=="NanoShop" and systems[id]==true then
- local returned=nil
- if string.find(message,"addCredit")~=nil then
- local accountName=splitString(message,",",2)
- local count=splitString(message,",",3)
- returned=addCredit(accountName,count)
- elseif string.find(message,"takeCredit")~=nil then
- local accountName=splitString(message,",",2)
- local count=splitString(message,",",3)
- returned=takeCredit(accountName,count)
- elseif string.find(message,"getCredit")~=nil then
- local accountName=splitString(message,",",2)
- local count=splitString(message,",",3)
- returned=getCredit(accountName)
- elseif string.find(message,"getValue")~=nil then
- local itemID=splitString(message,",",2)
- returned=getItemValue(itemID)
- end
- rednet.send(id,tostring(returned))
- end
- end
- function splitString(sourceString,splittingChar,index)
- results={}
- currentWord=""
- for i=1,string.len(sourceString) do
- letter=string.sub(sourceString,i,i)
- if letter==splittingChar then
- results[#results+1]=currentWord
- currentWord=""
- else
- currentWord=currentWord..letter
- end
- end
- results[#results+1]=currentWord
- return results[index],results
- end
- function setup()
- term.clear()
- term.setCursorPos(1,1)
- term.write("This computer is not for consumer use.")
- while true do
- handleMessages()
- end
- end
- setup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement