Fix crash with nil messages

This commit is contained in:
Herr Katze
2026-02-01 16:32:03 -08:00
parent 94683e34bf
commit b9db35ec9c
3 changed files with 53 additions and 35 deletions
+5
View File
@@ -24,6 +24,11 @@ local function interactWithCard(userUUID, mode, money)
sleep(30) sleep(30)
--shell.run("reboot") --shell.run("reboot")
end 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 if message.type == "account_data" and message.cardId == cardUUID then
local money = message.balance local money = message.balance
local playerUUID = message.uuid local playerUUID = message.uuid
+12 -6
View File
@@ -3,12 +3,12 @@
rednet.open("back") rednet.open("back")
local function interactWithCard(userUUID, mode, money) local function interactWithCard(userUUID, mode, money)
if mode == "updateBalance" then if mode == "updateBalance" then
rednet.broadcast({ rednet.broadcast({
uuid = userUUID, uuid = userUUID,
amount = money, amount = money,
type = "set" type = "set"
}, "machineBalanceModifier") }, "machineBalanceModifier")
end end
if mode == "getBalance" then if mode == "getBalance" then
@@ -25,6 +25,11 @@ local function interactWithCard(userUUID, mode, money)
sleep(30) sleep(30)
--shell.run("reboot") --shell.run("reboot")
end 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 if message.type == "account_data" and message.cardId == cardUUID then
local money = message.balance local money = message.balance
local playerUUID = message.uuid local playerUUID = message.uuid
@@ -37,6 +42,7 @@ local function interactWithCard(userUUID, mode, money)
end end
sleep(0.25) sleep(0.25)
nfc = peripheral.wrap("bottom") nfc = peripheral.wrap("bottom")
+34 -27
View File
@@ -1,40 +1,47 @@
--slot2 --slot2
rednet.open("back") rednet.open("back")
local function interactWithCard(userUUID, mode, money) local function interactWithCard(userUUID, mode, money)
if mode == "updateBalance" then if mode == "updateBalance" then
rednet.broadcast({ rednet.broadcast({
uuid = userUUID, uuid = userUUID,
amount = money, amount = money,
type = "set" type = "set"
}, "machineBalanceModifier") }, "machineBalanceModifier")
end end
if mode == "getBalance" then if mode == "getBalance" then
local _, _, cardUUID = os.pullEvent("nfc_data") local _, _, cardUUID = os.pullEvent("nfc_data")
rednet.broadcast({ rednet.broadcast({
card = cardUUID card = cardUUID
}, "getAccountData") }, "getAccountData")
while true do while true do
local id, message = rednet.receive("server_response", 10) local id, message = rednet.receive("server_response", 10)
if not id then if not id then
print("the server is down") print("the server is down")
print("please ping @minecartchris") print("please ping @minecartchris")
sleep(30) sleep(30)
--shell.run("reboot") --shell.run("reboot")
end end
if message.type == "account_data" and message.cardId == cardUUID then if not message then
local money = message.balance print("WTF!? I got a rednet message with no data!?")
local playerUUID = message.uuid print("Rebooting...")
local username = message.username sleep(5)
return money, playerUUID, username end
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
end end
os.pullEvent= function(...) os.pullEvent= function(...)
while true do while true do
local t = table.pack(os.pullEventRaw(...)) local t = table.pack(os.pullEventRaw(...))