Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shell.run("sha1")
- chat = peripheral.wrap("left")
- function split(str, pat)
- local t = {} -- NOTE: use {n = 0} in Lua-5.0
- local fpat = "(.-)" .. pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- modem=peripheral.wrap("bottom")
- modem.open(1)
- function makeWallet(hash,owner)
- if not fs.exists("/wallets/"..hash) then
- fs.makeDir("/wallets/"..hash)
- n = fs.open("/wallets/"..hash.."/owner","w")
- n.write(owner)
- n.close()
- fi=fs.open("/wallets/"..hash.."/inf/","w")
- fi.write("0")
- fi.close()
- return true
- else
- return false
- end
- end
- function readOwner(hash)
- n = fs.open("/wallets/"..hash.."/owner","r")
- owner = n.readAll()
- n.close()
- return owner
- end
- function checkWallet(hash)
- return fs.exists("/wallets/"..hash)
- end
- function delWallet(hash)
- fs.delete("/wallets/"..hash)
- end
- function nameToWH(name)
- return SHA1(name)
- end
- function setBal(hash,bal)
- if fs.exists("/wallets/"..hash.."/inf/") then
- fs.delete("/wallets/"..hash.."/inf/")
- end
- fi=fs.open("/wallets/"..hash.."/inf/","w")
- fi.write(tostring(bal))
- fi.close()
- end
- function getBal(hash)
- fi=fs.open("/wallets/"..hash.."/inf/","r")
- bal=tonumber(fi.readAll())
- fi.close()
- return bal
- end
- ownerName="justync7"
- term.clear()
- term.setCursorPos(1,1)
- print("CraftCoin Alpha 1.0 Master Server")
- if not fs.exists("/wallets/") then
- fs.makeDir("/wallets/")
- end
- ownerWallet=SHA1(ownerName)
- walletCount=0
- for i,v in pairs(fs.list("/wallets/")) do
- walletCount=walletCount+1
- end
- pi=3.14159265358979323846264338327950288419716939937510
- maxCoin=walletCount*1500000/(pi*2)
- print("Max CraftCoins is "..maxCoin)
- while true do
- event, player, message, reply, msg = os.pullEventRaw()
- if event == "chat" then
- messagep = split(message," ")
- if messagep[1] == ".echo" then
- chat.say(message:sub(7))
- elseif messagep[1] == ".cc" then
- if messagep[2] == "wallet" then
- if messagep[3] == "new" then
- t = makeWallet(nameToWH(player),player)
- if t == true then
- chat.tell(player,"Sucessfully created your new wallet!")
- else
- chat.tell(player,"Failed to create wallet, already exists or error, contact justync7.")
- end
- elseif messagep[3] == "check" then
- ts = checkWallet(messagep[4])
- if ts == true then
- chat.tell(player,"True: Wallet exists.")
- else
- chat.tell(player,"False: Wallet does not exist.")
- end
- elseif messagep[3] == "bal" then
- if messagep[4] == "user" then
- chat.tell(player,tostring(getBal(nameToWH(messagep[5]))))
- elseif messagep[4] == "wallet" then
- chat.tell(player,tostring(getBal(messagep[5])))
- end
- elseif messagep[3] == "pay" then
- if messagep[4] == "user" then
- rec=getBal(nameToWH(messagep[5]))
- sen=getBal(nameToWH(player))
- sen=sen-tonumber(messagep[6])
- rec=rec+tonumber(messagep[6])
- setBal(nameToWH(messagep[5]),rec)
- setBal(nameToWH(player),sen)
- elseif messagep[4] == "wallet" then
- rec=getBal(messagep[5])
- sen=getBal(nameToWH(player))
- sen=sen-tonumber(messagep[6])
- rec=rec+tonumber(messagep[6])
- setBal(messagep[5],rec)
- setBal(nameToWH(player),sen)
- end
- end
- elseif messagep[2] == "mine" then
- modem.transmit(1,1,"startmine "..nameToWH(player))
- chat.tell(player,"You are now mining for 1 CraftCoin!")
- elseif messagep[2] == "lua" then
- pcall(message:sub(9))
- end
- end
- elseif event == "modem_message" then
- messagep = split(msg," ")
- if messagep[1] == "mined" then
- if messagep[2] then
- bal = getBal(messagep[2])
- bal = bal + 1
- setBal(messagep[2],bal)
- chat.tell(readOwner(messagep[2]),"You mined a coin! +1 CraftCoin")
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement