Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
squall2044

SGCraft remote iris

Question

hi i'm looking to create and run a program that will automatically close the iris when a connection comes into the gate (figured that out)

then open it with a message (got that too). the part hat is confuseing me however is how do I filter it so that the program is only looking at what was typed to be sent. e.g. if the code was 12345 how do i get it to read that instead of reading sgMessageReceived "souceaddress" 12345?   

Code so far:

 

component = require("component")

event = require("event")

sg = component.proxy("...") --- deliberately put the three dots here as it changes

 

event.pull("sgDialIn")

 sg.closeIris()

event.pull("sgMessageReceived")

 sg.openIris()

 

 

thats what I have so far the problem is it opens the gate when it receives any message from the other-side of a gate. Anybody have any ideas?

 

Edit: Nevermind I got it figured out.

Useing my gates and 12345 as a test password this is what worked for me:

 
c = require("component")
e = require("event")
s = c.getPrimary("stargate")
 
e.pull("sgDialIn")
  print("Incoming Wormhole")
    print("Closing Iris")
      s.closeIris()
e.pull("sgStargateStateChange")
  print("Awaiting Signal")
local _, remoteAddress, payload = e.pull("sgMessageReceived")
  if payload == "12345" then
    print("Code Accpeted, Opening Iris")
      s.openIris()
else if payload ~= "12345" then
  print("Code Not Accepted, Disconnecting Gate")
    s.disconnect()
e.pull("sgStargateStateChange")
  print("Gate Disconnected, Opening Iris")
    s.openIris()
      print("Good-Bye")
  end
end
 
 
edit 2
And more importantly this is wireless:
Using 420 as the port and 12345 as a test password:
computer must have a wireless network card
computer connected to gate needs this program:
 
c = require("component")
e = require("event")
t = require("term")
local m = c.modem
 
s = c.getPrimary("stargate")
 
t.clear()
 
while true do
print(e.pull("sgDialIn"))
print("Incoming Wormhole")
print("Closing Iris")
s.closeIris()
m.open(420) --- Choose whatever port you want
print("Channel Open")
e.pull("sgStargateStateChange")
print("Awaiting Signal")
local _, _, from, port, _, message = e.pull("modem_message")
if message == "12345" then  --- choose whatever password you want
 print("Code Accpeted, Opening Iris")
  s.openIris()
   os.sleep(2)
    m.broadcast(420, "Iris Open") --- port must be the same as the one you chose earlier
     print("Welcome Home")
      os.sleep(10)
       print("Closing Gate")
        s.disconnect()
 else if message ~= "12345" then ---password must be the same as the one you chose earlier
  m.broadcast(420, "Code Rejected") --- port must be the same as the one you chose earlier
   print("Code: " ..(message).." Not Accepted, Disconnecting Gate")
    s.disconnect()
     e.pull("sgStargateStateChange")
      os.sleep(1)
       print("Gate Disconnected, Opening Iris")
        s.openIris()
         print("Good-Bye")
  end
 end
end

 

 

and on the tablet :

tablet must haves: wireless network card and keyboard

 

local component = require("component")
local event = require("event")
local m = component.modem -- get primary modem component
m.open(420) --- port must be the same as the computer
print(m.isOpen(420)) -- true --- see above though this line is not really needed
-- Send some message.
m.broadcast(420, "12345") --- port and password must be the same as the computer
-- Wait for a message from another network card.
local _, _, from, port, _, message = event.pull("modem_message")
print(message)
 
 
Hope this works for you as well as it has for me.
 
edit 3: tweaked the code so there is less to change
Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0
  • Solution

You need an IF statement around the sg,openIris() call, this statement needs to check the data you are sending in the sgMessageReceived validate it and if true open the iris.

 

I'm not at home to test this code but based on the Wiki my limited experience with OC and LUA I can suggest the below to help you move forward.

 

Without the broadcast code I've no idea what you've broadcast the "12345" text as, but if you read the wiki here: http://ocdoc.cil.li/component:modem you can see that it tells us your string will be one of the parameters sent at the end of the standard list. Simply check the parameter against what you want it to be or assign it to a variable called password for example I will assume the Wiki's example but with your required password:

 

Example Broadcast code (direct from the Wiki page and altered to send your password string 12345)

-- Hook components
-- (the Wiki has the event too but that's for the message receive part so i dropped it)
local component = require("component")
local m = component.modem -- get primary modem component

-- Open the port on the network and print out if it is open (should print true or this wont work)
m.open(123)
print(m.isOpen(123)) -- true

-- Send the password string, this could be a variable with your user input but for
-- now use a hard coded value, this has the weakness of if someone gets your device
-- they can use it to open your gate!
m.broadcast(321, "12345")

The receiving computer would have this to be able to get the message:

-- Hook the Events library
local event = require ("event")

-- Wait for a message from another network card.
local _, _, from, port, _, message = event.pull("modem_message")
password = tostring(message)

Once you've got that you'd simple check that the password matched the value you want and at that point open the Iris with something like:

IF(password == "12345")THEN
    sg.openIris()
    -- Maybe send back confirmation the iris is open?
END

Just food for thought, you'd probably want some way to know if the Iris has opened or not so you should send a message back to inform the user if they are safe or not as getting the password wrong would not open the iris and would most likely upset the travelers day!  :lol:

Link to post
Share on other sites
  • 0

try this

c = require("component")
e = require("event")
t = require("term")
local m = c.modem
 
s = c.getPrimary("stargate")
 
t.clear()
 
while true do
print(e.pull("sgDialIn"))
print("Incoming Wormhole")
print("Closing Iris")
s.closeIris()
m.open(420) --- Choose whatever port you want
print("Channel Open")
e.pull("sgStargateStateChange")
print("Awaiting Signal")
m.broadcast(420, "Awaiting Signal.")
local _, _, from, port, _, message = e.pull("modem_message")
if message == "12345" then  --- choose whatever password you want
 print("Code Accpeted, Opening Iris")
  s.openIris()
   os.sleep(2)
    m.broadcast(420, "Iris Open") --- port must be the same as the one you chose earlier
     print("Welcome Home")
      os.sleep(10)
       print("Closing Gate")
        s.disconnect()
 else if message ~= "12345" then ---password must be the same as the one you chose earlier
  m.broadcast(420, "Code Rejected") --- port must be the same as the one you chose earlier
   print("Code: " ..(message).." Not Accepted, Disconnecting Gate")
    s.disconnect()
     e.pull("sgStargateStateChange")
      os.sleep(1)
       print("Gate Disconnected, Opening Iris")
        s.openIris()
         print("Good-Bye")
  end
 end
end
 
 
tablet:
 
local component = require("component")
local event = require("event")
local m = component.modem -- get primary modem component
m.open(420) --- port must be the same as the computer
print(m.isOpen(420)) -- true --- see above though this line is not really needed
local _, _, from, port, _, message = event.pull("modem_message")
print(message)
-- Send some message.
m.broadcast(420, "12345") --- port and password must be the same as the computer
-- Wait for a message from another network card.
local _, _, from, port, _, message = event.pull("modem_message")
print(message)

 

 

 

remember to put the computer controlling the iris within range of opencomputers broadcast strength. But also remember that a wireless signal that passes through the stargate comes out the other side at half strength so be sure to be in range at the other side as well.  The changes I made to the code above will allow you to see if your iris computer is within range of the signals. If it doesn't work let me know and I'll try to help you through it.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.