codingbutter

P2P Beta-minified

Jan 25th, 2022 (edited)
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.48 KB | None | 0 0
  1. local a=(function()local a=function(b,c)if b.super or b.new then error("super and new can not exist within class defenitions",2)end;if c then setmetatable(b,{__index=c})b.super=c end;function b:new(...)local d={}setmetatable(d,{__index=self})if d.constructor then d:constructor(...)end;return d end;return b end;return a end)()local e=(function()local e={_version="0.1.2"}local f;local g={["\\"]="\\",["\""]="\"",["\b"]="b",["\f"]="f",["\n"]="n",["\r"]="r",["\t"]="t"}local h={["/"]="/"}for i,j in pairs(g)do h[j]=i end;local function k(l)return"\\"..(g[l]or string.format("u%04x",l:byte()))end;local function m(n)return"null"end;local function o(n,p)local q={}p=p or{}if p[n]then error("circular reference")end;p[n]=true;if rawget(n,1)~=nil or next(n)==nil then local r=0;for i in pairs(n)do if type(i)~="number"then error("invalid table: mixed or invalid key types")end;r=r+1 end;if r~=#n then error("invalid table: sparse array")end;for s,j in ipairs(n)do table.insert(q,f(j,p))end;p[n]=nil;return"["..table.concat(q,",").."]"else for i,j in pairs(n)do if type(i)~="string"then error("invalid table: mixed or invalid key types")end;table.insert(q,f(i,p)..":"..f(j,p))end;p[n]=nil;return"{"..table.concat(q,",").."}"end end;local function t(n)return'"'..n:gsub('[%z\1-\31\\"]',k)..'"'end;local function u(n)if n~=n or n<=-math.huge or n>=math.huge then error("unexpected number value '"..tostring(n).."'")end;return string.format("%.14g",n)end;local v={["nil"]=m,["table"]=o,["string"]=t,["number"]=u,["boolean"]=tostring}f=function(n,p)local w=type(n)local x=v[w]if x then return x(n,p)end;error("unexpected type '"..w.."'")end;function e.encode(n)return f(n)end;local y;local function z(...)local q={}for s=1,select("#",...)do q[select(s,...)]=true end;return q end;local A=z(" ","\t","\r","\n")local B=z(" ","\t","\r","\n","]","}",",")local C=z("\\","/",'"',"b","f","n","r","t","u")local D=z("true","false","null")local E={["true"]=true,["false"]=false,["null"]=nil}local function F(G,H,I,J)for s=H,#G do if I[G:sub(s,s)]~=J then return s end end;return#G+1 end;local function K(G,H,L)local M=1;local N=1;for s=1,H-1 do N=N+1;if G:sub(s,s)=="\n"then M=M+1;N=1 end end;error(string.format("%s at line %d col %d",L,M,N))end;local function O(r)local x=math.floor;if r<=0x7f then return string.char(r)elseif r<=0x7ff then return string.char(x(r/64)+192,r%64+128)elseif r<=0xffff then return string.char(x(r/4096)+224,x(r%4096/64)+128,r%64+128)elseif r<=0x10ffff then return string.char(x(r/262144)+240,x(r%262144/4096)+128,x(r%4096/64)+128,r%64+128)end;error(string.format("invalid unicode codepoint '%x'",r))end;local function P(Q)local R=tonumber(Q:sub(1,4),16)local S=tonumber(Q:sub(7,10),16)if S then return O((R-0xd800)*0x400+S-0xdc00+0x10000)else return O(R)end end;local function T(G,s)local q=""local U=s+1;local i=U;while U<=#G do local V=G:byte(U)if V<32 then K(G,U,"control character in string")elseif V==92 then q=q..G:sub(i,U-1)U=U+1;local l=G:sub(U,U)if l=="u"then local W=G:match("^[dD][89aAbB]%x%x\\u%x%x%x%x",U+1)or G:match("^%x%x%x%x",U+1)or K(G,U-1,"invalid unicode escape in string")q=q..P(W)U=U+#W else if not C[l]then K(G,U-1,"invalid escape char '"..l.."' in string")end;q=q..h[l]end;i=U+1 elseif V==34 then q=q..G:sub(i,U-1)return q,U+1 end;U=U+1 end;K(G,s,"expected closing quote for string")end;local function X(G,s)local V=F(G,s,B)local Q=G:sub(s,V-1)local r=tonumber(Q)if not r then K(G,s,"invalid number '"..Q.."'")end;return r,V end;local function Y(G,s)local V=F(G,s,B)local Z=G:sub(s,V-1)if not D[Z]then K(G,s,"invalid literal '"..Z.."'")end;return E[Z],V end;local function _(G,s)local q={}local r=1;s=s+1;while 1 do local V;s=F(G,s,A,true)if G:sub(s,s)=="]"then s=s+1;break end;V,s=y(G,s)q[r]=V;r=r+1;s=F(G,s,A,true)local a0=G:sub(s,s)s=s+1;if a0=="]"then break end;if a0~=","then K(G,s,"expected ']' or ','")end end;return q,s end;local function a1(G,s)local q={}s=s+1;while 1 do local a2,n;s=F(G,s,A,true)if G:sub(s,s)=="}"then s=s+1;break end;if G:sub(s,s)~='"'then K(G,s,"expected string for key")end;a2,s=y(G,s)s=F(G,s,A,true)if G:sub(s,s)~=":"then K(G,s,"expected ':' after key")end;s=F(G,s+1,A,true)n,s=y(G,s)q[a2]=n;s=F(G,s,A,true)local a0=G:sub(s,s)s=s+1;if a0=="}"then break end;if a0~=","then K(G,s,"expected '}' or ','")end end;return q,s end;local a3={['"']=T,["0"]=X,["1"]=X,["2"]=X,["3"]=X,["4"]=X,["5"]=X,["6"]=X,["7"]=X,["8"]=X,["9"]=X,["-"]=X,["t"]=Y,["f"]=Y,["n"]=Y,["["]=_,["{"]=a1}y=function(G,H)local a0=G:sub(H,H)local x=a3[a0]if x then return x(G,H)end;K(G,H,"unexpected character '"..a0 .."'")end;function e.decode(G)if type(G)~="string"then error("expected argument of type string, got "..type(G))end;local q,H=y(G,F(G,1,A,true))H=F(G,H,A,true)if H<=#G then K(G,H,"trailing garbage")end;return q end;return e end)()local a4="http://beastcraft.codingbutter.com:8888/"local a5="ws://beastcraft.codingbutter.com:3028"local a6=a({dispatch={connected=function()end},constructor=function(self,a7)self.username=a7 or os.getComputerID()self.peers={}self.ws,self.err=http.websocket(a5)if self.ws then self.connected=true end end,attachEventLoop=function(self,a8)parallel.waitForAll(function()while self.connected do local L=self.ws.receive()self:parseMessage(L)end end,function()local a9=os.startTimer(60)while self.connected==true do local aa=os.pullEvent("timer")if aa[2]==a9 and self.id and self.lobby and self.room then self:joinRoom(self.lobby,self.room,self.password)a9=os.startTimer(60)end end end,a8)end,captureRecieved=function(self)end,parseMessage=function(self,L)local ab=e.decode(L)local ac=ab.event;local ad=ab.payload;if ac=="peerId"then self.id=ad;self:joinRoom()self:send("peer_added",{message="Hello"},self.peers)self.dispatch["connected"]()else if ac=="peer_added"then self:joinRoom()end;local ae=ab.peer;if self.dispatch[ac]then self.dispatch[ac](ad,ae)end end end,send=function(self,ab,ad,af)local ag=af or self.peers;if type(ag)~="table"then ag={af}end;self.ws.send(e.encode({event=ab,peer={peerid=self.id,username=self.username},payload=ad,peers=ag}))end,on=function(self,ah,ai)self.dispatch[ah]=ai end,getPeers=function(self)return self.peers end,getRooms=function(aj)local ak=http.get(a4 ..aj)return e.decode(ak.readAll())end,joinRoom=function(self)local al=a4 ..self.lobby.."/"..self.room.."/"..self.id.."/"..self.username;if password then al=al.."?password="..password end;local am=e.decode(http.get(al).readAll())self.peers=am.error and{}or am end,connect=function(self,aj,an,password)self.lobby=aj;self.room=an;self.password=password;self:send("connect",{username=self.username})end,close=function(self)self.connected=false;self.ws.close()end})return a6
Add Comment
Please, Sign In to add comment