mirror of
https://github.com/LDDestroier/CC/
synced 2025-06-25 14:42:53 +00:00
Added password feature
This commit is contained in:
parent
70383c7658
commit
0f255e73fd
175
tron.lua
175
tron.lua
@ -347,6 +347,7 @@ if gridList[argList["--gridID"]] then
|
|||||||
gridID = argList["--gridID"]
|
gridID = argList["--gridID"]
|
||||||
end
|
end
|
||||||
local argumentName = argList[1]
|
local argumentName = argList[1]
|
||||||
|
local argumentPassword = argList[2] or ""
|
||||||
|
|
||||||
if useSkynet and (not http.websocket) then
|
if useSkynet and (not http.websocket) then
|
||||||
error("Skynet is not supported on this version of ComputerCraft.")
|
error("Skynet is not supported on this version of ComputerCraft.")
|
||||||
@ -1374,7 +1375,8 @@ local makeMenu = function(x, fromX, y, options, doAnimate, scrollInfo, _cpos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local nameChange = function(scrollInfo)
|
local specialRead = function(scrollInfo, specialNames, message, preInput)
|
||||||
|
specialNames = specialNames or {}
|
||||||
local gsX, gsY = (scrollInfo or {})[2] or 0, (scrollInfo or {})[3] or 0
|
local gsX, gsY = (scrollInfo or {})[2] or 0, (scrollInfo or {})[3] or 0
|
||||||
local step = (scrollInfo or {})[1] or 0
|
local step = (scrollInfo or {})[1] or 0
|
||||||
local tID = os.startTimer(gameDelayInit)
|
local tID = os.startTimer(gameDelayInit)
|
||||||
@ -1382,66 +1384,15 @@ local nameChange = function(scrollInfo)
|
|||||||
local cpos = 1
|
local cpos = 1
|
||||||
local maxSize = 15
|
local maxSize = 15
|
||||||
local evt
|
local evt
|
||||||
-- this has no functional significance. just some shoutouts
|
for x = 1, #preInput do
|
||||||
local specialNames = {
|
buff[x] = preInput:sub(x, x)
|
||||||
["blu"] = colors.blue,
|
|
||||||
["red"] = colors.red,
|
|
||||||
["ldd"] = colors.orange,
|
|
||||||
["lddestroier"] = colors.orange,
|
|
||||||
["hydraz"] = colors.yellow,
|
|
||||||
["hugeblank"] = colors.orange,
|
|
||||||
["bagel"] = colors.orange,
|
|
||||||
["3d6"] = colors.lime,
|
|
||||||
["lyqyd"] = colors.red,
|
|
||||||
["squiddev"] = colors.cyan,
|
|
||||||
["oeed"] = colors.lime,
|
|
||||||
["dog"] = colors.purple,
|
|
||||||
["nothy"] = colors.lightGray,
|
|
||||||
["kepler"] = colors.cyan,
|
|
||||||
["kepler155c"] = colors.cyan,
|
|
||||||
["anavrins"] = colors.blue,
|
|
||||||
["redmatters"] = colors.red,
|
|
||||||
["fatmanchummy"] = colors.purple,
|
|
||||||
["crazed"] = colors.lightBlue,
|
|
||||||
["ape"] = colors.brown,
|
|
||||||
["everyos"] = colors.red,
|
|
||||||
["lemmmy"] = colors.red,
|
|
||||||
["yemmel"] = colors.red,
|
|
||||||
["apemanzilla"] = colors.brown,
|
|
||||||
["osmarks"] = colors.green,
|
|
||||||
["gollark"] = colors.green,
|
|
||||||
["dece"] = colors.cyan,
|
|
||||||
["hpwebcamable"] = colors.lightGray,
|
|
||||||
["theoriginalbit"] = colors.blue,
|
|
||||||
["bombbloke"] = colors.red,
|
|
||||||
["kingofgamesyami"] = colors.lightBlue,
|
|
||||||
["pixeltoast"] = colors.lime,
|
|
||||||
["creator"] = colors.yellow,
|
|
||||||
["dannysmc"] = colors.purple,
|
|
||||||
["dannysmc95"] = colors.purple,
|
|
||||||
["kingdaro"] = colors.blue,
|
|
||||||
["valithor"] = colors.orange,
|
|
||||||
["logandark"] = colors.lightGray,
|
|
||||||
["lupus590"] = colors.lightGray,
|
|
||||||
["nitrogenfingers"] = colors.green,
|
|
||||||
["gravityscore"] = colors.lime,
|
|
||||||
["1lann"] = colors.gray,
|
|
||||||
["konlab"] = colors.brown,
|
|
||||||
["elvishjerricco"] = colors.pink
|
|
||||||
}
|
|
||||||
local prevName = argumentName or player[you].initName
|
|
||||||
for x = 1, #prevName do
|
|
||||||
buff[x] = prevName:sub(x, x)
|
|
||||||
cpos = cpos + 1
|
cpos = cpos + 1
|
||||||
end
|
end
|
||||||
term.setCursorBlink(true)
|
term.setCursorBlink(true)
|
||||||
local rend = function()
|
local rend = function()
|
||||||
if table.concat(buff):upper() == "GASTER" then
|
|
||||||
os.reboot() -- lol
|
|
||||||
end
|
|
||||||
drawGrid(gsX, gsY, true)
|
drawGrid(gsX, gsY, true)
|
||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
cwrite("Enter your name.", scr_y - 5)
|
cwrite(message, scr_y - 5)
|
||||||
term.setTextColor(specialNames[table.concat(buff):lower()] or colors.white)
|
term.setTextColor(specialNames[table.concat(buff):lower()] or colors.white)
|
||||||
term.setCursorPos( cwrite(table.concat(buff), scr_y - 3, nil, cpos) - 1, scr_y - 3)
|
term.setCursorPos( cwrite(table.concat(buff), scr_y - 3, nil, cpos) - 1, scr_y - 3)
|
||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
@ -1492,6 +1443,61 @@ local nameChange = function(scrollInfo)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local passwordChange = function(scrollInfo)
|
||||||
|
return specialRead(scrollInfo, {}, "Enter a password.", argumentPassword or "") or ""
|
||||||
|
end
|
||||||
|
|
||||||
|
local nameChange = function(scrollInfo)
|
||||||
|
-- this has no functional significance. just some shoutouts
|
||||||
|
local specialNames = {
|
||||||
|
["blu"] = colors.blue,
|
||||||
|
["red"] = colors.red,
|
||||||
|
["ldd"] = colors.orange,
|
||||||
|
["lddestroier"] = colors.orange,
|
||||||
|
["hydraz"] = colors.yellow,
|
||||||
|
["hugeblank"] = colors.orange,
|
||||||
|
["bagel"] = colors.orange,
|
||||||
|
["3d6"] = colors.lime,
|
||||||
|
["lyqyd"] = colors.red,
|
||||||
|
["squiddev"] = colors.cyan,
|
||||||
|
["oeed"] = colors.lime,
|
||||||
|
["dog"] = colors.purple,
|
||||||
|
["nothy"] = colors.lightGray,
|
||||||
|
["kepler"] = colors.cyan,
|
||||||
|
["kepler155c"] = colors.cyan,
|
||||||
|
["anavrins"] = colors.blue,
|
||||||
|
["redmatters"] = colors.red,
|
||||||
|
["fatmanchummy"] = colors.purple,
|
||||||
|
["crazed"] = colors.lightBlue,
|
||||||
|
["ape"] = colors.brown,
|
||||||
|
["everyos"] = colors.red,
|
||||||
|
["lemmmy"] = colors.red,
|
||||||
|
["yemmel"] = colors.red,
|
||||||
|
["apemanzilla"] = colors.brown,
|
||||||
|
["osmarks"] = colors.green,
|
||||||
|
["gollark"] = colors.green,
|
||||||
|
["dece"] = colors.cyan,
|
||||||
|
["hpwebcamable"] = colors.lightGray,
|
||||||
|
["theoriginalbit"] = colors.blue,
|
||||||
|
["bombbloke"] = colors.red,
|
||||||
|
["kingofgamesyami"] = colors.lightBlue,
|
||||||
|
["pixeltoast"] = colors.lime,
|
||||||
|
["creator"] = colors.yellow,
|
||||||
|
["dannysmc"] = colors.purple,
|
||||||
|
["dannysmc95"] = colors.purple,
|
||||||
|
["kingdaro"] = colors.blue,
|
||||||
|
["valithor"] = colors.orange,
|
||||||
|
["logandark"] = colors.lightGray,
|
||||||
|
["lupus590"] = colors.lightGray,
|
||||||
|
["nitrogenfingers"] = colors.green,
|
||||||
|
["gravityscore"] = colors.lime,
|
||||||
|
["1lann"] = colors.gray,
|
||||||
|
["konlab"] = colors.brown,
|
||||||
|
["elvishjerricco"] = colors.pink
|
||||||
|
}
|
||||||
|
return specialRead(scrollInfo, specialNames, "Enter your name.", argumentName or player[you].initName)
|
||||||
|
end
|
||||||
|
|
||||||
local titleScreen = function()
|
local titleScreen = function()
|
||||||
termclear()
|
termclear()
|
||||||
local menuOptions, options, choice, scrollInfo
|
local menuOptions, options, choice, scrollInfo
|
||||||
@ -1523,6 +1529,7 @@ local titleScreen = function()
|
|||||||
"Grid Demo",
|
"Grid Demo",
|
||||||
"Change Name",
|
"Change Name",
|
||||||
"Change Grid",
|
"Change Grid",
|
||||||
|
"Change Password",
|
||||||
(useSkynet and "Disable" or "Enable") .. " Skynet",
|
(useSkynet and "Disable" or "Enable") .. " Skynet",
|
||||||
"Back..."
|
"Back..."
|
||||||
}
|
}
|
||||||
@ -1546,6 +1553,8 @@ local titleScreen = function()
|
|||||||
gridID = (gridID % #gridList) + 1
|
gridID = (gridID % #gridList) + 1
|
||||||
gridFore, gridBack = table.unpack(gridList[gridID])
|
gridFore, gridBack = table.unpack(gridList[gridID])
|
||||||
elseif choice == 4 then
|
elseif choice == 4 then
|
||||||
|
argumentPassword = passwordChange(scrollInfo)
|
||||||
|
elseif choice == 5 then
|
||||||
if http.websocket then
|
if http.websocket then
|
||||||
useSkynet = not useSkynet
|
useSkynet = not useSkynet
|
||||||
setUpModem()
|
setUpModem()
|
||||||
@ -1564,7 +1573,7 @@ local titleScreen = function()
|
|||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
os.pullEvent("key")
|
os.pullEvent("key")
|
||||||
end
|
end
|
||||||
elseif choice == 5 then
|
elseif choice == 6 then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1938,34 +1947,37 @@ local networking = function()
|
|||||||
if channel == port and type(msg) == "table" then
|
if channel == port and type(msg) == "table" then
|
||||||
if type(msg.gameID) == "string" then
|
if type(msg.gameID) == "string" then
|
||||||
if waitingForGame and (type(msg.time) == "number") then
|
if waitingForGame and (type(msg.time) == "number") then
|
||||||
|
if msg.password == argumentPassword or (argumentPassword == "" and not msg.password) then
|
||||||
|
|
||||||
-- called while waiting for match
|
-- called while waiting for match
|
||||||
if msg.time < cTime then
|
if msg.time < cTime then
|
||||||
isHost = false
|
isHost = false
|
||||||
you, nou = nou, you
|
you, nou = nou, you
|
||||||
gamename = msg.gameID
|
gamename = msg.gameID
|
||||||
gameDelay = tonumber(msg.gameDelay) or gameDelayInit
|
gameDelay = tonumber(msg.gameDelay) or gameDelayInit
|
||||||
grid = msg.grid or copyTable(initGrid)
|
grid = msg.grid or copyTable(initGrid)
|
||||||
player = msg.player or player
|
player = msg.player or player
|
||||||
player[you].name = argumentName or player[you].initName
|
player[you].name = argumentName or player[you].initName
|
||||||
else
|
else
|
||||||
isHost = true
|
isHost = true
|
||||||
|
end
|
||||||
|
|
||||||
|
player[nou].name = msg.name or player[nou].initName
|
||||||
|
|
||||||
|
transmit(port, {
|
||||||
|
player = player,
|
||||||
|
gameID = gamename,
|
||||||
|
time = cTime,
|
||||||
|
name = argumentName,
|
||||||
|
password = argumentPassword,
|
||||||
|
grid = initGrid
|
||||||
|
})
|
||||||
|
waitingForGame = false
|
||||||
|
netKeysDown = {}
|
||||||
|
os.queueEvent("new_game", gameID)
|
||||||
|
return gameID
|
||||||
end
|
end
|
||||||
|
|
||||||
player[nou].name = msg.name or player[nou].initName
|
|
||||||
|
|
||||||
transmit(port, {
|
|
||||||
player = player,
|
|
||||||
gameID = gamename,
|
|
||||||
time = cTime,
|
|
||||||
name = argumentName,
|
|
||||||
grid = initGrid
|
|
||||||
})
|
|
||||||
waitingForGame = false
|
|
||||||
netKeysDown = {}
|
|
||||||
os.queueEvent("new_game", gameID)
|
|
||||||
return gameID
|
|
||||||
|
|
||||||
elseif msg.gameID == gamename then
|
elseif msg.gameID == gamename then
|
||||||
|
|
||||||
-- called during gameplay
|
-- called during gameplay
|
||||||
@ -2045,6 +2057,7 @@ local startGame = function()
|
|||||||
gameID = gamename,
|
gameID = gamename,
|
||||||
gameDelay = gameDelayInit,
|
gameDelay = gameDelayInit,
|
||||||
time = cTime,
|
time = cTime,
|
||||||
|
password = argumentPassword,
|
||||||
name = argumentName,
|
name = argumentName,
|
||||||
grid = initGrid
|
grid = initGrid
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user