Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- GS (Game Server)
- Just Does Games
- V 1.0.0
- Init Release
- V 1.0.1
- Added Error Support (ish)
- Added GS console output when booting a game
- Added Game Updater
- Added Support to disable updates for GS and games separate
- V 1.0.2
- Added game 'Draw'
- Removed 'Stocks' due to saving issues and being old
- Fixed install by requiring the 'gmupdate' to be true
- ]]--
- local version = "v1.0.2"
- local gsupdate = true -- Change this if you want gs updates
- local gmupdate = true -- Change this if you want game updates
- if not http then return printError("Http is not enabled.") end
- --[[
- Menu engine
- ]]--
- function m(x,y,x2,y2,menu)
- menu = menu or error("Failed to load Menu.")
- x,y = x or error("Failed to load x"), y or error("Failed to load y")
- x2,y2 = x2 or error("Failed to load x2"), y2 or error("Failed to load y2")
- local sel, scroll, run, w, h = 1,0,true, term.getSize()
- while run do
- for i=1, y2-y do
- if menu[i+scroll] ~= nil then
- term.setCursorPos(x,y+i-1)
- term.setTextColor(colors.white)
- if sel == i then write("> ") else write(" ") end
- if menu[i+scroll] == "Exit" then term.setTextColor(colors.white) elseif fs.exists(menu[i+scroll]..".lua") then term.setTextColor(colors.green) else term.setTextColor(colors.red) end
- write(menu[i+scroll])
- end
- end
- a,b = os.pullEvent("key")
- if b == keys.w or b == keys.up then
- if sel == 1 and scroll ~= 0 then
- scroll = scroll - 1
- elseif sel ~= 1 then
- sel = sel - 1
- end
- elseif b == keys.s or b == keys.down then
- if sel == y2-y and scroll ~= #menu-(y2-y) then
- scroll = scroll + 1
- elseif sel ~= math.min(y2-y,#menu) then
- sel = sel + 1
- end
- elseif b == keys.e or b == keys.enter then
- return sel+scroll
- end
- end
- end
- --[[
- Menu engine
- ]]--
- local w,h = term.getSize()
- local gm, gameDir = {}, "/"
- local games = {
- {
- name = "Clicker",
- pb = "FUzxUXuy"
- },
- {
- name = "Draw",
- pb = "DSWtjD9y"
- },
- {
- name = "Beta",
- pb = "x7gg2hbd"
- },
- }
- function searchForUpdates(gameid)
- if games[gameid] then
- print("Searching for updated for "..games[gameid].name.."...")
- local h = http.get("https://pastebin.com/raw/"..games[gameid].pb)
- if h then
- local f = fs.open(gameDir..games[gameid].name..".lua", "r")
- if f then
- local old, new = f.readAll(), h.readAll()
- f.close() h.close()
- if old ~= new then
- print("Updating...")
- local f = fs.open(gameDir..games[gameid].name..".lua", "w")
- f.write(new)
- f.close()
- end
- else
- h.close()
- error("Failed to install game # "..gameid)
- end
- end
- else
- error("Failed to find game #"..gameid)
- end
- end
- function install(gameid)
- if games[gameid] then
- print("Downloading "..games[gameid].name.."...")
- local h = http.get("https://pastebin.com/raw/"..games[gameid].pb)
- if h then
- local f = fs.open(gameDir..games[gameid].name..".lua", "w")
- if f then
- print("Installing "..games[gameid].name.."...")
- f.write(h.readAll())
- f.close() h.close()
- else
- h.close()
- error("Failed to install game # "..gameid)
- end
- else
- error("Failed to download game #"..gameid)
- end
- else
- error("Failed to find game #"..gameid)
- end
- end
- function rungame(gameid)
- term.clear() term.setCursorPos(1,1) print("GS") for i=1, w do write("=") end
- if games[gameid] then
- if not fs.exists(gameDir..games[gameid].name..".lua") and gmupdate then
- install(gameid)
- elseif gmupdate then
- searchForUpdates(gameid)
- end
- local r = os.run({}, gameDir..games[gameid].name..".lua")
- if not r then
- print("")
- print("GS") for i=1, w do write("=") end
- print("Program Crashed with error")
- sleep(1)
- print("")
- print("Press any key to exit.")
- os.pullEvent()
- end
- else
- error("Failed to find game #"..gameid)
- end
- end
- function runtime()
- local run = true
- while run do
- gm = {}
- for i=1, #games do
- table.insert(gm, games[i].name)
- end
- table.insert(gm, "Exit")
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- write("Game Server "..version.." | Just Does Games")
- local x = m(1,3,w,h-1,gm)
- if x == #gm then run = false else rungame(x) end
- end
- end
- print("Booting GS...")
- if gsupdate then
- local h = http.get("https://pastebin.com/raw/sKFnL4sr")
- if h then
- local f = fs.open(shell.getRunningProgram(), "r")
- if f then
- local old = f.readAll()
- local new = h.readAll()
- h.close()
- f.close()
- if old ~= new then
- f = fs.open(shell.getRunningProgram(), "w")
- f.write(new)
- f.close()
- end
- end
- end
- end
- runtime()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1) sleep(.1)
Add Comment
Please, Sign In to add comment