Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- gatelist={}
- strpart={}
- chat={}
- redsignal=0
- status="waiting"
- function sgSay(word,pre,lng)
- local i
- local V={"givename","nomodem","skip","yesmodem","nogates","incoming","connect","opened","cmdlist","startup","yes","no","wrong","startsuc","namesuc","nocommand","cmdlist","install"}
- local E={"Write address of the gate",
- "Modem not detected, connect the modem",
- "Press any key to continue",
- "Modem is found",
- "Gates not found",
- "Incoming wormhole",
- "Chevron 6 engaged",
- "Gates are already opened",
- "/list - view list of registred gates\n/getname - view the name of the gates\n/changename - change the name of the gates\n/changelang - change language\n/startup - add program to startup",
- "Do you want to add a program to the startup?",
- "1. Yes",
- "2. No",
- "Wrong value",
- "Program added to startup",
- "Name succsessfully changed",
- "No such command",
- "Type /cmdlist to view commands list",
- "Do you want to install the program?"}
- local R={"Napishi adres vrat",
- "Modem ne obnaruzhen, podkljuchite modem",
- "Nazhmite ljubuju klavishu dlja prodolzhenija",
- "Modem najden",
- "Vrat ne obnaruzheno",
- "Vhodjashij tonnel'",
- "Shevron 6 zablokirovan",
- "Vrata uzhe otkryty",
- "/list - pokazat' spisok najdennyh vrat\n/getname - pokazat' imja vrat\n/changename - pomenjat' imja vrat\n/changelang - pomenjat' jazyk\n/startup - dobavit' programmu v avtozapusk",
- "Vy hotite dobavit' programmu v avtozapusk?",
- "1. Da",
- "2. Net",
- "Nepravil'noe znachenie",
- "Pprogramma dobavlena v avtozapusk",
- "Imja uspeshno izmeneno",
- "Takoj komandy ne suwestvuet",
- "Napishi /cmdlist chtoby uvidet' spisok komand",
- "Vy hotite ustanovit' programmu?"}
- if lng==nil then lng=lang end
- if pre==nil then pre="" end
- for i=1,#V do
- if V[i]==word then
- word=i
- break
- end
- end
- if lng==1 then
- sgWrite(E[word])
- elseif lng==2 then
- sgWrite(R[word])
- end
- end
- function sgCmdList(lng)
- local i
- local V={"/list","/getname","/changename","/changelang","/startup","/close","/clear"}
- local E={"view list of registred gates",
- "view the name of the gates",
- "change the name of the gates",
- "change language",
- "add program to startup",
- "close the gates",
- "clear screen"}
- local R={"pokazat' spisok najdennyh vrat",
- "pokazat' imja vrat",
- "pomenjat' imja vrat",
- "pomenjat' jazyk",
- "dobavit' programmu v avtozapusk",
- "zakryt' vrata",
- "otchistit' ekran"}
- if lng==nil then lng=lang end
- for i=1,#V do
- if lng==1 then
- sgWrite(V[i].." - "..E[i])
- elseif lng==2 then
- sgWrite(V[i].." - "..R[i])
- end
- end
- end
- function sgSave()
- strpart[1]=lang
- strpart[2]=gatename
- file = io.open("stargate/stargate.dat", "w")
- local i=1
- while true do
- if strpart[i] == nil then break end
- file:write(strpart[i].."\n")
- i=i+1
- end
- file:close()
- end
- function sgLoad()
- file=io.open("stargate/stargate.dat", "r")
- local i=1
- while true do
- line=file:read()
- if line==nil then break end
- strpart[i]=line
- i=i+1
- end
- file:close()
- lang=strpart[1]+0
- gatename=strpart[2]
- end
- function sgLang()
- sgWrite("Choose language / Vyberi jazyk")
- sgWrite("1. English")
- sgWrite("2. Russkij")
- repeat
- lang=sgRead("lang")
- if lang=="1" then sgWrite("English")
- elseif lang=="2" then sgWrite("Russkij")
- else sgWrite("Wrong value / Nepravil'noe znachenie") end
- until lang=="1" or lang=="2"
- lang=lang+0
- end
- function sgWrite(text)
- if text~="" then
- local x,y=term.getCursorPos()
- chat[#chat+1]=text
- local k=#chat
- local i
- for i=16,2,-1 do
- if chat[k]==nil then break end
- term.setCursorPos(1,i)
- term.clearLine()
- write(chat[k])
- k=k-1
- end
- term.setCursorPos(x,y)
- end
- end
- function sgRead(pre)
- cmd=""
- if pre==nil then pre="" end
- term.setCursorPos(1, 18)
- term.clearLine()
- write(pre.."> ")
- while true do
- event,key=os.pullEvent()
- if event=="char" then
- write(key)
- cmd=cmd..key
- elseif event=="key" then
- if key==14 and #cmd>0 then
- term.setCursorPos(#pre+#cmd+2,18)
- write(" ")
- term.setCursorPos(#pre+#cmd+2,18)
- cmd=string.sub(cmd,1,#cmd-1)
- elseif key==28 then break end
- end
- end
- sgWrite(cmd)
- return cmd
- end
- function sgReceiver() --ХBF?80ХB8ХBDХB8ХBCХB0е?82 ?81ХB8ХB3ХBDХB0ХBB ХB8 ХB7ХB0ХBFХB8?81?8BХB2ХB0е?82 ХB2?80ХB0?82ХB0 ХB2 ?81ХBFХB8?81ХBEк/ХBF?80ХB8ХBDХB8ХBCХB0е?82 ХB2?85ХBEХB4?8F?89ХB8ХB9 ?82ХBEХBDХBDеХBB?8C.
- local i
- local msgs
- while true do
- id,msg=rednet.receive()
- msg=textutils.unserialize(msg)
- if msg[1]=="announce" then
- msgs=0
- for i=1,#gatelist do
- if gatelist[i]==msg[2] then msgs=msgs+1 end
- end
- if msgs==0 then gatelist[#gatelist+1]=msg[2] end
- elseif msg[1]=="open" then
- if msg[2]==gatename and status=="waiting" then status="incoming" end
- end
- end
- end
- function sgTransmitter() --ХBF?80ХB8ХBDХB8ХBCХB0е?82 кХBEХBCХB0ХBDХB4?8B/ХBE?82к?80?8BХB2ХB0е?82 ?82ХBEХBDХBDеХBB?8C
- while true do
- cmd=sgRead()
- if cmd=="/cmdlist" then
- sgCmdList()
- elseif cmd=="/list" then
- local i
- if gatelist[1]==nil then
- sgSay("nogates")
- else
- for i=1,#gatelist do
- if gatelist[i]==nil then break end
- sgWrite(gatelist[i])
- end
- end
- elseif cmd=="/getname" then
- sgWrite(gatename)
- elseif cmd=="/changename" then
- while true do
- gatename=sgRead("gatename")
- if gatename=="" or string.byte(gatename,1)==47 or string.find(gatename,";")~=nil or string.find(gatename," ")~=nil then
- sgSay("wrong")
- else
- sgSay("namesuc")
- break
- end
- end
- sgSave()
- elseif cmd=="/changelang" then
- sgWrite("1. English")
- sgWrite("2. Russkij")
- repeat
- lang=sgRead("lang")
- if lang=="1" then sgWrite("English")
- elseif lang=="2" then sgWrite("Russkij")
- else sgSay("wrong") end
- until lang=="1" or lang=="2"
- lang=lang+0
- sgSave()
- elseif cmd=="/startup" then
- file=io.open("startup", "w")
- file:write("shell.run(\"stargate/stargate.dat\")")
- file:close()
- sgSay("startsuc")
- elseif cmd=="/close" then
- status="waiting"
- redsignal=0
- elseif cmd=="/clear" then
- term.clear()
- term.setCursorPos(1, 1)
- write("GateOS 1.1")
- term.setCursorPos(1, 16)
- write("--------------------------------------------------")
- chat={}
- elseif string.find(cmd," ")~=nil then
- sgSay("wrong")
- elseif cmd=="" then
- else
- if string.byte(cmd,1)==47 then
- sgSay("nocommand")
- elseif status=="waiting" then
- rednet.broadcast(textutils.serialize({"open",cmd}))
- status="connecting"
- sgSay("connect")
- else
- sgSay("opened")
- end
- end
- end
- end
- function sgConnecter() --ХB2кХBB?8E?87ХB0е?82/ХB2?8BкХBB?8E?87ХB0е?82 ХB2?80ХB0?82ХB0
- local cnt
- local mo
- while true do
- modemside=nil
- for i=1,#rs.getSides() do
- if peripheral.getType(rs.getSides()[i])=="modem" then
- modemside=rs.getSides()[i]
- end
- end
- if modemside==nil then
- sgSay("nomodem")
- mo=false
- else
- if mo==false then
- sgSay("yesmodem")
- sleep(1)
- os.reboot()
- end
- end
- rednet.broadcast(textutils.serialize({"announce",gatename}))
- if status=="incoming" then
- redstone.setOutput("left", true)
- sgSay("incoming")
- status="opened"
- cnt=0
- elseif status=="connecting" then
- redstone.setOutput("right", true)
- sgSay("connecting")
- status="opened"
- cnt=0
- end
- if status=="opened" then
- cnt=cnt+1
- if cnt==10 then
- status="waiting"
- redstone.setOutput("left", false)
- redstone.setOutput("right", false)
- end
- end
- sleep(1)
- end
- end
- term.clear()
- term.setCursorPos(1, 1)
- write("GateOS 1.1")
- term.setCursorPos(1, 16)
- write("--------------------------------------------------")
- term.setCursorBlink(true)
- sgSay("cmdlist")
- if shell.resolveProgram("stargate/stargate.dat")==nil then
- if shell.resolveProgram("stargate/stargate.exe")==nil then
- sgLang()
- sgSay("install")
- sgSay("yes")
- sgSay("no")
- repeat
- inst=sgRead("install")
- if inst=="1" then
- shell.run("mkdir","stargate")
- shell.run("mv",shell.getRunningProgram(),"stargate/stargate.exe")
- file=io.open("startup", "w")
- file:write("shell.run(\"stargate/stargate.exe\")")
- file:close()
- os.reboot()
- elseif inst=="2" then
- os.reboot()
- else sgSay("wrong") end
- until inst=="1" or inst=="2"
- end
- sgLang()
- sgSay("givename")
- while true do
- gatename=sgRead("gatename")
- if gatename=="" or string.byte(gatename,1)==47 or string.find(gatename,";")~=nil or string.find(gatename," ")~=nil then
- sgSay("wrong")
- else
- break
- end
- end
- sgSave()
- else
- sgLoad()
- end
- while modemside==nil do
- for i=1,#rs.getSides() do
- if peripheral.getType(rs.getSides()[i])=="modem" then
- modemside=rs.getSides()[i]
- end
- end
- if modemside==nil then
- sgSay("nomodem")
- sgSay("skip")
- os.pullEvent("char")
- else
- sgSay("yesmodem")
- rednet.open(modemside)
- end
- end
- parallel.waitForAll(sgReceiver,sgConnecter,sgTransmitter)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement