Compare commits
5 Commits
94683e34bf
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8641697b4a | ||
|
|
7a5cca28b1 | ||
|
|
eaedfdf5b9 | ||
|
|
4aee1a174c | ||
|
|
b9db35ec9c |
@@ -24,6 +24,11 @@ local function interactWithCard(userUUID, mode, money)
|
||||
sleep(30)
|
||||
--shell.run("reboot")
|
||||
end
|
||||
if not message then
|
||||
print("WTF!? I got a rednet message with no data!?")
|
||||
print("Rebooting...")
|
||||
sleep(5)
|
||||
end
|
||||
if message.type == "account_data" and message.cardId == cardUUID then
|
||||
local money = message.balance
|
||||
local playerUUID = message.uuid
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
rednet.open("back")
|
||||
|
||||
local function interactWithCard(userUUID, mode, money)
|
||||
if mode == "updateBalance" then
|
||||
rednet.broadcast({
|
||||
uuid = userUUID,
|
||||
amount = money,
|
||||
type = "set"
|
||||
}, "machineBalanceModifier")
|
||||
if mode == "updateBalance" then
|
||||
rednet.broadcast({
|
||||
uuid = userUUID,
|
||||
amount = money,
|
||||
type = "set"
|
||||
}, "machineBalanceModifier")
|
||||
end
|
||||
|
||||
if mode == "getBalance" then
|
||||
@@ -25,6 +25,11 @@ local function interactWithCard(userUUID, mode, money)
|
||||
sleep(30)
|
||||
--shell.run("reboot")
|
||||
end
|
||||
if not message then
|
||||
print("WTF!? I got a rednet message with no data!?")
|
||||
print("Rebooting...")
|
||||
sleep(5)
|
||||
end
|
||||
if message.type == "account_data" and message.cardId == cardUUID then
|
||||
local money = message.balance
|
||||
local playerUUID = message.uuid
|
||||
@@ -37,6 +42,7 @@ local function interactWithCard(userUUID, mode, money)
|
||||
end
|
||||
|
||||
|
||||
|
||||
sleep(0.25)
|
||||
|
||||
nfc = peripheral.wrap("bottom")
|
||||
@@ -120,4 +126,4 @@ h.write(house)
|
||||
h.close()
|
||||
--print("If removing your card do it now")
|
||||
sleep(2)
|
||||
os.reboot()
|
||||
os.reboot()
|
||||
|
||||
@@ -1,40 +1,47 @@
|
||||
--slot2
|
||||
rednet.open("back")
|
||||
|
||||
|
||||
local function interactWithCard(userUUID, mode, money)
|
||||
if mode == "updateBalance" then
|
||||
rednet.broadcast({
|
||||
uuid = userUUID,
|
||||
amount = money,
|
||||
type = "set"
|
||||
}, "machineBalanceModifier")
|
||||
end
|
||||
if mode == "updateBalance" then
|
||||
rednet.broadcast({
|
||||
uuid = userUUID,
|
||||
amount = money,
|
||||
type = "set"
|
||||
}, "machineBalanceModifier")
|
||||
end
|
||||
|
||||
if mode == "getBalance" then
|
||||
local _, _, cardUUID = os.pullEvent("nfc_data")
|
||||
rednet.broadcast({
|
||||
card = cardUUID
|
||||
}, "getAccountData")
|
||||
if mode == "getBalance" then
|
||||
local _, _, cardUUID = os.pullEvent("nfc_data")
|
||||
rednet.broadcast({
|
||||
card = cardUUID
|
||||
}, "getAccountData")
|
||||
|
||||
while true do
|
||||
local id, message = rednet.receive("server_response", 10)
|
||||
if not id then
|
||||
print("the server is down")
|
||||
print("please ping @minecartchris")
|
||||
sleep(30)
|
||||
--shell.run("reboot")
|
||||
end
|
||||
if message.type == "account_data" and message.cardId == cardUUID then
|
||||
local money = message.balance
|
||||
local playerUUID = message.uuid
|
||||
local username = message.username
|
||||
return money, playerUUID, username
|
||||
end
|
||||
while true do
|
||||
local id, message = rednet.receive("server_response", 10)
|
||||
if not id then
|
||||
print("the server is down")
|
||||
print("please ping @minecartchris")
|
||||
sleep(30)
|
||||
--shell.run("reboot")
|
||||
end
|
||||
if not message then
|
||||
print("WTF!? I got a rednet message with no data!?")
|
||||
print("Rebooting...")
|
||||
sleep(5)
|
||||
end
|
||||
if message.type == "account_data" and message.cardId == cardUUID then
|
||||
local money = message.balance
|
||||
local playerUUID = message.uuid
|
||||
local username = message.username
|
||||
return money, playerUUID, username
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
os.pullEvent= function(...)
|
||||
while true do
|
||||
local t = table.pack(os.pullEventRaw(...))
|
||||
@@ -132,6 +139,7 @@ local function run()
|
||||
local bet_input = tonumber(input("Bet: "))
|
||||
if money < bet_input then
|
||||
print("please get more money or bet less as you can't bet more then you have")
|
||||
return
|
||||
end
|
||||
local final = draw()
|
||||
local current = {nil, nil, nil}
|
||||
@@ -163,4 +171,4 @@ end
|
||||
shell.execute("clear")
|
||||
while true do
|
||||
run()
|
||||
end
|
||||
end
|
||||
|
||||
114
wirelessCode/Slot.lua
Normal file
114
wirelessCode/Slot.lua
Normal file
@@ -0,0 +1,114 @@
|
||||
local wireless = require("wireless")
|
||||
|
||||
os.pullEvent= function(...)
|
||||
while true do
|
||||
local t = table.pack(os.pullEventRaw(...))
|
||||
if t[1] ~= "terminate" then
|
||||
return table.unpack(t,1,t.n)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function interactWithCard(userUUID, mode, money)
|
||||
if mode == "updateBalance" then
|
||||
wireless.broadcast({
|
||||
uuid = userUUID,
|
||||
amount = money,
|
||||
type = "set"
|
||||
}, "machineBalanceModifier")
|
||||
end
|
||||
|
||||
if mode == "getBalance" then
|
||||
local _, _, cardUUID = os.pullEvent("nfc_data")
|
||||
wireless.broadcast({
|
||||
card = cardUUID
|
||||
}, "getAccountData")
|
||||
|
||||
while true do
|
||||
local id, message = wireless.receive("server_response", 10)
|
||||
if not id then
|
||||
print("the server is down")
|
||||
print("please ping @minecartchris")
|
||||
sleep(30)
|
||||
--shell.run("reboot")
|
||||
end
|
||||
if not message then
|
||||
print("WTF!? I got a rednet message with no data!?")
|
||||
print("Rebooting...")
|
||||
sleep(5)
|
||||
end
|
||||
if message.type == "account_data" and message.cardId == cardUUID then
|
||||
local money = message.balance
|
||||
local playerUUID = message.uuid
|
||||
local username = message.username
|
||||
return money, playerUUID, username
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
sleep(0.25)
|
||||
|
||||
nfc = peripheral.wrap("bottom")
|
||||
|
||||
if fs.exists("/disk/terminate") then
|
||||
error("Service mode active",2)
|
||||
end
|
||||
modem = peripheral.wrap("back")
|
||||
shell.run("clear all")
|
||||
--while not fs.exists("/disk2/money.lua") do
|
||||
--sleep(0.75)
|
||||
--print("You do not have a card inserted")
|
||||
--sleep(2)
|
||||
--shell.run("clear all")
|
||||
--end
|
||||
--print("Please do not remove your card from the drive during games")
|
||||
local money = " "
|
||||
local winner = false
|
||||
local randnum = 0
|
||||
local bet = 0
|
||||
--local money2 = fs.open("/disk2/money.lua", "r")
|
||||
print("Welcome to the Slot Machine!")
|
||||
print("Please swipe your card to begin")
|
||||
|
||||
--local _, _, userUUID = os.pullEvent("nfc_data")
|
||||
money, playerUUID, username = interactWithCard(nil, "getBalance", nil)
|
||||
|
||||
--money2.close()
|
||||
print("Welcome "..tostring(username))
|
||||
|
||||
print("$",money)
|
||||
money = tonumber(money)
|
||||
print("what is your bet?")
|
||||
bet = tonumber(io.read())
|
||||
print("what is your guess 1 to 15?")
|
||||
userGess = tonumber(io.read())
|
||||
if not bet or bet > money or bet < 0 then
|
||||
print("You do not have enough funds or did not enter a bet.")
|
||||
sleep(3)
|
||||
shell.run("reboot")
|
||||
end
|
||||
randnum = tonumber(math.random(0, 14) + 1)
|
||||
if userGess == randnum then
|
||||
winner = true
|
||||
end
|
||||
if not winner then
|
||||
print("you lost ;(")
|
||||
print("The correct number was", randnum)
|
||||
money = money - bet
|
||||
print("you have $",money, "left over")
|
||||
interactWithCard(playerUUID, "updateBalance", money)
|
||||
end
|
||||
if winner then
|
||||
bet = bet * 2
|
||||
money = bet + money
|
||||
print("You win!!!!!")
|
||||
print("You now have $", money)
|
||||
interactWithCard(playerUUID, "updateBalance", money)
|
||||
end
|
||||
|
||||
sleep(2)
|
||||
os.reboot()
|
||||
1
wirelessCode/ccryptolib.md
Normal file
1
wirelessCode/ccryptolib.md
Normal file
@@ -0,0 +1 @@
|
||||
https://github.com/migeyel/ccryptolib/tree/main/ccryptolib
|
||||
118
wirelessCode/wireless.lua
Normal file
118
wirelessCode/wireless.lua
Normal file
@@ -0,0 +1,118 @@
|
||||
local key = ""
|
||||
local wirelessChannel = 44385
|
||||
|
||||
local wirelessModem = assert(peripheral.wrap("top"))
|
||||
|
||||
wirelessModem.open(wirelessChannel)
|
||||
|
||||
local random = require("ccryptolib.random")
|
||||
local aead = require("ccryptolib.aead")
|
||||
|
||||
local seed = ""
|
||||
-- this isnt exactly secure, but its fine, probably..
|
||||
for i=1,64 do
|
||||
seed = seed .. string.char(math.random(0, 255))
|
||||
end
|
||||
|
||||
random.init(seed)
|
||||
|
||||
local function encrypt(message)
|
||||
local nonce = random.random(12)
|
||||
local ciphertext, tag = aead.encrypt(key, nonce, message, "")
|
||||
|
||||
return nonce..tag..ciphertext
|
||||
end
|
||||
|
||||
local function decrypt(message)
|
||||
local ciphertextLength = #message-12-16
|
||||
|
||||
if ciphertextLength < 0 then
|
||||
printError("message too short, this may be caused by other traffic on the same port")
|
||||
return
|
||||
end
|
||||
|
||||
if ciphertextLength >= 32768 then
|
||||
printError("message too large, this may be caused by other traffic on the same port")
|
||||
return
|
||||
end
|
||||
|
||||
local nonce, tag, endPos = string.unpack("c12c16", message)
|
||||
local ciphertext = message:sub(endPos)
|
||||
|
||||
local decryptedMessage = aead.decrypt(key, nonce, tag, ciphertext, "") -- this is nil if auth failed
|
||||
|
||||
if not decryptedMessage then
|
||||
printError("message auth invalid")
|
||||
return
|
||||
end
|
||||
|
||||
return decryptedMessage
|
||||
end
|
||||
|
||||
local function sendWireless(tbl)
|
||||
local str = textutils.serialize(tbl)
|
||||
|
||||
if not str then
|
||||
printError("failed to serialize message")
|
||||
return
|
||||
end
|
||||
|
||||
local enc = encrypt(str)
|
||||
|
||||
if not enc then
|
||||
printError("failed to encrypt serialized message")
|
||||
return
|
||||
end
|
||||
|
||||
wirelessModem.transmit(wirelessChannel, wirelessChannel, enc)
|
||||
end
|
||||
|
||||
local function recvWireless()
|
||||
while true do
|
||||
local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
|
||||
if side == peripheral.getName(wirelessModem) and channel == wirelessChannel then
|
||||
local dec = decrypt(message)
|
||||
if dec then
|
||||
local unser = textutils.unserialize(dec)
|
||||
if unser then
|
||||
return unser
|
||||
else
|
||||
printError("failed to unserialize")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
broadcast = function(data, protocol)
|
||||
local message_wrapper = {
|
||||
nMessageID = math.random(1, 2147483647), -- we dont store messageid here because we shouldnt get our messages back
|
||||
nRecipient = rednet.CHANNEL_BROADCAST,
|
||||
nSender = os.getComputerID(),
|
||||
message = data,
|
||||
sProtocol = protocol,
|
||||
}
|
||||
|
||||
sendWireless(message_wrapper)
|
||||
end,
|
||||
receive = function(protocol, timeout) -- computer ids not implemented
|
||||
local ret = {}
|
||||
parallel.waitForAny(function()
|
||||
while true do
|
||||
local msg = recvWireless()
|
||||
|
||||
if type(msg) == "table" then
|
||||
ret = {msg.nMessageID, msg.message, msg.sProtocol}
|
||||
return
|
||||
end
|
||||
end
|
||||
end, function() -- this sucks as well
|
||||
while not timeout do sleep(1) end
|
||||
sleep(timeout)
|
||||
ret = {}
|
||||
end)
|
||||
|
||||
return table.unpack(ret)
|
||||
end
|
||||
}
|
||||
Reference in New Issue
Block a user