Maengorn

CC Remote

Jan 5th, 2021
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.79 KB | None | 0 0
  1. local a=5317;local b=5318;local c=false;local d=keys.leftCtrl;local e=colors.lightBlue;local f=colors.black;local g=colors.lightGray;local h=colors.gray;local i=colors.blue;local j=colors.black;local k=colors.red;local l=colors.white;local m=colors.lime;local n=colors.red;local o=1.3;local p=""local q=true;local r=false;local s=nil;local t=peripheral.getNames()if t[1]then if peripheral.getType(t[1])=="modem"then s=peripheral.wrap(t[1])else printError("No wireless modem found.")error()end else printError("No wireless modem found.")error()end;local function u()printError("Usage:")printError(shell.getRunningProgram().." host [vo] [HostCh] [ClientCh]")printError(shell.getRunningProgram().." join [HostCh] [ClientCh]")printError(shell.getRunningProgram().." help")error()end;local function v()printError("---------")printError("DISH v"..o)printError("---------")printError("View Only: Clients cannot control host")printError("HostCh: Channel the host speaks on")printError("ClientCh: Channel the clients speak on")error()end;local w={...}if#w<1 then u()else if w[1]=="help"then v()elseif w[1]=="host"then p="host"if w[2]then if w[2]=="true"or w[2]=="t"then c=true elseif w[2]=="false"or w[2]=="f"then c=false else u()end;if w[3]then a=tonumber(w[3])end;if w[4]then b=tonumber(w[4])end end elseif w[1]=="join"then p="client"if w[2]then a=tonumber(w[2])end;if w[3]then b=tonumber(w[3])end else u()end end;local function x()term.setBackgroundColor(e)term.setTextColor(f)term.clear()term.setCursorPos(4,2)print("DISH Menu")term.setCursorPos(2,4)print("Mode: ")term.setTextColor(h)term.setCursorPos(8,4)print(string.upper(p))term.setTextColor(f)term.setCursorPos(2,6)print("Channel (H):")term.setCursorPos(2,8)print("Channel (C):")term.setBackgroundColor(g)term.setTextColor(h)term.setCursorPos(2,7)print(" ")term.setCursorPos(2,7)print(a)term.setCursorPos(2,9)print(" ")term.setCursorPos(2,9)print(b)if p=="host"then term.setBackgroundColor(g)for y=1,4 do term.setCursorPos(2,10+y)print(" ")end;term.setTextColor(f)term.setCursorPos(2,11)print("Control Panel")term.setCursorPos(3,12)if c then term.setBackgroundColor(m)term.setTextColor(f)else term.setBackgroundColor(n)term.setTextColor(f)end;print(" View-Only ")end;term.setBackgroundColor(k)term.setTextColor(l)term.setCursorPos(2,16)print(" ")term.setCursorPos(2,17)print(" Exit DISH ")term.setCursorPos(2,18)print(" ")end;local function z()term.clear()term.setCursorPos(1,1)printError("DISH - Host")printError("Press "..keys.getName(d).." to open menu.")local A=term.current()local B={}for C,D in pairs(A)do B[C]=function(...)s.transmit(a,b,{p="DISH_TMF",n=C,a={...}})return D(...)end end;term.redirect(B)local function E()shell.run("/rom/programs/shell")end;local function F()while q do local G,H,I,J,K,L=os.pullEvent()if G=="modem_message"and I==b and J==a and K.p=="DISH_EVENT"then if not c then if not r then os.queueEvent(unpack(K.e))end end elseif G=="key"and H==d then local M=not r;w_MENU.setVisible(M)if M then term.redirect(w_MENU)x()else term.redirect(B)B.redraw()end;r=not r elseif G=="mouse_click"and r then if H==1 and I>=38 and I<=50 and J>=16 and J<=18 then q=false;term.redirect(w_ORIG)B.redraw()error()elseif H==1 and I>=39 and I<=49 and J==12 then c=not c;x()elseif H==1 and I>=38 and I<=50 and J==7 then term.setCursorPos(2,7)term.setBackgroundColor(g)term.setTextColor(h)print(" ")term.setCursorPos(2,7)local N=read()if tonumber(N)then a=tonumber(N)end;x()elseif H==1 and I>=38 and I<=50 and J==9 then term.setCursorPos(2,9)term.setBackgroundColor(g)term.setTextColor(h)print(" ")term.setCursorPos(2,9)local O=read()if tonumber(O)then s.close(b)b=tonumber(O)s.open(b)end;x()end end end end;local P=coroutine.create(E)local Q=coroutine.create(F)local R={}while true do if not r then coroutine.resume(P,unpack(R))end;coroutine.resume(Q,unpack(R))R={os.pullEvent()}if coroutine.status(P)=="dead"then q=false;s.transmit(a,b,{p="DISH_STOP"})term.setBackgroundColor(colors.black)term.clear()term.setCursorPos(1,1)printError("Server stopped running.")error()elseif coroutine.status(Q)=="dead"then q=false;s.transmit(a,b,{p="DISH_STOP"})term.setBackgroundColor(colors.black)term.clear()term.setCursorPos(1,1)printError("Server has been stopped.")error()end end end;local function S()term.clear()term.setCursorPos(1,1)printError("DISH - Client")printError("Press "..keys.getName(d).." to open menu.")while q do local G,H,I,J,K,L=os.pullEvent()if G=="modem_message"then if I==a and J==b and K.p=="DISH_TMF"then if term[K.n]and not r then term[K.n](unpack(K.a))end elseif I==a and J==b and K.p=="DISH_STOP"then q=false;term.setBackgroundColor(colors.black)term.clear()term.setCursorPos(1,1)printError("Host stopped the server.")term.redirect(w_ORIG)error()end elseif G=="key"and H==d then local M=not r;w_MENU.setVisible(M)if M then term.redirect(w_MENU)x()else term.redirect(w_MAIN)w_MAIN.redraw()end;r=not r elseif G=="mouse_click"and r then if H==1 and I>=38 and I<=50 and J>=16 and J<=18 then q=false;term.redirect(w_ORIG)w_MAIN.redraw()term.setBackgroundColor(colors.black)term.clear()term.setCursorPos(1,1)printError("Disconnected from server.")error()elseif H==1 and I>=38 and I<=50 and J==7 then term.setCursorPos(2,7)term.setBackgroundColor(g)term.setTextColor(h)print(" ")term.setCursorPos(2,7)local N=read()if tonumber(N)then s.close(a)a=tonumber(N)s.open(a)end;x()elseif H==1 and I>=38 and I<=50 and J==9 then term.setCursorPos(2,9)term.setBackgroundColor(g)term.setTextColor(h)print(" ")term.setCursorPos(2,9)local O=read()if tonumber(O)then b=tonumber(O)end;x()end else if not r then s.transmit(b,a,{p="DISH_EVENT",e={G,H,I,J,K,L}})end end end end;w_ORIG=term.current()w_MAIN=window.create(w_ORIG,1,1,51,19,true)w_MENU=window.create(w_ORIG,37,1,15,19,false)term.redirect(w_MAIN)if p=="client"then s.open(a)S()elseif p=="host"then s.open(b)z()end
Advertisement
Add Comment
Please, Sign In to add comment