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

Server Network Mainframe Idea, requires computers to be able to access server raid array on separate network

Question

as the title says, i want to make a server mainframe for controlling various things in a modded base. i want to have a computer in each room that i can type a program name and it will run it as if i was typing it on the mainframe console, that's probably the easy bit. the hard bit is i want to be able to type a special command and it will allow me to write programs to the raid array in the server room, on a separate network separated by about 10 network relays... yeah, it's a bit ambitious considering i am a bit of a noob at opencomputers, i can do basic stuff but nothing close to what most of you guys can probably do. i don't know if the idea is even possible, if you can help please do.

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

This is a cool idea. I believe there are a few libs out there that might help a lot in making this. Just my thoughts.. I think you have the difficulties reversed. Keeping a terminal responsive and in sync over a network is probably the trickier part. Sending files is pretty simple all around. Adding authentication (for validating if you want this or that machine reading or writing that particular file), or encryption if you're on a server or you want to control your base from outside of MC. Those last two may be unnecessary if you're playing single player or just don't care that much about network security.

Here is a simple example of sending a file between two computers on the same network. Crude but should demonstrate that it's pretty simple in principle.

client

-- # fget.lua
local args, opts = require("shell").parse(...)
local uptime = require("computer").uptime
local modem = require("component").modem
local pull = require("event").pull

local filename = assert(args[1], "Usage: fget filename [port] [timeout]")
local port = 22
local timeout = 5

if opts.port then
  local pnum = assert(tonumber(opts.port), "option 'port' must be a number!")
  port = assert(pnum > 0 and pnum <= 65535)
end

if opts.timeout then
  timeout = assert(tonumber(opts.timeout),"option 'timeout(seconds)' must be number. [~3 sec recommended]")
end

modem.open(port)

modem.broadcast(port, "F_REQUEST", filename) -- crude and will allow just about anybody to fulfill this request :/

local response, key
local stime = uptime()

repeat
  local ev = {pull((stime + timeout - uptime()), "(modem_message)(interrupted)")}

  if ev[1] == "interrupted" then
  	print(ev[1])
  	os.exit()
  elseif ev[1] == "modem_message" and ev[6] == "F_RESPONSE" then
    key = ev[7]
    response = true
    break
  end
until uptime() >= (stime + timeout)

if not response then
  print "timed out. no response"
  os.exit()
end

local _error
stime = uptime() -- # refresh timeout

repeat
  local ev = {pull((stime + timeout - uptime()), "(modem_message)(interrupted)")}

  if ev[1] == "interrupted" then
  	print(ev[1])
  	os.exit()
  elseif ev[1] == "modem_message" and ev[6] == key then
    stime = uptime() -- # refresh the timeout
    
    if not ev[7] then
      if ev[8] and ev[8] == "error" then
        _error = true
        io.stderr:write("error occured. '*drops pizza on the floor*'")
      end
      
      break
    end
    
    io.stdout:write(ev[7])
  end
until uptime() >= (stime + timeout)

if _error then
  os.exit(1)
end

-- # Disclaimer: this hasn't been tested :3

server

-- # fserv.lua
local shell = require("shell")
local uptime = require("computer").uptime
local modem = require("component").modem
local pull = require("event").pull
local uuid = require("uuid")
local fs = require("filesystem")

local args, opts = shell.parse(...)
local port = 22

-- # handle port options

local srvdir
if args[1] then
  assert(fs.exists(args[1]))
  assert(fs.isDirectory(args[1]))
  srvdir = args[1]
else
  srvdir = shell.getWorkingDirectory()
end

modem.open(port)

while true do
  local ev = {pull("(modem_message)(interrupted)")}
  
  if ev[1] == "interrupted" then
    print "quitting.."
    os.exit()
  elseif ev[1] == "modem_message" and ev[6] == "F_REQUEST" and ev[7] ~= nil then
    local path = srvdir..ev[7]
    
    if fs.exists(path) and (not fs.isDirectory(path)) then
      local chunkSize = modem.maxPacketSize() - 1024
      local res = {pcall(io.open, path, "r")}
      
      if not res[1] then
        io.stderr:write("service error: " .. res[2])
      else
        local fd = res[1]
        local chunk = fd:read(chunkSize)

        if chunk then
          local key = uuid.next()
          
          modem.send(ev[3], ev[4], "F_RESPONSE", key)

          repeat
            modem.send(ev[3], ev[4], key, chunk)
            
            res = {pcall(function()
                chunk = fd:read(chunkSize)
              end)}

            if not res[1] then
              modem.send(ev[3], ev[4], key, nil, 'error') -- # nil, 'error' signals srv failure on client
              break
            end
          until not chunk

          if res[1] then -- ok
            modem.send(ev[3], ev[4], key, nil) -- # eof on client
          else
            io.stderr:write(res[2] or "bad salsa")
          end
        end
      end
    end
  end
end

-- # Disclaimer!! Also untested.. :3

Hope this is helpful, if at least to get those wheels turning :3 

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.