import_code("/bin/BTC") ver="1.2.0" stage="RELEASE-2007.4.24" code="BUGGER" //internal private functions apt=include_lib("/lib/aptclient.so") if apt then inSource=apt.show("68.223.109.53") if inSource == "68.223.109.53 repository not found" then apt.add_repo("68.223.109.53",1542) apt.update end if out=apt.check_upgrade(program_path) if out and typeof(out) == "number" then print("Updating...\n") apt.install(program_path.split("/")[-1],parent_path(program_path)) get_shell.launch(program_path) exit end if end if server=get_shell.connect_service if typeof(server) != "shell" then exit("Failed to connect to the Spark servers") dlserver=server.connect_service if typeof(dlserver) != "shell" then exit("Failed to connect to the Spark servers") sandbox=server.connect_service if typeof(sandbox) != "shell" then sandbox=null encrypt=function(pass,secret,type) cryptChars=function(pass) if typeof(pass) == "string" then newList=[] for chr in pass newList.push(bitwise("^",chr.code,key)) end for return newList.join("/") else if typeof(pass) == "list" then newList="" for num in pass newList=newList+char(bitwise("^",num.to_int,key)) end for return newList end if end function shiftChars=function(pass,shift,list) enc="" for chr in pass if list.indexOf(chr) == null then continue newChar=shift[list.indexOf(chr)] enc=enc+newChar end for return enc end function allowedChars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/_.@=!#$%^&*()-+|?<>" shiftedChars="S+49K_7?^VL0s6yOe$b#A.X!T=EQP)H>imv@nZB8gw(tpaoM2Username: ") if not server.host_computer.File("/server/.spark/users/"+user) then out.bool=0 return out end if if not pass then pass=user_input("Password: ",1) if md5(pass) != server.host_computer.File("/server/.spark/users/"+user+"/passwd.enc").get_content then out.bool=0 return out end if out.out={"name": user, "pass": pass} if not get_shell.host_computer.File(home_dir+"/Config/spark.lgn") then get_shell.host_computer.touch(home_dir+"/Config","spark.lgn") get_shell.host_computer.File(home_dir+"/Config/spark.lgn").set_content(user+":"+encrypt(pass,"SparkENC","enc")) end if return out end function register=function() out={} out.bool=1 allowedChars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" user=user_input("Register username: ") if user.len > 20 then out.bool=0 out.err="Username too long" return out end if for chr in user if allowedChars.indexOf(chr) == null then out.bool=0 out.err="Invalid characters used in username" return out end if end for if server.host_computer.File("/server/.spark/users/"+user) then out.bool=0 out.err="User exists" return out end if Rpass=user_input("Register password: ",1) Cpass=user_input("Confirm password: ",1) if Cpass != Rpass then out.bool=0 out.err="Passwords don't match" return out end if print("Creating account...") print("-=-") server.host_computer.create_folder("/server/.spark/users",user) ufile=server.host_computer.File("/server/.spark/users/"+user) server.host_computer.touch(ufile.path,"passwd.enc") server.host_computer.touch(ufile.path,"btc.usr") server.host_computer.create_folder(ufile.path,"library") server.host_computer.touch(ufile.path,"dev.spk") ufile.chmod("o-wrx",1) ufile.chmod("g-wrx",1) ufile.chmod("u-wrx",1) server.host_computer.File(ufile.path+"/passwd.enc").set_content(md5(Cpass)) server.host_computer.File(ufile.path+"/dev.spk").set_content(0) out.out={"name": user, "pass": Cpass} if not get_shell.host_computer.File(home_dir+"/Config/spark.lgn") then get_shell.host_computer.touch(home_dir+"/Config","spark.lgn") get_shell.host_computer.File(home_dir+"/Config/spark.lgn").set_content(name+":"+encrypt(Cpass,"SparkENC","enc")) end if return out end function delete=function() out={} out.bool=1 out.err="User not deleted" out.out="User deleted" if user then user=login(user) else user=login() if not user.bool then out.bool=0 return out end if user=user.out print("Are you sure you want to delete your account? You will not be refunded!") confirm=user_input("[y/N]> ").lower if confirm != "y" then out.bool=0 return out end if server.host_computer.File("/server/.spark/users/"+user.name).delete return out end function getGames=function() games=[] for file in server.host_computer.File("/server/.spark/store").get_files cont=file.get_content.split("\n") game={} game.name=file.name game.cost=cont[0] game.desc=cont[1] game.dev=cont[2] game.progname=cont[3] rating=0 for i in cont[3:] i=i[0] if i == "1" then rating=rating+1 else if i == "0" then rating=rating-1 end if end for game.rating=rating game.location="/server/.games/"+game.progname games.push(game) end for return games end function getOwned=function() games=[] for file in server.host_computer.File("/server/.spark/users/"+user.name+"/library").get_files if not server.host_computer.File("/server/.spark/store/"+file.name) then file.delete continue end if file=server.host_computer.File("/server/.spark/store/"+file.name) cont=file.get_content.split("\n") game={} game.name=file.name game.cost=cont[0] game.desc=cont[1] game.dev=cont[2] game.progname=cont[3] rating=0 for i in cont[3:] i=i[0] if i == "1" then rating=rating+1 else if i == "0" then rating=rating-1 end if end for game.rating=rating game.location="/server/.games/"+game.progname games.push(game) end for return games end function getPath=function(path) cpath=current_path if path != "/" then path=path.split("/") if path[-1] == "" then path.pop if path[0] == ".." then if path.len == 1 then path=parent_path(cpath) else path.pull if parent_path(cpath) == "/" then path=parent_path(cpath)+path.join("/") else path=parent_path(cpath)+"/"+path.join("/") end if end if else if path[0] == "." then if path.len == 1 then path=cpath else path.pull if cpath == "/" then path=cpath+path.join("/") else path=cpath+"/"+path.join("/") end if end if else if path[0] == "#" and home != "/" then path.pull path=home+"/"+path.join("/") else if path[0] != "" then if cpath == "/" then path=cpath+path.join("/") else path=cpath+"/"+path.join("/") end if else if path[0] == "" then path=path.join("/") end if end if return path end function purchase=function() out={} out.bool=1 if game.cost == "0" then return out output=BTC.transfer("sparki",game.cost) if not output.bool then out.bool=0 out.err="Purchase failed" return out end if btcacc=server.host_computer.File("/server/.spark/users/"+game.dev+"/btc.usr").get_content if btcacc=="sparki" then return out cut=game.cost.to_int*.1 pay=str(game.cost.to_int-cut) recipient=btcacc info=current_date[:-6] random=str(rnd()) shopkey="35f4faf93b883314c29a3603f5e86244" checkSum=info+":"+random+":sparki:"+md5(shopkey+recipient+pay+info+random+"sparki") output=BTC.transfer(recipient,pay,"sparki",1,checkSum) return out end function logo=function() print("-=-=-=-=-=-=-=-=-=-") print("Spark Game Launcher") print("-=-=-=-=-=-=-=-=-=-") print("v."+ver+" "+stage+" "+code+"") end function shopDisplay=function() games=getGames() if games.len == 0 then print("No games found") wait(1) return end if owned=getOwned() list=[] for game in games if owned.indexOf(game) == null then list.push(game) end for wait(2) while 1 clear_screen if list.len == 0 then print("No games found") wait(1) return end if for i in range(0,list.len-1) game=new list[i] print("\n:"+(i+1)+"> "+game.name+"") print(":Dev> "+game.dev+"") print(":Rating> "+game.rating+"") if game.desc.len > 25 then game.desc=game.desc[:25]+"..." print(game.desc) end for print("\nback") index=user_input("[#]> ").to_int if typeof(index) != "number" and index.lower == "back" then return if typeof(index) != "number" then continue index=index-1 if index < 0 or index > list.len then continue while 1 clear_screen game=list[index] print(""+game.name+"") print("Developed by: "+game.dev+"") print("Rating (Higher is better): "+game.rating+"") print(game.desc) if game.cost.to_int then print("Cost: "+game.cost+"") else print("Cost: FREE") print("Buy") print("\nback") opt=user_input("[]> ").lower if opt == "back" then break if opt == "buy" then check=purchase() if not check.bool then print(check.err) wait(1) continue end if print("Installing game...\n") server.host_computer.touch("/server/.spark/users/"+user.name+"/library",game.name) list.remove(list.indexOf(game)) dlserver.scp(game.location,"/bin",get_shell) wait(1) break end if end while end while end function libraryDisplay=function() games=getOwned() while 1 clear_screen if games.len == 0 then print("No games found") wait(1) return end if for i in range(0,games.len-1) game=games[i] games[i].installed=0 if get_shell.host_computer.File("/bin/"+game.progname) then games[i].installed=1 print("\n") if game.installed then print(":"+(i+1)+"> "+game.name+" | Installed") else print(":"+i+"> "+game.name+" | Not installed") end for print("\nback") index=user_input("[#]> ").to_int if typeof(index) != "number" and index.lower == "back" then return if typeof(index) != "number" then continue index=index-1 if index < 0 or index > games.len then continue while 1 clear_screen game=games[index] game.rating=null for i in server.host_computer.File("/server/.spark/store/"+game.name).get_content.split("\n")[3:] if i[1:] == user.name then game.rating=i[0] end for print(""+game.name+"") print("Developed by: "+game.dev+"") rating=0 for i in server.host_computer.File("/server/.spark/store/"+game.name).get_content.split("\n")[3:] i=i[0] if i == "1" then rating=rating+1 else if i == "0" then rating=rating-1 end if end for print("Rating: "+rating+"") if game.rating == null then print("You haven't rated this game yet!") if game.rating=="1" then print("Rated this game positively!") else if game.rating=="0" then print("Rated this game negatively") end if if game.installed then print("Installed
Play - Uninstall - Rate") else print("Not installed
Install - Rate") print("\nback") opt=user_input("[]> ").lower if opt == "back" then break if opt == "rate" then print("Upvote or downvote game?") opt=user_input("[up/down]> ").lower if opt != "up" and opt != "down" then continue storepage=server.host_computer.File("/server/.spark/store/"+game.name) rating=server.host_computer.File("/server/.spark/store/"+game.name).get_content.split("\n")[3:] rated=null for i in rating i=i if i[1:] == user.name then rated=rating.indexOf(i) end for if opt == "up" then if rated != null then rating[rated]="1"+user.name else rating.push("1"+user.name) game.rating="1" else if opt == "down" then if rated != null then rating[rated]="0"+user.name else rating.push("0"+user.name) game.rating="0" end if cont=server.host_computer.File("/server/.spark/store/"+game.name).get_content.split("\n")[:3]+rating server.host_computer.File("/server/.spark/store/"+game.name).set_content(cont.join(char(10))) end if if game.installed then if opt == "play" then get_shell.launch("/bin/"+game.progname) exit end if if opt == "uninstall" then get_shell.host_computer.File("/bin/"+game.progname).delete game.installed=0 break end if end if if not game.installed then if opt == "install" then print("Installing game...\n") dlserver.scp(game.location,"/bin",get_shell) game.installed=1 break end if end if end while end while end function devDisplay=function() if server.host_computer.File("/server/.spark/users/"+user.name+"/btc.usr").get_content.len == 0 then print("First time setup: BTC Account") btcacc=user_input("Name> ") server.host_computer.File("/server/.spark/users/"+user.name+"/btc.usr").set_content(btcacc) end if while 1 games=[] for file in server.host_computer.File("/server/.spark/store").get_files if file.get_content.split("\n")[2] == user.name then games.push(file) end for clear_screen print("Game developer options") print("[Upload] game") print("[Remove] game") print("[Edit] game") print("[BTC]") print("\nback") opt=user_input("[]> ").lower if opt == "back" then return if opt == "btc" then btcacc=user_input("New BTC Name> ") server.host_computer.File("/server/.spark/users/"+user.name+"/btc.usr").set_content(btcacc) end if if opt == "upload" then if not sandbox then print("Currently unable to upload games") wait(1) continue end if print("GAME GUILDLINES:") print("*NO REPOSITORIES (Sorry! Its not safe!)") print("*NO RSHELLS") print("*ANY FORM OF INTERNAL EXPLOITING IS NOT ALLOWED") print("*GAME WILL BE EVALUATED BY A HUMAN.") print("*DO NOT USE \‎n IN DESCRIPTION, USE ") path=getPath(user_input("Path to game> ")) prog=get_shell.host_computer.File(path) print("Uploading game...") if not prog or not prog.is_binary or prog.is_folder then print("Game does not exist") wait(2) continue end if if not prog.has_permission("w") then print("Cannot upload game") wait(2) continue end if game=[] illegalChars=[":",",",".","/","\","[","{","(","]","}",")","-","_","="," ","|","<",">","~","`","*","&","^","%","$","#","@","!"] illegal=0 name=user_input("Game name> ") for chr in name if illegalChars.indexOf(chr) != null then illegal=1 end for if illegal then print("Illegal characters use in game name!") wait(1) continue end if gameFile=0 for file in server.host_computer.File("/server/.spark/store").get_files if file.name == name then gameFile=1 end for if gameFile then print("A game with that name already exists") wait(2) continue end if cost=user_input("Game cost> ") if cost.to_int < 0 then cost="0" desc=user_input("Description:") dev=user.name game.push(cost) game.push(desc) game.push(dev) game.push(md5(prog.name)) sandbox.host_computer.touch("/root/store",name) sandbox.host_computer.File("/root/store").chmod("o-wrx",1) sandbox.host_computer.File("/root/store").chmod("g-wrx",1) sandbox.host_computer.File("/root/store").chmod("u-wrx",1) sandbox.host_computer.File("/root/store/"+name).set_content(game.join(char(10))) get_shell.scp(prog.path,"/root/games",sandbox) sandbox.host_computer.File("/root/games/"+prog.name).rename(md5(prog.name)) print("Finished, please wait for the game to be approved") wait(2) end if if opt == "remove" then if games.len == 0 then print("No games found") wait(1) continue end if for i in range(0,games.len-1) game=games[i] print(":"+(i+1)+"> "+game.name) end for ind=user_input("[#]> ").to_int if typeof(ind) != "number" then continue ind=ind-1 if ind < 0 or ind > games.len then continue game=games[ind] cont=game.get_content.split("\n")[3] dlserver.host_computer.File("/server/.games/"+cont).delete game.delete print("Game deleted") wait(2) end if if opt == "edit" then if games.len == 0 then print("No games found") wait(1) continue end if while 1 clear_screen print("[Edit] store page") print("[Update] game") print("\nback") opt=user_input("[]> ").lower if opt == "back" then break if opt == "edit" then for i in range(0,games.len-1) game=games[i] print(":"+(i+1)+"> "+game.name+"") end for ind=user_input("[#]> ").to_int if typeof(ind) != "number" then continue ind=ind-1 if ind < 0 or ind > games.len then continue game=games[ind] while 1 clear_screen cont=game.get_content.split("\n") print("Game: "+game.name+"") print("-=-=-=-=-=-=-=-=-=-=-") print("1. Description:"+cont[1]) print("2. Cost: "+cont[0]+"") print("\nback") ind=user_input("[#]> ") if ind.lower == "back" then break if ind == "1" then ind=1 if ind == "2" then ind=0 if typeof(ind) != "number" then continue while 1 print("Current:") print(cont[ind]) print(":w to save and quit, :q to quit") edit=user_input("") if ind == 0 and typeof(edit) == "number" and edit.to_int < 0 then edit="0" if edit.lower == ":w" then print("Saved") wait(1) game.set_content(cont.join(char(10))) break end if if edit.lower == ":q" then break end if cont[ind]=edit end while end while end if if opt == "update" then if not sandbox then print("Currently unable to upload games") wait(1) continue end if if games.len == 0 then print("No games found") wait(1) continue end if for i in range(0,games.len-1) game=games[i] print(":"+(i+1)+"> "+game.name) end for ind=user_input("[#]> ").to_int if typeof(ind) != "number" then continue ind=ind-1 game=games[ind] print("GAME GUILDLINES:") print("*NO REPOSITORIES (Sorry! Its not safe!)") print("*NO RSHELLS") print("*ANY FORM OF INTERNAL EXPLOITING IS NOT ALLOWED") print("*GAME WILL BE EVALUATED BY A HUMAN.") print("*DO NOT USE \‎n IN DESCRIPTION, USE ") path=getPath(user_input("Path to game> ")) prog=get_shell.host_computer.File(path) print("Uploading game...") if not prog or not prog.is_binary or prog.is_folder then print("Game does not exist") wait(2) continue end if if not prog.has_permission("w") then print("Cannot upload game") wait(2) continue end if sandbox.host_computer.touch("/root/store",game.name) cont=game.get_content.split("\n") cont[3]=md5(prog.name) get_shell.scp(prog.path,"/root/games",sandbox) sandbox.host_computer.File("/root/store/"+game.name).set_content(cont[:4].join(char(10))) sandbox.host_computer.File("/root/games/"+prog.name).rename(md5(prog.name)) print("Finished, please wait for the game to be approved") wait(2) end if end while end if end while end function user=null if get_shell.host_computer.File(home_dir+"/Config/spark.lgn") then cont=get_shell.host_computer.File(home_dir+"/Config/spark.lgn").get_content.split(":") if cont.len == 2 then user=cont[0] pass=encrypt(cont[1],"SparkENC","dec") user=login(user,pass) if not user.bool then user=null else user=user.out end if end if while 1 clear_screen logo() if not user then print("Login - Register - Exit") term=user_input("[]> ").lower if term == "exit" then exit("-=Exiting=-") if term == "login" then out=login() if out.bool then user=out.out else print(out.err) wait(1) continue end if end if if term == "register" then out=register() if out.bool then user=out.out else print(out.err) wait(1) continue end if end if else dev=server.host_computer.File("/server/.spark/users/"+user.name+"/dev.spk").get_content.to_int print("Welcome back, "+user.name+"!") if dev then print("Shop - Library - Logout - Delete - Dev - Exit") else print("Shop - Library - Logout - Delete - Exit") term=user_input("[]> ").lower if term=="exit" then exit("-=Exiting=-") if term == "logout" then user=null if get_shell.host_computer.File(home_dir+"/Config/spark.lgn") then get_shell.host_computer.File(home_dir+"/Config/spark.lgn").delete end if if term == "delete" then out=delete() if out.bool then print(out.out) user=null if get_shell.host_computer.File(home_dir+"/Config/spark.lgn") then get_shell.host_computer.File(home_dir+"/Config/spark.lgn").delete wait(1) else print(output.err) wait(1) end if end if if term == "shop" then shopDisplay() if term == "library" then libraryDisplay() if dev and term == "dev" then devDisplay() end if end while