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

SGCraft and wireless

Question

Hi all I am trying to write a program to control sgcraft gates and
am having some trouble with the server side of things heres what I have
so far:
##########################################################################
local c = require("component")

local e = require("event")

local m = c.modem

local s = c.stargate

local computer = require("computer")

()
m.open(20)

m.broadcast(20, "Online.")

local _, _, f1, port, _, message1 = e.pull("modem_message")

if message1 == "s.dial('s.localAddress()')" then

  m.send(f1, 20, io.stderr:write("Cannot connect to self."))

 else if message1 == "s.dial('???-??????')" and s.energyAvailable() < s.energyToDial('????-??????') then

   m.send(f1, 10, io.stderr:write("Not enough energy to dial that gate."))

  else if message1 == "s.dial('????-??????')" and s.stargateState() == "Idle" then

    m.send(f1, 20, "Dialing.")

   else if message1 == "s.closeIris()" and s.irisState() ~= "offline" then

     m.send(f1, 20, "Closing Iris.")

    else if message1 == "s.openIris()" and s.irisState() ~= "offline" then

      m.send(f1, 20, "Opening Iris.")

     else if message1 == "s.disconnect()" and s.stargateState() ~= "Idle" then

       m.send(f1, 20, "Disconnecting.")

----    else if message1 ==

    else

      m.send(f1, 20, io.stderr:write("Command Not Recognized. PLease wait 30 SECONDS for shutdown"))

     end

    end

   end

  end

 end

end

-----print("Hello")


(message1) ----This is where I am having trouble
computer.shutdown()
#########################################################################

Right now the computer is hooked up to a stargate with an Iris and I cam call the methods
directly from the computer but I want to run them from a tablet so I can 
bury the computer and leave it with no screen and a wake message.

what I want it to do is if I send s.closeIris() the Iris will close but I am just getting a
/home/dial:37: syntax error near 'computer'

Can anyone help me?

Thank you in advance.
 

Edited by squall2044
Added more info
Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

I would recommend not executing strings sent down a network.. If you're just in a SP world then fine, have at it. But, if you're on multiplayer then this is a big security problem. Just saying..

A better solution would be to design commands / responses with parameters that can be sent between the client and server. i.e.

-- # On the server

-- # Other code implied up hurr...

local commands = {
	openIris = function()
		if s.irisState() ~= 'offline' then
			m.send( f1, 20, 'Opening Iris.' )
		end
	end,
	dial = function( address )
		if s.irisState() == 'idle' then
			m.send( f1, 20, string.format( 'Dialing %s', address )
		end
	end
	-- ... more commands go here
}

-- # on message...
-- # cmd should look like: { 'dial', 'kjai2sdiwdSOME_ADDRESSksjdlaks' }
local cmd = { string.match( message1, '(%a%d_)' ) }

local command, args = table.remove( cmd, 1 ), { table.unpack( cmd ) }

-- # This calls our command with any args sent with it. This is safer than load('msg') because 'msg' could be malicious.
commands[ command ]( table.unpack( args ) )

-- # DISCLAIMER: I haven't run this code. Could have bugs. But this is generally how I handle commands over the net.

 

Let me know if I need to clarify anything... :)

Edited by Molinko
formatting..
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.